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