blob: dc498c89061f161e7b017947a22d1668955f40e3 [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 }
cristye6365592010-04-02 17:31:23 +00001154 if (LocaleCompare("color-matrix",option+1) == 0)
1155 {
1156 Image
1157 *color_image;
1158
1159 KernelInfo
1160 *kernel;
1161
1162 (void) SyncImageSettings(image_info,*image);
1163 kernel=AcquireKernelInfo(argv[i+1]);
1164 if (kernel == (KernelInfo *) NULL)
1165 break;
1166 color_image=ColorMatrixImage(*image,kernel,exception);
1167 kernel=DestroyKernelInfo(kernel);
1168 if (color_image == (Image *) NULL)
1169 break;
1170 *image=DestroyImage(*image);
1171 *image=color_image;
1172 break;
1173 }
cristy3ed852e2009-09-05 21:47:34 +00001174 if (LocaleCompare("colors",option+1) == 0)
1175 {
1176 /*
1177 Reduce the number of colors in the image.
1178 */
1179 (void) SyncImageSettings(image_info,*image);
cristye27293e2009-12-18 02:53:20 +00001180 quantize_info->number_colors=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00001181 if (quantize_info->number_colors == 0)
1182 break;
1183 if (((*image)->storage_class == DirectClass) ||
1184 (*image)->colors > quantize_info->number_colors)
1185 (void) QuantizeImage(quantize_info,*image);
1186 else
1187 (void) CompressImageColormap(*image);
1188 InheritException(exception,&(*image)->exception);
1189 break;
1190 }
1191 if (LocaleCompare("colorspace",option+1) == 0)
1192 {
1193 ColorspaceType
1194 colorspace;
1195
1196 (void) SyncImageSettings(image_info,*image);
1197 if (*option == '+')
1198 {
1199 (void) TransformImageColorspace(*image,RGBColorspace);
1200 InheritException(exception,&(*image)->exception);
1201 break;
1202 }
1203 colorspace=(ColorspaceType) ParseMagickOption(
1204 MagickColorspaceOptions,MagickFalse,argv[i+1]);
1205 (void) TransformImageColorspace(*image,colorspace);
1206 InheritException(exception,&(*image)->exception);
1207 break;
1208 }
1209 if (LocaleCompare("contrast",option+1) == 0)
1210 {
1211 (void) SyncImageSettings(image_info,*image);
1212 (void) ContrastImage(*image,(*option == '-') ? MagickTrue :
1213 MagickFalse);
1214 InheritException(exception,&(*image)->exception);
1215 break;
1216 }
1217 if (LocaleCompare("contrast-stretch",option+1) == 0)
1218 {
1219 double
1220 black_point,
1221 white_point;
1222
cristy3ed852e2009-09-05 21:47:34 +00001223 MagickStatusType
1224 flags;
1225
1226 /*
1227 Contrast stretch image.
1228 */
1229 (void) SyncImageSettings(image_info,*image);
1230 flags=ParseGeometry(argv[i+1],&geometry_info);
1231 black_point=geometry_info.rho;
1232 white_point=(flags & SigmaValue) != 0 ? geometry_info.sigma :
1233 black_point;
1234 if ((flags & PercentValue) != 0)
1235 {
1236 black_point*=(double) (*image)->columns*(*image)->rows/100.0;
1237 white_point*=(double) (*image)->columns*(*image)->rows/100.0;
1238 }
1239 white_point=(MagickRealType) (*image)->columns*(*image)->rows-
1240 white_point;
1241 (void) ContrastStretchImageChannel(*image,channel,black_point,
1242 white_point);
1243 InheritException(exception,&(*image)->exception);
1244 break;
1245 }
1246 if (LocaleCompare("convolve",option+1) == 0)
1247 {
cristy36826ab2010-03-06 01:29:30 +00001248 double
1249 gamma;
1250
cristy3ed852e2009-09-05 21:47:34 +00001251 Image
1252 *convolve_image;
1253
cristy2be15382010-01-21 02:38:03 +00001254 KernelInfo
cristy56a9e512010-01-06 18:18:55 +00001255 *kernel;
cristy3ed852e2009-09-05 21:47:34 +00001256
cristy36826ab2010-03-06 01:29:30 +00001257 register long
1258 j;
1259
cristya6510532010-03-06 13:09:30 +00001260 (void) SyncImageSettings(image_info,*image);
cristy2be15382010-01-21 02:38:03 +00001261 kernel=AcquireKernelInfo(argv[i+1]);
1262 if (kernel == (KernelInfo *) NULL)
cristy56a9e512010-01-06 18:18:55 +00001263 break;
cristy36826ab2010-03-06 01:29:30 +00001264 gamma=0.0;
1265 for (j=0; j < (long) (kernel->width*kernel->height); j++)
1266 gamma+=kernel->values[j];
1267 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
cristyd2baf7d2010-03-06 04:26:44 +00001268 for (j=0; j < (long) (kernel->width*kernel->height); j++)
cristy36826ab2010-03-06 01:29:30 +00001269 kernel->values[j]*=gamma;
cristy6771f1e2010-03-05 19:43:39 +00001270 convolve_image=FilterImageChannel(*image,channel,kernel,exception);
anthony83ba99b2010-01-24 08:48:15 +00001271 kernel=DestroyKernelInfo(kernel);
cristy3ed852e2009-09-05 21:47:34 +00001272 if (convolve_image == (Image *) NULL)
1273 break;
1274 *image=DestroyImage(*image);
1275 *image=convolve_image;
1276 break;
1277 }
1278 if (LocaleCompare("crop",option+1) == 0)
1279 {
1280 (void) SyncImageSettings(image_info,*image);
1281 flags=ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1282 if (((geometry.width != 0) || (geometry.height != 0)) &&
1283 ((flags & XValue) == 0) && ((flags & YValue) == 0))
1284 break;
1285 (void) TransformImage(image,argv[i+1],(char *) NULL);
1286 InheritException(exception,&(*image)->exception);
1287 break;
1288 }
1289 if (LocaleCompare("cycle",option+1) == 0)
1290 {
1291 /*
1292 Cycle an image colormap.
1293 */
1294 (void) SyncImageSettings(image_info,*image);
cristyf2f27272009-12-17 14:48:46 +00001295 (void) CycleColormapImage(*image,StringToLong(argv[i+1]));
cristy3ed852e2009-09-05 21:47:34 +00001296 InheritException(exception,&(*image)->exception);
1297 break;
1298 }
1299 break;
1300 }
1301 case 'd':
1302 {
1303 if (LocaleCompare("decipher",option+1) == 0)
1304 {
1305 StringInfo
1306 *passkey;
1307
1308 /*
1309 Decipher pixels.
1310 */
1311 (void) SyncImageSettings(image_info,*image);
1312 passkey=FileToStringInfo(argv[i+1],~0,exception);
1313 if (passkey != (StringInfo *) NULL)
1314 {
1315 (void) PasskeyDecipherImage(*image,passkey,exception);
1316 passkey=DestroyStringInfo(passkey);
1317 }
1318 break;
1319 }
1320 if (LocaleCompare("density",option+1) == 0)
1321 {
1322 /*
1323 Set image density.
1324 */
1325 (void) CloneString(&draw_info->density,argv[i+1]);
1326 break;
1327 }
1328 if (LocaleCompare("depth",option+1) == 0)
1329 {
1330 (void) SyncImageSettings(image_info,*image);
1331 if (*option == '+')
1332 {
1333 (void) SetImageDepth(*image,MAGICKCORE_QUANTUM_DEPTH);
1334 break;
1335 }
cristye27293e2009-12-18 02:53:20 +00001336 (void) SetImageDepth(*image,StringToUnsignedLong(argv[i+1]));
cristy3ed852e2009-09-05 21:47:34 +00001337 break;
1338 }
1339 if (LocaleCompare("deskew",option+1) == 0)
1340 {
1341 double
1342 threshold;
1343
1344 Image
1345 *deskew_image;
1346
1347 /*
1348 Straighten the image.
1349 */
1350 (void) SyncImageSettings(image_info,*image);
1351 if (*option == '+')
1352 threshold=40.0*QuantumRange/100.0;
1353 else
cristyf2f27272009-12-17 14:48:46 +00001354 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
cristy3ed852e2009-09-05 21:47:34 +00001355 deskew_image=DeskewImage(*image,threshold,exception);
1356 if (deskew_image == (Image *) NULL)
1357 break;
1358 *image=DestroyImage(*image);
1359 *image=deskew_image;
1360 break;
1361 }
1362 if (LocaleCompare("despeckle",option+1) == 0)
1363 {
1364 Image
1365 *despeckle_image;
1366
1367 /*
1368 Reduce the speckles within an image.
1369 */
1370 (void) SyncImageSettings(image_info,*image);
1371 despeckle_image=DespeckleImage(*image,exception);
1372 if (despeckle_image == (Image *) NULL)
1373 break;
1374 *image=DestroyImage(*image);
1375 *image=despeckle_image;
1376 break;
1377 }
1378 if (LocaleCompare("display",option+1) == 0)
1379 {
1380 (void) CloneString(&draw_info->server_name,argv[i+1]);
1381 break;
1382 }
cristy3ed852e2009-09-05 21:47:34 +00001383 if (LocaleCompare("distort",option+1) == 0)
1384 {
1385 char
1386 *args,
1387 token[MaxTextExtent];
1388
1389 const char
1390 *p;
1391
1392 DistortImageMethod
1393 method;
1394
1395 double
1396 *arguments;
1397
1398 Image
1399 *distort_image;
1400
1401 register long
1402 x;
1403
1404 unsigned long
1405 number_arguments;
1406
1407 /*
1408 Distort image.
1409 */
1410 (void) SyncImageSettings(image_info,*image);
1411 method=(DistortImageMethod) ParseMagickOption(MagickDistortOptions,
1412 MagickFalse,argv[i+1]);
1413 args=InterpretImageProperties(image_info,*image,argv[i+2]);
1414 InheritException(exception,&(*image)->exception);
1415 if (args == (char *) NULL)
1416 break;
1417 p=(char *) args;
1418 for (x=0; *p != '\0'; x++)
1419 {
1420 GetMagickToken(p,&p,token);
1421 if (*token == ',')
1422 GetMagickToken(p,&p,token);
1423 }
1424 number_arguments=(unsigned long) x;
1425 arguments=(double *) AcquireQuantumMemory(number_arguments,
1426 sizeof(*arguments));
1427 if (arguments == (double *) NULL)
1428 ThrowWandFatalException(ResourceLimitFatalError,
1429 "MemoryAllocationFailed",(*image)->filename);
1430 (void) ResetMagickMemory(arguments,0,number_arguments*
1431 sizeof(*arguments));
1432 p=(char *) args;
1433 for (x=0; (x < (long) number_arguments) && (*p != '\0'); x++)
1434 {
1435 GetMagickToken(p,&p,token);
1436 if (*token == ',')
1437 GetMagickToken(p,&p,token);
cristyf2f27272009-12-17 14:48:46 +00001438 arguments[x]=StringToDouble(token);
cristy3ed852e2009-09-05 21:47:34 +00001439 }
1440 args=DestroyString(args);
1441 distort_image=DistortImage(*image,method,number_arguments,arguments,
1442 (*option == '+') ? MagickTrue : MagickFalse,exception);
1443 arguments=(double *) RelinquishMagickMemory(arguments);
1444 if (distort_image == (Image *) NULL)
1445 break;
1446 *image=DestroyImage(*image);
1447 *image=distort_image;
1448 break;
1449 }
1450 if (LocaleCompare("dither",option+1) == 0)
1451 {
1452 if (*option == '+')
1453 {
1454 quantize_info->dither=MagickFalse;
1455 break;
1456 }
1457 quantize_info->dither=MagickTrue;
1458 quantize_info->dither_method=(DitherMethod) ParseMagickOption(
1459 MagickDitherOptions,MagickFalse,argv[i+1]);
1460 if (quantize_info->dither_method == NoDitherMethod)
1461 quantize_info->dither=MagickFalse;
1462 break;
1463 }
1464 if (LocaleCompare("draw",option+1) == 0)
1465 {
1466 /*
1467 Draw image.
1468 */
1469 (void) SyncImageSettings(image_info,*image);
1470 (void) CloneString(&draw_info->primitive,argv[i+1]);
1471 (void) DrawImage(*image,draw_info);
1472 InheritException(exception,&(*image)->exception);
1473 break;
1474 }
1475 break;
1476 }
1477 case 'e':
1478 {
1479 if (LocaleCompare("edge",option+1) == 0)
1480 {
1481 Image
1482 *edge_image;
1483
1484 /*
1485 Enhance edges in the image.
1486 */
1487 (void) SyncImageSettings(image_info,*image);
1488 flags=ParseGeometry(argv[i+1],&geometry_info);
1489 if ((flags & SigmaValue) == 0)
1490 geometry_info.sigma=1.0;
1491 edge_image=EdgeImage(*image,geometry_info.rho,exception);
1492 if (edge_image == (Image *) NULL)
1493 break;
1494 *image=DestroyImage(*image);
1495 *image=edge_image;
1496 break;
1497 }
1498 if (LocaleCompare("emboss",option+1) == 0)
1499 {
1500 Image
1501 *emboss_image;
1502
1503 /*
1504 Gaussian embossen image.
1505 */
1506 (void) SyncImageSettings(image_info,*image);
1507 flags=ParseGeometry(argv[i+1],&geometry_info);
1508 if ((flags & SigmaValue) == 0)
1509 geometry_info.sigma=1.0;
1510 emboss_image=EmbossImage(*image,geometry_info.rho,
1511 geometry_info.sigma,exception);
1512 if (emboss_image == (Image *) NULL)
1513 break;
1514 *image=DestroyImage(*image);
1515 *image=emboss_image;
1516 break;
1517 }
1518 if (LocaleCompare("encipher",option+1) == 0)
1519 {
1520 StringInfo
1521 *passkey;
1522
1523 /*
1524 Encipher pixels.
1525 */
1526 (void) SyncImageSettings(image_info,*image);
1527 passkey=FileToStringInfo(argv[i+1],~0,exception);
1528 if (passkey != (StringInfo *) NULL)
1529 {
1530 (void) PasskeyEncipherImage(*image,passkey,exception);
1531 passkey=DestroyStringInfo(passkey);
1532 }
1533 break;
1534 }
1535 if (LocaleCompare("encoding",option+1) == 0)
1536 {
1537 (void) CloneString(&draw_info->encoding,argv[i+1]);
1538 break;
1539 }
1540 if (LocaleCompare("enhance",option+1) == 0)
1541 {
1542 Image
1543 *enhance_image;
1544
1545 /*
1546 Enhance image.
1547 */
1548 (void) SyncImageSettings(image_info,*image);
1549 enhance_image=EnhanceImage(*image,exception);
1550 if (enhance_image == (Image *) NULL)
1551 break;
1552 *image=DestroyImage(*image);
1553 *image=enhance_image;
1554 break;
1555 }
1556 if (LocaleCompare("equalize",option+1) == 0)
1557 {
1558 /*
1559 Equalize image.
1560 */
1561 (void) SyncImageSettings(image_info,*image);
1562 (void) EqualizeImageChannel(*image,channel);
1563 InheritException(exception,&(*image)->exception);
1564 break;
1565 }
1566 if (LocaleCompare("evaluate",option+1) == 0)
1567 {
1568 double
1569 constant;
1570
1571 MagickEvaluateOperator
1572 op;
1573
1574 (void) SyncImageSettings(image_info,*image);
1575 op=(MagickEvaluateOperator) ParseMagickOption(MagickEvaluateOptions,
1576 MagickFalse,argv[i+1]);
cristyf2f27272009-12-17 14:48:46 +00001577 constant=SiPrefixToDouble(argv[i+2],QuantumRange);
cristy3ed852e2009-09-05 21:47:34 +00001578 (void) EvaluateImageChannel(*image,channel,op,constant,exception);
1579 break;
1580 }
1581 if (LocaleCompare("extent",option+1) == 0)
1582 {
1583 Image
1584 *extent_image;
1585
1586 /*
1587 Set the image extent.
1588 */
1589 (void) SyncImageSettings(image_info,*image);
1590 flags=ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
cristyf0bbfd92009-11-25 14:12:31 +00001591 if (geometry.width == 0)
cristy2ea9a4e2009-11-25 14:30:22 +00001592 geometry.width=(*image)->columns;
cristyf0bbfd92009-11-25 14:12:31 +00001593 if (geometry.height == 0)
cristy2ea9a4e2009-11-25 14:30:22 +00001594 geometry.height=(*image)->rows;
cristy3ed852e2009-09-05 21:47:34 +00001595 geometry.x=(-geometry.x);
1596 geometry.y=(-geometry.y);
1597 extent_image=ExtentImage(*image,&geometry,exception);
1598 if (extent_image == (Image *) NULL)
1599 break;
1600 *image=DestroyImage(*image);
1601 *image=extent_image;
1602 break;
1603 }
1604 break;
1605 }
1606 case 'f':
1607 {
1608 if (LocaleCompare("family",option+1) == 0)
1609 {
1610 if (*option == '+')
1611 {
1612 if (draw_info->family != (char *) NULL)
1613 draw_info->family=DestroyString(draw_info->family);
1614 break;
1615 }
1616 (void) CloneString(&draw_info->family,argv[i+1]);
1617 break;
1618 }
cristy0fe961c2010-01-30 03:09:54 +00001619 if (LocaleCompare("features",option+1) == 0)
1620 {
1621 if (*option == '+')
1622 {
1623 (void) DeleteImageArtifact(*image,"identify:features");
1624 break;
1625 }
1626 (void) SetImageArtifact(*image,"identify:features",argv[i+1]);
1627 break;
1628 }
cristy3ed852e2009-09-05 21:47:34 +00001629 if (LocaleCompare("fill",option+1) == 0)
1630 {
1631 ExceptionInfo
1632 *sans;
1633
1634 GetMagickPixelPacket(*image,&fill);
1635 if (*option == '+')
1636 {
1637 (void) QueryMagickColor("none",&fill,exception);
1638 (void) QueryColorDatabase("none",&draw_info->fill,exception);
1639 if (draw_info->fill_pattern != (Image *) NULL)
1640 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
1641 break;
1642 }
1643 sans=AcquireExceptionInfo();
1644 (void) QueryMagickColor(argv[i+1],&fill,sans);
1645 status=QueryColorDatabase(argv[i+1],&draw_info->fill,sans);
1646 sans=DestroyExceptionInfo(sans);
1647 if (status == MagickFalse)
1648 draw_info->fill_pattern=GetImageCache(image_info,argv[i+1],
1649 exception);
1650 break;
1651 }
1652 if (LocaleCompare("flip",option+1) == 0)
1653 {
1654 Image
1655 *flip_image;
1656
1657 /*
1658 Flip image scanlines.
1659 */
1660 (void) SyncImageSettings(image_info,*image);
1661 flip_image=FlipImage(*image,exception);
1662 if (flip_image == (Image *) NULL)
1663 break;
1664 *image=DestroyImage(*image);
1665 *image=flip_image;
1666 break;
1667 }
1668 if (LocaleCompare("flop",option+1) == 0)
1669 {
1670 Image
1671 *flop_image;
1672
1673 /*
1674 Flop image scanlines.
1675 */
1676 (void) SyncImageSettings(image_info,*image);
1677 flop_image=FlopImage(*image,exception);
1678 if (flop_image == (Image *) NULL)
1679 break;
1680 *image=DestroyImage(*image);
1681 *image=flop_image;
1682 break;
1683 }
1684 if (LocaleCompare("floodfill",option+1) == 0)
1685 {
1686 MagickPixelPacket
1687 target;
1688
1689 /*
1690 Floodfill image.
1691 */
1692 (void) SyncImageSettings(image_info,*image);
1693 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
1694 (void) QueryMagickColor(argv[i+2],&target,exception);
1695 (void) FloodfillPaintImage(*image,channel,draw_info,&target,
1696 geometry.x,geometry.y,*option == '-' ? MagickFalse : MagickTrue);
1697 InheritException(exception,&(*image)->exception);
1698 break;
1699 }
1700 if (LocaleCompare("font",option+1) == 0)
1701 {
1702 if (*option == '+')
1703 {
1704 if (draw_info->font != (char *) NULL)
1705 draw_info->font=DestroyString(draw_info->font);
1706 break;
1707 }
1708 (void) CloneString(&draw_info->font,argv[i+1]);
1709 break;
1710 }
1711 if (LocaleCompare("format",option+1) == 0)
1712 {
1713 format=argv[i+1];
1714 break;
1715 }
1716 if (LocaleCompare("frame",option+1) == 0)
1717 {
1718 FrameInfo
1719 frame_info;
1720
1721 Image
1722 *frame_image;
1723
1724 /*
1725 Surround image with an ornamental border.
1726 */
1727 (void) SyncImageSettings(image_info,*image);
1728 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
1729 frame_info.width=geometry.width;
1730 frame_info.height=geometry.height;
1731 if ((flags & HeightValue) == 0)
1732 frame_info.height=geometry.width;
1733 frame_info.outer_bevel=geometry.x;
1734 frame_info.inner_bevel=geometry.y;
1735 frame_info.x=(long) frame_info.width;
1736 frame_info.y=(long) frame_info.height;
1737 frame_info.width=(*image)->columns+2*frame_info.width;
1738 frame_info.height=(*image)->rows+2*frame_info.height;
1739 frame_image=FrameImage(*image,&frame_info,exception);
1740 if (frame_image == (Image *) NULL)
1741 break;
1742 *image=DestroyImage(*image);
1743 *image=frame_image;
1744 break;
1745 }
1746 if (LocaleCompare("function",option+1) == 0)
1747 {
1748 char
1749 *arguments,
1750 token[MaxTextExtent];
1751
1752 const char
1753 *p;
1754
1755 double
1756 *parameters;
1757
1758 MagickFunction
1759 function;
1760
1761 register long
1762 x;
1763
1764 unsigned long
1765 number_parameters;
1766
1767 /*
1768 Function Modify Image Values
1769 */
1770 (void) SyncImageSettings(image_info,*image);
1771 function=(MagickFunction) ParseMagickOption(MagickFunctionOptions,
1772 MagickFalse,argv[i+1]);
1773 arguments=InterpretImageProperties(image_info,*image,argv[i+2]);
1774 InheritException(exception,&(*image)->exception);
1775 if (arguments == (char *) NULL)
1776 break;
1777 p=(char *) arguments;
1778 for (x=0; *p != '\0'; x++)
1779 {
1780 GetMagickToken(p,&p,token);
1781 if (*token == ',')
1782 GetMagickToken(p,&p,token);
1783 }
1784 number_parameters=(unsigned long) x;
1785 parameters=(double *) AcquireQuantumMemory(number_parameters,
1786 sizeof(*parameters));
1787 if (parameters == (double *) NULL)
1788 ThrowWandFatalException(ResourceLimitFatalError,
1789 "MemoryAllocationFailed",(*image)->filename);
1790 (void) ResetMagickMemory(parameters,0,number_parameters*
1791 sizeof(*parameters));
1792 p=(char *) arguments;
1793 for (x=0; (x < (long) number_parameters) && (*p != '\0'); x++)
1794 {
1795 GetMagickToken(p,&p,token);
1796 if (*token == ',')
1797 GetMagickToken(p,&p,token);
cristyf2f27272009-12-17 14:48:46 +00001798 parameters[x]=StringToDouble(token);
cristy3ed852e2009-09-05 21:47:34 +00001799 }
1800 arguments=DestroyString(arguments);
1801 (void) FunctionImageChannel(*image,channel,function,
1802 number_parameters,parameters,exception);
1803 parameters=(double *) RelinquishMagickMemory(parameters);
1804 break;
1805 }
1806 break;
1807 }
1808 case 'g':
1809 {
1810 if (LocaleCompare("gamma",option+1) == 0)
1811 {
1812 /*
1813 Gamma image.
1814 */
1815 (void) SyncImageSettings(image_info,*image);
1816 if (*option == '+')
cristyf2f27272009-12-17 14:48:46 +00001817 (*image)->gamma=StringToDouble(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00001818 else
1819 {
1820 if (strchr(argv[i+1],',') != (char *) NULL)
1821 (void) GammaImage(*image,argv[i+1]);
1822 else
cristya5447be2010-01-11 00:20:51 +00001823 (void) GammaImageChannel(*image,channel,
1824 StringToDouble(argv[i+1]));
cristy3ed852e2009-09-05 21:47:34 +00001825 InheritException(exception,&(*image)->exception);
1826 }
1827 break;
1828 }
1829 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
1830 (LocaleCompare("gaussian",option+1) == 0))
1831 {
1832 Image
1833 *gaussian_image;
1834
1835 /*
1836 Gaussian blur image.
1837 */
1838 (void) SyncImageSettings(image_info,*image);
1839 flags=ParseGeometry(argv[i+1],&geometry_info);
1840 if ((flags & SigmaValue) == 0)
1841 geometry_info.sigma=1.0;
1842 gaussian_image=GaussianBlurImageChannel(*image,channel,
1843 geometry_info.rho,geometry_info.sigma,exception);
1844 if (gaussian_image == (Image *) NULL)
1845 break;
1846 *image=DestroyImage(*image);
1847 *image=gaussian_image;
1848 break;
1849 }
1850 if (LocaleCompare("geometry",option+1) == 0)
1851 {
1852 (void) SyncImageSettings(image_info,*image);
1853 if (*option == '+')
1854 {
1855 if ((*image)->geometry != (char *) NULL)
1856 (*image)->geometry=DestroyString((*image)->geometry);
1857 break;
1858 }
1859 flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
1860 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
1861 (void) CloneString(&(*image)->geometry,argv[i+1]);
1862 else
1863 {
1864 Image
1865 *zoom_image;
1866
1867 /*
1868 Resize image.
1869 */
1870 zoom_image=ZoomImage(*image,geometry.width,geometry.height,
1871 exception);
1872 if (zoom_image == (Image *) NULL)
1873 break;
1874 *image=DestroyImage(*image);
1875 *image=zoom_image;
1876 }
1877 break;
1878 }
1879 if (LocaleCompare("gravity",option+1) == 0)
1880 {
1881 if (*option == '+')
1882 {
1883 draw_info->gravity=UndefinedGravity;
1884 break;
1885 }
1886 draw_info->gravity=(GravityType) ParseMagickOption(
1887 MagickGravityOptions,MagickFalse,argv[i+1]);
1888 break;
1889 }
1890 break;
1891 }
1892 case 'h':
1893 {
1894 if (LocaleCompare("highlight-color",option+1) == 0)
1895 {
1896 (void) SetImageArtifact(*image,option+1,argv[i+1]);
1897 break;
1898 }
1899 break;
1900 }
1901 case 'i':
1902 {
1903 if (LocaleCompare("identify",option+1) == 0)
1904 {
1905 char
1906 *text;
1907
1908 (void) SyncImageSettings(image_info,*image);
1909 if (format == (char *) NULL)
1910 {
1911 (void) IdentifyImage(*image,stdout,image_info->verbose);
1912 InheritException(exception,&(*image)->exception);
1913 break;
1914 }
1915 text=InterpretImageProperties(image_info,*image,format);
1916 InheritException(exception,&(*image)->exception);
1917 if (text == (char *) NULL)
1918 break;
1919 (void) fputs(text,stdout);
1920 (void) fputc('\n',stdout);
1921 text=DestroyString(text);
1922 break;
1923 }
1924 if (LocaleCompare("implode",option+1) == 0)
1925 {
1926 Image
1927 *implode_image;
1928
1929 /*
1930 Implode image.
1931 */
1932 (void) SyncImageSettings(image_info,*image);
1933 (void) ParseGeometry(argv[i+1],&geometry_info);
1934 implode_image=ImplodeImage(*image,geometry_info.rho,exception);
1935 if (implode_image == (Image *) NULL)
1936 break;
1937 *image=DestroyImage(*image);
1938 *image=implode_image;
1939 break;
1940 }
cristyb32b90a2009-09-07 21:45:48 +00001941 if (LocaleCompare("interline-spacing",option+1) == 0)
1942 {
1943 if (*option == '+')
1944 (void) ParseGeometry("0",&geometry_info);
1945 else
1946 (void) ParseGeometry(argv[i+1],&geometry_info);
1947 draw_info->interline_spacing=geometry_info.rho;
1948 break;
1949 }
cristy3ed852e2009-09-05 21:47:34 +00001950 if (LocaleCompare("interword-spacing",option+1) == 0)
1951 {
1952 if (*option == '+')
1953 (void) ParseGeometry("0",&geometry_info);
1954 else
1955 (void) ParseGeometry(argv[i+1],&geometry_info);
1956 draw_info->interword_spacing=geometry_info.rho;
1957 break;
1958 }
1959 break;
1960 }
1961 case 'k':
1962 {
1963 if (LocaleCompare("kerning",option+1) == 0)
1964 {
1965 if (*option == '+')
1966 (void) ParseGeometry("0",&geometry_info);
1967 else
1968 (void) ParseGeometry(argv[i+1],&geometry_info);
1969 draw_info->kerning=geometry_info.rho;
1970 break;
1971 }
1972 break;
1973 }
1974 case 'l':
1975 {
1976 if (LocaleCompare("lat",option+1) == 0)
1977 {
1978 Image
1979 *threshold_image;
1980
1981 /*
1982 Local adaptive threshold image.
1983 */
1984 (void) SyncImageSettings(image_info,*image);
1985 flags=ParseGeometry(argv[i+1],&geometry_info);
1986 if ((flags & PercentValue) != 0)
1987 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
1988 threshold_image=AdaptiveThresholdImage(*image,(unsigned long)
1989 geometry_info.rho,(unsigned long) geometry_info.sigma,
1990 (long) geometry_info.xi,exception);
1991 if (threshold_image == (Image *) NULL)
1992 break;
1993 *image=DestroyImage(*image);
1994 *image=threshold_image;
1995 break;
1996 }
1997 if (LocaleCompare("level",option+1) == 0)
1998 {
cristy3ed852e2009-09-05 21:47:34 +00001999 MagickRealType
2000 black_point,
2001 gamma,
2002 white_point;
2003
2004 MagickStatusType
2005 flags;
2006
2007 /*
2008 Parse levels.
2009 */
2010 (void) SyncImageSettings(image_info,*image);
2011 flags=ParseGeometry(argv[i+1],&geometry_info);
2012 black_point=geometry_info.rho;
2013 white_point=(MagickRealType) QuantumRange;
2014 if ((flags & SigmaValue) != 0)
2015 white_point=geometry_info.sigma;
2016 gamma=1.0;
2017 if ((flags & XiValue) != 0)
2018 gamma=geometry_info.xi;
2019 if ((flags & PercentValue) != 0)
2020 {
2021 black_point*=(MagickRealType) (QuantumRange/100.0);
2022 white_point*=(MagickRealType) (QuantumRange/100.0);
2023 }
2024 if ((flags & SigmaValue) == 0)
2025 white_point=(MagickRealType) QuantumRange-black_point;
2026 if ((*option == '+') || ((flags & AspectValue) != 0))
2027 (void) LevelizeImageChannel(*image,channel,black_point,
2028 white_point,gamma);
2029 else
2030 (void) LevelImageChannel(*image,channel,black_point,white_point,
2031 gamma);
2032 InheritException(exception,&(*image)->exception);
2033 break;
2034 }
2035 if (LocaleCompare("level-colors",option+1) == 0)
2036 {
2037 char
2038 token[MaxTextExtent];
2039
2040 const char
2041 *p;
2042
2043 MagickPixelPacket
2044 black_point,
2045 white_point;
2046
2047 p=(const char *) argv[i+1];
2048 GetMagickToken(p,&p,token); /* get black point color */
cristyee0f8d72009-09-19 00:58:29 +00002049 if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
cristy3ed852e2009-09-05 21:47:34 +00002050 (void) QueryMagickColor(token,&black_point,exception);
2051 else
cristyee0f8d72009-09-19 00:58:29 +00002052 (void) QueryMagickColor("#000000",&black_point,exception);
cristy3ed852e2009-09-05 21:47:34 +00002053 if (isalpha((int) token[0]) || (token[0] == '#'))
2054 GetMagickToken(p,&p,token);
cristyee0f8d72009-09-19 00:58:29 +00002055 if (*token == '\0')
cristy3ed852e2009-09-05 21:47:34 +00002056 white_point=black_point; /* set everything to that color */
2057 else
2058 {
2059 /*
2060 Get white point color.
2061 */
cristyee0f8d72009-09-19 00:58:29 +00002062 if ((isalpha((int) *token) == 0) && ((*token == '#') == 0))
cristy3ed852e2009-09-05 21:47:34 +00002063 GetMagickToken(p,&p,token);
cristyee0f8d72009-09-19 00:58:29 +00002064 if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
cristy3ed852e2009-09-05 21:47:34 +00002065 (void) QueryMagickColor(token,&white_point,exception);
2066 else
cristyee0f8d72009-09-19 00:58:29 +00002067 (void) QueryMagickColor("#ffffff",&white_point,exception);
cristy3ed852e2009-09-05 21:47:34 +00002068 }
cristy74fe8f12009-10-03 19:09:01 +00002069 (void) LevelColorsImageChannel(*image,channel,&black_point,
2070 &white_point,*option == '+' ? MagickTrue : MagickFalse);
cristy3ed852e2009-09-05 21:47:34 +00002071 break;
2072 }
2073 if (LocaleCompare("linear-stretch",option+1) == 0)
2074 {
2075 double
2076 black_point,
2077 white_point;
2078
cristy3ed852e2009-09-05 21:47:34 +00002079 MagickStatusType
2080 flags;
2081
2082 (void) SyncImageSettings(image_info,*image);
2083 flags=ParseGeometry(argv[i+1],&geometry_info);
2084 black_point=geometry_info.rho;
2085 white_point=(MagickRealType) (*image)->columns*(*image)->rows;
2086 if ((flags & SigmaValue) != 0)
2087 white_point=geometry_info.sigma;
2088 if ((flags & PercentValue) != 0)
2089 {
2090 black_point*=(double) (*image)->columns*(*image)->rows/100.0;
2091 white_point*=(double) (*image)->columns*(*image)->rows/100.0;
2092 }
2093 if ((flags & SigmaValue) == 0)
2094 white_point=(MagickRealType) (*image)->columns*(*image)->rows-
2095 black_point;
2096 (void) LinearStretchImage(*image,black_point,white_point);
2097 InheritException(exception,&(*image)->exception);
2098 break;
2099 }
2100 if (LocaleCompare("linewidth",option+1) == 0)
2101 {
cristyf2f27272009-12-17 14:48:46 +00002102 draw_info->stroke_width=StringToDouble(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00002103 break;
2104 }
2105 if (LocaleCompare("liquid-rescale",option+1) == 0)
2106 {
2107 Image
2108 *resize_image;
2109
2110 /*
2111 Liquid rescale image.
2112 */
2113 (void) SyncImageSettings(image_info,*image);
2114 flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2115 if ((flags & XValue) == 0)
2116 geometry.x=1;
2117 if ((flags & YValue) == 0)
2118 geometry.y=0;
2119 resize_image=LiquidRescaleImage(*image,geometry.width,
2120 geometry.height,1.0*geometry.x,1.0*geometry.y,exception);
2121 if (resize_image == (Image *) NULL)
2122 break;
2123 *image=DestroyImage(*image);
2124 *image=resize_image;
2125 break;
2126 }
2127 if (LocaleCompare("lowlight-color",option+1) == 0)
2128 {
2129 (void) SetImageArtifact(*image,option+1,argv[i+1]);
2130 break;
2131 }
2132 break;
2133 }
2134 case 'm':
2135 {
2136 if (LocaleCompare("map",option+1) == 0)
2137 {
2138 Image
2139 *remap_image;
2140
2141 /*
2142 Transform image colors to match this set of colors.
2143 */
2144 (void) SyncImageSettings(image_info,*image);
2145 if (*option == '+')
2146 break;
2147 remap_image=GetImageCache(image_info,argv[i+1],exception);
2148 if (remap_image == (Image *) NULL)
2149 break;
2150 (void) RemapImage(quantize_info,*image,remap_image);
2151 InheritException(exception,&(*image)->exception);
2152 remap_image=DestroyImage(remap_image);
2153 break;
2154 }
2155 if (LocaleCompare("mask",option+1) == 0)
2156 {
2157 Image
2158 *mask;
2159
2160 (void) SyncImageSettings(image_info,*image);
2161 if (*option == '+')
2162 {
2163 /*
2164 Remove a mask.
2165 */
2166 (void) SetImageMask(*image,(Image *) NULL);
2167 InheritException(exception,&(*image)->exception);
2168 break;
2169 }
2170 /*
2171 Set the image mask.
2172 */
2173 mask=GetImageCache(image_info,argv[i+1],exception);
2174 if (mask == (Image *) NULL)
2175 break;
2176 (void) SetImageMask(*image,mask);
2177 mask=DestroyImage(mask);
2178 InheritException(exception,&(*image)->exception);
2179 break;
2180 }
2181 if (LocaleCompare("matte",option+1) == 0)
2182 {
2183 (void) SetImageAlphaChannel(*image,(*option == '-') ?
2184 SetAlphaChannel : DeactivateAlphaChannel );
2185 InheritException(exception,&(*image)->exception);
2186 break;
2187 }
2188 if (LocaleCompare("median",option+1) == 0)
2189 {
2190 Image
2191 *median_image;
2192
2193 /*
2194 Median filter image.
2195 */
2196 (void) SyncImageSettings(image_info,*image);
2197 (void) ParseGeometry(argv[i+1],&geometry_info);
2198 median_image=MedianFilterImage(*image,geometry_info.rho,exception);
2199 if (median_image == (Image *) NULL)
2200 break;
2201 *image=DestroyImage(*image);
2202 *image=median_image;
2203 break;
2204 }
2205 if (LocaleCompare("modulate",option+1) == 0)
2206 {
2207 (void) SyncImageSettings(image_info,*image);
2208 (void) ModulateImage(*image,argv[i+1]);
2209 InheritException(exception,&(*image)->exception);
2210 break;
2211 }
2212 if (LocaleCompare("monitor",option+1) == 0)
2213 {
cristy7d34ef22010-03-25 01:11:22 +00002214 if (*option == '+')
2215 {
2216 (void) SetImageProgressMonitor(*image,
2217 (MagickProgressMonitor) NULL,(void *) NULL);
2218 break;
2219 }
cristy3ed852e2009-09-05 21:47:34 +00002220 (void) SetImageProgressMonitor(*image,MonitorProgress,
2221 (void *) NULL);
2222 break;
2223 }
2224 if (LocaleCompare("monochrome",option+1) == 0)
2225 {
2226 (void) SyncImageSettings(image_info,*image);
2227 (void) SetImageType(*image,BilevelType);
2228 InheritException(exception,&(*image)->exception);
2229 break;
2230 }
anthony29188a82010-01-22 10:12:34 +00002231 if (LocaleCompare("morphology",option+1) == 0)
2232 {
2233 MorphologyMethod
2234 method;
2235
2236 KernelInfo
2237 *kernel;
2238
2239 char
2240 token[MaxTextExtent];
2241
2242 const char
2243 *p;
2244
cristyef656912010-03-05 19:54:59 +00002245 long
anthony29188a82010-01-22 10:12:34 +00002246 iterations;
2247
2248 Image
2249 *morphology_image;
2250 /*
2251 Morphological Image Operation
2252 */
2253 (void) SyncImageSettings(image_info,*image);
2254 p=argv[i+1];
2255 GetMagickToken(p,&p,token);
2256 method=(MorphologyMethod) ParseMagickOption(MagickMorphologyOptions,
2257 MagickFalse,token);
cristyef656912010-03-05 19:54:59 +00002258 iterations=1L;
anthony29188a82010-01-22 10:12:34 +00002259 GetMagickToken(p,&p,token);
cristyef656912010-03-05 19:54:59 +00002260 if ((*p == ':') || (*p == ','))
anthony29188a82010-01-22 10:12:34 +00002261 GetMagickToken(p,&p,token);
cristyef656912010-03-05 19:54:59 +00002262 if ((*p != '\0'))
2263 iterations=StringToLong(p);
anthony29188a82010-01-22 10:12:34 +00002264 kernel=AcquireKernelInfo(argv[i+2]);
2265 if (kernel == (KernelInfo *) NULL)
2266 ThrowWandFatalException(ResourceLimitFatalError,
2267 "MemoryAllocationFailed",(*image)->filename);
anthony930be612010-02-08 04:26:15 +00002268 if ( GetImageArtifact(*image,"showkernel") != (const char *) NULL)
2269 ShowKernelInfo(kernel); /* display the kernel to stderr */
anthony29188a82010-01-22 10:12:34 +00002270 morphology_image=MorphologyImageChannel(*image,channel,method,
cristy02d5b4f2010-02-01 01:08:27 +00002271 iterations,kernel,exception);
anthony83ba99b2010-01-24 08:48:15 +00002272 kernel=DestroyKernelInfo(kernel);
anthony29188a82010-01-22 10:12:34 +00002273 if (morphology_image == (Image *) NULL)
2274 break;
2275 *image=DestroyImage(*image);
2276 *image=morphology_image;
2277 break;
2278 }
cristy3ed852e2009-09-05 21:47:34 +00002279 if (LocaleCompare("motion-blur",option+1) == 0)
2280 {
2281 Image
2282 *blur_image;
2283
2284 /*
2285 Motion blur image.
2286 */
2287 (void) SyncImageSettings(image_info,*image);
2288 flags=ParseGeometry(argv[i+1],&geometry_info);
2289 if ((flags & SigmaValue) == 0)
2290 geometry_info.sigma=1.0;
2291 blur_image=MotionBlurImageChannel(*image,channel,geometry_info.rho,
2292 geometry_info.sigma,geometry_info.xi,exception);
2293 if (blur_image == (Image *) NULL)
2294 break;
2295 *image=DestroyImage(*image);
2296 *image=blur_image;
2297 break;
2298 }
2299 break;
2300 }
2301 case 'n':
2302 {
2303 if (LocaleCompare("negate",option+1) == 0)
2304 {
2305 (void) SyncImageSettings(image_info,*image);
2306 (void) NegateImageChannel(*image,channel,*option == '+' ?
2307 MagickTrue : MagickFalse);
2308 InheritException(exception,&(*image)->exception);
2309 break;
2310 }
2311 if (LocaleCompare("noise",option+1) == 0)
2312 {
2313 Image
2314 *noisy_image;
2315
2316 (void) SyncImageSettings(image_info,*image);
2317 if (*option == '-')
2318 {
2319 (void) ParseGeometry(argv[i+1],&geometry_info);
2320 noisy_image=ReduceNoiseImage(*image,geometry_info.rho,
2321 exception);
2322 }
2323 else
2324 {
2325 NoiseType
2326 noise;
2327
2328 noise=(NoiseType) ParseMagickOption(MagickNoiseOptions,
2329 MagickFalse,argv[i+1]);
2330 noisy_image=AddNoiseImageChannel(*image,channel,noise,
2331 exception);
2332 }
2333 if (noisy_image == (Image *) NULL)
2334 break;
2335 *image=DestroyImage(*image);
2336 *image=noisy_image;
2337 break;
2338 }
2339 if (LocaleCompare("normalize",option+1) == 0)
2340 {
2341 (void) SyncImageSettings(image_info,*image);
2342 (void) NormalizeImageChannel(*image,channel);
2343 InheritException(exception,&(*image)->exception);
2344 break;
2345 }
2346 break;
2347 }
2348 case 'o':
2349 {
2350 if (LocaleCompare("opaque",option+1) == 0)
2351 {
2352 MagickPixelPacket
2353 target;
2354
2355 (void) SyncImageSettings(image_info,*image);
2356 (void) QueryMagickColor(argv[i+1],&target,exception);
2357 (void) OpaquePaintImageChannel(*image,channel,&target,&fill,
2358 *option == '-' ? MagickFalse : MagickTrue);
2359 break;
2360 }
2361 if (LocaleCompare("ordered-dither",option+1) == 0)
2362 {
2363 (void) SyncImageSettings(image_info,*image);
2364 (void) OrderedPosterizeImageChannel(*image,channel,argv[i+1],
2365 exception);
2366 break;
2367 }
2368 break;
2369 }
2370 case 'p':
2371 {
2372 if (LocaleCompare("paint",option+1) == 0)
2373 {
2374 Image
2375 *paint_image;
2376
2377 /*
2378 Oil paint image.
2379 */
2380 (void) SyncImageSettings(image_info,*image);
2381 (void) ParseGeometry(argv[i+1],&geometry_info);
2382 paint_image=OilPaintImage(*image,geometry_info.rho,exception);
2383 if (paint_image == (Image *) NULL)
2384 break;
2385 *image=DestroyImage(*image);
2386 *image=paint_image;
2387 break;
2388 }
2389 if (LocaleCompare("pen",option+1) == 0)
2390 {
2391 if (*option == '+')
2392 {
2393 (void) QueryColorDatabase("none",&draw_info->fill,exception);
2394 break;
2395 }
2396 (void) QueryColorDatabase(argv[i+1],&draw_info->fill,exception);
2397 break;
2398 }
2399 if (LocaleCompare("pointsize",option+1) == 0)
2400 {
2401 if (*option == '+')
2402 (void) ParseGeometry("12",&geometry_info);
2403 else
2404 (void) ParseGeometry(argv[i+1],&geometry_info);
2405 draw_info->pointsize=geometry_info.rho;
2406 break;
2407 }
2408 if (LocaleCompare("polaroid",option+1) == 0)
2409 {
2410 double
2411 angle;
2412
2413 Image
2414 *polaroid_image;
2415
2416 RandomInfo
2417 *random_info;
2418
2419 /*
2420 Simulate a Polaroid picture.
2421 */
2422 (void) SyncImageSettings(image_info,*image);
2423 random_info=AcquireRandomInfo();
2424 angle=22.5*(GetPseudoRandomValue(random_info)-0.5);
2425 random_info=DestroyRandomInfo(random_info);
2426 if (*option == '-')
2427 {
2428 SetGeometryInfo(&geometry_info);
2429 flags=ParseGeometry(argv[i+1],&geometry_info);
2430 angle=geometry_info.rho;
2431 }
2432 polaroid_image=PolaroidImage(*image,draw_info,angle,exception);
2433 if (polaroid_image == (Image *) NULL)
2434 break;
2435 *image=DestroyImage(*image);
2436 *image=polaroid_image;
2437 break;
2438 }
2439 if (LocaleCompare("posterize",option+1) == 0)
2440 {
2441 /*
2442 Posterize image.
2443 */
2444 (void) SyncImageSettings(image_info,*image);
cristye27293e2009-12-18 02:53:20 +00002445 (void) PosterizeImage(*image,StringToUnsignedLong(argv[i+1]),
cristy3ed852e2009-09-05 21:47:34 +00002446 quantize_info->dither);
2447 InheritException(exception,&(*image)->exception);
2448 break;
2449 }
2450 if (LocaleCompare("preview",option+1) == 0)
2451 {
2452 Image
2453 *preview_image;
2454
2455 PreviewType
2456 preview_type;
2457
2458 /*
2459 Preview image.
2460 */
2461 (void) SyncImageSettings(image_info,*image);
2462 if (*option == '+')
2463 preview_type=UndefinedPreview;
2464 else
2465 preview_type=(PreviewType) ParseMagickOption(MagickPreviewOptions,
2466 MagickFalse,argv[i+1]);
2467 preview_image=PreviewImage(*image,preview_type,exception);
2468 if (preview_image == (Image *) NULL)
2469 break;
2470 *image=DestroyImage(*image);
2471 *image=preview_image;
2472 break;
2473 }
2474 if (LocaleCompare("profile",option+1) == 0)
2475 {
2476 const char
2477 *name;
2478
2479 const StringInfo
2480 *profile;
2481
2482 Image
2483 *profile_image;
2484
2485 ImageInfo
2486 *profile_info;
2487
2488 (void) SyncImageSettings(image_info,*image);
2489 if (*option == '+')
2490 {
2491 /*
2492 Remove a profile from the image.
2493 */
2494 (void) ProfileImage(*image,argv[i+1],(const unsigned char *)
2495 NULL,0,MagickTrue);
2496 InheritException(exception,&(*image)->exception);
2497 break;
2498 }
2499 /*
2500 Associate a profile with the image.
2501 */
2502 profile_info=CloneImageInfo(image_info);
2503 profile=GetImageProfile(*image,"iptc");
2504 if (profile != (StringInfo *) NULL)
2505 profile_info->profile=(void *) CloneStringInfo(profile);
2506 profile_image=GetImageCache(profile_info,argv[i+1],exception);
2507 profile_info=DestroyImageInfo(profile_info);
2508 if (profile_image == (Image *) NULL)
2509 {
2510 char
2511 name[MaxTextExtent],
2512 filename[MaxTextExtent];
2513
2514 register char
2515 *p;
2516
2517 StringInfo
2518 *profile;
2519
2520 (void) CopyMagickString(filename,argv[i+1],MaxTextExtent);
2521 (void) CopyMagickString(name,argv[i+1],MaxTextExtent);
2522 for (p=filename; *p != '\0'; p++)
2523 if ((*p == ':') && (IsPathDirectory(argv[i+1]) < 0) &&
2524 (IsPathAccessible(argv[i+1]) == MagickFalse))
2525 {
2526 register char
2527 *q;
2528
2529 /*
2530 Look for profile name (e.g. name:profile).
2531 */
2532 (void) CopyMagickString(name,filename,(size_t)
2533 (p-filename+1));
2534 for (q=filename; *q != '\0'; q++)
2535 *q=(*++p);
2536 break;
2537 }
2538 profile=FileToStringInfo(filename,~0UL,exception);
2539 if (profile != (StringInfo *) NULL)
2540 {
2541 (void) ProfileImage(*image,name,GetStringInfoDatum(profile),
2542 (unsigned long) GetStringInfoLength(profile),MagickFalse);
2543 profile=DestroyStringInfo(profile);
2544 }
2545 break;
2546 }
2547 ResetImageProfileIterator(profile_image);
2548 name=GetNextImageProfile(profile_image);
2549 while (name != (const char *) NULL)
2550 {
2551 profile=GetImageProfile(profile_image,name);
2552 if (profile != (StringInfo *) NULL)
2553 (void) ProfileImage(*image,name,GetStringInfoDatum(profile),
2554 (unsigned long) GetStringInfoLength(profile),MagickFalse);
2555 name=GetNextImageProfile(profile_image);
2556 }
2557 profile_image=DestroyImage(profile_image);
2558 break;
2559 }
2560 break;
2561 }
2562 case 'q':
2563 {
2564 if (LocaleCompare("quantize",option+1) == 0)
2565 {
2566 if (*option == '+')
2567 {
2568 quantize_info->colorspace=UndefinedColorspace;
2569 break;
2570 }
2571 quantize_info->colorspace=(ColorspaceType) ParseMagickOption(
2572 MagickColorspaceOptions,MagickFalse,argv[i+1]);
2573 break;
2574 }
2575 break;
2576 }
2577 case 'r':
2578 {
2579 if (LocaleCompare("radial-blur",option+1) == 0)
2580 {
2581 Image
2582 *blur_image;
2583
2584 /*
2585 Radial blur image.
2586 */
2587 (void) SyncImageSettings(image_info,*image);
cristya5447be2010-01-11 00:20:51 +00002588 blur_image=RadialBlurImageChannel(*image,channel,
2589 StringToDouble(argv[i+1]),exception);
cristy3ed852e2009-09-05 21:47:34 +00002590 if (blur_image == (Image *) NULL)
2591 break;
2592 *image=DestroyImage(*image);
2593 *image=blur_image;
2594 break;
2595 }
2596 if (LocaleCompare("raise",option+1) == 0)
2597 {
2598 /*
2599 Surround image with a raise of solid color.
2600 */
2601 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2602 if ((flags & SigmaValue) == 0)
2603 geometry.height=geometry.width;
2604 (void) RaiseImage(*image,&geometry,*option == '-' ? MagickTrue :
2605 MagickFalse);
2606 InheritException(exception,&(*image)->exception);
2607 break;
2608 }
2609 if (LocaleCompare("random-threshold",option+1) == 0)
2610 {
2611 /*
2612 Threshold image.
2613 */
2614 (void) SyncImageSettings(image_info,*image);
2615 (void) RandomThresholdImageChannel(*image,channel,argv[i+1],
2616 exception);
2617 break;
2618 }
2619 if (LocaleCompare("recolor",option+1) == 0)
2620 {
2621 char
2622 token[MaxTextExtent];
2623
2624 const char
2625 *p;
2626
2627 double
2628 *color_matrix;
2629
2630 Image
2631 *recolor_image;
2632
2633 register long
2634 x;
2635
2636 unsigned long
2637 order;
2638
2639 /*
2640 Transform color image.
2641 */
2642 (void) SyncImageSettings(image_info,*image);
2643 p=argv[i+1];
2644 for (x=0; *p != '\0'; x++)
2645 {
2646 GetMagickToken(p,&p,token);
2647 if (*token == ',')
2648 GetMagickToken(p,&p,token);
2649 }
2650 order=(unsigned long) sqrt((double) x+1.0);
2651 color_matrix=(double *) AcquireQuantumMemory(order,order*
2652 sizeof(*color_matrix));
2653 if (color_matrix == (double *) NULL)
2654 ThrowWandFatalException(ResourceLimitFatalError,
2655 "MemoryAllocationFailed",(*image)->filename);
2656 p=argv[i+1];
2657 for (x=0; (x < (long) (order*order)) && (*p != '\0'); x++)
2658 {
2659 GetMagickToken(p,&p,token);
2660 if (*token == ',')
2661 GetMagickToken(p,&p,token);
cristyf2f27272009-12-17 14:48:46 +00002662 color_matrix[x]=StringToDouble(token);
cristy3ed852e2009-09-05 21:47:34 +00002663 }
2664 for ( ; x < (long) (order*order); x++)
2665 color_matrix[x]=0.0;
2666 recolor_image=RecolorImage(*image,order,color_matrix,exception);
2667 color_matrix=(double *) RelinquishMagickMemory(color_matrix);
2668 if (recolor_image == (Image *) NULL)
2669 break;
2670 *image=DestroyImage(*image);
2671 *image=recolor_image;
2672 break;
2673 }
2674 if (LocaleCompare("region",option+1) == 0)
2675 {
2676 Image
2677 *crop_image;
2678
2679 (void) SyncImageSettings(image_info,*image);
2680 if (region_image != (Image *) NULL)
2681 {
2682 /*
2683 Composite region.
2684 */
2685 (void) CompositeImage(region_image,(*image)->matte !=
2686 MagickFalse ? OverCompositeOp : CopyCompositeOp,*image,
2687 region_geometry.x,region_geometry.y);
2688 InheritException(exception,&region_image->exception);
2689 *image=DestroyImage(*image);
2690 *image=region_image;
2691 }
2692 if (*option == '+')
2693 {
2694 if (region_image != (Image *) NULL)
2695 region_image=DestroyImage(region_image);
2696 break;
2697 }
2698 /*
2699 Apply transformations to a selected region of the image.
2700 */
2701 (void) ParseGravityGeometry(*image,argv[i+1],&region_geometry,
2702 exception);
2703 crop_image=CropImage(*image,&region_geometry,exception);
2704 if (crop_image == (Image *) NULL)
2705 break;
2706 region_image=(*image);
2707 *image=crop_image;
2708 break;
2709 }
2710 if (LocaleCompare("render",option+1) == 0)
2711 {
2712 (void) SyncImageSettings(image_info,*image);
2713 draw_info->render=(*option == '+') ? MagickTrue : MagickFalse;
2714 break;
2715 }
2716 if (LocaleCompare("remap",option+1) == 0)
2717 {
2718 Image
2719 *remap_image;
2720
2721 /*
2722 Transform image colors to match this set of colors.
2723 */
2724 (void) SyncImageSettings(image_info,*image);
2725 if (*option == '+')
2726 break;
2727 remap_image=GetImageCache(image_info,argv[i+1],exception);
2728 if (remap_image == (Image *) NULL)
2729 break;
2730 (void) RemapImage(quantize_info,*image,remap_image);
2731 InheritException(exception,&(*image)->exception);
2732 remap_image=DestroyImage(remap_image);
2733 break;
2734 }
2735 if (LocaleCompare("repage",option+1) == 0)
2736 {
2737 if (*option == '+')
2738 {
2739 (void) ParseAbsoluteGeometry("0x0+0+0",&(*image)->page);
2740 break;
2741 }
2742 (void) ResetImagePage(*image,argv[i+1]);
2743 InheritException(exception,&(*image)->exception);
2744 break;
2745 }
2746 if (LocaleCompare("resample",option+1) == 0)
2747 {
2748 Image
2749 *resample_image;
2750
2751 /*
2752 Resample image.
2753 */
2754 (void) SyncImageSettings(image_info,*image);
2755 flags=ParseGeometry(argv[i+1],&geometry_info);
2756 if ((flags & SigmaValue) == 0)
2757 geometry_info.sigma=geometry_info.rho;
2758 resample_image=ResampleImage(*image,geometry_info.rho,
2759 geometry_info.sigma,(*image)->filter,(*image)->blur,exception);
2760 if (resample_image == (Image *) NULL)
2761 break;
2762 *image=DestroyImage(*image);
2763 *image=resample_image;
2764 break;
2765 }
2766 if (LocaleCompare("resize",option+1) == 0)
2767 {
2768 Image
2769 *resize_image;
2770
2771 /*
2772 Resize image.
2773 */
2774 (void) SyncImageSettings(image_info,*image);
2775 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2776 resize_image=ResizeImage(*image,geometry.width,geometry.height,
2777 (*image)->filter,(*image)->blur,exception);
2778 if (resize_image == (Image *) NULL)
2779 break;
2780 *image=DestroyImage(*image);
2781 *image=resize_image;
2782 break;
2783 }
2784 if (LocaleNCompare("respect-parentheses",option+1,17) == 0)
2785 {
2786 respect_parenthesis=(*option == '-') ? MagickTrue : MagickFalse;
2787 break;
2788 }
2789 if (LocaleCompare("roll",option+1) == 0)
2790 {
2791 Image
2792 *roll_image;
2793
2794 /*
2795 Roll image.
2796 */
2797 (void) SyncImageSettings(image_info,*image);
2798 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2799 roll_image=RollImage(*image,geometry.x,geometry.y,exception);
2800 if (roll_image == (Image *) NULL)
2801 break;
2802 *image=DestroyImage(*image);
2803 *image=roll_image;
2804 break;
2805 }
2806 if (LocaleCompare("rotate",option+1) == 0)
2807 {
2808 char
2809 *geometry;
2810
2811 Image
2812 *rotate_image;
2813
2814 /*
2815 Check for conditional image rotation.
2816 */
2817 (void) SyncImageSettings(image_info,*image);
2818 if (strchr(argv[i+1],'>') != (char *) NULL)
2819 if ((*image)->columns <= (*image)->rows)
2820 break;
2821 if (strchr(argv[i+1],'<') != (char *) NULL)
2822 if ((*image)->columns >= (*image)->rows)
2823 break;
2824 /*
2825 Rotate image.
2826 */
2827 geometry=ConstantString(argv[i+1]);
2828 (void) SubstituteString(&geometry,">","");
2829 (void) SubstituteString(&geometry,"<","");
2830 (void) ParseGeometry(geometry,&geometry_info);
2831 geometry=DestroyString(geometry);
2832 rotate_image=RotateImage(*image,geometry_info.rho,exception);
2833 if (rotate_image == (Image *) NULL)
2834 break;
2835 *image=DestroyImage(*image);
2836 *image=rotate_image;
2837 break;
2838 }
2839 break;
2840 }
2841 case 's':
2842 {
2843 if (LocaleCompare("sample",option+1) == 0)
2844 {
2845 Image
2846 *sample_image;
2847
2848 /*
2849 Sample image with pixel replication.
2850 */
2851 (void) SyncImageSettings(image_info,*image);
2852 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2853 sample_image=SampleImage(*image,geometry.width,geometry.height,
2854 exception);
2855 if (sample_image == (Image *) NULL)
2856 break;
2857 *image=DestroyImage(*image);
2858 *image=sample_image;
2859 break;
2860 }
2861 if (LocaleCompare("scale",option+1) == 0)
2862 {
2863 Image
2864 *scale_image;
2865
2866 /*
2867 Resize image.
2868 */
2869 (void) SyncImageSettings(image_info,*image);
2870 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2871 scale_image=ScaleImage(*image,geometry.width,geometry.height,
2872 exception);
2873 if (scale_image == (Image *) NULL)
2874 break;
2875 *image=DestroyImage(*image);
2876 *image=scale_image;
2877 break;
2878 }
2879 if (LocaleCompare("selective-blur",option+1) == 0)
2880 {
2881 Image
2882 *blur_image;
2883
2884 /*
2885 Selectively blur pixels within a contrast threshold.
2886 */
2887 (void) SyncImageSettings(image_info,*image);
2888 flags=ParseGeometry(argv[i+1],&geometry_info);
2889 if ((flags & PercentValue) != 0)
2890 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
2891 blur_image=SelectiveBlurImageChannel(*image,channel,
2892 geometry_info.rho,geometry_info.sigma,geometry_info.xi,exception);
2893 if (blur_image == (Image *) NULL)
2894 break;
2895 *image=DestroyImage(*image);
2896 *image=blur_image;
2897 break;
2898 }
2899 if (LocaleCompare("separate",option+1) == 0)
2900 {
2901 Image
2902 *separate_images;
2903
2904 /*
2905 Break channels into separate images.
2906 */
2907 (void) SyncImageSettings(image_info,*image);
2908 separate_images=SeparateImages(*image,channel,exception);
2909 if (separate_images == (Image *) NULL)
2910 break;
2911 *image=DestroyImage(*image);
2912 *image=separate_images;
2913 break;
2914 }
2915 if (LocaleCompare("sepia-tone",option+1) == 0)
2916 {
2917 double
2918 threshold;
2919
2920 Image
2921 *sepia_image;
2922
2923 /*
2924 Sepia-tone image.
2925 */
2926 (void) SyncImageSettings(image_info,*image);
cristyf2f27272009-12-17 14:48:46 +00002927 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
cristy3ed852e2009-09-05 21:47:34 +00002928 sepia_image=SepiaToneImage(*image,threshold,exception);
2929 if (sepia_image == (Image *) NULL)
2930 break;
2931 *image=DestroyImage(*image);
2932 *image=sepia_image;
2933 break;
2934 }
2935 if (LocaleCompare("segment",option+1) == 0)
2936 {
2937 /*
2938 Segment image.
2939 */
2940 (void) SyncImageSettings(image_info,*image);
2941 flags=ParseGeometry(argv[i+1],&geometry_info);
2942 if ((flags & SigmaValue) == 0)
2943 geometry_info.sigma=1.0;
2944 (void) SegmentImage(*image,(*image)->colorspace,image_info->verbose,
2945 geometry_info.rho,geometry_info.sigma);
2946 InheritException(exception,&(*image)->exception);
2947 break;
2948 }
2949 if (LocaleCompare("set",option+1) == 0)
2950 {
2951 /*
2952 Set image option.
2953 */
2954 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2955 (void) DeleteImageRegistry(argv[i+1]+9);
2956 else
2957 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
2958 (void) DeleteImageOption(image_info,argv[i+1]+7);
2959 else
2960 (void) DeleteImageProperty(*image,argv[i+1]);
2961 if (*option == '-')
2962 {
2963 char
2964 *value;
2965
2966 value=InterpretImageProperties(image_info,*image,argv[i+2]);
2967 if (value != (char *) NULL)
2968 {
2969 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2970 (void) SetImageRegistry(StringRegistryType,argv[i+1]+9,
2971 value,exception);
2972 else
2973 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
2974 {
2975 (void) SetImageOption(image_info,argv[i+1]+7,value);
2976 (void) SetImageArtifact(*image,argv[i+1]+7,value);
2977 }
2978 else
2979 (void) SetImageProperty(*image,argv[i+1],value);
2980 value=DestroyString(value);
2981 }
2982 }
2983 break;
2984 }
2985 if (LocaleCompare("shade",option+1) == 0)
2986 {
2987 Image
2988 *shade_image;
2989
2990 /*
2991 Shade 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 shade_image=ShadeImage(*image,(*option == '-') ? MagickTrue :
2998 MagickFalse,geometry_info.rho,geometry_info.sigma,exception);
2999 if (shade_image == (Image *) NULL)
3000 break;
3001 *image=DestroyImage(*image);
3002 *image=shade_image;
3003 break;
3004 }
3005 if (LocaleCompare("shadow",option+1) == 0)
3006 {
3007 Image
3008 *shadow_image;
3009
3010 /*
3011 Shadow image.
3012 */
3013 (void) SyncImageSettings(image_info,*image);
3014 flags=ParseGeometry(argv[i+1],&geometry_info);
3015 if ((flags & SigmaValue) == 0)
3016 geometry_info.sigma=1.0;
3017 if ((flags & XiValue) == 0)
3018 geometry_info.xi=4.0;
3019 if ((flags & PsiValue) == 0)
3020 geometry_info.psi=4.0;
3021 shadow_image=ShadowImage(*image,geometry_info.rho,
cristy0534a6b2010-03-18 01:19:38 +00003022 geometry_info.sigma,(long) ceil(geometry_info.xi-0.5),(long)
3023 ceil(geometry_info.psi-0.5),exception);
cristy3ed852e2009-09-05 21:47:34 +00003024 if (shadow_image == (Image *) NULL)
3025 break;
3026 *image=DestroyImage(*image);
3027 *image=shadow_image;
3028 break;
3029 }
3030 if (LocaleCompare("sharpen",option+1) == 0)
3031 {
3032 Image
3033 *sharp_image;
3034
3035 /*
3036 Sharpen image.
3037 */
3038 (void) SyncImageSettings(image_info,*image);
3039 flags=ParseGeometry(argv[i+1],&geometry_info);
3040 if ((flags & SigmaValue) == 0)
3041 geometry_info.sigma=1.0;
3042 sharp_image=SharpenImageChannel(*image,channel,geometry_info.rho,
3043 geometry_info.sigma,exception);
3044 if (sharp_image == (Image *) NULL)
3045 break;
3046 *image=DestroyImage(*image);
3047 *image=sharp_image;
3048 break;
3049 }
3050 if (LocaleCompare("shave",option+1) == 0)
3051 {
3052 Image
3053 *shave_image;
3054
3055 /*
3056 Shave the image edges.
3057 */
3058 (void) SyncImageSettings(image_info,*image);
3059 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
3060 shave_image=ShaveImage(*image,&geometry,exception);
3061 if (shave_image == (Image *) NULL)
3062 break;
3063 *image=DestroyImage(*image);
3064 *image=shave_image;
3065 break;
3066 }
3067 if (LocaleCompare("shear",option+1) == 0)
3068 {
3069 Image
3070 *shear_image;
3071
3072 /*
3073 Shear image.
3074 */
3075 (void) SyncImageSettings(image_info,*image);
3076 flags=ParseGeometry(argv[i+1],&geometry_info);
3077 if ((flags & SigmaValue) == 0)
3078 geometry_info.sigma=geometry_info.rho;
3079 shear_image=ShearImage(*image,geometry_info.rho,geometry_info.sigma,
3080 exception);
3081 if (shear_image == (Image *) NULL)
3082 break;
3083 *image=DestroyImage(*image);
3084 *image=shear_image;
3085 break;
3086 }
3087 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
3088 {
3089 /*
3090 Sigmoidal non-linearity contrast control.
3091 */
3092 (void) SyncImageSettings(image_info,*image);
3093 flags=ParseGeometry(argv[i+1],&geometry_info);
3094 if ((flags & SigmaValue) == 0)
3095 geometry_info.sigma=(double) QuantumRange/2.0;
3096 if ((flags & PercentValue) != 0)
3097 geometry_info.sigma=(double) QuantumRange*geometry_info.sigma/
3098 100.0;
3099 (void) SigmoidalContrastImageChannel(*image,channel,
3100 (*option == '-') ? MagickTrue : MagickFalse,geometry_info.rho,
3101 geometry_info.sigma);
3102 InheritException(exception,&(*image)->exception);
3103 break;
3104 }
3105 if (LocaleCompare("sketch",option+1) == 0)
3106 {
3107 Image
3108 *sketch_image;
3109
3110 /*
3111 Sketch image.
3112 */
3113 (void) SyncImageSettings(image_info,*image);
3114 flags=ParseGeometry(argv[i+1],&geometry_info);
3115 if ((flags & SigmaValue) == 0)
3116 geometry_info.sigma=1.0;
3117 sketch_image=SketchImage(*image,geometry_info.rho,
3118 geometry_info.sigma,geometry_info.xi,exception);
3119 if (sketch_image == (Image *) NULL)
3120 break;
3121 *image=DestroyImage(*image);
3122 *image=sketch_image;
3123 break;
3124 }
3125 if (LocaleCompare("solarize",option+1) == 0)
3126 {
3127 double
3128 threshold;
3129
3130 (void) SyncImageSettings(image_info,*image);
cristyf2f27272009-12-17 14:48:46 +00003131 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
cristy3ed852e2009-09-05 21:47:34 +00003132 (void) SolarizeImage(*image,threshold);
3133 InheritException(exception,&(*image)->exception);
3134 break;
3135 }
3136 if (LocaleCompare("sparse-color",option+1) == 0)
3137 {
3138 Image
3139 *sparse_image;
3140
3141 SparseColorMethod
3142 method;
3143
3144 char
3145 *arguments;
3146
3147 /*
3148 Sparse Color Interpolated Gradient
3149 */
3150 (void) SyncImageSettings(image_info,*image);
3151 method=(SparseColorMethod) ParseMagickOption(
3152 MagickSparseColorOptions,MagickFalse,argv[i+1]);
3153 arguments=InterpretImageProperties(image_info,*image,argv[i+2]);
3154 InheritException(exception,&(*image)->exception);
3155 if (arguments == (char *) NULL)
3156 break;
3157 sparse_image=SparseColorOption(*image,channel,method,arguments,
3158 option[0] == '+' ? MagickTrue : MagickFalse,exception);
3159 arguments=DestroyString(arguments);
3160 if (sparse_image == (Image *) NULL)
3161 break;
3162 *image=DestroyImage(*image);
3163 *image=sparse_image;
3164 break;
3165 }
3166 if (LocaleCompare("splice",option+1) == 0)
3167 {
3168 Image
3169 *splice_image;
3170
3171 /*
3172 Splice a solid color into the image.
3173 */
3174 (void) SyncImageSettings(image_info,*image);
3175 (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
3176 splice_image=SpliceImage(*image,&geometry,exception);
3177 if (splice_image == (Image *) NULL)
3178 break;
3179 *image=DestroyImage(*image);
3180 *image=splice_image;
3181 break;
3182 }
3183 if (LocaleCompare("spread",option+1) == 0)
3184 {
3185 Image
3186 *spread_image;
3187
3188 /*
3189 Spread an image.
3190 */
3191 (void) SyncImageSettings(image_info,*image);
3192 (void) ParseGeometry(argv[i+1],&geometry_info);
3193 spread_image=SpreadImage(*image,geometry_info.rho,exception);
3194 if (spread_image == (Image *) NULL)
3195 break;
3196 *image=DestroyImage(*image);
3197 *image=spread_image;
3198 break;
3199 }
3200 if (LocaleCompare("stretch",option+1) == 0)
3201 {
3202 if (*option == '+')
3203 {
3204 draw_info->stretch=UndefinedStretch;
3205 break;
3206 }
3207 draw_info->stretch=(StretchType) ParseMagickOption(
3208 MagickStretchOptions,MagickFalse,argv[i+1]);
3209 break;
3210 }
3211 if (LocaleCompare("strip",option+1) == 0)
3212 {
3213 /*
3214 Strip image of profiles and comments.
3215 */
3216 (void) SyncImageSettings(image_info,*image);
3217 (void) StripImage(*image);
3218 InheritException(exception,&(*image)->exception);
3219 break;
3220 }
3221 if (LocaleCompare("stroke",option+1) == 0)
3222 {
3223 ExceptionInfo
3224 *sans;
3225
3226 if (*option == '+')
3227 {
3228 (void) QueryColorDatabase("none",&draw_info->stroke,exception);
3229 if (draw_info->stroke_pattern != (Image *) NULL)
3230 draw_info->stroke_pattern=DestroyImage(
3231 draw_info->stroke_pattern);
3232 break;
3233 }
3234 sans=AcquireExceptionInfo();
3235 status=QueryColorDatabase(argv[i+1],&draw_info->stroke,sans);
3236 sans=DestroyExceptionInfo(sans);
3237 if (status == MagickFalse)
3238 draw_info->stroke_pattern=GetImageCache(image_info,argv[i+1],
3239 exception);
3240 break;
3241 }
3242 if (LocaleCompare("strokewidth",option+1) == 0)
3243 {
cristyf2f27272009-12-17 14:48:46 +00003244 draw_info->stroke_width=StringToDouble(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00003245 break;
3246 }
3247 if (LocaleCompare("style",option+1) == 0)
3248 {
3249 if (*option == '+')
3250 {
3251 draw_info->style=UndefinedStyle;
3252 break;
3253 }
3254 draw_info->style=(StyleType) ParseMagickOption(MagickStyleOptions,
3255 MagickFalse,argv[i+1]);
3256 break;
3257 }
3258 if (LocaleCompare("swirl",option+1) == 0)
3259 {
3260 Image
3261 *swirl_image;
3262
3263 /*
3264 Swirl image.
3265 */
3266 (void) SyncImageSettings(image_info,*image);
3267 (void) ParseGeometry(argv[i+1],&geometry_info);
3268 swirl_image=SwirlImage(*image,geometry_info.rho,exception);
3269 if (swirl_image == (Image *) NULL)
3270 break;
3271 *image=DestroyImage(*image);
3272 *image=swirl_image;
3273 break;
3274 }
3275 break;
3276 }
3277 case 't':
3278 {
3279 if (LocaleCompare("threshold",option+1) == 0)
3280 {
3281 double
3282 threshold;
3283
3284 /*
3285 Threshold image.
3286 */
3287 (void) SyncImageSettings(image_info,*image);
3288 if (*option == '+')
3289 threshold=(double) QuantumRange/2.5;
3290 else
cristyf2f27272009-12-17 14:48:46 +00003291 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
cristy3ed852e2009-09-05 21:47:34 +00003292 (void) BilevelImageChannel(*image,channel,threshold);
3293 InheritException(exception,&(*image)->exception);
3294 break;
3295 }
3296 if (LocaleCompare("thumbnail",option+1) == 0)
3297 {
3298 Image
3299 *thumbnail_image;
3300
3301 /*
3302 Thumbnail image.
3303 */
3304 (void) SyncImageSettings(image_info,*image);
3305 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
3306 thumbnail_image=ThumbnailImage(*image,geometry.width,
3307 geometry.height,exception);
3308 if (thumbnail_image == (Image *) NULL)
3309 break;
3310 *image=DestroyImage(*image);
3311 *image=thumbnail_image;
3312 break;
3313 }
3314 if (LocaleCompare("tile",option+1) == 0)
3315 {
3316 if (*option == '+')
3317 {
3318 if (draw_info->fill_pattern != (Image *) NULL)
3319 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
3320 break;
3321 }
3322 draw_info->fill_pattern=GetImageCache(image_info,argv[i+1],
3323 exception);
3324 break;
3325 }
3326 if (LocaleCompare("tint",option+1) == 0)
3327 {
3328 Image
3329 *tint_image;
3330
3331 /*
3332 Tint the image.
3333 */
3334 (void) SyncImageSettings(image_info,*image);
3335 tint_image=TintImage(*image,argv[i+1],draw_info->fill,exception);
3336 if (tint_image == (Image *) NULL)
3337 break;
3338 *image=DestroyImage(*image);
3339 *image=tint_image;
3340 break;
3341 }
3342 if (LocaleCompare("transform",option+1) == 0)
3343 {
3344 Image
3345 *transform_image;
3346
3347 /*
3348 Affine transform image.
3349 */
3350 (void) SyncImageSettings(image_info,*image);
3351 transform_image=AffineTransformImage(*image,&draw_info->affine,
3352 exception);
3353 if (transform_image == (Image *) NULL)
3354 break;
3355 *image=DestroyImage(*image);
3356 *image=transform_image;
3357 break;
3358 }
3359 if (LocaleCompare("transparent",option+1) == 0)
3360 {
3361 MagickPixelPacket
3362 target;
3363
3364 (void) SyncImageSettings(image_info,*image);
3365 (void) QueryMagickColor(argv[i+1],&target,exception);
3366 (void) TransparentPaintImage(*image,&target,(Quantum)
3367 TransparentOpacity,*option == '-' ? MagickFalse : MagickTrue);
3368 InheritException(exception,&(*image)->exception);
3369 break;
3370 }
3371 if (LocaleCompare("transpose",option+1) == 0)
3372 {
3373 Image
3374 *transpose_image;
3375
3376 /*
3377 Transpose image scanlines.
3378 */
3379 (void) SyncImageSettings(image_info,*image);
3380 transpose_image=TransposeImage(*image,exception);
3381 if (transpose_image == (Image *) NULL)
3382 break;
3383 *image=DestroyImage(*image);
3384 *image=transpose_image;
3385 break;
3386 }
3387 if (LocaleCompare("transverse",option+1) == 0)
3388 {
3389 Image
3390 *transverse_image;
3391
3392 /*
3393 Transverse image scanlines.
3394 */
3395 (void) SyncImageSettings(image_info,*image);
3396 transverse_image=TransverseImage(*image,exception);
3397 if (transverse_image == (Image *) NULL)
3398 break;
3399 *image=DestroyImage(*image);
3400 *image=transverse_image;
3401 break;
3402 }
3403 if (LocaleCompare("treedepth",option+1) == 0)
3404 {
cristye27293e2009-12-18 02:53:20 +00003405 quantize_info->tree_depth=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00003406 break;
3407 }
3408 if (LocaleCompare("trim",option+1) == 0)
3409 {
3410 Image
3411 *trim_image;
3412
3413 /*
3414 Trim image.
3415 */
3416 (void) SyncImageSettings(image_info,*image);
3417 trim_image=TrimImage(*image,exception);
3418 if (trim_image == (Image *) NULL)
3419 break;
3420 *image=DestroyImage(*image);
3421 *image=trim_image;
3422 break;
3423 }
3424 if (LocaleCompare("type",option+1) == 0)
3425 {
3426 ImageType
3427 type;
3428
3429 (void) SyncImageSettings(image_info,*image);
3430 if (*option == '+')
3431 type=UndefinedType;
3432 else
3433 type=(ImageType) ParseMagickOption(MagickTypeOptions,MagickFalse,
3434 argv[i+1]);
3435 (*image)->type=UndefinedType;
3436 (void) SetImageType(*image,type);
3437 InheritException(exception,&(*image)->exception);
3438 break;
3439 }
3440 break;
3441 }
3442 case 'u':
3443 {
3444 if (LocaleCompare("undercolor",option+1) == 0)
3445 {
3446 (void) QueryColorDatabase(argv[i+1],&draw_info->undercolor,
3447 exception);
3448 break;
3449 }
cristy045bd902010-01-30 18:56:24 +00003450 if (LocaleCompare("unique",option+1) == 0)
3451 {
3452 if (*option == '+')
3453 {
3454 (void) DeleteImageArtifact(*image,"identify:unique");
3455 break;
3456 }
3457 (void) SetImageArtifact(*image,"identify:unique","true");
3458 break;
3459 }
cristy3ed852e2009-09-05 21:47:34 +00003460 if (LocaleCompare("unique-colors",option+1) == 0)
3461 {
3462 Image
3463 *unique_image;
3464
3465 /*
3466 Unique image colors.
3467 */
3468 (void) SyncImageSettings(image_info,*image);
3469 unique_image=UniqueImageColors(*image,exception);
3470 if (unique_image == (Image *) NULL)
3471 break;
3472 *image=DestroyImage(*image);
3473 *image=unique_image;
3474 break;
3475 }
3476 if (LocaleCompare("unsharp",option+1) == 0)
3477 {
3478 Image
3479 *unsharp_image;
3480
3481 /*
3482 Unsharp mask image.
3483 */
3484 (void) SyncImageSettings(image_info,*image);
3485 flags=ParseGeometry(argv[i+1],&geometry_info);
3486 if ((flags & SigmaValue) == 0)
3487 geometry_info.sigma=1.0;
3488 if ((flags & XiValue) == 0)
3489 geometry_info.xi=1.0;
3490 if ((flags & PsiValue) == 0)
3491 geometry_info.psi=0.05;
3492 unsharp_image=UnsharpMaskImageChannel(*image,channel,
3493 geometry_info.rho,geometry_info.sigma,geometry_info.xi,
3494 geometry_info.psi,exception);
3495 if (unsharp_image == (Image *) NULL)
3496 break;
3497 *image=DestroyImage(*image);
3498 *image=unsharp_image;
3499 break;
3500 }
3501 break;
3502 }
3503 case 'v':
3504 {
3505 if (LocaleCompare("verbose",option+1) == 0)
3506 {
3507 (void) SetImageArtifact(*image,option+1,
3508 *option == '+' ? "false" : "true");
3509 break;
3510 }
3511 if (LocaleCompare("vignette",option+1) == 0)
3512 {
3513 Image
3514 *vignette_image;
3515
3516 /*
3517 Vignette image.
3518 */
3519 (void) SyncImageSettings(image_info,*image);
3520 flags=ParseGeometry(argv[i+1],&geometry_info);
3521 if ((flags & SigmaValue) == 0)
3522 geometry_info.sigma=1.0;
3523 if ((flags & XiValue) == 0)
3524 geometry_info.xi=0.1*(*image)->columns;
3525 if ((flags & PsiValue) == 0)
3526 geometry_info.psi=0.1*(*image)->rows;
3527 vignette_image=VignetteImage(*image,geometry_info.rho,
cristy0534a6b2010-03-18 01:19:38 +00003528 geometry_info.sigma,(long) ceil(geometry_info.xi-0.5),(long)
3529 ceil(geometry_info.psi-0.5),exception);
cristy3ed852e2009-09-05 21:47:34 +00003530 if (vignette_image == (Image *) NULL)
3531 break;
3532 *image=DestroyImage(*image);
3533 *image=vignette_image;
3534 break;
3535 }
3536 if (LocaleCompare("virtual-pixel",option+1) == 0)
3537 {
3538 if (*option == '+')
3539 {
3540 (void) SetImageVirtualPixelMethod(*image,
3541 UndefinedVirtualPixelMethod);
3542 break;
3543 }
3544 (void) SetImageVirtualPixelMethod(*image,(VirtualPixelMethod)
3545 ParseMagickOption(MagickVirtualPixelOptions,MagickFalse,
3546 argv[i+1]));
3547 break;
3548 }
3549 break;
3550 }
3551 case 'w':
3552 {
3553 if (LocaleCompare("wave",option+1) == 0)
3554 {
3555 Image
3556 *wave_image;
3557
3558 /*
3559 Wave image.
3560 */
3561 (void) SyncImageSettings(image_info,*image);
3562 flags=ParseGeometry(argv[i+1],&geometry_info);
3563 if ((flags & SigmaValue) == 0)
3564 geometry_info.sigma=1.0;
3565 wave_image=WaveImage(*image,geometry_info.rho,geometry_info.sigma,
3566 exception);
3567 if (wave_image == (Image *) NULL)
3568 break;
3569 *image=DestroyImage(*image);
3570 *image=wave_image;
3571 break;
3572 }
3573 if (LocaleCompare("weight",option+1) == 0)
3574 {
cristye27293e2009-12-18 02:53:20 +00003575 draw_info->weight=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00003576 if (LocaleCompare(argv[i+1],"all") == 0)
3577 draw_info->weight=0;
3578 if (LocaleCompare(argv[i+1],"bold") == 0)
3579 draw_info->weight=700;
3580 if (LocaleCompare(argv[i+1],"bolder") == 0)
3581 if (draw_info->weight <= 800)
3582 draw_info->weight+=100;
3583 if (LocaleCompare(argv[i+1],"lighter") == 0)
3584 if (draw_info->weight >= 100)
3585 draw_info->weight-=100;
3586 if (LocaleCompare(argv[i+1],"normal") == 0)
3587 draw_info->weight=400;
3588 break;
3589 }
3590 if (LocaleCompare("white-threshold",option+1) == 0)
3591 {
3592 /*
3593 White threshold image.
3594 */
3595 (void) SyncImageSettings(image_info,*image);
3596 (void) WhiteThresholdImageChannel(*image,channel,argv[i+1],
3597 exception);
3598 InheritException(exception,&(*image)->exception);
3599 break;
3600 }
3601 break;
3602 }
3603 default:
3604 break;
3605 }
3606 i+=count;
3607 }
3608 if (region_image != (Image *) NULL)
3609 {
3610 /*
3611 Composite transformed region onto image.
3612 */
3613 (void) SyncImageSettings(image_info,*image);
3614 (void) CompositeImage(region_image,(*image)->matte != MagickFalse ?
3615 OverCompositeOp : CopyCompositeOp,*image,region_geometry.x,
3616 region_geometry.y);
3617 InheritException(exception,&region_image->exception);
3618 *image=DestroyImage(*image);
3619 *image=region_image;
3620 }
3621 /*
3622 Free resources.
3623 */
3624 quantize_info=DestroyQuantizeInfo(quantize_info);
3625 draw_info=DestroyDrawInfo(draw_info);
3626 status=(*image)->exception.severity == UndefinedException ?
3627 MagickTrue : MagickFalse;
3628 return(status);
3629}
3630
3631/*
3632%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3633% %
3634% %
3635% %
3636% M o g r i f y I m a g e C o m m a n d %
3637% %
3638% %
3639% %
3640%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3641%
3642% MogrifyImageCommand() transforms an image or a sequence of images. These
3643% transforms include image scaling, image rotation, color reduction, and
3644% others. The transmogrified image overwrites the original image.
3645%
3646% The format of the MogrifyImageCommand method is:
3647%
3648% MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,int argc,
3649% const char **argv,char **metadata,ExceptionInfo *exception)
3650%
3651% A description of each parameter follows:
3652%
3653% o image_info: the image info.
3654%
3655% o argc: the number of elements in the argument vector.
3656%
3657% o argv: A text array containing the command line arguments.
3658%
3659% o metadata: any metadata is returned here.
3660%
3661% o exception: return any errors or warnings in this structure.
3662%
3663*/
3664
3665static MagickBooleanType MogrifyUsage(void)
3666{
3667 static const char
3668 *miscellaneous[]=
3669 {
3670 "-debug events display copious debugging information",
3671 "-help print program options",
3672 "-list type print a list of supported option arguments",
3673 "-log format format of debugging information",
3674 "-version print version information",
3675 (char *) NULL
3676 },
3677 *operators[]=
3678 {
3679 "-adaptive-blur geometry",
3680 " adaptively blur pixels; decrease effect near edges",
3681 "-adaptive-resize geometry",
3682 " adaptively resize image using 'mesh' interpolation",
3683 "-adaptive-sharpen geometry",
3684 " adaptively sharpen pixels; increase effect near edges",
3685 "-alpha option on, activate, off, deactivate, set, opaque, copy",
3686 " transparent, extract, background, or shape",
3687 "-annotate geometry text",
3688 " annotate the image with text",
3689 "-auto-gamma automagically adjust gamma level of image",
3690 "-auto-level automagically adjust color levels of image",
3691 "-auto-orient automagically orient (rotate) image",
3692 "-bench iterations measure performance",
3693 "-black-threshold value",
3694 " force all pixels below the threshold into black",
3695 "-blue-shift simulate a scene at nighttime in the moonlight",
3696 "-blur geometry reduce image noise and reduce detail levels",
3697 "-border geometry surround image with a border of color",
3698 "-bordercolor color border color",
cristya28d6b82010-01-11 20:03:47 +00003699 "-brightness-contrast geometry",
3700 " improve brightness / contrast of the image",
cristy3ed852e2009-09-05 21:47:34 +00003701 "-cdl filename color correct with a color decision list",
3702 "-charcoal radius simulate a charcoal drawing",
3703 "-chop geometry remove pixels from the image interior",
cristyecb0c6d2009-09-25 16:50:09 +00003704 "-clamp restrict pixel range from 0 to the quantum depth",
cristy3ed852e2009-09-05 21:47:34 +00003705 "-clip clip along the first path from the 8BIM profile",
3706 "-clip-mask filename associate a clip mask with the image",
3707 "-clip-path id clip along a named path from the 8BIM profile",
3708 "-colorize value colorize the image with the fill color",
cristye6365592010-04-02 17:31:23 +00003709 "-color-matrix matrix apply color correction to the image",
cristy3ed852e2009-09-05 21:47:34 +00003710 "-contrast enhance or reduce the image contrast",
3711 "-contrast-stretch geometry",
3712 " improve contrast by `stretching' the intensity range",
3713 "-convolve coefficients",
3714 " apply a convolution kernel to the image",
3715 "-cycle amount cycle the image colormap",
3716 "-decipher filename convert cipher pixels to plain pixels",
3717 "-deskew threshold straighten an image",
3718 "-despeckle reduce the speckles within an image",
3719 "-distort method args",
3720 " distort images according to given method ad args",
3721 "-draw string annotate the image with a graphic primitive",
3722 "-edge radius apply a filter to detect edges in the image",
3723 "-encipher filename convert plain pixels to cipher pixels",
3724 "-emboss radius emboss an image",
3725 "-enhance apply a digital filter to enhance a noisy image",
3726 "-equalize perform histogram equalization to an image",
3727 "-evaluate operator value",
cristyd18ae7c2010-03-07 17:39:52 +00003728 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003729 "-extent geometry set the image size",
3730 "-extract geometry extract area from image",
3731 "-fft implements the discrete Fourier transform (DFT)",
3732 "-flip flip image vertically",
3733 "-floodfill geometry color",
3734 " floodfill the image with color",
3735 "-flop flop image horizontally",
3736 "-frame geometry surround image with an ornamental border",
cristyc2b730e2009-11-24 14:32:09 +00003737 "-function name parameters",
cristy3ed852e2009-09-05 21:47:34 +00003738 " apply function over image values",
3739 "-gamma value level of gamma correction",
3740 "-gaussian-blur geometry",
3741 " reduce image noise and reduce detail levels",
cristy901f09d2009-10-16 22:56:10 +00003742 "-geometry geometry preferred size or location of the image",
cristy3ed852e2009-09-05 21:47:34 +00003743 "-identify identify the format and characteristics of the image",
3744 "-ift implements the inverse discrete Fourier transform (DFT)",
3745 "-implode amount implode image pixels about the center",
3746 "-lat geometry local adaptive thresholding",
3747 "-layers method optimize, merge, or compare image layers",
3748 "-level value adjust the level of image contrast",
3749 "-level-colors color,color",
cristyee0f8d72009-09-19 00:58:29 +00003750 " level image with the given colors",
cristy3ed852e2009-09-05 21:47:34 +00003751 "-linear-stretch geometry",
3752 " improve contrast by `stretching with saturation'",
3753 "-liquid-rescale geometry",
3754 " rescale image with seam-carving",
3755 "-median radius apply a median filter to the image",
3756 "-modulate value vary the brightness, saturation, and hue",
3757 "-monochrome transform image to black and white",
cristy7c1b9fd2010-02-02 14:36:00 +00003758 "-morphology method kernel",
anthony29188a82010-01-22 10:12:34 +00003759 " apply a morphology method to the image",
cristy3ed852e2009-09-05 21:47:34 +00003760 "-motion-blur geometry",
3761 " simulate motion blur",
3762 "-negate replace every pixel with its complementary color ",
3763 "-noise radius add or reduce noise in an image",
3764 "-normalize transform image to span the full range of colors",
3765 "-opaque color change this color to the fill color",
3766 "-ordered-dither NxN",
3767 " add a noise pattern to the image with specific",
3768 " amplitudes",
3769 "-paint radius simulate an oil painting",
3770 "-polaroid angle simulate a Polaroid picture",
3771 "-posterize levels reduce the image to a limited number of color levels",
3772 "-print string interpret string and print to console",
3773 "-profile filename add, delete, or apply an image profile",
3774 "-quantize colorspace reduce colors in this colorspace",
3775 "-radial-blur angle radial blur the image",
3776 "-raise value lighten/darken image edges to create a 3-D effect",
3777 "-random-threshold low,high",
3778 " random threshold the image",
cristy3ed852e2009-09-05 21:47:34 +00003779 "-region geometry apply options to a portion of the image",
3780 "-render render vector graphics",
3781 "-repage geometry size and location of an image canvas",
3782 "-resample geometry change the resolution of an image",
3783 "-resize geometry resize the image",
3784 "-roll geometry roll an image vertically or horizontally",
3785 "-rotate degrees apply Paeth rotation to the image",
3786 "-sample geometry scale image with pixel sampling",
3787 "-scale geometry scale the image",
3788 "-segment values segment an image",
3789 "-selective-blur geometry",
3790 " selectively blur pixels within a contrast threshold",
3791 "-sepia-tone threshold",
3792 " simulate a sepia-toned photo",
3793 "-set property value set an image property",
3794 "-shade degrees shade the image using a distant light source",
3795 "-shadow geometry simulate an image shadow",
3796 "-sharpen geometry sharpen the image",
3797 "-shave geometry shave pixels from the image edges",
3798 "-shear geometry slide one edge of the image along the X or Y axis",
3799 "-sigmoidal-contrast geometry",
3800 " increase the contrast without saturating highlights or shadows",
3801 "-sketch geometry simulate a pencil sketch",
3802 "-solarize threshold negate all pixels above the threshold level",
3803 "-sparse-color method args",
3804 " fill in a image based on a few color points",
3805 "-splice geometry splice the background color into the image",
3806 "-spread radius displace image pixels by a random amount",
3807 "-strip strip image of all profiles and comments",
3808 "-swirl degrees swirl image pixels about the center",
3809 "-threshold value threshold the image",
3810 "-thumbnail geometry create a thumbnail of the image",
3811 "-tile filename tile image when filling a graphic primitive",
3812 "-tint value tint the image with the fill color",
3813 "-transform affine transform image",
3814 "-transparent color make this color transparent within the image",
3815 "-transpose flip image vertically and rotate 90 degrees",
3816 "-transverse flop image horizontally and rotate 270 degrees",
3817 "-trim trim image edges",
3818 "-type type image type",
3819 "-unique-colors discard all but one of any pixel color",
3820 "-unsharp geometry sharpen the image",
3821 "-vignette geometry soften the edges of the image in vignette style",
3822 "-wave geometry alter an image along a sine wave",
3823 "-white-threshold value",
3824 " force all pixels above the threshold into white",
3825 (char *) NULL
3826 },
3827 *sequence_operators[]=
3828 {
3829 "-append append an image sequence",
cristy3ed852e2009-09-05 21:47:34 +00003830 "-clut apply a color lookup table to the image",
3831 "-coalesce merge a sequence of images",
3832 "-combine combine a sequence of images",
3833 "-composite composite image",
3834 "-crop geometry cut out a rectangular region of the image",
3835 "-deconstruct break down an image sequence into constituent parts",
cristyd18ae7c2010-03-07 17:39:52 +00003836 "-evaluate-sequence operator",
3837 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003838 "-flatten flatten a sequence of images",
3839 "-fx expression apply mathematical expression to an image channel(s)",
3840 "-hald-clut apply a Hald color lookup table to the image",
3841 "-morph value morph an image sequence",
3842 "-mosaic create a mosaic from an image sequence",
3843 "-process arguments process the image with a custom image filter",
3844 "-reverse reverse image sequence",
3845 "-separate separate an image channel into a grayscale image",
3846 "-write filename write images to this file",
3847 (char *) NULL
3848 },
3849 *settings[]=
3850 {
3851 "-adjoin join images into a single multi-image file",
3852 "-affine matrix affine transform matrix",
3853 "-alpha option activate, deactivate, reset, or set the alpha channel",
3854 "-antialias remove pixel-aliasing",
3855 "-authenticate password",
3856 " decipher image with this password",
3857 "-attenuate value lessen (or intensify) when adding noise to an image",
3858 "-background color background color",
3859 "-bias value add bias when convolving an image",
3860 "-black-point-compensation",
3861 " use black point compensation",
3862 "-blue-primary point chromaticity blue primary point",
3863 "-bordercolor color border color",
3864 "-caption string assign a caption to an image",
3865 "-channel type apply option to select image channels",
3866 "-colors value preferred number of colors in the image",
3867 "-colorspace type alternate image colorspace",
3868 "-comment string annotate image with comment",
3869 "-compose operator set image composite operator",
3870 "-compress type type of pixel compression when writing the image",
3871 "-define format:option",
3872 " define one or more image format options",
3873 "-delay value display the next image after pausing",
3874 "-density geometry horizontal and vertical density of the image",
3875 "-depth value image depth",
cristyc9b12952010-03-28 01:12:28 +00003876 "-direction type render text right-to-left or left-to-right",
cristy3ed852e2009-09-05 21:47:34 +00003877 "-display server get image or font from this X server",
3878 "-dispose method layer disposal method",
3879 "-dither method apply error diffusion to image",
3880 "-encoding type text encoding type",
3881 "-endian type endianness (MSB or LSB) of the image",
3882 "-family name render text with this font family",
3883 "-fill color color to use when filling a graphic primitive",
3884 "-filter type use this filter when resizing an image",
3885 "-font name render text with this font",
3886 "-format \"string\" output formatted image characteristics",
3887 "-fuzz distance colors within this distance are considered equal",
3888 "-gravity type horizontal and vertical text placement",
3889 "-green-primary point chromaticity green primary point",
3890 "-intent type type of rendering intent when managing the image color",
3891 "-interlace type type of image interlacing scheme",
cristyb32b90a2009-09-07 21:45:48 +00003892 "-interline-spacing value",
3893 " set the space between two text lines",
cristy3ed852e2009-09-05 21:47:34 +00003894 "-interpolate method pixel color interpolation method",
3895 "-interword-spacing value",
3896 " set the space between two words",
3897 "-kerning value set the space between two letters",
3898 "-label string assign a label to an image",
3899 "-limit type value pixel cache resource limit",
3900 "-loop iterations add Netscape loop extension to your GIF animation",
3901 "-mask filename associate a mask with the image",
3902 "-mattecolor color frame color",
3903 "-monitor monitor progress",
3904 "-orient type image orientation",
3905 "-page geometry size and location of an image canvas (setting)",
3906 "-ping efficiently determine image attributes",
3907 "-pointsize value font point size",
cristy7c1b9fd2010-02-02 14:36:00 +00003908 "-precision value maximum number of significant digits to print",
cristy3ed852e2009-09-05 21:47:34 +00003909 "-preview type image preview type",
3910 "-quality value JPEG/MIFF/PNG compression level",
3911 "-quiet suppress all warning messages",
3912 "-red-primary point chromaticity red primary point",
3913 "-regard-warnings pay attention to warning messages",
3914 "-remap filename transform image colors to match this set of colors",
3915 "-respect-parentheses settings remain in effect until parenthesis boundary",
3916 "-sampling-factor geometry",
3917 " horizontal and vertical sampling factor",
3918 "-scene value image scene number",
3919 "-seed value seed a new sequence of pseudo-random numbers",
3920 "-size geometry width and height of image",
3921 "-stretch type render text with this font stretch",
3922 "-stroke color graphic primitive stroke color",
3923 "-strokewidth value graphic primitive stroke width",
3924 "-style type render text with this font style",
3925 "-taint image as ineligible for bi-modal delegate",
3926 "-texture filename name of texture to tile onto the image background",
3927 "-tile-offset geometry",
3928 " tile offset",
3929 "-treedepth value color tree depth",
3930 "-transparent-color color",
3931 " transparent color",
3932 "-undercolor color annotation bounding box color",
3933 "-units type the units of image resolution",
3934 "-verbose print detailed information about the image",
3935 "-view FlashPix viewing transforms",
3936 "-virtual-pixel method",
3937 " virtual pixel access method",
3938 "-weight type render text with this font weight",
3939 "-white-point point chromaticity white point",
3940 (char *) NULL
3941 },
3942 *stack_operators[]=
3943 {
3944 "-clone index clone an image",
3945 "-delete index delete the image from the image sequence",
3946 "-insert index insert last image into the image sequence",
3947 "-swap indexes swap two images in the image sequence",
3948 (char *) NULL
3949 };
3950
3951 const char
3952 **p;
3953
3954 (void) printf("Version: %s\n",GetMagickVersion((unsigned long *) NULL));
cristy610b2e22009-10-22 14:59:43 +00003955 (void) printf("Copyright: %s\n",GetMagickCopyright());
3956 (void) printf("Features: %s\n\n",GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00003957 (void) printf("Usage: %s [options ...] file [ [options ...] file ...]\n",
3958 GetClientName());
3959 (void) printf("\nImage Settings:\n");
3960 for (p=settings; *p != (char *) NULL; p++)
3961 (void) printf(" %s\n",*p);
3962 (void) printf("\nImage Operators:\n");
3963 for (p=operators; *p != (char *) NULL; p++)
3964 (void) printf(" %s\n",*p);
3965 (void) printf("\nImage Sequence Operators:\n");
3966 for (p=sequence_operators; *p != (char *) NULL; p++)
3967 (void) printf(" %s\n",*p);
3968 (void) printf("\nImage Stack Operators:\n");
3969 for (p=stack_operators; *p != (char *) NULL; p++)
3970 (void) printf(" %s\n",*p);
3971 (void) printf("\nMiscellaneous Options:\n");
3972 for (p=miscellaneous; *p != (char *) NULL; p++)
3973 (void) printf(" %s\n",*p);
3974 (void) printf(
3975 "\nBy default, the image format of `file' is determined by its magic\n");
3976 (void) printf(
3977 "number. To specify a particular image format, precede the filename\n");
3978 (void) printf(
3979 "with an image format name and a colon (i.e. ps:image) or specify the\n");
3980 (void) printf(
3981 "image type as the filename suffix (i.e. image.ps). Specify 'file' as\n");
3982 (void) printf("'-' for standard input or output.\n");
3983 return(MagickFalse);
3984}
3985
3986WandExport MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,
3987 int argc,char **argv,char **wand_unused(metadata),ExceptionInfo *exception)
3988{
3989#define DestroyMogrify() \
3990{ \
3991 if (format != (char *) NULL) \
3992 format=DestroyString(format); \
3993 if (path != (char *) NULL) \
3994 path=DestroyString(path); \
3995 DestroyImageStack(); \
3996 for (i=0; i < (long) argc; i++) \
3997 argv[i]=DestroyString(argv[i]); \
3998 argv=(char **) RelinquishMagickMemory(argv); \
3999}
4000#define ThrowMogrifyException(asperity,tag,option) \
4001{ \
4002 (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag,"`%s'", \
4003 option); \
4004 DestroyMogrify(); \
4005 return(MagickFalse); \
4006}
4007#define ThrowMogrifyInvalidArgumentException(option,argument) \
4008{ \
4009 (void) ThrowMagickException(exception,GetMagickModule(),OptionError, \
4010 "InvalidArgument","`%s': %s",argument,option); \
4011 DestroyMogrify(); \
4012 return(MagickFalse); \
4013}
4014
4015 char
4016 *format,
4017 *option,
4018 *path;
4019
4020 Image
4021 *image;
4022
4023 ImageStack
4024 image_stack[MaxImageStackDepth+1];
4025
4026 long
4027 j,
4028 k;
4029
4030 register long
4031 i;
4032
4033 MagickBooleanType
4034 global_colormap;
4035
4036 MagickBooleanType
4037 fire,
4038 pend;
4039
4040 MagickStatusType
4041 status;
4042
4043 /*
4044 Set defaults.
4045 */
4046 assert(image_info != (ImageInfo *) NULL);
4047 assert(image_info->signature == MagickSignature);
4048 if (image_info->debug != MagickFalse)
4049 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
4050 assert(exception != (ExceptionInfo *) NULL);
4051 if (argc == 2)
4052 {
4053 option=argv[1];
4054 if ((LocaleCompare("version",option+1) == 0) ||
4055 (LocaleCompare("-version",option+1) == 0))
4056 {
4057 (void) fprintf(stdout,"Version: %s\n",
4058 GetMagickVersion((unsigned long *) NULL));
cristy610b2e22009-10-22 14:59:43 +00004059 (void) fprintf(stdout,"Copyright: %s\n",GetMagickCopyright());
4060 (void) fprintf(stdout,"Features: %s\n\n",GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00004061 return(MagickFalse);
4062 }
4063 }
4064 if (argc < 2)
cristy13e61a12010-02-04 20:19:00 +00004065 return(MogrifyUsage());
cristy3ed852e2009-09-05 21:47:34 +00004066 format=(char *) NULL;
4067 path=(char *) NULL;
4068 global_colormap=MagickFalse;
4069 k=0;
4070 j=1;
4071 NewImageStack();
4072 option=(char *) NULL;
4073 pend=MagickFalse;
4074 status=MagickTrue;
4075 /*
4076 Parse command line.
4077 */
4078 ReadCommandlLine(argc,&argv);
4079 status=ExpandFilenames(&argc,&argv);
4080 if (status == MagickFalse)
4081 ThrowMogrifyException(ResourceLimitError,"MemoryAllocationFailed",
4082 GetExceptionMessage(errno));
4083 for (i=1; i < (long) argc; i++)
4084 {
4085 option=argv[i];
4086 if (LocaleCompare(option,"(") == 0)
4087 {
4088 FireImageStack(MagickFalse,MagickTrue,pend);
4089 if (k == MaxImageStackDepth)
4090 ThrowMogrifyException(OptionError,"ParenthesisNestedTooDeeply",
4091 option);
4092 PushImageStack();
4093 continue;
4094 }
4095 if (LocaleCompare(option,")") == 0)
4096 {
4097 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
4098 if (k == 0)
4099 ThrowMogrifyException(OptionError,"UnableToParseExpression",option);
4100 PopImageStack();
4101 continue;
4102 }
4103 if (IsMagickOption(option) == MagickFalse)
4104 {
4105 char
4106 backup_filename[MaxTextExtent],
4107 *filename;
4108
4109 Image
4110 *images;
4111
4112 /*
4113 Option is a file name: begin by reading image from specified file.
4114 */
4115 FireImageStack(MagickFalse,MagickFalse,pend);
4116 filename=argv[i];
4117 if ((LocaleCompare(filename,"--") == 0) && (i < (argc-1)))
4118 filename=argv[++i];
4119 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
4120 images=ReadImages(image_info,exception);
4121 status&=(images != (Image *) NULL) &&
4122 (exception->severity < ErrorException);
4123 if (images == (Image *) NULL)
4124 continue;
4125 if (path != (char *) NULL)
4126 {
4127 GetPathComponent(option,TailPath,filename);
4128 (void) FormatMagickString(images->filename,MaxTextExtent,"%s%c%s",
4129 path,*DirectorySeparator,filename);
4130 }
4131 if (format != (char *) NULL)
4132 AppendImageFormat(format,images->filename);
4133 AppendImageStack(images);
4134 FinalizeImageSettings(image_info,image,MagickFalse);
4135 if (global_colormap != MagickFalse)
4136 {
4137 QuantizeInfo
4138 *quantize_info;
4139
4140 quantize_info=AcquireQuantizeInfo(image_info);
4141 (void) RemapImages(quantize_info,images,(Image *) NULL);
4142 quantize_info=DestroyQuantizeInfo(quantize_info);
4143 }
4144 *backup_filename='\0';
4145 if ((LocaleCompare(image->filename,"-") != 0) &&
4146 (IsPathWritable(image->filename) != MagickFalse))
4147 {
4148 register long
4149 i;
4150
4151 /*
4152 Rename image file as backup.
4153 */
4154 (void) CopyMagickString(backup_filename,image->filename,
4155 MaxTextExtent);
4156 for (i=0; i < 6; i++)
4157 {
4158 (void) ConcatenateMagickString(backup_filename,"~",MaxTextExtent);
4159 if (IsPathAccessible(backup_filename) == MagickFalse)
4160 break;
4161 }
4162 if ((IsPathAccessible(backup_filename) != MagickFalse) ||
4163 (rename(image->filename,backup_filename) != 0))
4164 *backup_filename='\0';
4165 }
4166 /*
4167 Write transmogrified image to disk.
4168 */
4169 image_info->synchronize=MagickTrue;
4170 status&=WriteImages(image_info,image,image->filename,exception);
4171 if ((status == MagickFalse) && (*backup_filename != '\0'))
4172 (void) remove(backup_filename);
4173 RemoveAllImageStack();
4174 continue;
4175 }
4176 pend=image != (Image *) NULL ? MagickTrue : MagickFalse;
4177 switch (*(option+1))
4178 {
4179 case 'a':
4180 {
4181 if (LocaleCompare("adaptive-blur",option+1) == 0)
4182 {
4183 i++;
4184 if (i == (long) argc)
4185 ThrowMogrifyException(OptionError,"MissingArgument",option);
4186 if (IsGeometry(argv[i]) == MagickFalse)
4187 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4188 break;
4189 }
4190 if (LocaleCompare("adaptive-resize",option+1) == 0)
4191 {
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("adaptive-sharpen",option+1) == 0)
4200 {
4201 i++;
4202 if (i == (long) argc)
4203 ThrowMogrifyException(OptionError,"MissingArgument",option);
4204 if (IsGeometry(argv[i]) == MagickFalse)
4205 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4206 break;
4207 }
4208 if (LocaleCompare("affine",option+1) == 0)
4209 {
4210 if (*option == '+')
4211 break;
4212 i++;
4213 if (i == (long) argc)
4214 ThrowMogrifyException(OptionError,"MissingArgument",option);
4215 if (IsGeometry(argv[i]) == MagickFalse)
4216 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4217 break;
4218 }
4219 if (LocaleCompare("alpha",option+1) == 0)
4220 {
4221 long
4222 type;
4223
4224 if (*option == '+')
4225 break;
4226 i++;
4227 if (i == (long) argc)
4228 ThrowMogrifyException(OptionError,"MissingArgument",option);
4229 type=ParseMagickOption(MagickAlphaOptions,MagickFalse,argv[i]);
4230 if (type < 0)
4231 ThrowMogrifyException(OptionError,"UnrecognizedAlphaChannelType",
4232 argv[i]);
4233 break;
4234 }
4235 if (LocaleCompare("annotate",option+1) == 0)
4236 {
4237 if (*option == '+')
4238 break;
4239 i++;
4240 if (i == (long) argc)
4241 ThrowMogrifyException(OptionError,"MissingArgument",option);
4242 if (IsGeometry(argv[i]) == MagickFalse)
4243 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4244 if (i == (long) argc)
4245 ThrowMogrifyException(OptionError,"MissingArgument",option);
4246 i++;
4247 break;
4248 }
4249 if (LocaleCompare("antialias",option+1) == 0)
4250 break;
4251 if (LocaleCompare("append",option+1) == 0)
4252 break;
4253 if (LocaleCompare("attenuate",option+1) == 0)
4254 {
4255 if (*option == '+')
4256 break;
4257 i++;
4258 if (i == (long) (argc-1))
4259 ThrowMogrifyException(OptionError,"MissingArgument",option);
4260 if (IsGeometry(argv[i]) == MagickFalse)
4261 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4262 break;
4263 }
4264 if (LocaleCompare("authenticate",option+1) == 0)
4265 {
4266 if (*option == '+')
4267 break;
4268 i++;
4269 if (i == (long) argc)
4270 ThrowMogrifyException(OptionError,"MissingArgument",option);
4271 break;
4272 }
4273 if (LocaleCompare("auto-gamma",option+1) == 0)
4274 break;
4275 if (LocaleCompare("auto-level",option+1) == 0)
4276 break;
4277 if (LocaleCompare("auto-orient",option+1) == 0)
4278 break;
4279 if (LocaleCompare("average",option+1) == 0)
4280 break;
4281 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4282 }
4283 case 'b':
4284 {
4285 if (LocaleCompare("background",option+1) == 0)
4286 {
4287 if (*option == '+')
4288 break;
4289 i++;
4290 if (i == (long) argc)
4291 ThrowMogrifyException(OptionError,"MissingArgument",option);
4292 break;
4293 }
4294 if (LocaleCompare("bias",option+1) == 0)
4295 {
4296 if (*option == '+')
4297 break;
4298 i++;
4299 if (i == (long) (argc-1))
4300 ThrowMogrifyException(OptionError,"MissingArgument",option);
4301 if (IsGeometry(argv[i]) == MagickFalse)
4302 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4303 break;
4304 }
4305 if (LocaleCompare("black-point-compensation",option+1) == 0)
4306 break;
4307 if (LocaleCompare("black-threshold",option+1) == 0)
4308 {
4309 if (*option == '+')
4310 break;
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("blue-primary",option+1) == 0)
4319 {
4320 if (*option == '+')
4321 break;
4322 i++;
4323 if (i == (long) argc)
4324 ThrowMogrifyException(OptionError,"MissingArgument",option);
4325 if (IsGeometry(argv[i]) == MagickFalse)
4326 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4327 break;
4328 }
4329 if (LocaleCompare("blue-shift",option+1) == 0)
4330 {
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("blur",option+1) == 0)
4339 {
4340 i++;
4341 if (i == (long) argc)
4342 ThrowMogrifyException(OptionError,"MissingArgument",option);
4343 if (IsGeometry(argv[i]) == MagickFalse)
4344 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4345 break;
4346 }
4347 if (LocaleCompare("border",option+1) == 0)
4348 {
4349 if (*option == '+')
4350 break;
4351 i++;
4352 if (i == (long) argc)
4353 ThrowMogrifyException(OptionError,"MissingArgument",option);
4354 if (IsGeometry(argv[i]) == MagickFalse)
4355 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4356 break;
4357 }
4358 if (LocaleCompare("bordercolor",option+1) == 0)
4359 {
4360 if (*option == '+')
4361 break;
4362 i++;
4363 if (i == (long) argc)
4364 ThrowMogrifyException(OptionError,"MissingArgument",option);
4365 break;
4366 }
4367 if (LocaleCompare("box",option+1) == 0)
4368 {
4369 if (*option == '+')
4370 break;
4371 i++;
4372 if (i == (long) argc)
4373 ThrowMogrifyException(OptionError,"MissingArgument",option);
4374 break;
4375 }
cristya28d6b82010-01-11 20:03:47 +00004376 if (LocaleCompare("brightness-contrast",option+1) == 0)
4377 {
4378 i++;
4379 if (i == (long) argc)
4380 ThrowMogrifyException(OptionError,"MissingArgument",option);
4381 if (IsGeometry(argv[i]) == MagickFalse)
4382 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4383 break;
4384 }
cristy3ed852e2009-09-05 21:47:34 +00004385 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4386 }
4387 case 'c':
4388 {
4389 if (LocaleCompare("cache",option+1) == 0)
4390 {
4391 if (*option == '+')
4392 break;
4393 i++;
4394 if (i == (long) argc)
4395 ThrowMogrifyException(OptionError,"MissingArgument",option);
4396 if (IsGeometry(argv[i]) == MagickFalse)
4397 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4398 break;
4399 }
4400 if (LocaleCompare("caption",option+1) == 0)
4401 {
4402 if (*option == '+')
4403 break;
4404 i++;
4405 if (i == (long) argc)
4406 ThrowMogrifyException(OptionError,"MissingArgument",option);
4407 break;
4408 }
4409 if (LocaleCompare("channel",option+1) == 0)
4410 {
4411 long
4412 channel;
4413
4414 if (*option == '+')
4415 break;
4416 i++;
4417 if (i == (long) (argc-1))
4418 ThrowMogrifyException(OptionError,"MissingArgument",option);
4419 channel=ParseChannelOption(argv[i]);
4420 if (channel < 0)
4421 ThrowMogrifyException(OptionError,"UnrecognizedChannelType",
4422 argv[i]);
4423 break;
4424 }
4425 if (LocaleCompare("cdl",option+1) == 0)
4426 {
4427 if (*option == '+')
4428 break;
4429 i++;
4430 if (i == (long) (argc-1))
4431 ThrowMogrifyException(OptionError,"MissingArgument",option);
4432 break;
4433 }
4434 if (LocaleCompare("charcoal",option+1) == 0)
4435 {
4436 if (*option == '+')
4437 break;
4438 i++;
4439 if (i == (long) argc)
4440 ThrowMogrifyException(OptionError,"MissingArgument",option);
4441 if (IsGeometry(argv[i]) == MagickFalse)
4442 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4443 break;
4444 }
4445 if (LocaleCompare("chop",option+1) == 0)
4446 {
4447 if (*option == '+')
4448 break;
4449 i++;
4450 if (i == (long) argc)
4451 ThrowMogrifyException(OptionError,"MissingArgument",option);
4452 if (IsGeometry(argv[i]) == MagickFalse)
4453 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4454 break;
4455 }
cristy1eb45dd2009-09-25 16:38:06 +00004456 if (LocaleCompare("clamp",option+1) == 0)
4457 break;
4458 if (LocaleCompare("clip",option+1) == 0)
4459 break;
cristy3ed852e2009-09-05 21:47:34 +00004460 if (LocaleCompare("clip-mask",option+1) == 0)
4461 {
4462 if (*option == '+')
4463 break;
4464 i++;
4465 if (i == (long) argc)
4466 ThrowMogrifyException(OptionError,"MissingArgument",option);
4467 break;
4468 }
4469 if (LocaleCompare("clut",option+1) == 0)
4470 break;
4471 if (LocaleCompare("coalesce",option+1) == 0)
4472 break;
4473 if (LocaleCompare("colorize",option+1) == 0)
4474 {
4475 if (*option == '+')
4476 break;
4477 i++;
4478 if (i == (long) argc)
4479 ThrowMogrifyException(OptionError,"MissingArgument",option);
4480 if (IsGeometry(argv[i]) == MagickFalse)
4481 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4482 break;
4483 }
cristye6365592010-04-02 17:31:23 +00004484 if (LocaleCompare("color-matrix",option+1) == 0)
4485 {
4486 if (*option == '+')
4487 break;
4488 i++;
4489 if (i == (long) (argc-1))
4490 ThrowMogrifyException(OptionError,"MissingArgument",option);
4491 if (IsGeometry(argv[i]) == MagickFalse)
4492 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4493 break;
4494 }
cristy3ed852e2009-09-05 21:47:34 +00004495 if (LocaleCompare("colors",option+1) == 0)
4496 {
4497 if (*option == '+')
4498 break;
4499 i++;
4500 if (i == (long) argc)
4501 ThrowMogrifyException(OptionError,"MissingArgument",option);
4502 if (IsGeometry(argv[i]) == MagickFalse)
4503 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4504 break;
4505 }
4506 if (LocaleCompare("colorspace",option+1) == 0)
4507 {
4508 long
4509 colorspace;
4510
4511 if (*option == '+')
4512 break;
4513 i++;
4514 if (i == (long) argc)
4515 ThrowMogrifyException(OptionError,"MissingArgument",option);
4516 colorspace=ParseMagickOption(MagickColorspaceOptions,MagickFalse,
4517 argv[i]);
4518 if (colorspace < 0)
4519 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
4520 argv[i]);
4521 break;
4522 }
4523 if (LocaleCompare("combine",option+1) == 0)
4524 break;
4525 if (LocaleCompare("comment",option+1) == 0)
4526 {
4527 if (*option == '+')
4528 break;
4529 i++;
4530 if (i == (long) argc)
4531 ThrowMogrifyException(OptionError,"MissingArgument",option);
4532 break;
4533 }
4534 if (LocaleCompare("composite",option+1) == 0)
4535 break;
4536 if (LocaleCompare("compress",option+1) == 0)
4537 {
4538 long
4539 compress;
4540
4541 if (*option == '+')
4542 break;
4543 i++;
4544 if (i == (long) argc)
4545 ThrowMogrifyException(OptionError,"MissingArgument",option);
4546 compress=ParseMagickOption(MagickCompressOptions,MagickFalse,
4547 argv[i]);
4548 if (compress < 0)
4549 ThrowMogrifyException(OptionError,"UnrecognizedImageCompression",
4550 argv[i]);
4551 break;
4552 }
cristy22879752009-10-25 23:55:40 +00004553 if (LocaleCompare("concurrent",option+1) == 0)
4554 break;
cristy3ed852e2009-09-05 21:47:34 +00004555 if (LocaleCompare("contrast",option+1) == 0)
4556 break;
4557 if (LocaleCompare("contrast-stretch",option+1) == 0)
4558 {
4559 i++;
4560 if (i == (long) argc)
4561 ThrowMogrifyException(OptionError,"MissingArgument",option);
4562 if (IsGeometry(argv[i]) == MagickFalse)
4563 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4564 break;
4565 }
4566 if (LocaleCompare("convolve",option+1) == 0)
4567 {
anthony29188a82010-01-22 10:12:34 +00004568 char
4569 token[MaxTextExtent];
4570
cristy3ed852e2009-09-05 21:47:34 +00004571 if (*option == '+')
4572 break;
4573 i++;
4574 if (i == (long) argc)
4575 ThrowMogrifyException(OptionError,"MissingArgument",option);
anthony29188a82010-01-22 10:12:34 +00004576#if 1
cristydfbe6ca2010-03-12 14:08:17 +00004577 (void) token;
cristy3ed852e2009-09-05 21:47:34 +00004578 if (IsGeometry(argv[i]) == MagickFalse)
4579 ThrowMogrifyInvalidArgumentException(option,argv[i]);
anthony29188a82010-01-22 10:12:34 +00004580#else
4581 /* Allow the use of built-in kernels like 'gaussian'
4582 * These may not work for kernels with 'nan' values, like 'diamond'
4583 */
4584 GetMagickToken(argv[i],NULL,token);
4585 if ( isalpha((int)token[0]) )
4586 {
4587 long
4588 op;
4589
4590 op=ParseMagickOption(MagickKernelOptions,MagickFalse,token);
4591 if (op < 0)
4592 ThrowMogrifyException(OptionError,"UnrecognizedKernelType",
4593 token);
4594 }
4595 /* geometry current returns invalid if 'nan' values are used */
4596 else if (IsGeometry(argv[i]) == MagickFalse)
4597 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4598#endif
cristy3ed852e2009-09-05 21:47:34 +00004599 break;
4600 }
4601 if (LocaleCompare("crop",option+1) == 0)
4602 {
4603 if (*option == '+')
4604 break;
4605 i++;
4606 if (i == (long) argc)
4607 ThrowMogrifyException(OptionError,"MissingArgument",option);
4608 if (IsGeometry(argv[i]) == MagickFalse)
4609 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4610 break;
4611 }
4612 if (LocaleCompare("cycle",option+1) == 0)
4613 {
4614 if (*option == '+')
4615 break;
4616 i++;
4617 if (i == (long) argc)
4618 ThrowMogrifyException(OptionError,"MissingArgument",option);
4619 if (IsGeometry(argv[i]) == MagickFalse)
4620 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4621 break;
4622 }
4623 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4624 }
4625 case 'd':
4626 {
4627 if (LocaleCompare("decipher",option+1) == 0)
4628 {
4629 if (*option == '+')
4630 break;
4631 i++;
4632 if (i == (long) (argc-1))
4633 ThrowMogrifyException(OptionError,"MissingArgument",option);
4634 break;
4635 }
4636 if (LocaleCompare("deconstruct",option+1) == 0)
4637 break;
4638 if (LocaleCompare("debug",option+1) == 0)
4639 {
4640 long
4641 event;
4642
4643 if (*option == '+')
4644 break;
4645 i++;
4646 if (i == (long) argc)
4647 ThrowMogrifyException(OptionError,"MissingArgument",option);
4648 event=ParseMagickOption(MagickLogEventOptions,MagickFalse,argv[i]);
4649 if (event < 0)
4650 ThrowMogrifyException(OptionError,"UnrecognizedEventType",
4651 argv[i]);
4652 (void) SetLogEventMask(argv[i]);
4653 break;
4654 }
4655 if (LocaleCompare("define",option+1) == 0)
4656 {
4657 i++;
4658 if (i == (long) argc)
4659 ThrowMogrifyException(OptionError,"MissingArgument",option);
4660 if (*option == '+')
4661 {
4662 const char
4663 *define;
4664
4665 define=GetImageOption(image_info,argv[i]);
4666 if (define == (const char *) NULL)
4667 ThrowMogrifyException(OptionError,"NoSuchOption",argv[i]);
4668 break;
4669 }
4670 break;
4671 }
4672 if (LocaleCompare("delay",option+1) == 0)
4673 {
4674 if (*option == '+')
4675 break;
4676 i++;
4677 if (i == (long) argc)
4678 ThrowMogrifyException(OptionError,"MissingArgument",option);
4679 if (IsGeometry(argv[i]) == MagickFalse)
4680 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4681 break;
4682 }
4683 if (LocaleCompare("density",option+1) == 0)
4684 {
4685 if (*option == '+')
4686 break;
4687 i++;
4688 if (i == (long) argc)
4689 ThrowMogrifyException(OptionError,"MissingArgument",option);
4690 if (IsGeometry(argv[i]) == MagickFalse)
4691 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4692 break;
4693 }
4694 if (LocaleCompare("depth",option+1) == 0)
4695 {
4696 if (*option == '+')
4697 break;
4698 i++;
4699 if (i == (long) argc)
4700 ThrowMogrifyException(OptionError,"MissingArgument",option);
4701 if (IsGeometry(argv[i]) == MagickFalse)
4702 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4703 break;
4704 }
4705 if (LocaleCompare("deskew",option+1) == 0)
4706 {
4707 if (*option == '+')
4708 break;
4709 i++;
4710 if (i == (long) argc)
4711 ThrowMogrifyException(OptionError,"MissingArgument",option);
4712 if (IsGeometry(argv[i]) == MagickFalse)
4713 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4714 break;
4715 }
4716 if (LocaleCompare("despeckle",option+1) == 0)
4717 break;
4718 if (LocaleCompare("dft",option+1) == 0)
4719 break;
cristyc9b12952010-03-28 01:12:28 +00004720 if (LocaleCompare("direction",option+1) == 0)
4721 {
4722 long
4723 direction;
4724
4725 if (*option == '+')
4726 break;
4727 i++;
4728 if (i == (long) argc)
4729 ThrowMogrifyException(OptionError,"MissingArgument",option);
4730 direction=ParseMagickOption(MagickDirectionOptions,MagickFalse,
4731 argv[i]);
4732 if (direction < 0)
4733 ThrowMogrifyException(OptionError,"UnrecognizedDirectionType",
4734 argv[i]);
4735 break;
4736 }
cristy3ed852e2009-09-05 21:47:34 +00004737 if (LocaleCompare("display",option+1) == 0)
4738 {
4739 if (*option == '+')
4740 break;
4741 i++;
4742 if (i == (long) argc)
4743 ThrowMogrifyException(OptionError,"MissingArgument",option);
4744 break;
4745 }
4746 if (LocaleCompare("dispose",option+1) == 0)
4747 {
4748 long
4749 dispose;
4750
4751 if (*option == '+')
4752 break;
4753 i++;
4754 if (i == (long) argc)
4755 ThrowMogrifyException(OptionError,"MissingArgument",option);
4756 dispose=ParseMagickOption(MagickDisposeOptions,MagickFalse,argv[i]);
4757 if (dispose < 0)
4758 ThrowMogrifyException(OptionError,"UnrecognizedDisposeMethod",
4759 argv[i]);
4760 break;
4761 }
4762 if (LocaleCompare("distort",option+1) == 0)
4763 {
4764 long
4765 op;
4766
4767 i++;
4768 if (i == (long) argc)
4769 ThrowMogrifyException(OptionError,"MissingArgument",option);
4770 op=ParseMagickOption(MagickDistortOptions,MagickFalse,argv[i]);
4771 if (op < 0)
4772 ThrowMogrifyException(OptionError,"UnrecognizedDistortMethod",
4773 argv[i]);
4774 i++;
4775 if (i == (long) (argc-1))
4776 ThrowMogrifyException(OptionError,"MissingArgument",option);
4777 break;
4778 }
4779 if (LocaleCompare("dither",option+1) == 0)
4780 {
4781 long
4782 method;
4783
4784 if (*option == '+')
4785 break;
4786 i++;
4787 if (i == (long) argc)
4788 ThrowMogrifyException(OptionError,"MissingArgument",option);
4789 method=ParseMagickOption(MagickDitherOptions,MagickFalse,argv[i]);
4790 if (method < 0)
4791 ThrowMogrifyException(OptionError,"UnrecognizedDitherMethod",
4792 argv[i]);
4793 break;
4794 }
4795 if (LocaleCompare("draw",option+1) == 0)
4796 {
4797 if (*option == '+')
4798 break;
4799 i++;
4800 if (i == (long) argc)
4801 ThrowMogrifyException(OptionError,"MissingArgument",option);
4802 break;
4803 }
cristy22879752009-10-25 23:55:40 +00004804 if (LocaleCompare("duration",option+1) == 0)
4805 {
4806 if (*option == '+')
4807 break;
4808 i++;
4809 if (i == (long) (argc-1))
4810 ThrowMogrifyException(OptionError,"MissingArgument",option);
4811 if (IsGeometry(argv[i]) == MagickFalse)
4812 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4813 break;
4814 }
cristy3ed852e2009-09-05 21:47:34 +00004815 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4816 }
4817 case 'e':
4818 {
4819 if (LocaleCompare("edge",option+1) == 0)
4820 {
4821 if (*option == '+')
4822 break;
4823 i++;
4824 if (i == (long) argc)
4825 ThrowMogrifyException(OptionError,"MissingArgument",option);
4826 if (IsGeometry(argv[i]) == MagickFalse)
4827 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4828 break;
4829 }
4830 if (LocaleCompare("emboss",option+1) == 0)
4831 {
4832 if (*option == '+')
4833 break;
4834 i++;
4835 if (i == (long) argc)
4836 ThrowMogrifyException(OptionError,"MissingArgument",option);
4837 if (IsGeometry(argv[i]) == MagickFalse)
4838 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4839 break;
4840 }
4841 if (LocaleCompare("encipher",option+1) == 0)
4842 {
4843 if (*option == '+')
4844 break;
4845 i++;
4846 if (i == (long) argc)
4847 ThrowMogrifyException(OptionError,"MissingArgument",option);
4848 break;
4849 }
4850 if (LocaleCompare("encoding",option+1) == 0)
4851 {
4852 if (*option == '+')
4853 break;
4854 i++;
4855 if (i == (long) argc)
4856 ThrowMogrifyException(OptionError,"MissingArgument",option);
4857 break;
4858 }
4859 if (LocaleCompare("endian",option+1) == 0)
4860 {
4861 long
4862 endian;
4863
4864 if (*option == '+')
4865 break;
4866 i++;
4867 if (i == (long) argc)
4868 ThrowMogrifyException(OptionError,"MissingArgument",option);
4869 endian=ParseMagickOption(MagickEndianOptions,MagickFalse,argv[i]);
4870 if (endian < 0)
4871 ThrowMogrifyException(OptionError,"UnrecognizedEndianType",
4872 argv[i]);
4873 break;
4874 }
4875 if (LocaleCompare("enhance",option+1) == 0)
4876 break;
4877 if (LocaleCompare("equalize",option+1) == 0)
4878 break;
4879 if (LocaleCompare("evaluate",option+1) == 0)
4880 {
4881 long
4882 op;
4883
4884 if (*option == '+')
4885 break;
4886 i++;
4887 if (i == (long) argc)
4888 ThrowMogrifyException(OptionError,"MissingArgument",option);
4889 op=ParseMagickOption(MagickEvaluateOptions,MagickFalse,argv[i]);
4890 if (op < 0)
4891 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4892 argv[i]);
4893 i++;
4894 if (i == (long) (argc-1))
4895 ThrowMogrifyException(OptionError,"MissingArgument",option);
4896 if (IsGeometry(argv[i]) == MagickFalse)
4897 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4898 break;
4899 }
cristyd18ae7c2010-03-07 17:39:52 +00004900 if (LocaleCompare("evaluate-sequence",option+1) == 0)
4901 {
4902 long
4903 op;
4904
4905 if (*option == '+')
4906 break;
4907 i++;
4908 if (i == (long) argc)
4909 ThrowMogrifyException(OptionError,"MissingArgument",option);
4910 op=ParseMagickOption(MagickEvaluateOptions,MagickFalse,argv[i]);
4911 if (op < 0)
4912 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4913 argv[i]);
4914 break;
4915 }
cristy3ed852e2009-09-05 21:47:34 +00004916 if (LocaleCompare("extent",option+1) == 0)
4917 {
4918 if (*option == '+')
4919 break;
4920 i++;
4921 if (i == (long) argc)
4922 ThrowMogrifyException(OptionError,"MissingArgument",option);
4923 if (IsGeometry(argv[i]) == MagickFalse)
4924 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4925 break;
4926 }
4927 if (LocaleCompare("extract",option+1) == 0)
4928 {
4929 if (*option == '+')
4930 break;
4931 i++;
4932 if (i == (long) argc)
4933 ThrowMogrifyException(OptionError,"MissingArgument",option);
4934 if (IsGeometry(argv[i]) == MagickFalse)
4935 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4936 break;
4937 }
4938 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4939 }
4940 case 'f':
4941 {
4942 if (LocaleCompare("family",option+1) == 0)
4943 {
4944 if (*option == '+')
4945 break;
4946 i++;
4947 if (i == (long) (argc-1))
4948 ThrowMogrifyException(OptionError,"MissingArgument",option);
4949 break;
4950 }
4951 if (LocaleCompare("fill",option+1) == 0)
4952 {
4953 if (*option == '+')
4954 break;
4955 i++;
4956 if (i == (long) argc)
4957 ThrowMogrifyException(OptionError,"MissingArgument",option);
4958 break;
4959 }
4960 if (LocaleCompare("filter",option+1) == 0)
4961 {
4962 long
4963 filter;
4964
4965 if (*option == '+')
4966 break;
4967 i++;
4968 if (i == (long) argc)
4969 ThrowMogrifyException(OptionError,"MissingArgument",option);
4970 filter=ParseMagickOption(MagickFilterOptions,MagickFalse,argv[i]);
4971 if (filter < 0)
4972 ThrowMogrifyException(OptionError,"UnrecognizedImageFilter",
4973 argv[i]);
4974 break;
4975 }
4976 if (LocaleCompare("flatten",option+1) == 0)
4977 break;
4978 if (LocaleCompare("flip",option+1) == 0)
4979 break;
4980 if (LocaleCompare("flop",option+1) == 0)
4981 break;
4982 if (LocaleCompare("floodfill",option+1) == 0)
4983 {
4984 if (*option == '+')
4985 break;
4986 i++;
4987 if (i == (long) argc)
4988 ThrowMogrifyException(OptionError,"MissingArgument",option);
4989 if (IsGeometry(argv[i]) == MagickFalse)
4990 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4991 i++;
4992 if (i == (long) argc)
4993 ThrowMogrifyException(OptionError,"MissingArgument",option);
4994 break;
4995 }
4996 if (LocaleCompare("font",option+1) == 0)
4997 {
4998 if (*option == '+')
4999 break;
5000 i++;
5001 if (i == (long) argc)
5002 ThrowMogrifyException(OptionError,"MissingArgument",option);
5003 break;
5004 }
5005 if (LocaleCompare("format",option+1) == 0)
5006 {
5007 (void) CopyMagickString(argv[i]+1,"sans",MaxTextExtent);
5008 (void) CloneString(&format,(char *) NULL);
5009 if (*option == '+')
5010 break;
5011 i++;
5012 if (i == (long) argc)
5013 ThrowMogrifyException(OptionError,"MissingArgument",option);
5014 (void) CloneString(&format,argv[i]);
5015 (void) CopyMagickString(image_info->filename,format,MaxTextExtent);
5016 (void) ConcatenateMagickString(image_info->filename,":",
5017 MaxTextExtent);
cristyd965a422010-03-03 17:47:35 +00005018 (void) SetImageInfo(image_info,0,exception);
cristy3ed852e2009-09-05 21:47:34 +00005019 if (*image_info->magick == '\0')
5020 ThrowMogrifyException(OptionError,"UnrecognizedImageFormat",
5021 format);
5022 break;
5023 }
5024 if (LocaleCompare("frame",option+1) == 0)
5025 {
5026 if (*option == '+')
5027 break;
5028 i++;
5029 if (i == (long) argc)
5030 ThrowMogrifyException(OptionError,"MissingArgument",option);
5031 if (IsGeometry(argv[i]) == MagickFalse)
5032 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5033 break;
5034 }
5035 if (LocaleCompare("function",option+1) == 0)
5036 {
5037 long
5038 op;
5039
5040 if (*option == '+')
5041 break;
5042 i++;
5043 if (i == (long) argc)
5044 ThrowMogrifyException(OptionError,"MissingArgument",option);
5045 op=ParseMagickOption(MagickFunctionOptions,MagickFalse,argv[i]);
5046 if (op < 0)
5047 ThrowMogrifyException(OptionError,"UnrecognizedFunction",argv[i]);
5048 i++;
5049 if (i == (long) (argc-1))
5050 ThrowMogrifyException(OptionError,"MissingArgument",option);
5051 break;
5052 }
5053 if (LocaleCompare("fuzz",option+1) == 0)
5054 {
5055 if (*option == '+')
5056 break;
5057 i++;
5058 if (i == (long) argc)
5059 ThrowMogrifyException(OptionError,"MissingArgument",option);
5060 if (IsGeometry(argv[i]) == MagickFalse)
5061 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5062 break;
5063 }
5064 if (LocaleCompare("fx",option+1) == 0)
5065 {
5066 if (*option == '+')
5067 break;
5068 i++;
5069 if (i == (long) (argc-1))
5070 ThrowMogrifyException(OptionError,"MissingArgument",option);
5071 break;
5072 }
5073 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5074 }
5075 case 'g':
5076 {
5077 if (LocaleCompare("gamma",option+1) == 0)
5078 {
5079 i++;
5080 if (i == (long) argc)
5081 ThrowMogrifyException(OptionError,"MissingArgument",option);
5082 if (IsGeometry(argv[i]) == MagickFalse)
5083 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5084 break;
5085 }
5086 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
5087 (LocaleCompare("gaussian",option+1) == 0))
5088 {
5089 i++;
5090 if (i == (long) argc)
5091 ThrowMogrifyException(OptionError,"MissingArgument",option);
5092 if (IsGeometry(argv[i]) == MagickFalse)
5093 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5094 break;
5095 }
5096 if (LocaleCompare("geometry",option+1) == 0)
5097 {
5098 if (*option == '+')
5099 break;
5100 i++;
5101 if (i == (long) argc)
5102 ThrowMogrifyException(OptionError,"MissingArgument",option);
5103 if (IsGeometry(argv[i]) == MagickFalse)
5104 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5105 break;
5106 }
5107 if (LocaleCompare("gravity",option+1) == 0)
5108 {
5109 long
5110 gravity;
5111
5112 if (*option == '+')
5113 break;
5114 i++;
5115 if (i == (long) argc)
5116 ThrowMogrifyException(OptionError,"MissingArgument",option);
5117 gravity=ParseMagickOption(MagickGravityOptions,MagickFalse,argv[i]);
5118 if (gravity < 0)
5119 ThrowMogrifyException(OptionError,"UnrecognizedGravityType",
5120 argv[i]);
5121 break;
5122 }
5123 if (LocaleCompare("green-primary",option+1) == 0)
5124 {
5125 if (*option == '+')
5126 break;
5127 i++;
5128 if (i == (long) argc)
5129 ThrowMogrifyException(OptionError,"MissingArgument",option);
5130 if (IsGeometry(argv[i]) == MagickFalse)
5131 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5132 break;
5133 }
5134 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5135 }
5136 case 'h':
5137 {
5138 if (LocaleCompare("hald-clut",option+1) == 0)
5139 break;
5140 if ((LocaleCompare("help",option+1) == 0) ||
5141 (LocaleCompare("-help",option+1) == 0))
5142 return(MogrifyUsage());
5143 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5144 }
5145 case 'i':
5146 {
5147 if (LocaleCompare("identify",option+1) == 0)
5148 break;
5149 if (LocaleCompare("idft",option+1) == 0)
5150 break;
5151 if (LocaleCompare("implode",option+1) == 0)
5152 {
5153 if (*option == '+')
5154 break;
5155 i++;
5156 if (i == (long) argc)
5157 ThrowMogrifyException(OptionError,"MissingArgument",option);
5158 if (IsGeometry(argv[i]) == MagickFalse)
5159 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5160 break;
5161 }
5162 if (LocaleCompare("intent",option+1) == 0)
5163 {
5164 long
5165 intent;
5166
5167 if (*option == '+')
5168 break;
5169 i++;
5170 if (i == (long) (argc-1))
5171 ThrowMogrifyException(OptionError,"MissingArgument",option);
5172 intent=ParseMagickOption(MagickIntentOptions,MagickFalse,argv[i]);
5173 if (intent < 0)
5174 ThrowMogrifyException(OptionError,"UnrecognizedIntentType",
5175 argv[i]);
5176 break;
5177 }
5178 if (LocaleCompare("interlace",option+1) == 0)
5179 {
5180 long
5181 interlace;
5182
5183 if (*option == '+')
5184 break;
5185 i++;
5186 if (i == (long) argc)
5187 ThrowMogrifyException(OptionError,"MissingArgument",option);
5188 interlace=ParseMagickOption(MagickInterlaceOptions,MagickFalse,
5189 argv[i]);
5190 if (interlace < 0)
5191 ThrowMogrifyException(OptionError,"UnrecognizedInterlaceType",
5192 argv[i]);
5193 break;
5194 }
cristyb32b90a2009-09-07 21:45:48 +00005195 if (LocaleCompare("interline-spacing",option+1) == 0)
5196 {
5197 if (*option == '+')
5198 break;
5199 i++;
5200 if (i == (long) (argc-1))
5201 ThrowMogrifyException(OptionError,"MissingArgument",option);
5202 if (IsGeometry(argv[i]) == MagickFalse)
5203 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5204 break;
5205 }
cristy3ed852e2009-09-05 21:47:34 +00005206 if (LocaleCompare("interpolate",option+1) == 0)
5207 {
5208 long
5209 interpolate;
5210
5211 if (*option == '+')
5212 break;
5213 i++;
5214 if (i == (long) argc)
5215 ThrowMogrifyException(OptionError,"MissingArgument",option);
5216 interpolate=ParseMagickOption(MagickInterpolateOptions,MagickFalse,
5217 argv[i]);
5218 if (interpolate < 0)
5219 ThrowMogrifyException(OptionError,"UnrecognizedInterpolateMethod",
5220 argv[i]);
5221 break;
5222 }
5223 if (LocaleCompare("interword-spacing",option+1) == 0)
5224 {
5225 if (*option == '+')
5226 break;
5227 i++;
5228 if (i == (long) (argc-1))
5229 ThrowMogrifyException(OptionError,"MissingArgument",option);
5230 if (IsGeometry(argv[i]) == MagickFalse)
5231 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5232 break;
5233 }
5234 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5235 }
5236 case 'k':
5237 {
5238 if (LocaleCompare("kerning",option+1) == 0)
5239 {
5240 if (*option == '+')
5241 break;
5242 i++;
5243 if (i == (long) (argc-1))
5244 ThrowMogrifyException(OptionError,"MissingArgument",option);
5245 if (IsGeometry(argv[i]) == MagickFalse)
5246 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5247 break;
5248 }
5249 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5250 }
5251 case 'l':
5252 {
5253 if (LocaleCompare("label",option+1) == 0)
5254 {
5255 if (*option == '+')
5256 break;
5257 i++;
5258 if (i == (long) argc)
5259 ThrowMogrifyException(OptionError,"MissingArgument",option);
5260 break;
5261 }
5262 if (LocaleCompare("lat",option+1) == 0)
5263 {
5264 if (*option == '+')
5265 break;
5266 i++;
5267 if (i == (long) argc)
5268 ThrowMogrifyException(OptionError,"MissingArgument",option);
5269 if (IsGeometry(argv[i]) == MagickFalse)
5270 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5271 }
5272 if (LocaleCompare("layers",option+1) == 0)
5273 {
5274 long
5275 type;
5276
5277 if (*option == '+')
5278 break;
5279 i++;
5280 if (i == (long) (argc-1))
5281 ThrowMogrifyException(OptionError,"MissingArgument",option);
5282 type=ParseMagickOption(MagickLayerOptions,MagickFalse,argv[i]);
5283 if (type < 0)
5284 ThrowMogrifyException(OptionError,"UnrecognizedLayerMethod",
5285 argv[i]);
5286 break;
5287 }
5288 if (LocaleCompare("level",option+1) == 0)
5289 {
5290 i++;
5291 if (i == (long) argc)
5292 ThrowMogrifyException(OptionError,"MissingArgument",option);
5293 if (IsGeometry(argv[i]) == MagickFalse)
5294 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5295 break;
5296 }
5297 if (LocaleCompare("level-colors",option+1) == 0)
5298 {
5299 i++;
5300 if (i == (long) argc)
5301 ThrowMogrifyException(OptionError,"MissingArgument",option);
5302 break;
5303 }
5304 if (LocaleCompare("linewidth",option+1) == 0)
5305 {
5306 if (*option == '+')
5307 break;
5308 i++;
5309 if (i == (long) argc)
5310 ThrowMogrifyException(OptionError,"MissingArgument",option);
5311 if (IsGeometry(argv[i]) == MagickFalse)
5312 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5313 break;
5314 }
5315 if (LocaleCompare("limit",option+1) == 0)
5316 {
5317 char
5318 *p;
5319
5320 double
5321 value;
5322
5323 long
5324 resource;
5325
5326 if (*option == '+')
5327 break;
5328 i++;
5329 if (i == (long) argc)
5330 ThrowMogrifyException(OptionError,"MissingArgument",option);
5331 resource=ParseMagickOption(MagickResourceOptions,MagickFalse,
5332 argv[i]);
5333 if (resource < 0)
5334 ThrowMogrifyException(OptionError,"UnrecognizedResourceType",
5335 argv[i]);
5336 i++;
5337 if (i == (long) argc)
5338 ThrowMogrifyException(OptionError,"MissingArgument",option);
5339 value=strtod(argv[i],&p);
5340 if ((p == argv[i]) && (LocaleCompare("unlimited",argv[i]) != 0))
5341 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5342 break;
5343 }
5344 if (LocaleCompare("liquid-rescale",option+1) == 0)
5345 {
5346 i++;
5347 if (i == (long) argc)
5348 ThrowMogrifyException(OptionError,"MissingArgument",option);
5349 if (IsGeometry(argv[i]) == MagickFalse)
5350 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5351 break;
5352 }
5353 if (LocaleCompare("list",option+1) == 0)
5354 {
5355 long
5356 list;
5357
5358 if (*option == '+')
5359 break;
5360 i++;
5361 if (i == (long) argc)
5362 ThrowMogrifyException(OptionError,"MissingArgument",option);
5363 list=ParseMagickOption(MagickListOptions,MagickFalse,argv[i]);
5364 if (list < 0)
5365 ThrowMogrifyException(OptionError,"UnrecognizedListType",argv[i]);
5366 (void) MogrifyImageInfo(image_info,(int) (i-j+1),(const char **)
5367 argv+j,exception);
5368 return(MagickTrue);
5369 }
5370 if (LocaleCompare("log",option+1) == 0)
5371 {
5372 if (*option == '+')
5373 break;
5374 i++;
5375 if ((i == (long) argc) ||
5376 (strchr(argv[i],'%') == (char *) NULL))
5377 ThrowMogrifyException(OptionError,"MissingArgument",option);
5378 break;
5379 }
5380 if (LocaleCompare("loop",option+1) == 0)
5381 {
5382 if (*option == '+')
5383 break;
5384 i++;
5385 if (i == (long) argc)
5386 ThrowMogrifyException(OptionError,"MissingArgument",option);
5387 if (IsGeometry(argv[i]) == MagickFalse)
5388 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5389 break;
5390 }
5391 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5392 }
5393 case 'm':
5394 {
5395 if (LocaleCompare("map",option+1) == 0)
5396 {
5397 global_colormap=(*option == '+') ? MagickTrue : MagickFalse;
5398 if (*option == '+')
5399 break;
5400 i++;
5401 if (i == (long) argc)
5402 ThrowMogrifyException(OptionError,"MissingArgument",option);
5403 break;
5404 }
5405 if (LocaleCompare("mask",option+1) == 0)
5406 {
5407 if (*option == '+')
5408 break;
5409 i++;
5410 if (i == (long) argc)
5411 ThrowMogrifyException(OptionError,"MissingArgument",option);
5412 break;
5413 }
5414 if (LocaleCompare("matte",option+1) == 0)
5415 break;
5416 if (LocaleCompare("mattecolor",option+1) == 0)
5417 {
5418 if (*option == '+')
5419 break;
5420 i++;
5421 if (i == (long) argc)
5422 ThrowMogrifyException(OptionError,"MissingArgument",option);
5423 break;
5424 }
cristyf40785b2010-03-06 02:27:27 +00005425 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00005426 break;
cristyf40785b2010-03-06 02:27:27 +00005427 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00005428 break;
cristy3ed852e2009-09-05 21:47:34 +00005429 if (LocaleCompare("modulate",option+1) == 0)
5430 {
5431 if (*option == '+')
5432 break;
5433 i++;
5434 if (i == (long) argc)
5435 ThrowMogrifyException(OptionError,"MissingArgument",option);
5436 if (IsGeometry(argv[i]) == MagickFalse)
5437 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5438 break;
5439 }
5440 if (LocaleCompare("median",option+1) == 0)
5441 {
5442 if (*option == '+')
5443 break;
5444 i++;
5445 if (i == (long) argc)
5446 ThrowMogrifyException(OptionError,"MissingArgument",option);
5447 if (IsGeometry(argv[i]) == MagickFalse)
5448 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5449 break;
5450 }
5451 if (LocaleCompare("monitor",option+1) == 0)
5452 break;
5453 if (LocaleCompare("monochrome",option+1) == 0)
5454 break;
5455 if (LocaleCompare("morph",option+1) == 0)
5456 {
5457 if (*option == '+')
5458 break;
5459 i++;
5460 if (i == (long) (argc-1))
5461 ThrowMogrifyException(OptionError,"MissingArgument",option);
5462 if (IsGeometry(argv[i]) == MagickFalse)
5463 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5464 break;
5465 }
anthony29188a82010-01-22 10:12:34 +00005466 if (LocaleCompare("morphology",option+1) == 0)
5467 {
5468 long
5469 op;
5470
5471 char
5472 token[MaxTextExtent];
5473
5474 i++;
5475 if (i == (long) argc)
5476 ThrowMogrifyException(OptionError,"MissingArgument",option);
5477 GetMagickToken(argv[i],NULL,token);
5478 op=ParseMagickOption(MagickMorphologyOptions,MagickFalse,token);
5479 if (op < 0)
5480 ThrowMogrifyException(OptionError,"UnrecognizedMorphologyMethod",
cristyf0c78232010-03-15 12:53:40 +00005481 token);
anthony29188a82010-01-22 10:12:34 +00005482 i++;
5483 if (i == (long) (argc-1))
5484 ThrowMogrifyException(OptionError,"MissingArgument",option);
5485 GetMagickToken(argv[i],NULL,token);
cristyf0c78232010-03-15 12:53:40 +00005486 if (isalpha((int) ((unsigned char) *token)) != 0)
anthony29188a82010-01-22 10:12:34 +00005487 {
5488 op=ParseMagickOption(MagickKernelOptions,MagickFalse,token);
5489 if (op < 0)
5490 ThrowMogrifyException(OptionError,"UnrecognizedKernelType",
cristyf0c78232010-03-15 12:53:40 +00005491 token);
anthony29188a82010-01-22 10:12:34 +00005492 }
anthony29188a82010-01-22 10:12:34 +00005493 break;
5494 }
cristy3ed852e2009-09-05 21:47:34 +00005495 if (LocaleCompare("mosaic",option+1) == 0)
5496 break;
5497 if (LocaleCompare("motion-blur",option+1) == 0)
5498 {
5499 if (*option == '+')
5500 break;
5501 i++;
5502 if (i == (long) argc)
5503 ThrowMogrifyException(OptionError,"MissingArgument",option);
5504 if (IsGeometry(argv[i]) == MagickFalse)
5505 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5506 break;
5507 }
5508 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5509 }
5510 case 'n':
5511 {
5512 if (LocaleCompare("negate",option+1) == 0)
5513 break;
5514 if (LocaleCompare("noise",option+1) == 0)
5515 {
5516 i++;
5517 if (i == (long) argc)
5518 ThrowMogrifyException(OptionError,"MissingArgument",option);
5519 if (*option == '+')
5520 {
5521 long
5522 noise;
5523
5524 noise=ParseMagickOption(MagickNoiseOptions,MagickFalse,argv[i]);
5525 if (noise < 0)
5526 ThrowMogrifyException(OptionError,"UnrecognizedNoiseType",
5527 argv[i]);
5528 break;
5529 }
5530 if (IsGeometry(argv[i]) == MagickFalse)
5531 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5532 break;
5533 }
5534 if (LocaleCompare("noop",option+1) == 0)
5535 break;
5536 if (LocaleCompare("normalize",option+1) == 0)
5537 break;
5538 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5539 }
5540 case 'o':
5541 {
5542 if (LocaleCompare("opaque",option+1) == 0)
5543 {
cristy3ed852e2009-09-05 21:47:34 +00005544 i++;
5545 if (i == (long) argc)
5546 ThrowMogrifyException(OptionError,"MissingArgument",option);
5547 break;
5548 }
5549 if (LocaleCompare("ordered-dither",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("orient",option+1) == 0)
5559 {
5560 long
5561 orientation;
5562
5563 orientation=UndefinedOrientation;
5564 if (*option == '+')
5565 break;
5566 i++;
5567 if (i == (long) (argc-1))
5568 ThrowMogrifyException(OptionError,"MissingArgument",option);
5569 orientation=ParseMagickOption(MagickOrientationOptions,MagickFalse,
5570 argv[i]);
5571 if (orientation < 0)
5572 ThrowMogrifyException(OptionError,"UnrecognizedImageOrientation",
5573 argv[i]);
5574 break;
5575 }
5576 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5577 }
5578 case 'p':
5579 {
5580 if (LocaleCompare("page",option+1) == 0)
5581 {
5582 if (*option == '+')
5583 break;
5584 i++;
5585 if (i == (long) argc)
5586 ThrowMogrifyException(OptionError,"MissingArgument",option);
5587 break;
5588 }
5589 if (LocaleCompare("paint",option+1) == 0)
5590 {
5591 if (*option == '+')
5592 break;
5593 i++;
5594 if (i == (long) argc)
5595 ThrowMogrifyException(OptionError,"MissingArgument",option);
5596 if (IsGeometry(argv[i]) == MagickFalse)
5597 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5598 break;
5599 }
5600 if (LocaleCompare("path",option+1) == 0)
5601 {
5602 (void) CloneString(&path,(char *) NULL);
5603 if (*option == '+')
5604 break;
5605 i++;
5606 if (i == (long) argc)
5607 ThrowMogrifyException(OptionError,"MissingArgument",option);
5608 (void) CloneString(&path,argv[i]);
5609 break;
5610 }
5611 if (LocaleCompare("pointsize",option+1) == 0)
5612 {
5613 if (*option == '+')
5614 break;
5615 i++;
5616 if (i == (long) argc)
5617 ThrowMogrifyException(OptionError,"MissingArgument",option);
5618 if (IsGeometry(argv[i]) == MagickFalse)
5619 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5620 break;
5621 }
5622 if (LocaleCompare("polaroid",option+1) == 0)
5623 {
5624 if (*option == '+')
5625 break;
5626 i++;
5627 if (i == (long) argc)
5628 ThrowMogrifyException(OptionError,"MissingArgument",option);
5629 if (IsGeometry(argv[i]) == MagickFalse)
5630 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5631 break;
5632 }
5633 if (LocaleCompare("posterize",option+1) == 0)
5634 {
5635 if (*option == '+')
5636 break;
5637 i++;
5638 if (i == (long) argc)
5639 ThrowMogrifyException(OptionError,"MissingArgument",option);
5640 if (IsGeometry(argv[i]) == MagickFalse)
5641 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5642 break;
5643 }
cristye7f51092010-01-17 00:39:37 +00005644 if (LocaleCompare("precision",option+1) == 0)
5645 {
5646 if (*option == '+')
5647 break;
5648 i++;
5649 if (i == (long) argc)
5650 ThrowMogrifyException(OptionError,"MissingArgument",option);
5651 if (IsGeometry(argv[i]) == MagickFalse)
5652 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5653 break;
5654 }
cristy3ed852e2009-09-05 21:47:34 +00005655 if (LocaleCompare("print",option+1) == 0)
5656 {
5657 if (*option == '+')
5658 break;
5659 i++;
5660 if (i == (long) argc)
5661 ThrowMogrifyException(OptionError,"MissingArgument",option);
5662 break;
5663 }
5664 if (LocaleCompare("process",option+1) == 0)
5665 {
5666 if (*option == '+')
5667 break;
5668 i++;
5669 if (i == (long) (argc-1))
5670 ThrowMogrifyException(OptionError,"MissingArgument",option);
5671 break;
5672 }
5673 if (LocaleCompare("profile",option+1) == 0)
5674 {
5675 i++;
5676 if (i == (long) argc)
5677 ThrowMogrifyException(OptionError,"MissingArgument",option);
5678 break;
5679 }
5680 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5681 }
5682 case 'q':
5683 {
5684 if (LocaleCompare("quality",option+1) == 0)
5685 {
5686 if (*option == '+')
5687 break;
5688 i++;
5689 if (i == (long) argc)
5690 ThrowMogrifyException(OptionError,"MissingArgument",option);
5691 if (IsGeometry(argv[i]) == MagickFalse)
5692 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5693 break;
5694 }
5695 if (LocaleCompare("quantize",option+1) == 0)
5696 {
5697 long
5698 colorspace;
5699
5700 if (*option == '+')
5701 break;
5702 i++;
5703 if (i == (long) (argc-1))
5704 ThrowMogrifyException(OptionError,"MissingArgument",option);
5705 colorspace=ParseMagickOption(MagickColorspaceOptions,MagickFalse,
5706 argv[i]);
5707 if (colorspace < 0)
5708 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
5709 argv[i]);
5710 break;
5711 }
5712 if (LocaleCompare("quiet",option+1) == 0)
5713 break;
5714 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5715 }
5716 case 'r':
5717 {
5718 if (LocaleCompare("radial-blur",option+1) == 0)
5719 {
5720 i++;
5721 if (i == (long) argc)
5722 ThrowMogrifyException(OptionError,"MissingArgument",option);
5723 if (IsGeometry(argv[i]) == MagickFalse)
5724 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5725 break;
5726 }
5727 if (LocaleCompare("raise",option+1) == 0)
5728 {
5729 i++;
5730 if (i == (long) argc)
5731 ThrowMogrifyException(OptionError,"MissingArgument",option);
5732 if (IsGeometry(argv[i]) == MagickFalse)
5733 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5734 break;
5735 }
5736 if (LocaleCompare("random-threshold",option+1) == 0)
5737 {
5738 if (*option == '+')
5739 break;
5740 i++;
5741 if (i == (long) argc)
5742 ThrowMogrifyException(OptionError,"MissingArgument",option);
5743 if (IsGeometry(argv[i]) == MagickFalse)
5744 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5745 break;
5746 }
cristye6365592010-04-02 17:31:23 +00005747 if (LocaleCompare("recolor",option+1) == 0)
5748 {
5749 if (*option == '+')
5750 break;
5751 i++;
5752 if (i == (long) (argc-1))
5753 ThrowMogrifyException(OptionError,"MissingArgument",option);
5754 if (IsGeometry(argv[i]) == MagickFalse)
5755 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5756 break;
5757 }
cristy3ed852e2009-09-05 21:47:34 +00005758 if (LocaleCompare("red-primary",option+1) == 0)
5759 {
5760 if (*option == '+')
5761 break;
5762 i++;
5763 if (i == (long) argc)
5764 ThrowMogrifyException(OptionError,"MissingArgument",option);
5765 if (IsGeometry(argv[i]) == MagickFalse)
5766 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5767 }
5768 if (LocaleCompare("region",option+1) == 0)
5769 {
5770 if (*option == '+')
5771 break;
5772 i++;
5773 if (i == (long) argc)
5774 ThrowMogrifyException(OptionError,"MissingArgument",option);
5775 if (IsGeometry(argv[i]) == MagickFalse)
5776 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5777 break;
5778 }
cristyf0c78232010-03-15 12:53:40 +00005779 if (LocaleCompare("remap",option+1) == 0)
5780 {
5781 if (*option == '+')
5782 break;
5783 i++;
5784 if (i == (long) (argc-1))
5785 ThrowMogrifyException(OptionError,"MissingArgument",option);
5786 break;
5787 }
cristy3ed852e2009-09-05 21:47:34 +00005788 if (LocaleCompare("render",option+1) == 0)
5789 break;
5790 if (LocaleCompare("repage",option+1) == 0)
5791 {
5792 if (*option == '+')
5793 break;
5794 i++;
5795 if (i == (long) argc)
5796 ThrowMogrifyException(OptionError,"MissingArgument",option);
5797 if (IsGeometry(argv[i]) == MagickFalse)
5798 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5799 break;
5800 }
5801 if (LocaleCompare("resample",option+1) == 0)
5802 {
5803 if (*option == '+')
5804 break;
5805 i++;
5806 if (i == (long) argc)
5807 ThrowMogrifyException(OptionError,"MissingArgument",option);
5808 if (IsGeometry(argv[i]) == MagickFalse)
5809 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5810 break;
5811 }
5812 if (LocaleCompare("resize",option+1) == 0)
5813 {
5814 if (*option == '+')
5815 break;
5816 i++;
5817 if (i == (long) argc)
5818 ThrowMogrifyException(OptionError,"MissingArgument",option);
5819 if (IsGeometry(argv[i]) == MagickFalse)
5820 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5821 break;
5822 }
5823 if (LocaleCompare("reverse",option+1) == 0)
5824 break;
5825 if (LocaleCompare("roll",option+1) == 0)
5826 {
5827 if (*option == '+')
5828 break;
5829 i++;
5830 if (i == (long) argc)
5831 ThrowMogrifyException(OptionError,"MissingArgument",option);
5832 if (IsGeometry(argv[i]) == MagickFalse)
5833 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5834 break;
5835 }
5836 if (LocaleCompare("rotate",option+1) == 0)
5837 {
5838 i++;
5839 if (i == (long) argc)
5840 ThrowMogrifyException(OptionError,"MissingArgument",option);
5841 if (IsGeometry(argv[i]) == MagickFalse)
5842 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5843 break;
5844 }
5845 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5846 }
5847 case 's':
5848 {
5849 if (LocaleCompare("sample",option+1) == 0)
5850 {
5851 if (*option == '+')
5852 break;
5853 i++;
5854 if (i == (long) argc)
5855 ThrowMogrifyException(OptionError,"MissingArgument",option);
5856 if (IsGeometry(argv[i]) == MagickFalse)
5857 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5858 break;
5859 }
5860 if (LocaleCompare("sampling-factor",option+1) == 0)
5861 {
5862 if (*option == '+')
5863 break;
5864 i++;
5865 if (i == (long) argc)
5866 ThrowMogrifyException(OptionError,"MissingArgument",option);
5867 if (IsGeometry(argv[i]) == MagickFalse)
5868 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5869 break;
5870 }
5871 if (LocaleCompare("scale",option+1) == 0)
5872 {
5873 if (*option == '+')
5874 break;
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("scene",option+1) == 0)
5883 {
5884 if (*option == '+')
5885 break;
5886 i++;
5887 if (i == (long) argc)
5888 ThrowMogrifyException(OptionError,"MissingArgument",option);
5889 if (IsGeometry(argv[i]) == MagickFalse)
5890 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5891 break;
5892 }
5893 if (LocaleCompare("seed",option+1) == 0)
5894 {
5895 if (*option == '+')
5896 break;
5897 i++;
5898 if (i == (long) argc)
5899 ThrowMogrifyException(OptionError,"MissingArgument",option);
5900 if (IsGeometry(argv[i]) == MagickFalse)
5901 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5902 break;
5903 }
5904 if (LocaleCompare("segment",option+1) == 0)
5905 {
5906 if (*option == '+')
5907 break;
5908 i++;
5909 if (i == (long) argc)
5910 ThrowMogrifyException(OptionError,"MissingArgument",option);
5911 if (IsGeometry(argv[i]) == MagickFalse)
5912 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5913 break;
5914 }
5915 if (LocaleCompare("selective-blur",option+1) == 0)
5916 {
5917 i++;
5918 if (i == (long) argc)
5919 ThrowMogrifyException(OptionError,"MissingArgument",option);
5920 if (IsGeometry(argv[i]) == MagickFalse)
5921 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5922 break;
5923 }
5924 if (LocaleCompare("separate",option+1) == 0)
5925 break;
5926 if (LocaleCompare("sepia-tone",option+1) == 0)
5927 {
5928 if (*option == '+')
5929 break;
5930 i++;
5931 if (i == (long) argc)
5932 ThrowMogrifyException(OptionError,"MissingArgument",option);
5933 if (IsGeometry(argv[i]) == MagickFalse)
5934 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5935 break;
5936 }
5937 if (LocaleCompare("set",option+1) == 0)
5938 {
5939 i++;
5940 if (i == (long) argc)
5941 ThrowMogrifyException(OptionError,"MissingArgument",option);
5942 if (*option == '+')
5943 break;
5944 i++;
5945 if (i == (long) argc)
5946 ThrowMogrifyException(OptionError,"MissingArgument",option);
5947 break;
5948 }
5949 if (LocaleCompare("shade",option+1) == 0)
5950 {
5951 i++;
5952 if (i == (long) argc)
5953 ThrowMogrifyException(OptionError,"MissingArgument",option);
5954 if (IsGeometry(argv[i]) == MagickFalse)
5955 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5956 break;
5957 }
5958 if (LocaleCompare("shadow",option+1) == 0)
5959 {
5960 if (*option == '+')
5961 break;
5962 i++;
5963 if (i == (long) argc)
5964 ThrowMogrifyException(OptionError,"MissingArgument",option);
5965 if (IsGeometry(argv[i]) == MagickFalse)
5966 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5967 break;
5968 }
5969 if (LocaleCompare("sharpen",option+1) == 0)
5970 {
5971 i++;
5972 if (i == (long) argc)
5973 ThrowMogrifyException(OptionError,"MissingArgument",option);
5974 if (IsGeometry(argv[i]) == MagickFalse)
5975 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5976 break;
5977 }
5978 if (LocaleCompare("shave",option+1) == 0)
5979 {
5980 if (*option == '+')
5981 break;
5982 i++;
5983 if (i == (long) argc)
5984 ThrowMogrifyException(OptionError,"MissingArgument",option);
5985 if (IsGeometry(argv[i]) == MagickFalse)
5986 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5987 break;
5988 }
5989 if (LocaleCompare("shear",option+1) == 0)
5990 {
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("sigmoidal-contrast",option+1) == 0)
5999 {
6000 i++;
6001 if (i == (long) (argc-1))
6002 ThrowMogrifyException(OptionError,"MissingArgument",option);
6003 if (IsGeometry(argv[i]) == MagickFalse)
6004 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6005 break;
6006 }
6007 if (LocaleCompare("size",option+1) == 0)
6008 {
6009 if (*option == '+')
6010 break;
6011 i++;
6012 if (i == (long) argc)
6013 ThrowMogrifyException(OptionError,"MissingArgument",option);
6014 if (IsGeometry(argv[i]) == MagickFalse)
6015 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6016 break;
6017 }
6018 if (LocaleCompare("sketch",option+1) == 0)
6019 {
6020 if (*option == '+')
6021 break;
6022 i++;
6023 if (i == (long) argc)
6024 ThrowMogrifyException(OptionError,"MissingArgument",option);
6025 if (IsGeometry(argv[i]) == MagickFalse)
6026 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6027 break;
6028 }
6029 if (LocaleCompare("solarize",option+1) == 0)
6030 {
6031 if (*option == '+')
6032 break;
6033 i++;
6034 if (i == (long) argc)
6035 ThrowMogrifyException(OptionError,"MissingArgument",option);
6036 if (IsGeometry(argv[i]) == MagickFalse)
6037 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6038 break;
6039 }
6040 if (LocaleCompare("sparse-color",option+1) == 0)
6041 {
6042 long
6043 op;
6044
6045 i++;
6046 if (i == (long) argc)
6047 ThrowMogrifyException(OptionError,"MissingArgument",option);
6048 op=ParseMagickOption(MagickSparseColorOptions,MagickFalse,argv[i]);
6049 if (op < 0)
6050 ThrowMogrifyException(OptionError,"UnrecognizedSparseColorMethod",
6051 argv[i]);
6052 i++;
6053 if (i == (long) (argc-1))
6054 ThrowMogrifyException(OptionError,"MissingArgument",option);
6055 break;
6056 }
6057 if (LocaleCompare("spread",option+1) == 0)
6058 {
6059 if (*option == '+')
6060 break;
6061 i++;
6062 if (i == (long) argc)
6063 ThrowMogrifyException(OptionError,"MissingArgument",option);
6064 if (IsGeometry(argv[i]) == MagickFalse)
6065 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6066 break;
6067 }
6068 if (LocaleCompare("stretch",option+1) == 0)
6069 {
6070 long
6071 stretch;
6072
6073 if (*option == '+')
6074 break;
6075 i++;
6076 if (i == (long) (argc-1))
6077 ThrowMogrifyException(OptionError,"MissingArgument",option);
6078 stretch=ParseMagickOption(MagickStretchOptions,MagickFalse,argv[i]);
6079 if (stretch < 0)
6080 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
6081 argv[i]);
6082 break;
6083 }
6084 if (LocaleCompare("strip",option+1) == 0)
6085 break;
6086 if (LocaleCompare("stroke",option+1) == 0)
6087 {
6088 if (*option == '+')
6089 break;
6090 i++;
6091 if (i == (long) argc)
6092 ThrowMogrifyException(OptionError,"MissingArgument",option);
6093 break;
6094 }
6095 if (LocaleCompare("strokewidth",option+1) == 0)
6096 {
6097 if (*option == '+')
6098 break;
6099 i++;
6100 if (i == (long) argc)
6101 ThrowMogrifyException(OptionError,"MissingArgument",option);
6102 if (IsGeometry(argv[i]) == MagickFalse)
6103 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6104 break;
6105 }
6106 if (LocaleCompare("style",option+1) == 0)
6107 {
6108 long
6109 style;
6110
6111 if (*option == '+')
6112 break;
6113 i++;
6114 if (i == (long) (argc-1))
6115 ThrowMogrifyException(OptionError,"MissingArgument",option);
6116 style=ParseMagickOption(MagickStyleOptions,MagickFalse,argv[i]);
6117 if (style < 0)
6118 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
6119 argv[i]);
6120 break;
6121 }
6122 if (LocaleCompare("swirl",option+1) == 0)
6123 {
6124 if (*option == '+')
6125 break;
6126 i++;
6127 if (i == (long) argc)
6128 ThrowMogrifyException(OptionError,"MissingArgument",option);
6129 if (IsGeometry(argv[i]) == MagickFalse)
6130 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6131 break;
6132 }
6133 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6134 }
6135 case 't':
6136 {
6137 if (LocaleCompare("taint",option+1) == 0)
6138 break;
6139 if (LocaleCompare("texture",option+1) == 0)
6140 {
6141 if (*option == '+')
6142 break;
6143 i++;
6144 if (i == (long) argc)
6145 ThrowMogrifyException(OptionError,"MissingArgument",option);
6146 break;
6147 }
6148 if (LocaleCompare("tile",option+1) == 0)
6149 {
6150 if (*option == '+')
6151 break;
6152 i++;
6153 if (i == (long) (argc-1))
6154 ThrowMogrifyException(OptionError,"MissingArgument",option);
6155 break;
6156 }
6157 if (LocaleCompare("tile-offset",option+1) == 0)
6158 {
6159 if (*option == '+')
6160 break;
6161 i++;
6162 if (i == (long) argc)
6163 ThrowMogrifyException(OptionError,"MissingArgument",option);
6164 if (IsGeometry(argv[i]) == MagickFalse)
6165 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6166 break;
6167 }
6168 if (LocaleCompare("tint",option+1) == 0)
6169 {
6170 if (*option == '+')
6171 break;
6172 i++;
6173 if (i == (long) (argc-1))
6174 ThrowMogrifyException(OptionError,"MissingArgument",option);
6175 if (IsGeometry(argv[i]) == MagickFalse)
6176 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6177 break;
6178 }
6179 if (LocaleCompare("transform",option+1) == 0)
6180 break;
6181 if (LocaleCompare("transpose",option+1) == 0)
6182 break;
6183 if (LocaleCompare("transverse",option+1) == 0)
6184 break;
6185 if (LocaleCompare("threshold",option+1) == 0)
6186 {
6187 if (*option == '+')
6188 break;
6189 i++;
6190 if (i == (long) argc)
6191 ThrowMogrifyException(OptionError,"MissingArgument",option);
6192 if (IsGeometry(argv[i]) == MagickFalse)
6193 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6194 break;
6195 }
6196 if (LocaleCompare("thumbnail",option+1) == 0)
6197 {
6198 if (*option == '+')
6199 break;
6200 i++;
6201 if (i == (long) argc)
6202 ThrowMogrifyException(OptionError,"MissingArgument",option);
6203 if (IsGeometry(argv[i]) == MagickFalse)
6204 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6205 break;
6206 }
6207 if (LocaleCompare("transparent",option+1) == 0)
6208 {
6209 i++;
6210 if (i == (long) argc)
6211 ThrowMogrifyException(OptionError,"MissingArgument",option);
6212 break;
6213 }
6214 if (LocaleCompare("transparent-color",option+1) == 0)
6215 {
6216 if (*option == '+')
6217 break;
6218 i++;
6219 if (i == (long) (argc-1))
6220 ThrowMogrifyException(OptionError,"MissingArgument",option);
6221 break;
6222 }
6223 if (LocaleCompare("treedepth",option+1) == 0)
6224 {
6225 if (*option == '+')
6226 break;
6227 i++;
6228 if (i == (long) argc)
6229 ThrowMogrifyException(OptionError,"MissingArgument",option);
6230 if (IsGeometry(argv[i]) == MagickFalse)
6231 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6232 break;
6233 }
6234 if (LocaleCompare("trim",option+1) == 0)
6235 break;
6236 if (LocaleCompare("type",option+1) == 0)
6237 {
6238 long
6239 type;
6240
6241 if (*option == '+')
6242 break;
6243 i++;
6244 if (i == (long) argc)
6245 ThrowMogrifyException(OptionError,"MissingArgument",option);
6246 type=ParseMagickOption(MagickTypeOptions,MagickFalse,argv[i]);
6247 if (type < 0)
6248 ThrowMogrifyException(OptionError,"UnrecognizedImageType",
6249 argv[i]);
6250 break;
6251 }
6252 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6253 }
6254 case 'u':
6255 {
6256 if (LocaleCompare("undercolor",option+1) == 0)
6257 {
6258 if (*option == '+')
6259 break;
6260 i++;
6261 if (i == (long) argc)
6262 ThrowMogrifyException(OptionError,"MissingArgument",option);
6263 break;
6264 }
6265 if (LocaleCompare("unique-colors",option+1) == 0)
6266 break;
6267 if (LocaleCompare("units",option+1) == 0)
6268 {
6269 long
6270 units;
6271
6272 if (*option == '+')
6273 break;
6274 i++;
6275 if (i == (long) argc)
6276 ThrowMogrifyException(OptionError,"MissingArgument",option);
6277 units=ParseMagickOption(MagickResolutionOptions,MagickFalse,
6278 argv[i]);
6279 if (units < 0)
6280 ThrowMogrifyException(OptionError,"UnrecognizedUnitsType",
6281 argv[i]);
6282 break;
6283 }
6284 if (LocaleCompare("unsharp",option+1) == 0)
6285 {
6286 i++;
6287 if (i == (long) argc)
6288 ThrowMogrifyException(OptionError,"MissingArgument",option);
6289 if (IsGeometry(argv[i]) == MagickFalse)
6290 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6291 break;
6292 }
6293 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6294 }
6295 case 'v':
6296 {
6297 if (LocaleCompare("verbose",option+1) == 0)
6298 {
6299 image_info->verbose=(*option == '-') ? MagickTrue : MagickFalse;
6300 break;
6301 }
6302 if ((LocaleCompare("version",option+1) == 0) ||
6303 (LocaleCompare("-version",option+1) == 0))
6304 {
6305 (void) fprintf(stdout,"Version: %s\n",
6306 GetMagickVersion((unsigned long *) NULL));
cristy610b2e22009-10-22 14:59:43 +00006307 (void) fprintf(stdout,"Copyright: %s\n",GetMagickCopyright());
6308 (void) fprintf(stdout,"Features: %s\n\n",GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00006309 break;
6310 }
6311 if (LocaleCompare("view",option+1) == 0)
6312 {
6313 if (*option == '+')
6314 break;
6315 i++;
6316 if (i == (long) argc)
6317 ThrowMogrifyException(OptionError,"MissingArgument",option);
6318 break;
6319 }
6320 if (LocaleCompare("vignette",option+1) == 0)
6321 {
6322 if (*option == '+')
6323 break;
6324 i++;
6325 if (i == (long) argc)
6326 ThrowMogrifyException(OptionError,"MissingArgument",option);
6327 if (IsGeometry(argv[i]) == MagickFalse)
6328 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6329 break;
6330 }
6331 if (LocaleCompare("virtual-pixel",option+1) == 0)
6332 {
6333 long
6334 method;
6335
6336 if (*option == '+')
6337 break;
6338 i++;
6339 if (i == (long) argc)
6340 ThrowMogrifyException(OptionError,"MissingArgument",option);
6341 method=ParseMagickOption(MagickVirtualPixelOptions,MagickFalse,
6342 argv[i]);
6343 if (method < 0)
6344 ThrowMogrifyException(OptionError,
6345 "UnrecognizedVirtualPixelMethod",argv[i]);
6346 break;
6347 }
6348 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6349 }
6350 case 'w':
6351 {
6352 if (LocaleCompare("wave",option+1) == 0)
6353 {
6354 i++;
6355 if (i == (long) argc)
6356 ThrowMogrifyException(OptionError,"MissingArgument",option);
6357 if (IsGeometry(argv[i]) == MagickFalse)
6358 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6359 break;
6360 }
6361 if (LocaleCompare("weight",option+1) == 0)
6362 {
6363 if (*option == '+')
6364 break;
6365 i++;
6366 if (i == (long) (argc-1))
6367 ThrowMogrifyException(OptionError,"MissingArgument",option);
6368 break;
6369 }
6370 if (LocaleCompare("white-point",option+1) == 0)
6371 {
6372 if (*option == '+')
6373 break;
6374 i++;
6375 if (i == (long) argc)
6376 ThrowMogrifyException(OptionError,"MissingArgument",option);
6377 if (IsGeometry(argv[i]) == MagickFalse)
6378 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6379 break;
6380 }
6381 if (LocaleCompare("white-threshold",option+1) == 0)
6382 {
6383 if (*option == '+')
6384 break;
6385 i++;
6386 if (i == (long) argc)
6387 ThrowMogrifyException(OptionError,"MissingArgument",option);
6388 if (IsGeometry(argv[i]) == MagickFalse)
6389 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6390 break;
6391 }
6392 if (LocaleCompare("write",option+1) == 0)
6393 {
6394 i++;
6395 if (i == (long) (argc-1))
6396 ThrowMogrifyException(OptionError,"MissingArgument",option);
6397 break;
6398 }
6399 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6400 }
6401 case '?':
6402 break;
6403 default:
6404 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6405 }
6406 fire=ParseMagickOption(MagickImageListOptions,MagickFalse,option+1) < 0 ?
6407 MagickFalse : MagickTrue;
6408 if (fire != MagickFalse)
6409 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
6410 }
6411 if (k != 0)
6412 ThrowMogrifyException(OptionError,"UnbalancedParenthesis",argv[i]);
6413 if (i != argc)
6414 ThrowMogrifyException(OptionError,"MissingAnImageFilename",argv[i]);
6415 DestroyMogrify();
6416 return(status != 0 ? MagickTrue : MagickFalse);
6417}
6418
6419/*
6420%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6421% %
6422% %
6423% %
6424+ M o g r i f y I m a g e I n f o %
6425% %
6426% %
6427% %
6428%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6429%
6430% MogrifyImageInfo() applies image processing settings to the image as
6431% prescribed by command line options.
6432%
6433% The format of the MogrifyImageInfo method is:
6434%
6435% MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,const int argc,
6436% const char **argv,ExceptionInfo *exception)
6437%
6438% A description of each parameter follows:
6439%
6440% o image_info: the image info..
6441%
6442% o argc: Specifies a pointer to an integer describing the number of
6443% elements in the argument vector.
6444%
6445% o argv: Specifies a pointer to a text array containing the command line
6446% arguments.
6447%
6448% o exception: return any errors or warnings in this structure.
6449%
6450*/
6451WandExport MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,
6452 const int argc,const char **argv,ExceptionInfo *exception)
6453{
6454 const char
6455 *option;
6456
6457 GeometryInfo
6458 geometry_info;
6459
6460 long
6461 count;
6462
6463 register long
6464 i;
6465
6466 /*
6467 Initialize method variables.
6468 */
6469 assert(image_info != (ImageInfo *) NULL);
6470 assert(image_info->signature == MagickSignature);
6471 if (image_info->debug != MagickFalse)
6472 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
6473 image_info->filename);
6474 if (argc < 0)
6475 return(MagickTrue);
6476 /*
6477 Set the image settings.
6478 */
6479 for (i=0; i < (long) argc; i++)
6480 {
6481 option=argv[i];
6482 if (IsMagickOption(option) == MagickFalse)
6483 continue;
6484 count=MagickMax(ParseMagickOption(MagickCommandOptions,MagickFalse,option),
6485 0L);
6486 if ((i+count) >= argc)
6487 break;
6488 switch (*(option+1))
6489 {
6490 case 'a':
6491 {
6492 if (LocaleCompare("adjoin",option+1) == 0)
6493 {
6494 image_info->adjoin=(*option == '-') ? MagickTrue : MagickFalse;
6495 break;
6496 }
6497 if (LocaleCompare("antialias",option+1) == 0)
6498 {
6499 image_info->antialias=(*option == '-') ? MagickTrue : MagickFalse;
6500 break;
6501 }
6502 if (LocaleCompare("attenuate",option+1) == 0)
6503 {
6504 if (*option == '+')
6505 {
6506 (void) DeleteImageOption(image_info,option+1);
6507 break;
6508 }
6509 (void) SetImageOption(image_info,option+1,argv[i+1]);
6510 break;
6511 }
6512 if (LocaleCompare("authenticate",option+1) == 0)
6513 {
6514 if (*option == '+')
6515 (void) CloneString(&image_info->authenticate,(char *) NULL);
6516 else
6517 (void) CloneString(&image_info->authenticate,argv[i+1]);
6518 break;
6519 }
6520 break;
6521 }
6522 case 'b':
6523 {
6524 if (LocaleCompare("background",option+1) == 0)
6525 {
6526 if (*option == '+')
6527 {
6528 (void) DeleteImageOption(image_info,option+1);
6529 (void) QueryColorDatabase(BackgroundColor,
6530 &image_info->background_color,exception);
6531 break;
6532 }
6533 (void) SetImageOption(image_info,option+1,argv[i+1]);
6534 (void) QueryColorDatabase(argv[i+1],&image_info->background_color,
6535 exception);
6536 break;
6537 }
6538 if (LocaleCompare("bias",option+1) == 0)
6539 {
6540 if (*option == '+')
6541 {
6542 (void) SetImageOption(image_info,option+1,"0.0");
6543 break;
6544 }
6545 (void) SetImageOption(image_info,option+1,argv[i+1]);
6546 break;
6547 }
6548 if (LocaleCompare("black-point-compensation",option+1) == 0)
6549 {
6550 if (*option == '+')
6551 {
6552 (void) SetImageOption(image_info,option+1,"false");
6553 break;
6554 }
6555 (void) SetImageOption(image_info,option+1,"true");
6556 break;
6557 }
6558 if (LocaleCompare("blue-primary",option+1) == 0)
6559 {
6560 if (*option == '+')
6561 {
6562 (void) SetImageOption(image_info,option+1,"0.0");
6563 break;
6564 }
6565 (void) SetImageOption(image_info,option+1,argv[i+1]);
6566 break;
6567 }
6568 if (LocaleCompare("bordercolor",option+1) == 0)
6569 {
6570 if (*option == '+')
6571 {
6572 (void) DeleteImageOption(image_info,option+1);
6573 (void) QueryColorDatabase(BorderColor,&image_info->border_color,
6574 exception);
6575 break;
6576 }
6577 (void) QueryColorDatabase(argv[i+1],&image_info->border_color,
6578 exception);
6579 (void) SetImageOption(image_info,option+1,argv[i+1]);
6580 break;
6581 }
6582 if (LocaleCompare("box",option+1) == 0)
6583 {
6584 if (*option == '+')
6585 {
6586 (void) SetImageOption(image_info,"undercolor","none");
6587 break;
6588 }
6589 (void) SetImageOption(image_info,"undercolor",argv[i+1]);
6590 break;
6591 }
6592 break;
6593 }
6594 case 'c':
6595 {
6596 if (LocaleCompare("cache",option+1) == 0)
6597 {
6598 MagickSizeType
6599 limit;
6600
6601 limit=MagickResourceInfinity;
6602 if (LocaleCompare("unlimited",argv[i+1]) != 0)
cristyf2f27272009-12-17 14:48:46 +00006603 limit=(MagickSizeType) SiPrefixToDouble(argv[i+1],100.0);
cristy3ed852e2009-09-05 21:47:34 +00006604 (void) SetMagickResourceLimit(MemoryResource,limit);
6605 (void) SetMagickResourceLimit(MapResource,2*limit);
6606 break;
6607 }
6608 if (LocaleCompare("caption",option+1) == 0)
6609 {
6610 if (*option == '+')
6611 {
6612 (void) DeleteImageOption(image_info,option+1);
6613 break;
6614 }
6615 (void) SetImageOption(image_info,option+1,argv[i+1]);
6616 break;
6617 }
6618 if (LocaleCompare("channel",option+1) == 0)
6619 {
6620 if (*option == '+')
6621 {
6622 image_info->channel=DefaultChannels;
6623 break;
6624 }
6625 image_info->channel=(ChannelType) ParseChannelOption(argv[i+1]);
6626 break;
6627 }
6628 if (LocaleCompare("colors",option+1) == 0)
6629 {
cristye27293e2009-12-18 02:53:20 +00006630 image_info->colors=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006631 break;
6632 }
6633 if (LocaleCompare("colorspace",option+1) == 0)
6634 {
6635 if (*option == '+')
6636 {
6637 image_info->colorspace=UndefinedColorspace;
6638 (void) SetImageOption(image_info,option+1,"undefined");
6639 break;
6640 }
6641 image_info->colorspace=(ColorspaceType) ParseMagickOption(
6642 MagickColorspaceOptions,MagickFalse,argv[i+1]);
6643 (void) SetImageOption(image_info,option+1,argv[i+1]);
6644 break;
6645 }
6646 if (LocaleCompare("compress",option+1) == 0)
6647 {
6648 if (*option == '+')
6649 {
6650 image_info->compression=UndefinedCompression;
6651 (void) SetImageOption(image_info,option+1,"undefined");
6652 break;
6653 }
6654 image_info->compression=(CompressionType) ParseMagickOption(
6655 MagickCompressOptions,MagickFalse,argv[i+1]);
6656 (void) SetImageOption(image_info,option+1,argv[i+1]);
6657 break;
6658 }
6659 if (LocaleCompare("comment",option+1) == 0)
6660 {
6661 if (*option == '+')
6662 {
6663 (void) DeleteImageOption(image_info,option+1);
6664 break;
6665 }
6666 (void) SetImageOption(image_info,option+1,argv[i+1]);
6667 break;
6668 }
6669 if (LocaleCompare("compose",option+1) == 0)
6670 {
6671 if (*option == '+')
6672 {
6673 (void) SetImageOption(image_info,option+1,"undefined");
6674 break;
6675 }
6676 (void) SetImageOption(image_info,option+1,argv[i+1]);
6677 break;
6678 }
6679 if (LocaleCompare("compress",option+1) == 0)
6680 {
6681 if (*option == '+')
6682 {
6683 image_info->compression=UndefinedCompression;
6684 (void) SetImageOption(image_info,option+1,"undefined");
6685 break;
6686 }
6687 image_info->compression=(CompressionType) ParseMagickOption(
6688 MagickCompressOptions,MagickFalse,argv[i+1]);
6689 (void) SetImageOption(image_info,option+1,argv[i+1]);
6690 break;
6691 }
6692 break;
6693 }
6694 case 'd':
6695 {
6696 if (LocaleCompare("debug",option+1) == 0)
6697 {
6698 if (*option == '+')
6699 (void) SetLogEventMask("none");
6700 else
6701 (void) SetLogEventMask(argv[i+1]);
6702 image_info->debug=IsEventLogging();
6703 break;
6704 }
6705 if (LocaleCompare("define",option+1) == 0)
6706 {
6707 if (*option == '+')
6708 {
6709 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6710 (void) DeleteImageRegistry(argv[i+1]+9);
6711 else
6712 (void) DeleteImageOption(image_info,argv[i+1]);
6713 break;
6714 }
6715 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6716 {
6717 (void) DefineImageRegistry(StringRegistryType,argv[i+1]+9,
6718 exception);
6719 break;
6720 }
6721 (void) DefineImageOption(image_info,argv[i+1]);
6722 break;
6723 }
6724 if (LocaleCompare("delay",option+1) == 0)
6725 {
6726 if (*option == '+')
6727 {
6728 (void) SetImageOption(image_info,option+1,"0");
6729 break;
6730 }
6731 (void) SetImageOption(image_info,option+1,argv[i+1]);
6732 break;
6733 }
6734 if (LocaleCompare("density",option+1) == 0)
6735 {
6736 /*
6737 Set image density.
6738 */
6739 if (*option == '+')
6740 {
6741 if (image_info->density != (char *) NULL)
6742 image_info->density=DestroyString(image_info->density);
6743 (void) SetImageOption(image_info,option+1,"72");
6744 break;
6745 }
6746 (void) CloneString(&image_info->density,argv[i+1]);
6747 (void) SetImageOption(image_info,option+1,argv[i+1]);
6748 break;
6749 }
6750 if (LocaleCompare("depth",option+1) == 0)
6751 {
6752 if (*option == '+')
6753 {
6754 image_info->depth=MAGICKCORE_QUANTUM_DEPTH;
6755 break;
6756 }
cristye27293e2009-12-18 02:53:20 +00006757 image_info->depth=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006758 break;
6759 }
cristyc9b12952010-03-28 01:12:28 +00006760 if (LocaleCompare("direction",option+1) == 0)
6761 {
6762 if (*option == '+')
6763 {
6764 (void) SetImageOption(image_info,option+1,"undefined");
6765 break;
6766 }
6767 (void) SetImageOption(image_info,option+1,argv[i+1]);
6768 break;
6769 }
cristy3ed852e2009-09-05 21:47:34 +00006770 if (LocaleCompare("display",option+1) == 0)
6771 {
6772 if (*option == '+')
6773 {
6774 if (image_info->server_name != (char *) NULL)
6775 image_info->server_name=DestroyString(
6776 image_info->server_name);
6777 break;
6778 }
6779 (void) CloneString(&image_info->server_name,argv[i+1]);
6780 break;
6781 }
6782 if (LocaleCompare("dispose",option+1) == 0)
6783 {
6784 if (*option == '+')
6785 {
6786 (void) SetImageOption(image_info,option+1,"undefined");
6787 break;
6788 }
6789 (void) SetImageOption(image_info,option+1,argv[i+1]);
6790 break;
6791 }
6792 if (LocaleCompare("dither",option+1) == 0)
6793 {
6794 if (*option == '+')
6795 {
6796 image_info->dither=MagickFalse;
6797 (void) SetImageOption(image_info,option+1,"undefined");
6798 break;
6799 }
6800 (void) SetImageOption(image_info,option+1,argv[i+1]);
6801 image_info->dither=MagickTrue;
6802 break;
6803 }
6804 break;
6805 }
6806 case 'e':
6807 {
6808 if (LocaleCompare("encoding",option+1) == 0)
6809 {
6810 if (*option == '+')
6811 {
6812 (void) SetImageOption(image_info,option+1,"undefined");
6813 break;
6814 }
6815 (void) SetImageOption(image_info,option+1,argv[i+1]);
6816 break;
6817 }
6818 if (LocaleCompare("endian",option+1) == 0)
6819 {
6820 if (*option == '+')
6821 {
6822 image_info->endian=UndefinedEndian;
6823 (void) SetImageOption(image_info,option+1,"undefined");
6824 break;
6825 }
6826 image_info->endian=(EndianType) ParseMagickOption(
6827 MagickEndianOptions,MagickFalse,argv[i+1]);
6828 (void) SetImageOption(image_info,option+1,argv[i+1]);
6829 break;
6830 }
6831 if (LocaleCompare("extract",option+1) == 0)
6832 {
6833 /*
6834 Set image extract geometry.
6835 */
6836 if (*option == '+')
6837 {
6838 if (image_info->extract != (char *) NULL)
6839 image_info->extract=DestroyString(image_info->extract);
6840 break;
6841 }
6842 (void) CloneString(&image_info->extract,argv[i+1]);
6843 break;
6844 }
6845 break;
6846 }
6847 case 'f':
6848 {
6849 if (LocaleCompare("fill",option+1) == 0)
6850 {
6851 if (*option == '+')
6852 {
6853 (void) SetImageOption(image_info,option+1,"none");
6854 break;
6855 }
6856 (void) SetImageOption(image_info,option+1,argv[i+1]);
6857 break;
6858 }
6859 if (LocaleCompare("filter",option+1) == 0)
6860 {
6861 if (*option == '+')
6862 {
6863 (void) SetImageOption(image_info,option+1,"undefined");
6864 break;
6865 }
6866 (void) SetImageOption(image_info,option+1,argv[i+1]);
6867 break;
6868 }
6869 if (LocaleCompare("font",option+1) == 0)
6870 {
6871 if (*option == '+')
6872 {
6873 if (image_info->font != (char *) NULL)
6874 image_info->font=DestroyString(image_info->font);
6875 break;
6876 }
6877 (void) CloneString(&image_info->font,argv[i+1]);
6878 break;
6879 }
6880 if (LocaleCompare("format",option+1) == 0)
6881 {
6882 register const char
6883 *q;
6884
6885 for (q=strchr(argv[i+1],'%'); q != (char *) NULL; q=strchr(q+1,'%'))
6886 if (strchr("gkrz@[#",*(q+1)) != (char *) NULL)
6887 image_info->ping=MagickFalse;
6888 (void) SetImageOption(image_info,option+1,argv[i+1]);
6889 break;
6890 }
6891 if (LocaleCompare("fuzz",option+1) == 0)
6892 {
6893 if (*option == '+')
6894 {
6895 image_info->fuzz=0.0;
6896 (void) SetImageOption(image_info,option+1,"0");
6897 break;
6898 }
cristyf2f27272009-12-17 14:48:46 +00006899 image_info->fuzz=SiPrefixToDouble(argv[i+1],(double) QuantumRange+
cristy3ed852e2009-09-05 21:47:34 +00006900 1.0);
6901 (void) SetImageOption(image_info,option+1,argv[i+1]);
6902 break;
6903 }
6904 break;
6905 }
6906 case 'g':
6907 {
6908 if (LocaleCompare("gravity",option+1) == 0)
6909 {
6910 if (*option == '+')
6911 {
6912 (void) SetImageOption(image_info,option+1,"undefined");
6913 break;
6914 }
6915 (void) SetImageOption(image_info,option+1,argv[i+1]);
6916 break;
6917 }
6918 if (LocaleCompare("green-primary",option+1) == 0)
6919 {
6920 if (*option == '+')
6921 {
6922 (void) SetImageOption(image_info,option+1,"0.0");
6923 break;
6924 }
6925 (void) SetImageOption(image_info,option+1,argv[i+1]);
6926 break;
6927 }
6928 break;
6929 }
6930 case 'i':
6931 {
6932 if (LocaleCompare("intent",option+1) == 0)
6933 {
6934 if (*option == '+')
6935 {
6936 (void) SetImageOption(image_info,option+1,"undefined");
6937 break;
6938 }
6939 (void) SetImageOption(image_info,option+1,argv[i+1]);
6940 break;
6941 }
6942 if (LocaleCompare("interlace",option+1) == 0)
6943 {
6944 if (*option == '+')
6945 {
6946 image_info->interlace=UndefinedInterlace;
6947 (void) SetImageOption(image_info,option+1,"undefined");
6948 break;
6949 }
6950 image_info->interlace=(InterlaceType) ParseMagickOption(
6951 MagickInterlaceOptions,MagickFalse,argv[i+1]);
6952 (void) SetImageOption(image_info,option+1,argv[i+1]);
6953 break;
6954 }
cristyb32b90a2009-09-07 21:45:48 +00006955 if (LocaleCompare("interline-spacing",option+1) == 0)
6956 {
6957 if (*option == '+')
6958 {
6959 (void) SetImageOption(image_info,option+1,"undefined");
6960 break;
6961 }
6962 (void) SetImageOption(image_info,option+1,argv[i+1]);
6963 break;
6964 }
cristy3ed852e2009-09-05 21:47:34 +00006965 if (LocaleCompare("interpolate",option+1) == 0)
6966 {
6967 if (*option == '+')
6968 {
6969 (void) SetImageOption(image_info,option+1,"undefined");
6970 break;
6971 }
6972 (void) SetImageOption(image_info,option+1,argv[i+1]);
6973 break;
6974 }
6975 if (LocaleCompare("interword-spacing",option+1) == 0)
6976 {
6977 if (*option == '+')
6978 {
6979 (void) SetImageOption(image_info,option+1,"undefined");
6980 break;
6981 }
6982 (void) SetImageOption(image_info,option+1,argv[i+1]);
6983 break;
6984 }
6985 break;
6986 }
6987 case 'k':
6988 {
6989 if (LocaleCompare("kerning",option+1) == 0)
6990 {
6991 if (*option == '+')
6992 {
6993 (void) SetImageOption(image_info,option+1,"undefined");
6994 break;
6995 }
6996 (void) SetImageOption(image_info,option+1,argv[i+1]);
6997 break;
6998 }
6999 break;
7000 }
7001 case 'l':
7002 {
7003 if (LocaleCompare("label",option+1) == 0)
7004 {
7005 if (*option == '+')
7006 {
7007 (void) DeleteImageOption(image_info,option+1);
7008 break;
7009 }
7010 (void) SetImageOption(image_info,option+1,argv[i+1]);
7011 break;
7012 }
7013 if (LocaleCompare("limit",option+1) == 0)
7014 {
7015 MagickSizeType
7016 limit;
7017
7018 ResourceType
7019 type;
7020
7021 if (*option == '+')
7022 break;
7023 type=(ResourceType) ParseMagickOption(MagickResourceOptions,
7024 MagickFalse,argv[i+1]);
7025 limit=MagickResourceInfinity;
7026 if (LocaleCompare("unlimited",argv[i+2]) != 0)
cristyf2f27272009-12-17 14:48:46 +00007027 limit=(MagickSizeType) SiPrefixToDouble(argv[i+2],100.0);
cristy3ed852e2009-09-05 21:47:34 +00007028 (void) SetMagickResourceLimit(type,limit);
7029 break;
7030 }
7031 if (LocaleCompare("list",option+1) == 0)
7032 {
7033 long
7034 list;
7035
7036 /*
7037 Display configuration list.
7038 */
7039 list=ParseMagickOption(MagickListOptions,MagickFalse,argv[i+1]);
7040 switch (list)
7041 {
7042 case MagickCoderOptions:
7043 {
7044 (void) ListCoderInfo((FILE *) NULL,exception);
7045 break;
7046 }
7047 case MagickColorOptions:
7048 {
7049 (void) ListColorInfo((FILE *) NULL,exception);
7050 break;
7051 }
7052 case MagickConfigureOptions:
7053 {
7054 (void) ListConfigureInfo((FILE *) NULL,exception);
7055 break;
7056 }
7057 case MagickDelegateOptions:
7058 {
7059 (void) ListDelegateInfo((FILE *) NULL,exception);
7060 break;
7061 }
7062 case MagickFontOptions:
7063 {
7064 (void) ListTypeInfo((FILE *) NULL,exception);
7065 break;
7066 }
7067 case MagickFormatOptions:
7068 {
7069 (void) ListMagickInfo((FILE *) NULL,exception);
7070 break;
7071 }
7072 case MagickLocaleOptions:
7073 {
7074 (void) ListLocaleInfo((FILE *) NULL,exception);
7075 break;
7076 }
7077 case MagickLogOptions:
7078 {
7079 (void) ListLogInfo((FILE *) NULL,exception);
7080 break;
7081 }
7082 case MagickMagicOptions:
7083 {
7084 (void) ListMagicInfo((FILE *) NULL,exception);
7085 break;
7086 }
7087 case MagickMimeOptions:
7088 {
7089 (void) ListMimeInfo((FILE *) NULL,exception);
7090 break;
7091 }
7092 case MagickModuleOptions:
7093 {
7094 (void) ListModuleInfo((FILE *) NULL,exception);
7095 break;
7096 }
7097 case MagickPolicyOptions:
7098 {
7099 (void) ListPolicyInfo((FILE *) NULL,exception);
7100 break;
7101 }
7102 case MagickResourceOptions:
7103 {
7104 (void) ListMagickResourceInfo((FILE *) NULL,exception);
7105 break;
7106 }
7107 case MagickThresholdOptions:
7108 {
7109 (void) ListThresholdMaps((FILE *) NULL,exception);
7110 break;
7111 }
7112 default:
7113 {
7114 (void) ListMagickOptions((FILE *) NULL,(MagickOption) list,
7115 exception);
7116 break;
7117 }
7118 }
7119 }
7120 if (LocaleCompare("log",option+1) == 0)
7121 {
7122 if (*option == '+')
7123 break;
7124 (void) SetLogFormat(argv[i+1]);
7125 break;
7126 }
7127 if (LocaleCompare("loop",option+1) == 0)
7128 {
7129 if (*option == '+')
7130 {
7131 (void) SetImageOption(image_info,option+1,"0");
7132 break;
7133 }
7134 (void) SetImageOption(image_info,option+1,argv[i+1]);
7135 break;
7136 }
7137 break;
7138 }
7139 case 'm':
7140 {
7141 if (LocaleCompare("matte",option+1) == 0)
7142 {
7143 if (*option == '+')
7144 {
7145 (void) SetImageOption(image_info,option+1,"false");
7146 break;
7147 }
7148 (void) SetImageOption(image_info,option+1,"true");
7149 break;
7150 }
7151 if (LocaleCompare("mattecolor",option+1) == 0)
7152 {
7153 if (*option == '+')
7154 {
7155 (void) SetImageOption(image_info,option+1,argv[i+1]);
7156 (void) QueryColorDatabase(MatteColor,&image_info->matte_color,
7157 exception);
7158 break;
7159 }
7160 (void) SetImageOption(image_info,option+1,argv[i+1]);
7161 (void) QueryColorDatabase(argv[i+1],&image_info->matte_color,
7162 exception);
7163 break;
7164 }
7165 if (LocaleCompare("monitor",option+1) == 0)
7166 {
7167 (void) SetImageInfoProgressMonitor(image_info,MonitorProgress,
7168 (void *) NULL);
7169 break;
7170 }
7171 if (LocaleCompare("monochrome",option+1) == 0)
7172 {
7173 image_info->monochrome=(*option == '-') ? MagickTrue : MagickFalse;
7174 break;
7175 }
7176 break;
7177 }
7178 case 'o':
7179 {
7180 if (LocaleCompare("orient",option+1) == 0)
7181 {
7182 if (*option == '+')
7183 {
7184 image_info->orientation=UndefinedOrientation;
7185 (void) SetImageOption(image_info,option+1,"undefined");
7186 break;
7187 }
7188 image_info->orientation=(OrientationType) ParseMagickOption(
7189 MagickOrientationOptions,MagickFalse,argv[i+1]);
7190 (void) SetImageOption(image_info,option+1,"undefined");
7191 break;
7192 }
7193 }
7194 case 'p':
7195 {
7196 if (LocaleCompare("page",option+1) == 0)
7197 {
7198 char
7199 *canonical_page,
7200 page[MaxTextExtent];
7201
7202 const char
7203 *image_option;
7204
7205 MagickStatusType
7206 flags;
7207
7208 RectangleInfo
7209 geometry;
7210
7211 if (*option == '+')
7212 {
7213 (void) DeleteImageOption(image_info,option+1);
7214 (void) CloneString(&image_info->page,(char *) NULL);
7215 break;
7216 }
7217 (void) ResetMagickMemory(&geometry,0,sizeof(geometry));
7218 image_option=GetImageOption(image_info,"page");
7219 if (image_option != (const char *) NULL)
7220 flags=ParseAbsoluteGeometry(image_option,&geometry);
7221 canonical_page=GetPageGeometry(argv[i+1]);
7222 flags=ParseAbsoluteGeometry(canonical_page,&geometry);
7223 canonical_page=DestroyString(canonical_page);
7224 (void) FormatMagickString(page,MaxTextExtent,"%lux%lu",
7225 geometry.width,geometry.height);
7226 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
7227 (void) FormatMagickString(page,MaxTextExtent,"%lux%lu%+ld%+ld",
7228 geometry.width,geometry.height,geometry.x,geometry.y);
7229 (void) SetImageOption(image_info,option+1,page);
7230 (void) CloneString(&image_info->page,page);
7231 break;
7232 }
7233 if (LocaleCompare("pen",option+1) == 0)
7234 {
7235 if (*option == '+')
7236 {
7237 (void) SetImageOption(image_info,option+1,"none");
7238 break;
7239 }
7240 (void) SetImageOption(image_info,option+1,argv[i+1]);
7241 break;
7242 }
7243 if (LocaleCompare("ping",option+1) == 0)
7244 {
7245 image_info->ping=(*option == '-') ? MagickTrue : MagickFalse;
7246 break;
7247 }
7248 if (LocaleCompare("pointsize",option+1) == 0)
7249 {
7250 if (*option == '+')
7251 geometry_info.rho=0.0;
7252 else
7253 (void) ParseGeometry(argv[i+1],&geometry_info);
7254 image_info->pointsize=geometry_info.rho;
7255 break;
7256 }
cristye7f51092010-01-17 00:39:37 +00007257 if (LocaleCompare("precision",option+1) == 0)
7258 {
cristybf2766a2010-01-17 03:33:23 +00007259 (void) SetMagickPrecision(StringToInteger(argv[i+1]));
cristye7f51092010-01-17 00:39:37 +00007260 break;
7261 }
cristy3ed852e2009-09-05 21:47:34 +00007262 if (LocaleCompare("preview",option+1) == 0)
7263 {
7264 /*
7265 Preview image.
7266 */
7267 if (*option == '+')
7268 {
7269 image_info->preview_type=UndefinedPreview;
7270 break;
7271 }
7272 image_info->preview_type=(PreviewType) ParseMagickOption(
7273 MagickPreviewOptions,MagickFalse,argv[i+1]);
7274 break;
7275 }
7276 break;
7277 }
7278 case 'q':
7279 {
7280 if (LocaleCompare("quality",option+1) == 0)
7281 {
7282 /*
7283 Set image compression quality.
7284 */
7285 if (*option == '+')
7286 {
7287 image_info->quality=UndefinedCompressionQuality;
7288 (void) SetImageOption(image_info,option+1,"0");
7289 break;
7290 }
cristye27293e2009-12-18 02:53:20 +00007291 image_info->quality=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007292 (void) SetImageOption(image_info,option+1,argv[i+1]);
7293 break;
7294 }
7295 if (LocaleCompare("quiet",option+1) == 0)
7296 {
7297 static WarningHandler
7298 warning_handler = (WarningHandler) NULL;
7299
7300 if (*option == '+')
7301 {
7302 /*
7303 Restore error or warning messages.
7304 */
7305 warning_handler=SetWarningHandler(warning_handler);
7306 break;
7307 }
7308 /*
7309 Suppress error or warning messages.
7310 */
7311 warning_handler=SetWarningHandler((WarningHandler) NULL);
7312 break;
7313 }
7314 break;
7315 }
7316 case 'r':
7317 {
7318 if (LocaleCompare("red-primary",option+1) == 0)
7319 {
7320 if (*option == '+')
7321 {
7322 (void) SetImageOption(image_info,option+1,"0.0");
7323 break;
7324 }
7325 (void) SetImageOption(image_info,option+1,argv[i+1]);
7326 break;
7327 }
7328 break;
7329 }
7330 case 's':
7331 {
7332 if (LocaleCompare("sampling-factor",option+1) == 0)
7333 {
7334 /*
7335 Set image sampling factor.
7336 */
7337 if (*option == '+')
7338 {
7339 if (image_info->sampling_factor != (char *) NULL)
7340 image_info->sampling_factor=DestroyString(
7341 image_info->sampling_factor);
7342 break;
7343 }
7344 (void) CloneString(&image_info->sampling_factor,argv[i+1]);
7345 break;
7346 }
7347 if (LocaleCompare("scene",option+1) == 0)
7348 {
7349 /*
7350 Set image scene.
7351 */
7352 if (*option == '+')
7353 {
7354 image_info->scene=0;
7355 (void) SetImageOption(image_info,option+1,"0");
7356 break;
7357 }
cristye27293e2009-12-18 02:53:20 +00007358 image_info->scene=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007359 (void) SetImageOption(image_info,option+1,argv[i+1]);
7360 break;
7361 }
7362 if (LocaleCompare("seed",option+1) == 0)
7363 {
7364 unsigned long
7365 seed;
7366
7367 if (*option == '+')
7368 {
7369 seed=(unsigned long) time((time_t *) NULL);
7370 SeedPseudoRandomGenerator(seed);
7371 break;
7372 }
cristye27293e2009-12-18 02:53:20 +00007373 seed=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007374 SeedPseudoRandomGenerator(seed);
7375 break;
7376 }
7377 if (LocaleCompare("size",option+1) == 0)
7378 {
7379 if (*option == '+')
7380 {
7381 if (image_info->size != (char *) NULL)
7382 image_info->size=DestroyString(image_info->size);
7383 break;
7384 }
7385 (void) CloneString(&image_info->size,argv[i+1]);
7386 break;
7387 }
7388 if (LocaleCompare("stroke",option+1) == 0)
7389 {
7390 if (*option == '+')
7391 {
7392 (void) SetImageOption(image_info,option+1,"none");
7393 break;
7394 }
7395 (void) SetImageOption(image_info,option+1,argv[i+1]);
7396 break;
7397 }
7398 if (LocaleCompare("strokewidth",option+1) == 0)
7399 {
7400 if (*option == '+')
7401 {
7402 (void) SetImageOption(image_info,option+1,"0");
7403 break;
7404 }
7405 (void) SetImageOption(image_info,option+1,argv[i+1]);
7406 break;
7407 }
7408 break;
7409 }
7410 case 't':
7411 {
7412 if (LocaleCompare("taint",option+1) == 0)
7413 {
7414 if (*option == '+')
7415 {
7416 (void) SetImageOption(image_info,option+1,"false");
7417 break;
7418 }
7419 (void) SetImageOption(image_info,option+1,"true");
7420 break;
7421 }
7422 if (LocaleCompare("texture",option+1) == 0)
7423 {
7424 if (*option == '+')
7425 {
7426 if (image_info->texture != (char *) NULL)
7427 image_info->texture=DestroyString(image_info->texture);
7428 break;
7429 }
7430 (void) CloneString(&image_info->texture,argv[i+1]);
7431 break;
7432 }
7433 if (LocaleCompare("tile-offset",option+1) == 0)
7434 {
7435 if (*option == '+')
7436 {
7437 (void) SetImageOption(image_info,option+1,"0");
7438 break;
7439 }
7440 (void) SetImageOption(image_info,option+1,argv[i+1]);
7441 break;
7442 }
7443 if (LocaleCompare("transparent-color",option+1) == 0)
7444 {
7445 if (*option == '+')
7446 {
7447 (void) QueryColorDatabase("none",&image_info->transparent_color, exception);
7448 (void) SetImageOption(image_info,option+1,"none");
7449 break;
7450 }
7451 (void) QueryColorDatabase(argv[i+1],&image_info->transparent_color,
7452 exception);
7453 (void) SetImageOption(image_info,option+1,argv[i+1]);
7454 break;
7455 }
7456 if (LocaleCompare("type",option+1) == 0)
7457 {
7458 if (*option == '+')
7459 {
7460 image_info->type=UndefinedType;
7461 (void) SetImageOption(image_info,option+1,"undefined");
7462 break;
7463 }
7464 image_info->type=(ImageType) ParseMagickOption(MagickTypeOptions,
7465 MagickFalse,argv[i+1]);
7466 (void) SetImageOption(image_info,option+1,argv[i+1]);
7467 break;
7468 }
7469 break;
7470 }
7471 case 'u':
7472 {
7473 if (LocaleCompare("undercolor",option+1) == 0)
7474 {
7475 if (*option == '+')
7476 {
7477 (void) DeleteImageOption(image_info,option+1);
7478 break;
7479 }
7480 (void) SetImageOption(image_info,option+1,argv[i+1]);
7481 break;
7482 }
7483 if (LocaleCompare("units",option+1) == 0)
7484 {
7485 if (*option == '+')
7486 {
7487 image_info->units=UndefinedResolution;
7488 (void) SetImageOption(image_info,option+1,"undefined");
7489 break;
7490 }
7491 image_info->units=(ResolutionType) ParseMagickOption(
7492 MagickResolutionOptions,MagickFalse,argv[i+1]);
7493 (void) SetImageOption(image_info,option+1,argv[i+1]);
7494 break;
7495 }
7496 break;
7497 }
7498 case 'v':
7499 {
7500 if (LocaleCompare("verbose",option+1) == 0)
7501 {
7502 if (*option == '+')
7503 {
7504 image_info->verbose=MagickFalse;
7505 break;
7506 }
7507 image_info->verbose=MagickTrue;
7508 image_info->ping=MagickFalse;
7509 break;
7510 }
7511 if (LocaleCompare("view",option+1) == 0)
7512 {
7513 if (*option == '+')
7514 {
7515 if (image_info->view != (char *) NULL)
7516 image_info->view=DestroyString(image_info->view);
7517 break;
7518 }
7519 (void) CloneString(&image_info->view,argv[i+1]);
7520 break;
7521 }
7522 if (LocaleCompare("virtual-pixel",option+1) == 0)
7523 {
7524 if (*option == '+')
7525 {
7526 image_info->virtual_pixel_method=UndefinedVirtualPixelMethod;
7527 (void) SetImageOption(image_info,option+1,"undefined");
7528 break;
7529 }
7530 image_info->virtual_pixel_method=(VirtualPixelMethod)
7531 ParseMagickOption(MagickVirtualPixelOptions,MagickFalse,
7532 argv[i+1]);
7533 (void) SetImageOption(image_info,option+1,argv[i+1]);
7534 break;
7535 }
7536 break;
7537 }
7538 case 'w':
7539 {
7540 if (LocaleCompare("white-point",option+1) == 0)
7541 {
7542 if (*option == '+')
7543 {
7544 (void) SetImageOption(image_info,option+1,"0.0");
7545 break;
7546 }
7547 (void) SetImageOption(image_info,option+1,argv[i+1]);
7548 break;
7549 }
7550 break;
7551 }
7552 default:
7553 break;
7554 }
7555 i+=count;
7556 }
7557 return(MagickTrue);
7558}
7559
7560/*
7561%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7562% %
7563% %
7564% %
7565+ M o g r i f y I m a g e L i s t %
7566% %
7567% %
7568% %
7569%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7570%
7571% MogrifyImageList() applies any command line options that might affect the
7572% entire image list (e.g. -append, -coalesce, etc.).
7573%
7574% The format of the MogrifyImage method is:
7575%
7576% MagickBooleanType MogrifyImageList(ImageInfo *image_info,const int argc,
7577% const char **argv,Image **images,ExceptionInfo *exception)
7578%
7579% A description of each parameter follows:
7580%
7581% o image_info: the image info..
7582%
7583% o argc: Specifies a pointer to an integer describing the number of
7584% elements in the argument vector.
7585%
7586% o argv: Specifies a pointer to a text array containing the command line
7587% arguments.
7588%
7589% o images: the images.
7590%
7591% o exception: return any errors or warnings in this structure.
7592%
7593*/
7594WandExport MagickBooleanType MogrifyImageList(ImageInfo *image_info,
7595 const int argc,const char **argv,Image **images,ExceptionInfo *exception)
7596{
7597 ChannelType
7598 channel;
7599
7600 const char
7601 *option;
7602
7603 long
7604 count,
7605 index;
7606
7607 MagickStatusType
7608 status;
7609
7610 QuantizeInfo
7611 *quantize_info;
7612
7613 register long
7614 i;
7615
7616 /*
7617 Apply options to the image list.
7618 */
7619 assert(image_info != (ImageInfo *) NULL);
7620 assert(image_info->signature == MagickSignature);
7621 assert(images != (Image **) NULL);
7622 assert((*images)->signature == MagickSignature);
7623 if ((*images)->debug != MagickFalse)
7624 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
7625 (*images)->filename);
7626 if ((argc <= 0) || (*argv == (char *) NULL))
7627 return(MagickTrue);
7628 quantize_info=AcquireQuantizeInfo(image_info);
7629 channel=image_info->channel;
7630 status=MagickTrue;
7631 for (i=0; i < (long) argc; i++)
7632 {
cristy74fe8f12009-10-03 19:09:01 +00007633 if (*images == (Image *) NULL)
7634 break;
cristy3ed852e2009-09-05 21:47:34 +00007635 option=argv[i];
7636 if (IsMagickOption(option) == MagickFalse)
7637 continue;
7638 count=MagickMax(ParseMagickOption(MagickCommandOptions,MagickFalse,option),
7639 0L);
7640 if ((i+count) >= argc)
7641 break;
7642 status=MogrifyImageInfo(image_info,count+1,argv+i,exception);
7643 switch (*(option+1))
7644 {
7645 case 'a':
7646 {
7647 if (LocaleCompare("affinity",option+1) == 0)
7648 {
7649 (void) SyncImagesSettings(image_info,*images);
7650 if (*option == '+')
7651 {
7652 (void) RemapImages(quantize_info,*images,(Image *) NULL);
7653 InheritException(exception,&(*images)->exception);
7654 break;
7655 }
7656 i++;
7657 break;
7658 }
7659 if (LocaleCompare("append",option+1) == 0)
7660 {
7661 Image
7662 *append_image;
7663
7664 (void) SyncImagesSettings(image_info,*images);
7665 append_image=AppendImages(*images,*option == '-' ? MagickTrue :
7666 MagickFalse,exception);
7667 if (append_image == (Image *) NULL)
7668 {
7669 status=MagickFalse;
7670 break;
7671 }
7672 *images=DestroyImageList(*images);
7673 *images=append_image;
7674 break;
7675 }
7676 if (LocaleCompare("average",option+1) == 0)
7677 {
7678 Image
7679 *average_image;
7680
cristyd18ae7c2010-03-07 17:39:52 +00007681 /*
7682 Average an image sequence (deprecated).
7683 */
cristy3ed852e2009-09-05 21:47:34 +00007684 (void) SyncImagesSettings(image_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007685 average_image=EvaluateImages(*images,MeanEvaluateOperator,
7686 exception);
cristy3ed852e2009-09-05 21:47:34 +00007687 if (average_image == (Image *) NULL)
7688 {
7689 status=MagickFalse;
7690 break;
7691 }
7692 *images=DestroyImageList(*images);
7693 *images=average_image;
7694 break;
7695 }
7696 break;
7697 }
7698 case 'c':
7699 {
7700 if (LocaleCompare("channel",option+1) == 0)
7701 {
7702 if (*option == '+')
7703 {
7704 channel=DefaultChannels;
7705 break;
7706 }
7707 channel=(ChannelType) ParseChannelOption(argv[i+1]);
7708 break;
7709 }
7710 if (LocaleCompare("clut",option+1) == 0)
7711 {
7712 Image
7713 *clut_image,
7714 *image;
7715
7716 (void) SyncImagesSettings(image_info,*images);
7717 image=RemoveFirstImageFromList(images);
7718 clut_image=RemoveFirstImageFromList(images);
7719 if (clut_image == (Image *) NULL)
7720 {
7721 status=MagickFalse;
7722 break;
7723 }
7724 (void) ClutImageChannel(image,channel,clut_image);
7725 clut_image=DestroyImage(clut_image);
7726 InheritException(exception,&image->exception);
7727 *images=DestroyImageList(*images);
7728 *images=image;
7729 break;
7730 }
7731 if (LocaleCompare("coalesce",option+1) == 0)
7732 {
7733 Image
7734 *coalesce_image;
7735
7736 (void) SyncImagesSettings(image_info,*images);
7737 coalesce_image=CoalesceImages(*images,exception);
7738 if (coalesce_image == (Image *) NULL)
7739 {
7740 status=MagickFalse;
7741 break;
7742 }
7743 *images=DestroyImageList(*images);
7744 *images=coalesce_image;
7745 break;
7746 }
7747 if (LocaleCompare("combine",option+1) == 0)
7748 {
7749 Image
7750 *combine_image;
7751
7752 (void) SyncImagesSettings(image_info,*images);
7753 combine_image=CombineImages(*images,channel,exception);
7754 if (combine_image == (Image *) NULL)
7755 {
7756 status=MagickFalse;
7757 break;
7758 }
7759 *images=DestroyImageList(*images);
7760 *images=combine_image;
7761 break;
7762 }
7763 if (LocaleCompare("composite",option+1) == 0)
7764 {
7765 Image
7766 *mask_image,
7767 *composite_image,
7768 *image;
7769
7770 RectangleInfo
7771 geometry;
7772
7773 (void) SyncImagesSettings(image_info,*images);
7774 image=RemoveFirstImageFromList(images);
7775 composite_image=RemoveFirstImageFromList(images);
7776 if (composite_image == (Image *) NULL)
7777 {
7778 status=MagickFalse;
7779 break;
7780 }
7781 (void) TransformImage(&composite_image,(char *) NULL,
7782 composite_image->geometry);
7783 SetGeometry(composite_image,&geometry);
7784 (void) ParseAbsoluteGeometry(composite_image->geometry,&geometry);
7785 GravityAdjustGeometry(image->columns,image->rows,image->gravity,
7786 &geometry);
7787 mask_image=RemoveFirstImageFromList(images);
7788 if (mask_image != (Image *) NULL)
7789 {
7790 if ((image->compose == DisplaceCompositeOp) ||
7791 (image->compose == DistortCompositeOp))
7792 {
7793 /*
7794 Merge Y displacement into X displacement image.
7795 */
7796 (void) CompositeImage(composite_image,CopyGreenCompositeOp,
7797 mask_image,0,0);
7798 mask_image=DestroyImage(mask_image);
7799 }
7800 else
7801 {
7802 /*
7803 Set a blending mask for the composition.
7804 */
7805 image->mask=mask_image;
7806 (void) NegateImage(image->mask,MagickFalse);
7807 }
7808 }
7809 (void) CompositeImageChannel(image,channel,image->compose,
7810 composite_image,geometry.x,geometry.y);
7811 if (image->mask != (Image *) NULL)
7812 image->mask=DestroyImage(image->mask);
7813 composite_image=DestroyImage(composite_image);
7814 InheritException(exception,&image->exception);
7815 *images=DestroyImageList(*images);
7816 *images=image;
7817 break;
7818 }
7819 if (LocaleCompare("crop",option+1) == 0)
7820 {
7821 MagickStatusType
7822 flags;
7823
7824 RectangleInfo
7825 geometry;
7826
7827 (void) SyncImagesSettings(image_info,*images);
7828 flags=ParseGravityGeometry(*images,argv[i+1],&geometry,exception);
7829 if (((geometry.width == 0) && (geometry.height == 0)) ||
7830 ((flags & XValue) != 0) || ((flags & YValue) != 0))
7831 break;
7832 (void) TransformImages(images,argv[i+1],(char *) NULL);
7833 InheritException(exception,&(*images)->exception);
7834 break;
7835 }
7836 break;
7837 }
7838 case 'd':
7839 {
7840 if (LocaleCompare("deconstruct",option+1) == 0)
7841 {
7842 Image
7843 *deconstruct_image;
7844
7845 (void) SyncImagesSettings(image_info,*images);
7846 deconstruct_image=DeconstructImages(*images,exception);
7847 if (deconstruct_image == (Image *) NULL)
7848 {
7849 status=MagickFalse;
7850 break;
7851 }
7852 *images=DestroyImageList(*images);
7853 *images=deconstruct_image;
7854 break;
7855 }
7856 if (LocaleCompare("delete",option+1) == 0)
7857 {
7858 if (*option == '+')
7859 DeleteImages(images,"-1",exception);
7860 else
7861 DeleteImages(images,argv[i+1],exception);
7862 break;
7863 }
7864 if (LocaleCompare("dither",option+1) == 0)
7865 {
7866 if (*option == '+')
7867 {
7868 quantize_info->dither=MagickFalse;
7869 break;
7870 }
7871 quantize_info->dither=MagickTrue;
7872 quantize_info->dither_method=(DitherMethod) ParseMagickOption(
7873 MagickDitherOptions,MagickFalse,argv[i+1]);
7874 break;
7875 }
7876 break;
7877 }
cristyd18ae7c2010-03-07 17:39:52 +00007878 case 'e':
7879 {
7880 if (LocaleCompare("evaluate-sequence",option+1) == 0)
7881 {
7882 Image
7883 *evaluate_image;
7884
7885 MagickEvaluateOperator
7886 op;
7887
7888 (void) SyncImageSettings(image_info,*images);
7889 op=(MagickEvaluateOperator) ParseMagickOption(MagickEvaluateOptions,
7890 MagickFalse,argv[i+1]);
7891 evaluate_image=EvaluateImages(*images,op,exception);
7892 if (evaluate_image == (Image *) NULL)
7893 {
7894 status=MagickFalse;
7895 break;
7896 }
7897 *images=DestroyImageList(*images);
7898 *images=evaluate_image;
7899 break;
7900 }
7901 break;
7902 }
cristy3ed852e2009-09-05 21:47:34 +00007903 case 'f':
7904 {
cristyf0a247f2009-10-04 00:20:03 +00007905 if (LocaleCompare("fft",option+1) == 0)
7906 {
7907 Image
7908 *fourier_image;
7909
7910 /*
7911 Implements the discrete Fourier transform (DFT).
7912 */
7913 (void) SyncImageSettings(image_info,*images);
7914 fourier_image=ForwardFourierTransformImage(*images,*option == '-' ?
7915 MagickTrue : MagickFalse,exception);
7916 if (fourier_image == (Image *) NULL)
7917 break;
7918 *images=DestroyImage(*images);
7919 *images=fourier_image;
7920 break;
7921 }
cristy3ed852e2009-09-05 21:47:34 +00007922 if (LocaleCompare("flatten",option+1) == 0)
7923 {
7924 Image
7925 *flatten_image;
7926
7927 (void) SyncImagesSettings(image_info,*images);
7928 flatten_image=MergeImageLayers(*images,FlattenLayer,exception);
7929 if (flatten_image == (Image *) NULL)
7930 break;
7931 *images=DestroyImageList(*images);
7932 *images=flatten_image;
7933 break;
7934 }
7935 if (LocaleCompare("fx",option+1) == 0)
7936 {
7937 Image
7938 *fx_image;
7939
7940 (void) SyncImagesSettings(image_info,*images);
7941 fx_image=FxImageChannel(*images,channel,argv[i+1],exception);
7942 if (fx_image == (Image *) NULL)
7943 {
7944 status=MagickFalse;
7945 break;
7946 }
7947 *images=DestroyImageList(*images);
7948 *images=fx_image;
7949 break;
7950 }
7951 break;
7952 }
7953 case 'h':
7954 {
7955 if (LocaleCompare("hald-clut",option+1) == 0)
7956 {
7957 Image
7958 *hald_image,
7959 *image;
7960
7961 (void) SyncImagesSettings(image_info,*images);
7962 image=RemoveFirstImageFromList(images);
7963 hald_image=RemoveFirstImageFromList(images);
7964 if (hald_image == (Image *) NULL)
7965 {
7966 status=MagickFalse;
7967 break;
7968 }
7969 (void) HaldClutImageChannel(image,channel,hald_image);
7970 hald_image=DestroyImage(hald_image);
7971 InheritException(exception,&image->exception);
cristy0aff6ea2009-11-14 01:40:53 +00007972 if (*images != (Image *) NULL)
7973 *images=DestroyImageList(*images);
cristy3ed852e2009-09-05 21:47:34 +00007974 *images=image;
7975 break;
7976 }
7977 break;
7978 }
7979 case 'i':
7980 {
7981 if (LocaleCompare("ift",option+1) == 0)
7982 {
7983 Image
cristy8587f882009-11-13 20:28:49 +00007984 *fourier_image,
7985 *magnitude_image,
7986 *phase_image;
cristy3ed852e2009-09-05 21:47:34 +00007987
7988 /*
7989 Implements the inverse fourier discrete Fourier transform (DFT).
7990 */
7991 (void) SyncImagesSettings(image_info,*images);
cristy8587f882009-11-13 20:28:49 +00007992 magnitude_image=RemoveFirstImageFromList(images);
7993 phase_image=RemoveFirstImageFromList(images);
7994 if (phase_image == (Image *) NULL)
7995 {
7996 status=MagickFalse;
7997 break;
7998 }
7999 fourier_image=InverseFourierTransformImage(magnitude_image,
8000 phase_image,*option == '-' ? MagickTrue : MagickFalse,exception);
cristy3ed852e2009-09-05 21:47:34 +00008001 if (fourier_image == (Image *) NULL)
8002 break;
cristy0aff6ea2009-11-14 01:40:53 +00008003 if (*images != (Image *) NULL)
8004 *images=DestroyImage(*images);
cristy3ed852e2009-09-05 21:47:34 +00008005 *images=fourier_image;
8006 break;
8007 }
8008 if (LocaleCompare("insert",option+1) == 0)
8009 {
8010 Image
8011 *p,
8012 *q;
8013
8014 index=0;
8015 if (*option != '+')
cristyf2f27272009-12-17 14:48:46 +00008016 index=StringToLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00008017 p=RemoveLastImageFromList(images);
8018 if (p == (Image *) NULL)
8019 {
8020 (void) ThrowMagickException(exception,GetMagickModule(),
8021 OptionError,"NoSuchImage","`%s'",argv[i+1]);
8022 status=MagickFalse;
8023 break;
8024 }
8025 q=p;
8026 if (index == 0)
8027 PrependImageToList(images,q);
8028 else
8029 if (index == (long) GetImageListLength(*images))
8030 AppendImageToList(images,q);
8031 else
8032 {
8033 q=GetImageFromList(*images,index-1);
8034 if (q == (Image *) NULL)
8035 {
8036 (void) ThrowMagickException(exception,GetMagickModule(),
8037 OptionError,"NoSuchImage","`%s'",argv[i+1]);
8038 status=MagickFalse;
8039 break;
8040 }
8041 InsertImageInList(&q,p);
8042 }
8043 *images=GetFirstImageInList(q);
8044 break;
8045 }
8046 break;
8047 }
8048 case 'l':
8049 {
8050 if (LocaleCompare("layers",option+1) == 0)
8051 {
8052 Image
8053 *layers;
8054
8055 ImageLayerMethod
8056 method;
8057
8058 (void) SyncImagesSettings(image_info,*images);
8059 layers=(Image *) NULL;
8060 method=(ImageLayerMethod) ParseMagickOption(MagickLayerOptions,
8061 MagickFalse,argv[i+1]);
8062 switch (method)
8063 {
8064 case CoalesceLayer:
8065 {
8066 layers=CoalesceImages(*images,exception);
8067 break;
8068 }
8069 case CompareAnyLayer:
8070 case CompareClearLayer:
8071 case CompareOverlayLayer:
8072 default:
8073 {
8074 layers=CompareImageLayers(*images,method,exception);
8075 break;
8076 }
8077 case MergeLayer:
8078 case FlattenLayer:
8079 case MosaicLayer:
8080 case TrimBoundsLayer:
8081 {
8082 layers=MergeImageLayers(*images,method,exception);
8083 break;
8084 }
8085 case DisposeLayer:
8086 {
8087 layers=DisposeImages(*images,exception);
8088 break;
8089 }
8090 case OptimizeImageLayer:
8091 {
8092 layers=OptimizeImageLayers(*images,exception);
8093 break;
8094 }
8095 case OptimizePlusLayer:
8096 {
8097 layers=OptimizePlusImageLayers(*images,exception);
8098 break;
8099 }
8100 case OptimizeTransLayer:
8101 {
8102 OptimizeImageTransparency(*images,exception);
8103 break;
8104 }
8105 case RemoveDupsLayer:
8106 {
8107 RemoveDuplicateLayers(images,exception);
8108 break;
8109 }
8110 case RemoveZeroLayer:
8111 {
8112 RemoveZeroDelayLayers(images,exception);
8113 break;
8114 }
8115 case OptimizeLayer:
8116 {
8117 /*
8118 General Purpose, GIF Animation Optimizer.
8119 */
8120 layers=CoalesceImages(*images,exception);
8121 if (layers == (Image *) NULL)
8122 {
8123 status=MagickFalse;
8124 break;
8125 }
8126 InheritException(exception,&layers->exception);
8127 *images=DestroyImageList(*images);
8128 *images=layers;
8129 layers=OptimizeImageLayers(*images,exception);
8130 if (layers == (Image *) NULL)
8131 {
8132 status=MagickFalse;
8133 break;
8134 }
8135 InheritException(exception,&layers->exception);
8136 *images=DestroyImageList(*images);
8137 *images=layers;
8138 layers=(Image *) NULL;
8139 OptimizeImageTransparency(*images,exception);
8140 InheritException(exception,&(*images)->exception);
8141 (void) RemapImages(quantize_info,*images,(Image *) NULL);
8142 break;
8143 }
8144 case CompositeLayer:
8145 {
8146 CompositeOperator
8147 compose;
8148
8149 Image
8150 *source;
8151
8152 RectangleInfo
8153 geometry;
8154
8155 /*
8156 Split image sequence at the first 'NULL:' image.
8157 */
8158 source=(*images);
8159 while (source != (Image *) NULL)
8160 {
8161 source=GetNextImageInList(source);
8162 if ((source != (Image *) NULL) &&
8163 (LocaleCompare(source->magick,"NULL") == 0))
8164 break;
8165 }
8166 if (source != (Image *) NULL)
8167 {
8168 if ((GetPreviousImageInList(source) == (Image *) NULL) ||
8169 (GetNextImageInList(source) == (Image *) NULL))
8170 source=(Image *) NULL;
8171 else
8172 {
8173 /*
8174 Separate the two lists, junk the null: image.
8175 */
8176 source=SplitImageList(source->previous);
8177 DeleteImageFromList(&source);
8178 }
8179 }
8180 if (source == (Image *) NULL)
8181 {
8182 (void) ThrowMagickException(exception,GetMagickModule(),
8183 OptionError,"MissingNullSeparator","layers Composite");
8184 status=MagickFalse;
8185 break;
8186 }
8187 /*
8188 Adjust offset with gravity and virtual canvas.
8189 */
8190 SetGeometry(*images,&geometry);
8191 (void) ParseAbsoluteGeometry((*images)->geometry,&geometry);
8192 geometry.width=source->page.width != 0 ?
8193 source->page.width : source->columns;
8194 geometry.height=source->page.height != 0 ?
8195 source->page.height : source->rows;
8196 GravityAdjustGeometry((*images)->page.width != 0 ?
8197 (*images)->page.width : (*images)->columns,
8198 (*images)->page.height != 0 ? (*images)->page.height :
8199 (*images)->rows,(*images)->gravity,&geometry);
8200 compose=OverCompositeOp;
8201 option=GetImageOption(image_info,"compose");
8202 if (option != (const char *) NULL)
8203 compose=(CompositeOperator) ParseMagickOption(
8204 MagickComposeOptions,MagickFalse,option);
8205 CompositeLayers(*images,compose,source,geometry.x,geometry.y,
8206 exception);
8207 source=DestroyImageList(source);
8208 break;
8209 }
8210 }
8211 if (layers == (Image *) NULL)
8212 break;
8213 InheritException(exception,&layers->exception);
8214 *images=DestroyImageList(*images);
8215 *images=layers;
8216 break;
8217 }
8218 break;
8219 }
8220 case 'm':
8221 {
8222 if (LocaleCompare("map",option+1) == 0)
8223 {
8224 (void) SyncImagesSettings(image_info,*images);
8225 if (*option == '+')
8226 {
8227 (void) RemapImages(quantize_info,*images,(Image *) NULL);
8228 InheritException(exception,&(*images)->exception);
8229 break;
8230 }
8231 i++;
8232 break;
8233 }
cristyf40785b2010-03-06 02:27:27 +00008234 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00008235 {
8236 Image
cristyf40785b2010-03-06 02:27:27 +00008237 *maximum_image;
cristy1c274c92010-03-06 02:06:45 +00008238
cristyd18ae7c2010-03-07 17:39:52 +00008239 /*
8240 Maximum image sequence (deprecated).
8241 */
cristy1c274c92010-03-06 02:06:45 +00008242 (void) SyncImagesSettings(image_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00008243 maximum_image=EvaluateImages(*images,MaxEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00008244 if (maximum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00008245 {
8246 status=MagickFalse;
8247 break;
8248 }
8249 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00008250 *images=maximum_image;
cristy1c274c92010-03-06 02:06:45 +00008251 break;
8252 }
cristyf40785b2010-03-06 02:27:27 +00008253 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00008254 {
8255 Image
cristyf40785b2010-03-06 02:27:27 +00008256 *minimum_image;
cristy1c274c92010-03-06 02:06:45 +00008257
cristyd18ae7c2010-03-07 17:39:52 +00008258 /*
8259 Minimum image sequence (deprecated).
8260 */
cristy1c274c92010-03-06 02:06:45 +00008261 (void) SyncImagesSettings(image_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00008262 minimum_image=EvaluateImages(*images,MinEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00008263 if (minimum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00008264 {
8265 status=MagickFalse;
8266 break;
8267 }
8268 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00008269 *images=minimum_image;
cristy1c274c92010-03-06 02:06:45 +00008270 break;
8271 }
cristy3ed852e2009-09-05 21:47:34 +00008272 if (LocaleCompare("morph",option+1) == 0)
8273 {
8274 Image
8275 *morph_image;
8276
8277 (void) SyncImagesSettings(image_info,*images);
cristye27293e2009-12-18 02:53:20 +00008278 morph_image=MorphImages(*images,StringToUnsignedLong(argv[i+1]),
cristy3ed852e2009-09-05 21:47:34 +00008279 exception);
8280 if (morph_image == (Image *) NULL)
8281 {
8282 status=MagickFalse;
8283 break;
8284 }
8285 *images=DestroyImageList(*images);
8286 *images=morph_image;
8287 break;
8288 }
8289 if (LocaleCompare("mosaic",option+1) == 0)
8290 {
8291 Image
8292 *mosaic_image;
8293
8294 (void) SyncImagesSettings(image_info,*images);
8295 mosaic_image=MergeImageLayers(*images,MosaicLayer,exception);
8296 if (mosaic_image == (Image *) NULL)
8297 {
8298 status=MagickFalse;
8299 break;
8300 }
8301 *images=DestroyImageList(*images);
8302 *images=mosaic_image;
8303 break;
8304 }
8305 break;
8306 }
8307 case 'p':
8308 {
8309 if (LocaleCompare("print",option+1) == 0)
8310 {
8311 char
8312 *string;
8313
8314 (void) SyncImagesSettings(image_info,*images);
8315 string=InterpretImageProperties(image_info,*images,argv[i+1]);
8316 if (string == (char *) NULL)
8317 break;
8318 InheritException(exception,&(*images)->exception);
8319 (void) fprintf(stdout,"%s",string);
8320 string=DestroyString(string);
8321 }
8322 if (LocaleCompare("process",option+1) == 0)
8323 {
8324 char
8325 **arguments;
8326
8327 int
8328 j,
8329 number_arguments;
8330
8331 (void) SyncImagesSettings(image_info,*images);
8332 arguments=StringToArgv(argv[i+1],&number_arguments);
8333 if (arguments == (char **) NULL)
8334 break;
8335 if ((argc > 1) && (strchr(arguments[1],'=') != (char *) NULL))
8336 {
8337 char
8338 breaker,
8339 quote,
8340 *token;
8341
8342 const char
8343 *arguments;
8344
8345 int
8346 next,
8347 status;
8348
8349 size_t
8350 length;
8351
8352 TokenInfo
8353 *token_info;
8354
8355 /*
8356 Support old style syntax, filter="-option arg".
8357 */
8358 length=strlen(argv[i+1]);
8359 token=(char *) NULL;
8360 if (~length >= MaxTextExtent)
8361 token=(char *) AcquireQuantumMemory(length+MaxTextExtent,
8362 sizeof(*token));
8363 if (token == (char *) NULL)
8364 break;
8365 next=0;
8366 arguments=argv[i+1];
8367 token_info=AcquireTokenInfo();
8368 status=Tokenizer(token_info,0,token,length,arguments,"","=",
8369 "\"",'\0',&breaker,&next,&quote);
8370 token_info=DestroyTokenInfo(token_info);
8371 if (status == 0)
8372 {
8373 const char
8374 *argv;
8375
8376 argv=(&(arguments[next]));
8377 (void) InvokeDynamicImageFilter(token,&(*images),1,&argv,
8378 exception);
8379 }
8380 token=DestroyString(token);
8381 break;
8382 }
8383 (void) InvokeDynamicImageFilter(arguments[1],&(*images),
8384 number_arguments-2,(const char **) arguments+2,exception);
8385 for (j=0; j < number_arguments; j++)
8386 arguments[j]=DestroyString(arguments[j]);
8387 arguments=(char **) RelinquishMagickMemory(arguments);
8388 break;
8389 }
8390 break;
8391 }
8392 case 'r':
8393 {
8394 if (LocaleCompare("reverse",option+1) == 0)
8395 {
8396 ReverseImageList(images);
8397 InheritException(exception,&(*images)->exception);
8398 break;
8399 }
8400 break;
8401 }
8402 case 's':
8403 {
8404 if (LocaleCompare("swap",option+1) == 0)
8405 {
8406 Image
8407 *p,
8408 *q,
8409 *swap;
8410
8411 long
8412 swap_index;
8413
8414 index=(-1);
8415 swap_index=(-2);
8416 if (*option != '+')
8417 {
8418 GeometryInfo
8419 geometry_info;
8420
8421 MagickStatusType
8422 flags;
8423
8424 swap_index=(-1);
8425 flags=ParseGeometry(argv[i+1],&geometry_info);
8426 index=(long) geometry_info.rho;
8427 if ((flags & SigmaValue) != 0)
8428 swap_index=(long) geometry_info.sigma;
8429 }
8430 p=GetImageFromList(*images,index);
8431 q=GetImageFromList(*images,swap_index);
8432 if ((p == (Image *) NULL) || (q == (Image *) NULL))
8433 {
8434 (void) ThrowMagickException(exception,GetMagickModule(),
8435 OptionError,"NoSuchImage","`%s'",(*images)->filename);
8436 status=MagickFalse;
8437 break;
8438 }
8439 if (p == q)
8440 break;
8441 swap=CloneImage(p,0,0,MagickTrue,exception);
8442 ReplaceImageInList(&p,CloneImage(q,0,0,MagickTrue,exception));
8443 ReplaceImageInList(&q,swap);
8444 *images=GetFirstImageInList(q);
8445 break;
8446 }
8447 break;
8448 }
8449 case 'w':
8450 {
8451 if (LocaleCompare("write",option+1) == 0)
8452 {
cristy06609ee2010-03-17 20:21:27 +00008453 char
8454 key[MaxTextExtent];
8455
cristy3ed852e2009-09-05 21:47:34 +00008456 Image
8457 *write_images;
8458
8459 ImageInfo
8460 *write_info;
8461
8462 (void) SyncImagesSettings(image_info,*images);
cristy06609ee2010-03-17 20:21:27 +00008463 (void) FormatMagickString(key,MaxTextExtent,"cache:%s",argv[i+1]);
8464 (void) DeleteImageRegistry(key);
cristy3ed852e2009-09-05 21:47:34 +00008465 write_images=(*images);
8466 if (*option == '+')
8467 write_images=CloneImageList(*images,exception);
8468 write_info=CloneImageInfo(image_info);
8469 status&=WriteImages(write_info,write_images,argv[i+1],exception);
8470 write_info=DestroyImageInfo(write_info);
8471 if (*option == '+')
8472 write_images=DestroyImageList(write_images);
8473 break;
8474 }
8475 break;
8476 }
8477 default:
8478 break;
8479 }
8480 i+=count;
8481 }
8482 quantize_info=DestroyQuantizeInfo(quantize_info);
8483 return(status != 0 ? MagickTrue : MagickFalse);
8484}
8485
8486/*
8487%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8488% %
8489% %
8490% %
8491+ M o g r i f y I m a g e s %
8492% %
8493% %
8494% %
8495%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8496%
8497% MogrifyImages() applies image processing options to a sequence of images as
8498% prescribed by command line options.
8499%
8500% The format of the MogrifyImage method is:
8501%
8502% MagickBooleanType MogrifyImages(ImageInfo *image_info,
8503% const MagickBooleanType post,const int argc,const char **argv,
8504% Image **images,Exceptioninfo *exception)
8505%
8506% A description of each parameter follows:
8507%
8508% o image_info: the image info..
8509%
8510% o post: If true, post process image list operators otherwise pre-process.
8511%
8512% o argc: Specifies a pointer to an integer describing the number of
8513% elements in the argument vector.
8514%
8515% o argv: Specifies a pointer to a text array containing the command line
8516% arguments.
8517%
8518% o images: the images.
8519%
8520% o exception: return any errors or warnings in this structure.
8521%
8522*/
8523WandExport MagickBooleanType MogrifyImages(ImageInfo *image_info,
8524 const MagickBooleanType post,const int argc,const char **argv,
8525 Image **images,ExceptionInfo *exception)
8526{
8527#define MogrifyImageTag "Mogrify/Image"
8528
8529 Image
8530 *image,
8531 *mogrify_images;
8532
cristy0e9f9c12010-02-11 03:00:47 +00008533 MagickBooleanType
8534 proceed;
8535
8536 MagickSizeType
8537 number_images;
8538
cristy3ed852e2009-09-05 21:47:34 +00008539 MagickStatusType
8540 status;
8541
8542 register long
8543 i;
8544
cristy3ed852e2009-09-05 21:47:34 +00008545 /*
8546 Apply options to individual images in the list.
8547 */
8548 assert(image_info != (ImageInfo *) NULL);
8549 assert(image_info->signature == MagickSignature);
8550 if (images == (Image **) NULL)
8551 return(MogrifyImage(image_info,argc,argv,images,exception));
8552 assert((*images)->signature == MagickSignature);
8553 if ((*images)->debug != MagickFalse)
8554 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
8555 (*images)->filename);
8556 if ((argc <= 0) || (*argv == (char *) NULL))
8557 return(MagickTrue);
8558 (void) SetImageInfoProgressMonitor(image_info,(MagickProgressMonitor) NULL,
8559 (void *) NULL);
8560 mogrify_images=NewImageList();
8561 number_images=GetImageListLength(*images);
8562 status=0;
8563 if (post == MagickFalse)
8564 status&=MogrifyImageList(image_info,argc,argv,images,exception);
8565 for (i=0; i < (long) number_images; i++)
8566 {
8567 image=RemoveFirstImageFromList(images);
8568 if (image == (Image *) NULL)
8569 continue;
8570 status&=MogrifyImage(image_info,argc,argv,&image,exception);
8571 AppendImageToList(&mogrify_images,image);
cristy0e9f9c12010-02-11 03:00:47 +00008572 proceed=SetImageProgress(image,MogrifyImageTag,(MagickOffsetType) i,
8573 number_images);
8574 if (proceed == MagickFalse)
8575 break;
cristy3ed852e2009-09-05 21:47:34 +00008576 }
8577 if (post != MagickFalse)
8578 status&=MogrifyImageList(image_info,argc,argv,&mogrify_images,exception);
8579 *images=mogrify_images;
8580 return(status != 0 ? MagickTrue : MagickFalse);
8581}