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