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