blob: 73227d3e8364625b911f10bca6880140b29fcadf [file] [log] [blame]
cristy3ed852e2009-09-05 21:47:34 +00001/*
2%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3% %
4% %
5% %
6% M M OOO GGGGG RRRR IIIII FFFFF Y Y %
7% MM MM O O G R R I F Y Y %
8% M M M O O G GGG RRRR I FFF Y %
9% M M O O G G R R I F Y %
10% M M OOO GGGG R R IIIII F Y %
11% %
12% %
13% MagickWand Module Methods %
14% %
15% Software Design %
16% John Cristy %
17% March 2000 %
18% %
19% %
cristy16af1cb2009-12-11 21:38:29 +000020% Copyright 1999-2010 ImageMagick Studio LLC, a non-profit organization %
cristy3ed852e2009-09-05 21:47:34 +000021% dedicated to making software imaging solutions freely available. %
22% %
23% You may not use this file except in compliance with the License. You may %
24% obtain a copy of the License at %
25% %
26% http://www.imagemagick.org/script/license.php %
27% %
28% Unless required by applicable law or agreed to in writing, software %
29% distributed under the License is distributed on an "AS IS" BASIS, %
30% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
31% See the License for the specific language governing permissions and %
32% limitations under the License. %
33% %
34%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35%
36% Use the mogrify program to resize an image, blur, crop, despeckle, dither,
37% draw on, flip, join, re-sample, and much more. This tool is similiar to
38% convert except that the original image file is overwritten (unless you
39% change the file suffix with the -format option) with any changes you
cristy6a917d92009-10-06 19:23:54 +000040% request.
cristy3ed852e2009-09-05 21:47:34 +000041%
42*/
43
44/*
45 Include declarations.
46*/
47#include "wand/studio.h"
48#include "wand/MagickWand.h"
49#include "wand/mogrify-private.h"
cristy0e9f9c12010-02-11 03:00:47 +000050#include "magick/monitor-private.h"
cristy3980b0d2009-10-25 14:37:13 +000051#include "magick/thread-private.h"
cristyf2f27272009-12-17 14:48:46 +000052#include "magick/string-private.h"
cristy3ed852e2009-09-05 21:47:34 +000053
54/*
55 Define declarations.
56*/
57#define UndefinedCompressionQuality 0UL
58
59/*
60 Constant declaration.
61*/
62static const char
cristy7138c592009-09-08 13:58:52 +000063 BackgroundColor[] = "#fff", /* white */
64 BorderColor[] = "#dfdfdf", /* gray */
65 MatteColor[] = "#bdbdbd"; /* gray */
cristy3ed852e2009-09-05 21:47:34 +000066
67/*
68%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
69% %
70% %
71% %
cristy3980b0d2009-10-25 14:37:13 +000072+ M a g i c k C o m m a n d G e n e s i s %
73% %
74% %
75% %
76%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
77%
78% MagickCommandGenesis() applies image processing options to an image as
79% prescribed by command line options.
80%
81% The format of the MagickCommandGenesis method is:
82%
83% MagickBooleanType MagickCommandGenesis(ImageInfo *image_info,
84% MagickCommand command,const int argc,const char **argv,Image **image)
85%
86% A description of each parameter follows:
87%
88% o image_info: the image info.
89%
90% o command: the magick command.
91%
92% o argc: Specifies a pointer to an integer describing the number of
93% elements in the argument vector.
94%
95% o argv: Specifies a pointer to a text array containing the command line
96% arguments.
97%
98% o image: the image.
99%
100% o exception: return any errors or warnings in this structure.
101%
102*/
103WandExport MagickBooleanType MagickCommandGenesis(ImageInfo *image_info,
104 MagickCommand command,int argc,char **argv,char **metadata,
105 ExceptionInfo *exception)
106{
107 char
108 *option;
109
110 double
111 duration,
112 elapsed_time,
113 user_time;
114
cristy3980b0d2009-10-25 14:37:13 +0000115 MagickBooleanType
116 concurrent,
117 regard_warnings,
118 status;
119
cristybb503372010-05-27 20:51:26 +0000120 register ssize_t
cristy3980b0d2009-10-25 14:37:13 +0000121 i;
122
123 TimerInfo
124 *timer;
125
cristybb503372010-05-27 20:51:26 +0000126 size_t
cristy3980b0d2009-10-25 14:37:13 +0000127 iterations;
128
cristyd0a94fa2010-03-12 14:18:11 +0000129 (void) setlocale(LC_ALL,"");
130 (void) setlocale(LC_NUMERIC,"C");
cristy3980b0d2009-10-25 14:37:13 +0000131 concurrent=MagickFalse;
132 duration=(-1.0);
133 iterations=1;
cristy33557d72009-11-06 00:54:33 +0000134 status=MagickFalse;
cristy3980b0d2009-10-25 14:37:13 +0000135 regard_warnings=MagickFalse;
cristybb503372010-05-27 20:51:26 +0000136 for (i=1; i < (ssize_t) (argc-1); i++)
cristy3980b0d2009-10-25 14:37:13 +0000137 {
138 option=argv[i];
139 if ((strlen(option) == 1) || ((*option != '-') && (*option != '+')))
140 continue;
141 if (LocaleCompare("bench",option+1) == 0)
cristye27293e2009-12-18 02:53:20 +0000142 iterations=StringToUnsignedLong(argv[++i]);
cristy3980b0d2009-10-25 14:37:13 +0000143 if (LocaleCompare("concurrent",option+1) == 0)
144 concurrent=MagickTrue;
145 if (LocaleCompare("debug",option+1) == 0)
146 (void) SetLogEventMask(argv[++i]);
147 if (LocaleCompare("duration",option+1) == 0)
cristyf2f27272009-12-17 14:48:46 +0000148 duration=StringToDouble(argv[++i]);
cristy3980b0d2009-10-25 14:37:13 +0000149 if (LocaleCompare("regard-warnings",option+1) == 0)
150 regard_warnings=MagickTrue;
151 }
152 timer=AcquireTimerInfo();
cristyceae09d2009-10-28 17:18:47 +0000153 if (concurrent == MagickFalse)
cristy3980b0d2009-10-25 14:37:13 +0000154 {
cristybb503372010-05-27 20:51:26 +0000155 for (i=0; i < (ssize_t) iterations; i++)
cristy3980b0d2009-10-25 14:37:13 +0000156 {
cristy33557d72009-11-06 00:54:33 +0000157 if (status != MagickFalse)
cristyceae09d2009-10-28 17:18:47 +0000158 continue;
159 if (duration > 0)
160 {
161 if (GetElapsedTime(timer) > duration)
162 continue;
163 (void) ContinueTimer(timer);
164 }
165 status=command(image_info,argc,argv,metadata,exception);
cristy3980b0d2009-10-25 14:37:13 +0000166 if (exception->severity != UndefinedException)
167 {
168 if ((exception->severity > ErrorException) ||
169 (regard_warnings != MagickFalse))
170 status=MagickTrue;
171 CatchException(exception);
172 }
cristy3d1a5512009-10-25 21:23:27 +0000173 if ((metadata != (char **) NULL) && (*metadata != (char *) NULL))
cristy3980b0d2009-10-25 14:37:13 +0000174 {
175 (void) fputs(*metadata,stdout);
176 (void) fputc('\n',stdout);
177 *metadata=DestroyString(*metadata);
178 }
179 }
180 }
cristyceae09d2009-10-28 17:18:47 +0000181 else
182 {
183 SetOpenMPNested(1);
cristyb5d5f722009-11-04 03:03:49 +0000184#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristyceae09d2009-10-28 17:18:47 +0000185 # pragma omp parallel for shared(status)
186#endif
cristybb503372010-05-27 20:51:26 +0000187 for (i=0; i < (ssize_t) iterations; i++)
cristyceae09d2009-10-28 17:18:47 +0000188 {
cristy33557d72009-11-06 00:54:33 +0000189 if (status != MagickFalse)
cristyceae09d2009-10-28 17:18:47 +0000190 continue;
191 if (duration > 0)
192 {
193 if (GetElapsedTime(timer) > duration)
194 continue;
195 (void) ContinueTimer(timer);
196 }
197 status=command(image_info,argc,argv,metadata,exception);
cristyb5d5f722009-11-04 03:03:49 +0000198#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy524549f2010-06-20 21:10:20 +0000199 # pragma omp critical (MagickCore_CommandGenesis)
cristyceae09d2009-10-28 17:18:47 +0000200#endif
201 {
202 if (exception->severity != UndefinedException)
203 {
204 if ((exception->severity > ErrorException) ||
205 (regard_warnings != MagickFalse))
206 status=MagickTrue;
207 CatchException(exception);
208 }
209 if ((metadata != (char **) NULL) && (*metadata != (char *) NULL))
210 {
211 (void) fputs(*metadata,stdout);
212 (void) fputc('\n',stdout);
213 *metadata=DestroyString(*metadata);
214 }
215 }
216 }
217 }
cristy3980b0d2009-10-25 14:37:13 +0000218 if (iterations > 1)
219 {
220 elapsed_time=GetElapsedTime(timer);
221 user_time=GetUserTime(timer);
cristy8cd5b312010-01-07 01:10:24 +0000222 (void) fprintf(stderr,
cristye8c25f92010-06-03 00:53:06 +0000223 "Performance: %.20gi %gips %0.3fu %.20g:%02g.%03g\n",(double)
224 iterations,1.0*iterations/elapsed_time,user_time,(double)
225 (elapsed_time/60.0),floor(fmod(elapsed_time,60.0)),(double)
226 (1000.0*(elapsed_time-floor(elapsed_time))));
cristy524549f2010-06-20 21:10:20 +0000227 (void) fflush(stderr);
cristy3980b0d2009-10-25 14:37:13 +0000228 }
229 timer=DestroyTimerInfo(timer);
cristy1f9e1ed2009-11-18 04:09:38 +0000230 return(status);
cristy3980b0d2009-10-25 14:37:13 +0000231}
232
233/*
234%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
235% %
236% %
237% %
cristy3ed852e2009-09-05 21:47:34 +0000238+ M o g r i f y I m a g e %
239% %
240% %
241% %
242%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
243%
244% MogrifyImage() applies image processing options to an image as prescribed
245% by command line options.
246%
247% The format of the MogrifyImage method is:
248%
249% MagickBooleanType MogrifyImage(ImageInfo *image_info,const int argc,
250% const char **argv,Image **image)
251%
252% A description of each parameter follows:
253%
254% o image_info: the image info..
255%
256% o argc: Specifies a pointer to an integer describing the number of
257% elements in the argument vector.
258%
259% o argv: Specifies a pointer to a text array containing the command line
260% arguments.
261%
262% o image: the image.
263%
264% o exception: return any errors or warnings in this structure.
265%
266*/
267
268static inline Image *GetImageCache(const ImageInfo *image_info,const char *path,
269 ExceptionInfo *exception)
270{
271 char
272 key[MaxTextExtent];
273
274 ExceptionInfo
275 *sans_exception;
276
277 Image
278 *image;
279
280 ImageInfo
281 *read_info;
282
283 (void) FormatMagickString(key,MaxTextExtent,"cache:%s",path);
284 sans_exception=AcquireExceptionInfo();
285 image=(Image *) GetImageRegistry(ImageRegistryType,key,sans_exception);
286 sans_exception=DestroyExceptionInfo(sans_exception);
287 if (image != (Image *) NULL)
288 return(image);
289 read_info=CloneImageInfo(image_info);
290 (void) CopyMagickString(read_info->filename,path,MaxTextExtent);
291 image=ReadImage(read_info,exception);
292 read_info=DestroyImageInfo(read_info);
293 if (image != (Image *) NULL)
294 (void) SetImageRegistry(ImageRegistryType,key,image,exception);
295 return(image);
296}
297
cristy3ed852e2009-09-05 21:47:34 +0000298static MagickBooleanType IsPathWritable(const char *path)
299{
300 if (IsPathAccessible(path) == MagickFalse)
301 return(MagickFalse);
302 if (access(path,W_OK) != 0)
303 return(MagickFalse);
304 return(MagickTrue);
305}
306
cristybb503372010-05-27 20:51:26 +0000307static inline ssize_t MagickMax(const ssize_t x,const ssize_t y)
cristy3ed852e2009-09-05 21:47:34 +0000308{
309 if (x > y)
310 return(x);
311 return(y);
312}
313
314static MagickBooleanType MonitorProgress(const char *text,
cristyb32b90a2009-09-07 21:45:48 +0000315 const MagickOffsetType offset,const MagickSizeType extent,
cristy3ed852e2009-09-05 21:47:34 +0000316 void *wand_unused(client_data))
317{
318 char
319 message[MaxTextExtent],
320 tag[MaxTextExtent];
321
322 const char
323 *locale_message;
324
325 register char
326 *p;
327
cristyb32b90a2009-09-07 21:45:48 +0000328 if (extent < 2)
cristy3ed852e2009-09-05 21:47:34 +0000329 return(MagickTrue);
330 (void) CopyMagickMemory(tag,text,MaxTextExtent);
331 p=strrchr(tag,'/');
332 if (p != (char *) NULL)
333 *p='\0';
334 (void) FormatMagickString(message,MaxTextExtent,"Monitor/%s",tag);
335 locale_message=GetLocaleMessage(message);
336 if (locale_message == message)
337 locale_message=tag;
338 if (p == (char *) NULL)
cristyb32b90a2009-09-07 21:45:48 +0000339 (void) fprintf(stderr,"%s: %ld of %lu, %02ld%% complete\r",locale_message,
cristyf2faecf2010-05-28 19:19:36 +0000340 (long) offset,(unsigned long) extent,(long) (100L*offset/(extent-1)));
cristy3ed852e2009-09-05 21:47:34 +0000341 else
cristyb32b90a2009-09-07 21:45:48 +0000342 (void) fprintf(stderr,"%s[%s]: %ld of %lu, %02ld%% complete\r",
cristyf2faecf2010-05-28 19:19:36 +0000343 locale_message,p+1,(long) offset,(unsigned long) extent,(long)
cristyb32b90a2009-09-07 21:45:48 +0000344 (100L*offset/(extent-1)));
345 if (offset == (MagickOffsetType) (extent-1))
cristy3ed852e2009-09-05 21:47:34 +0000346 (void) fprintf(stderr,"\n");
347 (void) fflush(stderr);
348 return(MagickTrue);
349}
350
351static Image *SparseColorOption(const Image *image,const ChannelType channel,
352 const SparseColorMethod method,const char *arguments,
353 const MagickBooleanType color_from_image,ExceptionInfo *exception)
354{
355 ChannelType
356 channels;
357
358 char
359 token[MaxTextExtent];
360
361 const char
362 *p;
363
364 double
365 *sparse_arguments;
366
cristybb503372010-05-27 20:51:26 +0000367 register size_t
cristy3ed852e2009-09-05 21:47:34 +0000368 x;
369
cristybb503372010-05-27 20:51:26 +0000370 size_t
cristy3ed852e2009-09-05 21:47:34 +0000371 number_arguments;
372
cristybb503372010-05-27 20:51:26 +0000373 size_t
cristy3ed852e2009-09-05 21:47:34 +0000374 number_colors;
375
376 Image
377 *sparse_image;
378
379 MagickPixelPacket
380 color;
381
382 MagickBooleanType
383 error;
384
385 assert(image != (Image *) NULL);
386 assert(image->signature == MagickSignature);
387 if (image->debug != MagickFalse)
388 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
389 assert(exception != (ExceptionInfo *) NULL);
390 assert(exception->signature == MagickSignature);
391 /*
392 Limit channels according to image - and add up number of color channel.
393 */
394 channels=channel;
395 if (image->colorspace != CMYKColorspace)
396 channels=(ChannelType) (channels & ~IndexChannel); /* no index channel */
397 if (image->matte == MagickFalse)
398 channels=(ChannelType) (channels & ~OpacityChannel); /* no alpha channel */
399 number_colors=0;
400 if ((channels & RedChannel) != 0)
401 number_colors++;
402 if ((channels & GreenChannel) != 0)
403 number_colors++;
404 if ((channels & BlueChannel) != 0)
405 number_colors++;
406 if ((channels & IndexChannel) != 0)
407 number_colors++;
408 if ((channels & OpacityChannel) != 0)
409 number_colors++;
410 /*
411 Read string, to determine number of arguments needed,
412 */
413 p=arguments;
414 x=0;
415 while( *p != '\0' )
416 {
417 GetMagickToken(p,&p,token);
418 if ( token[0] == ',' ) continue;
419 if ( isalpha((int) token[0]) || token[0] == '#' ) {
420 if ( color_from_image ) {
421 (void) ThrowMagickException(exception,GetMagickModule(),
422 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
423 "Color arg given, when colors are coming from image");
424 return( (Image *)NULL);
425 }
426 x += number_colors; /* color argument */
427 }
428 else {
429 x++; /* floating point argument */
430 }
431 }
432 error=MagickTrue;
433 if ( color_from_image ) {
434 /* just the control points are being given */
435 error = ( x % 2 != 0 ) ? MagickTrue : MagickFalse;
436 number_arguments=(x/2)*(2+number_colors);
437 }
438 else {
439 /* control points and color values */
440 error = ( x % (2+number_colors) != 0 ) ? MagickTrue : MagickFalse;
441 number_arguments=x;
442 }
443 if ( error ) {
444 (void) ThrowMagickException(exception,GetMagickModule(),
445 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
446 "Invalid number of Arguments");
447 return( (Image *)NULL);
448 }
449
450 /* Allocate and fill in the floating point arguments */
451 sparse_arguments=(double *) AcquireQuantumMemory(number_arguments,
452 sizeof(*sparse_arguments));
453 if (sparse_arguments == (double *) NULL) {
454 (void) ThrowMagickException(exception,GetMagickModule(),ResourceLimitError,
455 "MemoryAllocationFailed","%s","SparseColorOption");
456 return( (Image *)NULL);
457 }
458 (void) ResetMagickMemory(sparse_arguments,0,number_arguments*
459 sizeof(*sparse_arguments));
460 p=arguments;
461 x=0;
462 while( *p != '\0' && x < number_arguments ) {
463 /* X coordinate */
464 token[0]=','; while ( token[0] == ',' ) GetMagickToken(p,&p,token);
465 if ( token[0] == '\0' ) break;
466 if ( isalpha((int) token[0]) || token[0] == '#' ) {
467 (void) ThrowMagickException(exception,GetMagickModule(),
468 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
469 "Color found, instead of X-coord");
470 error = MagickTrue;
471 break;
472 }
cristyf2f27272009-12-17 14:48:46 +0000473 sparse_arguments[x++]=StringToDouble(token);
cristy3ed852e2009-09-05 21:47:34 +0000474 /* Y coordinate */
475 token[0]=','; while ( token[0] == ',' ) GetMagickToken(p,&p,token);
476 if ( token[0] == '\0' ) break;
477 if ( isalpha((int) token[0]) || token[0] == '#' ) {
478 (void) ThrowMagickException(exception,GetMagickModule(),
479 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
480 "Color found, instead of Y-coord");
481 error = MagickTrue;
482 break;
483 }
cristyf2f27272009-12-17 14:48:46 +0000484 sparse_arguments[x++]=StringToDouble(token);
cristy3ed852e2009-09-05 21:47:34 +0000485 /* color values for this control point */
486#if 0
487 if ( (color_from_image ) {
488 /* get color from image */
489 /* HOW??? */
490 }
491 else
492#endif
493 {
494 /* color name or function given in string argument */
495 token[0]=','; while ( token[0] == ',' ) GetMagickToken(p,&p,token);
496 if ( token[0] == '\0' ) break;
497 if ( isalpha((int) token[0]) || token[0] == '#' ) {
498 /* Color string given */
499 (void) QueryMagickColor(token,&color,exception);
500 if ( channels & RedChannel )
501 sparse_arguments[x++] = QuantumScale*color.red;
502 if ( channels & GreenChannel )
503 sparse_arguments[x++] = QuantumScale*color.green;
504 if ( channels & BlueChannel )
505 sparse_arguments[x++] = QuantumScale*color.blue;
506 if ( channels & IndexChannel )
507 sparse_arguments[x++] = QuantumScale*color.index;
508 if ( channels & OpacityChannel )
509 sparse_arguments[x++] = QuantumScale*color.opacity;
510 }
511 else {
512#if 0
513 /* the color name/function/value was not found - error */
514 break;
515#else
516 /* Colors given as a set of floating point values - experimental */
517 /* NB: token contains the first floating point value to use! */
518 if ( channels & RedChannel ) {
519 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
520 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
521 break;
cristy0f19e682009-12-17 14:55:51 +0000522 sparse_arguments[x++]=StringToDouble(token);
cristy3ed852e2009-09-05 21:47:34 +0000523 token[0] = ','; /* used this token - get another */
524 }
525 if ( channels & GreenChannel ) {
526 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
527 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
528 break;
cristy0f19e682009-12-17 14:55:51 +0000529 sparse_arguments[x++]=StringToDouble(token);
cristy3ed852e2009-09-05 21:47:34 +0000530 token[0] = ','; /* used this token - get another */
531 }
532 if ( channels & BlueChannel ) {
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 & IndexChannel ) {
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 & OpacityChannel ) {
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#endif
554 }
555 }
556 }
557 if ( number_arguments != x && !error ) {
558 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
559 "InvalidArgument","`%s': %s","sparse-color","Argument Parsing Error");
560 sparse_arguments=(double *) RelinquishMagickMemory(sparse_arguments);
561 return( (Image *)NULL);
562 }
563 if ( error )
564 return( (Image *)NULL);
565
566 /* Call the Interpolation function with the parsed arguments */
567 sparse_image=SparseColorImage(image,channels,method,number_arguments,
568 sparse_arguments,exception);
569 sparse_arguments=(double *) RelinquishMagickMemory(sparse_arguments);
570 return( sparse_image );
571}
572
573WandExport MagickBooleanType MogrifyImage(ImageInfo *image_info,const int argc,
574 const char **argv,Image **image,ExceptionInfo *exception)
575{
576 ChannelType
577 channel;
578
579 const char
580 *format,
581 *option;
582
583 DrawInfo
584 *draw_info;
585
586 GeometryInfo
587 geometry_info;
588
589 Image
590 *region_image;
591
cristy6b3da3a2010-06-20 02:21:46 +0000592 ImageInfo
593 *mogrify_info;
594
cristybb503372010-05-27 20:51:26 +0000595 ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000596 count;
597
598 MagickBooleanType
599 status;
600
601 MagickPixelPacket
602 fill;
603
604 MagickStatusType
605 flags;
606
607 QuantizeInfo
608 *quantize_info;
609
610 RectangleInfo
611 geometry,
612 region_geometry;
613
cristybb503372010-05-27 20:51:26 +0000614 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000615 i;
616
617 /*
618 Initialize method variables.
619 */
620 assert(image_info != (const ImageInfo *) NULL);
621 assert(image_info->signature == MagickSignature);
622 assert(image != (Image **) NULL);
623 assert((*image)->signature == MagickSignature);
624 if ((*image)->debug != MagickFalse)
625 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",(*image)->filename);
626 if (argc < 0)
627 return(MagickTrue);
cristy6b3da3a2010-06-20 02:21:46 +0000628 mogrify_info=CloneImageInfo(image_info);
629 draw_info=CloneDrawInfo(mogrify_info,(DrawInfo *) NULL);
630 quantize_info=AcquireQuantizeInfo(mogrify_info);
cristy3ed852e2009-09-05 21:47:34 +0000631 SetGeometryInfo(&geometry_info);
632 GetMagickPixelPacket(*image,&fill);
633 SetMagickPixelPacket(*image,&(*image)->background_color,(IndexPacket *) NULL,
634 &fill);
cristy6b3da3a2010-06-20 02:21:46 +0000635 channel=mogrify_info->channel;
636 format=GetImageOption(mogrify_info,"format");
cristy3ed852e2009-09-05 21:47:34 +0000637 SetGeometry(*image,&region_geometry);
638 region_image=NewImageList();
639 /*
640 Transmogrify the image.
641 */
cristybb503372010-05-27 20:51:26 +0000642 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +0000643 {
644 option=argv[i];
645 if (IsMagickOption(option) == MagickFalse)
646 continue;
647 count=MagickMax(ParseMagickOption(MagickCommandOptions,MagickFalse,option),
648 0L);
cristycee97112010-05-28 00:44:52 +0000649 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +0000650 break;
cristy6b3da3a2010-06-20 02:21:46 +0000651 status=MogrifyImageInfo(mogrify_info,(int) count+1,argv+i,exception);
cristy3ed852e2009-09-05 21:47:34 +0000652 switch (*(option+1))
653 {
654 case 'a':
655 {
656 if (LocaleCompare("adaptive-blur",option+1) == 0)
657 {
658 Image
659 *blur_image;
660
661 /*
662 Adaptive blur image.
663 */
cristy6b3da3a2010-06-20 02:21:46 +0000664 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000665 flags=ParseGeometry(argv[i+1],&geometry_info);
666 if ((flags & SigmaValue) == 0)
667 geometry_info.sigma=1.0;
668 blur_image=AdaptiveBlurImageChannel(*image,channel,
669 geometry_info.rho,geometry_info.sigma,exception);
670 if (blur_image == (Image *) NULL)
671 break;
672 *image=DestroyImage(*image);
673 *image=blur_image;
674 break;
675 }
676 if (LocaleCompare("adaptive-resize",option+1) == 0)
677 {
678 Image
679 *resize_image;
680
681 /*
682 Adaptive resize image.
683 */
cristy6b3da3a2010-06-20 02:21:46 +0000684 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000685 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
686 resize_image=AdaptiveResizeImage(*image,geometry.width,
687 geometry.height,exception);
688 if (resize_image == (Image *) NULL)
689 break;
690 *image=DestroyImage(*image);
691 *image=resize_image;
692 break;
693 }
694 if (LocaleCompare("adaptive-sharpen",option+1) == 0)
695 {
696 Image
697 *sharp_image;
698
699 /*
700 Adaptive sharpen image.
701 */
cristy6b3da3a2010-06-20 02:21:46 +0000702 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000703 flags=ParseGeometry(argv[i+1],&geometry_info);
704 if ((flags & SigmaValue) == 0)
705 geometry_info.sigma=1.0;
706 sharp_image=AdaptiveSharpenImageChannel(*image,channel,
707 geometry_info.rho,geometry_info.sigma,exception);
708 if (sharp_image == (Image *) NULL)
709 break;
710 *image=DestroyImage(*image);
711 *image=sharp_image;
712 break;
713 }
714 if (LocaleCompare("affine",option+1) == 0)
715 {
716 /*
717 Affine matrix.
718 */
719 if (*option == '+')
720 {
721 GetAffineMatrix(&draw_info->affine);
722 break;
723 }
724 (void) ParseAffineGeometry(argv[i+1],&draw_info->affine,exception);
725 break;
726 }
727 if (LocaleCompare("alpha",option+1) == 0)
728 {
729 AlphaChannelType
730 alpha_type;
731
cristy6b3da3a2010-06-20 02:21:46 +0000732 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000733 alpha_type=(AlphaChannelType) ParseMagickOption(MagickAlphaOptions,
734 MagickFalse,argv[i+1]);
735 (void) SetImageAlphaChannel(*image,alpha_type);
736 InheritException(exception,&(*image)->exception);
737 break;
738 }
739 if (LocaleCompare("annotate",option+1) == 0)
740 {
741 char
742 *text,
743 geometry[MaxTextExtent];
744
745 /*
746 Annotate image.
747 */
cristy6b3da3a2010-06-20 02:21:46 +0000748 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000749 SetGeometryInfo(&geometry_info);
750 flags=ParseGeometry(argv[i+1],&geometry_info);
751 if ((flags & SigmaValue) == 0)
752 geometry_info.sigma=geometry_info.rho;
cristy6b3da3a2010-06-20 02:21:46 +0000753 text=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
cristy3ed852e2009-09-05 21:47:34 +0000754 InheritException(exception,&(*image)->exception);
755 if (text == (char *) NULL)
756 break;
757 (void) CloneString(&draw_info->text,text);
758 text=DestroyString(text);
759 (void) FormatMagickString(geometry,MaxTextExtent,"%+f%+f",
760 geometry_info.xi,geometry_info.psi);
761 (void) CloneString(&draw_info->geometry,geometry);
762 draw_info->affine.sx=cos(DegreesToRadians(
763 fmod(geometry_info.rho,360.0)));
764 draw_info->affine.rx=sin(DegreesToRadians(
765 fmod(geometry_info.rho,360.0)));
766 draw_info->affine.ry=(-sin(DegreesToRadians(
767 fmod(geometry_info.sigma,360.0))));
768 draw_info->affine.sy=cos(DegreesToRadians(
769 fmod(geometry_info.sigma,360.0)));
770 (void) AnnotateImage(*image,draw_info);
771 InheritException(exception,&(*image)->exception);
772 break;
773 }
774 if (LocaleCompare("antialias",option+1) == 0)
775 {
776 draw_info->stroke_antialias=(*option == '-') ? MagickTrue :
777 MagickFalse;
778 draw_info->text_antialias=(*option == '-') ? MagickTrue :
779 MagickFalse;
780 break;
781 }
782 if (LocaleCompare("auto-gamma",option+1) == 0)
783 {
784 /*
785 Auto Adjust Gamma of image based on its mean
786 */
cristy6b3da3a2010-06-20 02:21:46 +0000787 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000788 (void) AutoGammaImageChannel(*image,channel);
789 break;
790 }
791 if (LocaleCompare("auto-level",option+1) == 0)
792 {
793 /*
794 Perfectly Normalize (max/min stretch) the image
795 */
cristy6b3da3a2010-06-20 02:21:46 +0000796 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000797 (void) AutoLevelImageChannel(*image,channel);
798 break;
799 }
800 if (LocaleCompare("auto-orient",option+1) == 0)
801 {
802 Image
803 *orient_image;
804
cristy6b3da3a2010-06-20 02:21:46 +0000805 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000806 orient_image=NewImageList();
807 switch ((*image)->orientation)
808 {
809 case TopRightOrientation:
810 {
811 orient_image=FlopImage(*image,exception);
812 break;
813 }
814 case BottomRightOrientation:
815 {
816 orient_image=RotateImage(*image,180.0,exception);
817 break;
818 }
819 case BottomLeftOrientation:
820 {
821 orient_image=FlipImage(*image,exception);
822 break;
823 }
824 case LeftTopOrientation:
825 {
826 orient_image=TransposeImage(*image,exception);
827 break;
828 }
829 case RightTopOrientation:
830 {
831 orient_image=RotateImage(*image,90.0,exception);
832 break;
833 }
834 case RightBottomOrientation:
835 {
836 orient_image=TransverseImage(*image,exception);
837 break;
838 }
839 case LeftBottomOrientation:
840 {
841 orient_image=RotateImage(*image,270.0,exception);
842 break;
843 }
844 default:
845 break;
846 }
847 if (orient_image == (Image *) NULL)
848 break;
849 orient_image->orientation=TopLeftOrientation;
850 *image=DestroyImage(*image);
851 *image=orient_image;
852 break;
853 }
854 break;
855 }
856 case 'b':
857 {
858 if (LocaleCompare("black-threshold",option+1) == 0)
859 {
860 /*
861 Black threshold image.
862 */
cristy6b3da3a2010-06-20 02:21:46 +0000863 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000864 (void) BlackThresholdImageChannel(*image,channel,argv[i+1],
865 exception);
866 InheritException(exception,&(*image)->exception);
867 break;
868 }
869 if (LocaleCompare("blue-shift",option+1) == 0)
870 {
871 Image
872 *shift_image;
873
874 /*
875 Blue shift image.
876 */
cristy6b3da3a2010-06-20 02:21:46 +0000877 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000878 geometry_info.rho=1.5;
879 if (*option == '-')
880 flags=ParseGeometry(argv[i+1],&geometry_info);
881 shift_image=BlueShiftImage(*image,geometry_info.rho,exception);
882 if (shift_image == (Image *) NULL)
883 break;
884 *image=DestroyImage(*image);
885 *image=shift_image;
886 break;
887 }
888 if (LocaleCompare("blur",option+1) == 0)
889 {
890 Image
891 *blur_image;
892
893 /*
894 Gaussian blur image.
895 */
cristy6b3da3a2010-06-20 02:21:46 +0000896 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000897 flags=ParseGeometry(argv[i+1],&geometry_info);
898 if ((flags & SigmaValue) == 0)
899 geometry_info.sigma=1.0;
900 blur_image=BlurImageChannel(*image,channel,geometry_info.rho,
901 geometry_info.sigma,exception);
902 if (blur_image == (Image *) NULL)
903 break;
904 *image=DestroyImage(*image);
905 *image=blur_image;
906 break;
907 }
908 if (LocaleCompare("border",option+1) == 0)
909 {
910 Image
911 *border_image;
912
913 /*
914 Surround image with a border of solid color.
915 */
cristy6b3da3a2010-06-20 02:21:46 +0000916 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000917 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
918 if ((flags & SigmaValue) == 0)
919 geometry.height=geometry.width;
920 border_image=BorderImage(*image,&geometry,exception);
921 if (border_image == (Image *) NULL)
922 break;
923 *image=DestroyImage(*image);
924 *image=border_image;
925 break;
926 }
927 if (LocaleCompare("bordercolor",option+1) == 0)
928 {
929 if (*option == '+')
930 {
931 (void) QueryColorDatabase(BorderColor,&draw_info->border_color,
932 exception);
933 break;
934 }
935 (void) QueryColorDatabase(argv[i+1],&draw_info->border_color,
936 exception);
937 break;
938 }
939 if (LocaleCompare("box",option+1) == 0)
940 {
941 (void) QueryColorDatabase(argv[i+1],&draw_info->undercolor,
942 exception);
943 break;
944 }
cristya28d6b82010-01-11 20:03:47 +0000945 if (LocaleCompare("brightness-contrast",option+1) == 0)
946 {
947 double
948 brightness,
949 contrast;
950
951 GeometryInfo
952 geometry_info;
953
954 MagickStatusType
955 flags;
956
957 /*
958 Brightness / contrast image.
959 */
cristy6b3da3a2010-06-20 02:21:46 +0000960 (void) SyncImageSettings(mogrify_info,*image);
cristya28d6b82010-01-11 20:03:47 +0000961 flags=ParseGeometry(argv[i+1],&geometry_info);
962 brightness=geometry_info.rho;
cristy81fbc8b2010-01-11 20:04:07 +0000963 contrast=0.0;
cristya28d6b82010-01-11 20:03:47 +0000964 if ((flags & SigmaValue) != 0)
965 contrast=geometry_info.sigma;
cristy02cc0f22010-01-12 00:02:32 +0000966 (void) BrightnessContrastImageChannel(*image,channel,brightness,
967 contrast);
cristya28d6b82010-01-11 20:03:47 +0000968 InheritException(exception,&(*image)->exception);
969 break;
970 }
cristy3ed852e2009-09-05 21:47:34 +0000971 break;
972 }
973 case 'c':
974 {
975 if (LocaleCompare("cdl",option+1) == 0)
976 {
977 char
978 *color_correction_collection;
979
980 /*
981 Color correct with a color decision list.
982 */
cristy6b3da3a2010-06-20 02:21:46 +0000983 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000984 color_correction_collection=FileToString(argv[i+1],~0,exception);
985 if (color_correction_collection == (char *) NULL)
986 break;
987 (void) ColorDecisionListImage(*image,color_correction_collection);
988 InheritException(exception,&(*image)->exception);
989 break;
990 }
991 if (LocaleCompare("channel",option+1) == 0)
992 {
993 if (*option == '+')
994 {
995 channel=DefaultChannels;
996 break;
997 }
998 channel=(ChannelType) ParseChannelOption(argv[i+1]);
999 break;
1000 }
1001 if (LocaleCompare("charcoal",option+1) == 0)
1002 {
1003 Image
1004 *charcoal_image;
1005
1006 /*
1007 Charcoal image.
1008 */
cristy6b3da3a2010-06-20 02:21:46 +00001009 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001010 flags=ParseGeometry(argv[i+1],&geometry_info);
1011 if ((flags & SigmaValue) == 0)
1012 geometry_info.sigma=1.0;
1013 charcoal_image=CharcoalImage(*image,geometry_info.rho,
1014 geometry_info.sigma,exception);
1015 if (charcoal_image == (Image *) NULL)
1016 break;
1017 *image=DestroyImage(*image);
1018 *image=charcoal_image;
1019 break;
1020 }
1021 if (LocaleCompare("chop",option+1) == 0)
1022 {
1023 Image
1024 *chop_image;
1025
1026 /*
1027 Chop the image.
1028 */
cristy6b3da3a2010-06-20 02:21:46 +00001029 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001030 (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1031 chop_image=ChopImage(*image,&geometry,exception);
1032 if (chop_image == (Image *) NULL)
1033 break;
1034 *image=DestroyImage(*image);
1035 *image=chop_image;
1036 break;
1037 }
cristy1eb45dd2009-09-25 16:38:06 +00001038 if (LocaleCompare("clamp",option+1) == 0)
1039 {
1040 /*
1041 Clamp image.
1042 */
cristy6b3da3a2010-06-20 02:21:46 +00001043 (void) SyncImageSettings(mogrify_info,*image);
cristy1eb45dd2009-09-25 16:38:06 +00001044 (void) ClampImageChannel(*image,channel);
1045 InheritException(exception,&(*image)->exception);
1046 break;
1047 }
cristy3ed852e2009-09-05 21:47:34 +00001048 if (LocaleCompare("clip",option+1) == 0)
1049 {
cristy6b3da3a2010-06-20 02:21:46 +00001050 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001051 if (*option == '+')
1052 {
1053 (void) SetImageClipMask(*image,(Image *) NULL);
1054 InheritException(exception,&(*image)->exception);
1055 break;
1056 }
1057 (void) ClipImage(*image);
1058 InheritException(exception,&(*image)->exception);
1059 break;
1060 }
1061 if (LocaleCompare("clip-mask",option+1) == 0)
1062 {
1063 Image
1064 *mask;
1065
cristybb503372010-05-27 20:51:26 +00001066 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001067 y;
1068
cristybb503372010-05-27 20:51:26 +00001069 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001070 x;
1071
1072 register PixelPacket
cristyc47d1f82009-11-26 01:44:43 +00001073 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00001074
cristy6b3da3a2010-06-20 02:21:46 +00001075 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001076 if (*option == '+')
1077 {
1078 /*
1079 Remove a mask.
1080 */
1081 (void) SetImageMask(*image,(Image *) NULL);
1082 InheritException(exception,&(*image)->exception);
1083 break;
1084 }
1085 /*
1086 Set the image mask.
1087 */
cristy6b3da3a2010-06-20 02:21:46 +00001088 mask=GetImageCache(mogrify_info,argv[i+1],exception);
cristy3ed852e2009-09-05 21:47:34 +00001089 if (mask == (Image *) NULL)
1090 break;
cristybb503372010-05-27 20:51:26 +00001091 for (y=0; y < (ssize_t) mask->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00001092 {
1093 q=GetAuthenticPixels(mask,0,y,mask->columns,1,exception);
1094 if (q == (PixelPacket *) NULL)
1095 break;
cristybb503372010-05-27 20:51:26 +00001096 for (x=0; x < (ssize_t) mask->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00001097 {
1098 if (mask->matte == MagickFalse)
1099 q->opacity=PixelIntensityToQuantum(q);
1100 q->red=q->opacity;
1101 q->green=q->opacity;
1102 q->blue=q->opacity;
1103 q++;
1104 }
1105 if (SyncAuthenticPixels(mask,exception) == MagickFalse)
1106 break;
1107 }
1108 if (SetImageStorageClass(mask,DirectClass) == MagickFalse)
1109 return(MagickFalse);
1110 mask->matte=MagickTrue;
1111 (void) SetImageClipMask(*image,mask);
1112 mask=DestroyImage(mask);
1113 InheritException(exception,&(*image)->exception);
1114 break;
1115 }
1116 if (LocaleCompare("clip-path",option+1) == 0)
1117 {
cristy6b3da3a2010-06-20 02:21:46 +00001118 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001119 (void) ClipImagePath(*image,argv[i+1],*option == '-' ? MagickTrue :
1120 MagickFalse);
1121 InheritException(exception,&(*image)->exception);
1122 break;
1123 }
1124 if (LocaleCompare("colorize",option+1) == 0)
1125 {
1126 Image
1127 *colorize_image;
1128
1129 /*
1130 Colorize the image.
1131 */
cristy6b3da3a2010-06-20 02:21:46 +00001132 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001133 colorize_image=ColorizeImage(*image,argv[i+1],draw_info->fill,
1134 exception);
1135 if (colorize_image == (Image *) NULL)
1136 break;
1137 *image=DestroyImage(*image);
1138 *image=colorize_image;
1139 break;
1140 }
cristye6365592010-04-02 17:31:23 +00001141 if (LocaleCompare("color-matrix",option+1) == 0)
1142 {
1143 Image
1144 *color_image;
1145
1146 KernelInfo
1147 *kernel;
1148
cristy6b3da3a2010-06-20 02:21:46 +00001149 (void) SyncImageSettings(mogrify_info,*image);
cristye6365592010-04-02 17:31:23 +00001150 kernel=AcquireKernelInfo(argv[i+1]);
1151 if (kernel == (KernelInfo *) NULL)
1152 break;
1153 color_image=ColorMatrixImage(*image,kernel,exception);
1154 kernel=DestroyKernelInfo(kernel);
1155 if (color_image == (Image *) NULL)
1156 break;
1157 *image=DestroyImage(*image);
1158 *image=color_image;
1159 break;
1160 }
cristy3ed852e2009-09-05 21:47:34 +00001161 if (LocaleCompare("colors",option+1) == 0)
1162 {
1163 /*
1164 Reduce the number of colors in the image.
1165 */
cristy6b3da3a2010-06-20 02:21:46 +00001166 (void) SyncImageSettings(mogrify_info,*image);
cristye27293e2009-12-18 02:53:20 +00001167 quantize_info->number_colors=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00001168 if (quantize_info->number_colors == 0)
1169 break;
1170 if (((*image)->storage_class == DirectClass) ||
1171 (*image)->colors > quantize_info->number_colors)
1172 (void) QuantizeImage(quantize_info,*image);
1173 else
1174 (void) CompressImageColormap(*image);
1175 InheritException(exception,&(*image)->exception);
1176 break;
1177 }
1178 if (LocaleCompare("colorspace",option+1) == 0)
1179 {
1180 ColorspaceType
1181 colorspace;
1182
cristy6b3da3a2010-06-20 02:21:46 +00001183 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001184 if (*option == '+')
1185 {
1186 (void) TransformImageColorspace(*image,RGBColorspace);
1187 InheritException(exception,&(*image)->exception);
1188 break;
1189 }
1190 colorspace=(ColorspaceType) ParseMagickOption(
1191 MagickColorspaceOptions,MagickFalse,argv[i+1]);
1192 (void) TransformImageColorspace(*image,colorspace);
1193 InheritException(exception,&(*image)->exception);
1194 break;
1195 }
1196 if (LocaleCompare("contrast",option+1) == 0)
1197 {
cristy6b3da3a2010-06-20 02:21:46 +00001198 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001199 (void) ContrastImage(*image,(*option == '-') ? MagickTrue :
1200 MagickFalse);
1201 InheritException(exception,&(*image)->exception);
1202 break;
1203 }
1204 if (LocaleCompare("contrast-stretch",option+1) == 0)
1205 {
1206 double
1207 black_point,
1208 white_point;
1209
cristy3ed852e2009-09-05 21:47:34 +00001210 MagickStatusType
1211 flags;
1212
1213 /*
1214 Contrast stretch image.
1215 */
cristy6b3da3a2010-06-20 02:21:46 +00001216 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001217 flags=ParseGeometry(argv[i+1],&geometry_info);
1218 black_point=geometry_info.rho;
1219 white_point=(flags & SigmaValue) != 0 ? geometry_info.sigma :
1220 black_point;
1221 if ((flags & PercentValue) != 0)
1222 {
1223 black_point*=(double) (*image)->columns*(*image)->rows/100.0;
1224 white_point*=(double) (*image)->columns*(*image)->rows/100.0;
1225 }
1226 white_point=(MagickRealType) (*image)->columns*(*image)->rows-
1227 white_point;
1228 (void) ContrastStretchImageChannel(*image,channel,black_point,
1229 white_point);
1230 InheritException(exception,&(*image)->exception);
1231 break;
1232 }
1233 if (LocaleCompare("convolve",option+1) == 0)
1234 {
cristy36826ab2010-03-06 01:29:30 +00001235 double
1236 gamma;
1237
cristy3ed852e2009-09-05 21:47:34 +00001238 Image
1239 *convolve_image;
1240
cristy2be15382010-01-21 02:38:03 +00001241 KernelInfo
cristy56a9e512010-01-06 18:18:55 +00001242 *kernel;
cristy3ed852e2009-09-05 21:47:34 +00001243
cristybb503372010-05-27 20:51:26 +00001244 register ssize_t
cristy36826ab2010-03-06 01:29:30 +00001245 j;
1246
cristy6b3da3a2010-06-20 02:21:46 +00001247 (void) SyncImageSettings(mogrify_info,*image);
cristy2be15382010-01-21 02:38:03 +00001248 kernel=AcquireKernelInfo(argv[i+1]);
1249 if (kernel == (KernelInfo *) NULL)
cristy56a9e512010-01-06 18:18:55 +00001250 break;
cristy36826ab2010-03-06 01:29:30 +00001251 gamma=0.0;
cristybb503372010-05-27 20:51:26 +00001252 for (j=0; j < (ssize_t) (kernel->width*kernel->height); j++)
cristy36826ab2010-03-06 01:29:30 +00001253 gamma+=kernel->values[j];
1254 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
cristybb503372010-05-27 20:51:26 +00001255 for (j=0; j < (ssize_t) (kernel->width*kernel->height); j++)
cristy36826ab2010-03-06 01:29:30 +00001256 kernel->values[j]*=gamma;
cristy6771f1e2010-03-05 19:43:39 +00001257 convolve_image=FilterImageChannel(*image,channel,kernel,exception);
anthony83ba99b2010-01-24 08:48:15 +00001258 kernel=DestroyKernelInfo(kernel);
cristy3ed852e2009-09-05 21:47:34 +00001259 if (convolve_image == (Image *) NULL)
1260 break;
1261 *image=DestroyImage(*image);
1262 *image=convolve_image;
1263 break;
1264 }
1265 if (LocaleCompare("crop",option+1) == 0)
1266 {
cristy6b3da3a2010-06-20 02:21:46 +00001267 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001268 flags=ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1269 if (((geometry.width != 0) || (geometry.height != 0)) &&
1270 ((flags & XValue) == 0) && ((flags & YValue) == 0))
1271 break;
1272 (void) TransformImage(image,argv[i+1],(char *) NULL);
1273 InheritException(exception,&(*image)->exception);
1274 break;
1275 }
1276 if (LocaleCompare("cycle",option+1) == 0)
1277 {
1278 /*
1279 Cycle an image colormap.
1280 */
cristy6b3da3a2010-06-20 02:21:46 +00001281 (void) SyncImageSettings(mogrify_info,*image);
cristyf2f27272009-12-17 14:48:46 +00001282 (void) CycleColormapImage(*image,StringToLong(argv[i+1]));
cristy3ed852e2009-09-05 21:47:34 +00001283 InheritException(exception,&(*image)->exception);
1284 break;
1285 }
1286 break;
1287 }
1288 case 'd':
1289 {
1290 if (LocaleCompare("decipher",option+1) == 0)
1291 {
1292 StringInfo
1293 *passkey;
1294
1295 /*
1296 Decipher pixels.
1297 */
cristy6b3da3a2010-06-20 02:21:46 +00001298 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001299 passkey=FileToStringInfo(argv[i+1],~0,exception);
1300 if (passkey != (StringInfo *) NULL)
1301 {
1302 (void) PasskeyDecipherImage(*image,passkey,exception);
1303 passkey=DestroyStringInfo(passkey);
1304 }
1305 break;
1306 }
1307 if (LocaleCompare("density",option+1) == 0)
1308 {
1309 /*
1310 Set image density.
1311 */
1312 (void) CloneString(&draw_info->density,argv[i+1]);
1313 break;
1314 }
1315 if (LocaleCompare("depth",option+1) == 0)
1316 {
cristy6b3da3a2010-06-20 02:21:46 +00001317 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001318 if (*option == '+')
1319 {
1320 (void) SetImageDepth(*image,MAGICKCORE_QUANTUM_DEPTH);
1321 break;
1322 }
cristye27293e2009-12-18 02:53:20 +00001323 (void) SetImageDepth(*image,StringToUnsignedLong(argv[i+1]));
cristy3ed852e2009-09-05 21:47:34 +00001324 break;
1325 }
1326 if (LocaleCompare("deskew",option+1) == 0)
1327 {
1328 double
1329 threshold;
1330
1331 Image
1332 *deskew_image;
1333
1334 /*
1335 Straighten the image.
1336 */
cristy6b3da3a2010-06-20 02:21:46 +00001337 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001338 if (*option == '+')
1339 threshold=40.0*QuantumRange/100.0;
1340 else
cristyf2f27272009-12-17 14:48:46 +00001341 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
cristy3ed852e2009-09-05 21:47:34 +00001342 deskew_image=DeskewImage(*image,threshold,exception);
1343 if (deskew_image == (Image *) NULL)
1344 break;
1345 *image=DestroyImage(*image);
1346 *image=deskew_image;
1347 break;
1348 }
1349 if (LocaleCompare("despeckle",option+1) == 0)
1350 {
1351 Image
1352 *despeckle_image;
1353
1354 /*
1355 Reduce the speckles within an image.
1356 */
cristy6b3da3a2010-06-20 02:21:46 +00001357 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001358 despeckle_image=DespeckleImage(*image,exception);
1359 if (despeckle_image == (Image *) NULL)
1360 break;
1361 *image=DestroyImage(*image);
1362 *image=despeckle_image;
1363 break;
1364 }
1365 if (LocaleCompare("display",option+1) == 0)
1366 {
1367 (void) CloneString(&draw_info->server_name,argv[i+1]);
1368 break;
1369 }
cristy3ed852e2009-09-05 21:47:34 +00001370 if (LocaleCompare("distort",option+1) == 0)
1371 {
1372 char
1373 *args,
1374 token[MaxTextExtent];
1375
1376 const char
1377 *p;
1378
1379 DistortImageMethod
1380 method;
1381
1382 double
1383 *arguments;
1384
1385 Image
1386 *distort_image;
1387
cristybb503372010-05-27 20:51:26 +00001388 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001389 x;
1390
cristybb503372010-05-27 20:51:26 +00001391 size_t
cristy3ed852e2009-09-05 21:47:34 +00001392 number_arguments;
1393
1394 /*
1395 Distort image.
1396 */
cristy6b3da3a2010-06-20 02:21:46 +00001397 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001398 method=(DistortImageMethod) ParseMagickOption(MagickDistortOptions,
1399 MagickFalse,argv[i+1]);
cristy6b3da3a2010-06-20 02:21:46 +00001400 args=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
cristy3ed852e2009-09-05 21:47:34 +00001401 InheritException(exception,&(*image)->exception);
1402 if (args == (char *) NULL)
1403 break;
1404 p=(char *) args;
1405 for (x=0; *p != '\0'; x++)
1406 {
1407 GetMagickToken(p,&p,token);
1408 if (*token == ',')
1409 GetMagickToken(p,&p,token);
1410 }
cristybb503372010-05-27 20:51:26 +00001411 number_arguments=(size_t) x;
cristy3ed852e2009-09-05 21:47:34 +00001412 arguments=(double *) AcquireQuantumMemory(number_arguments,
1413 sizeof(*arguments));
1414 if (arguments == (double *) NULL)
1415 ThrowWandFatalException(ResourceLimitFatalError,
1416 "MemoryAllocationFailed",(*image)->filename);
1417 (void) ResetMagickMemory(arguments,0,number_arguments*
1418 sizeof(*arguments));
1419 p=(char *) args;
cristybb503372010-05-27 20:51:26 +00001420 for (x=0; (x < (ssize_t) number_arguments) && (*p != '\0'); x++)
cristy3ed852e2009-09-05 21:47:34 +00001421 {
1422 GetMagickToken(p,&p,token);
1423 if (*token == ',')
1424 GetMagickToken(p,&p,token);
cristyf2f27272009-12-17 14:48:46 +00001425 arguments[x]=StringToDouble(token);
cristy3ed852e2009-09-05 21:47:34 +00001426 }
1427 args=DestroyString(args);
1428 distort_image=DistortImage(*image,method,number_arguments,arguments,
1429 (*option == '+') ? MagickTrue : MagickFalse,exception);
1430 arguments=(double *) RelinquishMagickMemory(arguments);
1431 if (distort_image == (Image *) NULL)
1432 break;
1433 *image=DestroyImage(*image);
1434 *image=distort_image;
1435 break;
1436 }
1437 if (LocaleCompare("dither",option+1) == 0)
1438 {
1439 if (*option == '+')
1440 {
1441 quantize_info->dither=MagickFalse;
1442 break;
1443 }
1444 quantize_info->dither=MagickTrue;
1445 quantize_info->dither_method=(DitherMethod) ParseMagickOption(
1446 MagickDitherOptions,MagickFalse,argv[i+1]);
1447 if (quantize_info->dither_method == NoDitherMethod)
1448 quantize_info->dither=MagickFalse;
1449 break;
1450 }
1451 if (LocaleCompare("draw",option+1) == 0)
1452 {
1453 /*
1454 Draw image.
1455 */
cristy6b3da3a2010-06-20 02:21:46 +00001456 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001457 (void) CloneString(&draw_info->primitive,argv[i+1]);
1458 (void) DrawImage(*image,draw_info);
1459 InheritException(exception,&(*image)->exception);
1460 break;
1461 }
1462 break;
1463 }
1464 case 'e':
1465 {
1466 if (LocaleCompare("edge",option+1) == 0)
1467 {
1468 Image
1469 *edge_image;
1470
1471 /*
1472 Enhance edges in the image.
1473 */
cristy6b3da3a2010-06-20 02:21:46 +00001474 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001475 flags=ParseGeometry(argv[i+1],&geometry_info);
1476 if ((flags & SigmaValue) == 0)
1477 geometry_info.sigma=1.0;
1478 edge_image=EdgeImage(*image,geometry_info.rho,exception);
1479 if (edge_image == (Image *) NULL)
1480 break;
1481 *image=DestroyImage(*image);
1482 *image=edge_image;
1483 break;
1484 }
1485 if (LocaleCompare("emboss",option+1) == 0)
1486 {
1487 Image
1488 *emboss_image;
1489
1490 /*
1491 Gaussian embossen image.
1492 */
cristy6b3da3a2010-06-20 02:21:46 +00001493 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001494 flags=ParseGeometry(argv[i+1],&geometry_info);
1495 if ((flags & SigmaValue) == 0)
1496 geometry_info.sigma=1.0;
1497 emboss_image=EmbossImage(*image,geometry_info.rho,
1498 geometry_info.sigma,exception);
1499 if (emboss_image == (Image *) NULL)
1500 break;
1501 *image=DestroyImage(*image);
1502 *image=emboss_image;
1503 break;
1504 }
1505 if (LocaleCompare("encipher",option+1) == 0)
1506 {
1507 StringInfo
1508 *passkey;
1509
1510 /*
1511 Encipher pixels.
1512 */
cristy6b3da3a2010-06-20 02:21:46 +00001513 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001514 passkey=FileToStringInfo(argv[i+1],~0,exception);
1515 if (passkey != (StringInfo *) NULL)
1516 {
1517 (void) PasskeyEncipherImage(*image,passkey,exception);
1518 passkey=DestroyStringInfo(passkey);
1519 }
1520 break;
1521 }
1522 if (LocaleCompare("encoding",option+1) == 0)
1523 {
1524 (void) CloneString(&draw_info->encoding,argv[i+1]);
1525 break;
1526 }
1527 if (LocaleCompare("enhance",option+1) == 0)
1528 {
1529 Image
1530 *enhance_image;
1531
1532 /*
1533 Enhance image.
1534 */
cristy6b3da3a2010-06-20 02:21:46 +00001535 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001536 enhance_image=EnhanceImage(*image,exception);
1537 if (enhance_image == (Image *) NULL)
1538 break;
1539 *image=DestroyImage(*image);
1540 *image=enhance_image;
1541 break;
1542 }
1543 if (LocaleCompare("equalize",option+1) == 0)
1544 {
1545 /*
1546 Equalize image.
1547 */
cristy6b3da3a2010-06-20 02:21:46 +00001548 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001549 (void) EqualizeImageChannel(*image,channel);
1550 InheritException(exception,&(*image)->exception);
1551 break;
1552 }
1553 if (LocaleCompare("evaluate",option+1) == 0)
1554 {
1555 double
1556 constant;
1557
1558 MagickEvaluateOperator
1559 op;
1560
cristy6b3da3a2010-06-20 02:21:46 +00001561 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001562 op=(MagickEvaluateOperator) ParseMagickOption(MagickEvaluateOptions,
1563 MagickFalse,argv[i+1]);
cristyf2f27272009-12-17 14:48:46 +00001564 constant=SiPrefixToDouble(argv[i+2],QuantumRange);
cristy3ed852e2009-09-05 21:47:34 +00001565 (void) EvaluateImageChannel(*image,channel,op,constant,exception);
1566 break;
1567 }
1568 if (LocaleCompare("extent",option+1) == 0)
1569 {
1570 Image
1571 *extent_image;
1572
1573 /*
1574 Set the image extent.
1575 */
cristy6b3da3a2010-06-20 02:21:46 +00001576 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001577 flags=ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
cristyf0bbfd92009-11-25 14:12:31 +00001578 if (geometry.width == 0)
cristy2ea9a4e2009-11-25 14:30:22 +00001579 geometry.width=(*image)->columns;
cristyf0bbfd92009-11-25 14:12:31 +00001580 if (geometry.height == 0)
cristy2ea9a4e2009-11-25 14:30:22 +00001581 geometry.height=(*image)->rows;
cristy3ed852e2009-09-05 21:47:34 +00001582 geometry.x=(-geometry.x);
1583 geometry.y=(-geometry.y);
1584 extent_image=ExtentImage(*image,&geometry,exception);
1585 if (extent_image == (Image *) NULL)
1586 break;
1587 *image=DestroyImage(*image);
1588 *image=extent_image;
1589 break;
1590 }
1591 break;
1592 }
1593 case 'f':
1594 {
1595 if (LocaleCompare("family",option+1) == 0)
1596 {
1597 if (*option == '+')
1598 {
1599 if (draw_info->family != (char *) NULL)
1600 draw_info->family=DestroyString(draw_info->family);
1601 break;
1602 }
1603 (void) CloneString(&draw_info->family,argv[i+1]);
1604 break;
1605 }
cristy0fe961c2010-01-30 03:09:54 +00001606 if (LocaleCompare("features",option+1) == 0)
1607 {
1608 if (*option == '+')
1609 {
1610 (void) DeleteImageArtifact(*image,"identify:features");
1611 break;
1612 }
1613 (void) SetImageArtifact(*image,"identify:features",argv[i+1]);
1614 break;
1615 }
cristy3ed852e2009-09-05 21:47:34 +00001616 if (LocaleCompare("fill",option+1) == 0)
1617 {
1618 ExceptionInfo
1619 *sans;
1620
1621 GetMagickPixelPacket(*image,&fill);
1622 if (*option == '+')
1623 {
1624 (void) QueryMagickColor("none",&fill,exception);
1625 (void) QueryColorDatabase("none",&draw_info->fill,exception);
1626 if (draw_info->fill_pattern != (Image *) NULL)
1627 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
1628 break;
1629 }
1630 sans=AcquireExceptionInfo();
1631 (void) QueryMagickColor(argv[i+1],&fill,sans);
1632 status=QueryColorDatabase(argv[i+1],&draw_info->fill,sans);
1633 sans=DestroyExceptionInfo(sans);
1634 if (status == MagickFalse)
cristy6b3da3a2010-06-20 02:21:46 +00001635 draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1],
cristy3ed852e2009-09-05 21:47:34 +00001636 exception);
1637 break;
1638 }
1639 if (LocaleCompare("flip",option+1) == 0)
1640 {
1641 Image
1642 *flip_image;
1643
1644 /*
1645 Flip image scanlines.
1646 */
cristy6b3da3a2010-06-20 02:21:46 +00001647 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001648 flip_image=FlipImage(*image,exception);
1649 if (flip_image == (Image *) NULL)
1650 break;
1651 *image=DestroyImage(*image);
1652 *image=flip_image;
1653 break;
1654 }
1655 if (LocaleCompare("flop",option+1) == 0)
1656 {
1657 Image
1658 *flop_image;
1659
1660 /*
1661 Flop image scanlines.
1662 */
cristy6b3da3a2010-06-20 02:21:46 +00001663 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001664 flop_image=FlopImage(*image,exception);
1665 if (flop_image == (Image *) NULL)
1666 break;
1667 *image=DestroyImage(*image);
1668 *image=flop_image;
1669 break;
1670 }
1671 if (LocaleCompare("floodfill",option+1) == 0)
1672 {
1673 MagickPixelPacket
1674 target;
1675
1676 /*
1677 Floodfill image.
1678 */
cristy6b3da3a2010-06-20 02:21:46 +00001679 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001680 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
1681 (void) QueryMagickColor(argv[i+2],&target,exception);
1682 (void) FloodfillPaintImage(*image,channel,draw_info,&target,
1683 geometry.x,geometry.y,*option == '-' ? MagickFalse : MagickTrue);
1684 InheritException(exception,&(*image)->exception);
1685 break;
1686 }
1687 if (LocaleCompare("font",option+1) == 0)
1688 {
1689 if (*option == '+')
1690 {
1691 if (draw_info->font != (char *) NULL)
1692 draw_info->font=DestroyString(draw_info->font);
1693 break;
1694 }
1695 (void) CloneString(&draw_info->font,argv[i+1]);
1696 break;
1697 }
1698 if (LocaleCompare("format",option+1) == 0)
1699 {
1700 format=argv[i+1];
1701 break;
1702 }
1703 if (LocaleCompare("frame",option+1) == 0)
1704 {
1705 FrameInfo
1706 frame_info;
1707
1708 Image
1709 *frame_image;
1710
1711 /*
1712 Surround image with an ornamental border.
1713 */
cristy6b3da3a2010-06-20 02:21:46 +00001714 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001715 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
1716 frame_info.width=geometry.width;
1717 frame_info.height=geometry.height;
1718 if ((flags & HeightValue) == 0)
1719 frame_info.height=geometry.width;
1720 frame_info.outer_bevel=geometry.x;
1721 frame_info.inner_bevel=geometry.y;
cristybb503372010-05-27 20:51:26 +00001722 frame_info.x=(ssize_t) frame_info.width;
1723 frame_info.y=(ssize_t) frame_info.height;
cristy3ed852e2009-09-05 21:47:34 +00001724 frame_info.width=(*image)->columns+2*frame_info.width;
1725 frame_info.height=(*image)->rows+2*frame_info.height;
1726 frame_image=FrameImage(*image,&frame_info,exception);
1727 if (frame_image == (Image *) NULL)
1728 break;
1729 *image=DestroyImage(*image);
1730 *image=frame_image;
1731 break;
1732 }
1733 if (LocaleCompare("function",option+1) == 0)
1734 {
1735 char
1736 *arguments,
1737 token[MaxTextExtent];
1738
1739 const char
1740 *p;
1741
1742 double
1743 *parameters;
1744
1745 MagickFunction
1746 function;
1747
cristybb503372010-05-27 20:51:26 +00001748 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001749 x;
1750
cristybb503372010-05-27 20:51:26 +00001751 size_t
cristy3ed852e2009-09-05 21:47:34 +00001752 number_parameters;
1753
1754 /*
1755 Function Modify Image Values
1756 */
cristy6b3da3a2010-06-20 02:21:46 +00001757 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001758 function=(MagickFunction) ParseMagickOption(MagickFunctionOptions,
1759 MagickFalse,argv[i+1]);
cristy6b3da3a2010-06-20 02:21:46 +00001760 arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
cristy3ed852e2009-09-05 21:47:34 +00001761 InheritException(exception,&(*image)->exception);
1762 if (arguments == (char *) NULL)
1763 break;
1764 p=(char *) arguments;
1765 for (x=0; *p != '\0'; x++)
1766 {
1767 GetMagickToken(p,&p,token);
1768 if (*token == ',')
1769 GetMagickToken(p,&p,token);
1770 }
cristybb503372010-05-27 20:51:26 +00001771 number_parameters=(size_t) x;
cristy3ed852e2009-09-05 21:47:34 +00001772 parameters=(double *) AcquireQuantumMemory(number_parameters,
1773 sizeof(*parameters));
1774 if (parameters == (double *) NULL)
1775 ThrowWandFatalException(ResourceLimitFatalError,
1776 "MemoryAllocationFailed",(*image)->filename);
1777 (void) ResetMagickMemory(parameters,0,number_parameters*
1778 sizeof(*parameters));
1779 p=(char *) arguments;
cristybb503372010-05-27 20:51:26 +00001780 for (x=0; (x < (ssize_t) number_parameters) && (*p != '\0'); x++)
cristy3ed852e2009-09-05 21:47:34 +00001781 {
1782 GetMagickToken(p,&p,token);
1783 if (*token == ',')
1784 GetMagickToken(p,&p,token);
cristyf2f27272009-12-17 14:48:46 +00001785 parameters[x]=StringToDouble(token);
cristy3ed852e2009-09-05 21:47:34 +00001786 }
1787 arguments=DestroyString(arguments);
1788 (void) FunctionImageChannel(*image,channel,function,
1789 number_parameters,parameters,exception);
1790 parameters=(double *) RelinquishMagickMemory(parameters);
1791 break;
1792 }
1793 break;
1794 }
1795 case 'g':
1796 {
1797 if (LocaleCompare("gamma",option+1) == 0)
1798 {
1799 /*
1800 Gamma image.
1801 */
cristy6b3da3a2010-06-20 02:21:46 +00001802 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001803 if (*option == '+')
cristyf2f27272009-12-17 14:48:46 +00001804 (*image)->gamma=StringToDouble(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00001805 else
1806 {
1807 if (strchr(argv[i+1],',') != (char *) NULL)
1808 (void) GammaImage(*image,argv[i+1]);
1809 else
cristya5447be2010-01-11 00:20:51 +00001810 (void) GammaImageChannel(*image,channel,
1811 StringToDouble(argv[i+1]));
cristy3ed852e2009-09-05 21:47:34 +00001812 InheritException(exception,&(*image)->exception);
1813 }
1814 break;
1815 }
1816 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
1817 (LocaleCompare("gaussian",option+1) == 0))
1818 {
1819 Image
1820 *gaussian_image;
1821
1822 /*
1823 Gaussian blur image.
1824 */
cristy6b3da3a2010-06-20 02:21:46 +00001825 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001826 flags=ParseGeometry(argv[i+1],&geometry_info);
1827 if ((flags & SigmaValue) == 0)
1828 geometry_info.sigma=1.0;
1829 gaussian_image=GaussianBlurImageChannel(*image,channel,
1830 geometry_info.rho,geometry_info.sigma,exception);
1831 if (gaussian_image == (Image *) NULL)
1832 break;
1833 *image=DestroyImage(*image);
1834 *image=gaussian_image;
1835 break;
1836 }
1837 if (LocaleCompare("geometry",option+1) == 0)
1838 {
cristy6b3da3a2010-06-20 02:21:46 +00001839 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001840 if (*option == '+')
1841 {
1842 if ((*image)->geometry != (char *) NULL)
1843 (*image)->geometry=DestroyString((*image)->geometry);
1844 break;
1845 }
1846 flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
1847 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
1848 (void) CloneString(&(*image)->geometry,argv[i+1]);
1849 else
1850 {
1851 Image
1852 *zoom_image;
1853
1854 /*
1855 Resize image.
1856 */
1857 zoom_image=ZoomImage(*image,geometry.width,geometry.height,
1858 exception);
1859 if (zoom_image == (Image *) NULL)
1860 break;
1861 *image=DestroyImage(*image);
1862 *image=zoom_image;
1863 }
1864 break;
1865 }
1866 if (LocaleCompare("gravity",option+1) == 0)
1867 {
1868 if (*option == '+')
1869 {
1870 draw_info->gravity=UndefinedGravity;
1871 break;
1872 }
1873 draw_info->gravity=(GravityType) ParseMagickOption(
1874 MagickGravityOptions,MagickFalse,argv[i+1]);
1875 break;
1876 }
1877 break;
1878 }
1879 case 'h':
1880 {
1881 if (LocaleCompare("highlight-color",option+1) == 0)
1882 {
1883 (void) SetImageArtifact(*image,option+1,argv[i+1]);
1884 break;
1885 }
1886 break;
1887 }
1888 case 'i':
1889 {
1890 if (LocaleCompare("identify",option+1) == 0)
1891 {
1892 char
1893 *text;
1894
cristy6b3da3a2010-06-20 02:21:46 +00001895 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001896 if (format == (char *) NULL)
1897 {
cristy6b3da3a2010-06-20 02:21:46 +00001898 (void) IdentifyImage(*image,stdout,mogrify_info->verbose);
cristy3ed852e2009-09-05 21:47:34 +00001899 InheritException(exception,&(*image)->exception);
1900 break;
1901 }
cristy6b3da3a2010-06-20 02:21:46 +00001902 text=InterpretImageProperties(mogrify_info,*image,format);
cristy3ed852e2009-09-05 21:47:34 +00001903 InheritException(exception,&(*image)->exception);
1904 if (text == (char *) NULL)
1905 break;
1906 (void) fputs(text,stdout);
1907 (void) fputc('\n',stdout);
1908 text=DestroyString(text);
1909 break;
1910 }
1911 if (LocaleCompare("implode",option+1) == 0)
1912 {
1913 Image
1914 *implode_image;
1915
1916 /*
1917 Implode image.
1918 */
cristy6b3da3a2010-06-20 02:21:46 +00001919 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001920 (void) ParseGeometry(argv[i+1],&geometry_info);
1921 implode_image=ImplodeImage(*image,geometry_info.rho,exception);
1922 if (implode_image == (Image *) NULL)
1923 break;
1924 *image=DestroyImage(*image);
1925 *image=implode_image;
1926 break;
1927 }
cristyb32b90a2009-09-07 21:45:48 +00001928 if (LocaleCompare("interline-spacing",option+1) == 0)
1929 {
1930 if (*option == '+')
1931 (void) ParseGeometry("0",&geometry_info);
1932 else
1933 (void) ParseGeometry(argv[i+1],&geometry_info);
1934 draw_info->interline_spacing=geometry_info.rho;
1935 break;
1936 }
cristy3ed852e2009-09-05 21:47:34 +00001937 if (LocaleCompare("interword-spacing",option+1) == 0)
1938 {
1939 if (*option == '+')
1940 (void) ParseGeometry("0",&geometry_info);
1941 else
1942 (void) ParseGeometry(argv[i+1],&geometry_info);
1943 draw_info->interword_spacing=geometry_info.rho;
1944 break;
1945 }
1946 break;
1947 }
1948 case 'k':
1949 {
1950 if (LocaleCompare("kerning",option+1) == 0)
1951 {
1952 if (*option == '+')
1953 (void) ParseGeometry("0",&geometry_info);
1954 else
1955 (void) ParseGeometry(argv[i+1],&geometry_info);
1956 draw_info->kerning=geometry_info.rho;
1957 break;
1958 }
1959 break;
1960 }
1961 case 'l':
1962 {
1963 if (LocaleCompare("lat",option+1) == 0)
1964 {
1965 Image
1966 *threshold_image;
1967
1968 /*
1969 Local adaptive threshold image.
1970 */
cristy6b3da3a2010-06-20 02:21:46 +00001971 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001972 flags=ParseGeometry(argv[i+1],&geometry_info);
1973 if ((flags & PercentValue) != 0)
1974 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
cristybb503372010-05-27 20:51:26 +00001975 threshold_image=AdaptiveThresholdImage(*image,(size_t)
1976 geometry_info.rho,(size_t) geometry_info.sigma,
1977 (ssize_t) geometry_info.xi,exception);
cristy3ed852e2009-09-05 21:47:34 +00001978 if (threshold_image == (Image *) NULL)
1979 break;
1980 *image=DestroyImage(*image);
1981 *image=threshold_image;
1982 break;
1983 }
1984 if (LocaleCompare("level",option+1) == 0)
1985 {
cristy3ed852e2009-09-05 21:47:34 +00001986 MagickRealType
1987 black_point,
1988 gamma,
1989 white_point;
1990
1991 MagickStatusType
1992 flags;
1993
1994 /*
1995 Parse levels.
1996 */
cristy6b3da3a2010-06-20 02:21:46 +00001997 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001998 flags=ParseGeometry(argv[i+1],&geometry_info);
1999 black_point=geometry_info.rho;
2000 white_point=(MagickRealType) QuantumRange;
2001 if ((flags & SigmaValue) != 0)
2002 white_point=geometry_info.sigma;
2003 gamma=1.0;
2004 if ((flags & XiValue) != 0)
2005 gamma=geometry_info.xi;
2006 if ((flags & PercentValue) != 0)
2007 {
2008 black_point*=(MagickRealType) (QuantumRange/100.0);
2009 white_point*=(MagickRealType) (QuantumRange/100.0);
2010 }
2011 if ((flags & SigmaValue) == 0)
2012 white_point=(MagickRealType) QuantumRange-black_point;
2013 if ((*option == '+') || ((flags & AspectValue) != 0))
2014 (void) LevelizeImageChannel(*image,channel,black_point,
2015 white_point,gamma);
2016 else
2017 (void) LevelImageChannel(*image,channel,black_point,white_point,
2018 gamma);
2019 InheritException(exception,&(*image)->exception);
2020 break;
2021 }
2022 if (LocaleCompare("level-colors",option+1) == 0)
2023 {
2024 char
2025 token[MaxTextExtent];
2026
2027 const char
2028 *p;
2029
2030 MagickPixelPacket
2031 black_point,
2032 white_point;
2033
2034 p=(const char *) argv[i+1];
2035 GetMagickToken(p,&p,token); /* get black point color */
cristyee0f8d72009-09-19 00:58:29 +00002036 if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
cristy3ed852e2009-09-05 21:47:34 +00002037 (void) QueryMagickColor(token,&black_point,exception);
2038 else
cristyee0f8d72009-09-19 00:58:29 +00002039 (void) QueryMagickColor("#000000",&black_point,exception);
cristy3ed852e2009-09-05 21:47:34 +00002040 if (isalpha((int) token[0]) || (token[0] == '#'))
2041 GetMagickToken(p,&p,token);
cristyee0f8d72009-09-19 00:58:29 +00002042 if (*token == '\0')
cristy3ed852e2009-09-05 21:47:34 +00002043 white_point=black_point; /* set everything to that color */
2044 else
2045 {
2046 /*
2047 Get white point color.
2048 */
cristyee0f8d72009-09-19 00:58:29 +00002049 if ((isalpha((int) *token) == 0) && ((*token == '#') == 0))
cristy3ed852e2009-09-05 21:47:34 +00002050 GetMagickToken(p,&p,token);
cristyee0f8d72009-09-19 00:58:29 +00002051 if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
cristy3ed852e2009-09-05 21:47:34 +00002052 (void) QueryMagickColor(token,&white_point,exception);
2053 else
cristyee0f8d72009-09-19 00:58:29 +00002054 (void) QueryMagickColor("#ffffff",&white_point,exception);
cristy3ed852e2009-09-05 21:47:34 +00002055 }
cristy74fe8f12009-10-03 19:09:01 +00002056 (void) LevelColorsImageChannel(*image,channel,&black_point,
2057 &white_point,*option == '+' ? MagickTrue : MagickFalse);
cristy3ed852e2009-09-05 21:47:34 +00002058 break;
2059 }
2060 if (LocaleCompare("linear-stretch",option+1) == 0)
2061 {
2062 double
2063 black_point,
2064 white_point;
2065
cristy3ed852e2009-09-05 21:47:34 +00002066 MagickStatusType
2067 flags;
2068
cristy6b3da3a2010-06-20 02:21:46 +00002069 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002070 flags=ParseGeometry(argv[i+1],&geometry_info);
2071 black_point=geometry_info.rho;
2072 white_point=(MagickRealType) (*image)->columns*(*image)->rows;
2073 if ((flags & SigmaValue) != 0)
2074 white_point=geometry_info.sigma;
2075 if ((flags & PercentValue) != 0)
2076 {
2077 black_point*=(double) (*image)->columns*(*image)->rows/100.0;
2078 white_point*=(double) (*image)->columns*(*image)->rows/100.0;
2079 }
2080 if ((flags & SigmaValue) == 0)
2081 white_point=(MagickRealType) (*image)->columns*(*image)->rows-
2082 black_point;
2083 (void) LinearStretchImage(*image,black_point,white_point);
2084 InheritException(exception,&(*image)->exception);
2085 break;
2086 }
2087 if (LocaleCompare("linewidth",option+1) == 0)
2088 {
cristyf2f27272009-12-17 14:48:46 +00002089 draw_info->stroke_width=StringToDouble(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00002090 break;
2091 }
2092 if (LocaleCompare("liquid-rescale",option+1) == 0)
2093 {
2094 Image
2095 *resize_image;
2096
2097 /*
2098 Liquid rescale image.
2099 */
cristy6b3da3a2010-06-20 02:21:46 +00002100 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002101 flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2102 if ((flags & XValue) == 0)
2103 geometry.x=1;
2104 if ((flags & YValue) == 0)
2105 geometry.y=0;
2106 resize_image=LiquidRescaleImage(*image,geometry.width,
2107 geometry.height,1.0*geometry.x,1.0*geometry.y,exception);
2108 if (resize_image == (Image *) NULL)
2109 break;
2110 *image=DestroyImage(*image);
2111 *image=resize_image;
2112 break;
2113 }
2114 if (LocaleCompare("lowlight-color",option+1) == 0)
2115 {
2116 (void) SetImageArtifact(*image,option+1,argv[i+1]);
2117 break;
2118 }
2119 break;
2120 }
2121 case 'm':
2122 {
2123 if (LocaleCompare("map",option+1) == 0)
2124 {
2125 Image
2126 *remap_image;
2127
2128 /*
2129 Transform image colors to match this set of colors.
2130 */
cristy6b3da3a2010-06-20 02:21:46 +00002131 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002132 if (*option == '+')
2133 break;
cristy6b3da3a2010-06-20 02:21:46 +00002134 remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
cristy3ed852e2009-09-05 21:47:34 +00002135 if (remap_image == (Image *) NULL)
2136 break;
2137 (void) RemapImage(quantize_info,*image,remap_image);
2138 InheritException(exception,&(*image)->exception);
2139 remap_image=DestroyImage(remap_image);
2140 break;
2141 }
2142 if (LocaleCompare("mask",option+1) == 0)
2143 {
2144 Image
2145 *mask;
2146
cristy6b3da3a2010-06-20 02:21:46 +00002147 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002148 if (*option == '+')
2149 {
2150 /*
2151 Remove a mask.
2152 */
2153 (void) SetImageMask(*image,(Image *) NULL);
2154 InheritException(exception,&(*image)->exception);
2155 break;
2156 }
2157 /*
2158 Set the image mask.
2159 */
cristy6b3da3a2010-06-20 02:21:46 +00002160 mask=GetImageCache(mogrify_info,argv[i+1],exception);
cristy3ed852e2009-09-05 21:47:34 +00002161 if (mask == (Image *) NULL)
2162 break;
2163 (void) SetImageMask(*image,mask);
2164 mask=DestroyImage(mask);
2165 InheritException(exception,&(*image)->exception);
2166 break;
2167 }
2168 if (LocaleCompare("matte",option+1) == 0)
2169 {
2170 (void) SetImageAlphaChannel(*image,(*option == '-') ?
2171 SetAlphaChannel : DeactivateAlphaChannel );
2172 InheritException(exception,&(*image)->exception);
2173 break;
2174 }
2175 if (LocaleCompare("median",option+1) == 0)
2176 {
2177 Image
2178 *median_image;
2179
2180 /*
2181 Median filter image.
2182 */
cristy6b3da3a2010-06-20 02:21:46 +00002183 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002184 (void) ParseGeometry(argv[i+1],&geometry_info);
2185 median_image=MedianFilterImage(*image,geometry_info.rho,exception);
2186 if (median_image == (Image *) NULL)
2187 break;
2188 *image=DestroyImage(*image);
2189 *image=median_image;
2190 break;
2191 }
2192 if (LocaleCompare("modulate",option+1) == 0)
2193 {
cristy6b3da3a2010-06-20 02:21:46 +00002194 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002195 (void) ModulateImage(*image,argv[i+1]);
2196 InheritException(exception,&(*image)->exception);
2197 break;
2198 }
2199 if (LocaleCompare("monitor",option+1) == 0)
2200 {
cristy7d34ef22010-03-25 01:11:22 +00002201 if (*option == '+')
2202 {
2203 (void) SetImageProgressMonitor(*image,
2204 (MagickProgressMonitor) NULL,(void *) NULL);
2205 break;
2206 }
cristy3ed852e2009-09-05 21:47:34 +00002207 (void) SetImageProgressMonitor(*image,MonitorProgress,
2208 (void *) NULL);
2209 break;
2210 }
2211 if (LocaleCompare("monochrome",option+1) == 0)
2212 {
cristy6b3da3a2010-06-20 02:21:46 +00002213 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002214 (void) SetImageType(*image,BilevelType);
2215 InheritException(exception,&(*image)->exception);
2216 break;
2217 }
anthony29188a82010-01-22 10:12:34 +00002218 if (LocaleCompare("morphology",option+1) == 0)
2219 {
anthony29188a82010-01-22 10:12:34 +00002220 char
2221 token[MaxTextExtent];
2222
2223 const char
2224 *p;
2225
cristye96405a2010-05-19 02:24:31 +00002226 Image
2227 *morphology_image;
2228
2229 KernelInfo
2230 *kernel;
2231
cristybb503372010-05-27 20:51:26 +00002232 ssize_t
anthony29188a82010-01-22 10:12:34 +00002233 iterations;
2234
cristye96405a2010-05-19 02:24:31 +00002235 MorphologyMethod
2236 method;
2237
anthony29188a82010-01-22 10:12:34 +00002238 /*
2239 Morphological Image Operation
2240 */
cristy6b3da3a2010-06-20 02:21:46 +00002241 (void) SyncImageSettings(mogrify_info,*image);
anthony29188a82010-01-22 10:12:34 +00002242 p=argv[i+1];
2243 GetMagickToken(p,&p,token);
2244 method=(MorphologyMethod) ParseMagickOption(MagickMorphologyOptions,
cristyd2c1e1e2010-05-08 01:05:44 +00002245 MagickFalse,token);
cristyef656912010-03-05 19:54:59 +00002246 iterations=1L;
anthony29188a82010-01-22 10:12:34 +00002247 GetMagickToken(p,&p,token);
cristyef656912010-03-05 19:54:59 +00002248 if ((*p == ':') || (*p == ','))
anthony29188a82010-01-22 10:12:34 +00002249 GetMagickToken(p,&p,token);
cristyef656912010-03-05 19:54:59 +00002250 if ((*p != '\0'))
2251 iterations=StringToLong(p);
anthony29188a82010-01-22 10:12:34 +00002252 kernel=AcquireKernelInfo(argv[i+2]);
2253 if (kernel == (KernelInfo *) NULL)
cristye96405a2010-05-19 02:24:31 +00002254 {
2255 (void) ThrowMagickException(exception,GetMagickModule(),
2256 OptionError,"UnabletoParseKernel","morphology");
2257 status=MagickFalse;
2258 break;
2259 }
anthony29188a82010-01-22 10:12:34 +00002260 morphology_image=MorphologyImageChannel(*image,channel,method,
cristy02d5b4f2010-02-01 01:08:27 +00002261 iterations,kernel,exception);
anthony83ba99b2010-01-24 08:48:15 +00002262 kernel=DestroyKernelInfo(kernel);
anthony29188a82010-01-22 10:12:34 +00002263 if (morphology_image == (Image *) NULL)
2264 break;
2265 *image=DestroyImage(*image);
2266 *image=morphology_image;
2267 break;
2268 }
cristy3ed852e2009-09-05 21:47:34 +00002269 if (LocaleCompare("motion-blur",option+1) == 0)
2270 {
2271 Image
2272 *blur_image;
2273
2274 /*
2275 Motion blur image.
2276 */
cristy6b3da3a2010-06-20 02:21:46 +00002277 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002278 flags=ParseGeometry(argv[i+1],&geometry_info);
2279 if ((flags & SigmaValue) == 0)
2280 geometry_info.sigma=1.0;
2281 blur_image=MotionBlurImageChannel(*image,channel,geometry_info.rho,
2282 geometry_info.sigma,geometry_info.xi,exception);
2283 if (blur_image == (Image *) NULL)
2284 break;
2285 *image=DestroyImage(*image);
2286 *image=blur_image;
2287 break;
2288 }
2289 break;
2290 }
2291 case 'n':
2292 {
2293 if (LocaleCompare("negate",option+1) == 0)
2294 {
cristy6b3da3a2010-06-20 02:21:46 +00002295 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002296 (void) NegateImageChannel(*image,channel,*option == '+' ?
2297 MagickTrue : MagickFalse);
2298 InheritException(exception,&(*image)->exception);
2299 break;
2300 }
2301 if (LocaleCompare("noise",option+1) == 0)
2302 {
2303 Image
2304 *noisy_image;
2305
cristy6b3da3a2010-06-20 02:21:46 +00002306 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002307 if (*option == '-')
2308 {
2309 (void) ParseGeometry(argv[i+1],&geometry_info);
2310 noisy_image=ReduceNoiseImage(*image,geometry_info.rho,
2311 exception);
2312 }
2313 else
2314 {
2315 NoiseType
2316 noise;
2317
2318 noise=(NoiseType) ParseMagickOption(MagickNoiseOptions,
2319 MagickFalse,argv[i+1]);
2320 noisy_image=AddNoiseImageChannel(*image,channel,noise,
2321 exception);
2322 }
2323 if (noisy_image == (Image *) NULL)
2324 break;
2325 *image=DestroyImage(*image);
2326 *image=noisy_image;
2327 break;
2328 }
2329 if (LocaleCompare("normalize",option+1) == 0)
2330 {
cristy6b3da3a2010-06-20 02:21:46 +00002331 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002332 (void) NormalizeImageChannel(*image,channel);
2333 InheritException(exception,&(*image)->exception);
2334 break;
2335 }
2336 break;
2337 }
2338 case 'o':
2339 {
2340 if (LocaleCompare("opaque",option+1) == 0)
2341 {
2342 MagickPixelPacket
2343 target;
2344
cristy6b3da3a2010-06-20 02:21:46 +00002345 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002346 (void) QueryMagickColor(argv[i+1],&target,exception);
2347 (void) OpaquePaintImageChannel(*image,channel,&target,&fill,
2348 *option == '-' ? MagickFalse : MagickTrue);
2349 break;
2350 }
2351 if (LocaleCompare("ordered-dither",option+1) == 0)
2352 {
cristy6b3da3a2010-06-20 02:21:46 +00002353 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002354 (void) OrderedPosterizeImageChannel(*image,channel,argv[i+1],
2355 exception);
2356 break;
2357 }
2358 break;
2359 }
2360 case 'p':
2361 {
2362 if (LocaleCompare("paint",option+1) == 0)
2363 {
2364 Image
2365 *paint_image;
2366
2367 /*
2368 Oil paint image.
2369 */
cristy6b3da3a2010-06-20 02:21:46 +00002370 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002371 (void) ParseGeometry(argv[i+1],&geometry_info);
2372 paint_image=OilPaintImage(*image,geometry_info.rho,exception);
2373 if (paint_image == (Image *) NULL)
2374 break;
2375 *image=DestroyImage(*image);
2376 *image=paint_image;
2377 break;
2378 }
2379 if (LocaleCompare("pen",option+1) == 0)
2380 {
2381 if (*option == '+')
2382 {
2383 (void) QueryColorDatabase("none",&draw_info->fill,exception);
2384 break;
2385 }
2386 (void) QueryColorDatabase(argv[i+1],&draw_info->fill,exception);
2387 break;
2388 }
2389 if (LocaleCompare("pointsize",option+1) == 0)
2390 {
2391 if (*option == '+')
2392 (void) ParseGeometry("12",&geometry_info);
2393 else
2394 (void) ParseGeometry(argv[i+1],&geometry_info);
2395 draw_info->pointsize=geometry_info.rho;
2396 break;
2397 }
2398 if (LocaleCompare("polaroid",option+1) == 0)
2399 {
2400 double
2401 angle;
2402
2403 Image
2404 *polaroid_image;
2405
2406 RandomInfo
2407 *random_info;
2408
2409 /*
2410 Simulate a Polaroid picture.
2411 */
cristy6b3da3a2010-06-20 02:21:46 +00002412 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002413 random_info=AcquireRandomInfo();
2414 angle=22.5*(GetPseudoRandomValue(random_info)-0.5);
2415 random_info=DestroyRandomInfo(random_info);
2416 if (*option == '-')
2417 {
2418 SetGeometryInfo(&geometry_info);
2419 flags=ParseGeometry(argv[i+1],&geometry_info);
2420 angle=geometry_info.rho;
2421 }
2422 polaroid_image=PolaroidImage(*image,draw_info,angle,exception);
2423 if (polaroid_image == (Image *) NULL)
2424 break;
2425 *image=DestroyImage(*image);
2426 *image=polaroid_image;
2427 break;
2428 }
2429 if (LocaleCompare("posterize",option+1) == 0)
2430 {
2431 /*
2432 Posterize image.
2433 */
cristy6b3da3a2010-06-20 02:21:46 +00002434 (void) SyncImageSettings(mogrify_info,*image);
cristye27293e2009-12-18 02:53:20 +00002435 (void) PosterizeImage(*image,StringToUnsignedLong(argv[i+1]),
cristy3ed852e2009-09-05 21:47:34 +00002436 quantize_info->dither);
2437 InheritException(exception,&(*image)->exception);
2438 break;
2439 }
2440 if (LocaleCompare("preview",option+1) == 0)
2441 {
2442 Image
2443 *preview_image;
2444
2445 PreviewType
2446 preview_type;
2447
2448 /*
2449 Preview image.
2450 */
cristy6b3da3a2010-06-20 02:21:46 +00002451 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002452 if (*option == '+')
2453 preview_type=UndefinedPreview;
2454 else
2455 preview_type=(PreviewType) ParseMagickOption(MagickPreviewOptions,
2456 MagickFalse,argv[i+1]);
2457 preview_image=PreviewImage(*image,preview_type,exception);
2458 if (preview_image == (Image *) NULL)
2459 break;
2460 *image=DestroyImage(*image);
2461 *image=preview_image;
2462 break;
2463 }
2464 if (LocaleCompare("profile",option+1) == 0)
2465 {
2466 const char
2467 *name;
2468
2469 const StringInfo
2470 *profile;
2471
2472 Image
2473 *profile_image;
2474
2475 ImageInfo
2476 *profile_info;
2477
cristy6b3da3a2010-06-20 02:21:46 +00002478 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002479 if (*option == '+')
2480 {
2481 /*
2482 Remove a profile from the image.
2483 */
2484 (void) ProfileImage(*image,argv[i+1],(const unsigned char *)
2485 NULL,0,MagickTrue);
2486 InheritException(exception,&(*image)->exception);
2487 break;
2488 }
2489 /*
2490 Associate a profile with the image.
2491 */
cristy6b3da3a2010-06-20 02:21:46 +00002492 profile_info=CloneImageInfo(mogrify_info);
cristy3ed852e2009-09-05 21:47:34 +00002493 profile=GetImageProfile(*image,"iptc");
2494 if (profile != (StringInfo *) NULL)
2495 profile_info->profile=(void *) CloneStringInfo(profile);
2496 profile_image=GetImageCache(profile_info,argv[i+1],exception);
2497 profile_info=DestroyImageInfo(profile_info);
2498 if (profile_image == (Image *) NULL)
2499 {
cristy3ed852e2009-09-05 21:47:34 +00002500 StringInfo
2501 *profile;
2502
cristy6b3da3a2010-06-20 02:21:46 +00002503 profile_info=CloneImageInfo(mogrify_info);
cristy071dd7b2010-04-09 13:04:54 +00002504 (void) CopyMagickString(profile_info->filename,argv[i+1],
2505 MaxTextExtent);
2506 profile=FileToStringInfo(profile_info->filename,~0UL,exception);
cristy3ed852e2009-09-05 21:47:34 +00002507 if (profile != (StringInfo *) NULL)
2508 {
cristy071dd7b2010-04-09 13:04:54 +00002509 (void) ProfileImage(*image,profile_info->magick,
cristybb503372010-05-27 20:51:26 +00002510 GetStringInfoDatum(profile),(size_t)
cristy071dd7b2010-04-09 13:04:54 +00002511 GetStringInfoLength(profile),MagickFalse);
cristy3ed852e2009-09-05 21:47:34 +00002512 profile=DestroyStringInfo(profile);
2513 }
cristy071dd7b2010-04-09 13:04:54 +00002514 profile_info=DestroyImageInfo(profile_info);
cristy3ed852e2009-09-05 21:47:34 +00002515 break;
2516 }
2517 ResetImageProfileIterator(profile_image);
2518 name=GetNextImageProfile(profile_image);
2519 while (name != (const char *) NULL)
2520 {
2521 profile=GetImageProfile(profile_image,name);
2522 if (profile != (StringInfo *) NULL)
2523 (void) ProfileImage(*image,name,GetStringInfoDatum(profile),
cristybb503372010-05-27 20:51:26 +00002524 (size_t) GetStringInfoLength(profile),MagickFalse);
cristy3ed852e2009-09-05 21:47:34 +00002525 name=GetNextImageProfile(profile_image);
2526 }
2527 profile_image=DestroyImage(profile_image);
2528 break;
2529 }
2530 break;
2531 }
2532 case 'q':
2533 {
2534 if (LocaleCompare("quantize",option+1) == 0)
2535 {
2536 if (*option == '+')
2537 {
2538 quantize_info->colorspace=UndefinedColorspace;
2539 break;
2540 }
2541 quantize_info->colorspace=(ColorspaceType) ParseMagickOption(
2542 MagickColorspaceOptions,MagickFalse,argv[i+1]);
2543 break;
2544 }
2545 break;
2546 }
2547 case 'r':
2548 {
2549 if (LocaleCompare("radial-blur",option+1) == 0)
2550 {
2551 Image
2552 *blur_image;
2553
2554 /*
2555 Radial blur image.
2556 */
cristy6b3da3a2010-06-20 02:21:46 +00002557 (void) SyncImageSettings(mogrify_info,*image);
cristya5447be2010-01-11 00:20:51 +00002558 blur_image=RadialBlurImageChannel(*image,channel,
2559 StringToDouble(argv[i+1]),exception);
cristy3ed852e2009-09-05 21:47:34 +00002560 if (blur_image == (Image *) NULL)
2561 break;
2562 *image=DestroyImage(*image);
2563 *image=blur_image;
2564 break;
2565 }
2566 if (LocaleCompare("raise",option+1) == 0)
2567 {
2568 /*
2569 Surround image with a raise of solid color.
2570 */
2571 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2572 if ((flags & SigmaValue) == 0)
2573 geometry.height=geometry.width;
2574 (void) RaiseImage(*image,&geometry,*option == '-' ? MagickTrue :
2575 MagickFalse);
2576 InheritException(exception,&(*image)->exception);
2577 break;
2578 }
2579 if (LocaleCompare("random-threshold",option+1) == 0)
2580 {
2581 /*
2582 Threshold image.
2583 */
cristy6b3da3a2010-06-20 02:21:46 +00002584 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002585 (void) RandomThresholdImageChannel(*image,channel,argv[i+1],
2586 exception);
2587 break;
2588 }
2589 if (LocaleCompare("recolor",option+1) == 0)
2590 {
cristy3ed852e2009-09-05 21:47:34 +00002591 Image
cristyf055ae42010-04-02 23:01:38 +00002592 *color_image;
cristy3ed852e2009-09-05 21:47:34 +00002593
cristyf055ae42010-04-02 23:01:38 +00002594 KernelInfo
2595 *kernel;
cristy3ed852e2009-09-05 21:47:34 +00002596
cristy6b3da3a2010-06-20 02:21:46 +00002597 (void) SyncImageSettings(mogrify_info,*image);
cristyf055ae42010-04-02 23:01:38 +00002598 kernel=AcquireKernelInfo(argv[i+1]);
2599 if (kernel == (KernelInfo *) NULL)
2600 break;
2601 color_image=ColorMatrixImage(*image,kernel,exception);
2602 kernel=DestroyKernelInfo(kernel);
2603 if (color_image == (Image *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002604 break;
2605 *image=DestroyImage(*image);
cristyf055ae42010-04-02 23:01:38 +00002606 *image=color_image;
cristy3ed852e2009-09-05 21:47:34 +00002607 break;
2608 }
2609 if (LocaleCompare("region",option+1) == 0)
2610 {
2611 Image
2612 *crop_image;
2613
cristy6b3da3a2010-06-20 02:21:46 +00002614 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002615 if (region_image != (Image *) NULL)
2616 {
2617 /*
2618 Composite region.
2619 */
2620 (void) CompositeImage(region_image,(*image)->matte !=
2621 MagickFalse ? OverCompositeOp : CopyCompositeOp,*image,
2622 region_geometry.x,region_geometry.y);
2623 InheritException(exception,&region_image->exception);
2624 *image=DestroyImage(*image);
2625 *image=region_image;
2626 }
2627 if (*option == '+')
2628 {
2629 if (region_image != (Image *) NULL)
2630 region_image=DestroyImage(region_image);
2631 break;
2632 }
2633 /*
2634 Apply transformations to a selected region of the image.
2635 */
2636 (void) ParseGravityGeometry(*image,argv[i+1],&region_geometry,
2637 exception);
2638 crop_image=CropImage(*image,&region_geometry,exception);
2639 if (crop_image == (Image *) NULL)
2640 break;
2641 region_image=(*image);
2642 *image=crop_image;
2643 break;
2644 }
2645 if (LocaleCompare("render",option+1) == 0)
2646 {
cristy6b3da3a2010-06-20 02:21:46 +00002647 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002648 draw_info->render=(*option == '+') ? MagickTrue : MagickFalse;
2649 break;
2650 }
2651 if (LocaleCompare("remap",option+1) == 0)
2652 {
2653 Image
2654 *remap_image;
2655
2656 /*
2657 Transform image colors to match this set of colors.
2658 */
cristy6b3da3a2010-06-20 02:21:46 +00002659 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002660 if (*option == '+')
2661 break;
cristy6b3da3a2010-06-20 02:21:46 +00002662 remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
cristy3ed852e2009-09-05 21:47:34 +00002663 if (remap_image == (Image *) NULL)
2664 break;
2665 (void) RemapImage(quantize_info,*image,remap_image);
2666 InheritException(exception,&(*image)->exception);
2667 remap_image=DestroyImage(remap_image);
2668 break;
2669 }
2670 if (LocaleCompare("repage",option+1) == 0)
2671 {
2672 if (*option == '+')
2673 {
2674 (void) ParseAbsoluteGeometry("0x0+0+0",&(*image)->page);
2675 break;
2676 }
2677 (void) ResetImagePage(*image,argv[i+1]);
2678 InheritException(exception,&(*image)->exception);
2679 break;
2680 }
2681 if (LocaleCompare("resample",option+1) == 0)
2682 {
2683 Image
2684 *resample_image;
2685
2686 /*
2687 Resample image.
2688 */
cristy6b3da3a2010-06-20 02:21:46 +00002689 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002690 flags=ParseGeometry(argv[i+1],&geometry_info);
2691 if ((flags & SigmaValue) == 0)
2692 geometry_info.sigma=geometry_info.rho;
2693 resample_image=ResampleImage(*image,geometry_info.rho,
2694 geometry_info.sigma,(*image)->filter,(*image)->blur,exception);
2695 if (resample_image == (Image *) NULL)
2696 break;
2697 *image=DestroyImage(*image);
2698 *image=resample_image;
2699 break;
2700 }
2701 if (LocaleCompare("resize",option+1) == 0)
2702 {
2703 Image
2704 *resize_image;
2705
2706 /*
2707 Resize image.
2708 */
cristy6b3da3a2010-06-20 02:21:46 +00002709 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002710 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2711 resize_image=ResizeImage(*image,geometry.width,geometry.height,
2712 (*image)->filter,(*image)->blur,exception);
2713 if (resize_image == (Image *) NULL)
2714 break;
2715 *image=DestroyImage(*image);
2716 *image=resize_image;
2717 break;
2718 }
2719 if (LocaleNCompare("respect-parentheses",option+1,17) == 0)
2720 {
2721 respect_parenthesis=(*option == '-') ? MagickTrue : MagickFalse;
2722 break;
2723 }
2724 if (LocaleCompare("roll",option+1) == 0)
2725 {
2726 Image
2727 *roll_image;
2728
2729 /*
2730 Roll image.
2731 */
cristy6b3da3a2010-06-20 02:21:46 +00002732 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002733 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2734 roll_image=RollImage(*image,geometry.x,geometry.y,exception);
2735 if (roll_image == (Image *) NULL)
2736 break;
2737 *image=DestroyImage(*image);
2738 *image=roll_image;
2739 break;
2740 }
2741 if (LocaleCompare("rotate",option+1) == 0)
2742 {
2743 char
2744 *geometry;
2745
2746 Image
2747 *rotate_image;
2748
2749 /*
2750 Check for conditional image rotation.
2751 */
cristy6b3da3a2010-06-20 02:21:46 +00002752 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002753 if (strchr(argv[i+1],'>') != (char *) NULL)
2754 if ((*image)->columns <= (*image)->rows)
2755 break;
2756 if (strchr(argv[i+1],'<') != (char *) NULL)
2757 if ((*image)->columns >= (*image)->rows)
2758 break;
2759 /*
2760 Rotate image.
2761 */
2762 geometry=ConstantString(argv[i+1]);
2763 (void) SubstituteString(&geometry,">","");
2764 (void) SubstituteString(&geometry,"<","");
2765 (void) ParseGeometry(geometry,&geometry_info);
2766 geometry=DestroyString(geometry);
2767 rotate_image=RotateImage(*image,geometry_info.rho,exception);
2768 if (rotate_image == (Image *) NULL)
2769 break;
2770 *image=DestroyImage(*image);
2771 *image=rotate_image;
2772 break;
2773 }
2774 break;
2775 }
2776 case 's':
2777 {
2778 if (LocaleCompare("sample",option+1) == 0)
2779 {
2780 Image
2781 *sample_image;
2782
2783 /*
2784 Sample image with pixel replication.
2785 */
cristy6b3da3a2010-06-20 02:21:46 +00002786 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002787 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2788 sample_image=SampleImage(*image,geometry.width,geometry.height,
2789 exception);
2790 if (sample_image == (Image *) NULL)
2791 break;
2792 *image=DestroyImage(*image);
2793 *image=sample_image;
2794 break;
2795 }
2796 if (LocaleCompare("scale",option+1) == 0)
2797 {
2798 Image
2799 *scale_image;
2800
2801 /*
2802 Resize image.
2803 */
cristy6b3da3a2010-06-20 02:21:46 +00002804 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002805 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2806 scale_image=ScaleImage(*image,geometry.width,geometry.height,
2807 exception);
2808 if (scale_image == (Image *) NULL)
2809 break;
2810 *image=DestroyImage(*image);
2811 *image=scale_image;
2812 break;
2813 }
2814 if (LocaleCompare("selective-blur",option+1) == 0)
2815 {
2816 Image
2817 *blur_image;
2818
2819 /*
2820 Selectively blur pixels within a contrast threshold.
2821 */
cristy6b3da3a2010-06-20 02:21:46 +00002822 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002823 flags=ParseGeometry(argv[i+1],&geometry_info);
2824 if ((flags & PercentValue) != 0)
2825 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
2826 blur_image=SelectiveBlurImageChannel(*image,channel,
2827 geometry_info.rho,geometry_info.sigma,geometry_info.xi,exception);
2828 if (blur_image == (Image *) NULL)
2829 break;
2830 *image=DestroyImage(*image);
2831 *image=blur_image;
2832 break;
2833 }
2834 if (LocaleCompare("separate",option+1) == 0)
2835 {
2836 Image
2837 *separate_images;
2838
2839 /*
2840 Break channels into separate images.
2841 */
cristy6b3da3a2010-06-20 02:21:46 +00002842 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002843 separate_images=SeparateImages(*image,channel,exception);
2844 if (separate_images == (Image *) NULL)
2845 break;
2846 *image=DestroyImage(*image);
2847 *image=separate_images;
2848 break;
2849 }
2850 if (LocaleCompare("sepia-tone",option+1) == 0)
2851 {
2852 double
2853 threshold;
2854
2855 Image
2856 *sepia_image;
2857
2858 /*
2859 Sepia-tone image.
2860 */
cristy6b3da3a2010-06-20 02:21:46 +00002861 (void) SyncImageSettings(mogrify_info,*image);
cristyf2f27272009-12-17 14:48:46 +00002862 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
cristy3ed852e2009-09-05 21:47:34 +00002863 sepia_image=SepiaToneImage(*image,threshold,exception);
2864 if (sepia_image == (Image *) NULL)
2865 break;
2866 *image=DestroyImage(*image);
2867 *image=sepia_image;
2868 break;
2869 }
2870 if (LocaleCompare("segment",option+1) == 0)
2871 {
2872 /*
2873 Segment image.
2874 */
cristy6b3da3a2010-06-20 02:21:46 +00002875 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002876 flags=ParseGeometry(argv[i+1],&geometry_info);
2877 if ((flags & SigmaValue) == 0)
2878 geometry_info.sigma=1.0;
cristy7e6164a2010-07-22 20:43:57 +00002879 (void) SegmentImage(*image,(*image)->colorspace,
2880 mogrify_info->verbose,geometry_info.rho,geometry_info.sigma);
cristy3ed852e2009-09-05 21:47:34 +00002881 InheritException(exception,&(*image)->exception);
2882 break;
2883 }
2884 if (LocaleCompare("set",option+1) == 0)
2885 {
cristy6d9a1292010-05-31 14:17:06 +00002886 char
2887 *value;
2888
cristy3ed852e2009-09-05 21:47:34 +00002889 /*
2890 Set image option.
2891 */
cristy6d9a1292010-05-31 14:17:06 +00002892 if (*option == '+')
2893 {
2894 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2895 (void) DeleteImageRegistry(argv[i+1]+9);
2896 else
2897 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
cristy7e109582010-06-01 12:56:44 +00002898 {
cristy6b3da3a2010-06-20 02:21:46 +00002899 (void) DeleteImageOption(mogrify_info,argv[i+1]+7);
cristy7e109582010-06-01 12:56:44 +00002900 (void) DeleteImageArtifact(*image,argv[i+1]+7);
2901 }
cristy6d9a1292010-05-31 14:17:06 +00002902 else
2903 (void) DeleteImageProperty(*image,argv[i+1]);
2904 break;
2905 }
cristy6b3da3a2010-06-20 02:21:46 +00002906 value=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
cristy6d9a1292010-05-31 14:17:06 +00002907 if (value == (char *) NULL)
2908 break;
cristy3ed852e2009-09-05 21:47:34 +00002909 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
cristy6d9a1292010-05-31 14:17:06 +00002910 (void) SetImageRegistry(StringRegistryType,argv[i+1]+9,value,
2911 exception);
cristy3ed852e2009-09-05 21:47:34 +00002912 else
2913 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
cristy6d9a1292010-05-31 14:17:06 +00002914 {
cristy6b3da3a2010-06-20 02:21:46 +00002915 (void) SetImageOption(mogrify_info,argv[i+1]+7,value);
cristy6d9a1292010-05-31 14:17:06 +00002916 (void) SetImageArtifact(*image,argv[i+1]+7,value);
2917 }
cristy3ed852e2009-09-05 21:47:34 +00002918 else
cristy6d9a1292010-05-31 14:17:06 +00002919 (void) SetImageProperty(*image,argv[i+1],value);
2920 value=DestroyString(value);
cristy3ed852e2009-09-05 21:47:34 +00002921 break;
2922 }
2923 if (LocaleCompare("shade",option+1) == 0)
2924 {
2925 Image
2926 *shade_image;
2927
2928 /*
2929 Shade image.
2930 */
cristy6b3da3a2010-06-20 02:21:46 +00002931 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002932 flags=ParseGeometry(argv[i+1],&geometry_info);
2933 if ((flags & SigmaValue) == 0)
2934 geometry_info.sigma=1.0;
2935 shade_image=ShadeImage(*image,(*option == '-') ? MagickTrue :
2936 MagickFalse,geometry_info.rho,geometry_info.sigma,exception);
2937 if (shade_image == (Image *) NULL)
2938 break;
2939 *image=DestroyImage(*image);
2940 *image=shade_image;
2941 break;
2942 }
2943 if (LocaleCompare("shadow",option+1) == 0)
2944 {
2945 Image
2946 *shadow_image;
2947
2948 /*
2949 Shadow image.
2950 */
cristy6b3da3a2010-06-20 02:21:46 +00002951 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002952 flags=ParseGeometry(argv[i+1],&geometry_info);
2953 if ((flags & SigmaValue) == 0)
2954 geometry_info.sigma=1.0;
2955 if ((flags & XiValue) == 0)
2956 geometry_info.xi=4.0;
2957 if ((flags & PsiValue) == 0)
2958 geometry_info.psi=4.0;
2959 shadow_image=ShadowImage(*image,geometry_info.rho,
cristybb503372010-05-27 20:51:26 +00002960 geometry_info.sigma,(ssize_t) ceil(geometry_info.xi-0.5),(ssize_t)
cristy0534a6b2010-03-18 01:19:38 +00002961 ceil(geometry_info.psi-0.5),exception);
cristy3ed852e2009-09-05 21:47:34 +00002962 if (shadow_image == (Image *) NULL)
2963 break;
2964 *image=DestroyImage(*image);
2965 *image=shadow_image;
2966 break;
2967 }
2968 if (LocaleCompare("sharpen",option+1) == 0)
2969 {
2970 Image
2971 *sharp_image;
2972
2973 /*
2974 Sharpen image.
2975 */
cristy6b3da3a2010-06-20 02:21:46 +00002976 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002977 flags=ParseGeometry(argv[i+1],&geometry_info);
2978 if ((flags & SigmaValue) == 0)
2979 geometry_info.sigma=1.0;
2980 sharp_image=SharpenImageChannel(*image,channel,geometry_info.rho,
2981 geometry_info.sigma,exception);
2982 if (sharp_image == (Image *) NULL)
2983 break;
2984 *image=DestroyImage(*image);
2985 *image=sharp_image;
2986 break;
2987 }
2988 if (LocaleCompare("shave",option+1) == 0)
2989 {
2990 Image
2991 *shave_image;
2992
2993 /*
2994 Shave the image edges.
2995 */
cristy6b3da3a2010-06-20 02:21:46 +00002996 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002997 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2998 shave_image=ShaveImage(*image,&geometry,exception);
2999 if (shave_image == (Image *) NULL)
3000 break;
3001 *image=DestroyImage(*image);
3002 *image=shave_image;
3003 break;
3004 }
3005 if (LocaleCompare("shear",option+1) == 0)
3006 {
3007 Image
3008 *shear_image;
3009
3010 /*
3011 Shear image.
3012 */
cristy6b3da3a2010-06-20 02:21:46 +00003013 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003014 flags=ParseGeometry(argv[i+1],&geometry_info);
3015 if ((flags & SigmaValue) == 0)
3016 geometry_info.sigma=geometry_info.rho;
3017 shear_image=ShearImage(*image,geometry_info.rho,geometry_info.sigma,
3018 exception);
3019 if (shear_image == (Image *) NULL)
3020 break;
3021 *image=DestroyImage(*image);
3022 *image=shear_image;
3023 break;
3024 }
3025 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
3026 {
3027 /*
3028 Sigmoidal non-linearity contrast control.
3029 */
cristy6b3da3a2010-06-20 02:21:46 +00003030 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003031 flags=ParseGeometry(argv[i+1],&geometry_info);
3032 if ((flags & SigmaValue) == 0)
3033 geometry_info.sigma=(double) QuantumRange/2.0;
3034 if ((flags & PercentValue) != 0)
3035 geometry_info.sigma=(double) QuantumRange*geometry_info.sigma/
3036 100.0;
3037 (void) SigmoidalContrastImageChannel(*image,channel,
3038 (*option == '-') ? MagickTrue : MagickFalse,geometry_info.rho,
3039 geometry_info.sigma);
3040 InheritException(exception,&(*image)->exception);
3041 break;
3042 }
3043 if (LocaleCompare("sketch",option+1) == 0)
3044 {
3045 Image
3046 *sketch_image;
3047
3048 /*
3049 Sketch image.
3050 */
cristy6b3da3a2010-06-20 02:21:46 +00003051 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003052 flags=ParseGeometry(argv[i+1],&geometry_info);
3053 if ((flags & SigmaValue) == 0)
3054 geometry_info.sigma=1.0;
3055 sketch_image=SketchImage(*image,geometry_info.rho,
3056 geometry_info.sigma,geometry_info.xi,exception);
3057 if (sketch_image == (Image *) NULL)
3058 break;
3059 *image=DestroyImage(*image);
3060 *image=sketch_image;
3061 break;
3062 }
3063 if (LocaleCompare("solarize",option+1) == 0)
3064 {
3065 double
3066 threshold;
3067
cristy6b3da3a2010-06-20 02:21:46 +00003068 (void) SyncImageSettings(mogrify_info,*image);
cristyf2f27272009-12-17 14:48:46 +00003069 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
cristy3ed852e2009-09-05 21:47:34 +00003070 (void) SolarizeImage(*image,threshold);
3071 InheritException(exception,&(*image)->exception);
3072 break;
3073 }
3074 if (LocaleCompare("sparse-color",option+1) == 0)
3075 {
3076 Image
3077 *sparse_image;
3078
3079 SparseColorMethod
3080 method;
3081
3082 char
3083 *arguments;
3084
3085 /*
3086 Sparse Color Interpolated Gradient
3087 */
cristy6b3da3a2010-06-20 02:21:46 +00003088 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003089 method=(SparseColorMethod) ParseMagickOption(
3090 MagickSparseColorOptions,MagickFalse,argv[i+1]);
cristy6b3da3a2010-06-20 02:21:46 +00003091 arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
cristy3ed852e2009-09-05 21:47:34 +00003092 InheritException(exception,&(*image)->exception);
3093 if (arguments == (char *) NULL)
3094 break;
3095 sparse_image=SparseColorOption(*image,channel,method,arguments,
3096 option[0] == '+' ? MagickTrue : MagickFalse,exception);
3097 arguments=DestroyString(arguments);
3098 if (sparse_image == (Image *) NULL)
3099 break;
3100 *image=DestroyImage(*image);
3101 *image=sparse_image;
3102 break;
3103 }
3104 if (LocaleCompare("splice",option+1) == 0)
3105 {
3106 Image
3107 *splice_image;
3108
3109 /*
3110 Splice a solid color into the image.
3111 */
cristy6b3da3a2010-06-20 02:21:46 +00003112 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003113 (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
3114 splice_image=SpliceImage(*image,&geometry,exception);
3115 if (splice_image == (Image *) NULL)
3116 break;
3117 *image=DestroyImage(*image);
3118 *image=splice_image;
3119 break;
3120 }
3121 if (LocaleCompare("spread",option+1) == 0)
3122 {
3123 Image
3124 *spread_image;
3125
3126 /*
3127 Spread an image.
3128 */
cristy6b3da3a2010-06-20 02:21:46 +00003129 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003130 (void) ParseGeometry(argv[i+1],&geometry_info);
3131 spread_image=SpreadImage(*image,geometry_info.rho,exception);
3132 if (spread_image == (Image *) NULL)
3133 break;
3134 *image=DestroyImage(*image);
3135 *image=spread_image;
3136 break;
3137 }
3138 if (LocaleCompare("stretch",option+1) == 0)
3139 {
3140 if (*option == '+')
3141 {
3142 draw_info->stretch=UndefinedStretch;
3143 break;
3144 }
3145 draw_info->stretch=(StretchType) ParseMagickOption(
3146 MagickStretchOptions,MagickFalse,argv[i+1]);
3147 break;
3148 }
3149 if (LocaleCompare("strip",option+1) == 0)
3150 {
3151 /*
3152 Strip image of profiles and comments.
3153 */
cristy6b3da3a2010-06-20 02:21:46 +00003154 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003155 (void) StripImage(*image);
3156 InheritException(exception,&(*image)->exception);
3157 break;
3158 }
3159 if (LocaleCompare("stroke",option+1) == 0)
3160 {
3161 ExceptionInfo
3162 *sans;
3163
3164 if (*option == '+')
3165 {
3166 (void) QueryColorDatabase("none",&draw_info->stroke,exception);
3167 if (draw_info->stroke_pattern != (Image *) NULL)
3168 draw_info->stroke_pattern=DestroyImage(
3169 draw_info->stroke_pattern);
3170 break;
3171 }
3172 sans=AcquireExceptionInfo();
3173 status=QueryColorDatabase(argv[i+1],&draw_info->stroke,sans);
3174 sans=DestroyExceptionInfo(sans);
3175 if (status == MagickFalse)
cristy6b3da3a2010-06-20 02:21:46 +00003176 draw_info->stroke_pattern=GetImageCache(mogrify_info,argv[i+1],
cristy3ed852e2009-09-05 21:47:34 +00003177 exception);
3178 break;
3179 }
3180 if (LocaleCompare("strokewidth",option+1) == 0)
3181 {
cristyf2f27272009-12-17 14:48:46 +00003182 draw_info->stroke_width=StringToDouble(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00003183 break;
3184 }
3185 if (LocaleCompare("style",option+1) == 0)
3186 {
3187 if (*option == '+')
3188 {
3189 draw_info->style=UndefinedStyle;
3190 break;
3191 }
3192 draw_info->style=(StyleType) ParseMagickOption(MagickStyleOptions,
3193 MagickFalse,argv[i+1]);
3194 break;
3195 }
3196 if (LocaleCompare("swirl",option+1) == 0)
3197 {
3198 Image
3199 *swirl_image;
3200
3201 /*
3202 Swirl image.
3203 */
cristy6b3da3a2010-06-20 02:21:46 +00003204 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003205 (void) ParseGeometry(argv[i+1],&geometry_info);
3206 swirl_image=SwirlImage(*image,geometry_info.rho,exception);
3207 if (swirl_image == (Image *) NULL)
3208 break;
3209 *image=DestroyImage(*image);
3210 *image=swirl_image;
3211 break;
3212 }
3213 break;
3214 }
3215 case 't':
3216 {
3217 if (LocaleCompare("threshold",option+1) == 0)
3218 {
3219 double
3220 threshold;
3221
3222 /*
3223 Threshold image.
3224 */
cristy6b3da3a2010-06-20 02:21:46 +00003225 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003226 if (*option == '+')
3227 threshold=(double) QuantumRange/2.5;
3228 else
cristyf2f27272009-12-17 14:48:46 +00003229 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
cristy3ed852e2009-09-05 21:47:34 +00003230 (void) BilevelImageChannel(*image,channel,threshold);
3231 InheritException(exception,&(*image)->exception);
3232 break;
3233 }
3234 if (LocaleCompare("thumbnail",option+1) == 0)
3235 {
3236 Image
3237 *thumbnail_image;
3238
3239 /*
3240 Thumbnail image.
3241 */
cristy6b3da3a2010-06-20 02:21:46 +00003242 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003243 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
3244 thumbnail_image=ThumbnailImage(*image,geometry.width,
3245 geometry.height,exception);
3246 if (thumbnail_image == (Image *) NULL)
3247 break;
3248 *image=DestroyImage(*image);
3249 *image=thumbnail_image;
3250 break;
3251 }
3252 if (LocaleCompare("tile",option+1) == 0)
3253 {
3254 if (*option == '+')
3255 {
3256 if (draw_info->fill_pattern != (Image *) NULL)
3257 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
3258 break;
3259 }
cristy6b3da3a2010-06-20 02:21:46 +00003260 draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1],
cristy3ed852e2009-09-05 21:47:34 +00003261 exception);
3262 break;
3263 }
3264 if (LocaleCompare("tint",option+1) == 0)
3265 {
3266 Image
3267 *tint_image;
3268
3269 /*
3270 Tint the image.
3271 */
cristy6b3da3a2010-06-20 02:21:46 +00003272 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003273 tint_image=TintImage(*image,argv[i+1],draw_info->fill,exception);
3274 if (tint_image == (Image *) NULL)
3275 break;
3276 *image=DestroyImage(*image);
3277 *image=tint_image;
3278 break;
3279 }
3280 if (LocaleCompare("transform",option+1) == 0)
3281 {
3282 Image
3283 *transform_image;
3284
3285 /*
3286 Affine transform image.
3287 */
cristy6b3da3a2010-06-20 02:21:46 +00003288 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003289 transform_image=AffineTransformImage(*image,&draw_info->affine,
3290 exception);
3291 if (transform_image == (Image *) NULL)
3292 break;
3293 *image=DestroyImage(*image);
3294 *image=transform_image;
3295 break;
3296 }
3297 if (LocaleCompare("transparent",option+1) == 0)
3298 {
3299 MagickPixelPacket
3300 target;
3301
cristy6b3da3a2010-06-20 02:21:46 +00003302 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003303 (void) QueryMagickColor(argv[i+1],&target,exception);
3304 (void) TransparentPaintImage(*image,&target,(Quantum)
3305 TransparentOpacity,*option == '-' ? MagickFalse : MagickTrue);
3306 InheritException(exception,&(*image)->exception);
3307 break;
3308 }
3309 if (LocaleCompare("transpose",option+1) == 0)
3310 {
3311 Image
3312 *transpose_image;
3313
3314 /*
3315 Transpose image scanlines.
3316 */
cristy6b3da3a2010-06-20 02:21:46 +00003317 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003318 transpose_image=TransposeImage(*image,exception);
3319 if (transpose_image == (Image *) NULL)
3320 break;
3321 *image=DestroyImage(*image);
3322 *image=transpose_image;
3323 break;
3324 }
3325 if (LocaleCompare("transverse",option+1) == 0)
3326 {
3327 Image
3328 *transverse_image;
3329
3330 /*
3331 Transverse image scanlines.
3332 */
cristy6b3da3a2010-06-20 02:21:46 +00003333 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003334 transverse_image=TransverseImage(*image,exception);
3335 if (transverse_image == (Image *) NULL)
3336 break;
3337 *image=DestroyImage(*image);
3338 *image=transverse_image;
3339 break;
3340 }
3341 if (LocaleCompare("treedepth",option+1) == 0)
3342 {
cristye27293e2009-12-18 02:53:20 +00003343 quantize_info->tree_depth=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00003344 break;
3345 }
3346 if (LocaleCompare("trim",option+1) == 0)
3347 {
3348 Image
3349 *trim_image;
3350
3351 /*
3352 Trim image.
3353 */
cristy6b3da3a2010-06-20 02:21:46 +00003354 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003355 trim_image=TrimImage(*image,exception);
3356 if (trim_image == (Image *) NULL)
3357 break;
3358 *image=DestroyImage(*image);
3359 *image=trim_image;
3360 break;
3361 }
3362 if (LocaleCompare("type",option+1) == 0)
3363 {
3364 ImageType
3365 type;
3366
cristy6b3da3a2010-06-20 02:21:46 +00003367 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003368 if (*option == '+')
3369 type=UndefinedType;
3370 else
3371 type=(ImageType) ParseMagickOption(MagickTypeOptions,MagickFalse,
3372 argv[i+1]);
3373 (*image)->type=UndefinedType;
3374 (void) SetImageType(*image,type);
3375 InheritException(exception,&(*image)->exception);
3376 break;
3377 }
3378 break;
3379 }
3380 case 'u':
3381 {
3382 if (LocaleCompare("undercolor",option+1) == 0)
3383 {
3384 (void) QueryColorDatabase(argv[i+1],&draw_info->undercolor,
3385 exception);
3386 break;
3387 }
cristy045bd902010-01-30 18:56:24 +00003388 if (LocaleCompare("unique",option+1) == 0)
3389 {
3390 if (*option == '+')
3391 {
cristy83fae872010-04-22 15:04:16 +00003392 (void) DeleteImageArtifact(*image,"identify:unique-colors");
cristy045bd902010-01-30 18:56:24 +00003393 break;
3394 }
cristy83fae872010-04-22 15:04:16 +00003395 (void) SetImageArtifact(*image,"identify:unique-colors","true");
cristy7e6164a2010-07-22 20:43:57 +00003396 (void) SetImageArtifact(*image,"identify:verbose","true");
cristy045bd902010-01-30 18:56:24 +00003397 break;
3398 }
cristy3ed852e2009-09-05 21:47:34 +00003399 if (LocaleCompare("unique-colors",option+1) == 0)
3400 {
3401 Image
3402 *unique_image;
3403
3404 /*
3405 Unique image colors.
3406 */
cristy6b3da3a2010-06-20 02:21:46 +00003407 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003408 unique_image=UniqueImageColors(*image,exception);
3409 if (unique_image == (Image *) NULL)
3410 break;
3411 *image=DestroyImage(*image);
3412 *image=unique_image;
3413 break;
3414 }
3415 if (LocaleCompare("unsharp",option+1) == 0)
3416 {
3417 Image
3418 *unsharp_image;
3419
3420 /*
3421 Unsharp mask image.
3422 */
cristy6b3da3a2010-06-20 02:21:46 +00003423 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003424 flags=ParseGeometry(argv[i+1],&geometry_info);
3425 if ((flags & SigmaValue) == 0)
3426 geometry_info.sigma=1.0;
3427 if ((flags & XiValue) == 0)
3428 geometry_info.xi=1.0;
3429 if ((flags & PsiValue) == 0)
3430 geometry_info.psi=0.05;
3431 unsharp_image=UnsharpMaskImageChannel(*image,channel,
3432 geometry_info.rho,geometry_info.sigma,geometry_info.xi,
3433 geometry_info.psi,exception);
3434 if (unsharp_image == (Image *) NULL)
3435 break;
3436 *image=DestroyImage(*image);
3437 *image=unsharp_image;
3438 break;
3439 }
3440 break;
3441 }
3442 case 'v':
3443 {
3444 if (LocaleCompare("verbose",option+1) == 0)
3445 {
3446 (void) SetImageArtifact(*image,option+1,
3447 *option == '+' ? "false" : "true");
3448 break;
3449 }
3450 if (LocaleCompare("vignette",option+1) == 0)
3451 {
3452 Image
3453 *vignette_image;
3454
3455 /*
3456 Vignette image.
3457 */
cristy6b3da3a2010-06-20 02:21:46 +00003458 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003459 flags=ParseGeometry(argv[i+1],&geometry_info);
3460 if ((flags & SigmaValue) == 0)
3461 geometry_info.sigma=1.0;
3462 if ((flags & XiValue) == 0)
3463 geometry_info.xi=0.1*(*image)->columns;
3464 if ((flags & PsiValue) == 0)
3465 geometry_info.psi=0.1*(*image)->rows;
3466 vignette_image=VignetteImage(*image,geometry_info.rho,
cristybb503372010-05-27 20:51:26 +00003467 geometry_info.sigma,(ssize_t) ceil(geometry_info.xi-0.5),(ssize_t)
cristy0534a6b2010-03-18 01:19:38 +00003468 ceil(geometry_info.psi-0.5),exception);
cristy3ed852e2009-09-05 21:47:34 +00003469 if (vignette_image == (Image *) NULL)
3470 break;
3471 *image=DestroyImage(*image);
3472 *image=vignette_image;
3473 break;
3474 }
3475 if (LocaleCompare("virtual-pixel",option+1) == 0)
3476 {
3477 if (*option == '+')
3478 {
3479 (void) SetImageVirtualPixelMethod(*image,
3480 UndefinedVirtualPixelMethod);
3481 break;
3482 }
3483 (void) SetImageVirtualPixelMethod(*image,(VirtualPixelMethod)
3484 ParseMagickOption(MagickVirtualPixelOptions,MagickFalse,
3485 argv[i+1]));
3486 break;
3487 }
3488 break;
3489 }
3490 case 'w':
3491 {
3492 if (LocaleCompare("wave",option+1) == 0)
3493 {
3494 Image
3495 *wave_image;
3496
3497 /*
3498 Wave image.
3499 */
cristy6b3da3a2010-06-20 02:21:46 +00003500 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003501 flags=ParseGeometry(argv[i+1],&geometry_info);
3502 if ((flags & SigmaValue) == 0)
3503 geometry_info.sigma=1.0;
3504 wave_image=WaveImage(*image,geometry_info.rho,geometry_info.sigma,
3505 exception);
3506 if (wave_image == (Image *) NULL)
3507 break;
3508 *image=DestroyImage(*image);
3509 *image=wave_image;
3510 break;
3511 }
3512 if (LocaleCompare("weight",option+1) == 0)
3513 {
cristye27293e2009-12-18 02:53:20 +00003514 draw_info->weight=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00003515 if (LocaleCompare(argv[i+1],"all") == 0)
3516 draw_info->weight=0;
3517 if (LocaleCompare(argv[i+1],"bold") == 0)
3518 draw_info->weight=700;
3519 if (LocaleCompare(argv[i+1],"bolder") == 0)
3520 if (draw_info->weight <= 800)
3521 draw_info->weight+=100;
3522 if (LocaleCompare(argv[i+1],"lighter") == 0)
3523 if (draw_info->weight >= 100)
3524 draw_info->weight-=100;
3525 if (LocaleCompare(argv[i+1],"normal") == 0)
3526 draw_info->weight=400;
3527 break;
3528 }
3529 if (LocaleCompare("white-threshold",option+1) == 0)
3530 {
3531 /*
3532 White threshold image.
3533 */
cristy6b3da3a2010-06-20 02:21:46 +00003534 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003535 (void) WhiteThresholdImageChannel(*image,channel,argv[i+1],
3536 exception);
3537 InheritException(exception,&(*image)->exception);
3538 break;
3539 }
3540 break;
3541 }
3542 default:
3543 break;
3544 }
3545 i+=count;
3546 }
3547 if (region_image != (Image *) NULL)
3548 {
3549 /*
3550 Composite transformed region onto image.
3551 */
cristy6b3da3a2010-06-20 02:21:46 +00003552 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003553 (void) CompositeImage(region_image,(*image)->matte != MagickFalse ?
3554 OverCompositeOp : CopyCompositeOp,*image,region_geometry.x,
3555 region_geometry.y);
3556 InheritException(exception,&region_image->exception);
3557 *image=DestroyImage(*image);
3558 *image=region_image;
3559 }
3560 /*
3561 Free resources.
3562 */
3563 quantize_info=DestroyQuantizeInfo(quantize_info);
3564 draw_info=DestroyDrawInfo(draw_info);
cristy6b3da3a2010-06-20 02:21:46 +00003565 mogrify_info=DestroyImageInfo(mogrify_info);
3566 status=(*image)->exception.severity == UndefinedException ? MagickTrue :
3567 MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00003568 return(status);
3569}
3570
3571/*
3572%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3573% %
3574% %
3575% %
3576% M o g r i f y I m a g e C o m m a n d %
3577% %
3578% %
3579% %
3580%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3581%
3582% MogrifyImageCommand() transforms an image or a sequence of images. These
3583% transforms include image scaling, image rotation, color reduction, and
3584% others. The transmogrified image overwrites the original image.
3585%
3586% The format of the MogrifyImageCommand method is:
3587%
3588% MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,int argc,
3589% const char **argv,char **metadata,ExceptionInfo *exception)
3590%
3591% A description of each parameter follows:
3592%
3593% o image_info: the image info.
3594%
3595% o argc: the number of elements in the argument vector.
3596%
3597% o argv: A text array containing the command line arguments.
3598%
3599% o metadata: any metadata is returned here.
3600%
3601% o exception: return any errors or warnings in this structure.
3602%
3603*/
3604
3605static MagickBooleanType MogrifyUsage(void)
3606{
3607 static const char
3608 *miscellaneous[]=
3609 {
3610 "-debug events display copious debugging information",
3611 "-help print program options",
3612 "-list type print a list of supported option arguments",
3613 "-log format format of debugging information",
3614 "-version print version information",
3615 (char *) NULL
3616 },
3617 *operators[]=
3618 {
3619 "-adaptive-blur geometry",
3620 " adaptively blur pixels; decrease effect near edges",
3621 "-adaptive-resize geometry",
3622 " adaptively resize image using 'mesh' interpolation",
3623 "-adaptive-sharpen geometry",
3624 " adaptively sharpen pixels; increase effect near edges",
3625 "-alpha option on, activate, off, deactivate, set, opaque, copy",
3626 " transparent, extract, background, or shape",
3627 "-annotate geometry text",
3628 " annotate the image with text",
3629 "-auto-gamma automagically adjust gamma level of image",
3630 "-auto-level automagically adjust color levels of image",
3631 "-auto-orient automagically orient (rotate) image",
3632 "-bench iterations measure performance",
3633 "-black-threshold value",
3634 " force all pixels below the threshold into black",
3635 "-blue-shift simulate a scene at nighttime in the moonlight",
3636 "-blur geometry reduce image noise and reduce detail levels",
3637 "-border geometry surround image with a border of color",
3638 "-bordercolor color border color",
cristya28d6b82010-01-11 20:03:47 +00003639 "-brightness-contrast geometry",
3640 " improve brightness / contrast of the image",
cristy3ed852e2009-09-05 21:47:34 +00003641 "-cdl filename color correct with a color decision list",
3642 "-charcoal radius simulate a charcoal drawing",
3643 "-chop geometry remove pixels from the image interior",
cristyecb0c6d2009-09-25 16:50:09 +00003644 "-clamp restrict pixel range from 0 to the quantum depth",
cristycee97112010-05-28 00:44:52 +00003645 "-clip clip along the first path from the 8BIM profile",
cristy3ed852e2009-09-05 21:47:34 +00003646 "-clip-mask filename associate a clip mask with the image",
cristycee97112010-05-28 00:44:52 +00003647 "-clip-path id clip along a named path from the 8BIM profile",
cristy3ed852e2009-09-05 21:47:34 +00003648 "-colorize value colorize the image with the fill color",
cristye6365592010-04-02 17:31:23 +00003649 "-color-matrix matrix apply color correction to the image",
cristy3ed852e2009-09-05 21:47:34 +00003650 "-contrast enhance or reduce the image contrast",
3651 "-contrast-stretch geometry",
3652 " improve contrast by `stretching' the intensity range",
3653 "-convolve coefficients",
3654 " apply a convolution kernel to the image",
3655 "-cycle amount cycle the image colormap",
3656 "-decipher filename convert cipher pixels to plain pixels",
3657 "-deskew threshold straighten an image",
3658 "-despeckle reduce the speckles within an image",
3659 "-distort method args",
3660 " distort images according to given method ad args",
3661 "-draw string annotate the image with a graphic primitive",
3662 "-edge radius apply a filter to detect edges in the image",
3663 "-encipher filename convert plain pixels to cipher pixels",
3664 "-emboss radius emboss an image",
3665 "-enhance apply a digital filter to enhance a noisy image",
3666 "-equalize perform histogram equalization to an image",
3667 "-evaluate operator value",
cristyd18ae7c2010-03-07 17:39:52 +00003668 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003669 "-extent geometry set the image size",
3670 "-extract geometry extract area from image",
3671 "-fft implements the discrete Fourier transform (DFT)",
3672 "-flip flip image vertically",
3673 "-floodfill geometry color",
3674 " floodfill the image with color",
3675 "-flop flop image horizontally",
3676 "-frame geometry surround image with an ornamental border",
cristyc2b730e2009-11-24 14:32:09 +00003677 "-function name parameters",
cristy3ed852e2009-09-05 21:47:34 +00003678 " apply function over image values",
3679 "-gamma value level of gamma correction",
3680 "-gaussian-blur geometry",
3681 " reduce image noise and reduce detail levels",
cristy901f09d2009-10-16 22:56:10 +00003682 "-geometry geometry preferred size or location of the image",
cristy3ed852e2009-09-05 21:47:34 +00003683 "-identify identify the format and characteristics of the image",
3684 "-ift implements the inverse discrete Fourier transform (DFT)",
3685 "-implode amount implode image pixels about the center",
3686 "-lat geometry local adaptive thresholding",
3687 "-layers method optimize, merge, or compare image layers",
3688 "-level value adjust the level of image contrast",
3689 "-level-colors color,color",
cristyee0f8d72009-09-19 00:58:29 +00003690 " level image with the given colors",
cristy3ed852e2009-09-05 21:47:34 +00003691 "-linear-stretch geometry",
3692 " improve contrast by `stretching with saturation'",
3693 "-liquid-rescale geometry",
3694 " rescale image with seam-carving",
3695 "-median radius apply a median filter to the image",
3696 "-modulate value vary the brightness, saturation, and hue",
3697 "-monochrome transform image to black and white",
cristy7c1b9fd2010-02-02 14:36:00 +00003698 "-morphology method kernel",
anthony29188a82010-01-22 10:12:34 +00003699 " apply a morphology method to the image",
cristy3ed852e2009-09-05 21:47:34 +00003700 "-motion-blur geometry",
3701 " simulate motion blur",
3702 "-negate replace every pixel with its complementary color ",
3703 "-noise radius add or reduce noise in an image",
3704 "-normalize transform image to span the full range of colors",
3705 "-opaque color change this color to the fill color",
3706 "-ordered-dither NxN",
3707 " add a noise pattern to the image with specific",
3708 " amplitudes",
3709 "-paint radius simulate an oil painting",
3710 "-polaroid angle simulate a Polaroid picture",
3711 "-posterize levels reduce the image to a limited number of color levels",
cristy3ed852e2009-09-05 21:47:34 +00003712 "-profile filename add, delete, or apply an image profile",
3713 "-quantize colorspace reduce colors in this colorspace",
3714 "-radial-blur angle radial blur the image",
3715 "-raise value lighten/darken image edges to create a 3-D effect",
3716 "-random-threshold low,high",
3717 " random threshold the image",
cristy3ed852e2009-09-05 21:47:34 +00003718 "-region geometry apply options to a portion of the image",
3719 "-render render vector graphics",
3720 "-repage geometry size and location of an image canvas",
3721 "-resample geometry change the resolution of an image",
3722 "-resize geometry resize the image",
3723 "-roll geometry roll an image vertically or horizontally",
3724 "-rotate degrees apply Paeth rotation to the image",
3725 "-sample geometry scale image with pixel sampling",
3726 "-scale geometry scale the image",
3727 "-segment values segment an image",
3728 "-selective-blur geometry",
3729 " selectively blur pixels within a contrast threshold",
3730 "-sepia-tone threshold",
3731 " simulate a sepia-toned photo",
3732 "-set property value set an image property",
3733 "-shade degrees shade the image using a distant light source",
3734 "-shadow geometry simulate an image shadow",
3735 "-sharpen geometry sharpen the image",
3736 "-shave geometry shave pixels from the image edges",
cristycee97112010-05-28 00:44:52 +00003737 "-shear geometry slide one edge of the image along the X or Y axis",
cristy3ed852e2009-09-05 21:47:34 +00003738 "-sigmoidal-contrast geometry",
3739 " increase the contrast without saturating highlights or shadows",
3740 "-sketch geometry simulate a pencil sketch",
3741 "-solarize threshold negate all pixels above the threshold level",
3742 "-sparse-color method args",
3743 " fill in a image based on a few color points",
3744 "-splice geometry splice the background color into the image",
3745 "-spread radius displace image pixels by a random amount",
3746 "-strip strip image of all profiles and comments",
3747 "-swirl degrees swirl image pixels about the center",
3748 "-threshold value threshold the image",
3749 "-thumbnail geometry create a thumbnail of the image",
3750 "-tile filename tile image when filling a graphic primitive",
3751 "-tint value tint the image with the fill color",
3752 "-transform affine transform image",
3753 "-transparent color make this color transparent within the image",
3754 "-transpose flip image vertically and rotate 90 degrees",
3755 "-transverse flop image horizontally and rotate 270 degrees",
3756 "-trim trim image edges",
3757 "-type type image type",
3758 "-unique-colors discard all but one of any pixel color",
3759 "-unsharp geometry sharpen the image",
3760 "-vignette geometry soften the edges of the image in vignette style",
cristycee97112010-05-28 00:44:52 +00003761 "-wave geometry alter an image along a sine wave",
cristy3ed852e2009-09-05 21:47:34 +00003762 "-white-threshold value",
3763 " force all pixels above the threshold into white",
3764 (char *) NULL
3765 },
3766 *sequence_operators[]=
3767 {
3768 "-append append an image sequence",
cristy3ed852e2009-09-05 21:47:34 +00003769 "-clut apply a color lookup table to the image",
3770 "-coalesce merge a sequence of images",
3771 "-combine combine a sequence of images",
3772 "-composite composite image",
3773 "-crop geometry cut out a rectangular region of the image",
3774 "-deconstruct break down an image sequence into constituent parts",
cristyd18ae7c2010-03-07 17:39:52 +00003775 "-evaluate-sequence operator",
3776 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003777 "-flatten flatten a sequence of images",
3778 "-fx expression apply mathematical expression to an image channel(s)",
3779 "-hald-clut apply a Hald color lookup table to the image",
3780 "-morph value morph an image sequence",
3781 "-mosaic create a mosaic from an image sequence",
cristy36b94822010-05-20 12:48:16 +00003782 "-print string interpret string and print to console",
cristy3ed852e2009-09-05 21:47:34 +00003783 "-process arguments process the image with a custom image filter",
3784 "-reverse reverse image sequence",
3785 "-separate separate an image channel into a grayscale image",
3786 "-write filename write images to this file",
3787 (char *) NULL
3788 },
3789 *settings[]=
3790 {
3791 "-adjoin join images into a single multi-image file",
3792 "-affine matrix affine transform matrix",
3793 "-alpha option activate, deactivate, reset, or set the alpha channel",
3794 "-antialias remove pixel-aliasing",
3795 "-authenticate password",
3796 " decipher image with this password",
3797 "-attenuate value lessen (or intensify) when adding noise to an image",
3798 "-background color background color",
3799 "-bias value add bias when convolving an image",
3800 "-black-point-compensation",
3801 " use black point compensation",
3802 "-blue-primary point chromaticity blue primary point",
3803 "-bordercolor color border color",
3804 "-caption string assign a caption to an image",
3805 "-channel type apply option to select image channels",
3806 "-colors value preferred number of colors in the image",
3807 "-colorspace type alternate image colorspace",
3808 "-comment string annotate image with comment",
3809 "-compose operator set image composite operator",
3810 "-compress type type of pixel compression when writing the image",
3811 "-define format:option",
3812 " define one or more image format options",
3813 "-delay value display the next image after pausing",
3814 "-density geometry horizontal and vertical density of the image",
3815 "-depth value image depth",
cristyc9b12952010-03-28 01:12:28 +00003816 "-direction type render text right-to-left or left-to-right",
cristy3ed852e2009-09-05 21:47:34 +00003817 "-display server get image or font from this X server",
3818 "-dispose method layer disposal method",
3819 "-dither method apply error diffusion to image",
3820 "-encoding type text encoding type",
3821 "-endian type endianness (MSB or LSB) of the image",
3822 "-family name render text with this font family",
3823 "-fill color color to use when filling a graphic primitive",
3824 "-filter type use this filter when resizing an image",
3825 "-font name render text with this font",
3826 "-format \"string\" output formatted image characteristics",
3827 "-fuzz distance colors within this distance are considered equal",
3828 "-gravity type horizontal and vertical text placement",
3829 "-green-primary point chromaticity green primary point",
3830 "-intent type type of rendering intent when managing the image color",
3831 "-interlace type type of image interlacing scheme",
cristyb32b90a2009-09-07 21:45:48 +00003832 "-interline-spacing value",
3833 " set the space between two text lines",
cristy3ed852e2009-09-05 21:47:34 +00003834 "-interpolate method pixel color interpolation method",
3835 "-interword-spacing value",
3836 " set the space between two words",
3837 "-kerning value set the space between two letters",
3838 "-label string assign a label to an image",
3839 "-limit type value pixel cache resource limit",
3840 "-loop iterations add Netscape loop extension to your GIF animation",
3841 "-mask filename associate a mask with the image",
3842 "-mattecolor color frame color",
3843 "-monitor monitor progress",
3844 "-orient type image orientation",
3845 "-page geometry size and location of an image canvas (setting)",
3846 "-ping efficiently determine image attributes",
3847 "-pointsize value font point size",
cristy7c1b9fd2010-02-02 14:36:00 +00003848 "-precision value maximum number of significant digits to print",
cristy3ed852e2009-09-05 21:47:34 +00003849 "-preview type image preview type",
3850 "-quality value JPEG/MIFF/PNG compression level",
3851 "-quiet suppress all warning messages",
3852 "-red-primary point chromaticity red primary point",
3853 "-regard-warnings pay attention to warning messages",
3854 "-remap filename transform image colors to match this set of colors",
3855 "-respect-parentheses settings remain in effect until parenthesis boundary",
3856 "-sampling-factor geometry",
3857 " horizontal and vertical sampling factor",
3858 "-scene value image scene number",
3859 "-seed value seed a new sequence of pseudo-random numbers",
3860 "-size geometry width and height of image",
3861 "-stretch type render text with this font stretch",
3862 "-stroke color graphic primitive stroke color",
3863 "-strokewidth value graphic primitive stroke width",
3864 "-style type render text with this font style",
3865 "-taint image as ineligible for bi-modal delegate",
3866 "-texture filename name of texture to tile onto the image background",
3867 "-tile-offset geometry",
3868 " tile offset",
3869 "-treedepth value color tree depth",
3870 "-transparent-color color",
3871 " transparent color",
3872 "-undercolor color annotation bounding box color",
3873 "-units type the units of image resolution",
3874 "-verbose print detailed information about the image",
3875 "-view FlashPix viewing transforms",
3876 "-virtual-pixel method",
3877 " virtual pixel access method",
3878 "-weight type render text with this font weight",
3879 "-white-point point chromaticity white point",
3880 (char *) NULL
3881 },
3882 *stack_operators[]=
3883 {
3884 "-clone index clone an image",
3885 "-delete index delete the image from the image sequence",
3886 "-insert index insert last image into the image sequence",
3887 "-swap indexes swap two images in the image sequence",
3888 (char *) NULL
3889 };
3890
3891 const char
3892 **p;
3893
cristybb503372010-05-27 20:51:26 +00003894 (void) printf("Version: %s\n",GetMagickVersion((size_t *) NULL));
cristy610b2e22009-10-22 14:59:43 +00003895 (void) printf("Copyright: %s\n",GetMagickCopyright());
3896 (void) printf("Features: %s\n\n",GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00003897 (void) printf("Usage: %s [options ...] file [ [options ...] file ...]\n",
3898 GetClientName());
3899 (void) printf("\nImage Settings:\n");
3900 for (p=settings; *p != (char *) NULL; p++)
3901 (void) printf(" %s\n",*p);
3902 (void) printf("\nImage Operators:\n");
3903 for (p=operators; *p != (char *) NULL; p++)
3904 (void) printf(" %s\n",*p);
3905 (void) printf("\nImage Sequence Operators:\n");
3906 for (p=sequence_operators; *p != (char *) NULL; p++)
3907 (void) printf(" %s\n",*p);
3908 (void) printf("\nImage Stack Operators:\n");
3909 for (p=stack_operators; *p != (char *) NULL; p++)
3910 (void) printf(" %s\n",*p);
3911 (void) printf("\nMiscellaneous Options:\n");
3912 for (p=miscellaneous; *p != (char *) NULL; p++)
3913 (void) printf(" %s\n",*p);
3914 (void) printf(
3915 "\nBy default, the image format of `file' is determined by its magic\n");
3916 (void) printf(
3917 "number. To specify a particular image format, precede the filename\n");
3918 (void) printf(
3919 "with an image format name and a colon (i.e. ps:image) or specify the\n");
3920 (void) printf(
3921 "image type as the filename suffix (i.e. image.ps). Specify 'file' as\n");
3922 (void) printf("'-' for standard input or output.\n");
3923 return(MagickFalse);
3924}
3925
3926WandExport MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,
3927 int argc,char **argv,char **wand_unused(metadata),ExceptionInfo *exception)
3928{
3929#define DestroyMogrify() \
3930{ \
3931 if (format != (char *) NULL) \
3932 format=DestroyString(format); \
3933 if (path != (char *) NULL) \
3934 path=DestroyString(path); \
3935 DestroyImageStack(); \
cristybb503372010-05-27 20:51:26 +00003936 for (i=0; i < (ssize_t) argc; i++) \
cristy3ed852e2009-09-05 21:47:34 +00003937 argv[i]=DestroyString(argv[i]); \
3938 argv=(char **) RelinquishMagickMemory(argv); \
3939}
3940#define ThrowMogrifyException(asperity,tag,option) \
3941{ \
3942 (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag,"`%s'", \
3943 option); \
3944 DestroyMogrify(); \
3945 return(MagickFalse); \
3946}
3947#define ThrowMogrifyInvalidArgumentException(option,argument) \
3948{ \
3949 (void) ThrowMagickException(exception,GetMagickModule(),OptionError, \
3950 "InvalidArgument","`%s': %s",argument,option); \
3951 DestroyMogrify(); \
3952 return(MagickFalse); \
3953}
3954
3955 char
3956 *format,
3957 *option,
3958 *path;
3959
3960 Image
3961 *image;
3962
3963 ImageStack
3964 image_stack[MaxImageStackDepth+1];
3965
cristybb503372010-05-27 20:51:26 +00003966 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003967 j,
3968 k;
3969
cristybb503372010-05-27 20:51:26 +00003970 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003971 i;
3972
3973 MagickBooleanType
3974 global_colormap;
3975
3976 MagickBooleanType
3977 fire,
3978 pend;
3979
3980 MagickStatusType
3981 status;
3982
3983 /*
3984 Set defaults.
3985 */
3986 assert(image_info != (ImageInfo *) NULL);
3987 assert(image_info->signature == MagickSignature);
3988 if (image_info->debug != MagickFalse)
3989 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3990 assert(exception != (ExceptionInfo *) NULL);
3991 if (argc == 2)
3992 {
3993 option=argv[1];
3994 if ((LocaleCompare("version",option+1) == 0) ||
3995 (LocaleCompare("-version",option+1) == 0))
3996 {
3997 (void) fprintf(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +00003998 GetMagickVersion((size_t *) NULL));
cristy610b2e22009-10-22 14:59:43 +00003999 (void) fprintf(stdout,"Copyright: %s\n",GetMagickCopyright());
4000 (void) fprintf(stdout,"Features: %s\n\n",GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00004001 return(MagickFalse);
4002 }
4003 }
4004 if (argc < 2)
cristy13e61a12010-02-04 20:19:00 +00004005 return(MogrifyUsage());
cristy3ed852e2009-09-05 21:47:34 +00004006 format=(char *) NULL;
4007 path=(char *) NULL;
4008 global_colormap=MagickFalse;
4009 k=0;
4010 j=1;
4011 NewImageStack();
4012 option=(char *) NULL;
4013 pend=MagickFalse;
4014 status=MagickTrue;
4015 /*
4016 Parse command line.
4017 */
4018 ReadCommandlLine(argc,&argv);
4019 status=ExpandFilenames(&argc,&argv);
4020 if (status == MagickFalse)
4021 ThrowMogrifyException(ResourceLimitError,"MemoryAllocationFailed",
4022 GetExceptionMessage(errno));
cristybb503372010-05-27 20:51:26 +00004023 for (i=1; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00004024 {
4025 option=argv[i];
4026 if (LocaleCompare(option,"(") == 0)
4027 {
4028 FireImageStack(MagickFalse,MagickTrue,pend);
4029 if (k == MaxImageStackDepth)
4030 ThrowMogrifyException(OptionError,"ParenthesisNestedTooDeeply",
4031 option);
4032 PushImageStack();
4033 continue;
4034 }
4035 if (LocaleCompare(option,")") == 0)
4036 {
4037 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
4038 if (k == 0)
4039 ThrowMogrifyException(OptionError,"UnableToParseExpression",option);
4040 PopImageStack();
4041 continue;
4042 }
4043 if (IsMagickOption(option) == MagickFalse)
4044 {
4045 char
4046 backup_filename[MaxTextExtent],
4047 *filename;
4048
4049 Image
4050 *images;
4051
4052 /*
4053 Option is a file name: begin by reading image from specified file.
4054 */
4055 FireImageStack(MagickFalse,MagickFalse,pend);
4056 filename=argv[i];
cristycee97112010-05-28 00:44:52 +00004057 if ((LocaleCompare(filename,"--") == 0) && (i < (ssize_t) (argc-1)))
cristy3ed852e2009-09-05 21:47:34 +00004058 filename=argv[++i];
4059 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
4060 images=ReadImages(image_info,exception);
4061 status&=(images != (Image *) NULL) &&
4062 (exception->severity < ErrorException);
4063 if (images == (Image *) NULL)
4064 continue;
cristydaa76602010-06-30 13:05:11 +00004065 if (format != (char *) NULL)
4066 (void) CopyMagickString(images->filename,images->magick_filename,
4067 MaxTextExtent);
cristy3ed852e2009-09-05 21:47:34 +00004068 if (path != (char *) NULL)
4069 {
4070 GetPathComponent(option,TailPath,filename);
4071 (void) FormatMagickString(images->filename,MaxTextExtent,"%s%c%s",
4072 path,*DirectorySeparator,filename);
4073 }
4074 if (format != (char *) NULL)
cristydaa76602010-06-30 13:05:11 +00004075 AppendImageFormat(format,images->filename);
cristy3ed852e2009-09-05 21:47:34 +00004076 AppendImageStack(images);
4077 FinalizeImageSettings(image_info,image,MagickFalse);
4078 if (global_colormap != MagickFalse)
4079 {
4080 QuantizeInfo
4081 *quantize_info;
4082
4083 quantize_info=AcquireQuantizeInfo(image_info);
4084 (void) RemapImages(quantize_info,images,(Image *) NULL);
4085 quantize_info=DestroyQuantizeInfo(quantize_info);
4086 }
4087 *backup_filename='\0';
4088 if ((LocaleCompare(image->filename,"-") != 0) &&
4089 (IsPathWritable(image->filename) != MagickFalse))
4090 {
cristybb503372010-05-27 20:51:26 +00004091 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004092 i;
4093
4094 /*
4095 Rename image file as backup.
4096 */
4097 (void) CopyMagickString(backup_filename,image->filename,
4098 MaxTextExtent);
4099 for (i=0; i < 6; i++)
4100 {
4101 (void) ConcatenateMagickString(backup_filename,"~",MaxTextExtent);
4102 if (IsPathAccessible(backup_filename) == MagickFalse)
4103 break;
4104 }
4105 if ((IsPathAccessible(backup_filename) != MagickFalse) ||
4106 (rename(image->filename,backup_filename) != 0))
4107 *backup_filename='\0';
4108 }
4109 /*
4110 Write transmogrified image to disk.
4111 */
4112 image_info->synchronize=MagickTrue;
4113 status&=WriteImages(image_info,image,image->filename,exception);
4114 if ((status == MagickFalse) && (*backup_filename != '\0'))
4115 (void) remove(backup_filename);
4116 RemoveAllImageStack();
4117 continue;
4118 }
4119 pend=image != (Image *) NULL ? MagickTrue : MagickFalse;
4120 switch (*(option+1))
4121 {
4122 case 'a':
4123 {
4124 if (LocaleCompare("adaptive-blur",option+1) == 0)
4125 {
4126 i++;
cristybb503372010-05-27 20:51:26 +00004127 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004128 ThrowMogrifyException(OptionError,"MissingArgument",option);
4129 if (IsGeometry(argv[i]) == MagickFalse)
4130 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4131 break;
4132 }
4133 if (LocaleCompare("adaptive-resize",option+1) == 0)
4134 {
4135 i++;
cristybb503372010-05-27 20:51:26 +00004136 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004137 ThrowMogrifyException(OptionError,"MissingArgument",option);
4138 if (IsGeometry(argv[i]) == MagickFalse)
4139 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4140 break;
4141 }
4142 if (LocaleCompare("adaptive-sharpen",option+1) == 0)
4143 {
4144 i++;
cristybb503372010-05-27 20:51:26 +00004145 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004146 ThrowMogrifyException(OptionError,"MissingArgument",option);
4147 if (IsGeometry(argv[i]) == MagickFalse)
4148 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4149 break;
4150 }
4151 if (LocaleCompare("affine",option+1) == 0)
4152 {
4153 if (*option == '+')
4154 break;
4155 i++;
cristybb503372010-05-27 20:51:26 +00004156 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004157 ThrowMogrifyException(OptionError,"MissingArgument",option);
4158 if (IsGeometry(argv[i]) == MagickFalse)
4159 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4160 break;
4161 }
4162 if (LocaleCompare("alpha",option+1) == 0)
4163 {
cristybb503372010-05-27 20:51:26 +00004164 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004165 type;
4166
4167 if (*option == '+')
4168 break;
4169 i++;
cristybb503372010-05-27 20:51:26 +00004170 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004171 ThrowMogrifyException(OptionError,"MissingArgument",option);
4172 type=ParseMagickOption(MagickAlphaOptions,MagickFalse,argv[i]);
4173 if (type < 0)
4174 ThrowMogrifyException(OptionError,"UnrecognizedAlphaChannelType",
4175 argv[i]);
4176 break;
4177 }
4178 if (LocaleCompare("annotate",option+1) == 0)
4179 {
4180 if (*option == '+')
4181 break;
4182 i++;
cristybb503372010-05-27 20:51:26 +00004183 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004184 ThrowMogrifyException(OptionError,"MissingArgument",option);
4185 if (IsGeometry(argv[i]) == MagickFalse)
4186 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristybb503372010-05-27 20:51:26 +00004187 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004188 ThrowMogrifyException(OptionError,"MissingArgument",option);
4189 i++;
4190 break;
4191 }
4192 if (LocaleCompare("antialias",option+1) == 0)
4193 break;
4194 if (LocaleCompare("append",option+1) == 0)
4195 break;
4196 if (LocaleCompare("attenuate",option+1) == 0)
4197 {
4198 if (*option == '+')
4199 break;
4200 i++;
cristybb503372010-05-27 20:51:26 +00004201 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004202 ThrowMogrifyException(OptionError,"MissingArgument",option);
4203 if (IsGeometry(argv[i]) == MagickFalse)
4204 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4205 break;
4206 }
4207 if (LocaleCompare("authenticate",option+1) == 0)
4208 {
4209 if (*option == '+')
4210 break;
4211 i++;
cristybb503372010-05-27 20:51:26 +00004212 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004213 ThrowMogrifyException(OptionError,"MissingArgument",option);
4214 break;
4215 }
4216 if (LocaleCompare("auto-gamma",option+1) == 0)
4217 break;
4218 if (LocaleCompare("auto-level",option+1) == 0)
4219 break;
4220 if (LocaleCompare("auto-orient",option+1) == 0)
4221 break;
4222 if (LocaleCompare("average",option+1) == 0)
4223 break;
4224 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4225 }
4226 case 'b':
4227 {
4228 if (LocaleCompare("background",option+1) == 0)
4229 {
4230 if (*option == '+')
4231 break;
4232 i++;
cristybb503372010-05-27 20:51:26 +00004233 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004234 ThrowMogrifyException(OptionError,"MissingArgument",option);
4235 break;
4236 }
4237 if (LocaleCompare("bias",option+1) == 0)
4238 {
4239 if (*option == '+')
4240 break;
4241 i++;
cristybb503372010-05-27 20:51:26 +00004242 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004243 ThrowMogrifyException(OptionError,"MissingArgument",option);
4244 if (IsGeometry(argv[i]) == MagickFalse)
4245 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4246 break;
4247 }
4248 if (LocaleCompare("black-point-compensation",option+1) == 0)
4249 break;
4250 if (LocaleCompare("black-threshold",option+1) == 0)
4251 {
4252 if (*option == '+')
4253 break;
4254 i++;
cristybb503372010-05-27 20:51:26 +00004255 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004256 ThrowMogrifyException(OptionError,"MissingArgument",option);
4257 if (IsGeometry(argv[i]) == MagickFalse)
4258 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4259 break;
4260 }
4261 if (LocaleCompare("blue-primary",option+1) == 0)
4262 {
4263 if (*option == '+')
4264 break;
4265 i++;
cristybb503372010-05-27 20:51:26 +00004266 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004267 ThrowMogrifyException(OptionError,"MissingArgument",option);
4268 if (IsGeometry(argv[i]) == MagickFalse)
4269 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4270 break;
4271 }
4272 if (LocaleCompare("blue-shift",option+1) == 0)
4273 {
4274 i++;
cristybb503372010-05-27 20:51:26 +00004275 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004276 ThrowMogrifyException(OptionError,"MissingArgument",option);
4277 if (IsGeometry(argv[i]) == MagickFalse)
4278 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4279 break;
4280 }
4281 if (LocaleCompare("blur",option+1) == 0)
4282 {
4283 i++;
cristybb503372010-05-27 20:51:26 +00004284 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004285 ThrowMogrifyException(OptionError,"MissingArgument",option);
4286 if (IsGeometry(argv[i]) == MagickFalse)
4287 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4288 break;
4289 }
4290 if (LocaleCompare("border",option+1) == 0)
4291 {
4292 if (*option == '+')
4293 break;
4294 i++;
cristybb503372010-05-27 20:51:26 +00004295 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004296 ThrowMogrifyException(OptionError,"MissingArgument",option);
4297 if (IsGeometry(argv[i]) == MagickFalse)
4298 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4299 break;
4300 }
4301 if (LocaleCompare("bordercolor",option+1) == 0)
4302 {
4303 if (*option == '+')
4304 break;
4305 i++;
cristybb503372010-05-27 20:51:26 +00004306 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004307 ThrowMogrifyException(OptionError,"MissingArgument",option);
4308 break;
4309 }
4310 if (LocaleCompare("box",option+1) == 0)
4311 {
4312 if (*option == '+')
4313 break;
4314 i++;
cristybb503372010-05-27 20:51:26 +00004315 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004316 ThrowMogrifyException(OptionError,"MissingArgument",option);
4317 break;
4318 }
cristya28d6b82010-01-11 20:03:47 +00004319 if (LocaleCompare("brightness-contrast",option+1) == 0)
4320 {
4321 i++;
cristybb503372010-05-27 20:51:26 +00004322 if (i == (ssize_t) argc)
cristya28d6b82010-01-11 20:03:47 +00004323 ThrowMogrifyException(OptionError,"MissingArgument",option);
4324 if (IsGeometry(argv[i]) == MagickFalse)
4325 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4326 break;
4327 }
cristy3ed852e2009-09-05 21:47:34 +00004328 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4329 }
4330 case 'c':
4331 {
4332 if (LocaleCompare("cache",option+1) == 0)
4333 {
4334 if (*option == '+')
4335 break;
4336 i++;
cristybb503372010-05-27 20:51:26 +00004337 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004338 ThrowMogrifyException(OptionError,"MissingArgument",option);
4339 if (IsGeometry(argv[i]) == MagickFalse)
4340 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4341 break;
4342 }
4343 if (LocaleCompare("caption",option+1) == 0)
4344 {
4345 if (*option == '+')
4346 break;
4347 i++;
cristybb503372010-05-27 20:51:26 +00004348 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004349 ThrowMogrifyException(OptionError,"MissingArgument",option);
4350 break;
4351 }
4352 if (LocaleCompare("channel",option+1) == 0)
4353 {
cristybb503372010-05-27 20:51:26 +00004354 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004355 channel;
4356
4357 if (*option == '+')
4358 break;
4359 i++;
cristybb503372010-05-27 20:51:26 +00004360 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004361 ThrowMogrifyException(OptionError,"MissingArgument",option);
4362 channel=ParseChannelOption(argv[i]);
4363 if (channel < 0)
4364 ThrowMogrifyException(OptionError,"UnrecognizedChannelType",
4365 argv[i]);
4366 break;
4367 }
4368 if (LocaleCompare("cdl",option+1) == 0)
4369 {
4370 if (*option == '+')
4371 break;
4372 i++;
cristybb503372010-05-27 20:51:26 +00004373 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004374 ThrowMogrifyException(OptionError,"MissingArgument",option);
4375 break;
4376 }
4377 if (LocaleCompare("charcoal",option+1) == 0)
4378 {
4379 if (*option == '+')
4380 break;
4381 i++;
cristybb503372010-05-27 20:51:26 +00004382 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004383 ThrowMogrifyException(OptionError,"MissingArgument",option);
4384 if (IsGeometry(argv[i]) == MagickFalse)
4385 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4386 break;
4387 }
4388 if (LocaleCompare("chop",option+1) == 0)
4389 {
4390 if (*option == '+')
4391 break;
4392 i++;
cristybb503372010-05-27 20:51:26 +00004393 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004394 ThrowMogrifyException(OptionError,"MissingArgument",option);
4395 if (IsGeometry(argv[i]) == MagickFalse)
4396 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4397 break;
4398 }
cristy1eb45dd2009-09-25 16:38:06 +00004399 if (LocaleCompare("clamp",option+1) == 0)
4400 break;
4401 if (LocaleCompare("clip",option+1) == 0)
4402 break;
cristy3ed852e2009-09-05 21:47:34 +00004403 if (LocaleCompare("clip-mask",option+1) == 0)
4404 {
4405 if (*option == '+')
4406 break;
4407 i++;
cristybb503372010-05-27 20:51:26 +00004408 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004409 ThrowMogrifyException(OptionError,"MissingArgument",option);
4410 break;
4411 }
4412 if (LocaleCompare("clut",option+1) == 0)
4413 break;
4414 if (LocaleCompare("coalesce",option+1) == 0)
4415 break;
4416 if (LocaleCompare("colorize",option+1) == 0)
4417 {
4418 if (*option == '+')
4419 break;
4420 i++;
cristybb503372010-05-27 20:51:26 +00004421 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004422 ThrowMogrifyException(OptionError,"MissingArgument",option);
4423 if (IsGeometry(argv[i]) == MagickFalse)
4424 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4425 break;
4426 }
cristye6365592010-04-02 17:31:23 +00004427 if (LocaleCompare("color-matrix",option+1) == 0)
4428 {
4429 if (*option == '+')
4430 break;
4431 i++;
cristybb503372010-05-27 20:51:26 +00004432 if (i == (ssize_t) (argc-1))
cristye6365592010-04-02 17:31:23 +00004433 ThrowMogrifyException(OptionError,"MissingArgument",option);
4434 if (IsGeometry(argv[i]) == MagickFalse)
4435 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4436 break;
4437 }
cristy3ed852e2009-09-05 21:47:34 +00004438 if (LocaleCompare("colors",option+1) == 0)
4439 {
4440 if (*option == '+')
4441 break;
4442 i++;
cristybb503372010-05-27 20:51:26 +00004443 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004444 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 {
cristybb503372010-05-27 20:51:26 +00004451 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004452 colorspace;
4453
4454 if (*option == '+')
4455 break;
4456 i++;
cristybb503372010-05-27 20:51:26 +00004457 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004458 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++;
cristybb503372010-05-27 20:51:26 +00004473 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004474 ThrowMogrifyException(OptionError,"MissingArgument",option);
4475 break;
4476 }
4477 if (LocaleCompare("composite",option+1) == 0)
4478 break;
4479 if (LocaleCompare("compress",option+1) == 0)
4480 {
cristybb503372010-05-27 20:51:26 +00004481 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004482 compress;
4483
4484 if (*option == '+')
4485 break;
4486 i++;
cristybb503372010-05-27 20:51:26 +00004487 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004488 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++;
cristybb503372010-05-27 20:51:26 +00004503 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004504 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++;
cristybb503372010-05-27 20:51:26 +00004517 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004518 ThrowMogrifyException(OptionError,"MissingArgument",option);
anthony29188a82010-01-22 10:12:34 +00004519#if 1
cristydfbe6ca2010-03-12 14:08:17 +00004520 (void) token;
cristy3ed852e2009-09-05 21:47:34 +00004521 if (IsGeometry(argv[i]) == MagickFalse)
4522 ThrowMogrifyInvalidArgumentException(option,argv[i]);
anthony29188a82010-01-22 10:12:34 +00004523#else
4524 /* Allow the use of built-in kernels like 'gaussian'
4525 * These may not work for kernels with 'nan' values, like 'diamond'
4526 */
4527 GetMagickToken(argv[i],NULL,token);
4528 if ( isalpha((int)token[0]) )
4529 {
cristybb503372010-05-27 20:51:26 +00004530 ssize_t
anthony29188a82010-01-22 10:12:34 +00004531 op;
4532
4533 op=ParseMagickOption(MagickKernelOptions,MagickFalse,token);
4534 if (op < 0)
4535 ThrowMogrifyException(OptionError,"UnrecognizedKernelType",
4536 token);
4537 }
4538 /* geometry current returns invalid if 'nan' values are used */
4539 else if (IsGeometry(argv[i]) == MagickFalse)
4540 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4541#endif
cristy3ed852e2009-09-05 21:47:34 +00004542 break;
4543 }
4544 if (LocaleCompare("crop",option+1) == 0)
4545 {
4546 if (*option == '+')
4547 break;
4548 i++;
cristybb503372010-05-27 20:51:26 +00004549 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004550 ThrowMogrifyException(OptionError,"MissingArgument",option);
4551 if (IsGeometry(argv[i]) == MagickFalse)
4552 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4553 break;
4554 }
4555 if (LocaleCompare("cycle",option+1) == 0)
4556 {
4557 if (*option == '+')
4558 break;
4559 i++;
cristybb503372010-05-27 20:51:26 +00004560 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004561 ThrowMogrifyException(OptionError,"MissingArgument",option);
4562 if (IsGeometry(argv[i]) == MagickFalse)
4563 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4564 break;
4565 }
4566 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4567 }
4568 case 'd':
4569 {
4570 if (LocaleCompare("decipher",option+1) == 0)
4571 {
4572 if (*option == '+')
4573 break;
4574 i++;
cristybb503372010-05-27 20:51:26 +00004575 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004576 ThrowMogrifyException(OptionError,"MissingArgument",option);
4577 break;
4578 }
4579 if (LocaleCompare("deconstruct",option+1) == 0)
4580 break;
4581 if (LocaleCompare("debug",option+1) == 0)
4582 {
cristybb503372010-05-27 20:51:26 +00004583 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004584 event;
4585
4586 if (*option == '+')
4587 break;
4588 i++;
cristybb503372010-05-27 20:51:26 +00004589 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004590 ThrowMogrifyException(OptionError,"MissingArgument",option);
4591 event=ParseMagickOption(MagickLogEventOptions,MagickFalse,argv[i]);
4592 if (event < 0)
4593 ThrowMogrifyException(OptionError,"UnrecognizedEventType",
4594 argv[i]);
4595 (void) SetLogEventMask(argv[i]);
4596 break;
4597 }
4598 if (LocaleCompare("define",option+1) == 0)
4599 {
4600 i++;
cristybb503372010-05-27 20:51:26 +00004601 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004602 ThrowMogrifyException(OptionError,"MissingArgument",option);
4603 if (*option == '+')
4604 {
4605 const char
4606 *define;
4607
4608 define=GetImageOption(image_info,argv[i]);
4609 if (define == (const char *) NULL)
4610 ThrowMogrifyException(OptionError,"NoSuchOption",argv[i]);
4611 break;
4612 }
4613 break;
4614 }
4615 if (LocaleCompare("delay",option+1) == 0)
4616 {
4617 if (*option == '+')
4618 break;
4619 i++;
cristybb503372010-05-27 20:51:26 +00004620 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004621 ThrowMogrifyException(OptionError,"MissingArgument",option);
4622 if (IsGeometry(argv[i]) == MagickFalse)
4623 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4624 break;
4625 }
4626 if (LocaleCompare("density",option+1) == 0)
4627 {
4628 if (*option == '+')
4629 break;
4630 i++;
cristybb503372010-05-27 20:51:26 +00004631 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004632 ThrowMogrifyException(OptionError,"MissingArgument",option);
4633 if (IsGeometry(argv[i]) == MagickFalse)
4634 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4635 break;
4636 }
4637 if (LocaleCompare("depth",option+1) == 0)
4638 {
4639 if (*option == '+')
4640 break;
4641 i++;
cristybb503372010-05-27 20:51:26 +00004642 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004643 ThrowMogrifyException(OptionError,"MissingArgument",option);
4644 if (IsGeometry(argv[i]) == MagickFalse)
4645 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4646 break;
4647 }
4648 if (LocaleCompare("deskew",option+1) == 0)
4649 {
4650 if (*option == '+')
4651 break;
4652 i++;
cristybb503372010-05-27 20:51:26 +00004653 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004654 ThrowMogrifyException(OptionError,"MissingArgument",option);
4655 if (IsGeometry(argv[i]) == MagickFalse)
4656 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4657 break;
4658 }
4659 if (LocaleCompare("despeckle",option+1) == 0)
4660 break;
4661 if (LocaleCompare("dft",option+1) == 0)
4662 break;
cristyc9b12952010-03-28 01:12:28 +00004663 if (LocaleCompare("direction",option+1) == 0)
4664 {
cristybb503372010-05-27 20:51:26 +00004665 ssize_t
cristyc9b12952010-03-28 01:12:28 +00004666 direction;
4667
4668 if (*option == '+')
4669 break;
4670 i++;
cristybb503372010-05-27 20:51:26 +00004671 if (i == (ssize_t) argc)
cristyc9b12952010-03-28 01:12:28 +00004672 ThrowMogrifyException(OptionError,"MissingArgument",option);
4673 direction=ParseMagickOption(MagickDirectionOptions,MagickFalse,
4674 argv[i]);
4675 if (direction < 0)
4676 ThrowMogrifyException(OptionError,"UnrecognizedDirectionType",
4677 argv[i]);
4678 break;
4679 }
cristy3ed852e2009-09-05 21:47:34 +00004680 if (LocaleCompare("display",option+1) == 0)
4681 {
4682 if (*option == '+')
4683 break;
4684 i++;
cristybb503372010-05-27 20:51:26 +00004685 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004686 ThrowMogrifyException(OptionError,"MissingArgument",option);
4687 break;
4688 }
4689 if (LocaleCompare("dispose",option+1) == 0)
4690 {
cristybb503372010-05-27 20:51:26 +00004691 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004692 dispose;
4693
4694 if (*option == '+')
4695 break;
4696 i++;
cristybb503372010-05-27 20:51:26 +00004697 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004698 ThrowMogrifyException(OptionError,"MissingArgument",option);
4699 dispose=ParseMagickOption(MagickDisposeOptions,MagickFalse,argv[i]);
4700 if (dispose < 0)
4701 ThrowMogrifyException(OptionError,"UnrecognizedDisposeMethod",
4702 argv[i]);
4703 break;
4704 }
4705 if (LocaleCompare("distort",option+1) == 0)
4706 {
cristybb503372010-05-27 20:51:26 +00004707 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004708 op;
4709
4710 i++;
cristybb503372010-05-27 20:51:26 +00004711 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004712 ThrowMogrifyException(OptionError,"MissingArgument",option);
4713 op=ParseMagickOption(MagickDistortOptions,MagickFalse,argv[i]);
4714 if (op < 0)
4715 ThrowMogrifyException(OptionError,"UnrecognizedDistortMethod",
4716 argv[i]);
4717 i++;
cristybb503372010-05-27 20:51:26 +00004718 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004719 ThrowMogrifyException(OptionError,"MissingArgument",option);
4720 break;
4721 }
4722 if (LocaleCompare("dither",option+1) == 0)
4723 {
cristybb503372010-05-27 20:51:26 +00004724 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004725 method;
4726
4727 if (*option == '+')
4728 break;
4729 i++;
cristybb503372010-05-27 20:51:26 +00004730 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004731 ThrowMogrifyException(OptionError,"MissingArgument",option);
4732 method=ParseMagickOption(MagickDitherOptions,MagickFalse,argv[i]);
4733 if (method < 0)
4734 ThrowMogrifyException(OptionError,"UnrecognizedDitherMethod",
4735 argv[i]);
4736 break;
4737 }
4738 if (LocaleCompare("draw",option+1) == 0)
4739 {
4740 if (*option == '+')
4741 break;
4742 i++;
cristybb503372010-05-27 20:51:26 +00004743 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004744 ThrowMogrifyException(OptionError,"MissingArgument",option);
4745 break;
4746 }
cristy22879752009-10-25 23:55:40 +00004747 if (LocaleCompare("duration",option+1) == 0)
4748 {
4749 if (*option == '+')
4750 break;
4751 i++;
cristybb503372010-05-27 20:51:26 +00004752 if (i == (ssize_t) (argc-1))
cristy22879752009-10-25 23:55:40 +00004753 ThrowMogrifyException(OptionError,"MissingArgument",option);
4754 if (IsGeometry(argv[i]) == MagickFalse)
4755 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4756 break;
4757 }
cristy3ed852e2009-09-05 21:47:34 +00004758 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4759 }
4760 case 'e':
4761 {
4762 if (LocaleCompare("edge",option+1) == 0)
4763 {
4764 if (*option == '+')
4765 break;
4766 i++;
cristybb503372010-05-27 20:51:26 +00004767 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004768 ThrowMogrifyException(OptionError,"MissingArgument",option);
4769 if (IsGeometry(argv[i]) == MagickFalse)
4770 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4771 break;
4772 }
4773 if (LocaleCompare("emboss",option+1) == 0)
4774 {
4775 if (*option == '+')
4776 break;
4777 i++;
cristybb503372010-05-27 20:51:26 +00004778 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004779 ThrowMogrifyException(OptionError,"MissingArgument",option);
4780 if (IsGeometry(argv[i]) == MagickFalse)
4781 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4782 break;
4783 }
4784 if (LocaleCompare("encipher",option+1) == 0)
4785 {
4786 if (*option == '+')
4787 break;
4788 i++;
cristybb503372010-05-27 20:51:26 +00004789 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004790 ThrowMogrifyException(OptionError,"MissingArgument",option);
4791 break;
4792 }
4793 if (LocaleCompare("encoding",option+1) == 0)
4794 {
4795 if (*option == '+')
4796 break;
4797 i++;
cristybb503372010-05-27 20:51:26 +00004798 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004799 ThrowMogrifyException(OptionError,"MissingArgument",option);
4800 break;
4801 }
4802 if (LocaleCompare("endian",option+1) == 0)
4803 {
cristybb503372010-05-27 20:51:26 +00004804 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004805 endian;
4806
4807 if (*option == '+')
4808 break;
4809 i++;
cristybb503372010-05-27 20:51:26 +00004810 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004811 ThrowMogrifyException(OptionError,"MissingArgument",option);
4812 endian=ParseMagickOption(MagickEndianOptions,MagickFalse,argv[i]);
4813 if (endian < 0)
4814 ThrowMogrifyException(OptionError,"UnrecognizedEndianType",
4815 argv[i]);
4816 break;
4817 }
4818 if (LocaleCompare("enhance",option+1) == 0)
4819 break;
4820 if (LocaleCompare("equalize",option+1) == 0)
4821 break;
4822 if (LocaleCompare("evaluate",option+1) == 0)
4823 {
cristybb503372010-05-27 20:51:26 +00004824 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004825 op;
4826
4827 if (*option == '+')
4828 break;
4829 i++;
cristybb503372010-05-27 20:51:26 +00004830 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004831 ThrowMogrifyException(OptionError,"MissingArgument",option);
4832 op=ParseMagickOption(MagickEvaluateOptions,MagickFalse,argv[i]);
4833 if (op < 0)
4834 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4835 argv[i]);
4836 i++;
cristybb503372010-05-27 20:51:26 +00004837 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004838 ThrowMogrifyException(OptionError,"MissingArgument",option);
4839 if (IsGeometry(argv[i]) == MagickFalse)
4840 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4841 break;
4842 }
cristyd18ae7c2010-03-07 17:39:52 +00004843 if (LocaleCompare("evaluate-sequence",option+1) == 0)
4844 {
cristybb503372010-05-27 20:51:26 +00004845 ssize_t
cristyd18ae7c2010-03-07 17:39:52 +00004846 op;
4847
4848 if (*option == '+')
4849 break;
4850 i++;
cristybb503372010-05-27 20:51:26 +00004851 if (i == (ssize_t) argc)
cristyd18ae7c2010-03-07 17:39:52 +00004852 ThrowMogrifyException(OptionError,"MissingArgument",option);
4853 op=ParseMagickOption(MagickEvaluateOptions,MagickFalse,argv[i]);
4854 if (op < 0)
4855 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4856 argv[i]);
4857 break;
4858 }
cristy3ed852e2009-09-05 21:47:34 +00004859 if (LocaleCompare("extent",option+1) == 0)
4860 {
4861 if (*option == '+')
4862 break;
4863 i++;
cristybb503372010-05-27 20:51:26 +00004864 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004865 ThrowMogrifyException(OptionError,"MissingArgument",option);
4866 if (IsGeometry(argv[i]) == MagickFalse)
4867 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4868 break;
4869 }
4870 if (LocaleCompare("extract",option+1) == 0)
4871 {
4872 if (*option == '+')
4873 break;
4874 i++;
cristybb503372010-05-27 20:51:26 +00004875 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004876 ThrowMogrifyException(OptionError,"MissingArgument",option);
4877 if (IsGeometry(argv[i]) == MagickFalse)
4878 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4879 break;
4880 }
4881 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4882 }
4883 case 'f':
4884 {
4885 if (LocaleCompare("family",option+1) == 0)
4886 {
4887 if (*option == '+')
4888 break;
4889 i++;
cristybb503372010-05-27 20:51:26 +00004890 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004891 ThrowMogrifyException(OptionError,"MissingArgument",option);
4892 break;
4893 }
4894 if (LocaleCompare("fill",option+1) == 0)
4895 {
4896 if (*option == '+')
4897 break;
4898 i++;
cristybb503372010-05-27 20:51:26 +00004899 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004900 ThrowMogrifyException(OptionError,"MissingArgument",option);
4901 break;
4902 }
4903 if (LocaleCompare("filter",option+1) == 0)
4904 {
cristybb503372010-05-27 20:51:26 +00004905 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004906 filter;
4907
4908 if (*option == '+')
4909 break;
4910 i++;
cristybb503372010-05-27 20:51:26 +00004911 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004912 ThrowMogrifyException(OptionError,"MissingArgument",option);
4913 filter=ParseMagickOption(MagickFilterOptions,MagickFalse,argv[i]);
4914 if (filter < 0)
4915 ThrowMogrifyException(OptionError,"UnrecognizedImageFilter",
4916 argv[i]);
4917 break;
4918 }
4919 if (LocaleCompare("flatten",option+1) == 0)
4920 break;
4921 if (LocaleCompare("flip",option+1) == 0)
4922 break;
4923 if (LocaleCompare("flop",option+1) == 0)
4924 break;
4925 if (LocaleCompare("floodfill",option+1) == 0)
4926 {
4927 if (*option == '+')
4928 break;
4929 i++;
cristybb503372010-05-27 20:51:26 +00004930 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004931 ThrowMogrifyException(OptionError,"MissingArgument",option);
4932 if (IsGeometry(argv[i]) == MagickFalse)
4933 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4934 i++;
cristybb503372010-05-27 20:51:26 +00004935 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004936 ThrowMogrifyException(OptionError,"MissingArgument",option);
4937 break;
4938 }
4939 if (LocaleCompare("font",option+1) == 0)
4940 {
4941 if (*option == '+')
4942 break;
4943 i++;
cristybb503372010-05-27 20:51:26 +00004944 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004945 ThrowMogrifyException(OptionError,"MissingArgument",option);
4946 break;
4947 }
4948 if (LocaleCompare("format",option+1) == 0)
4949 {
4950 (void) CopyMagickString(argv[i]+1,"sans",MaxTextExtent);
4951 (void) CloneString(&format,(char *) NULL);
4952 if (*option == '+')
4953 break;
4954 i++;
cristybb503372010-05-27 20:51:26 +00004955 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004956 ThrowMogrifyException(OptionError,"MissingArgument",option);
4957 (void) CloneString(&format,argv[i]);
4958 (void) CopyMagickString(image_info->filename,format,MaxTextExtent);
4959 (void) ConcatenateMagickString(image_info->filename,":",
4960 MaxTextExtent);
cristyd965a422010-03-03 17:47:35 +00004961 (void) SetImageInfo(image_info,0,exception);
cristy3ed852e2009-09-05 21:47:34 +00004962 if (*image_info->magick == '\0')
4963 ThrowMogrifyException(OptionError,"UnrecognizedImageFormat",
4964 format);
4965 break;
4966 }
4967 if (LocaleCompare("frame",option+1) == 0)
4968 {
4969 if (*option == '+')
4970 break;
4971 i++;
cristybb503372010-05-27 20:51:26 +00004972 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004973 ThrowMogrifyException(OptionError,"MissingArgument",option);
4974 if (IsGeometry(argv[i]) == MagickFalse)
4975 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4976 break;
4977 }
4978 if (LocaleCompare("function",option+1) == 0)
4979 {
cristybb503372010-05-27 20:51:26 +00004980 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004981 op;
4982
4983 if (*option == '+')
4984 break;
4985 i++;
cristybb503372010-05-27 20:51:26 +00004986 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004987 ThrowMogrifyException(OptionError,"MissingArgument",option);
4988 op=ParseMagickOption(MagickFunctionOptions,MagickFalse,argv[i]);
4989 if (op < 0)
4990 ThrowMogrifyException(OptionError,"UnrecognizedFunction",argv[i]);
4991 i++;
cristybb503372010-05-27 20:51:26 +00004992 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004993 ThrowMogrifyException(OptionError,"MissingArgument",option);
4994 break;
4995 }
4996 if (LocaleCompare("fuzz",option+1) == 0)
4997 {
4998 if (*option == '+')
4999 break;
5000 i++;
cristybb503372010-05-27 20:51:26 +00005001 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005002 ThrowMogrifyException(OptionError,"MissingArgument",option);
5003 if (IsGeometry(argv[i]) == MagickFalse)
5004 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5005 break;
5006 }
5007 if (LocaleCompare("fx",option+1) == 0)
5008 {
5009 if (*option == '+')
5010 break;
5011 i++;
cristybb503372010-05-27 20:51:26 +00005012 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005013 ThrowMogrifyException(OptionError,"MissingArgument",option);
5014 break;
5015 }
5016 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5017 }
5018 case 'g':
5019 {
5020 if (LocaleCompare("gamma",option+1) == 0)
5021 {
5022 i++;
cristybb503372010-05-27 20:51:26 +00005023 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005024 ThrowMogrifyException(OptionError,"MissingArgument",option);
5025 if (IsGeometry(argv[i]) == MagickFalse)
5026 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5027 break;
5028 }
5029 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
5030 (LocaleCompare("gaussian",option+1) == 0))
5031 {
5032 i++;
cristybb503372010-05-27 20:51:26 +00005033 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005034 ThrowMogrifyException(OptionError,"MissingArgument",option);
5035 if (IsGeometry(argv[i]) == MagickFalse)
5036 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5037 break;
5038 }
5039 if (LocaleCompare("geometry",option+1) == 0)
5040 {
5041 if (*option == '+')
5042 break;
5043 i++;
cristybb503372010-05-27 20:51:26 +00005044 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005045 ThrowMogrifyException(OptionError,"MissingArgument",option);
5046 if (IsGeometry(argv[i]) == MagickFalse)
5047 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5048 break;
5049 }
5050 if (LocaleCompare("gravity",option+1) == 0)
5051 {
cristybb503372010-05-27 20:51:26 +00005052 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005053 gravity;
5054
5055 if (*option == '+')
5056 break;
5057 i++;
cristybb503372010-05-27 20:51:26 +00005058 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005059 ThrowMogrifyException(OptionError,"MissingArgument",option);
5060 gravity=ParseMagickOption(MagickGravityOptions,MagickFalse,argv[i]);
5061 if (gravity < 0)
5062 ThrowMogrifyException(OptionError,"UnrecognizedGravityType",
5063 argv[i]);
5064 break;
5065 }
5066 if (LocaleCompare("green-primary",option+1) == 0)
5067 {
5068 if (*option == '+')
5069 break;
5070 i++;
cristybb503372010-05-27 20:51:26 +00005071 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005072 ThrowMogrifyException(OptionError,"MissingArgument",option);
5073 if (IsGeometry(argv[i]) == MagickFalse)
5074 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5075 break;
5076 }
5077 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5078 }
5079 case 'h':
5080 {
5081 if (LocaleCompare("hald-clut",option+1) == 0)
5082 break;
5083 if ((LocaleCompare("help",option+1) == 0) ||
5084 (LocaleCompare("-help",option+1) == 0))
5085 return(MogrifyUsage());
5086 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5087 }
5088 case 'i':
5089 {
5090 if (LocaleCompare("identify",option+1) == 0)
5091 break;
5092 if (LocaleCompare("idft",option+1) == 0)
5093 break;
5094 if (LocaleCompare("implode",option+1) == 0)
5095 {
5096 if (*option == '+')
5097 break;
5098 i++;
cristybb503372010-05-27 20:51:26 +00005099 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005100 ThrowMogrifyException(OptionError,"MissingArgument",option);
5101 if (IsGeometry(argv[i]) == MagickFalse)
5102 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5103 break;
5104 }
5105 if (LocaleCompare("intent",option+1) == 0)
5106 {
cristybb503372010-05-27 20:51:26 +00005107 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005108 intent;
5109
5110 if (*option == '+')
5111 break;
5112 i++;
cristybb503372010-05-27 20:51:26 +00005113 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005114 ThrowMogrifyException(OptionError,"MissingArgument",option);
5115 intent=ParseMagickOption(MagickIntentOptions,MagickFalse,argv[i]);
5116 if (intent < 0)
5117 ThrowMogrifyException(OptionError,"UnrecognizedIntentType",
5118 argv[i]);
5119 break;
5120 }
5121 if (LocaleCompare("interlace",option+1) == 0)
5122 {
cristybb503372010-05-27 20:51:26 +00005123 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005124 interlace;
5125
5126 if (*option == '+')
5127 break;
5128 i++;
cristybb503372010-05-27 20:51:26 +00005129 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005130 ThrowMogrifyException(OptionError,"MissingArgument",option);
5131 interlace=ParseMagickOption(MagickInterlaceOptions,MagickFalse,
5132 argv[i]);
5133 if (interlace < 0)
5134 ThrowMogrifyException(OptionError,"UnrecognizedInterlaceType",
5135 argv[i]);
5136 break;
5137 }
cristyb32b90a2009-09-07 21:45:48 +00005138 if (LocaleCompare("interline-spacing",option+1) == 0)
5139 {
5140 if (*option == '+')
5141 break;
5142 i++;
cristybb503372010-05-27 20:51:26 +00005143 if (i == (ssize_t) (argc-1))
cristyb32b90a2009-09-07 21:45:48 +00005144 ThrowMogrifyException(OptionError,"MissingArgument",option);
5145 if (IsGeometry(argv[i]) == MagickFalse)
5146 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5147 break;
5148 }
cristy3ed852e2009-09-05 21:47:34 +00005149 if (LocaleCompare("interpolate",option+1) == 0)
5150 {
cristybb503372010-05-27 20:51:26 +00005151 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005152 interpolate;
5153
5154 if (*option == '+')
5155 break;
5156 i++;
cristybb503372010-05-27 20:51:26 +00005157 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005158 ThrowMogrifyException(OptionError,"MissingArgument",option);
5159 interpolate=ParseMagickOption(MagickInterpolateOptions,MagickFalse,
5160 argv[i]);
5161 if (interpolate < 0)
5162 ThrowMogrifyException(OptionError,"UnrecognizedInterpolateMethod",
5163 argv[i]);
5164 break;
5165 }
5166 if (LocaleCompare("interword-spacing",option+1) == 0)
5167 {
5168 if (*option == '+')
5169 break;
5170 i++;
cristybb503372010-05-27 20:51:26 +00005171 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005172 ThrowMogrifyException(OptionError,"MissingArgument",option);
5173 if (IsGeometry(argv[i]) == MagickFalse)
5174 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5175 break;
5176 }
5177 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5178 }
5179 case 'k':
5180 {
5181 if (LocaleCompare("kerning",option+1) == 0)
5182 {
5183 if (*option == '+')
5184 break;
5185 i++;
cristybb503372010-05-27 20:51:26 +00005186 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005187 ThrowMogrifyException(OptionError,"MissingArgument",option);
5188 if (IsGeometry(argv[i]) == MagickFalse)
5189 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5190 break;
5191 }
5192 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5193 }
5194 case 'l':
5195 {
5196 if (LocaleCompare("label",option+1) == 0)
5197 {
5198 if (*option == '+')
5199 break;
5200 i++;
cristybb503372010-05-27 20:51:26 +00005201 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005202 ThrowMogrifyException(OptionError,"MissingArgument",option);
5203 break;
5204 }
5205 if (LocaleCompare("lat",option+1) == 0)
5206 {
5207 if (*option == '+')
5208 break;
5209 i++;
cristybb503372010-05-27 20:51:26 +00005210 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005211 ThrowMogrifyException(OptionError,"MissingArgument",option);
5212 if (IsGeometry(argv[i]) == MagickFalse)
5213 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5214 }
5215 if (LocaleCompare("layers",option+1) == 0)
5216 {
cristybb503372010-05-27 20:51:26 +00005217 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005218 type;
5219
5220 if (*option == '+')
5221 break;
5222 i++;
cristybb503372010-05-27 20:51:26 +00005223 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005224 ThrowMogrifyException(OptionError,"MissingArgument",option);
5225 type=ParseMagickOption(MagickLayerOptions,MagickFalse,argv[i]);
5226 if (type < 0)
5227 ThrowMogrifyException(OptionError,"UnrecognizedLayerMethod",
5228 argv[i]);
5229 break;
5230 }
5231 if (LocaleCompare("level",option+1) == 0)
5232 {
5233 i++;
cristybb503372010-05-27 20:51:26 +00005234 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005235 ThrowMogrifyException(OptionError,"MissingArgument",option);
5236 if (IsGeometry(argv[i]) == MagickFalse)
5237 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5238 break;
5239 }
5240 if (LocaleCompare("level-colors",option+1) == 0)
5241 {
5242 i++;
cristybb503372010-05-27 20:51:26 +00005243 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005244 ThrowMogrifyException(OptionError,"MissingArgument",option);
5245 break;
5246 }
5247 if (LocaleCompare("linewidth",option+1) == 0)
5248 {
5249 if (*option == '+')
5250 break;
5251 i++;
cristybb503372010-05-27 20:51:26 +00005252 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005253 ThrowMogrifyException(OptionError,"MissingArgument",option);
5254 if (IsGeometry(argv[i]) == MagickFalse)
5255 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5256 break;
5257 }
5258 if (LocaleCompare("limit",option+1) == 0)
5259 {
5260 char
5261 *p;
5262
5263 double
5264 value;
5265
cristybb503372010-05-27 20:51:26 +00005266 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005267 resource;
5268
5269 if (*option == '+')
5270 break;
5271 i++;
cristybb503372010-05-27 20:51:26 +00005272 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005273 ThrowMogrifyException(OptionError,"MissingArgument",option);
5274 resource=ParseMagickOption(MagickResourceOptions,MagickFalse,
5275 argv[i]);
5276 if (resource < 0)
5277 ThrowMogrifyException(OptionError,"UnrecognizedResourceType",
5278 argv[i]);
5279 i++;
cristybb503372010-05-27 20:51:26 +00005280 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005281 ThrowMogrifyException(OptionError,"MissingArgument",option);
5282 value=strtod(argv[i],&p);
5283 if ((p == argv[i]) && (LocaleCompare("unlimited",argv[i]) != 0))
5284 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5285 break;
5286 }
5287 if (LocaleCompare("liquid-rescale",option+1) == 0)
5288 {
5289 i++;
cristybb503372010-05-27 20:51:26 +00005290 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005291 ThrowMogrifyException(OptionError,"MissingArgument",option);
5292 if (IsGeometry(argv[i]) == MagickFalse)
5293 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5294 break;
5295 }
5296 if (LocaleCompare("list",option+1) == 0)
5297 {
cristybb503372010-05-27 20:51:26 +00005298 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005299 list;
5300
5301 if (*option == '+')
5302 break;
5303 i++;
cristybb503372010-05-27 20:51:26 +00005304 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005305 ThrowMogrifyException(OptionError,"MissingArgument",option);
5306 list=ParseMagickOption(MagickListOptions,MagickFalse,argv[i]);
5307 if (list < 0)
5308 ThrowMogrifyException(OptionError,"UnrecognizedListType",argv[i]);
cristyaeb2cbc2010-05-07 13:28:58 +00005309 status=MogrifyImageInfo(image_info,(int) (i-j+1),(const char **)
cristy3ed852e2009-09-05 21:47:34 +00005310 argv+j,exception);
cristyaeb2cbc2010-05-07 13:28:58 +00005311 return(status != 0 ? MagickFalse : MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00005312 }
5313 if (LocaleCompare("log",option+1) == 0)
5314 {
5315 if (*option == '+')
5316 break;
5317 i++;
cristybb503372010-05-27 20:51:26 +00005318 if ((i == (ssize_t) argc) ||
cristy3ed852e2009-09-05 21:47:34 +00005319 (strchr(argv[i],'%') == (char *) NULL))
5320 ThrowMogrifyException(OptionError,"MissingArgument",option);
5321 break;
5322 }
5323 if (LocaleCompare("loop",option+1) == 0)
5324 {
5325 if (*option == '+')
5326 break;
5327 i++;
cristybb503372010-05-27 20:51:26 +00005328 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005329 ThrowMogrifyException(OptionError,"MissingArgument",option);
5330 if (IsGeometry(argv[i]) == MagickFalse)
5331 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5332 break;
5333 }
5334 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5335 }
5336 case 'm':
5337 {
5338 if (LocaleCompare("map",option+1) == 0)
5339 {
5340 global_colormap=(*option == '+') ? MagickTrue : MagickFalse;
5341 if (*option == '+')
5342 break;
5343 i++;
cristybb503372010-05-27 20:51:26 +00005344 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005345 ThrowMogrifyException(OptionError,"MissingArgument",option);
5346 break;
5347 }
5348 if (LocaleCompare("mask",option+1) == 0)
5349 {
5350 if (*option == '+')
5351 break;
5352 i++;
cristybb503372010-05-27 20:51:26 +00005353 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005354 ThrowMogrifyException(OptionError,"MissingArgument",option);
5355 break;
5356 }
5357 if (LocaleCompare("matte",option+1) == 0)
5358 break;
5359 if (LocaleCompare("mattecolor",option+1) == 0)
5360 {
5361 if (*option == '+')
5362 break;
5363 i++;
cristybb503372010-05-27 20:51:26 +00005364 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005365 ThrowMogrifyException(OptionError,"MissingArgument",option);
5366 break;
5367 }
cristyf40785b2010-03-06 02:27:27 +00005368 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00005369 break;
cristyf40785b2010-03-06 02:27:27 +00005370 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00005371 break;
cristy3ed852e2009-09-05 21:47:34 +00005372 if (LocaleCompare("modulate",option+1) == 0)
5373 {
5374 if (*option == '+')
5375 break;
5376 i++;
cristybb503372010-05-27 20:51:26 +00005377 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005378 ThrowMogrifyException(OptionError,"MissingArgument",option);
5379 if (IsGeometry(argv[i]) == MagickFalse)
5380 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5381 break;
5382 }
5383 if (LocaleCompare("median",option+1) == 0)
5384 {
5385 if (*option == '+')
5386 break;
5387 i++;
cristybb503372010-05-27 20:51:26 +00005388 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005389 ThrowMogrifyException(OptionError,"MissingArgument",option);
5390 if (IsGeometry(argv[i]) == MagickFalse)
5391 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5392 break;
5393 }
5394 if (LocaleCompare("monitor",option+1) == 0)
5395 break;
5396 if (LocaleCompare("monochrome",option+1) == 0)
5397 break;
5398 if (LocaleCompare("morph",option+1) == 0)
5399 {
5400 if (*option == '+')
5401 break;
5402 i++;
cristybb503372010-05-27 20:51:26 +00005403 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005404 ThrowMogrifyException(OptionError,"MissingArgument",option);
5405 if (IsGeometry(argv[i]) == MagickFalse)
5406 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5407 break;
5408 }
anthony29188a82010-01-22 10:12:34 +00005409 if (LocaleCompare("morphology",option+1) == 0)
5410 {
cristybb503372010-05-27 20:51:26 +00005411 ssize_t
anthony29188a82010-01-22 10:12:34 +00005412 op;
5413
5414 char
5415 token[MaxTextExtent];
5416
5417 i++;
cristybb503372010-05-27 20:51:26 +00005418 if (i == (ssize_t) argc)
anthony29188a82010-01-22 10:12:34 +00005419 ThrowMogrifyException(OptionError,"MissingArgument",option);
5420 GetMagickToken(argv[i],NULL,token);
5421 op=ParseMagickOption(MagickMorphologyOptions,MagickFalse,token);
5422 if (op < 0)
5423 ThrowMogrifyException(OptionError,"UnrecognizedMorphologyMethod",
cristyf0c78232010-03-15 12:53:40 +00005424 token);
anthony29188a82010-01-22 10:12:34 +00005425 i++;
cristybb503372010-05-27 20:51:26 +00005426 if (i == (ssize_t) (argc-1))
anthony29188a82010-01-22 10:12:34 +00005427 ThrowMogrifyException(OptionError,"MissingArgument",option);
5428 GetMagickToken(argv[i],NULL,token);
cristyf0c78232010-03-15 12:53:40 +00005429 if (isalpha((int) ((unsigned char) *token)) != 0)
anthony29188a82010-01-22 10:12:34 +00005430 {
5431 op=ParseMagickOption(MagickKernelOptions,MagickFalse,token);
5432 if (op < 0)
5433 ThrowMogrifyException(OptionError,"UnrecognizedKernelType",
cristyf0c78232010-03-15 12:53:40 +00005434 token);
anthony29188a82010-01-22 10:12:34 +00005435 }
anthony29188a82010-01-22 10:12:34 +00005436 break;
5437 }
cristy3ed852e2009-09-05 21:47:34 +00005438 if (LocaleCompare("mosaic",option+1) == 0)
5439 break;
5440 if (LocaleCompare("motion-blur",option+1) == 0)
5441 {
5442 if (*option == '+')
5443 break;
5444 i++;
cristybb503372010-05-27 20:51:26 +00005445 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005446 ThrowMogrifyException(OptionError,"MissingArgument",option);
5447 if (IsGeometry(argv[i]) == MagickFalse)
5448 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5449 break;
5450 }
5451 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5452 }
5453 case 'n':
5454 {
5455 if (LocaleCompare("negate",option+1) == 0)
5456 break;
5457 if (LocaleCompare("noise",option+1) == 0)
5458 {
5459 i++;
cristybb503372010-05-27 20:51:26 +00005460 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005461 ThrowMogrifyException(OptionError,"MissingArgument",option);
5462 if (*option == '+')
5463 {
cristybb503372010-05-27 20:51:26 +00005464 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005465 noise;
5466
5467 noise=ParseMagickOption(MagickNoiseOptions,MagickFalse,argv[i]);
5468 if (noise < 0)
5469 ThrowMogrifyException(OptionError,"UnrecognizedNoiseType",
5470 argv[i]);
5471 break;
5472 }
5473 if (IsGeometry(argv[i]) == MagickFalse)
5474 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5475 break;
5476 }
5477 if (LocaleCompare("noop",option+1) == 0)
5478 break;
5479 if (LocaleCompare("normalize",option+1) == 0)
5480 break;
5481 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5482 }
5483 case 'o':
5484 {
5485 if (LocaleCompare("opaque",option+1) == 0)
5486 {
cristy3ed852e2009-09-05 21:47:34 +00005487 i++;
cristybb503372010-05-27 20:51:26 +00005488 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005489 ThrowMogrifyException(OptionError,"MissingArgument",option);
5490 break;
5491 }
5492 if (LocaleCompare("ordered-dither",option+1) == 0)
5493 {
5494 if (*option == '+')
5495 break;
5496 i++;
cristybb503372010-05-27 20:51:26 +00005497 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005498 ThrowMogrifyException(OptionError,"MissingArgument",option);
5499 break;
5500 }
5501 if (LocaleCompare("orient",option+1) == 0)
5502 {
cristybb503372010-05-27 20:51:26 +00005503 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005504 orientation;
5505
5506 orientation=UndefinedOrientation;
5507 if (*option == '+')
5508 break;
5509 i++;
cristybb503372010-05-27 20:51:26 +00005510 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005511 ThrowMogrifyException(OptionError,"MissingArgument",option);
5512 orientation=ParseMagickOption(MagickOrientationOptions,MagickFalse,
5513 argv[i]);
5514 if (orientation < 0)
5515 ThrowMogrifyException(OptionError,"UnrecognizedImageOrientation",
5516 argv[i]);
5517 break;
5518 }
5519 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5520 }
5521 case 'p':
5522 {
5523 if (LocaleCompare("page",option+1) == 0)
5524 {
5525 if (*option == '+')
5526 break;
5527 i++;
cristybb503372010-05-27 20:51:26 +00005528 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005529 ThrowMogrifyException(OptionError,"MissingArgument",option);
5530 break;
5531 }
5532 if (LocaleCompare("paint",option+1) == 0)
5533 {
5534 if (*option == '+')
5535 break;
5536 i++;
cristybb503372010-05-27 20:51:26 +00005537 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005538 ThrowMogrifyException(OptionError,"MissingArgument",option);
5539 if (IsGeometry(argv[i]) == MagickFalse)
5540 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5541 break;
5542 }
5543 if (LocaleCompare("path",option+1) == 0)
5544 {
5545 (void) CloneString(&path,(char *) NULL);
5546 if (*option == '+')
5547 break;
5548 i++;
cristybb503372010-05-27 20:51:26 +00005549 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005550 ThrowMogrifyException(OptionError,"MissingArgument",option);
5551 (void) CloneString(&path,argv[i]);
5552 break;
5553 }
5554 if (LocaleCompare("pointsize",option+1) == 0)
5555 {
5556 if (*option == '+')
5557 break;
5558 i++;
cristybb503372010-05-27 20:51:26 +00005559 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005560 ThrowMogrifyException(OptionError,"MissingArgument",option);
5561 if (IsGeometry(argv[i]) == MagickFalse)
5562 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5563 break;
5564 }
5565 if (LocaleCompare("polaroid",option+1) == 0)
5566 {
5567 if (*option == '+')
5568 break;
5569 i++;
cristybb503372010-05-27 20:51:26 +00005570 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005571 ThrowMogrifyException(OptionError,"MissingArgument",option);
5572 if (IsGeometry(argv[i]) == MagickFalse)
5573 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5574 break;
5575 }
5576 if (LocaleCompare("posterize",option+1) == 0)
5577 {
5578 if (*option == '+')
5579 break;
5580 i++;
cristybb503372010-05-27 20:51:26 +00005581 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005582 ThrowMogrifyException(OptionError,"MissingArgument",option);
5583 if (IsGeometry(argv[i]) == MagickFalse)
5584 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5585 break;
5586 }
cristye7f51092010-01-17 00:39:37 +00005587 if (LocaleCompare("precision",option+1) == 0)
5588 {
5589 if (*option == '+')
5590 break;
5591 i++;
cristybb503372010-05-27 20:51:26 +00005592 if (i == (ssize_t) argc)
cristye7f51092010-01-17 00:39:37 +00005593 ThrowMogrifyException(OptionError,"MissingArgument",option);
5594 if (IsGeometry(argv[i]) == MagickFalse)
5595 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5596 break;
5597 }
cristy3ed852e2009-09-05 21:47:34 +00005598 if (LocaleCompare("print",option+1) == 0)
5599 {
5600 if (*option == '+')
5601 break;
5602 i++;
cristybb503372010-05-27 20:51:26 +00005603 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005604 ThrowMogrifyException(OptionError,"MissingArgument",option);
5605 break;
5606 }
5607 if (LocaleCompare("process",option+1) == 0)
5608 {
5609 if (*option == '+')
5610 break;
5611 i++;
cristybb503372010-05-27 20:51:26 +00005612 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005613 ThrowMogrifyException(OptionError,"MissingArgument",option);
5614 break;
5615 }
5616 if (LocaleCompare("profile",option+1) == 0)
5617 {
5618 i++;
cristybb503372010-05-27 20:51:26 +00005619 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005620 ThrowMogrifyException(OptionError,"MissingArgument",option);
5621 break;
5622 }
5623 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5624 }
5625 case 'q':
5626 {
5627 if (LocaleCompare("quality",option+1) == 0)
5628 {
5629 if (*option == '+')
5630 break;
5631 i++;
cristybb503372010-05-27 20:51:26 +00005632 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005633 ThrowMogrifyException(OptionError,"MissingArgument",option);
5634 if (IsGeometry(argv[i]) == MagickFalse)
5635 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5636 break;
5637 }
5638 if (LocaleCompare("quantize",option+1) == 0)
5639 {
cristybb503372010-05-27 20:51:26 +00005640 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005641 colorspace;
5642
5643 if (*option == '+')
5644 break;
5645 i++;
cristybb503372010-05-27 20:51:26 +00005646 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005647 ThrowMogrifyException(OptionError,"MissingArgument",option);
5648 colorspace=ParseMagickOption(MagickColorspaceOptions,MagickFalse,
5649 argv[i]);
5650 if (colorspace < 0)
5651 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
5652 argv[i]);
5653 break;
5654 }
5655 if (LocaleCompare("quiet",option+1) == 0)
5656 break;
5657 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5658 }
5659 case 'r':
5660 {
5661 if (LocaleCompare("radial-blur",option+1) == 0)
5662 {
5663 i++;
cristybb503372010-05-27 20:51:26 +00005664 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005665 ThrowMogrifyException(OptionError,"MissingArgument",option);
5666 if (IsGeometry(argv[i]) == MagickFalse)
5667 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5668 break;
5669 }
5670 if (LocaleCompare("raise",option+1) == 0)
5671 {
5672 i++;
cristybb503372010-05-27 20:51:26 +00005673 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005674 ThrowMogrifyException(OptionError,"MissingArgument",option);
5675 if (IsGeometry(argv[i]) == MagickFalse)
5676 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5677 break;
5678 }
5679 if (LocaleCompare("random-threshold",option+1) == 0)
5680 {
5681 if (*option == '+')
5682 break;
5683 i++;
cristybb503372010-05-27 20:51:26 +00005684 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005685 ThrowMogrifyException(OptionError,"MissingArgument",option);
5686 if (IsGeometry(argv[i]) == MagickFalse)
5687 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5688 break;
5689 }
cristye6365592010-04-02 17:31:23 +00005690 if (LocaleCompare("recolor",option+1) == 0)
5691 {
5692 if (*option == '+')
5693 break;
5694 i++;
cristybb503372010-05-27 20:51:26 +00005695 if (i == (ssize_t) (argc-1))
cristye6365592010-04-02 17:31:23 +00005696 ThrowMogrifyException(OptionError,"MissingArgument",option);
5697 if (IsGeometry(argv[i]) == MagickFalse)
5698 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5699 break;
5700 }
cristy3ed852e2009-09-05 21:47:34 +00005701 if (LocaleCompare("red-primary",option+1) == 0)
5702 {
5703 if (*option == '+')
5704 break;
5705 i++;
cristybb503372010-05-27 20:51:26 +00005706 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005707 ThrowMogrifyException(OptionError,"MissingArgument",option);
5708 if (IsGeometry(argv[i]) == MagickFalse)
5709 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5710 }
cristy9f2083a2010-04-22 19:48:05 +00005711 if (LocaleCompare("regard-warnings",option+1) == 0)
5712 break;
cristy3ed852e2009-09-05 21:47:34 +00005713 if (LocaleCompare("region",option+1) == 0)
5714 {
5715 if (*option == '+')
5716 break;
5717 i++;
cristybb503372010-05-27 20:51:26 +00005718 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005719 ThrowMogrifyException(OptionError,"MissingArgument",option);
5720 if (IsGeometry(argv[i]) == MagickFalse)
5721 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5722 break;
5723 }
cristyf0c78232010-03-15 12:53:40 +00005724 if (LocaleCompare("remap",option+1) == 0)
5725 {
5726 if (*option == '+')
5727 break;
5728 i++;
cristybb503372010-05-27 20:51:26 +00005729 if (i == (ssize_t) (argc-1))
cristyf0c78232010-03-15 12:53:40 +00005730 ThrowMogrifyException(OptionError,"MissingArgument",option);
5731 break;
5732 }
cristy3ed852e2009-09-05 21:47:34 +00005733 if (LocaleCompare("render",option+1) == 0)
5734 break;
5735 if (LocaleCompare("repage",option+1) == 0)
5736 {
5737 if (*option == '+')
5738 break;
5739 i++;
cristybb503372010-05-27 20:51:26 +00005740 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005741 ThrowMogrifyException(OptionError,"MissingArgument",option);
5742 if (IsGeometry(argv[i]) == MagickFalse)
5743 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5744 break;
5745 }
5746 if (LocaleCompare("resample",option+1) == 0)
5747 {
5748 if (*option == '+')
5749 break;
5750 i++;
cristybb503372010-05-27 20:51:26 +00005751 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005752 ThrowMogrifyException(OptionError,"MissingArgument",option);
5753 if (IsGeometry(argv[i]) == MagickFalse)
5754 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5755 break;
5756 }
5757 if (LocaleCompare("resize",option+1) == 0)
5758 {
5759 if (*option == '+')
5760 break;
5761 i++;
cristybb503372010-05-27 20:51:26 +00005762 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005763 ThrowMogrifyException(OptionError,"MissingArgument",option);
5764 if (IsGeometry(argv[i]) == MagickFalse)
5765 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5766 break;
5767 }
5768 if (LocaleCompare("reverse",option+1) == 0)
5769 break;
5770 if (LocaleCompare("roll",option+1) == 0)
5771 {
5772 if (*option == '+')
5773 break;
5774 i++;
cristybb503372010-05-27 20:51:26 +00005775 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005776 ThrowMogrifyException(OptionError,"MissingArgument",option);
5777 if (IsGeometry(argv[i]) == MagickFalse)
5778 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5779 break;
5780 }
5781 if (LocaleCompare("rotate",option+1) == 0)
5782 {
5783 i++;
cristybb503372010-05-27 20:51:26 +00005784 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005785 ThrowMogrifyException(OptionError,"MissingArgument",option);
5786 if (IsGeometry(argv[i]) == MagickFalse)
5787 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5788 break;
5789 }
5790 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5791 }
5792 case 's':
5793 {
5794 if (LocaleCompare("sample",option+1) == 0)
5795 {
5796 if (*option == '+')
5797 break;
5798 i++;
cristybb503372010-05-27 20:51:26 +00005799 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005800 ThrowMogrifyException(OptionError,"MissingArgument",option);
5801 if (IsGeometry(argv[i]) == MagickFalse)
5802 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5803 break;
5804 }
5805 if (LocaleCompare("sampling-factor",option+1) == 0)
5806 {
5807 if (*option == '+')
5808 break;
5809 i++;
cristybb503372010-05-27 20:51:26 +00005810 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005811 ThrowMogrifyException(OptionError,"MissingArgument",option);
5812 if (IsGeometry(argv[i]) == MagickFalse)
5813 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5814 break;
5815 }
5816 if (LocaleCompare("scale",option+1) == 0)
5817 {
5818 if (*option == '+')
5819 break;
5820 i++;
cristybb503372010-05-27 20:51:26 +00005821 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005822 ThrowMogrifyException(OptionError,"MissingArgument",option);
5823 if (IsGeometry(argv[i]) == MagickFalse)
5824 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5825 break;
5826 }
5827 if (LocaleCompare("scene",option+1) == 0)
5828 {
5829 if (*option == '+')
5830 break;
5831 i++;
cristybb503372010-05-27 20:51:26 +00005832 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005833 ThrowMogrifyException(OptionError,"MissingArgument",option);
5834 if (IsGeometry(argv[i]) == MagickFalse)
5835 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5836 break;
5837 }
5838 if (LocaleCompare("seed",option+1) == 0)
5839 {
5840 if (*option == '+')
5841 break;
5842 i++;
cristybb503372010-05-27 20:51:26 +00005843 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005844 ThrowMogrifyException(OptionError,"MissingArgument",option);
5845 if (IsGeometry(argv[i]) == MagickFalse)
5846 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5847 break;
5848 }
5849 if (LocaleCompare("segment",option+1) == 0)
5850 {
5851 if (*option == '+')
5852 break;
5853 i++;
cristybb503372010-05-27 20:51:26 +00005854 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005855 ThrowMogrifyException(OptionError,"MissingArgument",option);
5856 if (IsGeometry(argv[i]) == MagickFalse)
5857 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5858 break;
5859 }
5860 if (LocaleCompare("selective-blur",option+1) == 0)
5861 {
5862 i++;
cristybb503372010-05-27 20:51:26 +00005863 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005864 ThrowMogrifyException(OptionError,"MissingArgument",option);
5865 if (IsGeometry(argv[i]) == MagickFalse)
5866 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5867 break;
5868 }
5869 if (LocaleCompare("separate",option+1) == 0)
5870 break;
5871 if (LocaleCompare("sepia-tone",option+1) == 0)
5872 {
5873 if (*option == '+')
5874 break;
5875 i++;
cristybb503372010-05-27 20:51:26 +00005876 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005877 ThrowMogrifyException(OptionError,"MissingArgument",option);
5878 if (IsGeometry(argv[i]) == MagickFalse)
5879 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5880 break;
5881 }
5882 if (LocaleCompare("set",option+1) == 0)
5883 {
5884 i++;
cristybb503372010-05-27 20:51:26 +00005885 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005886 ThrowMogrifyException(OptionError,"MissingArgument",option);
5887 if (*option == '+')
5888 break;
5889 i++;
cristybb503372010-05-27 20:51:26 +00005890 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005891 ThrowMogrifyException(OptionError,"MissingArgument",option);
5892 break;
5893 }
5894 if (LocaleCompare("shade",option+1) == 0)
5895 {
5896 i++;
cristybb503372010-05-27 20:51:26 +00005897 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005898 ThrowMogrifyException(OptionError,"MissingArgument",option);
5899 if (IsGeometry(argv[i]) == MagickFalse)
5900 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5901 break;
5902 }
5903 if (LocaleCompare("shadow",option+1) == 0)
5904 {
5905 if (*option == '+')
5906 break;
5907 i++;
cristybb503372010-05-27 20:51:26 +00005908 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005909 ThrowMogrifyException(OptionError,"MissingArgument",option);
5910 if (IsGeometry(argv[i]) == MagickFalse)
5911 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5912 break;
5913 }
5914 if (LocaleCompare("sharpen",option+1) == 0)
5915 {
5916 i++;
cristybb503372010-05-27 20:51:26 +00005917 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005918 ThrowMogrifyException(OptionError,"MissingArgument",option);
5919 if (IsGeometry(argv[i]) == MagickFalse)
5920 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5921 break;
5922 }
5923 if (LocaleCompare("shave",option+1) == 0)
5924 {
5925 if (*option == '+')
5926 break;
5927 i++;
cristybb503372010-05-27 20:51:26 +00005928 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005929 ThrowMogrifyException(OptionError,"MissingArgument",option);
5930 if (IsGeometry(argv[i]) == MagickFalse)
5931 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5932 break;
5933 }
5934 if (LocaleCompare("shear",option+1) == 0)
5935 {
5936 i++;
cristybb503372010-05-27 20:51:26 +00005937 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005938 ThrowMogrifyException(OptionError,"MissingArgument",option);
5939 if (IsGeometry(argv[i]) == MagickFalse)
5940 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5941 break;
5942 }
5943 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
5944 {
5945 i++;
cristybb503372010-05-27 20:51:26 +00005946 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005947 ThrowMogrifyException(OptionError,"MissingArgument",option);
5948 if (IsGeometry(argv[i]) == MagickFalse)
5949 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5950 break;
5951 }
5952 if (LocaleCompare("size",option+1) == 0)
5953 {
5954 if (*option == '+')
5955 break;
5956 i++;
cristybb503372010-05-27 20:51:26 +00005957 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005958 ThrowMogrifyException(OptionError,"MissingArgument",option);
5959 if (IsGeometry(argv[i]) == MagickFalse)
5960 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5961 break;
5962 }
5963 if (LocaleCompare("sketch",option+1) == 0)
5964 {
5965 if (*option == '+')
5966 break;
5967 i++;
cristybb503372010-05-27 20:51:26 +00005968 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005969 ThrowMogrifyException(OptionError,"MissingArgument",option);
5970 if (IsGeometry(argv[i]) == MagickFalse)
5971 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5972 break;
5973 }
5974 if (LocaleCompare("solarize",option+1) == 0)
5975 {
5976 if (*option == '+')
5977 break;
5978 i++;
cristybb503372010-05-27 20:51:26 +00005979 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005980 ThrowMogrifyException(OptionError,"MissingArgument",option);
5981 if (IsGeometry(argv[i]) == MagickFalse)
5982 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5983 break;
5984 }
5985 if (LocaleCompare("sparse-color",option+1) == 0)
5986 {
cristybb503372010-05-27 20:51:26 +00005987 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005988 op;
5989
5990 i++;
cristybb503372010-05-27 20:51:26 +00005991 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005992 ThrowMogrifyException(OptionError,"MissingArgument",option);
5993 op=ParseMagickOption(MagickSparseColorOptions,MagickFalse,argv[i]);
5994 if (op < 0)
5995 ThrowMogrifyException(OptionError,"UnrecognizedSparseColorMethod",
5996 argv[i]);
5997 i++;
cristybb503372010-05-27 20:51:26 +00005998 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005999 ThrowMogrifyException(OptionError,"MissingArgument",option);
6000 break;
6001 }
6002 if (LocaleCompare("spread",option+1) == 0)
6003 {
6004 if (*option == '+')
6005 break;
6006 i++;
cristybb503372010-05-27 20:51:26 +00006007 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006008 ThrowMogrifyException(OptionError,"MissingArgument",option);
6009 if (IsGeometry(argv[i]) == MagickFalse)
6010 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6011 break;
6012 }
6013 if (LocaleCompare("stretch",option+1) == 0)
6014 {
cristybb503372010-05-27 20:51:26 +00006015 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006016 stretch;
6017
6018 if (*option == '+')
6019 break;
6020 i++;
cristybb503372010-05-27 20:51:26 +00006021 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006022 ThrowMogrifyException(OptionError,"MissingArgument",option);
6023 stretch=ParseMagickOption(MagickStretchOptions,MagickFalse,argv[i]);
6024 if (stretch < 0)
6025 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
6026 argv[i]);
6027 break;
6028 }
6029 if (LocaleCompare("strip",option+1) == 0)
6030 break;
6031 if (LocaleCompare("stroke",option+1) == 0)
6032 {
6033 if (*option == '+')
6034 break;
6035 i++;
cristybb503372010-05-27 20:51:26 +00006036 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006037 ThrowMogrifyException(OptionError,"MissingArgument",option);
6038 break;
6039 }
6040 if (LocaleCompare("strokewidth",option+1) == 0)
6041 {
6042 if (*option == '+')
6043 break;
6044 i++;
cristybb503372010-05-27 20:51:26 +00006045 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006046 ThrowMogrifyException(OptionError,"MissingArgument",option);
6047 if (IsGeometry(argv[i]) == MagickFalse)
6048 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6049 break;
6050 }
6051 if (LocaleCompare("style",option+1) == 0)
6052 {
cristybb503372010-05-27 20:51:26 +00006053 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006054 style;
6055
6056 if (*option == '+')
6057 break;
6058 i++;
cristybb503372010-05-27 20:51:26 +00006059 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006060 ThrowMogrifyException(OptionError,"MissingArgument",option);
6061 style=ParseMagickOption(MagickStyleOptions,MagickFalse,argv[i]);
6062 if (style < 0)
6063 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
6064 argv[i]);
6065 break;
6066 }
6067 if (LocaleCompare("swirl",option+1) == 0)
6068 {
6069 if (*option == '+')
6070 break;
6071 i++;
cristybb503372010-05-27 20:51:26 +00006072 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006073 ThrowMogrifyException(OptionError,"MissingArgument",option);
6074 if (IsGeometry(argv[i]) == MagickFalse)
6075 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6076 break;
6077 }
6078 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6079 }
6080 case 't':
6081 {
6082 if (LocaleCompare("taint",option+1) == 0)
6083 break;
6084 if (LocaleCompare("texture",option+1) == 0)
6085 {
6086 if (*option == '+')
6087 break;
6088 i++;
cristybb503372010-05-27 20:51:26 +00006089 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006090 ThrowMogrifyException(OptionError,"MissingArgument",option);
6091 break;
6092 }
6093 if (LocaleCompare("tile",option+1) == 0)
6094 {
6095 if (*option == '+')
6096 break;
6097 i++;
cristybb503372010-05-27 20:51:26 +00006098 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006099 ThrowMogrifyException(OptionError,"MissingArgument",option);
6100 break;
6101 }
6102 if (LocaleCompare("tile-offset",option+1) == 0)
6103 {
6104 if (*option == '+')
6105 break;
6106 i++;
cristybb503372010-05-27 20:51:26 +00006107 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006108 ThrowMogrifyException(OptionError,"MissingArgument",option);
6109 if (IsGeometry(argv[i]) == MagickFalse)
6110 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6111 break;
6112 }
6113 if (LocaleCompare("tint",option+1) == 0)
6114 {
6115 if (*option == '+')
6116 break;
6117 i++;
cristybb503372010-05-27 20:51:26 +00006118 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006119 ThrowMogrifyException(OptionError,"MissingArgument",option);
6120 if (IsGeometry(argv[i]) == MagickFalse)
6121 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6122 break;
6123 }
6124 if (LocaleCompare("transform",option+1) == 0)
6125 break;
6126 if (LocaleCompare("transpose",option+1) == 0)
6127 break;
6128 if (LocaleCompare("transverse",option+1) == 0)
6129 break;
6130 if (LocaleCompare("threshold",option+1) == 0)
6131 {
6132 if (*option == '+')
6133 break;
6134 i++;
cristybb503372010-05-27 20:51:26 +00006135 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006136 ThrowMogrifyException(OptionError,"MissingArgument",option);
6137 if (IsGeometry(argv[i]) == MagickFalse)
6138 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6139 break;
6140 }
6141 if (LocaleCompare("thumbnail",option+1) == 0)
6142 {
6143 if (*option == '+')
6144 break;
6145 i++;
cristybb503372010-05-27 20:51:26 +00006146 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006147 ThrowMogrifyException(OptionError,"MissingArgument",option);
6148 if (IsGeometry(argv[i]) == MagickFalse)
6149 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6150 break;
6151 }
6152 if (LocaleCompare("transparent",option+1) == 0)
6153 {
6154 i++;
cristybb503372010-05-27 20:51:26 +00006155 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006156 ThrowMogrifyException(OptionError,"MissingArgument",option);
6157 break;
6158 }
6159 if (LocaleCompare("transparent-color",option+1) == 0)
6160 {
6161 if (*option == '+')
6162 break;
6163 i++;
cristybb503372010-05-27 20:51:26 +00006164 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006165 ThrowMogrifyException(OptionError,"MissingArgument",option);
6166 break;
6167 }
6168 if (LocaleCompare("treedepth",option+1) == 0)
6169 {
6170 if (*option == '+')
6171 break;
6172 i++;
cristybb503372010-05-27 20:51:26 +00006173 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006174 ThrowMogrifyException(OptionError,"MissingArgument",option);
6175 if (IsGeometry(argv[i]) == MagickFalse)
6176 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6177 break;
6178 }
6179 if (LocaleCompare("trim",option+1) == 0)
6180 break;
6181 if (LocaleCompare("type",option+1) == 0)
6182 {
cristybb503372010-05-27 20:51:26 +00006183 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006184 type;
6185
6186 if (*option == '+')
6187 break;
6188 i++;
cristybb503372010-05-27 20:51:26 +00006189 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006190 ThrowMogrifyException(OptionError,"MissingArgument",option);
6191 type=ParseMagickOption(MagickTypeOptions,MagickFalse,argv[i]);
6192 if (type < 0)
6193 ThrowMogrifyException(OptionError,"UnrecognizedImageType",
6194 argv[i]);
6195 break;
6196 }
6197 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6198 }
6199 case 'u':
6200 {
6201 if (LocaleCompare("undercolor",option+1) == 0)
6202 {
6203 if (*option == '+')
6204 break;
6205 i++;
cristybb503372010-05-27 20:51:26 +00006206 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006207 ThrowMogrifyException(OptionError,"MissingArgument",option);
6208 break;
6209 }
6210 if (LocaleCompare("unique-colors",option+1) == 0)
6211 break;
6212 if (LocaleCompare("units",option+1) == 0)
6213 {
cristybb503372010-05-27 20:51:26 +00006214 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006215 units;
6216
6217 if (*option == '+')
6218 break;
6219 i++;
cristybb503372010-05-27 20:51:26 +00006220 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006221 ThrowMogrifyException(OptionError,"MissingArgument",option);
6222 units=ParseMagickOption(MagickResolutionOptions,MagickFalse,
6223 argv[i]);
6224 if (units < 0)
6225 ThrowMogrifyException(OptionError,"UnrecognizedUnitsType",
6226 argv[i]);
6227 break;
6228 }
6229 if (LocaleCompare("unsharp",option+1) == 0)
6230 {
6231 i++;
cristybb503372010-05-27 20:51:26 +00006232 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006233 ThrowMogrifyException(OptionError,"MissingArgument",option);
6234 if (IsGeometry(argv[i]) == MagickFalse)
6235 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6236 break;
6237 }
6238 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6239 }
6240 case 'v':
6241 {
6242 if (LocaleCompare("verbose",option+1) == 0)
6243 {
6244 image_info->verbose=(*option == '-') ? MagickTrue : MagickFalse;
6245 break;
6246 }
6247 if ((LocaleCompare("version",option+1) == 0) ||
6248 (LocaleCompare("-version",option+1) == 0))
6249 {
6250 (void) fprintf(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +00006251 GetMagickVersion((size_t *) NULL));
cristy610b2e22009-10-22 14:59:43 +00006252 (void) fprintf(stdout,"Copyright: %s\n",GetMagickCopyright());
6253 (void) fprintf(stdout,"Features: %s\n\n",GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00006254 break;
6255 }
6256 if (LocaleCompare("view",option+1) == 0)
6257 {
6258 if (*option == '+')
6259 break;
6260 i++;
cristybb503372010-05-27 20:51:26 +00006261 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006262 ThrowMogrifyException(OptionError,"MissingArgument",option);
6263 break;
6264 }
6265 if (LocaleCompare("vignette",option+1) == 0)
6266 {
6267 if (*option == '+')
6268 break;
6269 i++;
cristybb503372010-05-27 20:51:26 +00006270 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006271 ThrowMogrifyException(OptionError,"MissingArgument",option);
6272 if (IsGeometry(argv[i]) == MagickFalse)
6273 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6274 break;
6275 }
6276 if (LocaleCompare("virtual-pixel",option+1) == 0)
6277 {
cristybb503372010-05-27 20:51:26 +00006278 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006279 method;
6280
6281 if (*option == '+')
6282 break;
6283 i++;
cristybb503372010-05-27 20:51:26 +00006284 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006285 ThrowMogrifyException(OptionError,"MissingArgument",option);
6286 method=ParseMagickOption(MagickVirtualPixelOptions,MagickFalse,
6287 argv[i]);
6288 if (method < 0)
6289 ThrowMogrifyException(OptionError,
6290 "UnrecognizedVirtualPixelMethod",argv[i]);
6291 break;
6292 }
6293 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6294 }
6295 case 'w':
6296 {
6297 if (LocaleCompare("wave",option+1) == 0)
6298 {
6299 i++;
cristybb503372010-05-27 20:51:26 +00006300 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006301 ThrowMogrifyException(OptionError,"MissingArgument",option);
6302 if (IsGeometry(argv[i]) == MagickFalse)
6303 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6304 break;
6305 }
6306 if (LocaleCompare("weight",option+1) == 0)
6307 {
6308 if (*option == '+')
6309 break;
6310 i++;
cristybb503372010-05-27 20:51:26 +00006311 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006312 ThrowMogrifyException(OptionError,"MissingArgument",option);
6313 break;
6314 }
6315 if (LocaleCompare("white-point",option+1) == 0)
6316 {
6317 if (*option == '+')
6318 break;
6319 i++;
cristybb503372010-05-27 20:51:26 +00006320 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006321 ThrowMogrifyException(OptionError,"MissingArgument",option);
6322 if (IsGeometry(argv[i]) == MagickFalse)
6323 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6324 break;
6325 }
6326 if (LocaleCompare("white-threshold",option+1) == 0)
6327 {
6328 if (*option == '+')
6329 break;
6330 i++;
cristybb503372010-05-27 20:51:26 +00006331 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006332 ThrowMogrifyException(OptionError,"MissingArgument",option);
6333 if (IsGeometry(argv[i]) == MagickFalse)
6334 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6335 break;
6336 }
6337 if (LocaleCompare("write",option+1) == 0)
6338 {
6339 i++;
cristybb503372010-05-27 20:51:26 +00006340 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006341 ThrowMogrifyException(OptionError,"MissingArgument",option);
6342 break;
6343 }
6344 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6345 }
6346 case '?':
6347 break;
6348 default:
6349 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6350 }
6351 fire=ParseMagickOption(MagickImageListOptions,MagickFalse,option+1) < 0 ?
6352 MagickFalse : MagickTrue;
6353 if (fire != MagickFalse)
6354 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
6355 }
6356 if (k != 0)
6357 ThrowMogrifyException(OptionError,"UnbalancedParenthesis",argv[i]);
cristycee97112010-05-28 00:44:52 +00006358 if (i != (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006359 ThrowMogrifyException(OptionError,"MissingAnImageFilename",argv[i]);
6360 DestroyMogrify();
6361 return(status != 0 ? MagickTrue : MagickFalse);
6362}
6363
6364/*
6365%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6366% %
6367% %
6368% %
6369+ M o g r i f y I m a g e I n f o %
6370% %
6371% %
6372% %
6373%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6374%
6375% MogrifyImageInfo() applies image processing settings to the image as
6376% prescribed by command line options.
6377%
6378% The format of the MogrifyImageInfo method is:
6379%
6380% MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,const int argc,
6381% const char **argv,ExceptionInfo *exception)
6382%
6383% A description of each parameter follows:
6384%
6385% o image_info: the image info..
6386%
6387% o argc: Specifies a pointer to an integer describing the number of
6388% elements in the argument vector.
6389%
6390% o argv: Specifies a pointer to a text array containing the command line
6391% arguments.
6392%
6393% o exception: return any errors or warnings in this structure.
6394%
6395*/
6396WandExport MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,
6397 const int argc,const char **argv,ExceptionInfo *exception)
6398{
6399 const char
6400 *option;
6401
6402 GeometryInfo
6403 geometry_info;
6404
cristybb503372010-05-27 20:51:26 +00006405 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006406 count;
6407
cristybb503372010-05-27 20:51:26 +00006408 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006409 i;
6410
6411 /*
6412 Initialize method variables.
6413 */
6414 assert(image_info != (ImageInfo *) NULL);
6415 assert(image_info->signature == MagickSignature);
6416 if (image_info->debug != MagickFalse)
6417 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
6418 image_info->filename);
6419 if (argc < 0)
6420 return(MagickTrue);
6421 /*
6422 Set the image settings.
6423 */
cristybb503372010-05-27 20:51:26 +00006424 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00006425 {
6426 option=argv[i];
6427 if (IsMagickOption(option) == MagickFalse)
6428 continue;
6429 count=MagickMax(ParseMagickOption(MagickCommandOptions,MagickFalse,option),
6430 0L);
cristycee97112010-05-28 00:44:52 +00006431 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006432 break;
6433 switch (*(option+1))
6434 {
6435 case 'a':
6436 {
6437 if (LocaleCompare("adjoin",option+1) == 0)
6438 {
6439 image_info->adjoin=(*option == '-') ? MagickTrue : MagickFalse;
6440 break;
6441 }
6442 if (LocaleCompare("antialias",option+1) == 0)
6443 {
6444 image_info->antialias=(*option == '-') ? MagickTrue : MagickFalse;
6445 break;
6446 }
6447 if (LocaleCompare("attenuate",option+1) == 0)
6448 {
6449 if (*option == '+')
6450 {
6451 (void) DeleteImageOption(image_info,option+1);
6452 break;
6453 }
6454 (void) SetImageOption(image_info,option+1,argv[i+1]);
6455 break;
6456 }
6457 if (LocaleCompare("authenticate",option+1) == 0)
6458 {
6459 if (*option == '+')
6460 (void) CloneString(&image_info->authenticate,(char *) NULL);
6461 else
6462 (void) CloneString(&image_info->authenticate,argv[i+1]);
6463 break;
6464 }
6465 break;
6466 }
6467 case 'b':
6468 {
6469 if (LocaleCompare("background",option+1) == 0)
6470 {
6471 if (*option == '+')
6472 {
6473 (void) DeleteImageOption(image_info,option+1);
6474 (void) QueryColorDatabase(BackgroundColor,
6475 &image_info->background_color,exception);
6476 break;
6477 }
6478 (void) SetImageOption(image_info,option+1,argv[i+1]);
6479 (void) QueryColorDatabase(argv[i+1],&image_info->background_color,
6480 exception);
6481 break;
6482 }
6483 if (LocaleCompare("bias",option+1) == 0)
6484 {
6485 if (*option == '+')
6486 {
6487 (void) SetImageOption(image_info,option+1,"0.0");
6488 break;
6489 }
6490 (void) SetImageOption(image_info,option+1,argv[i+1]);
6491 break;
6492 }
6493 if (LocaleCompare("black-point-compensation",option+1) == 0)
6494 {
6495 if (*option == '+')
6496 {
6497 (void) SetImageOption(image_info,option+1,"false");
6498 break;
6499 }
6500 (void) SetImageOption(image_info,option+1,"true");
6501 break;
6502 }
6503 if (LocaleCompare("blue-primary",option+1) == 0)
6504 {
6505 if (*option == '+')
6506 {
6507 (void) SetImageOption(image_info,option+1,"0.0");
6508 break;
6509 }
6510 (void) SetImageOption(image_info,option+1,argv[i+1]);
6511 break;
6512 }
6513 if (LocaleCompare("bordercolor",option+1) == 0)
6514 {
6515 if (*option == '+')
6516 {
6517 (void) DeleteImageOption(image_info,option+1);
6518 (void) QueryColorDatabase(BorderColor,&image_info->border_color,
6519 exception);
6520 break;
6521 }
6522 (void) QueryColorDatabase(argv[i+1],&image_info->border_color,
6523 exception);
6524 (void) SetImageOption(image_info,option+1,argv[i+1]);
6525 break;
6526 }
6527 if (LocaleCompare("box",option+1) == 0)
6528 {
6529 if (*option == '+')
6530 {
6531 (void) SetImageOption(image_info,"undercolor","none");
6532 break;
6533 }
6534 (void) SetImageOption(image_info,"undercolor",argv[i+1]);
6535 break;
6536 }
6537 break;
6538 }
6539 case 'c':
6540 {
6541 if (LocaleCompare("cache",option+1) == 0)
6542 {
6543 MagickSizeType
6544 limit;
6545
6546 limit=MagickResourceInfinity;
6547 if (LocaleCompare("unlimited",argv[i+1]) != 0)
cristyf2f27272009-12-17 14:48:46 +00006548 limit=(MagickSizeType) SiPrefixToDouble(argv[i+1],100.0);
cristy3ed852e2009-09-05 21:47:34 +00006549 (void) SetMagickResourceLimit(MemoryResource,limit);
6550 (void) SetMagickResourceLimit(MapResource,2*limit);
6551 break;
6552 }
6553 if (LocaleCompare("caption",option+1) == 0)
6554 {
6555 if (*option == '+')
6556 {
6557 (void) DeleteImageOption(image_info,option+1);
6558 break;
6559 }
6560 (void) SetImageOption(image_info,option+1,argv[i+1]);
6561 break;
6562 }
6563 if (LocaleCompare("channel",option+1) == 0)
6564 {
6565 if (*option == '+')
6566 {
6567 image_info->channel=DefaultChannels;
6568 break;
6569 }
6570 image_info->channel=(ChannelType) ParseChannelOption(argv[i+1]);
6571 break;
6572 }
6573 if (LocaleCompare("colors",option+1) == 0)
6574 {
cristye27293e2009-12-18 02:53:20 +00006575 image_info->colors=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006576 break;
6577 }
6578 if (LocaleCompare("colorspace",option+1) == 0)
6579 {
6580 if (*option == '+')
6581 {
6582 image_info->colorspace=UndefinedColorspace;
6583 (void) SetImageOption(image_info,option+1,"undefined");
6584 break;
6585 }
6586 image_info->colorspace=(ColorspaceType) ParseMagickOption(
6587 MagickColorspaceOptions,MagickFalse,argv[i+1]);
6588 (void) SetImageOption(image_info,option+1,argv[i+1]);
6589 break;
6590 }
6591 if (LocaleCompare("compress",option+1) == 0)
6592 {
6593 if (*option == '+')
6594 {
6595 image_info->compression=UndefinedCompression;
6596 (void) SetImageOption(image_info,option+1,"undefined");
6597 break;
6598 }
6599 image_info->compression=(CompressionType) ParseMagickOption(
6600 MagickCompressOptions,MagickFalse,argv[i+1]);
6601 (void) SetImageOption(image_info,option+1,argv[i+1]);
6602 break;
6603 }
6604 if (LocaleCompare("comment",option+1) == 0)
6605 {
6606 if (*option == '+')
6607 {
6608 (void) DeleteImageOption(image_info,option+1);
6609 break;
6610 }
6611 (void) SetImageOption(image_info,option+1,argv[i+1]);
6612 break;
6613 }
6614 if (LocaleCompare("compose",option+1) == 0)
6615 {
6616 if (*option == '+')
6617 {
6618 (void) SetImageOption(image_info,option+1,"undefined");
6619 break;
6620 }
6621 (void) SetImageOption(image_info,option+1,argv[i+1]);
6622 break;
6623 }
6624 if (LocaleCompare("compress",option+1) == 0)
6625 {
6626 if (*option == '+')
6627 {
6628 image_info->compression=UndefinedCompression;
6629 (void) SetImageOption(image_info,option+1,"undefined");
6630 break;
6631 }
6632 image_info->compression=(CompressionType) ParseMagickOption(
6633 MagickCompressOptions,MagickFalse,argv[i+1]);
6634 (void) SetImageOption(image_info,option+1,argv[i+1]);
6635 break;
6636 }
6637 break;
6638 }
6639 case 'd':
6640 {
6641 if (LocaleCompare("debug",option+1) == 0)
6642 {
6643 if (*option == '+')
6644 (void) SetLogEventMask("none");
6645 else
6646 (void) SetLogEventMask(argv[i+1]);
6647 image_info->debug=IsEventLogging();
6648 break;
6649 }
6650 if (LocaleCompare("define",option+1) == 0)
6651 {
6652 if (*option == '+')
6653 {
6654 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6655 (void) DeleteImageRegistry(argv[i+1]+9);
6656 else
6657 (void) DeleteImageOption(image_info,argv[i+1]);
6658 break;
6659 }
6660 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6661 {
6662 (void) DefineImageRegistry(StringRegistryType,argv[i+1]+9,
6663 exception);
6664 break;
6665 }
6666 (void) DefineImageOption(image_info,argv[i+1]);
6667 break;
6668 }
6669 if (LocaleCompare("delay",option+1) == 0)
6670 {
6671 if (*option == '+')
6672 {
6673 (void) SetImageOption(image_info,option+1,"0");
6674 break;
6675 }
6676 (void) SetImageOption(image_info,option+1,argv[i+1]);
6677 break;
6678 }
6679 if (LocaleCompare("density",option+1) == 0)
6680 {
6681 /*
6682 Set image density.
6683 */
6684 if (*option == '+')
6685 {
6686 if (image_info->density != (char *) NULL)
6687 image_info->density=DestroyString(image_info->density);
6688 (void) SetImageOption(image_info,option+1,"72");
6689 break;
6690 }
6691 (void) CloneString(&image_info->density,argv[i+1]);
6692 (void) SetImageOption(image_info,option+1,argv[i+1]);
6693 break;
6694 }
6695 if (LocaleCompare("depth",option+1) == 0)
6696 {
6697 if (*option == '+')
6698 {
6699 image_info->depth=MAGICKCORE_QUANTUM_DEPTH;
6700 break;
6701 }
cristye27293e2009-12-18 02:53:20 +00006702 image_info->depth=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006703 break;
6704 }
cristyc9b12952010-03-28 01:12:28 +00006705 if (LocaleCompare("direction",option+1) == 0)
6706 {
6707 if (*option == '+')
6708 {
6709 (void) SetImageOption(image_info,option+1,"undefined");
6710 break;
6711 }
6712 (void) SetImageOption(image_info,option+1,argv[i+1]);
6713 break;
6714 }
cristy3ed852e2009-09-05 21:47:34 +00006715 if (LocaleCompare("display",option+1) == 0)
6716 {
6717 if (*option == '+')
6718 {
6719 if (image_info->server_name != (char *) NULL)
6720 image_info->server_name=DestroyString(
6721 image_info->server_name);
6722 break;
6723 }
6724 (void) CloneString(&image_info->server_name,argv[i+1]);
6725 break;
6726 }
6727 if (LocaleCompare("dispose",option+1) == 0)
6728 {
6729 if (*option == '+')
6730 {
6731 (void) SetImageOption(image_info,option+1,"undefined");
6732 break;
6733 }
6734 (void) SetImageOption(image_info,option+1,argv[i+1]);
6735 break;
6736 }
6737 if (LocaleCompare("dither",option+1) == 0)
6738 {
6739 if (*option == '+')
6740 {
6741 image_info->dither=MagickFalse;
cristyd5acfd12010-06-15 00:11:38 +00006742 (void) SetImageOption(image_info,option+1,"none");
cristy3ed852e2009-09-05 21:47:34 +00006743 break;
6744 }
6745 (void) SetImageOption(image_info,option+1,argv[i+1]);
6746 image_info->dither=MagickTrue;
6747 break;
6748 }
6749 break;
6750 }
6751 case 'e':
6752 {
6753 if (LocaleCompare("encoding",option+1) == 0)
6754 {
6755 if (*option == '+')
6756 {
6757 (void) SetImageOption(image_info,option+1,"undefined");
6758 break;
6759 }
6760 (void) SetImageOption(image_info,option+1,argv[i+1]);
6761 break;
6762 }
6763 if (LocaleCompare("endian",option+1) == 0)
6764 {
6765 if (*option == '+')
6766 {
6767 image_info->endian=UndefinedEndian;
6768 (void) SetImageOption(image_info,option+1,"undefined");
6769 break;
6770 }
6771 image_info->endian=(EndianType) ParseMagickOption(
6772 MagickEndianOptions,MagickFalse,argv[i+1]);
6773 (void) SetImageOption(image_info,option+1,argv[i+1]);
6774 break;
6775 }
6776 if (LocaleCompare("extract",option+1) == 0)
6777 {
6778 /*
6779 Set image extract geometry.
6780 */
6781 if (*option == '+')
6782 {
6783 if (image_info->extract != (char *) NULL)
6784 image_info->extract=DestroyString(image_info->extract);
6785 break;
6786 }
6787 (void) CloneString(&image_info->extract,argv[i+1]);
6788 break;
6789 }
6790 break;
6791 }
6792 case 'f':
6793 {
6794 if (LocaleCompare("fill",option+1) == 0)
6795 {
6796 if (*option == '+')
6797 {
6798 (void) SetImageOption(image_info,option+1,"none");
6799 break;
6800 }
6801 (void) SetImageOption(image_info,option+1,argv[i+1]);
6802 break;
6803 }
6804 if (LocaleCompare("filter",option+1) == 0)
6805 {
6806 if (*option == '+')
6807 {
6808 (void) SetImageOption(image_info,option+1,"undefined");
6809 break;
6810 }
6811 (void) SetImageOption(image_info,option+1,argv[i+1]);
6812 break;
6813 }
6814 if (LocaleCompare("font",option+1) == 0)
6815 {
6816 if (*option == '+')
6817 {
6818 if (image_info->font != (char *) NULL)
6819 image_info->font=DestroyString(image_info->font);
6820 break;
6821 }
6822 (void) CloneString(&image_info->font,argv[i+1]);
6823 break;
6824 }
6825 if (LocaleCompare("format",option+1) == 0)
6826 {
6827 register const char
6828 *q;
6829
6830 for (q=strchr(argv[i+1],'%'); q != (char *) NULL; q=strchr(q+1,'%'))
6831 if (strchr("gkrz@[#",*(q+1)) != (char *) NULL)
6832 image_info->ping=MagickFalse;
6833 (void) SetImageOption(image_info,option+1,argv[i+1]);
6834 break;
6835 }
6836 if (LocaleCompare("fuzz",option+1) == 0)
6837 {
6838 if (*option == '+')
6839 {
6840 image_info->fuzz=0.0;
6841 (void) SetImageOption(image_info,option+1,"0");
6842 break;
6843 }
cristyf2f27272009-12-17 14:48:46 +00006844 image_info->fuzz=SiPrefixToDouble(argv[i+1],(double) QuantumRange+
cristy3ed852e2009-09-05 21:47:34 +00006845 1.0);
6846 (void) SetImageOption(image_info,option+1,argv[i+1]);
6847 break;
6848 }
6849 break;
6850 }
6851 case 'g':
6852 {
6853 if (LocaleCompare("gravity",option+1) == 0)
6854 {
6855 if (*option == '+')
6856 {
6857 (void) SetImageOption(image_info,option+1,"undefined");
6858 break;
6859 }
6860 (void) SetImageOption(image_info,option+1,argv[i+1]);
6861 break;
6862 }
6863 if (LocaleCompare("green-primary",option+1) == 0)
6864 {
6865 if (*option == '+')
6866 {
6867 (void) SetImageOption(image_info,option+1,"0.0");
6868 break;
6869 }
6870 (void) SetImageOption(image_info,option+1,argv[i+1]);
6871 break;
6872 }
6873 break;
6874 }
6875 case 'i':
6876 {
6877 if (LocaleCompare("intent",option+1) == 0)
6878 {
6879 if (*option == '+')
6880 {
6881 (void) SetImageOption(image_info,option+1,"undefined");
6882 break;
6883 }
6884 (void) SetImageOption(image_info,option+1,argv[i+1]);
6885 break;
6886 }
6887 if (LocaleCompare("interlace",option+1) == 0)
6888 {
6889 if (*option == '+')
6890 {
6891 image_info->interlace=UndefinedInterlace;
6892 (void) SetImageOption(image_info,option+1,"undefined");
6893 break;
6894 }
6895 image_info->interlace=(InterlaceType) ParseMagickOption(
6896 MagickInterlaceOptions,MagickFalse,argv[i+1]);
6897 (void) SetImageOption(image_info,option+1,argv[i+1]);
6898 break;
6899 }
cristyb32b90a2009-09-07 21:45:48 +00006900 if (LocaleCompare("interline-spacing",option+1) == 0)
6901 {
6902 if (*option == '+')
6903 {
6904 (void) SetImageOption(image_info,option+1,"undefined");
6905 break;
6906 }
6907 (void) SetImageOption(image_info,option+1,argv[i+1]);
6908 break;
6909 }
cristy3ed852e2009-09-05 21:47:34 +00006910 if (LocaleCompare("interpolate",option+1) == 0)
6911 {
6912 if (*option == '+')
6913 {
6914 (void) SetImageOption(image_info,option+1,"undefined");
6915 break;
6916 }
6917 (void) SetImageOption(image_info,option+1,argv[i+1]);
6918 break;
6919 }
6920 if (LocaleCompare("interword-spacing",option+1) == 0)
6921 {
6922 if (*option == '+')
6923 {
6924 (void) SetImageOption(image_info,option+1,"undefined");
6925 break;
6926 }
6927 (void) SetImageOption(image_info,option+1,argv[i+1]);
6928 break;
6929 }
6930 break;
6931 }
6932 case 'k':
6933 {
6934 if (LocaleCompare("kerning",option+1) == 0)
6935 {
6936 if (*option == '+')
6937 {
6938 (void) SetImageOption(image_info,option+1,"undefined");
6939 break;
6940 }
6941 (void) SetImageOption(image_info,option+1,argv[i+1]);
6942 break;
6943 }
6944 break;
6945 }
6946 case 'l':
6947 {
6948 if (LocaleCompare("label",option+1) == 0)
6949 {
6950 if (*option == '+')
6951 {
6952 (void) DeleteImageOption(image_info,option+1);
6953 break;
6954 }
6955 (void) SetImageOption(image_info,option+1,argv[i+1]);
6956 break;
6957 }
6958 if (LocaleCompare("limit",option+1) == 0)
6959 {
6960 MagickSizeType
6961 limit;
6962
6963 ResourceType
6964 type;
6965
6966 if (*option == '+')
6967 break;
6968 type=(ResourceType) ParseMagickOption(MagickResourceOptions,
6969 MagickFalse,argv[i+1]);
6970 limit=MagickResourceInfinity;
6971 if (LocaleCompare("unlimited",argv[i+2]) != 0)
cristyf2f27272009-12-17 14:48:46 +00006972 limit=(MagickSizeType) SiPrefixToDouble(argv[i+2],100.0);
cristy3ed852e2009-09-05 21:47:34 +00006973 (void) SetMagickResourceLimit(type,limit);
6974 break;
6975 }
6976 if (LocaleCompare("list",option+1) == 0)
6977 {
cristybb503372010-05-27 20:51:26 +00006978 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006979 list;
6980
6981 /*
6982 Display configuration list.
6983 */
6984 list=ParseMagickOption(MagickListOptions,MagickFalse,argv[i+1]);
6985 switch (list)
6986 {
6987 case MagickCoderOptions:
6988 {
6989 (void) ListCoderInfo((FILE *) NULL,exception);
6990 break;
6991 }
6992 case MagickColorOptions:
6993 {
6994 (void) ListColorInfo((FILE *) NULL,exception);
6995 break;
6996 }
6997 case MagickConfigureOptions:
6998 {
6999 (void) ListConfigureInfo((FILE *) NULL,exception);
7000 break;
7001 }
7002 case MagickDelegateOptions:
7003 {
7004 (void) ListDelegateInfo((FILE *) NULL,exception);
7005 break;
7006 }
7007 case MagickFontOptions:
7008 {
7009 (void) ListTypeInfo((FILE *) NULL,exception);
7010 break;
7011 }
7012 case MagickFormatOptions:
7013 {
7014 (void) ListMagickInfo((FILE *) NULL,exception);
7015 break;
7016 }
7017 case MagickLocaleOptions:
7018 {
7019 (void) ListLocaleInfo((FILE *) NULL,exception);
7020 break;
7021 }
7022 case MagickLogOptions:
7023 {
7024 (void) ListLogInfo((FILE *) NULL,exception);
7025 break;
7026 }
7027 case MagickMagicOptions:
7028 {
7029 (void) ListMagicInfo((FILE *) NULL,exception);
7030 break;
7031 }
7032 case MagickMimeOptions:
7033 {
7034 (void) ListMimeInfo((FILE *) NULL,exception);
7035 break;
7036 }
7037 case MagickModuleOptions:
7038 {
7039 (void) ListModuleInfo((FILE *) NULL,exception);
7040 break;
7041 }
7042 case MagickPolicyOptions:
7043 {
7044 (void) ListPolicyInfo((FILE *) NULL,exception);
7045 break;
7046 }
7047 case MagickResourceOptions:
7048 {
7049 (void) ListMagickResourceInfo((FILE *) NULL,exception);
7050 break;
7051 }
7052 case MagickThresholdOptions:
7053 {
7054 (void) ListThresholdMaps((FILE *) NULL,exception);
7055 break;
7056 }
7057 default:
7058 {
7059 (void) ListMagickOptions((FILE *) NULL,(MagickOption) list,
7060 exception);
7061 break;
7062 }
7063 }
cristyaeb2cbc2010-05-07 13:28:58 +00007064 break;
cristy3ed852e2009-09-05 21:47:34 +00007065 }
7066 if (LocaleCompare("log",option+1) == 0)
7067 {
7068 if (*option == '+')
7069 break;
7070 (void) SetLogFormat(argv[i+1]);
7071 break;
7072 }
7073 if (LocaleCompare("loop",option+1) == 0)
7074 {
7075 if (*option == '+')
7076 {
7077 (void) SetImageOption(image_info,option+1,"0");
7078 break;
7079 }
7080 (void) SetImageOption(image_info,option+1,argv[i+1]);
7081 break;
7082 }
7083 break;
7084 }
7085 case 'm':
7086 {
7087 if (LocaleCompare("matte",option+1) == 0)
7088 {
7089 if (*option == '+')
7090 {
7091 (void) SetImageOption(image_info,option+1,"false");
7092 break;
7093 }
7094 (void) SetImageOption(image_info,option+1,"true");
7095 break;
7096 }
7097 if (LocaleCompare("mattecolor",option+1) == 0)
7098 {
7099 if (*option == '+')
7100 {
7101 (void) SetImageOption(image_info,option+1,argv[i+1]);
7102 (void) QueryColorDatabase(MatteColor,&image_info->matte_color,
7103 exception);
7104 break;
7105 }
7106 (void) SetImageOption(image_info,option+1,argv[i+1]);
7107 (void) QueryColorDatabase(argv[i+1],&image_info->matte_color,
7108 exception);
7109 break;
7110 }
7111 if (LocaleCompare("monitor",option+1) == 0)
7112 {
7113 (void) SetImageInfoProgressMonitor(image_info,MonitorProgress,
7114 (void *) NULL);
7115 break;
7116 }
7117 if (LocaleCompare("monochrome",option+1) == 0)
7118 {
7119 image_info->monochrome=(*option == '-') ? MagickTrue : MagickFalse;
7120 break;
7121 }
7122 break;
7123 }
7124 case 'o':
7125 {
7126 if (LocaleCompare("orient",option+1) == 0)
7127 {
7128 if (*option == '+')
7129 {
7130 image_info->orientation=UndefinedOrientation;
7131 (void) SetImageOption(image_info,option+1,"undefined");
7132 break;
7133 }
7134 image_info->orientation=(OrientationType) ParseMagickOption(
7135 MagickOrientationOptions,MagickFalse,argv[i+1]);
cristyc6e214d2010-08-08 00:31:08 +00007136 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007137 break;
7138 }
7139 }
7140 case 'p':
7141 {
7142 if (LocaleCompare("page",option+1) == 0)
7143 {
7144 char
7145 *canonical_page,
7146 page[MaxTextExtent];
7147
7148 const char
7149 *image_option;
7150
7151 MagickStatusType
7152 flags;
7153
7154 RectangleInfo
7155 geometry;
7156
7157 if (*option == '+')
7158 {
7159 (void) DeleteImageOption(image_info,option+1);
7160 (void) CloneString(&image_info->page,(char *) NULL);
7161 break;
7162 }
7163 (void) ResetMagickMemory(&geometry,0,sizeof(geometry));
7164 image_option=GetImageOption(image_info,"page");
7165 if (image_option != (const char *) NULL)
7166 flags=ParseAbsoluteGeometry(image_option,&geometry);
7167 canonical_page=GetPageGeometry(argv[i+1]);
7168 flags=ParseAbsoluteGeometry(canonical_page,&geometry);
7169 canonical_page=DestroyString(canonical_page);
7170 (void) FormatMagickString(page,MaxTextExtent,"%lux%lu",
cristyf2faecf2010-05-28 19:19:36 +00007171 (unsigned long) geometry.width,(unsigned long) geometry.height);
cristy3ed852e2009-09-05 21:47:34 +00007172 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
7173 (void) FormatMagickString(page,MaxTextExtent,"%lux%lu%+ld%+ld",
cristyf2faecf2010-05-28 19:19:36 +00007174 (unsigned long) geometry.width,(unsigned long) geometry.height,
7175 (long) geometry.x,(long) geometry.y);
cristy3ed852e2009-09-05 21:47:34 +00007176 (void) SetImageOption(image_info,option+1,page);
7177 (void) CloneString(&image_info->page,page);
7178 break;
7179 }
7180 if (LocaleCompare("pen",option+1) == 0)
7181 {
7182 if (*option == '+')
7183 {
7184 (void) SetImageOption(image_info,option+1,"none");
7185 break;
7186 }
7187 (void) SetImageOption(image_info,option+1,argv[i+1]);
7188 break;
7189 }
7190 if (LocaleCompare("ping",option+1) == 0)
7191 {
7192 image_info->ping=(*option == '-') ? MagickTrue : MagickFalse;
7193 break;
7194 }
7195 if (LocaleCompare("pointsize",option+1) == 0)
7196 {
7197 if (*option == '+')
7198 geometry_info.rho=0.0;
7199 else
7200 (void) ParseGeometry(argv[i+1],&geometry_info);
7201 image_info->pointsize=geometry_info.rho;
7202 break;
7203 }
cristye7f51092010-01-17 00:39:37 +00007204 if (LocaleCompare("precision",option+1) == 0)
7205 {
cristybf2766a2010-01-17 03:33:23 +00007206 (void) SetMagickPrecision(StringToInteger(argv[i+1]));
cristye7f51092010-01-17 00:39:37 +00007207 break;
7208 }
cristy3ed852e2009-09-05 21:47:34 +00007209 if (LocaleCompare("preview",option+1) == 0)
7210 {
7211 /*
7212 Preview image.
7213 */
7214 if (*option == '+')
7215 {
7216 image_info->preview_type=UndefinedPreview;
7217 break;
7218 }
7219 image_info->preview_type=(PreviewType) ParseMagickOption(
7220 MagickPreviewOptions,MagickFalse,argv[i+1]);
7221 break;
7222 }
7223 break;
7224 }
7225 case 'q':
7226 {
7227 if (LocaleCompare("quality",option+1) == 0)
7228 {
7229 /*
7230 Set image compression quality.
7231 */
7232 if (*option == '+')
7233 {
7234 image_info->quality=UndefinedCompressionQuality;
7235 (void) SetImageOption(image_info,option+1,"0");
7236 break;
7237 }
cristye27293e2009-12-18 02:53:20 +00007238 image_info->quality=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007239 (void) SetImageOption(image_info,option+1,argv[i+1]);
7240 break;
7241 }
7242 if (LocaleCompare("quiet",option+1) == 0)
7243 {
7244 static WarningHandler
7245 warning_handler = (WarningHandler) NULL;
7246
7247 if (*option == '+')
7248 {
7249 /*
7250 Restore error or warning messages.
7251 */
7252 warning_handler=SetWarningHandler(warning_handler);
7253 break;
7254 }
7255 /*
7256 Suppress error or warning messages.
7257 */
7258 warning_handler=SetWarningHandler((WarningHandler) NULL);
7259 break;
7260 }
7261 break;
7262 }
7263 case 'r':
7264 {
7265 if (LocaleCompare("red-primary",option+1) == 0)
7266 {
7267 if (*option == '+')
7268 {
7269 (void) SetImageOption(image_info,option+1,"0.0");
7270 break;
7271 }
7272 (void) SetImageOption(image_info,option+1,argv[i+1]);
7273 break;
7274 }
7275 break;
7276 }
7277 case 's':
7278 {
7279 if (LocaleCompare("sampling-factor",option+1) == 0)
7280 {
7281 /*
7282 Set image sampling factor.
7283 */
7284 if (*option == '+')
7285 {
7286 if (image_info->sampling_factor != (char *) NULL)
7287 image_info->sampling_factor=DestroyString(
7288 image_info->sampling_factor);
7289 break;
7290 }
7291 (void) CloneString(&image_info->sampling_factor,argv[i+1]);
7292 break;
7293 }
7294 if (LocaleCompare("scene",option+1) == 0)
7295 {
7296 /*
7297 Set image scene.
7298 */
7299 if (*option == '+')
7300 {
7301 image_info->scene=0;
7302 (void) SetImageOption(image_info,option+1,"0");
7303 break;
7304 }
cristye27293e2009-12-18 02:53:20 +00007305 image_info->scene=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007306 (void) SetImageOption(image_info,option+1,argv[i+1]);
7307 break;
7308 }
7309 if (LocaleCompare("seed",option+1) == 0)
7310 {
cristybb503372010-05-27 20:51:26 +00007311 size_t
cristy3ed852e2009-09-05 21:47:34 +00007312 seed;
7313
7314 if (*option == '+')
7315 {
cristybb503372010-05-27 20:51:26 +00007316 seed=(size_t) time((time_t *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00007317 SeedPseudoRandomGenerator(seed);
7318 break;
7319 }
cristye27293e2009-12-18 02:53:20 +00007320 seed=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007321 SeedPseudoRandomGenerator(seed);
7322 break;
7323 }
7324 if (LocaleCompare("size",option+1) == 0)
7325 {
7326 if (*option == '+')
7327 {
7328 if (image_info->size != (char *) NULL)
7329 image_info->size=DestroyString(image_info->size);
7330 break;
7331 }
7332 (void) CloneString(&image_info->size,argv[i+1]);
7333 break;
7334 }
7335 if (LocaleCompare("stroke",option+1) == 0)
7336 {
7337 if (*option == '+')
7338 {
7339 (void) SetImageOption(image_info,option+1,"none");
7340 break;
7341 }
7342 (void) SetImageOption(image_info,option+1,argv[i+1]);
7343 break;
7344 }
7345 if (LocaleCompare("strokewidth",option+1) == 0)
7346 {
7347 if (*option == '+')
7348 {
7349 (void) SetImageOption(image_info,option+1,"0");
7350 break;
7351 }
7352 (void) SetImageOption(image_info,option+1,argv[i+1]);
7353 break;
7354 }
7355 break;
7356 }
7357 case 't':
7358 {
7359 if (LocaleCompare("taint",option+1) == 0)
7360 {
7361 if (*option == '+')
7362 {
7363 (void) SetImageOption(image_info,option+1,"false");
7364 break;
7365 }
7366 (void) SetImageOption(image_info,option+1,"true");
7367 break;
7368 }
7369 if (LocaleCompare("texture",option+1) == 0)
7370 {
7371 if (*option == '+')
7372 {
7373 if (image_info->texture != (char *) NULL)
7374 image_info->texture=DestroyString(image_info->texture);
7375 break;
7376 }
7377 (void) CloneString(&image_info->texture,argv[i+1]);
7378 break;
7379 }
7380 if (LocaleCompare("tile-offset",option+1) == 0)
7381 {
7382 if (*option == '+')
7383 {
7384 (void) SetImageOption(image_info,option+1,"0");
7385 break;
7386 }
7387 (void) SetImageOption(image_info,option+1,argv[i+1]);
7388 break;
7389 }
7390 if (LocaleCompare("transparent-color",option+1) == 0)
7391 {
7392 if (*option == '+')
7393 {
7394 (void) QueryColorDatabase("none",&image_info->transparent_color, exception);
7395 (void) SetImageOption(image_info,option+1,"none");
7396 break;
7397 }
7398 (void) QueryColorDatabase(argv[i+1],&image_info->transparent_color,
7399 exception);
7400 (void) SetImageOption(image_info,option+1,argv[i+1]);
7401 break;
7402 }
7403 if (LocaleCompare("type",option+1) == 0)
7404 {
7405 if (*option == '+')
7406 {
7407 image_info->type=UndefinedType;
7408 (void) SetImageOption(image_info,option+1,"undefined");
7409 break;
7410 }
7411 image_info->type=(ImageType) ParseMagickOption(MagickTypeOptions,
7412 MagickFalse,argv[i+1]);
7413 (void) SetImageOption(image_info,option+1,argv[i+1]);
7414 break;
7415 }
7416 break;
7417 }
7418 case 'u':
7419 {
7420 if (LocaleCompare("undercolor",option+1) == 0)
7421 {
7422 if (*option == '+')
7423 {
7424 (void) DeleteImageOption(image_info,option+1);
7425 break;
7426 }
7427 (void) SetImageOption(image_info,option+1,argv[i+1]);
7428 break;
7429 }
7430 if (LocaleCompare("units",option+1) == 0)
7431 {
7432 if (*option == '+')
7433 {
7434 image_info->units=UndefinedResolution;
7435 (void) SetImageOption(image_info,option+1,"undefined");
7436 break;
7437 }
7438 image_info->units=(ResolutionType) ParseMagickOption(
7439 MagickResolutionOptions,MagickFalse,argv[i+1]);
7440 (void) SetImageOption(image_info,option+1,argv[i+1]);
7441 break;
7442 }
7443 break;
7444 }
7445 case 'v':
7446 {
7447 if (LocaleCompare("verbose",option+1) == 0)
7448 {
7449 if (*option == '+')
7450 {
7451 image_info->verbose=MagickFalse;
7452 break;
7453 }
7454 image_info->verbose=MagickTrue;
7455 image_info->ping=MagickFalse;
7456 break;
7457 }
7458 if (LocaleCompare("view",option+1) == 0)
7459 {
7460 if (*option == '+')
7461 {
7462 if (image_info->view != (char *) NULL)
7463 image_info->view=DestroyString(image_info->view);
7464 break;
7465 }
7466 (void) CloneString(&image_info->view,argv[i+1]);
7467 break;
7468 }
7469 if (LocaleCompare("virtual-pixel",option+1) == 0)
7470 {
7471 if (*option == '+')
7472 {
7473 image_info->virtual_pixel_method=UndefinedVirtualPixelMethod;
7474 (void) SetImageOption(image_info,option+1,"undefined");
7475 break;
7476 }
7477 image_info->virtual_pixel_method=(VirtualPixelMethod)
7478 ParseMagickOption(MagickVirtualPixelOptions,MagickFalse,
7479 argv[i+1]);
7480 (void) SetImageOption(image_info,option+1,argv[i+1]);
7481 break;
7482 }
7483 break;
7484 }
7485 case 'w':
7486 {
7487 if (LocaleCompare("white-point",option+1) == 0)
7488 {
7489 if (*option == '+')
7490 {
7491 (void) SetImageOption(image_info,option+1,"0.0");
7492 break;
7493 }
7494 (void) SetImageOption(image_info,option+1,argv[i+1]);
7495 break;
7496 }
7497 break;
7498 }
7499 default:
7500 break;
7501 }
7502 i+=count;
7503 }
7504 return(MagickTrue);
7505}
7506
7507/*
7508%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7509% %
7510% %
7511% %
7512+ M o g r i f y I m a g e L i s t %
7513% %
7514% %
7515% %
7516%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7517%
7518% MogrifyImageList() applies any command line options that might affect the
7519% entire image list (e.g. -append, -coalesce, etc.).
7520%
7521% The format of the MogrifyImage method is:
7522%
7523% MagickBooleanType MogrifyImageList(ImageInfo *image_info,const int argc,
7524% const char **argv,Image **images,ExceptionInfo *exception)
7525%
7526% A description of each parameter follows:
7527%
7528% o image_info: the image info..
7529%
7530% o argc: Specifies a pointer to an integer describing the number of
7531% elements in the argument vector.
7532%
7533% o argv: Specifies a pointer to a text array containing the command line
7534% arguments.
7535%
7536% o images: the images.
7537%
7538% o exception: return any errors or warnings in this structure.
7539%
7540*/
7541WandExport MagickBooleanType MogrifyImageList(ImageInfo *image_info,
7542 const int argc,const char **argv,Image **images,ExceptionInfo *exception)
7543{
7544 ChannelType
7545 channel;
7546
7547 const char
7548 *option;
7549
cristy6b3da3a2010-06-20 02:21:46 +00007550 ImageInfo
7551 *mogrify_info;
cristy3ed852e2009-09-05 21:47:34 +00007552
7553 MagickStatusType
7554 status;
7555
7556 QuantizeInfo
7557 *quantize_info;
7558
cristybb503372010-05-27 20:51:26 +00007559 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00007560 i;
7561
cristy6b3da3a2010-06-20 02:21:46 +00007562 ssize_t
7563 count,
7564 index;
7565
cristy3ed852e2009-09-05 21:47:34 +00007566 /*
7567 Apply options to the image list.
7568 */
7569 assert(image_info != (ImageInfo *) NULL);
7570 assert(image_info->signature == MagickSignature);
7571 assert(images != (Image **) NULL);
7572 assert((*images)->signature == MagickSignature);
7573 if ((*images)->debug != MagickFalse)
7574 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
7575 (*images)->filename);
7576 if ((argc <= 0) || (*argv == (char *) NULL))
7577 return(MagickTrue);
cristy6b3da3a2010-06-20 02:21:46 +00007578 mogrify_info=CloneImageInfo(image_info);
7579 quantize_info=AcquireQuantizeInfo(mogrify_info);
7580 channel=mogrify_info->channel;
cristy3ed852e2009-09-05 21:47:34 +00007581 status=MagickTrue;
cristybb503372010-05-27 20:51:26 +00007582 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00007583 {
cristy74fe8f12009-10-03 19:09:01 +00007584 if (*images == (Image *) NULL)
7585 break;
cristy3ed852e2009-09-05 21:47:34 +00007586 option=argv[i];
7587 if (IsMagickOption(option) == MagickFalse)
7588 continue;
7589 count=MagickMax(ParseMagickOption(MagickCommandOptions,MagickFalse,option),
7590 0L);
cristycee97112010-05-28 00:44:52 +00007591 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00007592 break;
cristy6b3da3a2010-06-20 02:21:46 +00007593 status=MogrifyImageInfo(mogrify_info,(int) count+1,argv+i,exception);
cristy3ed852e2009-09-05 21:47:34 +00007594 switch (*(option+1))
7595 {
7596 case 'a':
7597 {
7598 if (LocaleCompare("affinity",option+1) == 0)
7599 {
cristy6b3da3a2010-06-20 02:21:46 +00007600 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007601 if (*option == '+')
7602 {
7603 (void) RemapImages(quantize_info,*images,(Image *) NULL);
7604 InheritException(exception,&(*images)->exception);
7605 break;
7606 }
7607 i++;
7608 break;
7609 }
7610 if (LocaleCompare("append",option+1) == 0)
7611 {
7612 Image
7613 *append_image;
7614
cristy6b3da3a2010-06-20 02:21:46 +00007615 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007616 append_image=AppendImages(*images,*option == '-' ? MagickTrue :
7617 MagickFalse,exception);
7618 if (append_image == (Image *) NULL)
7619 {
7620 status=MagickFalse;
7621 break;
7622 }
7623 *images=DestroyImageList(*images);
7624 *images=append_image;
7625 break;
7626 }
7627 if (LocaleCompare("average",option+1) == 0)
7628 {
7629 Image
7630 *average_image;
7631
cristyd18ae7c2010-03-07 17:39:52 +00007632 /*
7633 Average an image sequence (deprecated).
7634 */
cristy6b3da3a2010-06-20 02:21:46 +00007635 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007636 average_image=EvaluateImages(*images,MeanEvaluateOperator,
7637 exception);
cristy3ed852e2009-09-05 21:47:34 +00007638 if (average_image == (Image *) NULL)
7639 {
7640 status=MagickFalse;
7641 break;
7642 }
7643 *images=DestroyImageList(*images);
7644 *images=average_image;
7645 break;
7646 }
7647 break;
7648 }
7649 case 'c':
7650 {
7651 if (LocaleCompare("channel",option+1) == 0)
7652 {
7653 if (*option == '+')
7654 {
7655 channel=DefaultChannels;
7656 break;
7657 }
7658 channel=(ChannelType) ParseChannelOption(argv[i+1]);
7659 break;
7660 }
7661 if (LocaleCompare("clut",option+1) == 0)
7662 {
7663 Image
7664 *clut_image,
7665 *image;
7666
cristy6b3da3a2010-06-20 02:21:46 +00007667 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007668 image=RemoveFirstImageFromList(images);
7669 clut_image=RemoveFirstImageFromList(images);
7670 if (clut_image == (Image *) NULL)
7671 {
7672 status=MagickFalse;
7673 break;
7674 }
7675 (void) ClutImageChannel(image,channel,clut_image);
7676 clut_image=DestroyImage(clut_image);
7677 InheritException(exception,&image->exception);
7678 *images=DestroyImageList(*images);
7679 *images=image;
7680 break;
7681 }
7682 if (LocaleCompare("coalesce",option+1) == 0)
7683 {
7684 Image
7685 *coalesce_image;
7686
cristy6b3da3a2010-06-20 02:21:46 +00007687 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007688 coalesce_image=CoalesceImages(*images,exception);
7689 if (coalesce_image == (Image *) NULL)
7690 {
7691 status=MagickFalse;
7692 break;
7693 }
7694 *images=DestroyImageList(*images);
7695 *images=coalesce_image;
7696 break;
7697 }
7698 if (LocaleCompare("combine",option+1) == 0)
7699 {
7700 Image
7701 *combine_image;
7702
cristy6b3da3a2010-06-20 02:21:46 +00007703 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007704 combine_image=CombineImages(*images,channel,exception);
7705 if (combine_image == (Image *) NULL)
7706 {
7707 status=MagickFalse;
7708 break;
7709 }
7710 *images=DestroyImageList(*images);
7711 *images=combine_image;
7712 break;
7713 }
7714 if (LocaleCompare("composite",option+1) == 0)
7715 {
7716 Image
7717 *mask_image,
7718 *composite_image,
7719 *image;
7720
7721 RectangleInfo
7722 geometry;
7723
cristy6b3da3a2010-06-20 02:21:46 +00007724 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007725 image=RemoveFirstImageFromList(images);
7726 composite_image=RemoveFirstImageFromList(images);
7727 if (composite_image == (Image *) NULL)
7728 {
7729 status=MagickFalse;
7730 break;
7731 }
7732 (void) TransformImage(&composite_image,(char *) NULL,
7733 composite_image->geometry);
7734 SetGeometry(composite_image,&geometry);
7735 (void) ParseAbsoluteGeometry(composite_image->geometry,&geometry);
7736 GravityAdjustGeometry(image->columns,image->rows,image->gravity,
7737 &geometry);
7738 mask_image=RemoveFirstImageFromList(images);
7739 if (mask_image != (Image *) NULL)
7740 {
7741 if ((image->compose == DisplaceCompositeOp) ||
7742 (image->compose == DistortCompositeOp))
7743 {
7744 /*
7745 Merge Y displacement into X displacement image.
7746 */
7747 (void) CompositeImage(composite_image,CopyGreenCompositeOp,
7748 mask_image,0,0);
7749 mask_image=DestroyImage(mask_image);
7750 }
7751 else
7752 {
7753 /*
7754 Set a blending mask for the composition.
7755 */
7756 image->mask=mask_image;
7757 (void) NegateImage(image->mask,MagickFalse);
7758 }
7759 }
7760 (void) CompositeImageChannel(image,channel,image->compose,
7761 composite_image,geometry.x,geometry.y);
7762 if (image->mask != (Image *) NULL)
7763 image->mask=DestroyImage(image->mask);
7764 composite_image=DestroyImage(composite_image);
7765 InheritException(exception,&image->exception);
7766 *images=DestroyImageList(*images);
7767 *images=image;
7768 break;
7769 }
7770 if (LocaleCompare("crop",option+1) == 0)
7771 {
7772 MagickStatusType
7773 flags;
7774
7775 RectangleInfo
7776 geometry;
7777
cristy6b3da3a2010-06-20 02:21:46 +00007778 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007779 flags=ParseGravityGeometry(*images,argv[i+1],&geometry,exception);
7780 if (((geometry.width == 0) && (geometry.height == 0)) ||
7781 ((flags & XValue) != 0) || ((flags & YValue) != 0))
7782 break;
7783 (void) TransformImages(images,argv[i+1],(char *) NULL);
7784 InheritException(exception,&(*images)->exception);
7785 break;
7786 }
7787 break;
7788 }
7789 case 'd':
7790 {
7791 if (LocaleCompare("deconstruct",option+1) == 0)
7792 {
7793 Image
7794 *deconstruct_image;
7795
cristy6b3da3a2010-06-20 02:21:46 +00007796 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007797 deconstruct_image=DeconstructImages(*images,exception);
7798 if (deconstruct_image == (Image *) NULL)
7799 {
7800 status=MagickFalse;
7801 break;
7802 }
7803 *images=DestroyImageList(*images);
7804 *images=deconstruct_image;
7805 break;
7806 }
7807 if (LocaleCompare("delete",option+1) == 0)
7808 {
7809 if (*option == '+')
7810 DeleteImages(images,"-1",exception);
7811 else
7812 DeleteImages(images,argv[i+1],exception);
7813 break;
7814 }
7815 if (LocaleCompare("dither",option+1) == 0)
7816 {
7817 if (*option == '+')
7818 {
7819 quantize_info->dither=MagickFalse;
7820 break;
7821 }
7822 quantize_info->dither=MagickTrue;
7823 quantize_info->dither_method=(DitherMethod) ParseMagickOption(
7824 MagickDitherOptions,MagickFalse,argv[i+1]);
7825 break;
7826 }
7827 break;
7828 }
cristyd18ae7c2010-03-07 17:39:52 +00007829 case 'e':
7830 {
7831 if (LocaleCompare("evaluate-sequence",option+1) == 0)
7832 {
7833 Image
7834 *evaluate_image;
7835
7836 MagickEvaluateOperator
7837 op;
7838
cristy6b3da3a2010-06-20 02:21:46 +00007839 (void) SyncImageSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007840 op=(MagickEvaluateOperator) ParseMagickOption(MagickEvaluateOptions,
7841 MagickFalse,argv[i+1]);
7842 evaluate_image=EvaluateImages(*images,op,exception);
7843 if (evaluate_image == (Image *) NULL)
7844 {
7845 status=MagickFalse;
7846 break;
7847 }
7848 *images=DestroyImageList(*images);
7849 *images=evaluate_image;
7850 break;
7851 }
7852 break;
7853 }
cristy3ed852e2009-09-05 21:47:34 +00007854 case 'f':
7855 {
cristyf0a247f2009-10-04 00:20:03 +00007856 if (LocaleCompare("fft",option+1) == 0)
7857 {
7858 Image
7859 *fourier_image;
7860
7861 /*
7862 Implements the discrete Fourier transform (DFT).
7863 */
cristy6b3da3a2010-06-20 02:21:46 +00007864 (void) SyncImageSettings(mogrify_info,*images);
cristyf0a247f2009-10-04 00:20:03 +00007865 fourier_image=ForwardFourierTransformImage(*images,*option == '-' ?
7866 MagickTrue : MagickFalse,exception);
7867 if (fourier_image == (Image *) NULL)
7868 break;
7869 *images=DestroyImage(*images);
7870 *images=fourier_image;
7871 break;
7872 }
cristy3ed852e2009-09-05 21:47:34 +00007873 if (LocaleCompare("flatten",option+1) == 0)
7874 {
7875 Image
7876 *flatten_image;
7877
cristy6b3da3a2010-06-20 02:21:46 +00007878 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007879 flatten_image=MergeImageLayers(*images,FlattenLayer,exception);
7880 if (flatten_image == (Image *) NULL)
7881 break;
7882 *images=DestroyImageList(*images);
7883 *images=flatten_image;
7884 break;
7885 }
7886 if (LocaleCompare("fx",option+1) == 0)
7887 {
7888 Image
7889 *fx_image;
7890
cristy6b3da3a2010-06-20 02:21:46 +00007891 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007892 fx_image=FxImageChannel(*images,channel,argv[i+1],exception);
7893 if (fx_image == (Image *) NULL)
7894 {
7895 status=MagickFalse;
7896 break;
7897 }
7898 *images=DestroyImageList(*images);
7899 *images=fx_image;
7900 break;
7901 }
7902 break;
7903 }
7904 case 'h':
7905 {
7906 if (LocaleCompare("hald-clut",option+1) == 0)
7907 {
7908 Image
7909 *hald_image,
7910 *image;
7911
cristy6b3da3a2010-06-20 02:21:46 +00007912 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007913 image=RemoveFirstImageFromList(images);
7914 hald_image=RemoveFirstImageFromList(images);
7915 if (hald_image == (Image *) NULL)
7916 {
7917 status=MagickFalse;
7918 break;
7919 }
7920 (void) HaldClutImageChannel(image,channel,hald_image);
7921 hald_image=DestroyImage(hald_image);
7922 InheritException(exception,&image->exception);
cristy0aff6ea2009-11-14 01:40:53 +00007923 if (*images != (Image *) NULL)
7924 *images=DestroyImageList(*images);
cristy3ed852e2009-09-05 21:47:34 +00007925 *images=image;
7926 break;
7927 }
7928 break;
7929 }
7930 case 'i':
7931 {
7932 if (LocaleCompare("ift",option+1) == 0)
7933 {
7934 Image
cristy8587f882009-11-13 20:28:49 +00007935 *fourier_image,
7936 *magnitude_image,
7937 *phase_image;
cristy3ed852e2009-09-05 21:47:34 +00007938
7939 /*
7940 Implements the inverse fourier discrete Fourier transform (DFT).
7941 */
cristy6b3da3a2010-06-20 02:21:46 +00007942 (void) SyncImagesSettings(mogrify_info,*images);
cristy8587f882009-11-13 20:28:49 +00007943 magnitude_image=RemoveFirstImageFromList(images);
7944 phase_image=RemoveFirstImageFromList(images);
7945 if (phase_image == (Image *) NULL)
7946 {
7947 status=MagickFalse;
7948 break;
7949 }
7950 fourier_image=InverseFourierTransformImage(magnitude_image,
7951 phase_image,*option == '-' ? MagickTrue : MagickFalse,exception);
cristy3ed852e2009-09-05 21:47:34 +00007952 if (fourier_image == (Image *) NULL)
7953 break;
cristy0aff6ea2009-11-14 01:40:53 +00007954 if (*images != (Image *) NULL)
7955 *images=DestroyImage(*images);
cristy3ed852e2009-09-05 21:47:34 +00007956 *images=fourier_image;
7957 break;
7958 }
7959 if (LocaleCompare("insert",option+1) == 0)
7960 {
7961 Image
7962 *p,
7963 *q;
7964
7965 index=0;
7966 if (*option != '+')
cristyf2f27272009-12-17 14:48:46 +00007967 index=StringToLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007968 p=RemoveLastImageFromList(images);
7969 if (p == (Image *) NULL)
7970 {
7971 (void) ThrowMagickException(exception,GetMagickModule(),
7972 OptionError,"NoSuchImage","`%s'",argv[i+1]);
7973 status=MagickFalse;
7974 break;
7975 }
7976 q=p;
7977 if (index == 0)
7978 PrependImageToList(images,q);
7979 else
cristybb503372010-05-27 20:51:26 +00007980 if (index == (ssize_t) GetImageListLength(*images))
cristy3ed852e2009-09-05 21:47:34 +00007981 AppendImageToList(images,q);
7982 else
7983 {
7984 q=GetImageFromList(*images,index-1);
7985 if (q == (Image *) NULL)
7986 {
7987 (void) ThrowMagickException(exception,GetMagickModule(),
7988 OptionError,"NoSuchImage","`%s'",argv[i+1]);
7989 status=MagickFalse;
7990 break;
7991 }
7992 InsertImageInList(&q,p);
7993 }
7994 *images=GetFirstImageInList(q);
7995 break;
7996 }
7997 break;
7998 }
7999 case 'l':
8000 {
8001 if (LocaleCompare("layers",option+1) == 0)
8002 {
8003 Image
8004 *layers;
8005
8006 ImageLayerMethod
8007 method;
8008
cristy6b3da3a2010-06-20 02:21:46 +00008009 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00008010 layers=(Image *) NULL;
8011 method=(ImageLayerMethod) ParseMagickOption(MagickLayerOptions,
8012 MagickFalse,argv[i+1]);
8013 switch (method)
8014 {
8015 case CoalesceLayer:
8016 {
8017 layers=CoalesceImages(*images,exception);
8018 break;
8019 }
8020 case CompareAnyLayer:
8021 case CompareClearLayer:
8022 case CompareOverlayLayer:
8023 default:
8024 {
8025 layers=CompareImageLayers(*images,method,exception);
8026 break;
8027 }
8028 case MergeLayer:
8029 case FlattenLayer:
8030 case MosaicLayer:
8031 case TrimBoundsLayer:
8032 {
8033 layers=MergeImageLayers(*images,method,exception);
8034 break;
8035 }
8036 case DisposeLayer:
8037 {
8038 layers=DisposeImages(*images,exception);
8039 break;
8040 }
8041 case OptimizeImageLayer:
8042 {
8043 layers=OptimizeImageLayers(*images,exception);
8044 break;
8045 }
8046 case OptimizePlusLayer:
8047 {
8048 layers=OptimizePlusImageLayers(*images,exception);
8049 break;
8050 }
8051 case OptimizeTransLayer:
8052 {
8053 OptimizeImageTransparency(*images,exception);
8054 break;
8055 }
8056 case RemoveDupsLayer:
8057 {
8058 RemoveDuplicateLayers(images,exception);
8059 break;
8060 }
8061 case RemoveZeroLayer:
8062 {
8063 RemoveZeroDelayLayers(images,exception);
8064 break;
8065 }
8066 case OptimizeLayer:
8067 {
8068 /*
8069 General Purpose, GIF Animation Optimizer.
8070 */
8071 layers=CoalesceImages(*images,exception);
8072 if (layers == (Image *) NULL)
8073 {
8074 status=MagickFalse;
8075 break;
8076 }
8077 InheritException(exception,&layers->exception);
8078 *images=DestroyImageList(*images);
8079 *images=layers;
8080 layers=OptimizeImageLayers(*images,exception);
8081 if (layers == (Image *) NULL)
8082 {
8083 status=MagickFalse;
8084 break;
8085 }
8086 InheritException(exception,&layers->exception);
8087 *images=DestroyImageList(*images);
8088 *images=layers;
8089 layers=(Image *) NULL;
8090 OptimizeImageTransparency(*images,exception);
8091 InheritException(exception,&(*images)->exception);
8092 (void) RemapImages(quantize_info,*images,(Image *) NULL);
8093 break;
8094 }
8095 case CompositeLayer:
8096 {
8097 CompositeOperator
8098 compose;
8099
8100 Image
8101 *source;
8102
8103 RectangleInfo
8104 geometry;
8105
8106 /*
8107 Split image sequence at the first 'NULL:' image.
8108 */
8109 source=(*images);
8110 while (source != (Image *) NULL)
8111 {
8112 source=GetNextImageInList(source);
8113 if ((source != (Image *) NULL) &&
8114 (LocaleCompare(source->magick,"NULL") == 0))
8115 break;
8116 }
8117 if (source != (Image *) NULL)
8118 {
8119 if ((GetPreviousImageInList(source) == (Image *) NULL) ||
8120 (GetNextImageInList(source) == (Image *) NULL))
8121 source=(Image *) NULL;
8122 else
8123 {
8124 /*
8125 Separate the two lists, junk the null: image.
8126 */
8127 source=SplitImageList(source->previous);
8128 DeleteImageFromList(&source);
8129 }
8130 }
8131 if (source == (Image *) NULL)
8132 {
8133 (void) ThrowMagickException(exception,GetMagickModule(),
8134 OptionError,"MissingNullSeparator","layers Composite");
8135 status=MagickFalse;
8136 break;
8137 }
8138 /*
8139 Adjust offset with gravity and virtual canvas.
8140 */
8141 SetGeometry(*images,&geometry);
8142 (void) ParseAbsoluteGeometry((*images)->geometry,&geometry);
8143 geometry.width=source->page.width != 0 ?
8144 source->page.width : source->columns;
8145 geometry.height=source->page.height != 0 ?
8146 source->page.height : source->rows;
8147 GravityAdjustGeometry((*images)->page.width != 0 ?
8148 (*images)->page.width : (*images)->columns,
8149 (*images)->page.height != 0 ? (*images)->page.height :
8150 (*images)->rows,(*images)->gravity,&geometry);
8151 compose=OverCompositeOp;
cristy6b3da3a2010-06-20 02:21:46 +00008152 option=GetImageOption(mogrify_info,"compose");
cristy3ed852e2009-09-05 21:47:34 +00008153 if (option != (const char *) NULL)
8154 compose=(CompositeOperator) ParseMagickOption(
8155 MagickComposeOptions,MagickFalse,option);
8156 CompositeLayers(*images,compose,source,geometry.x,geometry.y,
8157 exception);
8158 source=DestroyImageList(source);
8159 break;
8160 }
8161 }
8162 if (layers == (Image *) NULL)
8163 break;
8164 InheritException(exception,&layers->exception);
8165 *images=DestroyImageList(*images);
8166 *images=layers;
8167 break;
8168 }
8169 break;
8170 }
8171 case 'm':
8172 {
8173 if (LocaleCompare("map",option+1) == 0)
8174 {
cristy6b3da3a2010-06-20 02:21:46 +00008175 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00008176 if (*option == '+')
8177 {
8178 (void) RemapImages(quantize_info,*images,(Image *) NULL);
8179 InheritException(exception,&(*images)->exception);
8180 break;
8181 }
8182 i++;
8183 break;
8184 }
cristyf40785b2010-03-06 02:27:27 +00008185 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00008186 {
8187 Image
cristyf40785b2010-03-06 02:27:27 +00008188 *maximum_image;
cristy1c274c92010-03-06 02:06:45 +00008189
cristyd18ae7c2010-03-07 17:39:52 +00008190 /*
8191 Maximum image sequence (deprecated).
8192 */
cristy6b3da3a2010-06-20 02:21:46 +00008193 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00008194 maximum_image=EvaluateImages(*images,MaxEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00008195 if (maximum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00008196 {
8197 status=MagickFalse;
8198 break;
8199 }
8200 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00008201 *images=maximum_image;
cristy1c274c92010-03-06 02:06:45 +00008202 break;
8203 }
cristyf40785b2010-03-06 02:27:27 +00008204 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00008205 {
8206 Image
cristyf40785b2010-03-06 02:27:27 +00008207 *minimum_image;
cristy1c274c92010-03-06 02:06:45 +00008208
cristyd18ae7c2010-03-07 17:39:52 +00008209 /*
8210 Minimum image sequence (deprecated).
8211 */
cristy6b3da3a2010-06-20 02:21:46 +00008212 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00008213 minimum_image=EvaluateImages(*images,MinEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00008214 if (minimum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00008215 {
8216 status=MagickFalse;
8217 break;
8218 }
8219 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00008220 *images=minimum_image;
cristy1c274c92010-03-06 02:06:45 +00008221 break;
8222 }
cristy3ed852e2009-09-05 21:47:34 +00008223 if (LocaleCompare("morph",option+1) == 0)
8224 {
8225 Image
8226 *morph_image;
8227
cristy6b3da3a2010-06-20 02:21:46 +00008228 (void) SyncImagesSettings(mogrify_info,*images);
cristye27293e2009-12-18 02:53:20 +00008229 morph_image=MorphImages(*images,StringToUnsignedLong(argv[i+1]),
cristy3ed852e2009-09-05 21:47:34 +00008230 exception);
8231 if (morph_image == (Image *) NULL)
8232 {
8233 status=MagickFalse;
8234 break;
8235 }
8236 *images=DestroyImageList(*images);
8237 *images=morph_image;
8238 break;
8239 }
8240 if (LocaleCompare("mosaic",option+1) == 0)
8241 {
8242 Image
8243 *mosaic_image;
8244
cristy6b3da3a2010-06-20 02:21:46 +00008245 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00008246 mosaic_image=MergeImageLayers(*images,MosaicLayer,exception);
8247 if (mosaic_image == (Image *) NULL)
8248 {
8249 status=MagickFalse;
8250 break;
8251 }
8252 *images=DestroyImageList(*images);
8253 *images=mosaic_image;
8254 break;
8255 }
8256 break;
8257 }
8258 case 'p':
8259 {
8260 if (LocaleCompare("print",option+1) == 0)
8261 {
8262 char
8263 *string;
8264
cristy6b3da3a2010-06-20 02:21:46 +00008265 (void) SyncImagesSettings(mogrify_info,*images);
8266 string=InterpretImageProperties(mogrify_info,*images,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00008267 if (string == (char *) NULL)
8268 break;
8269 InheritException(exception,&(*images)->exception);
8270 (void) fprintf(stdout,"%s",string);
8271 string=DestroyString(string);
8272 }
8273 if (LocaleCompare("process",option+1) == 0)
8274 {
8275 char
8276 **arguments;
8277
8278 int
8279 j,
8280 number_arguments;
8281
cristy6b3da3a2010-06-20 02:21:46 +00008282 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00008283 arguments=StringToArgv(argv[i+1],&number_arguments);
8284 if (arguments == (char **) NULL)
8285 break;
8286 if ((argc > 1) && (strchr(arguments[1],'=') != (char *) NULL))
8287 {
8288 char
8289 breaker,
8290 quote,
8291 *token;
8292
8293 const char
8294 *arguments;
8295
8296 int
8297 next,
8298 status;
8299
8300 size_t
8301 length;
8302
8303 TokenInfo
8304 *token_info;
8305
8306 /*
8307 Support old style syntax, filter="-option arg".
8308 */
8309 length=strlen(argv[i+1]);
8310 token=(char *) NULL;
8311 if (~length >= MaxTextExtent)
8312 token=(char *) AcquireQuantumMemory(length+MaxTextExtent,
8313 sizeof(*token));
8314 if (token == (char *) NULL)
8315 break;
8316 next=0;
8317 arguments=argv[i+1];
8318 token_info=AcquireTokenInfo();
8319 status=Tokenizer(token_info,0,token,length,arguments,"","=",
8320 "\"",'\0',&breaker,&next,&quote);
8321 token_info=DestroyTokenInfo(token_info);
8322 if (status == 0)
8323 {
8324 const char
8325 *argv;
8326
8327 argv=(&(arguments[next]));
8328 (void) InvokeDynamicImageFilter(token,&(*images),1,&argv,
8329 exception);
8330 }
8331 token=DestroyString(token);
8332 break;
8333 }
cristy91c0da22010-05-02 01:44:07 +00008334 (void) SubstituteString(&arguments[1],"-","");
cristy3ed852e2009-09-05 21:47:34 +00008335 (void) InvokeDynamicImageFilter(arguments[1],&(*images),
8336 number_arguments-2,(const char **) arguments+2,exception);
8337 for (j=0; j < number_arguments; j++)
8338 arguments[j]=DestroyString(arguments[j]);
8339 arguments=(char **) RelinquishMagickMemory(arguments);
8340 break;
8341 }
8342 break;
8343 }
8344 case 'r':
8345 {
8346 if (LocaleCompare("reverse",option+1) == 0)
8347 {
8348 ReverseImageList(images);
8349 InheritException(exception,&(*images)->exception);
8350 break;
8351 }
8352 break;
8353 }
8354 case 's':
8355 {
8356 if (LocaleCompare("swap",option+1) == 0)
8357 {
8358 Image
8359 *p,
8360 *q,
8361 *swap;
8362
cristybb503372010-05-27 20:51:26 +00008363 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00008364 swap_index;
8365
8366 index=(-1);
8367 swap_index=(-2);
8368 if (*option != '+')
8369 {
8370 GeometryInfo
8371 geometry_info;
8372
8373 MagickStatusType
8374 flags;
8375
8376 swap_index=(-1);
8377 flags=ParseGeometry(argv[i+1],&geometry_info);
cristybb503372010-05-27 20:51:26 +00008378 index=(ssize_t) geometry_info.rho;
cristy3ed852e2009-09-05 21:47:34 +00008379 if ((flags & SigmaValue) != 0)
cristybb503372010-05-27 20:51:26 +00008380 swap_index=(ssize_t) geometry_info.sigma;
cristy3ed852e2009-09-05 21:47:34 +00008381 }
8382 p=GetImageFromList(*images,index);
8383 q=GetImageFromList(*images,swap_index);
8384 if ((p == (Image *) NULL) || (q == (Image *) NULL))
8385 {
8386 (void) ThrowMagickException(exception,GetMagickModule(),
8387 OptionError,"NoSuchImage","`%s'",(*images)->filename);
8388 status=MagickFalse;
8389 break;
8390 }
8391 if (p == q)
8392 break;
8393 swap=CloneImage(p,0,0,MagickTrue,exception);
8394 ReplaceImageInList(&p,CloneImage(q,0,0,MagickTrue,exception));
8395 ReplaceImageInList(&q,swap);
8396 *images=GetFirstImageInList(q);
8397 break;
8398 }
8399 break;
8400 }
8401 case 'w':
8402 {
8403 if (LocaleCompare("write",option+1) == 0)
8404 {
cristy071dd7b2010-04-09 13:04:54 +00008405 char
cristy06609ee2010-03-17 20:21:27 +00008406 key[MaxTextExtent];
8407
cristy3ed852e2009-09-05 21:47:34 +00008408 Image
8409 *write_images;
8410
8411 ImageInfo
8412 *write_info;
8413
cristy6b3da3a2010-06-20 02:21:46 +00008414 (void) SyncImagesSettings(mogrify_info,*images);
cristy06609ee2010-03-17 20:21:27 +00008415 (void) FormatMagickString(key,MaxTextExtent,"cache:%s",argv[i+1]);
8416 (void) DeleteImageRegistry(key);
cristy3ed852e2009-09-05 21:47:34 +00008417 write_images=(*images);
8418 if (*option == '+')
8419 write_images=CloneImageList(*images,exception);
cristy6b3da3a2010-06-20 02:21:46 +00008420 write_info=CloneImageInfo(mogrify_info);
cristy3ed852e2009-09-05 21:47:34 +00008421 status&=WriteImages(write_info,write_images,argv[i+1],exception);
8422 write_info=DestroyImageInfo(write_info);
8423 if (*option == '+')
8424 write_images=DestroyImageList(write_images);
8425 break;
8426 }
8427 break;
8428 }
8429 default:
8430 break;
8431 }
8432 i+=count;
8433 }
8434 quantize_info=DestroyQuantizeInfo(quantize_info);
cristy6b3da3a2010-06-20 02:21:46 +00008435 mogrify_info=DestroyImageInfo(mogrify_info);
8436 status&=MogrifyImageInfo(image_info,argc,argv,exception);
cristy3ed852e2009-09-05 21:47:34 +00008437 return(status != 0 ? MagickTrue : MagickFalse);
8438}
8439
8440/*
8441%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8442% %
8443% %
8444% %
8445+ M o g r i f y I m a g e s %
8446% %
8447% %
8448% %
8449%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8450%
8451% MogrifyImages() applies image processing options to a sequence of images as
8452% prescribed by command line options.
8453%
8454% The format of the MogrifyImage method is:
8455%
8456% MagickBooleanType MogrifyImages(ImageInfo *image_info,
8457% const MagickBooleanType post,const int argc,const char **argv,
8458% Image **images,Exceptioninfo *exception)
8459%
8460% A description of each parameter follows:
8461%
8462% o image_info: the image info..
8463%
8464% o post: If true, post process image list operators otherwise pre-process.
8465%
8466% o argc: Specifies a pointer to an integer describing the number of
8467% elements in the argument vector.
8468%
8469% o argv: Specifies a pointer to a text array containing the command line
8470% arguments.
8471%
8472% o images: the images.
8473%
8474% o exception: return any errors or warnings in this structure.
8475%
8476*/
8477WandExport MagickBooleanType MogrifyImages(ImageInfo *image_info,
8478 const MagickBooleanType post,const int argc,const char **argv,
8479 Image **images,ExceptionInfo *exception)
8480{
8481#define MogrifyImageTag "Mogrify/Image"
8482
8483 Image
8484 *image,
8485 *mogrify_images;
8486
cristy0e9f9c12010-02-11 03:00:47 +00008487 MagickBooleanType
8488 proceed;
8489
8490 MagickSizeType
8491 number_images;
8492
cristy3ed852e2009-09-05 21:47:34 +00008493 MagickStatusType
8494 status;
8495
cristybb503372010-05-27 20:51:26 +00008496 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00008497 i;
8498
cristy3ed852e2009-09-05 21:47:34 +00008499 /*
8500 Apply options to individual images in the list.
8501 */
8502 assert(image_info != (ImageInfo *) NULL);
8503 assert(image_info->signature == MagickSignature);
8504 if (images == (Image **) NULL)
8505 return(MogrifyImage(image_info,argc,argv,images,exception));
8506 assert((*images)->signature == MagickSignature);
8507 if ((*images)->debug != MagickFalse)
8508 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
8509 (*images)->filename);
8510 if ((argc <= 0) || (*argv == (char *) NULL))
8511 return(MagickTrue);
8512 (void) SetImageInfoProgressMonitor(image_info,(MagickProgressMonitor) NULL,
8513 (void *) NULL);
8514 mogrify_images=NewImageList();
8515 number_images=GetImageListLength(*images);
8516 status=0;
8517 if (post == MagickFalse)
8518 status&=MogrifyImageList(image_info,argc,argv,images,exception);
cristybb503372010-05-27 20:51:26 +00008519 for (i=0; i < (ssize_t) number_images; i++)
cristy3ed852e2009-09-05 21:47:34 +00008520 {
8521 image=RemoveFirstImageFromList(images);
8522 if (image == (Image *) NULL)
8523 continue;
8524 status&=MogrifyImage(image_info,argc,argv,&image,exception);
8525 AppendImageToList(&mogrify_images,image);
cristy0e9f9c12010-02-11 03:00:47 +00008526 proceed=SetImageProgress(image,MogrifyImageTag,(MagickOffsetType) i,
8527 number_images);
8528 if (proceed == MagickFalse)
8529 break;
cristy3ed852e2009-09-05 21:47:34 +00008530 }
8531 if (post != MagickFalse)
8532 status&=MogrifyImageList(image_info,argc,argv,&mogrify_images,exception);
8533 *images=mogrify_images;
8534 return(status != 0 ? MagickTrue : MagickFalse);
8535}