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