blob: 874f5723ca0670cb5dde2f363dc2a762384f3db7 [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 {
cristyb6bd4ad2010-08-08 01:12:27 +00004153 KernelInfo
4154 *kernel_info;
4155
cristy3ed852e2009-09-05 21:47:34 +00004156 if (*option == '+')
4157 break;
4158 i++;
cristybb503372010-05-27 20:51:26 +00004159 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004160 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00004161 kernel_info=AcquireKernelInfo(argv[i]);
4162 if (kernel_info == (KernelInfo *) NULL)
4163 ThrowConvertInvalidArgumentException(option,argv[i]);
4164 kernel_info=DestroyKernelInfo(kernel_info);
cristy3ed852e2009-09-05 21:47:34 +00004165 break;
4166 }
4167 if (LocaleCompare("alpha",option+1) == 0)
4168 {
cristybb503372010-05-27 20:51:26 +00004169 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004170 type;
4171
4172 if (*option == '+')
4173 break;
4174 i++;
cristybb503372010-05-27 20:51:26 +00004175 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004176 ThrowMogrifyException(OptionError,"MissingArgument",option);
4177 type=ParseMagickOption(MagickAlphaOptions,MagickFalse,argv[i]);
4178 if (type < 0)
4179 ThrowMogrifyException(OptionError,"UnrecognizedAlphaChannelType",
4180 argv[i]);
4181 break;
4182 }
4183 if (LocaleCompare("annotate",option+1) == 0)
4184 {
4185 if (*option == '+')
4186 break;
4187 i++;
cristybb503372010-05-27 20:51:26 +00004188 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004189 ThrowMogrifyException(OptionError,"MissingArgument",option);
4190 if (IsGeometry(argv[i]) == MagickFalse)
4191 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristybb503372010-05-27 20:51:26 +00004192 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004193 ThrowMogrifyException(OptionError,"MissingArgument",option);
4194 i++;
4195 break;
4196 }
4197 if (LocaleCompare("antialias",option+1) == 0)
4198 break;
4199 if (LocaleCompare("append",option+1) == 0)
4200 break;
4201 if (LocaleCompare("attenuate",option+1) == 0)
4202 {
4203 if (*option == '+')
4204 break;
4205 i++;
cristybb503372010-05-27 20:51:26 +00004206 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004207 ThrowMogrifyException(OptionError,"MissingArgument",option);
4208 if (IsGeometry(argv[i]) == MagickFalse)
4209 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4210 break;
4211 }
4212 if (LocaleCompare("authenticate",option+1) == 0)
4213 {
4214 if (*option == '+')
4215 break;
4216 i++;
cristybb503372010-05-27 20:51:26 +00004217 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004218 ThrowMogrifyException(OptionError,"MissingArgument",option);
4219 break;
4220 }
4221 if (LocaleCompare("auto-gamma",option+1) == 0)
4222 break;
4223 if (LocaleCompare("auto-level",option+1) == 0)
4224 break;
4225 if (LocaleCompare("auto-orient",option+1) == 0)
4226 break;
4227 if (LocaleCompare("average",option+1) == 0)
4228 break;
4229 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4230 }
4231 case 'b':
4232 {
4233 if (LocaleCompare("background",option+1) == 0)
4234 {
4235 if (*option == '+')
4236 break;
4237 i++;
cristybb503372010-05-27 20:51:26 +00004238 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004239 ThrowMogrifyException(OptionError,"MissingArgument",option);
4240 break;
4241 }
4242 if (LocaleCompare("bias",option+1) == 0)
4243 {
4244 if (*option == '+')
4245 break;
4246 i++;
cristybb503372010-05-27 20:51:26 +00004247 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004248 ThrowMogrifyException(OptionError,"MissingArgument",option);
4249 if (IsGeometry(argv[i]) == MagickFalse)
4250 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4251 break;
4252 }
4253 if (LocaleCompare("black-point-compensation",option+1) == 0)
4254 break;
4255 if (LocaleCompare("black-threshold",option+1) == 0)
4256 {
4257 if (*option == '+')
4258 break;
4259 i++;
cristybb503372010-05-27 20:51:26 +00004260 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004261 ThrowMogrifyException(OptionError,"MissingArgument",option);
4262 if (IsGeometry(argv[i]) == MagickFalse)
4263 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4264 break;
4265 }
4266 if (LocaleCompare("blue-primary",option+1) == 0)
4267 {
4268 if (*option == '+')
4269 break;
4270 i++;
cristybb503372010-05-27 20:51:26 +00004271 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004272 ThrowMogrifyException(OptionError,"MissingArgument",option);
4273 if (IsGeometry(argv[i]) == MagickFalse)
4274 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4275 break;
4276 }
4277 if (LocaleCompare("blue-shift",option+1) == 0)
4278 {
4279 i++;
cristybb503372010-05-27 20:51:26 +00004280 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004281 ThrowMogrifyException(OptionError,"MissingArgument",option);
4282 if (IsGeometry(argv[i]) == MagickFalse)
4283 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4284 break;
4285 }
4286 if (LocaleCompare("blur",option+1) == 0)
4287 {
4288 i++;
cristybb503372010-05-27 20:51:26 +00004289 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004290 ThrowMogrifyException(OptionError,"MissingArgument",option);
4291 if (IsGeometry(argv[i]) == MagickFalse)
4292 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4293 break;
4294 }
4295 if (LocaleCompare("border",option+1) == 0)
4296 {
4297 if (*option == '+')
4298 break;
4299 i++;
cristybb503372010-05-27 20:51:26 +00004300 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004301 ThrowMogrifyException(OptionError,"MissingArgument",option);
4302 if (IsGeometry(argv[i]) == MagickFalse)
4303 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4304 break;
4305 }
4306 if (LocaleCompare("bordercolor",option+1) == 0)
4307 {
4308 if (*option == '+')
4309 break;
4310 i++;
cristybb503372010-05-27 20:51:26 +00004311 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004312 ThrowMogrifyException(OptionError,"MissingArgument",option);
4313 break;
4314 }
4315 if (LocaleCompare("box",option+1) == 0)
4316 {
4317 if (*option == '+')
4318 break;
4319 i++;
cristybb503372010-05-27 20:51:26 +00004320 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004321 ThrowMogrifyException(OptionError,"MissingArgument",option);
4322 break;
4323 }
cristya28d6b82010-01-11 20:03:47 +00004324 if (LocaleCompare("brightness-contrast",option+1) == 0)
4325 {
4326 i++;
cristybb503372010-05-27 20:51:26 +00004327 if (i == (ssize_t) argc)
cristya28d6b82010-01-11 20:03:47 +00004328 ThrowMogrifyException(OptionError,"MissingArgument",option);
4329 if (IsGeometry(argv[i]) == MagickFalse)
4330 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4331 break;
4332 }
cristy3ed852e2009-09-05 21:47:34 +00004333 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4334 }
4335 case 'c':
4336 {
4337 if (LocaleCompare("cache",option+1) == 0)
4338 {
4339 if (*option == '+')
4340 break;
4341 i++;
cristybb503372010-05-27 20:51:26 +00004342 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004343 ThrowMogrifyException(OptionError,"MissingArgument",option);
4344 if (IsGeometry(argv[i]) == MagickFalse)
4345 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4346 break;
4347 }
4348 if (LocaleCompare("caption",option+1) == 0)
4349 {
4350 if (*option == '+')
4351 break;
4352 i++;
cristybb503372010-05-27 20:51:26 +00004353 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004354 ThrowMogrifyException(OptionError,"MissingArgument",option);
4355 break;
4356 }
4357 if (LocaleCompare("channel",option+1) == 0)
4358 {
cristybb503372010-05-27 20:51:26 +00004359 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004360 channel;
4361
4362 if (*option == '+')
4363 break;
4364 i++;
cristybb503372010-05-27 20:51:26 +00004365 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004366 ThrowMogrifyException(OptionError,"MissingArgument",option);
4367 channel=ParseChannelOption(argv[i]);
4368 if (channel < 0)
4369 ThrowMogrifyException(OptionError,"UnrecognizedChannelType",
4370 argv[i]);
4371 break;
4372 }
4373 if (LocaleCompare("cdl",option+1) == 0)
4374 {
4375 if (*option == '+')
4376 break;
4377 i++;
cristybb503372010-05-27 20:51:26 +00004378 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004379 ThrowMogrifyException(OptionError,"MissingArgument",option);
4380 break;
4381 }
4382 if (LocaleCompare("charcoal",option+1) == 0)
4383 {
4384 if (*option == '+')
4385 break;
4386 i++;
cristybb503372010-05-27 20:51:26 +00004387 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004388 ThrowMogrifyException(OptionError,"MissingArgument",option);
4389 if (IsGeometry(argv[i]) == MagickFalse)
4390 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4391 break;
4392 }
4393 if (LocaleCompare("chop",option+1) == 0)
4394 {
4395 if (*option == '+')
4396 break;
4397 i++;
cristybb503372010-05-27 20:51:26 +00004398 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004399 ThrowMogrifyException(OptionError,"MissingArgument",option);
4400 if (IsGeometry(argv[i]) == MagickFalse)
4401 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4402 break;
4403 }
cristy1eb45dd2009-09-25 16:38:06 +00004404 if (LocaleCompare("clamp",option+1) == 0)
4405 break;
4406 if (LocaleCompare("clip",option+1) == 0)
4407 break;
cristy3ed852e2009-09-05 21:47:34 +00004408 if (LocaleCompare("clip-mask",option+1) == 0)
4409 {
4410 if (*option == '+')
4411 break;
4412 i++;
cristybb503372010-05-27 20:51:26 +00004413 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004414 ThrowMogrifyException(OptionError,"MissingArgument",option);
4415 break;
4416 }
4417 if (LocaleCompare("clut",option+1) == 0)
4418 break;
4419 if (LocaleCompare("coalesce",option+1) == 0)
4420 break;
4421 if (LocaleCompare("colorize",option+1) == 0)
4422 {
4423 if (*option == '+')
4424 break;
4425 i++;
cristybb503372010-05-27 20:51:26 +00004426 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004427 ThrowMogrifyException(OptionError,"MissingArgument",option);
4428 if (IsGeometry(argv[i]) == MagickFalse)
4429 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4430 break;
4431 }
cristye6365592010-04-02 17:31:23 +00004432 if (LocaleCompare("color-matrix",option+1) == 0)
4433 {
cristyb6bd4ad2010-08-08 01:12:27 +00004434 KernelInfo
4435 *kernel_info;
4436
cristye6365592010-04-02 17:31:23 +00004437 if (*option == '+')
4438 break;
4439 i++;
cristybb503372010-05-27 20:51:26 +00004440 if (i == (ssize_t) (argc-1))
cristye6365592010-04-02 17:31:23 +00004441 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00004442 kernel_info=AcquireKernelInfo(argv[i]);
4443 if (kernel_info == (KernelInfo *) NULL)
4444 ThrowConvertInvalidArgumentException(option,argv[i]);
4445 kernel_info=DestroyKernelInfo(kernel_info);
cristye6365592010-04-02 17:31:23 +00004446 break;
4447 }
cristy3ed852e2009-09-05 21:47:34 +00004448 if (LocaleCompare("colors",option+1) == 0)
4449 {
4450 if (*option == '+')
4451 break;
4452 i++;
cristybb503372010-05-27 20:51:26 +00004453 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004454 ThrowMogrifyException(OptionError,"MissingArgument",option);
4455 if (IsGeometry(argv[i]) == MagickFalse)
4456 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4457 break;
4458 }
4459 if (LocaleCompare("colorspace",option+1) == 0)
4460 {
cristybb503372010-05-27 20:51:26 +00004461 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004462 colorspace;
4463
4464 if (*option == '+')
4465 break;
4466 i++;
cristybb503372010-05-27 20:51:26 +00004467 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004468 ThrowMogrifyException(OptionError,"MissingArgument",option);
4469 colorspace=ParseMagickOption(MagickColorspaceOptions,MagickFalse,
4470 argv[i]);
4471 if (colorspace < 0)
4472 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
4473 argv[i]);
4474 break;
4475 }
4476 if (LocaleCompare("combine",option+1) == 0)
4477 break;
4478 if (LocaleCompare("comment",option+1) == 0)
4479 {
4480 if (*option == '+')
4481 break;
4482 i++;
cristybb503372010-05-27 20:51:26 +00004483 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004484 ThrowMogrifyException(OptionError,"MissingArgument",option);
4485 break;
4486 }
4487 if (LocaleCompare("composite",option+1) == 0)
4488 break;
4489 if (LocaleCompare("compress",option+1) == 0)
4490 {
cristybb503372010-05-27 20:51:26 +00004491 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004492 compress;
4493
4494 if (*option == '+')
4495 break;
4496 i++;
cristybb503372010-05-27 20:51:26 +00004497 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004498 ThrowMogrifyException(OptionError,"MissingArgument",option);
4499 compress=ParseMagickOption(MagickCompressOptions,MagickFalse,
4500 argv[i]);
4501 if (compress < 0)
4502 ThrowMogrifyException(OptionError,"UnrecognizedImageCompression",
4503 argv[i]);
4504 break;
4505 }
cristy22879752009-10-25 23:55:40 +00004506 if (LocaleCompare("concurrent",option+1) == 0)
4507 break;
cristy3ed852e2009-09-05 21:47:34 +00004508 if (LocaleCompare("contrast",option+1) == 0)
4509 break;
4510 if (LocaleCompare("contrast-stretch",option+1) == 0)
4511 {
4512 i++;
cristybb503372010-05-27 20:51:26 +00004513 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004514 ThrowMogrifyException(OptionError,"MissingArgument",option);
4515 if (IsGeometry(argv[i]) == MagickFalse)
4516 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4517 break;
4518 }
4519 if (LocaleCompare("convolve",option+1) == 0)
4520 {
anthony29188a82010-01-22 10:12:34 +00004521 char
4522 token[MaxTextExtent];
4523
cristyb6bd4ad2010-08-08 01:12:27 +00004524 KernelInfo
4525 *kernel_info;
4526
cristy3ed852e2009-09-05 21:47:34 +00004527 if (*option == '+')
4528 break;
4529 i++;
cristybb503372010-05-27 20:51:26 +00004530 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004531 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00004532 kernel_info=AcquireKernelInfo(argv[i]);
4533 if (kernel_info == (KernelInfo *) NULL)
4534 ThrowConvertInvalidArgumentException(option,argv[i]);
4535 kernel_info=DestroyKernelInfo(kernel_info);
cristy3ed852e2009-09-05 21:47:34 +00004536 break;
4537 }
4538 if (LocaleCompare("crop",option+1) == 0)
4539 {
4540 if (*option == '+')
4541 break;
4542 i++;
cristybb503372010-05-27 20:51:26 +00004543 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004544 ThrowMogrifyException(OptionError,"MissingArgument",option);
4545 if (IsGeometry(argv[i]) == MagickFalse)
4546 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4547 break;
4548 }
4549 if (LocaleCompare("cycle",option+1) == 0)
4550 {
4551 if (*option == '+')
4552 break;
4553 i++;
cristybb503372010-05-27 20:51:26 +00004554 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004555 ThrowMogrifyException(OptionError,"MissingArgument",option);
4556 if (IsGeometry(argv[i]) == MagickFalse)
4557 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4558 break;
4559 }
4560 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4561 }
4562 case 'd':
4563 {
4564 if (LocaleCompare("decipher",option+1) == 0)
4565 {
4566 if (*option == '+')
4567 break;
4568 i++;
cristybb503372010-05-27 20:51:26 +00004569 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004570 ThrowMogrifyException(OptionError,"MissingArgument",option);
4571 break;
4572 }
4573 if (LocaleCompare("deconstruct",option+1) == 0)
4574 break;
4575 if (LocaleCompare("debug",option+1) == 0)
4576 {
cristybb503372010-05-27 20:51:26 +00004577 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004578 event;
4579
4580 if (*option == '+')
4581 break;
4582 i++;
cristybb503372010-05-27 20:51:26 +00004583 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004584 ThrowMogrifyException(OptionError,"MissingArgument",option);
4585 event=ParseMagickOption(MagickLogEventOptions,MagickFalse,argv[i]);
4586 if (event < 0)
4587 ThrowMogrifyException(OptionError,"UnrecognizedEventType",
4588 argv[i]);
4589 (void) SetLogEventMask(argv[i]);
4590 break;
4591 }
4592 if (LocaleCompare("define",option+1) == 0)
4593 {
4594 i++;
cristybb503372010-05-27 20:51:26 +00004595 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004596 ThrowMogrifyException(OptionError,"MissingArgument",option);
4597 if (*option == '+')
4598 {
4599 const char
4600 *define;
4601
4602 define=GetImageOption(image_info,argv[i]);
4603 if (define == (const char *) NULL)
4604 ThrowMogrifyException(OptionError,"NoSuchOption",argv[i]);
4605 break;
4606 }
4607 break;
4608 }
4609 if (LocaleCompare("delay",option+1) == 0)
4610 {
4611 if (*option == '+')
4612 break;
4613 i++;
cristybb503372010-05-27 20:51:26 +00004614 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004615 ThrowMogrifyException(OptionError,"MissingArgument",option);
4616 if (IsGeometry(argv[i]) == MagickFalse)
4617 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4618 break;
4619 }
4620 if (LocaleCompare("density",option+1) == 0)
4621 {
4622 if (*option == '+')
4623 break;
4624 i++;
cristybb503372010-05-27 20:51:26 +00004625 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004626 ThrowMogrifyException(OptionError,"MissingArgument",option);
4627 if (IsGeometry(argv[i]) == MagickFalse)
4628 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4629 break;
4630 }
4631 if (LocaleCompare("depth",option+1) == 0)
4632 {
4633 if (*option == '+')
4634 break;
4635 i++;
cristybb503372010-05-27 20:51:26 +00004636 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004637 ThrowMogrifyException(OptionError,"MissingArgument",option);
4638 if (IsGeometry(argv[i]) == MagickFalse)
4639 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4640 break;
4641 }
4642 if (LocaleCompare("deskew",option+1) == 0)
4643 {
4644 if (*option == '+')
4645 break;
4646 i++;
cristybb503372010-05-27 20:51:26 +00004647 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004648 ThrowMogrifyException(OptionError,"MissingArgument",option);
4649 if (IsGeometry(argv[i]) == MagickFalse)
4650 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4651 break;
4652 }
4653 if (LocaleCompare("despeckle",option+1) == 0)
4654 break;
4655 if (LocaleCompare("dft",option+1) == 0)
4656 break;
cristyc9b12952010-03-28 01:12:28 +00004657 if (LocaleCompare("direction",option+1) == 0)
4658 {
cristybb503372010-05-27 20:51:26 +00004659 ssize_t
cristyc9b12952010-03-28 01:12:28 +00004660 direction;
4661
4662 if (*option == '+')
4663 break;
4664 i++;
cristybb503372010-05-27 20:51:26 +00004665 if (i == (ssize_t) argc)
cristyc9b12952010-03-28 01:12:28 +00004666 ThrowMogrifyException(OptionError,"MissingArgument",option);
4667 direction=ParseMagickOption(MagickDirectionOptions,MagickFalse,
4668 argv[i]);
4669 if (direction < 0)
4670 ThrowMogrifyException(OptionError,"UnrecognizedDirectionType",
4671 argv[i]);
4672 break;
4673 }
cristy3ed852e2009-09-05 21:47:34 +00004674 if (LocaleCompare("display",option+1) == 0)
4675 {
4676 if (*option == '+')
4677 break;
4678 i++;
cristybb503372010-05-27 20:51:26 +00004679 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004680 ThrowMogrifyException(OptionError,"MissingArgument",option);
4681 break;
4682 }
4683 if (LocaleCompare("dispose",option+1) == 0)
4684 {
cristybb503372010-05-27 20:51:26 +00004685 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004686 dispose;
4687
4688 if (*option == '+')
4689 break;
4690 i++;
cristybb503372010-05-27 20:51:26 +00004691 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004692 ThrowMogrifyException(OptionError,"MissingArgument",option);
4693 dispose=ParseMagickOption(MagickDisposeOptions,MagickFalse,argv[i]);
4694 if (dispose < 0)
4695 ThrowMogrifyException(OptionError,"UnrecognizedDisposeMethod",
4696 argv[i]);
4697 break;
4698 }
4699 if (LocaleCompare("distort",option+1) == 0)
4700 {
cristybb503372010-05-27 20:51:26 +00004701 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004702 op;
4703
4704 i++;
cristybb503372010-05-27 20:51:26 +00004705 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004706 ThrowMogrifyException(OptionError,"MissingArgument",option);
4707 op=ParseMagickOption(MagickDistortOptions,MagickFalse,argv[i]);
4708 if (op < 0)
4709 ThrowMogrifyException(OptionError,"UnrecognizedDistortMethod",
4710 argv[i]);
4711 i++;
cristybb503372010-05-27 20:51:26 +00004712 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004713 ThrowMogrifyException(OptionError,"MissingArgument",option);
4714 break;
4715 }
4716 if (LocaleCompare("dither",option+1) == 0)
4717 {
cristybb503372010-05-27 20:51:26 +00004718 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004719 method;
4720
4721 if (*option == '+')
4722 break;
4723 i++;
cristybb503372010-05-27 20:51:26 +00004724 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004725 ThrowMogrifyException(OptionError,"MissingArgument",option);
4726 method=ParseMagickOption(MagickDitherOptions,MagickFalse,argv[i]);
4727 if (method < 0)
4728 ThrowMogrifyException(OptionError,"UnrecognizedDitherMethod",
4729 argv[i]);
4730 break;
4731 }
4732 if (LocaleCompare("draw",option+1) == 0)
4733 {
4734 if (*option == '+')
4735 break;
4736 i++;
cristybb503372010-05-27 20:51:26 +00004737 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004738 ThrowMogrifyException(OptionError,"MissingArgument",option);
4739 break;
4740 }
cristy22879752009-10-25 23:55:40 +00004741 if (LocaleCompare("duration",option+1) == 0)
4742 {
4743 if (*option == '+')
4744 break;
4745 i++;
cristybb503372010-05-27 20:51:26 +00004746 if (i == (ssize_t) (argc-1))
cristy22879752009-10-25 23:55:40 +00004747 ThrowMogrifyException(OptionError,"MissingArgument",option);
4748 if (IsGeometry(argv[i]) == MagickFalse)
4749 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4750 break;
4751 }
cristy3ed852e2009-09-05 21:47:34 +00004752 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4753 }
4754 case 'e':
4755 {
4756 if (LocaleCompare("edge",option+1) == 0)
4757 {
4758 if (*option == '+')
4759 break;
4760 i++;
cristybb503372010-05-27 20:51:26 +00004761 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004762 ThrowMogrifyException(OptionError,"MissingArgument",option);
4763 if (IsGeometry(argv[i]) == MagickFalse)
4764 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4765 break;
4766 }
4767 if (LocaleCompare("emboss",option+1) == 0)
4768 {
4769 if (*option == '+')
4770 break;
4771 i++;
cristybb503372010-05-27 20:51:26 +00004772 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004773 ThrowMogrifyException(OptionError,"MissingArgument",option);
4774 if (IsGeometry(argv[i]) == MagickFalse)
4775 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4776 break;
4777 }
4778 if (LocaleCompare("encipher",option+1) == 0)
4779 {
4780 if (*option == '+')
4781 break;
4782 i++;
cristybb503372010-05-27 20:51:26 +00004783 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004784 ThrowMogrifyException(OptionError,"MissingArgument",option);
4785 break;
4786 }
4787 if (LocaleCompare("encoding",option+1) == 0)
4788 {
4789 if (*option == '+')
4790 break;
4791 i++;
cristybb503372010-05-27 20:51:26 +00004792 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004793 ThrowMogrifyException(OptionError,"MissingArgument",option);
4794 break;
4795 }
4796 if (LocaleCompare("endian",option+1) == 0)
4797 {
cristybb503372010-05-27 20:51:26 +00004798 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004799 endian;
4800
4801 if (*option == '+')
4802 break;
4803 i++;
cristybb503372010-05-27 20:51:26 +00004804 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004805 ThrowMogrifyException(OptionError,"MissingArgument",option);
4806 endian=ParseMagickOption(MagickEndianOptions,MagickFalse,argv[i]);
4807 if (endian < 0)
4808 ThrowMogrifyException(OptionError,"UnrecognizedEndianType",
4809 argv[i]);
4810 break;
4811 }
4812 if (LocaleCompare("enhance",option+1) == 0)
4813 break;
4814 if (LocaleCompare("equalize",option+1) == 0)
4815 break;
4816 if (LocaleCompare("evaluate",option+1) == 0)
4817 {
cristybb503372010-05-27 20:51:26 +00004818 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004819 op;
4820
4821 if (*option == '+')
4822 break;
4823 i++;
cristybb503372010-05-27 20:51:26 +00004824 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004825 ThrowMogrifyException(OptionError,"MissingArgument",option);
4826 op=ParseMagickOption(MagickEvaluateOptions,MagickFalse,argv[i]);
4827 if (op < 0)
4828 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4829 argv[i]);
4830 i++;
cristybb503372010-05-27 20:51:26 +00004831 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004832 ThrowMogrifyException(OptionError,"MissingArgument",option);
4833 if (IsGeometry(argv[i]) == MagickFalse)
4834 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4835 break;
4836 }
cristyd18ae7c2010-03-07 17:39:52 +00004837 if (LocaleCompare("evaluate-sequence",option+1) == 0)
4838 {
cristybb503372010-05-27 20:51:26 +00004839 ssize_t
cristyd18ae7c2010-03-07 17:39:52 +00004840 op;
4841
4842 if (*option == '+')
4843 break;
4844 i++;
cristybb503372010-05-27 20:51:26 +00004845 if (i == (ssize_t) argc)
cristyd18ae7c2010-03-07 17:39:52 +00004846 ThrowMogrifyException(OptionError,"MissingArgument",option);
4847 op=ParseMagickOption(MagickEvaluateOptions,MagickFalse,argv[i]);
4848 if (op < 0)
4849 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4850 argv[i]);
4851 break;
4852 }
cristy3ed852e2009-09-05 21:47:34 +00004853 if (LocaleCompare("extent",option+1) == 0)
4854 {
4855 if (*option == '+')
4856 break;
4857 i++;
cristybb503372010-05-27 20:51:26 +00004858 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004859 ThrowMogrifyException(OptionError,"MissingArgument",option);
4860 if (IsGeometry(argv[i]) == MagickFalse)
4861 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4862 break;
4863 }
4864 if (LocaleCompare("extract",option+1) == 0)
4865 {
4866 if (*option == '+')
4867 break;
4868 i++;
cristybb503372010-05-27 20:51:26 +00004869 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004870 ThrowMogrifyException(OptionError,"MissingArgument",option);
4871 if (IsGeometry(argv[i]) == MagickFalse)
4872 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4873 break;
4874 }
4875 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4876 }
4877 case 'f':
4878 {
4879 if (LocaleCompare("family",option+1) == 0)
4880 {
4881 if (*option == '+')
4882 break;
4883 i++;
cristybb503372010-05-27 20:51:26 +00004884 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004885 ThrowMogrifyException(OptionError,"MissingArgument",option);
4886 break;
4887 }
4888 if (LocaleCompare("fill",option+1) == 0)
4889 {
4890 if (*option == '+')
4891 break;
4892 i++;
cristybb503372010-05-27 20:51:26 +00004893 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004894 ThrowMogrifyException(OptionError,"MissingArgument",option);
4895 break;
4896 }
4897 if (LocaleCompare("filter",option+1) == 0)
4898 {
cristybb503372010-05-27 20:51:26 +00004899 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004900 filter;
4901
4902 if (*option == '+')
4903 break;
4904 i++;
cristybb503372010-05-27 20:51:26 +00004905 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004906 ThrowMogrifyException(OptionError,"MissingArgument",option);
4907 filter=ParseMagickOption(MagickFilterOptions,MagickFalse,argv[i]);
4908 if (filter < 0)
4909 ThrowMogrifyException(OptionError,"UnrecognizedImageFilter",
4910 argv[i]);
4911 break;
4912 }
4913 if (LocaleCompare("flatten",option+1) == 0)
4914 break;
4915 if (LocaleCompare("flip",option+1) == 0)
4916 break;
4917 if (LocaleCompare("flop",option+1) == 0)
4918 break;
4919 if (LocaleCompare("floodfill",option+1) == 0)
4920 {
4921 if (*option == '+')
4922 break;
4923 i++;
cristybb503372010-05-27 20:51:26 +00004924 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004925 ThrowMogrifyException(OptionError,"MissingArgument",option);
4926 if (IsGeometry(argv[i]) == MagickFalse)
4927 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4928 i++;
cristybb503372010-05-27 20:51:26 +00004929 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004930 ThrowMogrifyException(OptionError,"MissingArgument",option);
4931 break;
4932 }
4933 if (LocaleCompare("font",option+1) == 0)
4934 {
4935 if (*option == '+')
4936 break;
4937 i++;
cristybb503372010-05-27 20:51:26 +00004938 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004939 ThrowMogrifyException(OptionError,"MissingArgument",option);
4940 break;
4941 }
4942 if (LocaleCompare("format",option+1) == 0)
4943 {
4944 (void) CopyMagickString(argv[i]+1,"sans",MaxTextExtent);
4945 (void) CloneString(&format,(char *) NULL);
4946 if (*option == '+')
4947 break;
4948 i++;
cristybb503372010-05-27 20:51:26 +00004949 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004950 ThrowMogrifyException(OptionError,"MissingArgument",option);
4951 (void) CloneString(&format,argv[i]);
4952 (void) CopyMagickString(image_info->filename,format,MaxTextExtent);
4953 (void) ConcatenateMagickString(image_info->filename,":",
4954 MaxTextExtent);
cristyd965a422010-03-03 17:47:35 +00004955 (void) SetImageInfo(image_info,0,exception);
cristy3ed852e2009-09-05 21:47:34 +00004956 if (*image_info->magick == '\0')
4957 ThrowMogrifyException(OptionError,"UnrecognizedImageFormat",
4958 format);
4959 break;
4960 }
4961 if (LocaleCompare("frame",option+1) == 0)
4962 {
4963 if (*option == '+')
4964 break;
4965 i++;
cristybb503372010-05-27 20:51:26 +00004966 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004967 ThrowMogrifyException(OptionError,"MissingArgument",option);
4968 if (IsGeometry(argv[i]) == MagickFalse)
4969 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4970 break;
4971 }
4972 if (LocaleCompare("function",option+1) == 0)
4973 {
cristybb503372010-05-27 20:51:26 +00004974 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004975 op;
4976
4977 if (*option == '+')
4978 break;
4979 i++;
cristybb503372010-05-27 20:51:26 +00004980 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004981 ThrowMogrifyException(OptionError,"MissingArgument",option);
4982 op=ParseMagickOption(MagickFunctionOptions,MagickFalse,argv[i]);
4983 if (op < 0)
4984 ThrowMogrifyException(OptionError,"UnrecognizedFunction",argv[i]);
4985 i++;
cristybb503372010-05-27 20:51:26 +00004986 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004987 ThrowMogrifyException(OptionError,"MissingArgument",option);
4988 break;
4989 }
4990 if (LocaleCompare("fuzz",option+1) == 0)
4991 {
4992 if (*option == '+')
4993 break;
4994 i++;
cristybb503372010-05-27 20:51:26 +00004995 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004996 ThrowMogrifyException(OptionError,"MissingArgument",option);
4997 if (IsGeometry(argv[i]) == MagickFalse)
4998 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4999 break;
5000 }
5001 if (LocaleCompare("fx",option+1) == 0)
5002 {
5003 if (*option == '+')
5004 break;
5005 i++;
cristybb503372010-05-27 20:51:26 +00005006 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005007 ThrowMogrifyException(OptionError,"MissingArgument",option);
5008 break;
5009 }
5010 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5011 }
5012 case 'g':
5013 {
5014 if (LocaleCompare("gamma",option+1) == 0)
5015 {
5016 i++;
cristybb503372010-05-27 20:51:26 +00005017 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005018 ThrowMogrifyException(OptionError,"MissingArgument",option);
5019 if (IsGeometry(argv[i]) == MagickFalse)
5020 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5021 break;
5022 }
5023 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
5024 (LocaleCompare("gaussian",option+1) == 0))
5025 {
5026 i++;
cristybb503372010-05-27 20:51:26 +00005027 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005028 ThrowMogrifyException(OptionError,"MissingArgument",option);
5029 if (IsGeometry(argv[i]) == MagickFalse)
5030 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5031 break;
5032 }
5033 if (LocaleCompare("geometry",option+1) == 0)
5034 {
5035 if (*option == '+')
5036 break;
5037 i++;
cristybb503372010-05-27 20:51:26 +00005038 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005039 ThrowMogrifyException(OptionError,"MissingArgument",option);
5040 if (IsGeometry(argv[i]) == MagickFalse)
5041 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5042 break;
5043 }
5044 if (LocaleCompare("gravity",option+1) == 0)
5045 {
cristybb503372010-05-27 20:51:26 +00005046 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005047 gravity;
5048
5049 if (*option == '+')
5050 break;
5051 i++;
cristybb503372010-05-27 20:51:26 +00005052 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005053 ThrowMogrifyException(OptionError,"MissingArgument",option);
5054 gravity=ParseMagickOption(MagickGravityOptions,MagickFalse,argv[i]);
5055 if (gravity < 0)
5056 ThrowMogrifyException(OptionError,"UnrecognizedGravityType",
5057 argv[i]);
5058 break;
5059 }
5060 if (LocaleCompare("green-primary",option+1) == 0)
5061 {
5062 if (*option == '+')
5063 break;
5064 i++;
cristybb503372010-05-27 20:51:26 +00005065 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005066 ThrowMogrifyException(OptionError,"MissingArgument",option);
5067 if (IsGeometry(argv[i]) == MagickFalse)
5068 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5069 break;
5070 }
5071 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5072 }
5073 case 'h':
5074 {
5075 if (LocaleCompare("hald-clut",option+1) == 0)
5076 break;
5077 if ((LocaleCompare("help",option+1) == 0) ||
5078 (LocaleCompare("-help",option+1) == 0))
5079 return(MogrifyUsage());
5080 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5081 }
5082 case 'i':
5083 {
5084 if (LocaleCompare("identify",option+1) == 0)
5085 break;
5086 if (LocaleCompare("idft",option+1) == 0)
5087 break;
5088 if (LocaleCompare("implode",option+1) == 0)
5089 {
5090 if (*option == '+')
5091 break;
5092 i++;
cristybb503372010-05-27 20:51:26 +00005093 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005094 ThrowMogrifyException(OptionError,"MissingArgument",option);
5095 if (IsGeometry(argv[i]) == MagickFalse)
5096 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5097 break;
5098 }
5099 if (LocaleCompare("intent",option+1) == 0)
5100 {
cristybb503372010-05-27 20:51:26 +00005101 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005102 intent;
5103
5104 if (*option == '+')
5105 break;
5106 i++;
cristybb503372010-05-27 20:51:26 +00005107 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005108 ThrowMogrifyException(OptionError,"MissingArgument",option);
5109 intent=ParseMagickOption(MagickIntentOptions,MagickFalse,argv[i]);
5110 if (intent < 0)
5111 ThrowMogrifyException(OptionError,"UnrecognizedIntentType",
5112 argv[i]);
5113 break;
5114 }
5115 if (LocaleCompare("interlace",option+1) == 0)
5116 {
cristybb503372010-05-27 20:51:26 +00005117 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005118 interlace;
5119
5120 if (*option == '+')
5121 break;
5122 i++;
cristybb503372010-05-27 20:51:26 +00005123 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005124 ThrowMogrifyException(OptionError,"MissingArgument",option);
5125 interlace=ParseMagickOption(MagickInterlaceOptions,MagickFalse,
5126 argv[i]);
5127 if (interlace < 0)
5128 ThrowMogrifyException(OptionError,"UnrecognizedInterlaceType",
5129 argv[i]);
5130 break;
5131 }
cristyb32b90a2009-09-07 21:45:48 +00005132 if (LocaleCompare("interline-spacing",option+1) == 0)
5133 {
5134 if (*option == '+')
5135 break;
5136 i++;
cristybb503372010-05-27 20:51:26 +00005137 if (i == (ssize_t) (argc-1))
cristyb32b90a2009-09-07 21:45:48 +00005138 ThrowMogrifyException(OptionError,"MissingArgument",option);
5139 if (IsGeometry(argv[i]) == MagickFalse)
5140 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5141 break;
5142 }
cristy3ed852e2009-09-05 21:47:34 +00005143 if (LocaleCompare("interpolate",option+1) == 0)
5144 {
cristybb503372010-05-27 20:51:26 +00005145 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005146 interpolate;
5147
5148 if (*option == '+')
5149 break;
5150 i++;
cristybb503372010-05-27 20:51:26 +00005151 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005152 ThrowMogrifyException(OptionError,"MissingArgument",option);
5153 interpolate=ParseMagickOption(MagickInterpolateOptions,MagickFalse,
5154 argv[i]);
5155 if (interpolate < 0)
5156 ThrowMogrifyException(OptionError,"UnrecognizedInterpolateMethod",
5157 argv[i]);
5158 break;
5159 }
5160 if (LocaleCompare("interword-spacing",option+1) == 0)
5161 {
5162 if (*option == '+')
5163 break;
5164 i++;
cristybb503372010-05-27 20:51:26 +00005165 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005166 ThrowMogrifyException(OptionError,"MissingArgument",option);
5167 if (IsGeometry(argv[i]) == MagickFalse)
5168 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5169 break;
5170 }
5171 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5172 }
5173 case 'k':
5174 {
5175 if (LocaleCompare("kerning",option+1) == 0)
5176 {
5177 if (*option == '+')
5178 break;
5179 i++;
cristybb503372010-05-27 20:51:26 +00005180 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005181 ThrowMogrifyException(OptionError,"MissingArgument",option);
5182 if (IsGeometry(argv[i]) == MagickFalse)
5183 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5184 break;
5185 }
5186 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5187 }
5188 case 'l':
5189 {
5190 if (LocaleCompare("label",option+1) == 0)
5191 {
5192 if (*option == '+')
5193 break;
5194 i++;
cristybb503372010-05-27 20:51:26 +00005195 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005196 ThrowMogrifyException(OptionError,"MissingArgument",option);
5197 break;
5198 }
5199 if (LocaleCompare("lat",option+1) == 0)
5200 {
5201 if (*option == '+')
5202 break;
5203 i++;
cristybb503372010-05-27 20:51:26 +00005204 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005205 ThrowMogrifyException(OptionError,"MissingArgument",option);
5206 if (IsGeometry(argv[i]) == MagickFalse)
5207 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5208 }
5209 if (LocaleCompare("layers",option+1) == 0)
5210 {
cristybb503372010-05-27 20:51:26 +00005211 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005212 type;
5213
5214 if (*option == '+')
5215 break;
5216 i++;
cristybb503372010-05-27 20:51:26 +00005217 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005218 ThrowMogrifyException(OptionError,"MissingArgument",option);
5219 type=ParseMagickOption(MagickLayerOptions,MagickFalse,argv[i]);
5220 if (type < 0)
5221 ThrowMogrifyException(OptionError,"UnrecognizedLayerMethod",
5222 argv[i]);
5223 break;
5224 }
5225 if (LocaleCompare("level",option+1) == 0)
5226 {
5227 i++;
cristybb503372010-05-27 20:51:26 +00005228 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005229 ThrowMogrifyException(OptionError,"MissingArgument",option);
5230 if (IsGeometry(argv[i]) == MagickFalse)
5231 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5232 break;
5233 }
5234 if (LocaleCompare("level-colors",option+1) == 0)
5235 {
5236 i++;
cristybb503372010-05-27 20:51:26 +00005237 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005238 ThrowMogrifyException(OptionError,"MissingArgument",option);
5239 break;
5240 }
5241 if (LocaleCompare("linewidth",option+1) == 0)
5242 {
5243 if (*option == '+')
5244 break;
5245 i++;
cristybb503372010-05-27 20:51:26 +00005246 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005247 ThrowMogrifyException(OptionError,"MissingArgument",option);
5248 if (IsGeometry(argv[i]) == MagickFalse)
5249 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5250 break;
5251 }
5252 if (LocaleCompare("limit",option+1) == 0)
5253 {
5254 char
5255 *p;
5256
5257 double
5258 value;
5259
cristybb503372010-05-27 20:51:26 +00005260 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005261 resource;
5262
5263 if (*option == '+')
5264 break;
5265 i++;
cristybb503372010-05-27 20:51:26 +00005266 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005267 ThrowMogrifyException(OptionError,"MissingArgument",option);
5268 resource=ParseMagickOption(MagickResourceOptions,MagickFalse,
5269 argv[i]);
5270 if (resource < 0)
5271 ThrowMogrifyException(OptionError,"UnrecognizedResourceType",
5272 argv[i]);
5273 i++;
cristybb503372010-05-27 20:51:26 +00005274 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005275 ThrowMogrifyException(OptionError,"MissingArgument",option);
5276 value=strtod(argv[i],&p);
5277 if ((p == argv[i]) && (LocaleCompare("unlimited",argv[i]) != 0))
5278 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5279 break;
5280 }
5281 if (LocaleCompare("liquid-rescale",option+1) == 0)
5282 {
5283 i++;
cristybb503372010-05-27 20:51:26 +00005284 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005285 ThrowMogrifyException(OptionError,"MissingArgument",option);
5286 if (IsGeometry(argv[i]) == MagickFalse)
5287 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5288 break;
5289 }
5290 if (LocaleCompare("list",option+1) == 0)
5291 {
cristybb503372010-05-27 20:51:26 +00005292 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005293 list;
5294
5295 if (*option == '+')
5296 break;
5297 i++;
cristybb503372010-05-27 20:51:26 +00005298 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005299 ThrowMogrifyException(OptionError,"MissingArgument",option);
5300 list=ParseMagickOption(MagickListOptions,MagickFalse,argv[i]);
5301 if (list < 0)
5302 ThrowMogrifyException(OptionError,"UnrecognizedListType",argv[i]);
cristyaeb2cbc2010-05-07 13:28:58 +00005303 status=MogrifyImageInfo(image_info,(int) (i-j+1),(const char **)
cristy3ed852e2009-09-05 21:47:34 +00005304 argv+j,exception);
cristyaeb2cbc2010-05-07 13:28:58 +00005305 return(status != 0 ? MagickFalse : MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00005306 }
5307 if (LocaleCompare("log",option+1) == 0)
5308 {
5309 if (*option == '+')
5310 break;
5311 i++;
cristybb503372010-05-27 20:51:26 +00005312 if ((i == (ssize_t) argc) ||
cristy3ed852e2009-09-05 21:47:34 +00005313 (strchr(argv[i],'%') == (char *) NULL))
5314 ThrowMogrifyException(OptionError,"MissingArgument",option);
5315 break;
5316 }
5317 if (LocaleCompare("loop",option+1) == 0)
5318 {
5319 if (*option == '+')
5320 break;
5321 i++;
cristybb503372010-05-27 20:51:26 +00005322 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005323 ThrowMogrifyException(OptionError,"MissingArgument",option);
5324 if (IsGeometry(argv[i]) == MagickFalse)
5325 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5326 break;
5327 }
5328 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5329 }
5330 case 'm':
5331 {
5332 if (LocaleCompare("map",option+1) == 0)
5333 {
5334 global_colormap=(*option == '+') ? MagickTrue : MagickFalse;
5335 if (*option == '+')
5336 break;
5337 i++;
cristybb503372010-05-27 20:51:26 +00005338 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005339 ThrowMogrifyException(OptionError,"MissingArgument",option);
5340 break;
5341 }
5342 if (LocaleCompare("mask",option+1) == 0)
5343 {
5344 if (*option == '+')
5345 break;
5346 i++;
cristybb503372010-05-27 20:51:26 +00005347 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005348 ThrowMogrifyException(OptionError,"MissingArgument",option);
5349 break;
5350 }
5351 if (LocaleCompare("matte",option+1) == 0)
5352 break;
5353 if (LocaleCompare("mattecolor",option+1) == 0)
5354 {
5355 if (*option == '+')
5356 break;
5357 i++;
cristybb503372010-05-27 20:51:26 +00005358 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005359 ThrowMogrifyException(OptionError,"MissingArgument",option);
5360 break;
5361 }
cristyf40785b2010-03-06 02:27:27 +00005362 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00005363 break;
cristyf40785b2010-03-06 02:27:27 +00005364 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00005365 break;
cristy3ed852e2009-09-05 21:47:34 +00005366 if (LocaleCompare("modulate",option+1) == 0)
5367 {
5368 if (*option == '+')
5369 break;
5370 i++;
cristybb503372010-05-27 20:51:26 +00005371 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005372 ThrowMogrifyException(OptionError,"MissingArgument",option);
5373 if (IsGeometry(argv[i]) == MagickFalse)
5374 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5375 break;
5376 }
5377 if (LocaleCompare("median",option+1) == 0)
5378 {
5379 if (*option == '+')
5380 break;
5381 i++;
cristybb503372010-05-27 20:51:26 +00005382 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005383 ThrowMogrifyException(OptionError,"MissingArgument",option);
5384 if (IsGeometry(argv[i]) == MagickFalse)
5385 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5386 break;
5387 }
5388 if (LocaleCompare("monitor",option+1) == 0)
5389 break;
5390 if (LocaleCompare("monochrome",option+1) == 0)
5391 break;
5392 if (LocaleCompare("morph",option+1) == 0)
5393 {
5394 if (*option == '+')
5395 break;
5396 i++;
cristybb503372010-05-27 20:51:26 +00005397 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005398 ThrowMogrifyException(OptionError,"MissingArgument",option);
5399 if (IsGeometry(argv[i]) == MagickFalse)
5400 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5401 break;
5402 }
anthony29188a82010-01-22 10:12:34 +00005403 if (LocaleCompare("morphology",option+1) == 0)
5404 {
anthony29188a82010-01-22 10:12:34 +00005405 char
5406 token[MaxTextExtent];
5407
cristyb6bd4ad2010-08-08 01:12:27 +00005408 KernelInfo
5409 *kernel_info;
5410
5411 ssize_t
5412 op;
5413
anthony29188a82010-01-22 10:12:34 +00005414 i++;
cristybb503372010-05-27 20:51:26 +00005415 if (i == (ssize_t) argc)
anthony29188a82010-01-22 10:12:34 +00005416 ThrowMogrifyException(OptionError,"MissingArgument",option);
5417 GetMagickToken(argv[i],NULL,token);
5418 op=ParseMagickOption(MagickMorphologyOptions,MagickFalse,token);
5419 if (op < 0)
5420 ThrowMogrifyException(OptionError,"UnrecognizedMorphologyMethod",
cristyf0c78232010-03-15 12:53:40 +00005421 token);
anthony29188a82010-01-22 10:12:34 +00005422 i++;
cristybb503372010-05-27 20:51:26 +00005423 if (i == (ssize_t) (argc-1))
anthony29188a82010-01-22 10:12:34 +00005424 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00005425 kernel_info=AcquireKernelInfo(argv[i]);
5426 if (kernel_info == (KernelInfo *) NULL)
5427 ThrowConvertInvalidArgumentException(option,argv[i]);
5428 kernel_info=DestroyKernelInfo(kernel_info);
anthony29188a82010-01-22 10:12:34 +00005429 break;
5430 }
cristy3ed852e2009-09-05 21:47:34 +00005431 if (LocaleCompare("mosaic",option+1) == 0)
5432 break;
5433 if (LocaleCompare("motion-blur",option+1) == 0)
5434 {
5435 if (*option == '+')
5436 break;
5437 i++;
cristybb503372010-05-27 20:51:26 +00005438 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005439 ThrowMogrifyException(OptionError,"MissingArgument",option);
5440 if (IsGeometry(argv[i]) == MagickFalse)
5441 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5442 break;
5443 }
5444 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5445 }
5446 case 'n':
5447 {
5448 if (LocaleCompare("negate",option+1) == 0)
5449 break;
5450 if (LocaleCompare("noise",option+1) == 0)
5451 {
5452 i++;
cristybb503372010-05-27 20:51:26 +00005453 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005454 ThrowMogrifyException(OptionError,"MissingArgument",option);
5455 if (*option == '+')
5456 {
cristybb503372010-05-27 20:51:26 +00005457 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005458 noise;
5459
5460 noise=ParseMagickOption(MagickNoiseOptions,MagickFalse,argv[i]);
5461 if (noise < 0)
5462 ThrowMogrifyException(OptionError,"UnrecognizedNoiseType",
5463 argv[i]);
5464 break;
5465 }
5466 if (IsGeometry(argv[i]) == MagickFalse)
5467 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5468 break;
5469 }
5470 if (LocaleCompare("noop",option+1) == 0)
5471 break;
5472 if (LocaleCompare("normalize",option+1) == 0)
5473 break;
5474 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5475 }
5476 case 'o':
5477 {
5478 if (LocaleCompare("opaque",option+1) == 0)
5479 {
cristy3ed852e2009-09-05 21:47:34 +00005480 i++;
cristybb503372010-05-27 20:51:26 +00005481 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005482 ThrowMogrifyException(OptionError,"MissingArgument",option);
5483 break;
5484 }
5485 if (LocaleCompare("ordered-dither",option+1) == 0)
5486 {
5487 if (*option == '+')
5488 break;
5489 i++;
cristybb503372010-05-27 20:51:26 +00005490 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005491 ThrowMogrifyException(OptionError,"MissingArgument",option);
5492 break;
5493 }
5494 if (LocaleCompare("orient",option+1) == 0)
5495 {
cristybb503372010-05-27 20:51:26 +00005496 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005497 orientation;
5498
5499 orientation=UndefinedOrientation;
5500 if (*option == '+')
5501 break;
5502 i++;
cristybb503372010-05-27 20:51:26 +00005503 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005504 ThrowMogrifyException(OptionError,"MissingArgument",option);
5505 orientation=ParseMagickOption(MagickOrientationOptions,MagickFalse,
5506 argv[i]);
5507 if (orientation < 0)
5508 ThrowMogrifyException(OptionError,"UnrecognizedImageOrientation",
5509 argv[i]);
5510 break;
5511 }
5512 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5513 }
5514 case 'p':
5515 {
5516 if (LocaleCompare("page",option+1) == 0)
5517 {
5518 if (*option == '+')
5519 break;
5520 i++;
cristybb503372010-05-27 20:51:26 +00005521 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005522 ThrowMogrifyException(OptionError,"MissingArgument",option);
5523 break;
5524 }
5525 if (LocaleCompare("paint",option+1) == 0)
5526 {
5527 if (*option == '+')
5528 break;
5529 i++;
cristybb503372010-05-27 20:51:26 +00005530 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005531 ThrowMogrifyException(OptionError,"MissingArgument",option);
5532 if (IsGeometry(argv[i]) == MagickFalse)
5533 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5534 break;
5535 }
5536 if (LocaleCompare("path",option+1) == 0)
5537 {
5538 (void) CloneString(&path,(char *) NULL);
5539 if (*option == '+')
5540 break;
5541 i++;
cristybb503372010-05-27 20:51:26 +00005542 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005543 ThrowMogrifyException(OptionError,"MissingArgument",option);
5544 (void) CloneString(&path,argv[i]);
5545 break;
5546 }
5547 if (LocaleCompare("pointsize",option+1) == 0)
5548 {
5549 if (*option == '+')
5550 break;
5551 i++;
cristybb503372010-05-27 20:51:26 +00005552 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005553 ThrowMogrifyException(OptionError,"MissingArgument",option);
5554 if (IsGeometry(argv[i]) == MagickFalse)
5555 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5556 break;
5557 }
5558 if (LocaleCompare("polaroid",option+1) == 0)
5559 {
5560 if (*option == '+')
5561 break;
5562 i++;
cristybb503372010-05-27 20:51:26 +00005563 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005564 ThrowMogrifyException(OptionError,"MissingArgument",option);
5565 if (IsGeometry(argv[i]) == MagickFalse)
5566 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5567 break;
5568 }
5569 if (LocaleCompare("posterize",option+1) == 0)
5570 {
5571 if (*option == '+')
5572 break;
5573 i++;
cristybb503372010-05-27 20:51:26 +00005574 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005575 ThrowMogrifyException(OptionError,"MissingArgument",option);
5576 if (IsGeometry(argv[i]) == MagickFalse)
5577 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5578 break;
5579 }
cristye7f51092010-01-17 00:39:37 +00005580 if (LocaleCompare("precision",option+1) == 0)
5581 {
5582 if (*option == '+')
5583 break;
5584 i++;
cristybb503372010-05-27 20:51:26 +00005585 if (i == (ssize_t) argc)
cristye7f51092010-01-17 00:39:37 +00005586 ThrowMogrifyException(OptionError,"MissingArgument",option);
5587 if (IsGeometry(argv[i]) == MagickFalse)
5588 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5589 break;
5590 }
cristy3ed852e2009-09-05 21:47:34 +00005591 if (LocaleCompare("print",option+1) == 0)
5592 {
5593 if (*option == '+')
5594 break;
5595 i++;
cristybb503372010-05-27 20:51:26 +00005596 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005597 ThrowMogrifyException(OptionError,"MissingArgument",option);
5598 break;
5599 }
5600 if (LocaleCompare("process",option+1) == 0)
5601 {
5602 if (*option == '+')
5603 break;
5604 i++;
cristybb503372010-05-27 20:51:26 +00005605 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005606 ThrowMogrifyException(OptionError,"MissingArgument",option);
5607 break;
5608 }
5609 if (LocaleCompare("profile",option+1) == 0)
5610 {
5611 i++;
cristybb503372010-05-27 20:51:26 +00005612 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005613 ThrowMogrifyException(OptionError,"MissingArgument",option);
5614 break;
5615 }
5616 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5617 }
5618 case 'q':
5619 {
5620 if (LocaleCompare("quality",option+1) == 0)
5621 {
5622 if (*option == '+')
5623 break;
5624 i++;
cristybb503372010-05-27 20:51:26 +00005625 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005626 ThrowMogrifyException(OptionError,"MissingArgument",option);
5627 if (IsGeometry(argv[i]) == MagickFalse)
5628 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5629 break;
5630 }
5631 if (LocaleCompare("quantize",option+1) == 0)
5632 {
cristybb503372010-05-27 20:51:26 +00005633 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005634 colorspace;
5635
5636 if (*option == '+')
5637 break;
5638 i++;
cristybb503372010-05-27 20:51:26 +00005639 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005640 ThrowMogrifyException(OptionError,"MissingArgument",option);
5641 colorspace=ParseMagickOption(MagickColorspaceOptions,MagickFalse,
5642 argv[i]);
5643 if (colorspace < 0)
5644 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
5645 argv[i]);
5646 break;
5647 }
5648 if (LocaleCompare("quiet",option+1) == 0)
5649 break;
5650 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5651 }
5652 case 'r':
5653 {
5654 if (LocaleCompare("radial-blur",option+1) == 0)
5655 {
5656 i++;
cristybb503372010-05-27 20:51:26 +00005657 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005658 ThrowMogrifyException(OptionError,"MissingArgument",option);
5659 if (IsGeometry(argv[i]) == MagickFalse)
5660 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5661 break;
5662 }
5663 if (LocaleCompare("raise",option+1) == 0)
5664 {
5665 i++;
cristybb503372010-05-27 20:51:26 +00005666 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005667 ThrowMogrifyException(OptionError,"MissingArgument",option);
5668 if (IsGeometry(argv[i]) == MagickFalse)
5669 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5670 break;
5671 }
5672 if (LocaleCompare("random-threshold",option+1) == 0)
5673 {
5674 if (*option == '+')
5675 break;
5676 i++;
cristybb503372010-05-27 20:51:26 +00005677 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005678 ThrowMogrifyException(OptionError,"MissingArgument",option);
5679 if (IsGeometry(argv[i]) == MagickFalse)
5680 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5681 break;
5682 }
cristye6365592010-04-02 17:31:23 +00005683 if (LocaleCompare("recolor",option+1) == 0)
5684 {
5685 if (*option == '+')
5686 break;
5687 i++;
cristybb503372010-05-27 20:51:26 +00005688 if (i == (ssize_t) (argc-1))
cristye6365592010-04-02 17:31:23 +00005689 ThrowMogrifyException(OptionError,"MissingArgument",option);
5690 if (IsGeometry(argv[i]) == MagickFalse)
5691 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5692 break;
5693 }
cristy3ed852e2009-09-05 21:47:34 +00005694 if (LocaleCompare("red-primary",option+1) == 0)
5695 {
5696 if (*option == '+')
5697 break;
5698 i++;
cristybb503372010-05-27 20:51:26 +00005699 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005700 ThrowMogrifyException(OptionError,"MissingArgument",option);
5701 if (IsGeometry(argv[i]) == MagickFalse)
5702 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5703 }
cristy9f2083a2010-04-22 19:48:05 +00005704 if (LocaleCompare("regard-warnings",option+1) == 0)
5705 break;
cristy3ed852e2009-09-05 21:47:34 +00005706 if (LocaleCompare("region",option+1) == 0)
5707 {
5708 if (*option == '+')
5709 break;
5710 i++;
cristybb503372010-05-27 20:51:26 +00005711 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005712 ThrowMogrifyException(OptionError,"MissingArgument",option);
5713 if (IsGeometry(argv[i]) == MagickFalse)
5714 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5715 break;
5716 }
cristyf0c78232010-03-15 12:53:40 +00005717 if (LocaleCompare("remap",option+1) == 0)
5718 {
5719 if (*option == '+')
5720 break;
5721 i++;
cristybb503372010-05-27 20:51:26 +00005722 if (i == (ssize_t) (argc-1))
cristyf0c78232010-03-15 12:53:40 +00005723 ThrowMogrifyException(OptionError,"MissingArgument",option);
5724 break;
5725 }
cristy3ed852e2009-09-05 21:47:34 +00005726 if (LocaleCompare("render",option+1) == 0)
5727 break;
5728 if (LocaleCompare("repage",option+1) == 0)
5729 {
5730 if (*option == '+')
5731 break;
5732 i++;
cristybb503372010-05-27 20:51:26 +00005733 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005734 ThrowMogrifyException(OptionError,"MissingArgument",option);
5735 if (IsGeometry(argv[i]) == MagickFalse)
5736 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5737 break;
5738 }
5739 if (LocaleCompare("resample",option+1) == 0)
5740 {
5741 if (*option == '+')
5742 break;
5743 i++;
cristybb503372010-05-27 20:51:26 +00005744 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005745 ThrowMogrifyException(OptionError,"MissingArgument",option);
5746 if (IsGeometry(argv[i]) == MagickFalse)
5747 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5748 break;
5749 }
5750 if (LocaleCompare("resize",option+1) == 0)
5751 {
5752 if (*option == '+')
5753 break;
5754 i++;
cristybb503372010-05-27 20:51:26 +00005755 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005756 ThrowMogrifyException(OptionError,"MissingArgument",option);
5757 if (IsGeometry(argv[i]) == MagickFalse)
5758 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5759 break;
5760 }
5761 if (LocaleCompare("reverse",option+1) == 0)
5762 break;
5763 if (LocaleCompare("roll",option+1) == 0)
5764 {
5765 if (*option == '+')
5766 break;
5767 i++;
cristybb503372010-05-27 20:51:26 +00005768 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005769 ThrowMogrifyException(OptionError,"MissingArgument",option);
5770 if (IsGeometry(argv[i]) == MagickFalse)
5771 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5772 break;
5773 }
5774 if (LocaleCompare("rotate",option+1) == 0)
5775 {
5776 i++;
cristybb503372010-05-27 20:51:26 +00005777 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005778 ThrowMogrifyException(OptionError,"MissingArgument",option);
5779 if (IsGeometry(argv[i]) == MagickFalse)
5780 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5781 break;
5782 }
5783 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5784 }
5785 case 's':
5786 {
5787 if (LocaleCompare("sample",option+1) == 0)
5788 {
5789 if (*option == '+')
5790 break;
5791 i++;
cristybb503372010-05-27 20:51:26 +00005792 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005793 ThrowMogrifyException(OptionError,"MissingArgument",option);
5794 if (IsGeometry(argv[i]) == MagickFalse)
5795 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5796 break;
5797 }
5798 if (LocaleCompare("sampling-factor",option+1) == 0)
5799 {
5800 if (*option == '+')
5801 break;
5802 i++;
cristybb503372010-05-27 20:51:26 +00005803 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005804 ThrowMogrifyException(OptionError,"MissingArgument",option);
5805 if (IsGeometry(argv[i]) == MagickFalse)
5806 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5807 break;
5808 }
5809 if (LocaleCompare("scale",option+1) == 0)
5810 {
5811 if (*option == '+')
5812 break;
5813 i++;
cristybb503372010-05-27 20:51:26 +00005814 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005815 ThrowMogrifyException(OptionError,"MissingArgument",option);
5816 if (IsGeometry(argv[i]) == MagickFalse)
5817 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5818 break;
5819 }
5820 if (LocaleCompare("scene",option+1) == 0)
5821 {
5822 if (*option == '+')
5823 break;
5824 i++;
cristybb503372010-05-27 20:51:26 +00005825 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005826 ThrowMogrifyException(OptionError,"MissingArgument",option);
5827 if (IsGeometry(argv[i]) == MagickFalse)
5828 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5829 break;
5830 }
5831 if (LocaleCompare("seed",option+1) == 0)
5832 {
5833 if (*option == '+')
5834 break;
5835 i++;
cristybb503372010-05-27 20:51:26 +00005836 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005837 ThrowMogrifyException(OptionError,"MissingArgument",option);
5838 if (IsGeometry(argv[i]) == MagickFalse)
5839 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5840 break;
5841 }
5842 if (LocaleCompare("segment",option+1) == 0)
5843 {
5844 if (*option == '+')
5845 break;
5846 i++;
cristybb503372010-05-27 20:51:26 +00005847 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005848 ThrowMogrifyException(OptionError,"MissingArgument",option);
5849 if (IsGeometry(argv[i]) == MagickFalse)
5850 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5851 break;
5852 }
5853 if (LocaleCompare("selective-blur",option+1) == 0)
5854 {
5855 i++;
cristybb503372010-05-27 20:51:26 +00005856 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005857 ThrowMogrifyException(OptionError,"MissingArgument",option);
5858 if (IsGeometry(argv[i]) == MagickFalse)
5859 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5860 break;
5861 }
5862 if (LocaleCompare("separate",option+1) == 0)
5863 break;
5864 if (LocaleCompare("sepia-tone",option+1) == 0)
5865 {
5866 if (*option == '+')
5867 break;
5868 i++;
cristybb503372010-05-27 20:51:26 +00005869 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005870 ThrowMogrifyException(OptionError,"MissingArgument",option);
5871 if (IsGeometry(argv[i]) == MagickFalse)
5872 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5873 break;
5874 }
5875 if (LocaleCompare("set",option+1) == 0)
5876 {
5877 i++;
cristybb503372010-05-27 20:51:26 +00005878 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005879 ThrowMogrifyException(OptionError,"MissingArgument",option);
5880 if (*option == '+')
5881 break;
5882 i++;
cristybb503372010-05-27 20:51:26 +00005883 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005884 ThrowMogrifyException(OptionError,"MissingArgument",option);
5885 break;
5886 }
5887 if (LocaleCompare("shade",option+1) == 0)
5888 {
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 if (IsGeometry(argv[i]) == MagickFalse)
5893 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5894 break;
5895 }
5896 if (LocaleCompare("shadow",option+1) == 0)
5897 {
5898 if (*option == '+')
5899 break;
5900 i++;
cristybb503372010-05-27 20:51:26 +00005901 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005902 ThrowMogrifyException(OptionError,"MissingArgument",option);
5903 if (IsGeometry(argv[i]) == MagickFalse)
5904 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5905 break;
5906 }
5907 if (LocaleCompare("sharpen",option+1) == 0)
5908 {
5909 i++;
cristybb503372010-05-27 20:51:26 +00005910 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005911 ThrowMogrifyException(OptionError,"MissingArgument",option);
5912 if (IsGeometry(argv[i]) == MagickFalse)
5913 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5914 break;
5915 }
5916 if (LocaleCompare("shave",option+1) == 0)
5917 {
5918 if (*option == '+')
5919 break;
5920 i++;
cristybb503372010-05-27 20:51:26 +00005921 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005922 ThrowMogrifyException(OptionError,"MissingArgument",option);
5923 if (IsGeometry(argv[i]) == MagickFalse)
5924 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5925 break;
5926 }
5927 if (LocaleCompare("shear",option+1) == 0)
5928 {
5929 i++;
cristybb503372010-05-27 20:51:26 +00005930 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005931 ThrowMogrifyException(OptionError,"MissingArgument",option);
5932 if (IsGeometry(argv[i]) == MagickFalse)
5933 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5934 break;
5935 }
5936 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
5937 {
5938 i++;
cristybb503372010-05-27 20:51:26 +00005939 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005940 ThrowMogrifyException(OptionError,"MissingArgument",option);
5941 if (IsGeometry(argv[i]) == MagickFalse)
5942 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5943 break;
5944 }
5945 if (LocaleCompare("size",option+1) == 0)
5946 {
5947 if (*option == '+')
5948 break;
5949 i++;
cristybb503372010-05-27 20:51:26 +00005950 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005951 ThrowMogrifyException(OptionError,"MissingArgument",option);
5952 if (IsGeometry(argv[i]) == MagickFalse)
5953 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5954 break;
5955 }
5956 if (LocaleCompare("sketch",option+1) == 0)
5957 {
5958 if (*option == '+')
5959 break;
5960 i++;
cristybb503372010-05-27 20:51:26 +00005961 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005962 ThrowMogrifyException(OptionError,"MissingArgument",option);
5963 if (IsGeometry(argv[i]) == MagickFalse)
5964 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5965 break;
5966 }
5967 if (LocaleCompare("solarize",option+1) == 0)
5968 {
5969 if (*option == '+')
5970 break;
5971 i++;
cristybb503372010-05-27 20:51:26 +00005972 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005973 ThrowMogrifyException(OptionError,"MissingArgument",option);
5974 if (IsGeometry(argv[i]) == MagickFalse)
5975 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5976 break;
5977 }
5978 if (LocaleCompare("sparse-color",option+1) == 0)
5979 {
cristybb503372010-05-27 20:51:26 +00005980 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005981 op;
5982
5983 i++;
cristybb503372010-05-27 20:51:26 +00005984 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005985 ThrowMogrifyException(OptionError,"MissingArgument",option);
5986 op=ParseMagickOption(MagickSparseColorOptions,MagickFalse,argv[i]);
5987 if (op < 0)
5988 ThrowMogrifyException(OptionError,"UnrecognizedSparseColorMethod",
5989 argv[i]);
5990 i++;
cristybb503372010-05-27 20:51:26 +00005991 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005992 ThrowMogrifyException(OptionError,"MissingArgument",option);
5993 break;
5994 }
5995 if (LocaleCompare("spread",option+1) == 0)
5996 {
5997 if (*option == '+')
5998 break;
5999 i++;
cristybb503372010-05-27 20:51:26 +00006000 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006001 ThrowMogrifyException(OptionError,"MissingArgument",option);
6002 if (IsGeometry(argv[i]) == MagickFalse)
6003 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6004 break;
6005 }
6006 if (LocaleCompare("stretch",option+1) == 0)
6007 {
cristybb503372010-05-27 20:51:26 +00006008 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006009 stretch;
6010
6011 if (*option == '+')
6012 break;
6013 i++;
cristybb503372010-05-27 20:51:26 +00006014 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006015 ThrowMogrifyException(OptionError,"MissingArgument",option);
6016 stretch=ParseMagickOption(MagickStretchOptions,MagickFalse,argv[i]);
6017 if (stretch < 0)
6018 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
6019 argv[i]);
6020 break;
6021 }
6022 if (LocaleCompare("strip",option+1) == 0)
6023 break;
6024 if (LocaleCompare("stroke",option+1) == 0)
6025 {
6026 if (*option == '+')
6027 break;
6028 i++;
cristybb503372010-05-27 20:51:26 +00006029 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006030 ThrowMogrifyException(OptionError,"MissingArgument",option);
6031 break;
6032 }
6033 if (LocaleCompare("strokewidth",option+1) == 0)
6034 {
6035 if (*option == '+')
6036 break;
6037 i++;
cristybb503372010-05-27 20:51:26 +00006038 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006039 ThrowMogrifyException(OptionError,"MissingArgument",option);
6040 if (IsGeometry(argv[i]) == MagickFalse)
6041 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6042 break;
6043 }
6044 if (LocaleCompare("style",option+1) == 0)
6045 {
cristybb503372010-05-27 20:51:26 +00006046 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006047 style;
6048
6049 if (*option == '+')
6050 break;
6051 i++;
cristybb503372010-05-27 20:51:26 +00006052 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006053 ThrowMogrifyException(OptionError,"MissingArgument",option);
6054 style=ParseMagickOption(MagickStyleOptions,MagickFalse,argv[i]);
6055 if (style < 0)
6056 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
6057 argv[i]);
6058 break;
6059 }
6060 if (LocaleCompare("swirl",option+1) == 0)
6061 {
6062 if (*option == '+')
6063 break;
6064 i++;
cristybb503372010-05-27 20:51:26 +00006065 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006066 ThrowMogrifyException(OptionError,"MissingArgument",option);
6067 if (IsGeometry(argv[i]) == MagickFalse)
6068 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6069 break;
6070 }
6071 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6072 }
6073 case 't':
6074 {
6075 if (LocaleCompare("taint",option+1) == 0)
6076 break;
6077 if (LocaleCompare("texture",option+1) == 0)
6078 {
6079 if (*option == '+')
6080 break;
6081 i++;
cristybb503372010-05-27 20:51:26 +00006082 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006083 ThrowMogrifyException(OptionError,"MissingArgument",option);
6084 break;
6085 }
6086 if (LocaleCompare("tile",option+1) == 0)
6087 {
6088 if (*option == '+')
6089 break;
6090 i++;
cristybb503372010-05-27 20:51:26 +00006091 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006092 ThrowMogrifyException(OptionError,"MissingArgument",option);
6093 break;
6094 }
6095 if (LocaleCompare("tile-offset",option+1) == 0)
6096 {
6097 if (*option == '+')
6098 break;
6099 i++;
cristybb503372010-05-27 20:51:26 +00006100 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006101 ThrowMogrifyException(OptionError,"MissingArgument",option);
6102 if (IsGeometry(argv[i]) == MagickFalse)
6103 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6104 break;
6105 }
6106 if (LocaleCompare("tint",option+1) == 0)
6107 {
6108 if (*option == '+')
6109 break;
6110 i++;
cristybb503372010-05-27 20:51:26 +00006111 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006112 ThrowMogrifyException(OptionError,"MissingArgument",option);
6113 if (IsGeometry(argv[i]) == MagickFalse)
6114 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6115 break;
6116 }
6117 if (LocaleCompare("transform",option+1) == 0)
6118 break;
6119 if (LocaleCompare("transpose",option+1) == 0)
6120 break;
6121 if (LocaleCompare("transverse",option+1) == 0)
6122 break;
6123 if (LocaleCompare("threshold",option+1) == 0)
6124 {
6125 if (*option == '+')
6126 break;
6127 i++;
cristybb503372010-05-27 20:51:26 +00006128 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006129 ThrowMogrifyException(OptionError,"MissingArgument",option);
6130 if (IsGeometry(argv[i]) == MagickFalse)
6131 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6132 break;
6133 }
6134 if (LocaleCompare("thumbnail",option+1) == 0)
6135 {
6136 if (*option == '+')
6137 break;
6138 i++;
cristybb503372010-05-27 20:51:26 +00006139 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006140 ThrowMogrifyException(OptionError,"MissingArgument",option);
6141 if (IsGeometry(argv[i]) == MagickFalse)
6142 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6143 break;
6144 }
6145 if (LocaleCompare("transparent",option+1) == 0)
6146 {
6147 i++;
cristybb503372010-05-27 20:51:26 +00006148 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006149 ThrowMogrifyException(OptionError,"MissingArgument",option);
6150 break;
6151 }
6152 if (LocaleCompare("transparent-color",option+1) == 0)
6153 {
6154 if (*option == '+')
6155 break;
6156 i++;
cristybb503372010-05-27 20:51:26 +00006157 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006158 ThrowMogrifyException(OptionError,"MissingArgument",option);
6159 break;
6160 }
6161 if (LocaleCompare("treedepth",option+1) == 0)
6162 {
6163 if (*option == '+')
6164 break;
6165 i++;
cristybb503372010-05-27 20:51:26 +00006166 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006167 ThrowMogrifyException(OptionError,"MissingArgument",option);
6168 if (IsGeometry(argv[i]) == MagickFalse)
6169 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6170 break;
6171 }
6172 if (LocaleCompare("trim",option+1) == 0)
6173 break;
6174 if (LocaleCompare("type",option+1) == 0)
6175 {
cristybb503372010-05-27 20:51:26 +00006176 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006177 type;
6178
6179 if (*option == '+')
6180 break;
6181 i++;
cristybb503372010-05-27 20:51:26 +00006182 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006183 ThrowMogrifyException(OptionError,"MissingArgument",option);
6184 type=ParseMagickOption(MagickTypeOptions,MagickFalse,argv[i]);
6185 if (type < 0)
6186 ThrowMogrifyException(OptionError,"UnrecognizedImageType",
6187 argv[i]);
6188 break;
6189 }
6190 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6191 }
6192 case 'u':
6193 {
6194 if (LocaleCompare("undercolor",option+1) == 0)
6195 {
6196 if (*option == '+')
6197 break;
6198 i++;
cristybb503372010-05-27 20:51:26 +00006199 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006200 ThrowMogrifyException(OptionError,"MissingArgument",option);
6201 break;
6202 }
6203 if (LocaleCompare("unique-colors",option+1) == 0)
6204 break;
6205 if (LocaleCompare("units",option+1) == 0)
6206 {
cristybb503372010-05-27 20:51:26 +00006207 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006208 units;
6209
6210 if (*option == '+')
6211 break;
6212 i++;
cristybb503372010-05-27 20:51:26 +00006213 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006214 ThrowMogrifyException(OptionError,"MissingArgument",option);
6215 units=ParseMagickOption(MagickResolutionOptions,MagickFalse,
6216 argv[i]);
6217 if (units < 0)
6218 ThrowMogrifyException(OptionError,"UnrecognizedUnitsType",
6219 argv[i]);
6220 break;
6221 }
6222 if (LocaleCompare("unsharp",option+1) == 0)
6223 {
6224 i++;
cristybb503372010-05-27 20:51:26 +00006225 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006226 ThrowMogrifyException(OptionError,"MissingArgument",option);
6227 if (IsGeometry(argv[i]) == MagickFalse)
6228 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6229 break;
6230 }
6231 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6232 }
6233 case 'v':
6234 {
6235 if (LocaleCompare("verbose",option+1) == 0)
6236 {
6237 image_info->verbose=(*option == '-') ? MagickTrue : MagickFalse;
6238 break;
6239 }
6240 if ((LocaleCompare("version",option+1) == 0) ||
6241 (LocaleCompare("-version",option+1) == 0))
6242 {
6243 (void) fprintf(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +00006244 GetMagickVersion((size_t *) NULL));
cristy610b2e22009-10-22 14:59:43 +00006245 (void) fprintf(stdout,"Copyright: %s\n",GetMagickCopyright());
6246 (void) fprintf(stdout,"Features: %s\n\n",GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00006247 break;
6248 }
6249 if (LocaleCompare("view",option+1) == 0)
6250 {
6251 if (*option == '+')
6252 break;
6253 i++;
cristybb503372010-05-27 20:51:26 +00006254 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006255 ThrowMogrifyException(OptionError,"MissingArgument",option);
6256 break;
6257 }
6258 if (LocaleCompare("vignette",option+1) == 0)
6259 {
6260 if (*option == '+')
6261 break;
6262 i++;
cristybb503372010-05-27 20:51:26 +00006263 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006264 ThrowMogrifyException(OptionError,"MissingArgument",option);
6265 if (IsGeometry(argv[i]) == MagickFalse)
6266 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6267 break;
6268 }
6269 if (LocaleCompare("virtual-pixel",option+1) == 0)
6270 {
cristybb503372010-05-27 20:51:26 +00006271 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006272 method;
6273
6274 if (*option == '+')
6275 break;
6276 i++;
cristybb503372010-05-27 20:51:26 +00006277 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006278 ThrowMogrifyException(OptionError,"MissingArgument",option);
6279 method=ParseMagickOption(MagickVirtualPixelOptions,MagickFalse,
6280 argv[i]);
6281 if (method < 0)
6282 ThrowMogrifyException(OptionError,
6283 "UnrecognizedVirtualPixelMethod",argv[i]);
6284 break;
6285 }
6286 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6287 }
6288 case 'w':
6289 {
6290 if (LocaleCompare("wave",option+1) == 0)
6291 {
6292 i++;
cristybb503372010-05-27 20:51:26 +00006293 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006294 ThrowMogrifyException(OptionError,"MissingArgument",option);
6295 if (IsGeometry(argv[i]) == MagickFalse)
6296 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6297 break;
6298 }
6299 if (LocaleCompare("weight",option+1) == 0)
6300 {
6301 if (*option == '+')
6302 break;
6303 i++;
cristybb503372010-05-27 20:51:26 +00006304 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006305 ThrowMogrifyException(OptionError,"MissingArgument",option);
6306 break;
6307 }
6308 if (LocaleCompare("white-point",option+1) == 0)
6309 {
6310 if (*option == '+')
6311 break;
6312 i++;
cristybb503372010-05-27 20:51:26 +00006313 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006314 ThrowMogrifyException(OptionError,"MissingArgument",option);
6315 if (IsGeometry(argv[i]) == MagickFalse)
6316 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6317 break;
6318 }
6319 if (LocaleCompare("white-threshold",option+1) == 0)
6320 {
6321 if (*option == '+')
6322 break;
6323 i++;
cristybb503372010-05-27 20:51:26 +00006324 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006325 ThrowMogrifyException(OptionError,"MissingArgument",option);
6326 if (IsGeometry(argv[i]) == MagickFalse)
6327 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6328 break;
6329 }
6330 if (LocaleCompare("write",option+1) == 0)
6331 {
6332 i++;
cristybb503372010-05-27 20:51:26 +00006333 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006334 ThrowMogrifyException(OptionError,"MissingArgument",option);
6335 break;
6336 }
6337 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6338 }
6339 case '?':
6340 break;
6341 default:
6342 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6343 }
6344 fire=ParseMagickOption(MagickImageListOptions,MagickFalse,option+1) < 0 ?
6345 MagickFalse : MagickTrue;
6346 if (fire != MagickFalse)
6347 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
6348 }
6349 if (k != 0)
6350 ThrowMogrifyException(OptionError,"UnbalancedParenthesis",argv[i]);
cristycee97112010-05-28 00:44:52 +00006351 if (i != (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006352 ThrowMogrifyException(OptionError,"MissingAnImageFilename",argv[i]);
6353 DestroyMogrify();
6354 return(status != 0 ? MagickTrue : MagickFalse);
6355}
6356
6357/*
6358%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6359% %
6360% %
6361% %
6362+ M o g r i f y I m a g e I n f o %
6363% %
6364% %
6365% %
6366%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6367%
6368% MogrifyImageInfo() applies image processing settings to the image as
6369% prescribed by command line options.
6370%
6371% The format of the MogrifyImageInfo method is:
6372%
6373% MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,const int argc,
6374% const char **argv,ExceptionInfo *exception)
6375%
6376% A description of each parameter follows:
6377%
6378% o image_info: the image info..
6379%
6380% o argc: Specifies a pointer to an integer describing the number of
6381% elements in the argument vector.
6382%
6383% o argv: Specifies a pointer to a text array containing the command line
6384% arguments.
6385%
6386% o exception: return any errors or warnings in this structure.
6387%
6388*/
6389WandExport MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,
6390 const int argc,const char **argv,ExceptionInfo *exception)
6391{
6392 const char
6393 *option;
6394
6395 GeometryInfo
6396 geometry_info;
6397
cristybb503372010-05-27 20:51:26 +00006398 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006399 count;
6400
cristybb503372010-05-27 20:51:26 +00006401 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006402 i;
6403
6404 /*
6405 Initialize method variables.
6406 */
6407 assert(image_info != (ImageInfo *) NULL);
6408 assert(image_info->signature == MagickSignature);
6409 if (image_info->debug != MagickFalse)
6410 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
6411 image_info->filename);
6412 if (argc < 0)
6413 return(MagickTrue);
6414 /*
6415 Set the image settings.
6416 */
cristybb503372010-05-27 20:51:26 +00006417 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00006418 {
6419 option=argv[i];
6420 if (IsMagickOption(option) == MagickFalse)
6421 continue;
6422 count=MagickMax(ParseMagickOption(MagickCommandOptions,MagickFalse,option),
6423 0L);
cristycee97112010-05-28 00:44:52 +00006424 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006425 break;
6426 switch (*(option+1))
6427 {
6428 case 'a':
6429 {
6430 if (LocaleCompare("adjoin",option+1) == 0)
6431 {
6432 image_info->adjoin=(*option == '-') ? MagickTrue : MagickFalse;
6433 break;
6434 }
6435 if (LocaleCompare("antialias",option+1) == 0)
6436 {
6437 image_info->antialias=(*option == '-') ? MagickTrue : MagickFalse;
6438 break;
6439 }
6440 if (LocaleCompare("attenuate",option+1) == 0)
6441 {
6442 if (*option == '+')
6443 {
6444 (void) DeleteImageOption(image_info,option+1);
6445 break;
6446 }
6447 (void) SetImageOption(image_info,option+1,argv[i+1]);
6448 break;
6449 }
6450 if (LocaleCompare("authenticate",option+1) == 0)
6451 {
6452 if (*option == '+')
6453 (void) CloneString(&image_info->authenticate,(char *) NULL);
6454 else
6455 (void) CloneString(&image_info->authenticate,argv[i+1]);
6456 break;
6457 }
6458 break;
6459 }
6460 case 'b':
6461 {
6462 if (LocaleCompare("background",option+1) == 0)
6463 {
6464 if (*option == '+')
6465 {
6466 (void) DeleteImageOption(image_info,option+1);
6467 (void) QueryColorDatabase(BackgroundColor,
6468 &image_info->background_color,exception);
6469 break;
6470 }
6471 (void) SetImageOption(image_info,option+1,argv[i+1]);
6472 (void) QueryColorDatabase(argv[i+1],&image_info->background_color,
6473 exception);
6474 break;
6475 }
6476 if (LocaleCompare("bias",option+1) == 0)
6477 {
6478 if (*option == '+')
6479 {
6480 (void) SetImageOption(image_info,option+1,"0.0");
6481 break;
6482 }
6483 (void) SetImageOption(image_info,option+1,argv[i+1]);
6484 break;
6485 }
6486 if (LocaleCompare("black-point-compensation",option+1) == 0)
6487 {
6488 if (*option == '+')
6489 {
6490 (void) SetImageOption(image_info,option+1,"false");
6491 break;
6492 }
6493 (void) SetImageOption(image_info,option+1,"true");
6494 break;
6495 }
6496 if (LocaleCompare("blue-primary",option+1) == 0)
6497 {
6498 if (*option == '+')
6499 {
6500 (void) SetImageOption(image_info,option+1,"0.0");
6501 break;
6502 }
6503 (void) SetImageOption(image_info,option+1,argv[i+1]);
6504 break;
6505 }
6506 if (LocaleCompare("bordercolor",option+1) == 0)
6507 {
6508 if (*option == '+')
6509 {
6510 (void) DeleteImageOption(image_info,option+1);
6511 (void) QueryColorDatabase(BorderColor,&image_info->border_color,
6512 exception);
6513 break;
6514 }
6515 (void) QueryColorDatabase(argv[i+1],&image_info->border_color,
6516 exception);
6517 (void) SetImageOption(image_info,option+1,argv[i+1]);
6518 break;
6519 }
6520 if (LocaleCompare("box",option+1) == 0)
6521 {
6522 if (*option == '+')
6523 {
6524 (void) SetImageOption(image_info,"undercolor","none");
6525 break;
6526 }
6527 (void) SetImageOption(image_info,"undercolor",argv[i+1]);
6528 break;
6529 }
6530 break;
6531 }
6532 case 'c':
6533 {
6534 if (LocaleCompare("cache",option+1) == 0)
6535 {
6536 MagickSizeType
6537 limit;
6538
6539 limit=MagickResourceInfinity;
6540 if (LocaleCompare("unlimited",argv[i+1]) != 0)
cristyf2f27272009-12-17 14:48:46 +00006541 limit=(MagickSizeType) SiPrefixToDouble(argv[i+1],100.0);
cristy3ed852e2009-09-05 21:47:34 +00006542 (void) SetMagickResourceLimit(MemoryResource,limit);
6543 (void) SetMagickResourceLimit(MapResource,2*limit);
6544 break;
6545 }
6546 if (LocaleCompare("caption",option+1) == 0)
6547 {
6548 if (*option == '+')
6549 {
6550 (void) DeleteImageOption(image_info,option+1);
6551 break;
6552 }
6553 (void) SetImageOption(image_info,option+1,argv[i+1]);
6554 break;
6555 }
6556 if (LocaleCompare("channel",option+1) == 0)
6557 {
6558 if (*option == '+')
6559 {
6560 image_info->channel=DefaultChannels;
6561 break;
6562 }
6563 image_info->channel=(ChannelType) ParseChannelOption(argv[i+1]);
6564 break;
6565 }
6566 if (LocaleCompare("colors",option+1) == 0)
6567 {
cristye27293e2009-12-18 02:53:20 +00006568 image_info->colors=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006569 break;
6570 }
6571 if (LocaleCompare("colorspace",option+1) == 0)
6572 {
6573 if (*option == '+')
6574 {
6575 image_info->colorspace=UndefinedColorspace;
6576 (void) SetImageOption(image_info,option+1,"undefined");
6577 break;
6578 }
6579 image_info->colorspace=(ColorspaceType) ParseMagickOption(
6580 MagickColorspaceOptions,MagickFalse,argv[i+1]);
6581 (void) SetImageOption(image_info,option+1,argv[i+1]);
6582 break;
6583 }
6584 if (LocaleCompare("compress",option+1) == 0)
6585 {
6586 if (*option == '+')
6587 {
6588 image_info->compression=UndefinedCompression;
6589 (void) SetImageOption(image_info,option+1,"undefined");
6590 break;
6591 }
6592 image_info->compression=(CompressionType) ParseMagickOption(
6593 MagickCompressOptions,MagickFalse,argv[i+1]);
6594 (void) SetImageOption(image_info,option+1,argv[i+1]);
6595 break;
6596 }
6597 if (LocaleCompare("comment",option+1) == 0)
6598 {
6599 if (*option == '+')
6600 {
6601 (void) DeleteImageOption(image_info,option+1);
6602 break;
6603 }
6604 (void) SetImageOption(image_info,option+1,argv[i+1]);
6605 break;
6606 }
6607 if (LocaleCompare("compose",option+1) == 0)
6608 {
6609 if (*option == '+')
6610 {
6611 (void) SetImageOption(image_info,option+1,"undefined");
6612 break;
6613 }
6614 (void) SetImageOption(image_info,option+1,argv[i+1]);
6615 break;
6616 }
6617 if (LocaleCompare("compress",option+1) == 0)
6618 {
6619 if (*option == '+')
6620 {
6621 image_info->compression=UndefinedCompression;
6622 (void) SetImageOption(image_info,option+1,"undefined");
6623 break;
6624 }
6625 image_info->compression=(CompressionType) ParseMagickOption(
6626 MagickCompressOptions,MagickFalse,argv[i+1]);
6627 (void) SetImageOption(image_info,option+1,argv[i+1]);
6628 break;
6629 }
6630 break;
6631 }
6632 case 'd':
6633 {
6634 if (LocaleCompare("debug",option+1) == 0)
6635 {
6636 if (*option == '+')
6637 (void) SetLogEventMask("none");
6638 else
6639 (void) SetLogEventMask(argv[i+1]);
6640 image_info->debug=IsEventLogging();
6641 break;
6642 }
6643 if (LocaleCompare("define",option+1) == 0)
6644 {
6645 if (*option == '+')
6646 {
6647 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6648 (void) DeleteImageRegistry(argv[i+1]+9);
6649 else
6650 (void) DeleteImageOption(image_info,argv[i+1]);
6651 break;
6652 }
6653 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6654 {
6655 (void) DefineImageRegistry(StringRegistryType,argv[i+1]+9,
6656 exception);
6657 break;
6658 }
6659 (void) DefineImageOption(image_info,argv[i+1]);
6660 break;
6661 }
6662 if (LocaleCompare("delay",option+1) == 0)
6663 {
6664 if (*option == '+')
6665 {
6666 (void) SetImageOption(image_info,option+1,"0");
6667 break;
6668 }
6669 (void) SetImageOption(image_info,option+1,argv[i+1]);
6670 break;
6671 }
6672 if (LocaleCompare("density",option+1) == 0)
6673 {
6674 /*
6675 Set image density.
6676 */
6677 if (*option == '+')
6678 {
6679 if (image_info->density != (char *) NULL)
6680 image_info->density=DestroyString(image_info->density);
6681 (void) SetImageOption(image_info,option+1,"72");
6682 break;
6683 }
6684 (void) CloneString(&image_info->density,argv[i+1]);
6685 (void) SetImageOption(image_info,option+1,argv[i+1]);
6686 break;
6687 }
6688 if (LocaleCompare("depth",option+1) == 0)
6689 {
6690 if (*option == '+')
6691 {
6692 image_info->depth=MAGICKCORE_QUANTUM_DEPTH;
6693 break;
6694 }
cristye27293e2009-12-18 02:53:20 +00006695 image_info->depth=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006696 break;
6697 }
cristyc9b12952010-03-28 01:12:28 +00006698 if (LocaleCompare("direction",option+1) == 0)
6699 {
6700 if (*option == '+')
6701 {
6702 (void) SetImageOption(image_info,option+1,"undefined");
6703 break;
6704 }
6705 (void) SetImageOption(image_info,option+1,argv[i+1]);
6706 break;
6707 }
cristy3ed852e2009-09-05 21:47:34 +00006708 if (LocaleCompare("display",option+1) == 0)
6709 {
6710 if (*option == '+')
6711 {
6712 if (image_info->server_name != (char *) NULL)
6713 image_info->server_name=DestroyString(
6714 image_info->server_name);
6715 break;
6716 }
6717 (void) CloneString(&image_info->server_name,argv[i+1]);
6718 break;
6719 }
6720 if (LocaleCompare("dispose",option+1) == 0)
6721 {
6722 if (*option == '+')
6723 {
6724 (void) SetImageOption(image_info,option+1,"undefined");
6725 break;
6726 }
6727 (void) SetImageOption(image_info,option+1,argv[i+1]);
6728 break;
6729 }
6730 if (LocaleCompare("dither",option+1) == 0)
6731 {
6732 if (*option == '+')
6733 {
6734 image_info->dither=MagickFalse;
cristyd5acfd12010-06-15 00:11:38 +00006735 (void) SetImageOption(image_info,option+1,"none");
cristy3ed852e2009-09-05 21:47:34 +00006736 break;
6737 }
6738 (void) SetImageOption(image_info,option+1,argv[i+1]);
6739 image_info->dither=MagickTrue;
6740 break;
6741 }
6742 break;
6743 }
6744 case 'e':
6745 {
6746 if (LocaleCompare("encoding",option+1) == 0)
6747 {
6748 if (*option == '+')
6749 {
6750 (void) SetImageOption(image_info,option+1,"undefined");
6751 break;
6752 }
6753 (void) SetImageOption(image_info,option+1,argv[i+1]);
6754 break;
6755 }
6756 if (LocaleCompare("endian",option+1) == 0)
6757 {
6758 if (*option == '+')
6759 {
6760 image_info->endian=UndefinedEndian;
6761 (void) SetImageOption(image_info,option+1,"undefined");
6762 break;
6763 }
6764 image_info->endian=(EndianType) ParseMagickOption(
6765 MagickEndianOptions,MagickFalse,argv[i+1]);
6766 (void) SetImageOption(image_info,option+1,argv[i+1]);
6767 break;
6768 }
6769 if (LocaleCompare("extract",option+1) == 0)
6770 {
6771 /*
6772 Set image extract geometry.
6773 */
6774 if (*option == '+')
6775 {
6776 if (image_info->extract != (char *) NULL)
6777 image_info->extract=DestroyString(image_info->extract);
6778 break;
6779 }
6780 (void) CloneString(&image_info->extract,argv[i+1]);
6781 break;
6782 }
6783 break;
6784 }
6785 case 'f':
6786 {
6787 if (LocaleCompare("fill",option+1) == 0)
6788 {
6789 if (*option == '+')
6790 {
6791 (void) SetImageOption(image_info,option+1,"none");
6792 break;
6793 }
6794 (void) SetImageOption(image_info,option+1,argv[i+1]);
6795 break;
6796 }
6797 if (LocaleCompare("filter",option+1) == 0)
6798 {
6799 if (*option == '+')
6800 {
6801 (void) SetImageOption(image_info,option+1,"undefined");
6802 break;
6803 }
6804 (void) SetImageOption(image_info,option+1,argv[i+1]);
6805 break;
6806 }
6807 if (LocaleCompare("font",option+1) == 0)
6808 {
6809 if (*option == '+')
6810 {
6811 if (image_info->font != (char *) NULL)
6812 image_info->font=DestroyString(image_info->font);
6813 break;
6814 }
6815 (void) CloneString(&image_info->font,argv[i+1]);
6816 break;
6817 }
6818 if (LocaleCompare("format",option+1) == 0)
6819 {
6820 register const char
6821 *q;
6822
6823 for (q=strchr(argv[i+1],'%'); q != (char *) NULL; q=strchr(q+1,'%'))
6824 if (strchr("gkrz@[#",*(q+1)) != (char *) NULL)
6825 image_info->ping=MagickFalse;
6826 (void) SetImageOption(image_info,option+1,argv[i+1]);
6827 break;
6828 }
6829 if (LocaleCompare("fuzz",option+1) == 0)
6830 {
6831 if (*option == '+')
6832 {
6833 image_info->fuzz=0.0;
6834 (void) SetImageOption(image_info,option+1,"0");
6835 break;
6836 }
cristyf2f27272009-12-17 14:48:46 +00006837 image_info->fuzz=SiPrefixToDouble(argv[i+1],(double) QuantumRange+
cristy3ed852e2009-09-05 21:47:34 +00006838 1.0);
6839 (void) SetImageOption(image_info,option+1,argv[i+1]);
6840 break;
6841 }
6842 break;
6843 }
6844 case 'g':
6845 {
6846 if (LocaleCompare("gravity",option+1) == 0)
6847 {
6848 if (*option == '+')
6849 {
6850 (void) SetImageOption(image_info,option+1,"undefined");
6851 break;
6852 }
6853 (void) SetImageOption(image_info,option+1,argv[i+1]);
6854 break;
6855 }
6856 if (LocaleCompare("green-primary",option+1) == 0)
6857 {
6858 if (*option == '+')
6859 {
6860 (void) SetImageOption(image_info,option+1,"0.0");
6861 break;
6862 }
6863 (void) SetImageOption(image_info,option+1,argv[i+1]);
6864 break;
6865 }
6866 break;
6867 }
6868 case 'i':
6869 {
6870 if (LocaleCompare("intent",option+1) == 0)
6871 {
6872 if (*option == '+')
6873 {
6874 (void) SetImageOption(image_info,option+1,"undefined");
6875 break;
6876 }
6877 (void) SetImageOption(image_info,option+1,argv[i+1]);
6878 break;
6879 }
6880 if (LocaleCompare("interlace",option+1) == 0)
6881 {
6882 if (*option == '+')
6883 {
6884 image_info->interlace=UndefinedInterlace;
6885 (void) SetImageOption(image_info,option+1,"undefined");
6886 break;
6887 }
6888 image_info->interlace=(InterlaceType) ParseMagickOption(
6889 MagickInterlaceOptions,MagickFalse,argv[i+1]);
6890 (void) SetImageOption(image_info,option+1,argv[i+1]);
6891 break;
6892 }
cristyb32b90a2009-09-07 21:45:48 +00006893 if (LocaleCompare("interline-spacing",option+1) == 0)
6894 {
6895 if (*option == '+')
6896 {
6897 (void) SetImageOption(image_info,option+1,"undefined");
6898 break;
6899 }
6900 (void) SetImageOption(image_info,option+1,argv[i+1]);
6901 break;
6902 }
cristy3ed852e2009-09-05 21:47:34 +00006903 if (LocaleCompare("interpolate",option+1) == 0)
6904 {
6905 if (*option == '+')
6906 {
6907 (void) SetImageOption(image_info,option+1,"undefined");
6908 break;
6909 }
6910 (void) SetImageOption(image_info,option+1,argv[i+1]);
6911 break;
6912 }
6913 if (LocaleCompare("interword-spacing",option+1) == 0)
6914 {
6915 if (*option == '+')
6916 {
6917 (void) SetImageOption(image_info,option+1,"undefined");
6918 break;
6919 }
6920 (void) SetImageOption(image_info,option+1,argv[i+1]);
6921 break;
6922 }
6923 break;
6924 }
6925 case 'k':
6926 {
6927 if (LocaleCompare("kerning",option+1) == 0)
6928 {
6929 if (*option == '+')
6930 {
6931 (void) SetImageOption(image_info,option+1,"undefined");
6932 break;
6933 }
6934 (void) SetImageOption(image_info,option+1,argv[i+1]);
6935 break;
6936 }
6937 break;
6938 }
6939 case 'l':
6940 {
6941 if (LocaleCompare("label",option+1) == 0)
6942 {
6943 if (*option == '+')
6944 {
6945 (void) DeleteImageOption(image_info,option+1);
6946 break;
6947 }
6948 (void) SetImageOption(image_info,option+1,argv[i+1]);
6949 break;
6950 }
6951 if (LocaleCompare("limit",option+1) == 0)
6952 {
6953 MagickSizeType
6954 limit;
6955
6956 ResourceType
6957 type;
6958
6959 if (*option == '+')
6960 break;
6961 type=(ResourceType) ParseMagickOption(MagickResourceOptions,
6962 MagickFalse,argv[i+1]);
6963 limit=MagickResourceInfinity;
6964 if (LocaleCompare("unlimited",argv[i+2]) != 0)
cristyf2f27272009-12-17 14:48:46 +00006965 limit=(MagickSizeType) SiPrefixToDouble(argv[i+2],100.0);
cristy3ed852e2009-09-05 21:47:34 +00006966 (void) SetMagickResourceLimit(type,limit);
6967 break;
6968 }
6969 if (LocaleCompare("list",option+1) == 0)
6970 {
cristybb503372010-05-27 20:51:26 +00006971 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006972 list;
6973
6974 /*
6975 Display configuration list.
6976 */
6977 list=ParseMagickOption(MagickListOptions,MagickFalse,argv[i+1]);
6978 switch (list)
6979 {
6980 case MagickCoderOptions:
6981 {
6982 (void) ListCoderInfo((FILE *) NULL,exception);
6983 break;
6984 }
6985 case MagickColorOptions:
6986 {
6987 (void) ListColorInfo((FILE *) NULL,exception);
6988 break;
6989 }
6990 case MagickConfigureOptions:
6991 {
6992 (void) ListConfigureInfo((FILE *) NULL,exception);
6993 break;
6994 }
6995 case MagickDelegateOptions:
6996 {
6997 (void) ListDelegateInfo((FILE *) NULL,exception);
6998 break;
6999 }
7000 case MagickFontOptions:
7001 {
7002 (void) ListTypeInfo((FILE *) NULL,exception);
7003 break;
7004 }
7005 case MagickFormatOptions:
7006 {
7007 (void) ListMagickInfo((FILE *) NULL,exception);
7008 break;
7009 }
7010 case MagickLocaleOptions:
7011 {
7012 (void) ListLocaleInfo((FILE *) NULL,exception);
7013 break;
7014 }
7015 case MagickLogOptions:
7016 {
7017 (void) ListLogInfo((FILE *) NULL,exception);
7018 break;
7019 }
7020 case MagickMagicOptions:
7021 {
7022 (void) ListMagicInfo((FILE *) NULL,exception);
7023 break;
7024 }
7025 case MagickMimeOptions:
7026 {
7027 (void) ListMimeInfo((FILE *) NULL,exception);
7028 break;
7029 }
7030 case MagickModuleOptions:
7031 {
7032 (void) ListModuleInfo((FILE *) NULL,exception);
7033 break;
7034 }
7035 case MagickPolicyOptions:
7036 {
7037 (void) ListPolicyInfo((FILE *) NULL,exception);
7038 break;
7039 }
7040 case MagickResourceOptions:
7041 {
7042 (void) ListMagickResourceInfo((FILE *) NULL,exception);
7043 break;
7044 }
7045 case MagickThresholdOptions:
7046 {
7047 (void) ListThresholdMaps((FILE *) NULL,exception);
7048 break;
7049 }
7050 default:
7051 {
7052 (void) ListMagickOptions((FILE *) NULL,(MagickOption) list,
7053 exception);
7054 break;
7055 }
7056 }
cristyaeb2cbc2010-05-07 13:28:58 +00007057 break;
cristy3ed852e2009-09-05 21:47:34 +00007058 }
7059 if (LocaleCompare("log",option+1) == 0)
7060 {
7061 if (*option == '+')
7062 break;
7063 (void) SetLogFormat(argv[i+1]);
7064 break;
7065 }
7066 if (LocaleCompare("loop",option+1) == 0)
7067 {
7068 if (*option == '+')
7069 {
7070 (void) SetImageOption(image_info,option+1,"0");
7071 break;
7072 }
7073 (void) SetImageOption(image_info,option+1,argv[i+1]);
7074 break;
7075 }
7076 break;
7077 }
7078 case 'm':
7079 {
7080 if (LocaleCompare("matte",option+1) == 0)
7081 {
7082 if (*option == '+')
7083 {
7084 (void) SetImageOption(image_info,option+1,"false");
7085 break;
7086 }
7087 (void) SetImageOption(image_info,option+1,"true");
7088 break;
7089 }
7090 if (LocaleCompare("mattecolor",option+1) == 0)
7091 {
7092 if (*option == '+')
7093 {
7094 (void) SetImageOption(image_info,option+1,argv[i+1]);
7095 (void) QueryColorDatabase(MatteColor,&image_info->matte_color,
7096 exception);
7097 break;
7098 }
7099 (void) SetImageOption(image_info,option+1,argv[i+1]);
7100 (void) QueryColorDatabase(argv[i+1],&image_info->matte_color,
7101 exception);
7102 break;
7103 }
7104 if (LocaleCompare("monitor",option+1) == 0)
7105 {
7106 (void) SetImageInfoProgressMonitor(image_info,MonitorProgress,
7107 (void *) NULL);
7108 break;
7109 }
7110 if (LocaleCompare("monochrome",option+1) == 0)
7111 {
7112 image_info->monochrome=(*option == '-') ? MagickTrue : MagickFalse;
7113 break;
7114 }
7115 break;
7116 }
7117 case 'o':
7118 {
7119 if (LocaleCompare("orient",option+1) == 0)
7120 {
7121 if (*option == '+')
7122 {
7123 image_info->orientation=UndefinedOrientation;
7124 (void) SetImageOption(image_info,option+1,"undefined");
7125 break;
7126 }
7127 image_info->orientation=(OrientationType) ParseMagickOption(
7128 MagickOrientationOptions,MagickFalse,argv[i+1]);
cristyc6e214d2010-08-08 00:31:08 +00007129 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007130 break;
7131 }
7132 }
7133 case 'p':
7134 {
7135 if (LocaleCompare("page",option+1) == 0)
7136 {
7137 char
7138 *canonical_page,
7139 page[MaxTextExtent];
7140
7141 const char
7142 *image_option;
7143
7144 MagickStatusType
7145 flags;
7146
7147 RectangleInfo
7148 geometry;
7149
7150 if (*option == '+')
7151 {
7152 (void) DeleteImageOption(image_info,option+1);
7153 (void) CloneString(&image_info->page,(char *) NULL);
7154 break;
7155 }
7156 (void) ResetMagickMemory(&geometry,0,sizeof(geometry));
7157 image_option=GetImageOption(image_info,"page");
7158 if (image_option != (const char *) NULL)
7159 flags=ParseAbsoluteGeometry(image_option,&geometry);
7160 canonical_page=GetPageGeometry(argv[i+1]);
7161 flags=ParseAbsoluteGeometry(canonical_page,&geometry);
7162 canonical_page=DestroyString(canonical_page);
7163 (void) FormatMagickString(page,MaxTextExtent,"%lux%lu",
cristyf2faecf2010-05-28 19:19:36 +00007164 (unsigned long) geometry.width,(unsigned long) geometry.height);
cristy3ed852e2009-09-05 21:47:34 +00007165 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
7166 (void) FormatMagickString(page,MaxTextExtent,"%lux%lu%+ld%+ld",
cristyf2faecf2010-05-28 19:19:36 +00007167 (unsigned long) geometry.width,(unsigned long) geometry.height,
7168 (long) geometry.x,(long) geometry.y);
cristy3ed852e2009-09-05 21:47:34 +00007169 (void) SetImageOption(image_info,option+1,page);
7170 (void) CloneString(&image_info->page,page);
7171 break;
7172 }
7173 if (LocaleCompare("pen",option+1) == 0)
7174 {
7175 if (*option == '+')
7176 {
7177 (void) SetImageOption(image_info,option+1,"none");
7178 break;
7179 }
7180 (void) SetImageOption(image_info,option+1,argv[i+1]);
7181 break;
7182 }
7183 if (LocaleCompare("ping",option+1) == 0)
7184 {
7185 image_info->ping=(*option == '-') ? MagickTrue : MagickFalse;
7186 break;
7187 }
7188 if (LocaleCompare("pointsize",option+1) == 0)
7189 {
7190 if (*option == '+')
7191 geometry_info.rho=0.0;
7192 else
7193 (void) ParseGeometry(argv[i+1],&geometry_info);
7194 image_info->pointsize=geometry_info.rho;
7195 break;
7196 }
cristye7f51092010-01-17 00:39:37 +00007197 if (LocaleCompare("precision",option+1) == 0)
7198 {
cristybf2766a2010-01-17 03:33:23 +00007199 (void) SetMagickPrecision(StringToInteger(argv[i+1]));
cristye7f51092010-01-17 00:39:37 +00007200 break;
7201 }
cristy3ed852e2009-09-05 21:47:34 +00007202 if (LocaleCompare("preview",option+1) == 0)
7203 {
7204 /*
7205 Preview image.
7206 */
7207 if (*option == '+')
7208 {
7209 image_info->preview_type=UndefinedPreview;
7210 break;
7211 }
7212 image_info->preview_type=(PreviewType) ParseMagickOption(
7213 MagickPreviewOptions,MagickFalse,argv[i+1]);
7214 break;
7215 }
7216 break;
7217 }
7218 case 'q':
7219 {
7220 if (LocaleCompare("quality",option+1) == 0)
7221 {
7222 /*
7223 Set image compression quality.
7224 */
7225 if (*option == '+')
7226 {
7227 image_info->quality=UndefinedCompressionQuality;
7228 (void) SetImageOption(image_info,option+1,"0");
7229 break;
7230 }
cristye27293e2009-12-18 02:53:20 +00007231 image_info->quality=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007232 (void) SetImageOption(image_info,option+1,argv[i+1]);
7233 break;
7234 }
7235 if (LocaleCompare("quiet",option+1) == 0)
7236 {
7237 static WarningHandler
7238 warning_handler = (WarningHandler) NULL;
7239
7240 if (*option == '+')
7241 {
7242 /*
7243 Restore error or warning messages.
7244 */
7245 warning_handler=SetWarningHandler(warning_handler);
7246 break;
7247 }
7248 /*
7249 Suppress error or warning messages.
7250 */
7251 warning_handler=SetWarningHandler((WarningHandler) NULL);
7252 break;
7253 }
7254 break;
7255 }
7256 case 'r':
7257 {
7258 if (LocaleCompare("red-primary",option+1) == 0)
7259 {
7260 if (*option == '+')
7261 {
7262 (void) SetImageOption(image_info,option+1,"0.0");
7263 break;
7264 }
7265 (void) SetImageOption(image_info,option+1,argv[i+1]);
7266 break;
7267 }
7268 break;
7269 }
7270 case 's':
7271 {
7272 if (LocaleCompare("sampling-factor",option+1) == 0)
7273 {
7274 /*
7275 Set image sampling factor.
7276 */
7277 if (*option == '+')
7278 {
7279 if (image_info->sampling_factor != (char *) NULL)
7280 image_info->sampling_factor=DestroyString(
7281 image_info->sampling_factor);
7282 break;
7283 }
7284 (void) CloneString(&image_info->sampling_factor,argv[i+1]);
7285 break;
7286 }
7287 if (LocaleCompare("scene",option+1) == 0)
7288 {
7289 /*
7290 Set image scene.
7291 */
7292 if (*option == '+')
7293 {
7294 image_info->scene=0;
7295 (void) SetImageOption(image_info,option+1,"0");
7296 break;
7297 }
cristye27293e2009-12-18 02:53:20 +00007298 image_info->scene=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007299 (void) SetImageOption(image_info,option+1,argv[i+1]);
7300 break;
7301 }
7302 if (LocaleCompare("seed",option+1) == 0)
7303 {
cristybb503372010-05-27 20:51:26 +00007304 size_t
cristy3ed852e2009-09-05 21:47:34 +00007305 seed;
7306
7307 if (*option == '+')
7308 {
cristybb503372010-05-27 20:51:26 +00007309 seed=(size_t) time((time_t *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00007310 SeedPseudoRandomGenerator(seed);
7311 break;
7312 }
cristye27293e2009-12-18 02:53:20 +00007313 seed=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007314 SeedPseudoRandomGenerator(seed);
7315 break;
7316 }
7317 if (LocaleCompare("size",option+1) == 0)
7318 {
7319 if (*option == '+')
7320 {
7321 if (image_info->size != (char *) NULL)
7322 image_info->size=DestroyString(image_info->size);
7323 break;
7324 }
7325 (void) CloneString(&image_info->size,argv[i+1]);
7326 break;
7327 }
7328 if (LocaleCompare("stroke",option+1) == 0)
7329 {
7330 if (*option == '+')
7331 {
7332 (void) SetImageOption(image_info,option+1,"none");
7333 break;
7334 }
7335 (void) SetImageOption(image_info,option+1,argv[i+1]);
7336 break;
7337 }
7338 if (LocaleCompare("strokewidth",option+1) == 0)
7339 {
7340 if (*option == '+')
7341 {
7342 (void) SetImageOption(image_info,option+1,"0");
7343 break;
7344 }
7345 (void) SetImageOption(image_info,option+1,argv[i+1]);
7346 break;
7347 }
7348 break;
7349 }
7350 case 't':
7351 {
7352 if (LocaleCompare("taint",option+1) == 0)
7353 {
7354 if (*option == '+')
7355 {
7356 (void) SetImageOption(image_info,option+1,"false");
7357 break;
7358 }
7359 (void) SetImageOption(image_info,option+1,"true");
7360 break;
7361 }
7362 if (LocaleCompare("texture",option+1) == 0)
7363 {
7364 if (*option == '+')
7365 {
7366 if (image_info->texture != (char *) NULL)
7367 image_info->texture=DestroyString(image_info->texture);
7368 break;
7369 }
7370 (void) CloneString(&image_info->texture,argv[i+1]);
7371 break;
7372 }
7373 if (LocaleCompare("tile-offset",option+1) == 0)
7374 {
7375 if (*option == '+')
7376 {
7377 (void) SetImageOption(image_info,option+1,"0");
7378 break;
7379 }
7380 (void) SetImageOption(image_info,option+1,argv[i+1]);
7381 break;
7382 }
7383 if (LocaleCompare("transparent-color",option+1) == 0)
7384 {
7385 if (*option == '+')
7386 {
7387 (void) QueryColorDatabase("none",&image_info->transparent_color, exception);
7388 (void) SetImageOption(image_info,option+1,"none");
7389 break;
7390 }
7391 (void) QueryColorDatabase(argv[i+1],&image_info->transparent_color,
7392 exception);
7393 (void) SetImageOption(image_info,option+1,argv[i+1]);
7394 break;
7395 }
7396 if (LocaleCompare("type",option+1) == 0)
7397 {
7398 if (*option == '+')
7399 {
7400 image_info->type=UndefinedType;
7401 (void) SetImageOption(image_info,option+1,"undefined");
7402 break;
7403 }
7404 image_info->type=(ImageType) ParseMagickOption(MagickTypeOptions,
7405 MagickFalse,argv[i+1]);
7406 (void) SetImageOption(image_info,option+1,argv[i+1]);
7407 break;
7408 }
7409 break;
7410 }
7411 case 'u':
7412 {
7413 if (LocaleCompare("undercolor",option+1) == 0)
7414 {
7415 if (*option == '+')
7416 {
7417 (void) DeleteImageOption(image_info,option+1);
7418 break;
7419 }
7420 (void) SetImageOption(image_info,option+1,argv[i+1]);
7421 break;
7422 }
7423 if (LocaleCompare("units",option+1) == 0)
7424 {
7425 if (*option == '+')
7426 {
7427 image_info->units=UndefinedResolution;
7428 (void) SetImageOption(image_info,option+1,"undefined");
7429 break;
7430 }
7431 image_info->units=(ResolutionType) ParseMagickOption(
7432 MagickResolutionOptions,MagickFalse,argv[i+1]);
7433 (void) SetImageOption(image_info,option+1,argv[i+1]);
7434 break;
7435 }
7436 break;
7437 }
7438 case 'v':
7439 {
7440 if (LocaleCompare("verbose",option+1) == 0)
7441 {
7442 if (*option == '+')
7443 {
7444 image_info->verbose=MagickFalse;
7445 break;
7446 }
7447 image_info->verbose=MagickTrue;
7448 image_info->ping=MagickFalse;
7449 break;
7450 }
7451 if (LocaleCompare("view",option+1) == 0)
7452 {
7453 if (*option == '+')
7454 {
7455 if (image_info->view != (char *) NULL)
7456 image_info->view=DestroyString(image_info->view);
7457 break;
7458 }
7459 (void) CloneString(&image_info->view,argv[i+1]);
7460 break;
7461 }
7462 if (LocaleCompare("virtual-pixel",option+1) == 0)
7463 {
7464 if (*option == '+')
7465 {
7466 image_info->virtual_pixel_method=UndefinedVirtualPixelMethod;
7467 (void) SetImageOption(image_info,option+1,"undefined");
7468 break;
7469 }
7470 image_info->virtual_pixel_method=(VirtualPixelMethod)
7471 ParseMagickOption(MagickVirtualPixelOptions,MagickFalse,
7472 argv[i+1]);
7473 (void) SetImageOption(image_info,option+1,argv[i+1]);
7474 break;
7475 }
7476 break;
7477 }
7478 case 'w':
7479 {
7480 if (LocaleCompare("white-point",option+1) == 0)
7481 {
7482 if (*option == '+')
7483 {
7484 (void) SetImageOption(image_info,option+1,"0.0");
7485 break;
7486 }
7487 (void) SetImageOption(image_info,option+1,argv[i+1]);
7488 break;
7489 }
7490 break;
7491 }
7492 default:
7493 break;
7494 }
7495 i+=count;
7496 }
7497 return(MagickTrue);
7498}
7499
7500/*
7501%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7502% %
7503% %
7504% %
7505+ M o g r i f y I m a g e L i s t %
7506% %
7507% %
7508% %
7509%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7510%
7511% MogrifyImageList() applies any command line options that might affect the
7512% entire image list (e.g. -append, -coalesce, etc.).
7513%
7514% The format of the MogrifyImage method is:
7515%
7516% MagickBooleanType MogrifyImageList(ImageInfo *image_info,const int argc,
7517% const char **argv,Image **images,ExceptionInfo *exception)
7518%
7519% A description of each parameter follows:
7520%
7521% o image_info: the image info..
7522%
7523% o argc: Specifies a pointer to an integer describing the number of
7524% elements in the argument vector.
7525%
7526% o argv: Specifies a pointer to a text array containing the command line
7527% arguments.
7528%
7529% o images: the images.
7530%
7531% o exception: return any errors or warnings in this structure.
7532%
7533*/
7534WandExport MagickBooleanType MogrifyImageList(ImageInfo *image_info,
7535 const int argc,const char **argv,Image **images,ExceptionInfo *exception)
7536{
7537 ChannelType
7538 channel;
7539
7540 const char
7541 *option;
7542
cristy6b3da3a2010-06-20 02:21:46 +00007543 ImageInfo
7544 *mogrify_info;
cristy3ed852e2009-09-05 21:47:34 +00007545
7546 MagickStatusType
7547 status;
7548
7549 QuantizeInfo
7550 *quantize_info;
7551
cristybb503372010-05-27 20:51:26 +00007552 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00007553 i;
7554
cristy6b3da3a2010-06-20 02:21:46 +00007555 ssize_t
7556 count,
7557 index;
7558
cristy3ed852e2009-09-05 21:47:34 +00007559 /*
7560 Apply options to the image list.
7561 */
7562 assert(image_info != (ImageInfo *) NULL);
7563 assert(image_info->signature == MagickSignature);
7564 assert(images != (Image **) NULL);
7565 assert((*images)->signature == MagickSignature);
7566 if ((*images)->debug != MagickFalse)
7567 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
7568 (*images)->filename);
7569 if ((argc <= 0) || (*argv == (char *) NULL))
7570 return(MagickTrue);
cristy6b3da3a2010-06-20 02:21:46 +00007571 mogrify_info=CloneImageInfo(image_info);
7572 quantize_info=AcquireQuantizeInfo(mogrify_info);
7573 channel=mogrify_info->channel;
cristy3ed852e2009-09-05 21:47:34 +00007574 status=MagickTrue;
cristybb503372010-05-27 20:51:26 +00007575 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00007576 {
cristy74fe8f12009-10-03 19:09:01 +00007577 if (*images == (Image *) NULL)
7578 break;
cristy3ed852e2009-09-05 21:47:34 +00007579 option=argv[i];
7580 if (IsMagickOption(option) == MagickFalse)
7581 continue;
7582 count=MagickMax(ParseMagickOption(MagickCommandOptions,MagickFalse,option),
7583 0L);
cristycee97112010-05-28 00:44:52 +00007584 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00007585 break;
cristy6b3da3a2010-06-20 02:21:46 +00007586 status=MogrifyImageInfo(mogrify_info,(int) count+1,argv+i,exception);
cristy3ed852e2009-09-05 21:47:34 +00007587 switch (*(option+1))
7588 {
7589 case 'a':
7590 {
7591 if (LocaleCompare("affinity",option+1) == 0)
7592 {
cristy6b3da3a2010-06-20 02:21:46 +00007593 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007594 if (*option == '+')
7595 {
7596 (void) RemapImages(quantize_info,*images,(Image *) NULL);
7597 InheritException(exception,&(*images)->exception);
7598 break;
7599 }
7600 i++;
7601 break;
7602 }
7603 if (LocaleCompare("append",option+1) == 0)
7604 {
7605 Image
7606 *append_image;
7607
cristy6b3da3a2010-06-20 02:21:46 +00007608 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007609 append_image=AppendImages(*images,*option == '-' ? MagickTrue :
7610 MagickFalse,exception);
7611 if (append_image == (Image *) NULL)
7612 {
7613 status=MagickFalse;
7614 break;
7615 }
7616 *images=DestroyImageList(*images);
7617 *images=append_image;
7618 break;
7619 }
7620 if (LocaleCompare("average",option+1) == 0)
7621 {
7622 Image
7623 *average_image;
7624
cristyd18ae7c2010-03-07 17:39:52 +00007625 /*
7626 Average an image sequence (deprecated).
7627 */
cristy6b3da3a2010-06-20 02:21:46 +00007628 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007629 average_image=EvaluateImages(*images,MeanEvaluateOperator,
7630 exception);
cristy3ed852e2009-09-05 21:47:34 +00007631 if (average_image == (Image *) NULL)
7632 {
7633 status=MagickFalse;
7634 break;
7635 }
7636 *images=DestroyImageList(*images);
7637 *images=average_image;
7638 break;
7639 }
7640 break;
7641 }
7642 case 'c':
7643 {
7644 if (LocaleCompare("channel",option+1) == 0)
7645 {
7646 if (*option == '+')
7647 {
7648 channel=DefaultChannels;
7649 break;
7650 }
7651 channel=(ChannelType) ParseChannelOption(argv[i+1]);
7652 break;
7653 }
7654 if (LocaleCompare("clut",option+1) == 0)
7655 {
7656 Image
7657 *clut_image,
7658 *image;
7659
cristy6b3da3a2010-06-20 02:21:46 +00007660 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007661 image=RemoveFirstImageFromList(images);
7662 clut_image=RemoveFirstImageFromList(images);
7663 if (clut_image == (Image *) NULL)
7664 {
7665 status=MagickFalse;
7666 break;
7667 }
7668 (void) ClutImageChannel(image,channel,clut_image);
7669 clut_image=DestroyImage(clut_image);
7670 InheritException(exception,&image->exception);
7671 *images=DestroyImageList(*images);
7672 *images=image;
7673 break;
7674 }
7675 if (LocaleCompare("coalesce",option+1) == 0)
7676 {
7677 Image
7678 *coalesce_image;
7679
cristy6b3da3a2010-06-20 02:21:46 +00007680 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007681 coalesce_image=CoalesceImages(*images,exception);
7682 if (coalesce_image == (Image *) NULL)
7683 {
7684 status=MagickFalse;
7685 break;
7686 }
7687 *images=DestroyImageList(*images);
7688 *images=coalesce_image;
7689 break;
7690 }
7691 if (LocaleCompare("combine",option+1) == 0)
7692 {
7693 Image
7694 *combine_image;
7695
cristy6b3da3a2010-06-20 02:21:46 +00007696 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007697 combine_image=CombineImages(*images,channel,exception);
7698 if (combine_image == (Image *) NULL)
7699 {
7700 status=MagickFalse;
7701 break;
7702 }
7703 *images=DestroyImageList(*images);
7704 *images=combine_image;
7705 break;
7706 }
7707 if (LocaleCompare("composite",option+1) == 0)
7708 {
7709 Image
7710 *mask_image,
7711 *composite_image,
7712 *image;
7713
7714 RectangleInfo
7715 geometry;
7716
cristy6b3da3a2010-06-20 02:21:46 +00007717 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007718 image=RemoveFirstImageFromList(images);
7719 composite_image=RemoveFirstImageFromList(images);
7720 if (composite_image == (Image *) NULL)
7721 {
7722 status=MagickFalse;
7723 break;
7724 }
7725 (void) TransformImage(&composite_image,(char *) NULL,
7726 composite_image->geometry);
7727 SetGeometry(composite_image,&geometry);
7728 (void) ParseAbsoluteGeometry(composite_image->geometry,&geometry);
7729 GravityAdjustGeometry(image->columns,image->rows,image->gravity,
7730 &geometry);
7731 mask_image=RemoveFirstImageFromList(images);
7732 if (mask_image != (Image *) NULL)
7733 {
7734 if ((image->compose == DisplaceCompositeOp) ||
7735 (image->compose == DistortCompositeOp))
7736 {
7737 /*
7738 Merge Y displacement into X displacement image.
7739 */
7740 (void) CompositeImage(composite_image,CopyGreenCompositeOp,
7741 mask_image,0,0);
7742 mask_image=DestroyImage(mask_image);
7743 }
7744 else
7745 {
7746 /*
7747 Set a blending mask for the composition.
7748 */
7749 image->mask=mask_image;
7750 (void) NegateImage(image->mask,MagickFalse);
7751 }
7752 }
7753 (void) CompositeImageChannel(image,channel,image->compose,
7754 composite_image,geometry.x,geometry.y);
7755 if (image->mask != (Image *) NULL)
7756 image->mask=DestroyImage(image->mask);
7757 composite_image=DestroyImage(composite_image);
7758 InheritException(exception,&image->exception);
7759 *images=DestroyImageList(*images);
7760 *images=image;
7761 break;
7762 }
7763 if (LocaleCompare("crop",option+1) == 0)
7764 {
7765 MagickStatusType
7766 flags;
7767
7768 RectangleInfo
7769 geometry;
7770
cristy6b3da3a2010-06-20 02:21:46 +00007771 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007772 flags=ParseGravityGeometry(*images,argv[i+1],&geometry,exception);
7773 if (((geometry.width == 0) && (geometry.height == 0)) ||
7774 ((flags & XValue) != 0) || ((flags & YValue) != 0))
7775 break;
7776 (void) TransformImages(images,argv[i+1],(char *) NULL);
7777 InheritException(exception,&(*images)->exception);
7778 break;
7779 }
7780 break;
7781 }
7782 case 'd':
7783 {
7784 if (LocaleCompare("deconstruct",option+1) == 0)
7785 {
7786 Image
7787 *deconstruct_image;
7788
cristy6b3da3a2010-06-20 02:21:46 +00007789 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007790 deconstruct_image=DeconstructImages(*images,exception);
7791 if (deconstruct_image == (Image *) NULL)
7792 {
7793 status=MagickFalse;
7794 break;
7795 }
7796 *images=DestroyImageList(*images);
7797 *images=deconstruct_image;
7798 break;
7799 }
7800 if (LocaleCompare("delete",option+1) == 0)
7801 {
7802 if (*option == '+')
7803 DeleteImages(images,"-1",exception);
7804 else
7805 DeleteImages(images,argv[i+1],exception);
7806 break;
7807 }
7808 if (LocaleCompare("dither",option+1) == 0)
7809 {
7810 if (*option == '+')
7811 {
7812 quantize_info->dither=MagickFalse;
7813 break;
7814 }
7815 quantize_info->dither=MagickTrue;
7816 quantize_info->dither_method=(DitherMethod) ParseMagickOption(
7817 MagickDitherOptions,MagickFalse,argv[i+1]);
7818 break;
7819 }
7820 break;
7821 }
cristyd18ae7c2010-03-07 17:39:52 +00007822 case 'e':
7823 {
7824 if (LocaleCompare("evaluate-sequence",option+1) == 0)
7825 {
7826 Image
7827 *evaluate_image;
7828
7829 MagickEvaluateOperator
7830 op;
7831
cristy6b3da3a2010-06-20 02:21:46 +00007832 (void) SyncImageSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007833 op=(MagickEvaluateOperator) ParseMagickOption(MagickEvaluateOptions,
7834 MagickFalse,argv[i+1]);
7835 evaluate_image=EvaluateImages(*images,op,exception);
7836 if (evaluate_image == (Image *) NULL)
7837 {
7838 status=MagickFalse;
7839 break;
7840 }
7841 *images=DestroyImageList(*images);
7842 *images=evaluate_image;
7843 break;
7844 }
7845 break;
7846 }
cristy3ed852e2009-09-05 21:47:34 +00007847 case 'f':
7848 {
cristyf0a247f2009-10-04 00:20:03 +00007849 if (LocaleCompare("fft",option+1) == 0)
7850 {
7851 Image
7852 *fourier_image;
7853
7854 /*
7855 Implements the discrete Fourier transform (DFT).
7856 */
cristy6b3da3a2010-06-20 02:21:46 +00007857 (void) SyncImageSettings(mogrify_info,*images);
cristyf0a247f2009-10-04 00:20:03 +00007858 fourier_image=ForwardFourierTransformImage(*images,*option == '-' ?
7859 MagickTrue : MagickFalse,exception);
7860 if (fourier_image == (Image *) NULL)
7861 break;
7862 *images=DestroyImage(*images);
7863 *images=fourier_image;
7864 break;
7865 }
cristy3ed852e2009-09-05 21:47:34 +00007866 if (LocaleCompare("flatten",option+1) == 0)
7867 {
7868 Image
7869 *flatten_image;
7870
cristy6b3da3a2010-06-20 02:21:46 +00007871 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007872 flatten_image=MergeImageLayers(*images,FlattenLayer,exception);
7873 if (flatten_image == (Image *) NULL)
7874 break;
7875 *images=DestroyImageList(*images);
7876 *images=flatten_image;
7877 break;
7878 }
7879 if (LocaleCompare("fx",option+1) == 0)
7880 {
7881 Image
7882 *fx_image;
7883
cristy6b3da3a2010-06-20 02:21:46 +00007884 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007885 fx_image=FxImageChannel(*images,channel,argv[i+1],exception);
7886 if (fx_image == (Image *) NULL)
7887 {
7888 status=MagickFalse;
7889 break;
7890 }
7891 *images=DestroyImageList(*images);
7892 *images=fx_image;
7893 break;
7894 }
7895 break;
7896 }
7897 case 'h':
7898 {
7899 if (LocaleCompare("hald-clut",option+1) == 0)
7900 {
7901 Image
7902 *hald_image,
7903 *image;
7904
cristy6b3da3a2010-06-20 02:21:46 +00007905 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007906 image=RemoveFirstImageFromList(images);
7907 hald_image=RemoveFirstImageFromList(images);
7908 if (hald_image == (Image *) NULL)
7909 {
7910 status=MagickFalse;
7911 break;
7912 }
7913 (void) HaldClutImageChannel(image,channel,hald_image);
7914 hald_image=DestroyImage(hald_image);
7915 InheritException(exception,&image->exception);
cristy0aff6ea2009-11-14 01:40:53 +00007916 if (*images != (Image *) NULL)
7917 *images=DestroyImageList(*images);
cristy3ed852e2009-09-05 21:47:34 +00007918 *images=image;
7919 break;
7920 }
7921 break;
7922 }
7923 case 'i':
7924 {
7925 if (LocaleCompare("ift",option+1) == 0)
7926 {
7927 Image
cristy8587f882009-11-13 20:28:49 +00007928 *fourier_image,
7929 *magnitude_image,
7930 *phase_image;
cristy3ed852e2009-09-05 21:47:34 +00007931
7932 /*
7933 Implements the inverse fourier discrete Fourier transform (DFT).
7934 */
cristy6b3da3a2010-06-20 02:21:46 +00007935 (void) SyncImagesSettings(mogrify_info,*images);
cristy8587f882009-11-13 20:28:49 +00007936 magnitude_image=RemoveFirstImageFromList(images);
7937 phase_image=RemoveFirstImageFromList(images);
7938 if (phase_image == (Image *) NULL)
7939 {
7940 status=MagickFalse;
7941 break;
7942 }
7943 fourier_image=InverseFourierTransformImage(magnitude_image,
7944 phase_image,*option == '-' ? MagickTrue : MagickFalse,exception);
cristy3ed852e2009-09-05 21:47:34 +00007945 if (fourier_image == (Image *) NULL)
7946 break;
cristy0aff6ea2009-11-14 01:40:53 +00007947 if (*images != (Image *) NULL)
7948 *images=DestroyImage(*images);
cristy3ed852e2009-09-05 21:47:34 +00007949 *images=fourier_image;
7950 break;
7951 }
7952 if (LocaleCompare("insert",option+1) == 0)
7953 {
7954 Image
7955 *p,
7956 *q;
7957
7958 index=0;
7959 if (*option != '+')
cristyf2f27272009-12-17 14:48:46 +00007960 index=StringToLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007961 p=RemoveLastImageFromList(images);
7962 if (p == (Image *) NULL)
7963 {
7964 (void) ThrowMagickException(exception,GetMagickModule(),
7965 OptionError,"NoSuchImage","`%s'",argv[i+1]);
7966 status=MagickFalse;
7967 break;
7968 }
7969 q=p;
7970 if (index == 0)
7971 PrependImageToList(images,q);
7972 else
cristybb503372010-05-27 20:51:26 +00007973 if (index == (ssize_t) GetImageListLength(*images))
cristy3ed852e2009-09-05 21:47:34 +00007974 AppendImageToList(images,q);
7975 else
7976 {
7977 q=GetImageFromList(*images,index-1);
7978 if (q == (Image *) NULL)
7979 {
7980 (void) ThrowMagickException(exception,GetMagickModule(),
7981 OptionError,"NoSuchImage","`%s'",argv[i+1]);
7982 status=MagickFalse;
7983 break;
7984 }
7985 InsertImageInList(&q,p);
7986 }
7987 *images=GetFirstImageInList(q);
7988 break;
7989 }
7990 break;
7991 }
7992 case 'l':
7993 {
7994 if (LocaleCompare("layers",option+1) == 0)
7995 {
7996 Image
7997 *layers;
7998
7999 ImageLayerMethod
8000 method;
8001
cristy6b3da3a2010-06-20 02:21:46 +00008002 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00008003 layers=(Image *) NULL;
8004 method=(ImageLayerMethod) ParseMagickOption(MagickLayerOptions,
8005 MagickFalse,argv[i+1]);
8006 switch (method)
8007 {
8008 case CoalesceLayer:
8009 {
8010 layers=CoalesceImages(*images,exception);
8011 break;
8012 }
8013 case CompareAnyLayer:
8014 case CompareClearLayer:
8015 case CompareOverlayLayer:
8016 default:
8017 {
8018 layers=CompareImageLayers(*images,method,exception);
8019 break;
8020 }
8021 case MergeLayer:
8022 case FlattenLayer:
8023 case MosaicLayer:
8024 case TrimBoundsLayer:
8025 {
8026 layers=MergeImageLayers(*images,method,exception);
8027 break;
8028 }
8029 case DisposeLayer:
8030 {
8031 layers=DisposeImages(*images,exception);
8032 break;
8033 }
8034 case OptimizeImageLayer:
8035 {
8036 layers=OptimizeImageLayers(*images,exception);
8037 break;
8038 }
8039 case OptimizePlusLayer:
8040 {
8041 layers=OptimizePlusImageLayers(*images,exception);
8042 break;
8043 }
8044 case OptimizeTransLayer:
8045 {
8046 OptimizeImageTransparency(*images,exception);
8047 break;
8048 }
8049 case RemoveDupsLayer:
8050 {
8051 RemoveDuplicateLayers(images,exception);
8052 break;
8053 }
8054 case RemoveZeroLayer:
8055 {
8056 RemoveZeroDelayLayers(images,exception);
8057 break;
8058 }
8059 case OptimizeLayer:
8060 {
8061 /*
8062 General Purpose, GIF Animation Optimizer.
8063 */
8064 layers=CoalesceImages(*images,exception);
8065 if (layers == (Image *) NULL)
8066 {
8067 status=MagickFalse;
8068 break;
8069 }
8070 InheritException(exception,&layers->exception);
8071 *images=DestroyImageList(*images);
8072 *images=layers;
8073 layers=OptimizeImageLayers(*images,exception);
8074 if (layers == (Image *) NULL)
8075 {
8076 status=MagickFalse;
8077 break;
8078 }
8079 InheritException(exception,&layers->exception);
8080 *images=DestroyImageList(*images);
8081 *images=layers;
8082 layers=(Image *) NULL;
8083 OptimizeImageTransparency(*images,exception);
8084 InheritException(exception,&(*images)->exception);
8085 (void) RemapImages(quantize_info,*images,(Image *) NULL);
8086 break;
8087 }
8088 case CompositeLayer:
8089 {
8090 CompositeOperator
8091 compose;
8092
8093 Image
8094 *source;
8095
8096 RectangleInfo
8097 geometry;
8098
8099 /*
8100 Split image sequence at the first 'NULL:' image.
8101 */
8102 source=(*images);
8103 while (source != (Image *) NULL)
8104 {
8105 source=GetNextImageInList(source);
8106 if ((source != (Image *) NULL) &&
8107 (LocaleCompare(source->magick,"NULL") == 0))
8108 break;
8109 }
8110 if (source != (Image *) NULL)
8111 {
8112 if ((GetPreviousImageInList(source) == (Image *) NULL) ||
8113 (GetNextImageInList(source) == (Image *) NULL))
8114 source=(Image *) NULL;
8115 else
8116 {
8117 /*
8118 Separate the two lists, junk the null: image.
8119 */
8120 source=SplitImageList(source->previous);
8121 DeleteImageFromList(&source);
8122 }
8123 }
8124 if (source == (Image *) NULL)
8125 {
8126 (void) ThrowMagickException(exception,GetMagickModule(),
8127 OptionError,"MissingNullSeparator","layers Composite");
8128 status=MagickFalse;
8129 break;
8130 }
8131 /*
8132 Adjust offset with gravity and virtual canvas.
8133 */
8134 SetGeometry(*images,&geometry);
8135 (void) ParseAbsoluteGeometry((*images)->geometry,&geometry);
8136 geometry.width=source->page.width != 0 ?
8137 source->page.width : source->columns;
8138 geometry.height=source->page.height != 0 ?
8139 source->page.height : source->rows;
8140 GravityAdjustGeometry((*images)->page.width != 0 ?
8141 (*images)->page.width : (*images)->columns,
8142 (*images)->page.height != 0 ? (*images)->page.height :
8143 (*images)->rows,(*images)->gravity,&geometry);
8144 compose=OverCompositeOp;
cristy6b3da3a2010-06-20 02:21:46 +00008145 option=GetImageOption(mogrify_info,"compose");
cristy3ed852e2009-09-05 21:47:34 +00008146 if (option != (const char *) NULL)
8147 compose=(CompositeOperator) ParseMagickOption(
8148 MagickComposeOptions,MagickFalse,option);
8149 CompositeLayers(*images,compose,source,geometry.x,geometry.y,
8150 exception);
8151 source=DestroyImageList(source);
8152 break;
8153 }
8154 }
8155 if (layers == (Image *) NULL)
8156 break;
8157 InheritException(exception,&layers->exception);
8158 *images=DestroyImageList(*images);
8159 *images=layers;
8160 break;
8161 }
8162 break;
8163 }
8164 case 'm':
8165 {
8166 if (LocaleCompare("map",option+1) == 0)
8167 {
cristy6b3da3a2010-06-20 02:21:46 +00008168 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00008169 if (*option == '+')
8170 {
8171 (void) RemapImages(quantize_info,*images,(Image *) NULL);
8172 InheritException(exception,&(*images)->exception);
8173 break;
8174 }
8175 i++;
8176 break;
8177 }
cristyf40785b2010-03-06 02:27:27 +00008178 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00008179 {
8180 Image
cristyf40785b2010-03-06 02:27:27 +00008181 *maximum_image;
cristy1c274c92010-03-06 02:06:45 +00008182
cristyd18ae7c2010-03-07 17:39:52 +00008183 /*
8184 Maximum image sequence (deprecated).
8185 */
cristy6b3da3a2010-06-20 02:21:46 +00008186 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00008187 maximum_image=EvaluateImages(*images,MaxEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00008188 if (maximum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00008189 {
8190 status=MagickFalse;
8191 break;
8192 }
8193 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00008194 *images=maximum_image;
cristy1c274c92010-03-06 02:06:45 +00008195 break;
8196 }
cristyf40785b2010-03-06 02:27:27 +00008197 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00008198 {
8199 Image
cristyf40785b2010-03-06 02:27:27 +00008200 *minimum_image;
cristy1c274c92010-03-06 02:06:45 +00008201
cristyd18ae7c2010-03-07 17:39:52 +00008202 /*
8203 Minimum image sequence (deprecated).
8204 */
cristy6b3da3a2010-06-20 02:21:46 +00008205 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00008206 minimum_image=EvaluateImages(*images,MinEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00008207 if (minimum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00008208 {
8209 status=MagickFalse;
8210 break;
8211 }
8212 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00008213 *images=minimum_image;
cristy1c274c92010-03-06 02:06:45 +00008214 break;
8215 }
cristy3ed852e2009-09-05 21:47:34 +00008216 if (LocaleCompare("morph",option+1) == 0)
8217 {
8218 Image
8219 *morph_image;
8220
cristy6b3da3a2010-06-20 02:21:46 +00008221 (void) SyncImagesSettings(mogrify_info,*images);
cristye27293e2009-12-18 02:53:20 +00008222 morph_image=MorphImages(*images,StringToUnsignedLong(argv[i+1]),
cristy3ed852e2009-09-05 21:47:34 +00008223 exception);
8224 if (morph_image == (Image *) NULL)
8225 {
8226 status=MagickFalse;
8227 break;
8228 }
8229 *images=DestroyImageList(*images);
8230 *images=morph_image;
8231 break;
8232 }
8233 if (LocaleCompare("mosaic",option+1) == 0)
8234 {
8235 Image
8236 *mosaic_image;
8237
cristy6b3da3a2010-06-20 02:21:46 +00008238 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00008239 mosaic_image=MergeImageLayers(*images,MosaicLayer,exception);
8240 if (mosaic_image == (Image *) NULL)
8241 {
8242 status=MagickFalse;
8243 break;
8244 }
8245 *images=DestroyImageList(*images);
8246 *images=mosaic_image;
8247 break;
8248 }
8249 break;
8250 }
8251 case 'p':
8252 {
8253 if (LocaleCompare("print",option+1) == 0)
8254 {
8255 char
8256 *string;
8257
cristy6b3da3a2010-06-20 02:21:46 +00008258 (void) SyncImagesSettings(mogrify_info,*images);
8259 string=InterpretImageProperties(mogrify_info,*images,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00008260 if (string == (char *) NULL)
8261 break;
8262 InheritException(exception,&(*images)->exception);
8263 (void) fprintf(stdout,"%s",string);
8264 string=DestroyString(string);
8265 }
8266 if (LocaleCompare("process",option+1) == 0)
8267 {
8268 char
8269 **arguments;
8270
8271 int
8272 j,
8273 number_arguments;
8274
cristy6b3da3a2010-06-20 02:21:46 +00008275 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00008276 arguments=StringToArgv(argv[i+1],&number_arguments);
8277 if (arguments == (char **) NULL)
8278 break;
8279 if ((argc > 1) && (strchr(arguments[1],'=') != (char *) NULL))
8280 {
8281 char
8282 breaker,
8283 quote,
8284 *token;
8285
8286 const char
8287 *arguments;
8288
8289 int
8290 next,
8291 status;
8292
8293 size_t
8294 length;
8295
8296 TokenInfo
8297 *token_info;
8298
8299 /*
8300 Support old style syntax, filter="-option arg".
8301 */
8302 length=strlen(argv[i+1]);
8303 token=(char *) NULL;
8304 if (~length >= MaxTextExtent)
8305 token=(char *) AcquireQuantumMemory(length+MaxTextExtent,
8306 sizeof(*token));
8307 if (token == (char *) NULL)
8308 break;
8309 next=0;
8310 arguments=argv[i+1];
8311 token_info=AcquireTokenInfo();
8312 status=Tokenizer(token_info,0,token,length,arguments,"","=",
8313 "\"",'\0',&breaker,&next,&quote);
8314 token_info=DestroyTokenInfo(token_info);
8315 if (status == 0)
8316 {
8317 const char
8318 *argv;
8319
8320 argv=(&(arguments[next]));
8321 (void) InvokeDynamicImageFilter(token,&(*images),1,&argv,
8322 exception);
8323 }
8324 token=DestroyString(token);
8325 break;
8326 }
cristy91c0da22010-05-02 01:44:07 +00008327 (void) SubstituteString(&arguments[1],"-","");
cristy3ed852e2009-09-05 21:47:34 +00008328 (void) InvokeDynamicImageFilter(arguments[1],&(*images),
8329 number_arguments-2,(const char **) arguments+2,exception);
8330 for (j=0; j < number_arguments; j++)
8331 arguments[j]=DestroyString(arguments[j]);
8332 arguments=(char **) RelinquishMagickMemory(arguments);
8333 break;
8334 }
8335 break;
8336 }
8337 case 'r':
8338 {
8339 if (LocaleCompare("reverse",option+1) == 0)
8340 {
8341 ReverseImageList(images);
8342 InheritException(exception,&(*images)->exception);
8343 break;
8344 }
8345 break;
8346 }
8347 case 's':
8348 {
8349 if (LocaleCompare("swap",option+1) == 0)
8350 {
8351 Image
8352 *p,
8353 *q,
8354 *swap;
8355
cristybb503372010-05-27 20:51:26 +00008356 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00008357 swap_index;
8358
8359 index=(-1);
8360 swap_index=(-2);
8361 if (*option != '+')
8362 {
8363 GeometryInfo
8364 geometry_info;
8365
8366 MagickStatusType
8367 flags;
8368
8369 swap_index=(-1);
8370 flags=ParseGeometry(argv[i+1],&geometry_info);
cristybb503372010-05-27 20:51:26 +00008371 index=(ssize_t) geometry_info.rho;
cristy3ed852e2009-09-05 21:47:34 +00008372 if ((flags & SigmaValue) != 0)
cristybb503372010-05-27 20:51:26 +00008373 swap_index=(ssize_t) geometry_info.sigma;
cristy3ed852e2009-09-05 21:47:34 +00008374 }
8375 p=GetImageFromList(*images,index);
8376 q=GetImageFromList(*images,swap_index);
8377 if ((p == (Image *) NULL) || (q == (Image *) NULL))
8378 {
8379 (void) ThrowMagickException(exception,GetMagickModule(),
8380 OptionError,"NoSuchImage","`%s'",(*images)->filename);
8381 status=MagickFalse;
8382 break;
8383 }
8384 if (p == q)
8385 break;
8386 swap=CloneImage(p,0,0,MagickTrue,exception);
8387 ReplaceImageInList(&p,CloneImage(q,0,0,MagickTrue,exception));
8388 ReplaceImageInList(&q,swap);
8389 *images=GetFirstImageInList(q);
8390 break;
8391 }
8392 break;
8393 }
8394 case 'w':
8395 {
8396 if (LocaleCompare("write",option+1) == 0)
8397 {
cristy071dd7b2010-04-09 13:04:54 +00008398 char
cristy06609ee2010-03-17 20:21:27 +00008399 key[MaxTextExtent];
8400
cristy3ed852e2009-09-05 21:47:34 +00008401 Image
8402 *write_images;
8403
8404 ImageInfo
8405 *write_info;
8406
cristy6b3da3a2010-06-20 02:21:46 +00008407 (void) SyncImagesSettings(mogrify_info,*images);
cristy06609ee2010-03-17 20:21:27 +00008408 (void) FormatMagickString(key,MaxTextExtent,"cache:%s",argv[i+1]);
8409 (void) DeleteImageRegistry(key);
cristy3ed852e2009-09-05 21:47:34 +00008410 write_images=(*images);
8411 if (*option == '+')
8412 write_images=CloneImageList(*images,exception);
cristy6b3da3a2010-06-20 02:21:46 +00008413 write_info=CloneImageInfo(mogrify_info);
cristy3ed852e2009-09-05 21:47:34 +00008414 status&=WriteImages(write_info,write_images,argv[i+1],exception);
8415 write_info=DestroyImageInfo(write_info);
8416 if (*option == '+')
8417 write_images=DestroyImageList(write_images);
8418 break;
8419 }
8420 break;
8421 }
8422 default:
8423 break;
8424 }
8425 i+=count;
8426 }
8427 quantize_info=DestroyQuantizeInfo(quantize_info);
cristy6b3da3a2010-06-20 02:21:46 +00008428 mogrify_info=DestroyImageInfo(mogrify_info);
8429 status&=MogrifyImageInfo(image_info,argc,argv,exception);
cristy3ed852e2009-09-05 21:47:34 +00008430 return(status != 0 ? MagickTrue : MagickFalse);
8431}
8432
8433/*
8434%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8435% %
8436% %
8437% %
8438+ M o g r i f y I m a g e s %
8439% %
8440% %
8441% %
8442%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8443%
8444% MogrifyImages() applies image processing options to a sequence of images as
8445% prescribed by command line options.
8446%
8447% The format of the MogrifyImage method is:
8448%
8449% MagickBooleanType MogrifyImages(ImageInfo *image_info,
8450% const MagickBooleanType post,const int argc,const char **argv,
8451% Image **images,Exceptioninfo *exception)
8452%
8453% A description of each parameter follows:
8454%
8455% o image_info: the image info..
8456%
8457% o post: If true, post process image list operators otherwise pre-process.
8458%
8459% o argc: Specifies a pointer to an integer describing the number of
8460% elements in the argument vector.
8461%
8462% o argv: Specifies a pointer to a text array containing the command line
8463% arguments.
8464%
8465% o images: the images.
8466%
8467% o exception: return any errors or warnings in this structure.
8468%
8469*/
8470WandExport MagickBooleanType MogrifyImages(ImageInfo *image_info,
8471 const MagickBooleanType post,const int argc,const char **argv,
8472 Image **images,ExceptionInfo *exception)
8473{
8474#define MogrifyImageTag "Mogrify/Image"
8475
8476 Image
8477 *image,
8478 *mogrify_images;
8479
cristy0e9f9c12010-02-11 03:00:47 +00008480 MagickBooleanType
8481 proceed;
8482
8483 MagickSizeType
8484 number_images;
8485
cristy3ed852e2009-09-05 21:47:34 +00008486 MagickStatusType
8487 status;
8488
cristybb503372010-05-27 20:51:26 +00008489 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00008490 i;
8491
cristy3ed852e2009-09-05 21:47:34 +00008492 /*
8493 Apply options to individual images in the list.
8494 */
8495 assert(image_info != (ImageInfo *) NULL);
8496 assert(image_info->signature == MagickSignature);
8497 if (images == (Image **) NULL)
8498 return(MogrifyImage(image_info,argc,argv,images,exception));
8499 assert((*images)->signature == MagickSignature);
8500 if ((*images)->debug != MagickFalse)
8501 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
8502 (*images)->filename);
8503 if ((argc <= 0) || (*argv == (char *) NULL))
8504 return(MagickTrue);
8505 (void) SetImageInfoProgressMonitor(image_info,(MagickProgressMonitor) NULL,
8506 (void *) NULL);
8507 mogrify_images=NewImageList();
8508 number_images=GetImageListLength(*images);
8509 status=0;
8510 if (post == MagickFalse)
8511 status&=MogrifyImageList(image_info,argc,argv,images,exception);
cristybb503372010-05-27 20:51:26 +00008512 for (i=0; i < (ssize_t) number_images; i++)
cristy3ed852e2009-09-05 21:47:34 +00008513 {
8514 image=RemoveFirstImageFromList(images);
8515 if (image == (Image *) NULL)
8516 continue;
8517 status&=MogrifyImage(image_info,argc,argv,&image,exception);
8518 AppendImageToList(&mogrify_images,image);
cristy0e9f9c12010-02-11 03:00:47 +00008519 proceed=SetImageProgress(image,MogrifyImageTag,(MagickOffsetType) i,
8520 number_images);
8521 if (proceed == MagickFalse)
8522 break;
cristy3ed852e2009-09-05 21:47:34 +00008523 }
8524 if (post != MagickFalse)
8525 status&=MogrifyImageList(image_info,argc,argv,&mogrify_images,exception);
8526 *images=mogrify_images;
8527 return(status != 0 ? MagickTrue : MagickFalse);
8528}