blob: 8aa1c1b8cdfb7810ebd3a8f2f2b2fe1095f80589 [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 {
cristy83fae872010-04-22 15:04:16 +00003381 (void) DeleteImageArtifact(*image,"identify:unique-colors");
cristy045bd902010-01-30 18:56:24 +00003382 break;
3383 }
cristy83fae872010-04-22 15:04:16 +00003384 (void) SetImageArtifact(*image,"identify:unique-colors","true");
cristy045bd902010-01-30 18:56:24 +00003385 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]);
cristyaeb2cbc2010-05-07 13:28:58 +00005293 status=MogrifyImageInfo(image_info,(int) (i-j+1),(const char **)
cristy3ed852e2009-09-05 21:47:34 +00005294 argv+j,exception);
cristyaeb2cbc2010-05-07 13:28:58 +00005295 return(status != 0 ? MagickFalse : MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00005296 }
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 }
cristy9f2083a2010-04-22 19:48:05 +00005695 if (LocaleCompare("regard-warnings",option+1) == 0)
5696 break;
cristy3ed852e2009-09-05 21:47:34 +00005697 if (LocaleCompare("region",option+1) == 0)
5698 {
5699 if (*option == '+')
5700 break;
5701 i++;
5702 if (i == (long) argc)
5703 ThrowMogrifyException(OptionError,"MissingArgument",option);
5704 if (IsGeometry(argv[i]) == MagickFalse)
5705 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5706 break;
5707 }
cristyf0c78232010-03-15 12:53:40 +00005708 if (LocaleCompare("remap",option+1) == 0)
5709 {
5710 if (*option == '+')
5711 break;
5712 i++;
5713 if (i == (long) (argc-1))
5714 ThrowMogrifyException(OptionError,"MissingArgument",option);
5715 break;
5716 }
cristy3ed852e2009-09-05 21:47:34 +00005717 if (LocaleCompare("render",option+1) == 0)
5718 break;
5719 if (LocaleCompare("repage",option+1) == 0)
5720 {
5721 if (*option == '+')
5722 break;
5723 i++;
5724 if (i == (long) argc)
5725 ThrowMogrifyException(OptionError,"MissingArgument",option);
5726 if (IsGeometry(argv[i]) == MagickFalse)
5727 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5728 break;
5729 }
5730 if (LocaleCompare("resample",option+1) == 0)
5731 {
5732 if (*option == '+')
5733 break;
5734 i++;
5735 if (i == (long) argc)
5736 ThrowMogrifyException(OptionError,"MissingArgument",option);
5737 if (IsGeometry(argv[i]) == MagickFalse)
5738 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5739 break;
5740 }
5741 if (LocaleCompare("resize",option+1) == 0)
5742 {
5743 if (*option == '+')
5744 break;
5745 i++;
5746 if (i == (long) argc)
5747 ThrowMogrifyException(OptionError,"MissingArgument",option);
5748 if (IsGeometry(argv[i]) == MagickFalse)
5749 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5750 break;
5751 }
5752 if (LocaleCompare("reverse",option+1) == 0)
5753 break;
5754 if (LocaleCompare("roll",option+1) == 0)
5755 {
5756 if (*option == '+')
5757 break;
5758 i++;
5759 if (i == (long) argc)
5760 ThrowMogrifyException(OptionError,"MissingArgument",option);
5761 if (IsGeometry(argv[i]) == MagickFalse)
5762 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5763 break;
5764 }
5765 if (LocaleCompare("rotate",option+1) == 0)
5766 {
5767 i++;
5768 if (i == (long) argc)
5769 ThrowMogrifyException(OptionError,"MissingArgument",option);
5770 if (IsGeometry(argv[i]) == MagickFalse)
5771 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5772 break;
5773 }
5774 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5775 }
5776 case 's':
5777 {
5778 if (LocaleCompare("sample",option+1) == 0)
5779 {
5780 if (*option == '+')
5781 break;
5782 i++;
5783 if (i == (long) argc)
5784 ThrowMogrifyException(OptionError,"MissingArgument",option);
5785 if (IsGeometry(argv[i]) == MagickFalse)
5786 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5787 break;
5788 }
5789 if (LocaleCompare("sampling-factor",option+1) == 0)
5790 {
5791 if (*option == '+')
5792 break;
5793 i++;
5794 if (i == (long) argc)
5795 ThrowMogrifyException(OptionError,"MissingArgument",option);
5796 if (IsGeometry(argv[i]) == MagickFalse)
5797 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5798 break;
5799 }
5800 if (LocaleCompare("scale",option+1) == 0)
5801 {
5802 if (*option == '+')
5803 break;
5804 i++;
5805 if (i == (long) argc)
5806 ThrowMogrifyException(OptionError,"MissingArgument",option);
5807 if (IsGeometry(argv[i]) == MagickFalse)
5808 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5809 break;
5810 }
5811 if (LocaleCompare("scene",option+1) == 0)
5812 {
5813 if (*option == '+')
5814 break;
5815 i++;
5816 if (i == (long) argc)
5817 ThrowMogrifyException(OptionError,"MissingArgument",option);
5818 if (IsGeometry(argv[i]) == MagickFalse)
5819 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5820 break;
5821 }
5822 if (LocaleCompare("seed",option+1) == 0)
5823 {
5824 if (*option == '+')
5825 break;
5826 i++;
5827 if (i == (long) argc)
5828 ThrowMogrifyException(OptionError,"MissingArgument",option);
5829 if (IsGeometry(argv[i]) == MagickFalse)
5830 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5831 break;
5832 }
5833 if (LocaleCompare("segment",option+1) == 0)
5834 {
5835 if (*option == '+')
5836 break;
5837 i++;
5838 if (i == (long) argc)
5839 ThrowMogrifyException(OptionError,"MissingArgument",option);
5840 if (IsGeometry(argv[i]) == MagickFalse)
5841 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5842 break;
5843 }
5844 if (LocaleCompare("selective-blur",option+1) == 0)
5845 {
5846 i++;
5847 if (i == (long) argc)
5848 ThrowMogrifyException(OptionError,"MissingArgument",option);
5849 if (IsGeometry(argv[i]) == MagickFalse)
5850 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5851 break;
5852 }
5853 if (LocaleCompare("separate",option+1) == 0)
5854 break;
5855 if (LocaleCompare("sepia-tone",option+1) == 0)
5856 {
5857 if (*option == '+')
5858 break;
5859 i++;
5860 if (i == (long) argc)
5861 ThrowMogrifyException(OptionError,"MissingArgument",option);
5862 if (IsGeometry(argv[i]) == MagickFalse)
5863 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5864 break;
5865 }
5866 if (LocaleCompare("set",option+1) == 0)
5867 {
5868 i++;
5869 if (i == (long) argc)
5870 ThrowMogrifyException(OptionError,"MissingArgument",option);
5871 if (*option == '+')
5872 break;
5873 i++;
5874 if (i == (long) argc)
5875 ThrowMogrifyException(OptionError,"MissingArgument",option);
5876 break;
5877 }
5878 if (LocaleCompare("shade",option+1) == 0)
5879 {
5880 i++;
5881 if (i == (long) argc)
5882 ThrowMogrifyException(OptionError,"MissingArgument",option);
5883 if (IsGeometry(argv[i]) == MagickFalse)
5884 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5885 break;
5886 }
5887 if (LocaleCompare("shadow",option+1) == 0)
5888 {
5889 if (*option == '+')
5890 break;
5891 i++;
5892 if (i == (long) argc)
5893 ThrowMogrifyException(OptionError,"MissingArgument",option);
5894 if (IsGeometry(argv[i]) == MagickFalse)
5895 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5896 break;
5897 }
5898 if (LocaleCompare("sharpen",option+1) == 0)
5899 {
5900 i++;
5901 if (i == (long) argc)
5902 ThrowMogrifyException(OptionError,"MissingArgument",option);
5903 if (IsGeometry(argv[i]) == MagickFalse)
5904 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5905 break;
5906 }
5907 if (LocaleCompare("shave",option+1) == 0)
5908 {
5909 if (*option == '+')
5910 break;
5911 i++;
5912 if (i == (long) argc)
5913 ThrowMogrifyException(OptionError,"MissingArgument",option);
5914 if (IsGeometry(argv[i]) == MagickFalse)
5915 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5916 break;
5917 }
5918 if (LocaleCompare("shear",option+1) == 0)
5919 {
5920 i++;
5921 if (i == (long) argc)
5922 ThrowMogrifyException(OptionError,"MissingArgument",option);
5923 if (IsGeometry(argv[i]) == MagickFalse)
5924 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5925 break;
5926 }
5927 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
5928 {
5929 i++;
5930 if (i == (long) (argc-1))
5931 ThrowMogrifyException(OptionError,"MissingArgument",option);
5932 if (IsGeometry(argv[i]) == MagickFalse)
5933 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5934 break;
5935 }
5936 if (LocaleCompare("size",option+1) == 0)
5937 {
5938 if (*option == '+')
5939 break;
5940 i++;
5941 if (i == (long) argc)
5942 ThrowMogrifyException(OptionError,"MissingArgument",option);
5943 if (IsGeometry(argv[i]) == MagickFalse)
5944 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5945 break;
5946 }
5947 if (LocaleCompare("sketch",option+1) == 0)
5948 {
5949 if (*option == '+')
5950 break;
5951 i++;
5952 if (i == (long) argc)
5953 ThrowMogrifyException(OptionError,"MissingArgument",option);
5954 if (IsGeometry(argv[i]) == MagickFalse)
5955 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5956 break;
5957 }
5958 if (LocaleCompare("solarize",option+1) == 0)
5959 {
5960 if (*option == '+')
5961 break;
5962 i++;
5963 if (i == (long) argc)
5964 ThrowMogrifyException(OptionError,"MissingArgument",option);
5965 if (IsGeometry(argv[i]) == MagickFalse)
5966 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5967 break;
5968 }
5969 if (LocaleCompare("sparse-color",option+1) == 0)
5970 {
5971 long
5972 op;
5973
5974 i++;
5975 if (i == (long) argc)
5976 ThrowMogrifyException(OptionError,"MissingArgument",option);
5977 op=ParseMagickOption(MagickSparseColorOptions,MagickFalse,argv[i]);
5978 if (op < 0)
5979 ThrowMogrifyException(OptionError,"UnrecognizedSparseColorMethod",
5980 argv[i]);
5981 i++;
5982 if (i == (long) (argc-1))
5983 ThrowMogrifyException(OptionError,"MissingArgument",option);
5984 break;
5985 }
5986 if (LocaleCompare("spread",option+1) == 0)
5987 {
5988 if (*option == '+')
5989 break;
5990 i++;
5991 if (i == (long) argc)
5992 ThrowMogrifyException(OptionError,"MissingArgument",option);
5993 if (IsGeometry(argv[i]) == MagickFalse)
5994 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5995 break;
5996 }
5997 if (LocaleCompare("stretch",option+1) == 0)
5998 {
5999 long
6000 stretch;
6001
6002 if (*option == '+')
6003 break;
6004 i++;
6005 if (i == (long) (argc-1))
6006 ThrowMogrifyException(OptionError,"MissingArgument",option);
6007 stretch=ParseMagickOption(MagickStretchOptions,MagickFalse,argv[i]);
6008 if (stretch < 0)
6009 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
6010 argv[i]);
6011 break;
6012 }
6013 if (LocaleCompare("strip",option+1) == 0)
6014 break;
6015 if (LocaleCompare("stroke",option+1) == 0)
6016 {
6017 if (*option == '+')
6018 break;
6019 i++;
6020 if (i == (long) argc)
6021 ThrowMogrifyException(OptionError,"MissingArgument",option);
6022 break;
6023 }
6024 if (LocaleCompare("strokewidth",option+1) == 0)
6025 {
6026 if (*option == '+')
6027 break;
6028 i++;
6029 if (i == (long) argc)
6030 ThrowMogrifyException(OptionError,"MissingArgument",option);
6031 if (IsGeometry(argv[i]) == MagickFalse)
6032 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6033 break;
6034 }
6035 if (LocaleCompare("style",option+1) == 0)
6036 {
6037 long
6038 style;
6039
6040 if (*option == '+')
6041 break;
6042 i++;
6043 if (i == (long) (argc-1))
6044 ThrowMogrifyException(OptionError,"MissingArgument",option);
6045 style=ParseMagickOption(MagickStyleOptions,MagickFalse,argv[i]);
6046 if (style < 0)
6047 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
6048 argv[i]);
6049 break;
6050 }
6051 if (LocaleCompare("swirl",option+1) == 0)
6052 {
6053 if (*option == '+')
6054 break;
6055 i++;
6056 if (i == (long) argc)
6057 ThrowMogrifyException(OptionError,"MissingArgument",option);
6058 if (IsGeometry(argv[i]) == MagickFalse)
6059 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6060 break;
6061 }
6062 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6063 }
6064 case 't':
6065 {
6066 if (LocaleCompare("taint",option+1) == 0)
6067 break;
6068 if (LocaleCompare("texture",option+1) == 0)
6069 {
6070 if (*option == '+')
6071 break;
6072 i++;
6073 if (i == (long) argc)
6074 ThrowMogrifyException(OptionError,"MissingArgument",option);
6075 break;
6076 }
6077 if (LocaleCompare("tile",option+1) == 0)
6078 {
6079 if (*option == '+')
6080 break;
6081 i++;
6082 if (i == (long) (argc-1))
6083 ThrowMogrifyException(OptionError,"MissingArgument",option);
6084 break;
6085 }
6086 if (LocaleCompare("tile-offset",option+1) == 0)
6087 {
6088 if (*option == '+')
6089 break;
6090 i++;
6091 if (i == (long) argc)
6092 ThrowMogrifyException(OptionError,"MissingArgument",option);
6093 if (IsGeometry(argv[i]) == MagickFalse)
6094 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6095 break;
6096 }
6097 if (LocaleCompare("tint",option+1) == 0)
6098 {
6099 if (*option == '+')
6100 break;
6101 i++;
6102 if (i == (long) (argc-1))
6103 ThrowMogrifyException(OptionError,"MissingArgument",option);
6104 if (IsGeometry(argv[i]) == MagickFalse)
6105 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6106 break;
6107 }
6108 if (LocaleCompare("transform",option+1) == 0)
6109 break;
6110 if (LocaleCompare("transpose",option+1) == 0)
6111 break;
6112 if (LocaleCompare("transverse",option+1) == 0)
6113 break;
6114 if (LocaleCompare("threshold",option+1) == 0)
6115 {
6116 if (*option == '+')
6117 break;
6118 i++;
6119 if (i == (long) argc)
6120 ThrowMogrifyException(OptionError,"MissingArgument",option);
6121 if (IsGeometry(argv[i]) == MagickFalse)
6122 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6123 break;
6124 }
6125 if (LocaleCompare("thumbnail",option+1) == 0)
6126 {
6127 if (*option == '+')
6128 break;
6129 i++;
6130 if (i == (long) argc)
6131 ThrowMogrifyException(OptionError,"MissingArgument",option);
6132 if (IsGeometry(argv[i]) == MagickFalse)
6133 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6134 break;
6135 }
6136 if (LocaleCompare("transparent",option+1) == 0)
6137 {
6138 i++;
6139 if (i == (long) argc)
6140 ThrowMogrifyException(OptionError,"MissingArgument",option);
6141 break;
6142 }
6143 if (LocaleCompare("transparent-color",option+1) == 0)
6144 {
6145 if (*option == '+')
6146 break;
6147 i++;
6148 if (i == (long) (argc-1))
6149 ThrowMogrifyException(OptionError,"MissingArgument",option);
6150 break;
6151 }
6152 if (LocaleCompare("treedepth",option+1) == 0)
6153 {
6154 if (*option == '+')
6155 break;
6156 i++;
6157 if (i == (long) argc)
6158 ThrowMogrifyException(OptionError,"MissingArgument",option);
6159 if (IsGeometry(argv[i]) == MagickFalse)
6160 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6161 break;
6162 }
6163 if (LocaleCompare("trim",option+1) == 0)
6164 break;
6165 if (LocaleCompare("type",option+1) == 0)
6166 {
6167 long
6168 type;
6169
6170 if (*option == '+')
6171 break;
6172 i++;
6173 if (i == (long) argc)
6174 ThrowMogrifyException(OptionError,"MissingArgument",option);
6175 type=ParseMagickOption(MagickTypeOptions,MagickFalse,argv[i]);
6176 if (type < 0)
6177 ThrowMogrifyException(OptionError,"UnrecognizedImageType",
6178 argv[i]);
6179 break;
6180 }
6181 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6182 }
6183 case 'u':
6184 {
6185 if (LocaleCompare("undercolor",option+1) == 0)
6186 {
6187 if (*option == '+')
6188 break;
6189 i++;
6190 if (i == (long) argc)
6191 ThrowMogrifyException(OptionError,"MissingArgument",option);
6192 break;
6193 }
6194 if (LocaleCompare("unique-colors",option+1) == 0)
6195 break;
6196 if (LocaleCompare("units",option+1) == 0)
6197 {
6198 long
6199 units;
6200
6201 if (*option == '+')
6202 break;
6203 i++;
6204 if (i == (long) argc)
6205 ThrowMogrifyException(OptionError,"MissingArgument",option);
6206 units=ParseMagickOption(MagickResolutionOptions,MagickFalse,
6207 argv[i]);
6208 if (units < 0)
6209 ThrowMogrifyException(OptionError,"UnrecognizedUnitsType",
6210 argv[i]);
6211 break;
6212 }
6213 if (LocaleCompare("unsharp",option+1) == 0)
6214 {
6215 i++;
6216 if (i == (long) argc)
6217 ThrowMogrifyException(OptionError,"MissingArgument",option);
6218 if (IsGeometry(argv[i]) == MagickFalse)
6219 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6220 break;
6221 }
6222 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6223 }
6224 case 'v':
6225 {
6226 if (LocaleCompare("verbose",option+1) == 0)
6227 {
6228 image_info->verbose=(*option == '-') ? MagickTrue : MagickFalse;
6229 break;
6230 }
6231 if ((LocaleCompare("version",option+1) == 0) ||
6232 (LocaleCompare("-version",option+1) == 0))
6233 {
6234 (void) fprintf(stdout,"Version: %s\n",
6235 GetMagickVersion((unsigned long *) NULL));
cristy610b2e22009-10-22 14:59:43 +00006236 (void) fprintf(stdout,"Copyright: %s\n",GetMagickCopyright());
6237 (void) fprintf(stdout,"Features: %s\n\n",GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00006238 break;
6239 }
6240 if (LocaleCompare("view",option+1) == 0)
6241 {
6242 if (*option == '+')
6243 break;
6244 i++;
6245 if (i == (long) argc)
6246 ThrowMogrifyException(OptionError,"MissingArgument",option);
6247 break;
6248 }
6249 if (LocaleCompare("vignette",option+1) == 0)
6250 {
6251 if (*option == '+')
6252 break;
6253 i++;
6254 if (i == (long) argc)
6255 ThrowMogrifyException(OptionError,"MissingArgument",option);
6256 if (IsGeometry(argv[i]) == MagickFalse)
6257 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6258 break;
6259 }
6260 if (LocaleCompare("virtual-pixel",option+1) == 0)
6261 {
6262 long
6263 method;
6264
6265 if (*option == '+')
6266 break;
6267 i++;
6268 if (i == (long) argc)
6269 ThrowMogrifyException(OptionError,"MissingArgument",option);
6270 method=ParseMagickOption(MagickVirtualPixelOptions,MagickFalse,
6271 argv[i]);
6272 if (method < 0)
6273 ThrowMogrifyException(OptionError,
6274 "UnrecognizedVirtualPixelMethod",argv[i]);
6275 break;
6276 }
6277 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6278 }
6279 case 'w':
6280 {
6281 if (LocaleCompare("wave",option+1) == 0)
6282 {
6283 i++;
6284 if (i == (long) argc)
6285 ThrowMogrifyException(OptionError,"MissingArgument",option);
6286 if (IsGeometry(argv[i]) == MagickFalse)
6287 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6288 break;
6289 }
6290 if (LocaleCompare("weight",option+1) == 0)
6291 {
6292 if (*option == '+')
6293 break;
6294 i++;
6295 if (i == (long) (argc-1))
6296 ThrowMogrifyException(OptionError,"MissingArgument",option);
6297 break;
6298 }
6299 if (LocaleCompare("white-point",option+1) == 0)
6300 {
6301 if (*option == '+')
6302 break;
6303 i++;
6304 if (i == (long) argc)
6305 ThrowMogrifyException(OptionError,"MissingArgument",option);
6306 if (IsGeometry(argv[i]) == MagickFalse)
6307 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6308 break;
6309 }
6310 if (LocaleCompare("white-threshold",option+1) == 0)
6311 {
6312 if (*option == '+')
6313 break;
6314 i++;
6315 if (i == (long) argc)
6316 ThrowMogrifyException(OptionError,"MissingArgument",option);
6317 if (IsGeometry(argv[i]) == MagickFalse)
6318 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6319 break;
6320 }
6321 if (LocaleCompare("write",option+1) == 0)
6322 {
6323 i++;
6324 if (i == (long) (argc-1))
6325 ThrowMogrifyException(OptionError,"MissingArgument",option);
6326 break;
6327 }
6328 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6329 }
6330 case '?':
6331 break;
6332 default:
6333 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6334 }
6335 fire=ParseMagickOption(MagickImageListOptions,MagickFalse,option+1) < 0 ?
6336 MagickFalse : MagickTrue;
6337 if (fire != MagickFalse)
6338 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
6339 }
6340 if (k != 0)
6341 ThrowMogrifyException(OptionError,"UnbalancedParenthesis",argv[i]);
6342 if (i != argc)
6343 ThrowMogrifyException(OptionError,"MissingAnImageFilename",argv[i]);
6344 DestroyMogrify();
6345 return(status != 0 ? MagickTrue : MagickFalse);
6346}
6347
6348/*
6349%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6350% %
6351% %
6352% %
6353+ M o g r i f y I m a g e I n f o %
6354% %
6355% %
6356% %
6357%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6358%
6359% MogrifyImageInfo() applies image processing settings to the image as
6360% prescribed by command line options.
6361%
6362% The format of the MogrifyImageInfo method is:
6363%
6364% MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,const int argc,
6365% const char **argv,ExceptionInfo *exception)
6366%
6367% A description of each parameter follows:
6368%
6369% o image_info: the image info..
6370%
6371% o argc: Specifies a pointer to an integer describing the number of
6372% elements in the argument vector.
6373%
6374% o argv: Specifies a pointer to a text array containing the command line
6375% arguments.
6376%
6377% o exception: return any errors or warnings in this structure.
6378%
6379*/
6380WandExport MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,
6381 const int argc,const char **argv,ExceptionInfo *exception)
6382{
6383 const char
6384 *option;
6385
6386 GeometryInfo
6387 geometry_info;
6388
6389 long
6390 count;
6391
6392 register long
6393 i;
6394
6395 /*
6396 Initialize method variables.
6397 */
6398 assert(image_info != (ImageInfo *) NULL);
6399 assert(image_info->signature == MagickSignature);
6400 if (image_info->debug != MagickFalse)
6401 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
6402 image_info->filename);
6403 if (argc < 0)
6404 return(MagickTrue);
6405 /*
6406 Set the image settings.
6407 */
6408 for (i=0; i < (long) argc; i++)
6409 {
6410 option=argv[i];
6411 if (IsMagickOption(option) == MagickFalse)
6412 continue;
6413 count=MagickMax(ParseMagickOption(MagickCommandOptions,MagickFalse,option),
6414 0L);
6415 if ((i+count) >= argc)
6416 break;
6417 switch (*(option+1))
6418 {
6419 case 'a':
6420 {
6421 if (LocaleCompare("adjoin",option+1) == 0)
6422 {
6423 image_info->adjoin=(*option == '-') ? MagickTrue : MagickFalse;
6424 break;
6425 }
6426 if (LocaleCompare("antialias",option+1) == 0)
6427 {
6428 image_info->antialias=(*option == '-') ? MagickTrue : MagickFalse;
6429 break;
6430 }
6431 if (LocaleCompare("attenuate",option+1) == 0)
6432 {
6433 if (*option == '+')
6434 {
6435 (void) DeleteImageOption(image_info,option+1);
6436 break;
6437 }
6438 (void) SetImageOption(image_info,option+1,argv[i+1]);
6439 break;
6440 }
6441 if (LocaleCompare("authenticate",option+1) == 0)
6442 {
6443 if (*option == '+')
6444 (void) CloneString(&image_info->authenticate,(char *) NULL);
6445 else
6446 (void) CloneString(&image_info->authenticate,argv[i+1]);
6447 break;
6448 }
6449 break;
6450 }
6451 case 'b':
6452 {
6453 if (LocaleCompare("background",option+1) == 0)
6454 {
6455 if (*option == '+')
6456 {
6457 (void) DeleteImageOption(image_info,option+1);
6458 (void) QueryColorDatabase(BackgroundColor,
6459 &image_info->background_color,exception);
6460 break;
6461 }
6462 (void) SetImageOption(image_info,option+1,argv[i+1]);
6463 (void) QueryColorDatabase(argv[i+1],&image_info->background_color,
6464 exception);
6465 break;
6466 }
6467 if (LocaleCompare("bias",option+1) == 0)
6468 {
6469 if (*option == '+')
6470 {
6471 (void) SetImageOption(image_info,option+1,"0.0");
6472 break;
6473 }
6474 (void) SetImageOption(image_info,option+1,argv[i+1]);
6475 break;
6476 }
6477 if (LocaleCompare("black-point-compensation",option+1) == 0)
6478 {
6479 if (*option == '+')
6480 {
6481 (void) SetImageOption(image_info,option+1,"false");
6482 break;
6483 }
6484 (void) SetImageOption(image_info,option+1,"true");
6485 break;
6486 }
6487 if (LocaleCompare("blue-primary",option+1) == 0)
6488 {
6489 if (*option == '+')
6490 {
6491 (void) SetImageOption(image_info,option+1,"0.0");
6492 break;
6493 }
6494 (void) SetImageOption(image_info,option+1,argv[i+1]);
6495 break;
6496 }
6497 if (LocaleCompare("bordercolor",option+1) == 0)
6498 {
6499 if (*option == '+')
6500 {
6501 (void) DeleteImageOption(image_info,option+1);
6502 (void) QueryColorDatabase(BorderColor,&image_info->border_color,
6503 exception);
6504 break;
6505 }
6506 (void) QueryColorDatabase(argv[i+1],&image_info->border_color,
6507 exception);
6508 (void) SetImageOption(image_info,option+1,argv[i+1]);
6509 break;
6510 }
6511 if (LocaleCompare("box",option+1) == 0)
6512 {
6513 if (*option == '+')
6514 {
6515 (void) SetImageOption(image_info,"undercolor","none");
6516 break;
6517 }
6518 (void) SetImageOption(image_info,"undercolor",argv[i+1]);
6519 break;
6520 }
6521 break;
6522 }
6523 case 'c':
6524 {
6525 if (LocaleCompare("cache",option+1) == 0)
6526 {
6527 MagickSizeType
6528 limit;
6529
6530 limit=MagickResourceInfinity;
6531 if (LocaleCompare("unlimited",argv[i+1]) != 0)
cristyf2f27272009-12-17 14:48:46 +00006532 limit=(MagickSizeType) SiPrefixToDouble(argv[i+1],100.0);
cristy3ed852e2009-09-05 21:47:34 +00006533 (void) SetMagickResourceLimit(MemoryResource,limit);
6534 (void) SetMagickResourceLimit(MapResource,2*limit);
6535 break;
6536 }
6537 if (LocaleCompare("caption",option+1) == 0)
6538 {
6539 if (*option == '+')
6540 {
6541 (void) DeleteImageOption(image_info,option+1);
6542 break;
6543 }
6544 (void) SetImageOption(image_info,option+1,argv[i+1]);
6545 break;
6546 }
6547 if (LocaleCompare("channel",option+1) == 0)
6548 {
6549 if (*option == '+')
6550 {
6551 image_info->channel=DefaultChannels;
6552 break;
6553 }
6554 image_info->channel=(ChannelType) ParseChannelOption(argv[i+1]);
6555 break;
6556 }
6557 if (LocaleCompare("colors",option+1) == 0)
6558 {
cristye27293e2009-12-18 02:53:20 +00006559 image_info->colors=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006560 break;
6561 }
6562 if (LocaleCompare("colorspace",option+1) == 0)
6563 {
6564 if (*option == '+')
6565 {
6566 image_info->colorspace=UndefinedColorspace;
6567 (void) SetImageOption(image_info,option+1,"undefined");
6568 break;
6569 }
6570 image_info->colorspace=(ColorspaceType) ParseMagickOption(
6571 MagickColorspaceOptions,MagickFalse,argv[i+1]);
6572 (void) SetImageOption(image_info,option+1,argv[i+1]);
6573 break;
6574 }
6575 if (LocaleCompare("compress",option+1) == 0)
6576 {
6577 if (*option == '+')
6578 {
6579 image_info->compression=UndefinedCompression;
6580 (void) SetImageOption(image_info,option+1,"undefined");
6581 break;
6582 }
6583 image_info->compression=(CompressionType) ParseMagickOption(
6584 MagickCompressOptions,MagickFalse,argv[i+1]);
6585 (void) SetImageOption(image_info,option+1,argv[i+1]);
6586 break;
6587 }
6588 if (LocaleCompare("comment",option+1) == 0)
6589 {
6590 if (*option == '+')
6591 {
6592 (void) DeleteImageOption(image_info,option+1);
6593 break;
6594 }
6595 (void) SetImageOption(image_info,option+1,argv[i+1]);
6596 break;
6597 }
6598 if (LocaleCompare("compose",option+1) == 0)
6599 {
6600 if (*option == '+')
6601 {
6602 (void) SetImageOption(image_info,option+1,"undefined");
6603 break;
6604 }
6605 (void) SetImageOption(image_info,option+1,argv[i+1]);
6606 break;
6607 }
6608 if (LocaleCompare("compress",option+1) == 0)
6609 {
6610 if (*option == '+')
6611 {
6612 image_info->compression=UndefinedCompression;
6613 (void) SetImageOption(image_info,option+1,"undefined");
6614 break;
6615 }
6616 image_info->compression=(CompressionType) ParseMagickOption(
6617 MagickCompressOptions,MagickFalse,argv[i+1]);
6618 (void) SetImageOption(image_info,option+1,argv[i+1]);
6619 break;
6620 }
6621 break;
6622 }
6623 case 'd':
6624 {
6625 if (LocaleCompare("debug",option+1) == 0)
6626 {
6627 if (*option == '+')
6628 (void) SetLogEventMask("none");
6629 else
6630 (void) SetLogEventMask(argv[i+1]);
6631 image_info->debug=IsEventLogging();
6632 break;
6633 }
6634 if (LocaleCompare("define",option+1) == 0)
6635 {
6636 if (*option == '+')
6637 {
6638 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6639 (void) DeleteImageRegistry(argv[i+1]+9);
6640 else
6641 (void) DeleteImageOption(image_info,argv[i+1]);
6642 break;
6643 }
6644 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6645 {
6646 (void) DefineImageRegistry(StringRegistryType,argv[i+1]+9,
6647 exception);
6648 break;
6649 }
6650 (void) DefineImageOption(image_info,argv[i+1]);
6651 break;
6652 }
6653 if (LocaleCompare("delay",option+1) == 0)
6654 {
6655 if (*option == '+')
6656 {
6657 (void) SetImageOption(image_info,option+1,"0");
6658 break;
6659 }
6660 (void) SetImageOption(image_info,option+1,argv[i+1]);
6661 break;
6662 }
6663 if (LocaleCompare("density",option+1) == 0)
6664 {
6665 /*
6666 Set image density.
6667 */
6668 if (*option == '+')
6669 {
6670 if (image_info->density != (char *) NULL)
6671 image_info->density=DestroyString(image_info->density);
6672 (void) SetImageOption(image_info,option+1,"72");
6673 break;
6674 }
6675 (void) CloneString(&image_info->density,argv[i+1]);
6676 (void) SetImageOption(image_info,option+1,argv[i+1]);
6677 break;
6678 }
6679 if (LocaleCompare("depth",option+1) == 0)
6680 {
6681 if (*option == '+')
6682 {
6683 image_info->depth=MAGICKCORE_QUANTUM_DEPTH;
6684 break;
6685 }
cristye27293e2009-12-18 02:53:20 +00006686 image_info->depth=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006687 break;
6688 }
cristyc9b12952010-03-28 01:12:28 +00006689 if (LocaleCompare("direction",option+1) == 0)
6690 {
6691 if (*option == '+')
6692 {
6693 (void) SetImageOption(image_info,option+1,"undefined");
6694 break;
6695 }
6696 (void) SetImageOption(image_info,option+1,argv[i+1]);
6697 break;
6698 }
cristy3ed852e2009-09-05 21:47:34 +00006699 if (LocaleCompare("display",option+1) == 0)
6700 {
6701 if (*option == '+')
6702 {
6703 if (image_info->server_name != (char *) NULL)
6704 image_info->server_name=DestroyString(
6705 image_info->server_name);
6706 break;
6707 }
6708 (void) CloneString(&image_info->server_name,argv[i+1]);
6709 break;
6710 }
6711 if (LocaleCompare("dispose",option+1) == 0)
6712 {
6713 if (*option == '+')
6714 {
6715 (void) SetImageOption(image_info,option+1,"undefined");
6716 break;
6717 }
6718 (void) SetImageOption(image_info,option+1,argv[i+1]);
6719 break;
6720 }
6721 if (LocaleCompare("dither",option+1) == 0)
6722 {
6723 if (*option == '+')
6724 {
6725 image_info->dither=MagickFalse;
6726 (void) SetImageOption(image_info,option+1,"undefined");
6727 break;
6728 }
6729 (void) SetImageOption(image_info,option+1,argv[i+1]);
6730 image_info->dither=MagickTrue;
6731 break;
6732 }
6733 break;
6734 }
6735 case 'e':
6736 {
6737 if (LocaleCompare("encoding",option+1) == 0)
6738 {
6739 if (*option == '+')
6740 {
6741 (void) SetImageOption(image_info,option+1,"undefined");
6742 break;
6743 }
6744 (void) SetImageOption(image_info,option+1,argv[i+1]);
6745 break;
6746 }
6747 if (LocaleCompare("endian",option+1) == 0)
6748 {
6749 if (*option == '+')
6750 {
6751 image_info->endian=UndefinedEndian;
6752 (void) SetImageOption(image_info,option+1,"undefined");
6753 break;
6754 }
6755 image_info->endian=(EndianType) ParseMagickOption(
6756 MagickEndianOptions,MagickFalse,argv[i+1]);
6757 (void) SetImageOption(image_info,option+1,argv[i+1]);
6758 break;
6759 }
6760 if (LocaleCompare("extract",option+1) == 0)
6761 {
6762 /*
6763 Set image extract geometry.
6764 */
6765 if (*option == '+')
6766 {
6767 if (image_info->extract != (char *) NULL)
6768 image_info->extract=DestroyString(image_info->extract);
6769 break;
6770 }
6771 (void) CloneString(&image_info->extract,argv[i+1]);
6772 break;
6773 }
6774 break;
6775 }
6776 case 'f':
6777 {
6778 if (LocaleCompare("fill",option+1) == 0)
6779 {
6780 if (*option == '+')
6781 {
6782 (void) SetImageOption(image_info,option+1,"none");
6783 break;
6784 }
6785 (void) SetImageOption(image_info,option+1,argv[i+1]);
6786 break;
6787 }
6788 if (LocaleCompare("filter",option+1) == 0)
6789 {
6790 if (*option == '+')
6791 {
6792 (void) SetImageOption(image_info,option+1,"undefined");
6793 break;
6794 }
6795 (void) SetImageOption(image_info,option+1,argv[i+1]);
6796 break;
6797 }
6798 if (LocaleCompare("font",option+1) == 0)
6799 {
6800 if (*option == '+')
6801 {
6802 if (image_info->font != (char *) NULL)
6803 image_info->font=DestroyString(image_info->font);
6804 break;
6805 }
6806 (void) CloneString(&image_info->font,argv[i+1]);
6807 break;
6808 }
6809 if (LocaleCompare("format",option+1) == 0)
6810 {
6811 register const char
6812 *q;
6813
6814 for (q=strchr(argv[i+1],'%'); q != (char *) NULL; q=strchr(q+1,'%'))
6815 if (strchr("gkrz@[#",*(q+1)) != (char *) NULL)
6816 image_info->ping=MagickFalse;
6817 (void) SetImageOption(image_info,option+1,argv[i+1]);
6818 break;
6819 }
6820 if (LocaleCompare("fuzz",option+1) == 0)
6821 {
6822 if (*option == '+')
6823 {
6824 image_info->fuzz=0.0;
6825 (void) SetImageOption(image_info,option+1,"0");
6826 break;
6827 }
cristyf2f27272009-12-17 14:48:46 +00006828 image_info->fuzz=SiPrefixToDouble(argv[i+1],(double) QuantumRange+
cristy3ed852e2009-09-05 21:47:34 +00006829 1.0);
6830 (void) SetImageOption(image_info,option+1,argv[i+1]);
6831 break;
6832 }
6833 break;
6834 }
6835 case 'g':
6836 {
6837 if (LocaleCompare("gravity",option+1) == 0)
6838 {
6839 if (*option == '+')
6840 {
6841 (void) SetImageOption(image_info,option+1,"undefined");
6842 break;
6843 }
6844 (void) SetImageOption(image_info,option+1,argv[i+1]);
6845 break;
6846 }
6847 if (LocaleCompare("green-primary",option+1) == 0)
6848 {
6849 if (*option == '+')
6850 {
6851 (void) SetImageOption(image_info,option+1,"0.0");
6852 break;
6853 }
6854 (void) SetImageOption(image_info,option+1,argv[i+1]);
6855 break;
6856 }
6857 break;
6858 }
6859 case 'i':
6860 {
6861 if (LocaleCompare("intent",option+1) == 0)
6862 {
6863 if (*option == '+')
6864 {
6865 (void) SetImageOption(image_info,option+1,"undefined");
6866 break;
6867 }
6868 (void) SetImageOption(image_info,option+1,argv[i+1]);
6869 break;
6870 }
6871 if (LocaleCompare("interlace",option+1) == 0)
6872 {
6873 if (*option == '+')
6874 {
6875 image_info->interlace=UndefinedInterlace;
6876 (void) SetImageOption(image_info,option+1,"undefined");
6877 break;
6878 }
6879 image_info->interlace=(InterlaceType) ParseMagickOption(
6880 MagickInterlaceOptions,MagickFalse,argv[i+1]);
6881 (void) SetImageOption(image_info,option+1,argv[i+1]);
6882 break;
6883 }
cristyb32b90a2009-09-07 21:45:48 +00006884 if (LocaleCompare("interline-spacing",option+1) == 0)
6885 {
6886 if (*option == '+')
6887 {
6888 (void) SetImageOption(image_info,option+1,"undefined");
6889 break;
6890 }
6891 (void) SetImageOption(image_info,option+1,argv[i+1]);
6892 break;
6893 }
cristy3ed852e2009-09-05 21:47:34 +00006894 if (LocaleCompare("interpolate",option+1) == 0)
6895 {
6896 if (*option == '+')
6897 {
6898 (void) SetImageOption(image_info,option+1,"undefined");
6899 break;
6900 }
6901 (void) SetImageOption(image_info,option+1,argv[i+1]);
6902 break;
6903 }
6904 if (LocaleCompare("interword-spacing",option+1) == 0)
6905 {
6906 if (*option == '+')
6907 {
6908 (void) SetImageOption(image_info,option+1,"undefined");
6909 break;
6910 }
6911 (void) SetImageOption(image_info,option+1,argv[i+1]);
6912 break;
6913 }
6914 break;
6915 }
6916 case 'k':
6917 {
6918 if (LocaleCompare("kerning",option+1) == 0)
6919 {
6920 if (*option == '+')
6921 {
6922 (void) SetImageOption(image_info,option+1,"undefined");
6923 break;
6924 }
6925 (void) SetImageOption(image_info,option+1,argv[i+1]);
6926 break;
6927 }
6928 break;
6929 }
6930 case 'l':
6931 {
6932 if (LocaleCompare("label",option+1) == 0)
6933 {
6934 if (*option == '+')
6935 {
6936 (void) DeleteImageOption(image_info,option+1);
6937 break;
6938 }
6939 (void) SetImageOption(image_info,option+1,argv[i+1]);
6940 break;
6941 }
6942 if (LocaleCompare("limit",option+1) == 0)
6943 {
6944 MagickSizeType
6945 limit;
6946
6947 ResourceType
6948 type;
6949
6950 if (*option == '+')
6951 break;
6952 type=(ResourceType) ParseMagickOption(MagickResourceOptions,
6953 MagickFalse,argv[i+1]);
6954 limit=MagickResourceInfinity;
6955 if (LocaleCompare("unlimited",argv[i+2]) != 0)
cristyf2f27272009-12-17 14:48:46 +00006956 limit=(MagickSizeType) SiPrefixToDouble(argv[i+2],100.0);
cristy3ed852e2009-09-05 21:47:34 +00006957 (void) SetMagickResourceLimit(type,limit);
6958 break;
6959 }
6960 if (LocaleCompare("list",option+1) == 0)
6961 {
6962 long
6963 list;
6964
6965 /*
6966 Display configuration list.
6967 */
6968 list=ParseMagickOption(MagickListOptions,MagickFalse,argv[i+1]);
6969 switch (list)
6970 {
6971 case MagickCoderOptions:
6972 {
6973 (void) ListCoderInfo((FILE *) NULL,exception);
6974 break;
6975 }
6976 case MagickColorOptions:
6977 {
6978 (void) ListColorInfo((FILE *) NULL,exception);
6979 break;
6980 }
6981 case MagickConfigureOptions:
6982 {
6983 (void) ListConfigureInfo((FILE *) NULL,exception);
6984 break;
6985 }
6986 case MagickDelegateOptions:
6987 {
6988 (void) ListDelegateInfo((FILE *) NULL,exception);
6989 break;
6990 }
6991 case MagickFontOptions:
6992 {
6993 (void) ListTypeInfo((FILE *) NULL,exception);
6994 break;
6995 }
6996 case MagickFormatOptions:
6997 {
6998 (void) ListMagickInfo((FILE *) NULL,exception);
6999 break;
7000 }
7001 case MagickLocaleOptions:
7002 {
7003 (void) ListLocaleInfo((FILE *) NULL,exception);
7004 break;
7005 }
7006 case MagickLogOptions:
7007 {
7008 (void) ListLogInfo((FILE *) NULL,exception);
7009 break;
7010 }
7011 case MagickMagicOptions:
7012 {
7013 (void) ListMagicInfo((FILE *) NULL,exception);
7014 break;
7015 }
7016 case MagickMimeOptions:
7017 {
7018 (void) ListMimeInfo((FILE *) NULL,exception);
7019 break;
7020 }
7021 case MagickModuleOptions:
7022 {
7023 (void) ListModuleInfo((FILE *) NULL,exception);
7024 break;
7025 }
7026 case MagickPolicyOptions:
7027 {
7028 (void) ListPolicyInfo((FILE *) NULL,exception);
7029 break;
7030 }
7031 case MagickResourceOptions:
7032 {
7033 (void) ListMagickResourceInfo((FILE *) NULL,exception);
7034 break;
7035 }
7036 case MagickThresholdOptions:
7037 {
7038 (void) ListThresholdMaps((FILE *) NULL,exception);
7039 break;
7040 }
7041 default:
7042 {
7043 (void) ListMagickOptions((FILE *) NULL,(MagickOption) list,
7044 exception);
7045 break;
7046 }
7047 }
cristyaeb2cbc2010-05-07 13:28:58 +00007048 break;
cristy3ed852e2009-09-05 21:47:34 +00007049 }
7050 if (LocaleCompare("log",option+1) == 0)
7051 {
7052 if (*option == '+')
7053 break;
7054 (void) SetLogFormat(argv[i+1]);
7055 break;
7056 }
7057 if (LocaleCompare("loop",option+1) == 0)
7058 {
7059 if (*option == '+')
7060 {
7061 (void) SetImageOption(image_info,option+1,"0");
7062 break;
7063 }
7064 (void) SetImageOption(image_info,option+1,argv[i+1]);
7065 break;
7066 }
7067 break;
7068 }
7069 case 'm':
7070 {
7071 if (LocaleCompare("matte",option+1) == 0)
7072 {
7073 if (*option == '+')
7074 {
7075 (void) SetImageOption(image_info,option+1,"false");
7076 break;
7077 }
7078 (void) SetImageOption(image_info,option+1,"true");
7079 break;
7080 }
7081 if (LocaleCompare("mattecolor",option+1) == 0)
7082 {
7083 if (*option == '+')
7084 {
7085 (void) SetImageOption(image_info,option+1,argv[i+1]);
7086 (void) QueryColorDatabase(MatteColor,&image_info->matte_color,
7087 exception);
7088 break;
7089 }
7090 (void) SetImageOption(image_info,option+1,argv[i+1]);
7091 (void) QueryColorDatabase(argv[i+1],&image_info->matte_color,
7092 exception);
7093 break;
7094 }
7095 if (LocaleCompare("monitor",option+1) == 0)
7096 {
7097 (void) SetImageInfoProgressMonitor(image_info,MonitorProgress,
7098 (void *) NULL);
7099 break;
7100 }
7101 if (LocaleCompare("monochrome",option+1) == 0)
7102 {
7103 image_info->monochrome=(*option == '-') ? MagickTrue : MagickFalse;
7104 break;
7105 }
7106 break;
7107 }
7108 case 'o':
7109 {
7110 if (LocaleCompare("orient",option+1) == 0)
7111 {
7112 if (*option == '+')
7113 {
7114 image_info->orientation=UndefinedOrientation;
7115 (void) SetImageOption(image_info,option+1,"undefined");
7116 break;
7117 }
7118 image_info->orientation=(OrientationType) ParseMagickOption(
7119 MagickOrientationOptions,MagickFalse,argv[i+1]);
7120 (void) SetImageOption(image_info,option+1,"undefined");
7121 break;
7122 }
7123 }
7124 case 'p':
7125 {
7126 if (LocaleCompare("page",option+1) == 0)
7127 {
7128 char
7129 *canonical_page,
7130 page[MaxTextExtent];
7131
7132 const char
7133 *image_option;
7134
7135 MagickStatusType
7136 flags;
7137
7138 RectangleInfo
7139 geometry;
7140
7141 if (*option == '+')
7142 {
7143 (void) DeleteImageOption(image_info,option+1);
7144 (void) CloneString(&image_info->page,(char *) NULL);
7145 break;
7146 }
7147 (void) ResetMagickMemory(&geometry,0,sizeof(geometry));
7148 image_option=GetImageOption(image_info,"page");
7149 if (image_option != (const char *) NULL)
7150 flags=ParseAbsoluteGeometry(image_option,&geometry);
7151 canonical_page=GetPageGeometry(argv[i+1]);
7152 flags=ParseAbsoluteGeometry(canonical_page,&geometry);
7153 canonical_page=DestroyString(canonical_page);
7154 (void) FormatMagickString(page,MaxTextExtent,"%lux%lu",
7155 geometry.width,geometry.height);
7156 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
7157 (void) FormatMagickString(page,MaxTextExtent,"%lux%lu%+ld%+ld",
7158 geometry.width,geometry.height,geometry.x,geometry.y);
7159 (void) SetImageOption(image_info,option+1,page);
7160 (void) CloneString(&image_info->page,page);
7161 break;
7162 }
7163 if (LocaleCompare("pen",option+1) == 0)
7164 {
7165 if (*option == '+')
7166 {
7167 (void) SetImageOption(image_info,option+1,"none");
7168 break;
7169 }
7170 (void) SetImageOption(image_info,option+1,argv[i+1]);
7171 break;
7172 }
7173 if (LocaleCompare("ping",option+1) == 0)
7174 {
7175 image_info->ping=(*option == '-') ? MagickTrue : MagickFalse;
7176 break;
7177 }
7178 if (LocaleCompare("pointsize",option+1) == 0)
7179 {
7180 if (*option == '+')
7181 geometry_info.rho=0.0;
7182 else
7183 (void) ParseGeometry(argv[i+1],&geometry_info);
7184 image_info->pointsize=geometry_info.rho;
7185 break;
7186 }
cristye7f51092010-01-17 00:39:37 +00007187 if (LocaleCompare("precision",option+1) == 0)
7188 {
cristybf2766a2010-01-17 03:33:23 +00007189 (void) SetMagickPrecision(StringToInteger(argv[i+1]));
cristye7f51092010-01-17 00:39:37 +00007190 break;
7191 }
cristy3ed852e2009-09-05 21:47:34 +00007192 if (LocaleCompare("preview",option+1) == 0)
7193 {
7194 /*
7195 Preview image.
7196 */
7197 if (*option == '+')
7198 {
7199 image_info->preview_type=UndefinedPreview;
7200 break;
7201 }
7202 image_info->preview_type=(PreviewType) ParseMagickOption(
7203 MagickPreviewOptions,MagickFalse,argv[i+1]);
7204 break;
7205 }
7206 break;
7207 }
7208 case 'q':
7209 {
7210 if (LocaleCompare("quality",option+1) == 0)
7211 {
7212 /*
7213 Set image compression quality.
7214 */
7215 if (*option == '+')
7216 {
7217 image_info->quality=UndefinedCompressionQuality;
7218 (void) SetImageOption(image_info,option+1,"0");
7219 break;
7220 }
cristye27293e2009-12-18 02:53:20 +00007221 image_info->quality=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007222 (void) SetImageOption(image_info,option+1,argv[i+1]);
7223 break;
7224 }
7225 if (LocaleCompare("quiet",option+1) == 0)
7226 {
7227 static WarningHandler
7228 warning_handler = (WarningHandler) NULL;
7229
7230 if (*option == '+')
7231 {
7232 /*
7233 Restore error or warning messages.
7234 */
7235 warning_handler=SetWarningHandler(warning_handler);
7236 break;
7237 }
7238 /*
7239 Suppress error or warning messages.
7240 */
7241 warning_handler=SetWarningHandler((WarningHandler) NULL);
7242 break;
7243 }
7244 break;
7245 }
7246 case 'r':
7247 {
7248 if (LocaleCompare("red-primary",option+1) == 0)
7249 {
7250 if (*option == '+')
7251 {
7252 (void) SetImageOption(image_info,option+1,"0.0");
7253 break;
7254 }
7255 (void) SetImageOption(image_info,option+1,argv[i+1]);
7256 break;
7257 }
7258 break;
7259 }
7260 case 's':
7261 {
7262 if (LocaleCompare("sampling-factor",option+1) == 0)
7263 {
7264 /*
7265 Set image sampling factor.
7266 */
7267 if (*option == '+')
7268 {
7269 if (image_info->sampling_factor != (char *) NULL)
7270 image_info->sampling_factor=DestroyString(
7271 image_info->sampling_factor);
7272 break;
7273 }
7274 (void) CloneString(&image_info->sampling_factor,argv[i+1]);
7275 break;
7276 }
7277 if (LocaleCompare("scene",option+1) == 0)
7278 {
7279 /*
7280 Set image scene.
7281 */
7282 if (*option == '+')
7283 {
7284 image_info->scene=0;
7285 (void) SetImageOption(image_info,option+1,"0");
7286 break;
7287 }
cristye27293e2009-12-18 02:53:20 +00007288 image_info->scene=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007289 (void) SetImageOption(image_info,option+1,argv[i+1]);
7290 break;
7291 }
7292 if (LocaleCompare("seed",option+1) == 0)
7293 {
7294 unsigned long
7295 seed;
7296
7297 if (*option == '+')
7298 {
7299 seed=(unsigned long) time((time_t *) NULL);
7300 SeedPseudoRandomGenerator(seed);
7301 break;
7302 }
cristye27293e2009-12-18 02:53:20 +00007303 seed=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007304 SeedPseudoRandomGenerator(seed);
7305 break;
7306 }
7307 if (LocaleCompare("size",option+1) == 0)
7308 {
7309 if (*option == '+')
7310 {
7311 if (image_info->size != (char *) NULL)
7312 image_info->size=DestroyString(image_info->size);
7313 break;
7314 }
7315 (void) CloneString(&image_info->size,argv[i+1]);
7316 break;
7317 }
7318 if (LocaleCompare("stroke",option+1) == 0)
7319 {
7320 if (*option == '+')
7321 {
7322 (void) SetImageOption(image_info,option+1,"none");
7323 break;
7324 }
7325 (void) SetImageOption(image_info,option+1,argv[i+1]);
7326 break;
7327 }
7328 if (LocaleCompare("strokewidth",option+1) == 0)
7329 {
7330 if (*option == '+')
7331 {
7332 (void) SetImageOption(image_info,option+1,"0");
7333 break;
7334 }
7335 (void) SetImageOption(image_info,option+1,argv[i+1]);
7336 break;
7337 }
7338 break;
7339 }
7340 case 't':
7341 {
7342 if (LocaleCompare("taint",option+1) == 0)
7343 {
7344 if (*option == '+')
7345 {
7346 (void) SetImageOption(image_info,option+1,"false");
7347 break;
7348 }
7349 (void) SetImageOption(image_info,option+1,"true");
7350 break;
7351 }
7352 if (LocaleCompare("texture",option+1) == 0)
7353 {
7354 if (*option == '+')
7355 {
7356 if (image_info->texture != (char *) NULL)
7357 image_info->texture=DestroyString(image_info->texture);
7358 break;
7359 }
7360 (void) CloneString(&image_info->texture,argv[i+1]);
7361 break;
7362 }
7363 if (LocaleCompare("tile-offset",option+1) == 0)
7364 {
7365 if (*option == '+')
7366 {
7367 (void) SetImageOption(image_info,option+1,"0");
7368 break;
7369 }
7370 (void) SetImageOption(image_info,option+1,argv[i+1]);
7371 break;
7372 }
7373 if (LocaleCompare("transparent-color",option+1) == 0)
7374 {
7375 if (*option == '+')
7376 {
7377 (void) QueryColorDatabase("none",&image_info->transparent_color, exception);
7378 (void) SetImageOption(image_info,option+1,"none");
7379 break;
7380 }
7381 (void) QueryColorDatabase(argv[i+1],&image_info->transparent_color,
7382 exception);
7383 (void) SetImageOption(image_info,option+1,argv[i+1]);
7384 break;
7385 }
7386 if (LocaleCompare("type",option+1) == 0)
7387 {
7388 if (*option == '+')
7389 {
7390 image_info->type=UndefinedType;
7391 (void) SetImageOption(image_info,option+1,"undefined");
7392 break;
7393 }
7394 image_info->type=(ImageType) ParseMagickOption(MagickTypeOptions,
7395 MagickFalse,argv[i+1]);
7396 (void) SetImageOption(image_info,option+1,argv[i+1]);
7397 break;
7398 }
7399 break;
7400 }
7401 case 'u':
7402 {
7403 if (LocaleCompare("undercolor",option+1) == 0)
7404 {
7405 if (*option == '+')
7406 {
7407 (void) DeleteImageOption(image_info,option+1);
7408 break;
7409 }
7410 (void) SetImageOption(image_info,option+1,argv[i+1]);
7411 break;
7412 }
7413 if (LocaleCompare("units",option+1) == 0)
7414 {
7415 if (*option == '+')
7416 {
7417 image_info->units=UndefinedResolution;
7418 (void) SetImageOption(image_info,option+1,"undefined");
7419 break;
7420 }
7421 image_info->units=(ResolutionType) ParseMagickOption(
7422 MagickResolutionOptions,MagickFalse,argv[i+1]);
7423 (void) SetImageOption(image_info,option+1,argv[i+1]);
7424 break;
7425 }
7426 break;
7427 }
7428 case 'v':
7429 {
7430 if (LocaleCompare("verbose",option+1) == 0)
7431 {
7432 if (*option == '+')
7433 {
7434 image_info->verbose=MagickFalse;
7435 break;
7436 }
7437 image_info->verbose=MagickTrue;
7438 image_info->ping=MagickFalse;
7439 break;
7440 }
7441 if (LocaleCompare("view",option+1) == 0)
7442 {
7443 if (*option == '+')
7444 {
7445 if (image_info->view != (char *) NULL)
7446 image_info->view=DestroyString(image_info->view);
7447 break;
7448 }
7449 (void) CloneString(&image_info->view,argv[i+1]);
7450 break;
7451 }
7452 if (LocaleCompare("virtual-pixel",option+1) == 0)
7453 {
7454 if (*option == '+')
7455 {
7456 image_info->virtual_pixel_method=UndefinedVirtualPixelMethod;
7457 (void) SetImageOption(image_info,option+1,"undefined");
7458 break;
7459 }
7460 image_info->virtual_pixel_method=(VirtualPixelMethod)
7461 ParseMagickOption(MagickVirtualPixelOptions,MagickFalse,
7462 argv[i+1]);
7463 (void) SetImageOption(image_info,option+1,argv[i+1]);
7464 break;
7465 }
7466 break;
7467 }
7468 case 'w':
7469 {
7470 if (LocaleCompare("white-point",option+1) == 0)
7471 {
7472 if (*option == '+')
7473 {
7474 (void) SetImageOption(image_info,option+1,"0.0");
7475 break;
7476 }
7477 (void) SetImageOption(image_info,option+1,argv[i+1]);
7478 break;
7479 }
7480 break;
7481 }
7482 default:
7483 break;
7484 }
7485 i+=count;
7486 }
7487 return(MagickTrue);
7488}
7489
7490/*
7491%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7492% %
7493% %
7494% %
7495+ M o g r i f y I m a g e L i s t %
7496% %
7497% %
7498% %
7499%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7500%
7501% MogrifyImageList() applies any command line options that might affect the
7502% entire image list (e.g. -append, -coalesce, etc.).
7503%
7504% The format of the MogrifyImage method is:
7505%
7506% MagickBooleanType MogrifyImageList(ImageInfo *image_info,const int argc,
7507% const char **argv,Image **images,ExceptionInfo *exception)
7508%
7509% A description of each parameter follows:
7510%
7511% o image_info: the image info..
7512%
7513% o argc: Specifies a pointer to an integer describing the number of
7514% elements in the argument vector.
7515%
7516% o argv: Specifies a pointer to a text array containing the command line
7517% arguments.
7518%
7519% o images: the images.
7520%
7521% o exception: return any errors or warnings in this structure.
7522%
7523*/
7524WandExport MagickBooleanType MogrifyImageList(ImageInfo *image_info,
7525 const int argc,const char **argv,Image **images,ExceptionInfo *exception)
7526{
7527 ChannelType
7528 channel;
7529
7530 const char
7531 *option;
7532
7533 long
7534 count,
7535 index;
7536
7537 MagickStatusType
7538 status;
7539
7540 QuantizeInfo
7541 *quantize_info;
7542
7543 register long
7544 i;
7545
7546 /*
7547 Apply options to the image list.
7548 */
7549 assert(image_info != (ImageInfo *) NULL);
7550 assert(image_info->signature == MagickSignature);
7551 assert(images != (Image **) NULL);
7552 assert((*images)->signature == MagickSignature);
7553 if ((*images)->debug != MagickFalse)
7554 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
7555 (*images)->filename);
7556 if ((argc <= 0) || (*argv == (char *) NULL))
7557 return(MagickTrue);
7558 quantize_info=AcquireQuantizeInfo(image_info);
7559 channel=image_info->channel;
7560 status=MagickTrue;
7561 for (i=0; i < (long) argc; i++)
7562 {
cristy74fe8f12009-10-03 19:09:01 +00007563 if (*images == (Image *) NULL)
7564 break;
cristy3ed852e2009-09-05 21:47:34 +00007565 option=argv[i];
7566 if (IsMagickOption(option) == MagickFalse)
7567 continue;
7568 count=MagickMax(ParseMagickOption(MagickCommandOptions,MagickFalse,option),
7569 0L);
7570 if ((i+count) >= argc)
7571 break;
7572 status=MogrifyImageInfo(image_info,count+1,argv+i,exception);
7573 switch (*(option+1))
7574 {
7575 case 'a':
7576 {
7577 if (LocaleCompare("affinity",option+1) == 0)
7578 {
7579 (void) SyncImagesSettings(image_info,*images);
7580 if (*option == '+')
7581 {
7582 (void) RemapImages(quantize_info,*images,(Image *) NULL);
7583 InheritException(exception,&(*images)->exception);
7584 break;
7585 }
7586 i++;
7587 break;
7588 }
7589 if (LocaleCompare("append",option+1) == 0)
7590 {
7591 Image
7592 *append_image;
7593
7594 (void) SyncImagesSettings(image_info,*images);
7595 append_image=AppendImages(*images,*option == '-' ? MagickTrue :
7596 MagickFalse,exception);
7597 if (append_image == (Image *) NULL)
7598 {
7599 status=MagickFalse;
7600 break;
7601 }
7602 *images=DestroyImageList(*images);
7603 *images=append_image;
7604 break;
7605 }
7606 if (LocaleCompare("average",option+1) == 0)
7607 {
7608 Image
7609 *average_image;
7610
cristyd18ae7c2010-03-07 17:39:52 +00007611 /*
7612 Average an image sequence (deprecated).
7613 */
cristy3ed852e2009-09-05 21:47:34 +00007614 (void) SyncImagesSettings(image_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007615 average_image=EvaluateImages(*images,MeanEvaluateOperator,
7616 exception);
cristy3ed852e2009-09-05 21:47:34 +00007617 if (average_image == (Image *) NULL)
7618 {
7619 status=MagickFalse;
7620 break;
7621 }
7622 *images=DestroyImageList(*images);
7623 *images=average_image;
7624 break;
7625 }
7626 break;
7627 }
7628 case 'c':
7629 {
7630 if (LocaleCompare("channel",option+1) == 0)
7631 {
7632 if (*option == '+')
7633 {
7634 channel=DefaultChannels;
7635 break;
7636 }
7637 channel=(ChannelType) ParseChannelOption(argv[i+1]);
7638 break;
7639 }
7640 if (LocaleCompare("clut",option+1) == 0)
7641 {
7642 Image
7643 *clut_image,
7644 *image;
7645
7646 (void) SyncImagesSettings(image_info,*images);
7647 image=RemoveFirstImageFromList(images);
7648 clut_image=RemoveFirstImageFromList(images);
7649 if (clut_image == (Image *) NULL)
7650 {
7651 status=MagickFalse;
7652 break;
7653 }
7654 (void) ClutImageChannel(image,channel,clut_image);
7655 clut_image=DestroyImage(clut_image);
7656 InheritException(exception,&image->exception);
7657 *images=DestroyImageList(*images);
7658 *images=image;
7659 break;
7660 }
7661 if (LocaleCompare("coalesce",option+1) == 0)
7662 {
7663 Image
7664 *coalesce_image;
7665
7666 (void) SyncImagesSettings(image_info,*images);
7667 coalesce_image=CoalesceImages(*images,exception);
7668 if (coalesce_image == (Image *) NULL)
7669 {
7670 status=MagickFalse;
7671 break;
7672 }
7673 *images=DestroyImageList(*images);
7674 *images=coalesce_image;
7675 break;
7676 }
7677 if (LocaleCompare("combine",option+1) == 0)
7678 {
7679 Image
7680 *combine_image;
7681
7682 (void) SyncImagesSettings(image_info,*images);
7683 combine_image=CombineImages(*images,channel,exception);
7684 if (combine_image == (Image *) NULL)
7685 {
7686 status=MagickFalse;
7687 break;
7688 }
7689 *images=DestroyImageList(*images);
7690 *images=combine_image;
7691 break;
7692 }
7693 if (LocaleCompare("composite",option+1) == 0)
7694 {
7695 Image
7696 *mask_image,
7697 *composite_image,
7698 *image;
7699
7700 RectangleInfo
7701 geometry;
7702
7703 (void) SyncImagesSettings(image_info,*images);
7704 image=RemoveFirstImageFromList(images);
7705 composite_image=RemoveFirstImageFromList(images);
7706 if (composite_image == (Image *) NULL)
7707 {
7708 status=MagickFalse;
7709 break;
7710 }
7711 (void) TransformImage(&composite_image,(char *) NULL,
7712 composite_image->geometry);
7713 SetGeometry(composite_image,&geometry);
7714 (void) ParseAbsoluteGeometry(composite_image->geometry,&geometry);
7715 GravityAdjustGeometry(image->columns,image->rows,image->gravity,
7716 &geometry);
7717 mask_image=RemoveFirstImageFromList(images);
7718 if (mask_image != (Image *) NULL)
7719 {
7720 if ((image->compose == DisplaceCompositeOp) ||
7721 (image->compose == DistortCompositeOp))
7722 {
7723 /*
7724 Merge Y displacement into X displacement image.
7725 */
7726 (void) CompositeImage(composite_image,CopyGreenCompositeOp,
7727 mask_image,0,0);
7728 mask_image=DestroyImage(mask_image);
7729 }
7730 else
7731 {
7732 /*
7733 Set a blending mask for the composition.
7734 */
7735 image->mask=mask_image;
7736 (void) NegateImage(image->mask,MagickFalse);
7737 }
7738 }
7739 (void) CompositeImageChannel(image,channel,image->compose,
7740 composite_image,geometry.x,geometry.y);
7741 if (image->mask != (Image *) NULL)
7742 image->mask=DestroyImage(image->mask);
7743 composite_image=DestroyImage(composite_image);
7744 InheritException(exception,&image->exception);
7745 *images=DestroyImageList(*images);
7746 *images=image;
7747 break;
7748 }
7749 if (LocaleCompare("crop",option+1) == 0)
7750 {
7751 MagickStatusType
7752 flags;
7753
7754 RectangleInfo
7755 geometry;
7756
7757 (void) SyncImagesSettings(image_info,*images);
7758 flags=ParseGravityGeometry(*images,argv[i+1],&geometry,exception);
7759 if (((geometry.width == 0) && (geometry.height == 0)) ||
7760 ((flags & XValue) != 0) || ((flags & YValue) != 0))
7761 break;
7762 (void) TransformImages(images,argv[i+1],(char *) NULL);
7763 InheritException(exception,&(*images)->exception);
7764 break;
7765 }
7766 break;
7767 }
7768 case 'd':
7769 {
7770 if (LocaleCompare("deconstruct",option+1) == 0)
7771 {
7772 Image
7773 *deconstruct_image;
7774
7775 (void) SyncImagesSettings(image_info,*images);
7776 deconstruct_image=DeconstructImages(*images,exception);
7777 if (deconstruct_image == (Image *) NULL)
7778 {
7779 status=MagickFalse;
7780 break;
7781 }
7782 *images=DestroyImageList(*images);
7783 *images=deconstruct_image;
7784 break;
7785 }
7786 if (LocaleCompare("delete",option+1) == 0)
7787 {
7788 if (*option == '+')
7789 DeleteImages(images,"-1",exception);
7790 else
7791 DeleteImages(images,argv[i+1],exception);
7792 break;
7793 }
7794 if (LocaleCompare("dither",option+1) == 0)
7795 {
7796 if (*option == '+')
7797 {
7798 quantize_info->dither=MagickFalse;
7799 break;
7800 }
7801 quantize_info->dither=MagickTrue;
7802 quantize_info->dither_method=(DitherMethod) ParseMagickOption(
7803 MagickDitherOptions,MagickFalse,argv[i+1]);
7804 break;
7805 }
7806 break;
7807 }
cristyd18ae7c2010-03-07 17:39:52 +00007808 case 'e':
7809 {
7810 if (LocaleCompare("evaluate-sequence",option+1) == 0)
7811 {
7812 Image
7813 *evaluate_image;
7814
7815 MagickEvaluateOperator
7816 op;
7817
7818 (void) SyncImageSettings(image_info,*images);
7819 op=(MagickEvaluateOperator) ParseMagickOption(MagickEvaluateOptions,
7820 MagickFalse,argv[i+1]);
7821 evaluate_image=EvaluateImages(*images,op,exception);
7822 if (evaluate_image == (Image *) NULL)
7823 {
7824 status=MagickFalse;
7825 break;
7826 }
7827 *images=DestroyImageList(*images);
7828 *images=evaluate_image;
7829 break;
7830 }
7831 break;
7832 }
cristy3ed852e2009-09-05 21:47:34 +00007833 case 'f':
7834 {
cristyf0a247f2009-10-04 00:20:03 +00007835 if (LocaleCompare("fft",option+1) == 0)
7836 {
7837 Image
7838 *fourier_image;
7839
7840 /*
7841 Implements the discrete Fourier transform (DFT).
7842 */
7843 (void) SyncImageSettings(image_info,*images);
7844 fourier_image=ForwardFourierTransformImage(*images,*option == '-' ?
7845 MagickTrue : MagickFalse,exception);
7846 if (fourier_image == (Image *) NULL)
7847 break;
7848 *images=DestroyImage(*images);
7849 *images=fourier_image;
7850 break;
7851 }
cristy3ed852e2009-09-05 21:47:34 +00007852 if (LocaleCompare("flatten",option+1) == 0)
7853 {
7854 Image
7855 *flatten_image;
7856
7857 (void) SyncImagesSettings(image_info,*images);
7858 flatten_image=MergeImageLayers(*images,FlattenLayer,exception);
7859 if (flatten_image == (Image *) NULL)
7860 break;
7861 *images=DestroyImageList(*images);
7862 *images=flatten_image;
7863 break;
7864 }
7865 if (LocaleCompare("fx",option+1) == 0)
7866 {
7867 Image
7868 *fx_image;
7869
7870 (void) SyncImagesSettings(image_info,*images);
7871 fx_image=FxImageChannel(*images,channel,argv[i+1],exception);
7872 if (fx_image == (Image *) NULL)
7873 {
7874 status=MagickFalse;
7875 break;
7876 }
7877 *images=DestroyImageList(*images);
7878 *images=fx_image;
7879 break;
7880 }
7881 break;
7882 }
7883 case 'h':
7884 {
7885 if (LocaleCompare("hald-clut",option+1) == 0)
7886 {
7887 Image
7888 *hald_image,
7889 *image;
7890
7891 (void) SyncImagesSettings(image_info,*images);
7892 image=RemoveFirstImageFromList(images);
7893 hald_image=RemoveFirstImageFromList(images);
7894 if (hald_image == (Image *) NULL)
7895 {
7896 status=MagickFalse;
7897 break;
7898 }
7899 (void) HaldClutImageChannel(image,channel,hald_image);
7900 hald_image=DestroyImage(hald_image);
7901 InheritException(exception,&image->exception);
cristy0aff6ea2009-11-14 01:40:53 +00007902 if (*images != (Image *) NULL)
7903 *images=DestroyImageList(*images);
cristy3ed852e2009-09-05 21:47:34 +00007904 *images=image;
7905 break;
7906 }
7907 break;
7908 }
7909 case 'i':
7910 {
7911 if (LocaleCompare("ift",option+1) == 0)
7912 {
7913 Image
cristy8587f882009-11-13 20:28:49 +00007914 *fourier_image,
7915 *magnitude_image,
7916 *phase_image;
cristy3ed852e2009-09-05 21:47:34 +00007917
7918 /*
7919 Implements the inverse fourier discrete Fourier transform (DFT).
7920 */
7921 (void) SyncImagesSettings(image_info,*images);
cristy8587f882009-11-13 20:28:49 +00007922 magnitude_image=RemoveFirstImageFromList(images);
7923 phase_image=RemoveFirstImageFromList(images);
7924 if (phase_image == (Image *) NULL)
7925 {
7926 status=MagickFalse;
7927 break;
7928 }
7929 fourier_image=InverseFourierTransformImage(magnitude_image,
7930 phase_image,*option == '-' ? MagickTrue : MagickFalse,exception);
cristy3ed852e2009-09-05 21:47:34 +00007931 if (fourier_image == (Image *) NULL)
7932 break;
cristy0aff6ea2009-11-14 01:40:53 +00007933 if (*images != (Image *) NULL)
7934 *images=DestroyImage(*images);
cristy3ed852e2009-09-05 21:47:34 +00007935 *images=fourier_image;
7936 break;
7937 }
7938 if (LocaleCompare("insert",option+1) == 0)
7939 {
7940 Image
7941 *p,
7942 *q;
7943
7944 index=0;
7945 if (*option != '+')
cristyf2f27272009-12-17 14:48:46 +00007946 index=StringToLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007947 p=RemoveLastImageFromList(images);
7948 if (p == (Image *) NULL)
7949 {
7950 (void) ThrowMagickException(exception,GetMagickModule(),
7951 OptionError,"NoSuchImage","`%s'",argv[i+1]);
7952 status=MagickFalse;
7953 break;
7954 }
7955 q=p;
7956 if (index == 0)
7957 PrependImageToList(images,q);
7958 else
7959 if (index == (long) GetImageListLength(*images))
7960 AppendImageToList(images,q);
7961 else
7962 {
7963 q=GetImageFromList(*images,index-1);
7964 if (q == (Image *) NULL)
7965 {
7966 (void) ThrowMagickException(exception,GetMagickModule(),
7967 OptionError,"NoSuchImage","`%s'",argv[i+1]);
7968 status=MagickFalse;
7969 break;
7970 }
7971 InsertImageInList(&q,p);
7972 }
7973 *images=GetFirstImageInList(q);
7974 break;
7975 }
7976 break;
7977 }
7978 case 'l':
7979 {
7980 if (LocaleCompare("layers",option+1) == 0)
7981 {
7982 Image
7983 *layers;
7984
7985 ImageLayerMethod
7986 method;
7987
7988 (void) SyncImagesSettings(image_info,*images);
7989 layers=(Image *) NULL;
7990 method=(ImageLayerMethod) ParseMagickOption(MagickLayerOptions,
7991 MagickFalse,argv[i+1]);
7992 switch (method)
7993 {
7994 case CoalesceLayer:
7995 {
7996 layers=CoalesceImages(*images,exception);
7997 break;
7998 }
7999 case CompareAnyLayer:
8000 case CompareClearLayer:
8001 case CompareOverlayLayer:
8002 default:
8003 {
8004 layers=CompareImageLayers(*images,method,exception);
8005 break;
8006 }
8007 case MergeLayer:
8008 case FlattenLayer:
8009 case MosaicLayer:
8010 case TrimBoundsLayer:
8011 {
8012 layers=MergeImageLayers(*images,method,exception);
8013 break;
8014 }
8015 case DisposeLayer:
8016 {
8017 layers=DisposeImages(*images,exception);
8018 break;
8019 }
8020 case OptimizeImageLayer:
8021 {
8022 layers=OptimizeImageLayers(*images,exception);
8023 break;
8024 }
8025 case OptimizePlusLayer:
8026 {
8027 layers=OptimizePlusImageLayers(*images,exception);
8028 break;
8029 }
8030 case OptimizeTransLayer:
8031 {
8032 OptimizeImageTransparency(*images,exception);
8033 break;
8034 }
8035 case RemoveDupsLayer:
8036 {
8037 RemoveDuplicateLayers(images,exception);
8038 break;
8039 }
8040 case RemoveZeroLayer:
8041 {
8042 RemoveZeroDelayLayers(images,exception);
8043 break;
8044 }
8045 case OptimizeLayer:
8046 {
8047 /*
8048 General Purpose, GIF Animation Optimizer.
8049 */
8050 layers=CoalesceImages(*images,exception);
8051 if (layers == (Image *) NULL)
8052 {
8053 status=MagickFalse;
8054 break;
8055 }
8056 InheritException(exception,&layers->exception);
8057 *images=DestroyImageList(*images);
8058 *images=layers;
8059 layers=OptimizeImageLayers(*images,exception);
8060 if (layers == (Image *) NULL)
8061 {
8062 status=MagickFalse;
8063 break;
8064 }
8065 InheritException(exception,&layers->exception);
8066 *images=DestroyImageList(*images);
8067 *images=layers;
8068 layers=(Image *) NULL;
8069 OptimizeImageTransparency(*images,exception);
8070 InheritException(exception,&(*images)->exception);
8071 (void) RemapImages(quantize_info,*images,(Image *) NULL);
8072 break;
8073 }
8074 case CompositeLayer:
8075 {
8076 CompositeOperator
8077 compose;
8078
8079 Image
8080 *source;
8081
8082 RectangleInfo
8083 geometry;
8084
8085 /*
8086 Split image sequence at the first 'NULL:' image.
8087 */
8088 source=(*images);
8089 while (source != (Image *) NULL)
8090 {
8091 source=GetNextImageInList(source);
8092 if ((source != (Image *) NULL) &&
8093 (LocaleCompare(source->magick,"NULL") == 0))
8094 break;
8095 }
8096 if (source != (Image *) NULL)
8097 {
8098 if ((GetPreviousImageInList(source) == (Image *) NULL) ||
8099 (GetNextImageInList(source) == (Image *) NULL))
8100 source=(Image *) NULL;
8101 else
8102 {
8103 /*
8104 Separate the two lists, junk the null: image.
8105 */
8106 source=SplitImageList(source->previous);
8107 DeleteImageFromList(&source);
8108 }
8109 }
8110 if (source == (Image *) NULL)
8111 {
8112 (void) ThrowMagickException(exception,GetMagickModule(),
8113 OptionError,"MissingNullSeparator","layers Composite");
8114 status=MagickFalse;
8115 break;
8116 }
8117 /*
8118 Adjust offset with gravity and virtual canvas.
8119 */
8120 SetGeometry(*images,&geometry);
8121 (void) ParseAbsoluteGeometry((*images)->geometry,&geometry);
8122 geometry.width=source->page.width != 0 ?
8123 source->page.width : source->columns;
8124 geometry.height=source->page.height != 0 ?
8125 source->page.height : source->rows;
8126 GravityAdjustGeometry((*images)->page.width != 0 ?
8127 (*images)->page.width : (*images)->columns,
8128 (*images)->page.height != 0 ? (*images)->page.height :
8129 (*images)->rows,(*images)->gravity,&geometry);
8130 compose=OverCompositeOp;
8131 option=GetImageOption(image_info,"compose");
8132 if (option != (const char *) NULL)
8133 compose=(CompositeOperator) ParseMagickOption(
8134 MagickComposeOptions,MagickFalse,option);
8135 CompositeLayers(*images,compose,source,geometry.x,geometry.y,
8136 exception);
8137 source=DestroyImageList(source);
8138 break;
8139 }
8140 }
8141 if (layers == (Image *) NULL)
8142 break;
8143 InheritException(exception,&layers->exception);
8144 *images=DestroyImageList(*images);
8145 *images=layers;
8146 break;
8147 }
8148 break;
8149 }
8150 case 'm':
8151 {
8152 if (LocaleCompare("map",option+1) == 0)
8153 {
8154 (void) SyncImagesSettings(image_info,*images);
8155 if (*option == '+')
8156 {
8157 (void) RemapImages(quantize_info,*images,(Image *) NULL);
8158 InheritException(exception,&(*images)->exception);
8159 break;
8160 }
8161 i++;
8162 break;
8163 }
cristyf40785b2010-03-06 02:27:27 +00008164 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00008165 {
8166 Image
cristyf40785b2010-03-06 02:27:27 +00008167 *maximum_image;
cristy1c274c92010-03-06 02:06:45 +00008168
cristyd18ae7c2010-03-07 17:39:52 +00008169 /*
8170 Maximum image sequence (deprecated).
8171 */
cristy1c274c92010-03-06 02:06:45 +00008172 (void) SyncImagesSettings(image_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00008173 maximum_image=EvaluateImages(*images,MaxEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00008174 if (maximum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00008175 {
8176 status=MagickFalse;
8177 break;
8178 }
8179 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00008180 *images=maximum_image;
cristy1c274c92010-03-06 02:06:45 +00008181 break;
8182 }
cristyf40785b2010-03-06 02:27:27 +00008183 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00008184 {
8185 Image
cristyf40785b2010-03-06 02:27:27 +00008186 *minimum_image;
cristy1c274c92010-03-06 02:06:45 +00008187
cristyd18ae7c2010-03-07 17:39:52 +00008188 /*
8189 Minimum image sequence (deprecated).
8190 */
cristy1c274c92010-03-06 02:06:45 +00008191 (void) SyncImagesSettings(image_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00008192 minimum_image=EvaluateImages(*images,MinEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00008193 if (minimum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00008194 {
8195 status=MagickFalse;
8196 break;
8197 }
8198 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00008199 *images=minimum_image;
cristy1c274c92010-03-06 02:06:45 +00008200 break;
8201 }
cristy3ed852e2009-09-05 21:47:34 +00008202 if (LocaleCompare("morph",option+1) == 0)
8203 {
8204 Image
8205 *morph_image;
8206
8207 (void) SyncImagesSettings(image_info,*images);
cristye27293e2009-12-18 02:53:20 +00008208 morph_image=MorphImages(*images,StringToUnsignedLong(argv[i+1]),
cristy3ed852e2009-09-05 21:47:34 +00008209 exception);
8210 if (morph_image == (Image *) NULL)
8211 {
8212 status=MagickFalse;
8213 break;
8214 }
8215 *images=DestroyImageList(*images);
8216 *images=morph_image;
8217 break;
8218 }
8219 if (LocaleCompare("mosaic",option+1) == 0)
8220 {
8221 Image
8222 *mosaic_image;
8223
8224 (void) SyncImagesSettings(image_info,*images);
8225 mosaic_image=MergeImageLayers(*images,MosaicLayer,exception);
8226 if (mosaic_image == (Image *) NULL)
8227 {
8228 status=MagickFalse;
8229 break;
8230 }
8231 *images=DestroyImageList(*images);
8232 *images=mosaic_image;
8233 break;
8234 }
8235 break;
8236 }
8237 case 'p':
8238 {
8239 if (LocaleCompare("print",option+1) == 0)
8240 {
8241 char
8242 *string;
8243
8244 (void) SyncImagesSettings(image_info,*images);
8245 string=InterpretImageProperties(image_info,*images,argv[i+1]);
8246 if (string == (char *) NULL)
8247 break;
8248 InheritException(exception,&(*images)->exception);
8249 (void) fprintf(stdout,"%s",string);
8250 string=DestroyString(string);
8251 }
8252 if (LocaleCompare("process",option+1) == 0)
8253 {
8254 char
8255 **arguments;
8256
8257 int
8258 j,
8259 number_arguments;
8260
8261 (void) SyncImagesSettings(image_info,*images);
8262 arguments=StringToArgv(argv[i+1],&number_arguments);
8263 if (arguments == (char **) NULL)
8264 break;
8265 if ((argc > 1) && (strchr(arguments[1],'=') != (char *) NULL))
8266 {
8267 char
8268 breaker,
8269 quote,
8270 *token;
8271
8272 const char
8273 *arguments;
8274
8275 int
8276 next,
8277 status;
8278
8279 size_t
8280 length;
8281
8282 TokenInfo
8283 *token_info;
8284
8285 /*
8286 Support old style syntax, filter="-option arg".
8287 */
8288 length=strlen(argv[i+1]);
8289 token=(char *) NULL;
8290 if (~length >= MaxTextExtent)
8291 token=(char *) AcquireQuantumMemory(length+MaxTextExtent,
8292 sizeof(*token));
8293 if (token == (char *) NULL)
8294 break;
8295 next=0;
8296 arguments=argv[i+1];
8297 token_info=AcquireTokenInfo();
8298 status=Tokenizer(token_info,0,token,length,arguments,"","=",
8299 "\"",'\0',&breaker,&next,&quote);
8300 token_info=DestroyTokenInfo(token_info);
8301 if (status == 0)
8302 {
8303 const char
8304 *argv;
8305
8306 argv=(&(arguments[next]));
8307 (void) InvokeDynamicImageFilter(token,&(*images),1,&argv,
8308 exception);
8309 }
8310 token=DestroyString(token);
8311 break;
8312 }
cristy91c0da22010-05-02 01:44:07 +00008313 (void) SubstituteString(&arguments[1],"-","");
cristy3ed852e2009-09-05 21:47:34 +00008314 (void) InvokeDynamicImageFilter(arguments[1],&(*images),
8315 number_arguments-2,(const char **) arguments+2,exception);
8316 for (j=0; j < number_arguments; j++)
8317 arguments[j]=DestroyString(arguments[j]);
8318 arguments=(char **) RelinquishMagickMemory(arguments);
8319 break;
8320 }
8321 break;
8322 }
8323 case 'r':
8324 {
8325 if (LocaleCompare("reverse",option+1) == 0)
8326 {
8327 ReverseImageList(images);
8328 InheritException(exception,&(*images)->exception);
8329 break;
8330 }
8331 break;
8332 }
8333 case 's':
8334 {
8335 if (LocaleCompare("swap",option+1) == 0)
8336 {
8337 Image
8338 *p,
8339 *q,
8340 *swap;
8341
8342 long
8343 swap_index;
8344
8345 index=(-1);
8346 swap_index=(-2);
8347 if (*option != '+')
8348 {
8349 GeometryInfo
8350 geometry_info;
8351
8352 MagickStatusType
8353 flags;
8354
8355 swap_index=(-1);
8356 flags=ParseGeometry(argv[i+1],&geometry_info);
8357 index=(long) geometry_info.rho;
8358 if ((flags & SigmaValue) != 0)
8359 swap_index=(long) geometry_info.sigma;
8360 }
8361 p=GetImageFromList(*images,index);
8362 q=GetImageFromList(*images,swap_index);
8363 if ((p == (Image *) NULL) || (q == (Image *) NULL))
8364 {
8365 (void) ThrowMagickException(exception,GetMagickModule(),
8366 OptionError,"NoSuchImage","`%s'",(*images)->filename);
8367 status=MagickFalse;
8368 break;
8369 }
8370 if (p == q)
8371 break;
8372 swap=CloneImage(p,0,0,MagickTrue,exception);
8373 ReplaceImageInList(&p,CloneImage(q,0,0,MagickTrue,exception));
8374 ReplaceImageInList(&q,swap);
8375 *images=GetFirstImageInList(q);
8376 break;
8377 }
8378 break;
8379 }
8380 case 'w':
8381 {
8382 if (LocaleCompare("write",option+1) == 0)
8383 {
cristy071dd7b2010-04-09 13:04:54 +00008384 char
cristy06609ee2010-03-17 20:21:27 +00008385 key[MaxTextExtent];
8386
cristy3ed852e2009-09-05 21:47:34 +00008387 Image
8388 *write_images;
8389
8390 ImageInfo
8391 *write_info;
8392
8393 (void) SyncImagesSettings(image_info,*images);
cristy06609ee2010-03-17 20:21:27 +00008394 (void) FormatMagickString(key,MaxTextExtent,"cache:%s",argv[i+1]);
8395 (void) DeleteImageRegistry(key);
cristy3ed852e2009-09-05 21:47:34 +00008396 write_images=(*images);
8397 if (*option == '+')
8398 write_images=CloneImageList(*images,exception);
8399 write_info=CloneImageInfo(image_info);
8400 status&=WriteImages(write_info,write_images,argv[i+1],exception);
8401 write_info=DestroyImageInfo(write_info);
8402 if (*option == '+')
8403 write_images=DestroyImageList(write_images);
8404 break;
8405 }
8406 break;
8407 }
8408 default:
8409 break;
8410 }
8411 i+=count;
8412 }
8413 quantize_info=DestroyQuantizeInfo(quantize_info);
8414 return(status != 0 ? MagickTrue : MagickFalse);
8415}
8416
8417/*
8418%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8419% %
8420% %
8421% %
8422+ M o g r i f y I m a g e s %
8423% %
8424% %
8425% %
8426%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8427%
8428% MogrifyImages() applies image processing options to a sequence of images as
8429% prescribed by command line options.
8430%
8431% The format of the MogrifyImage method is:
8432%
8433% MagickBooleanType MogrifyImages(ImageInfo *image_info,
8434% const MagickBooleanType post,const int argc,const char **argv,
8435% Image **images,Exceptioninfo *exception)
8436%
8437% A description of each parameter follows:
8438%
8439% o image_info: the image info..
8440%
8441% o post: If true, post process image list operators otherwise pre-process.
8442%
8443% o argc: Specifies a pointer to an integer describing the number of
8444% elements in the argument vector.
8445%
8446% o argv: Specifies a pointer to a text array containing the command line
8447% arguments.
8448%
8449% o images: the images.
8450%
8451% o exception: return any errors or warnings in this structure.
8452%
8453*/
8454WandExport MagickBooleanType MogrifyImages(ImageInfo *image_info,
8455 const MagickBooleanType post,const int argc,const char **argv,
8456 Image **images,ExceptionInfo *exception)
8457{
8458#define MogrifyImageTag "Mogrify/Image"
8459
8460 Image
8461 *image,
8462 *mogrify_images;
8463
cristy0e9f9c12010-02-11 03:00:47 +00008464 MagickBooleanType
8465 proceed;
8466
8467 MagickSizeType
8468 number_images;
8469
cristy3ed852e2009-09-05 21:47:34 +00008470 MagickStatusType
8471 status;
8472
8473 register long
8474 i;
8475
cristy3ed852e2009-09-05 21:47:34 +00008476 /*
8477 Apply options to individual images in the list.
8478 */
8479 assert(image_info != (ImageInfo *) NULL);
8480 assert(image_info->signature == MagickSignature);
8481 if (images == (Image **) NULL)
8482 return(MogrifyImage(image_info,argc,argv,images,exception));
8483 assert((*images)->signature == MagickSignature);
8484 if ((*images)->debug != MagickFalse)
8485 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
8486 (*images)->filename);
8487 if ((argc <= 0) || (*argv == (char *) NULL))
8488 return(MagickTrue);
8489 (void) SetImageInfoProgressMonitor(image_info,(MagickProgressMonitor) NULL,
8490 (void *) NULL);
8491 mogrify_images=NewImageList();
8492 number_images=GetImageListLength(*images);
8493 status=0;
8494 if (post == MagickFalse)
8495 status&=MogrifyImageList(image_info,argc,argv,images,exception);
8496 for (i=0; i < (long) number_images; i++)
8497 {
8498 image=RemoveFirstImageFromList(images);
8499 if (image == (Image *) NULL)
8500 continue;
8501 status&=MogrifyImage(image_info,argc,argv,&image,exception);
8502 AppendImageToList(&mogrify_images,image);
cristy0e9f9c12010-02-11 03:00:47 +00008503 proceed=SetImageProgress(image,MogrifyImageTag,(MagickOffsetType) i,
8504 number_images);
8505 if (proceed == MagickFalse)
8506 break;
cristy3ed852e2009-09-05 21:47:34 +00008507 }
8508 if (post != MagickFalse)
8509 status&=MogrifyImageList(image_info,argc,argv,&mogrify_images,exception);
8510 *images=mogrify_images;
8511 return(status != 0 ? MagickTrue : MagickFalse);
8512}