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