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