blob: f4fc073614bea88e82056379ce12e8fa9e98251d [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% %
cristy5063d812010-10-19 16:28:10 +000072% M a g i c k C o m m a n d G e n e s i s %
cristy3980b0d2009-10-25 14:37:13 +000073% %
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,
cristy5063d812010-10-19 16:28:10 +000084% MagickCommand command,int argc,char **argv,char **metadata,
85% ExceptionInfo *exception)
cristy3980b0d2009-10-25 14:37:13 +000086%
87% A description of each parameter follows:
88%
89% o image_info: the image info.
90%
cristy5063d812010-10-19 16:28:10 +000091% o command: Choose from ConvertImageCommand, IdentifyImageCommand,
92% MogrifyImageCommand, CompositeImageCommand, CompareImageCommand,
93% ConjureImageCommand, StreamImageCommand, ImportImageCommand,
94% DisplayImageCommand, or AnimateImageCommand.
cristy3980b0d2009-10-25 14:37:13 +000095%
96% o argc: Specifies a pointer to an integer describing the number of
97% elements in the argument vector.
98%
99% o argv: Specifies a pointer to a text array containing the command line
100% arguments.
101%
cristy5063d812010-10-19 16:28:10 +0000102% o metadata: any metadata is returned here.
cristy3980b0d2009-10-25 14:37:13 +0000103%
104% o exception: return any errors or warnings in this structure.
105%
106*/
107WandExport MagickBooleanType MagickCommandGenesis(ImageInfo *image_info,
108 MagickCommand command,int argc,char **argv,char **metadata,
109 ExceptionInfo *exception)
110{
111 char
112 *option;
113
114 double
115 duration,
116 elapsed_time,
117 user_time;
118
cristy3980b0d2009-10-25 14:37:13 +0000119 MagickBooleanType
120 concurrent,
121 regard_warnings,
122 status;
123
cristybb503372010-05-27 20:51:26 +0000124 register ssize_t
cristy3980b0d2009-10-25 14:37:13 +0000125 i;
126
127 TimerInfo
128 *timer;
129
cristybb503372010-05-27 20:51:26 +0000130 size_t
cristy3980b0d2009-10-25 14:37:13 +0000131 iterations;
132
cristyd0a94fa2010-03-12 14:18:11 +0000133 (void) setlocale(LC_ALL,"");
134 (void) setlocale(LC_NUMERIC,"C");
cristy3980b0d2009-10-25 14:37:13 +0000135 concurrent=MagickFalse;
136 duration=(-1.0);
137 iterations=1;
cristy33557d72009-11-06 00:54:33 +0000138 status=MagickFalse;
cristy3980b0d2009-10-25 14:37:13 +0000139 regard_warnings=MagickFalse;
cristybb503372010-05-27 20:51:26 +0000140 for (i=1; i < (ssize_t) (argc-1); i++)
cristy3980b0d2009-10-25 14:37:13 +0000141 {
142 option=argv[i];
143 if ((strlen(option) == 1) || ((*option != '-') && (*option != '+')))
144 continue;
145 if (LocaleCompare("bench",option+1) == 0)
cristye27293e2009-12-18 02:53:20 +0000146 iterations=StringToUnsignedLong(argv[++i]);
cristy3980b0d2009-10-25 14:37:13 +0000147 if (LocaleCompare("concurrent",option+1) == 0)
148 concurrent=MagickTrue;
149 if (LocaleCompare("debug",option+1) == 0)
150 (void) SetLogEventMask(argv[++i]);
151 if (LocaleCompare("duration",option+1) == 0)
cristyf2f27272009-12-17 14:48:46 +0000152 duration=StringToDouble(argv[++i]);
cristy3980b0d2009-10-25 14:37:13 +0000153 if (LocaleCompare("regard-warnings",option+1) == 0)
154 regard_warnings=MagickTrue;
155 }
156 timer=AcquireTimerInfo();
cristyceae09d2009-10-28 17:18:47 +0000157 if (concurrent == MagickFalse)
cristy3980b0d2009-10-25 14:37:13 +0000158 {
cristybb503372010-05-27 20:51:26 +0000159 for (i=0; i < (ssize_t) iterations; i++)
cristy3980b0d2009-10-25 14:37:13 +0000160 {
cristy33557d72009-11-06 00:54:33 +0000161 if (status != MagickFalse)
cristyceae09d2009-10-28 17:18:47 +0000162 continue;
163 if (duration > 0)
164 {
165 if (GetElapsedTime(timer) > duration)
166 continue;
167 (void) ContinueTimer(timer);
168 }
169 status=command(image_info,argc,argv,metadata,exception);
cristy3980b0d2009-10-25 14:37:13 +0000170 if (exception->severity != UndefinedException)
171 {
172 if ((exception->severity > ErrorException) ||
173 (regard_warnings != MagickFalse))
174 status=MagickTrue;
175 CatchException(exception);
176 }
cristy3d1a5512009-10-25 21:23:27 +0000177 if ((metadata != (char **) NULL) && (*metadata != (char *) NULL))
cristy3980b0d2009-10-25 14:37:13 +0000178 {
179 (void) fputs(*metadata,stdout);
180 (void) fputc('\n',stdout);
181 *metadata=DestroyString(*metadata);
182 }
183 }
184 }
cristyceae09d2009-10-28 17:18:47 +0000185 else
186 {
187 SetOpenMPNested(1);
cristyb5d5f722009-11-04 03:03:49 +0000188#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristyceae09d2009-10-28 17:18:47 +0000189 # pragma omp parallel for shared(status)
190#endif
cristybb503372010-05-27 20:51:26 +0000191 for (i=0; i < (ssize_t) iterations; i++)
cristyceae09d2009-10-28 17:18:47 +0000192 {
cristy33557d72009-11-06 00:54:33 +0000193 if (status != MagickFalse)
cristyceae09d2009-10-28 17:18:47 +0000194 continue;
195 if (duration > 0)
196 {
197 if (GetElapsedTime(timer) > duration)
198 continue;
199 (void) ContinueTimer(timer);
200 }
201 status=command(image_info,argc,argv,metadata,exception);
cristyb5d5f722009-11-04 03:03:49 +0000202#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy524549f2010-06-20 21:10:20 +0000203 # pragma omp critical (MagickCore_CommandGenesis)
cristyceae09d2009-10-28 17:18:47 +0000204#endif
205 {
206 if (exception->severity != UndefinedException)
207 {
208 if ((exception->severity > ErrorException) ||
209 (regard_warnings != MagickFalse))
210 status=MagickTrue;
211 CatchException(exception);
212 }
213 if ((metadata != (char **) NULL) && (*metadata != (char *) NULL))
214 {
215 (void) fputs(*metadata,stdout);
216 (void) fputc('\n',stdout);
217 *metadata=DestroyString(*metadata);
218 }
219 }
220 }
221 }
cristy3980b0d2009-10-25 14:37:13 +0000222 if (iterations > 1)
223 {
224 elapsed_time=GetElapsedTime(timer);
225 user_time=GetUserTime(timer);
cristy8cd5b312010-01-07 01:10:24 +0000226 (void) fprintf(stderr,
cristye8c25f92010-06-03 00:53:06 +0000227 "Performance: %.20gi %gips %0.3fu %.20g:%02g.%03g\n",(double)
228 iterations,1.0*iterations/elapsed_time,user_time,(double)
229 (elapsed_time/60.0),floor(fmod(elapsed_time,60.0)),(double)
230 (1000.0*(elapsed_time-floor(elapsed_time))));
cristy524549f2010-06-20 21:10:20 +0000231 (void) fflush(stderr);
cristy3980b0d2009-10-25 14:37:13 +0000232 }
233 timer=DestroyTimerInfo(timer);
cristy1f9e1ed2009-11-18 04:09:38 +0000234 return(status);
cristy3980b0d2009-10-25 14:37:13 +0000235}
236
237/*
238%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
239% %
240% %
241% %
cristy3ed852e2009-09-05 21:47:34 +0000242+ M o g r i f y I m a g e %
243% %
244% %
245% %
246%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
247%
248% MogrifyImage() applies image processing options to an image as prescribed
249% by command line options.
250%
251% The format of the MogrifyImage method is:
252%
253% MagickBooleanType MogrifyImage(ImageInfo *image_info,const int argc,
254% const char **argv,Image **image)
255%
256% A description of each parameter follows:
257%
258% o image_info: the image info..
259%
260% o argc: Specifies a pointer to an integer describing the number of
261% elements in the argument vector.
262%
263% o argv: Specifies a pointer to a text array containing the command line
264% arguments.
265%
266% o image: the image.
267%
268% o exception: return any errors or warnings in this structure.
269%
270*/
271
272static inline Image *GetImageCache(const ImageInfo *image_info,const char *path,
273 ExceptionInfo *exception)
274{
275 char
276 key[MaxTextExtent];
277
278 ExceptionInfo
279 *sans_exception;
280
281 Image
282 *image;
283
284 ImageInfo
285 *read_info;
286
287 (void) FormatMagickString(key,MaxTextExtent,"cache:%s",path);
288 sans_exception=AcquireExceptionInfo();
289 image=(Image *) GetImageRegistry(ImageRegistryType,key,sans_exception);
290 sans_exception=DestroyExceptionInfo(sans_exception);
291 if (image != (Image *) NULL)
292 return(image);
293 read_info=CloneImageInfo(image_info);
294 (void) CopyMagickString(read_info->filename,path,MaxTextExtent);
295 image=ReadImage(read_info,exception);
296 read_info=DestroyImageInfo(read_info);
297 if (image != (Image *) NULL)
298 (void) SetImageRegistry(ImageRegistryType,key,image,exception);
299 return(image);
300}
301
cristy3ed852e2009-09-05 21:47:34 +0000302static MagickBooleanType IsPathWritable(const char *path)
303{
304 if (IsPathAccessible(path) == MagickFalse)
305 return(MagickFalse);
306 if (access(path,W_OK) != 0)
307 return(MagickFalse);
308 return(MagickTrue);
309}
310
cristybb503372010-05-27 20:51:26 +0000311static inline ssize_t MagickMax(const ssize_t x,const ssize_t y)
cristy3ed852e2009-09-05 21:47:34 +0000312{
313 if (x > y)
314 return(x);
315 return(y);
316}
317
318static MagickBooleanType MonitorProgress(const char *text,
cristyb32b90a2009-09-07 21:45:48 +0000319 const MagickOffsetType offset,const MagickSizeType extent,
cristy3ed852e2009-09-05 21:47:34 +0000320 void *wand_unused(client_data))
321{
322 char
323 message[MaxTextExtent],
324 tag[MaxTextExtent];
325
326 const char
327 *locale_message;
328
329 register char
330 *p;
331
cristyb32b90a2009-09-07 21:45:48 +0000332 if (extent < 2)
cristy3ed852e2009-09-05 21:47:34 +0000333 return(MagickTrue);
334 (void) CopyMagickMemory(tag,text,MaxTextExtent);
335 p=strrchr(tag,'/');
336 if (p != (char *) NULL)
337 *p='\0';
338 (void) FormatMagickString(message,MaxTextExtent,"Monitor/%s",tag);
339 locale_message=GetLocaleMessage(message);
340 if (locale_message == message)
341 locale_message=tag;
342 if (p == (char *) NULL)
cristyb32b90a2009-09-07 21:45:48 +0000343 (void) fprintf(stderr,"%s: %ld of %lu, %02ld%% complete\r",locale_message,
cristyf2faecf2010-05-28 19:19:36 +0000344 (long) offset,(unsigned long) extent,(long) (100L*offset/(extent-1)));
cristy3ed852e2009-09-05 21:47:34 +0000345 else
cristyb32b90a2009-09-07 21:45:48 +0000346 (void) fprintf(stderr,"%s[%s]: %ld of %lu, %02ld%% complete\r",
cristyf2faecf2010-05-28 19:19:36 +0000347 locale_message,p+1,(long) offset,(unsigned long) extent,(long)
cristyb32b90a2009-09-07 21:45:48 +0000348 (100L*offset/(extent-1)));
349 if (offset == (MagickOffsetType) (extent-1))
cristy3ed852e2009-09-05 21:47:34 +0000350 (void) fprintf(stderr,"\n");
351 (void) fflush(stderr);
352 return(MagickTrue);
353}
354
355static Image *SparseColorOption(const Image *image,const ChannelType channel,
356 const SparseColorMethod method,const char *arguments,
357 const MagickBooleanType color_from_image,ExceptionInfo *exception)
358{
359 ChannelType
360 channels;
361
362 char
363 token[MaxTextExtent];
364
365 const char
366 *p;
367
368 double
369 *sparse_arguments;
370
cristybb503372010-05-27 20:51:26 +0000371 register size_t
cristy3ed852e2009-09-05 21:47:34 +0000372 x;
373
cristybb503372010-05-27 20:51:26 +0000374 size_t
cristy3ed852e2009-09-05 21:47:34 +0000375 number_arguments;
376
cristybb503372010-05-27 20:51:26 +0000377 size_t
cristy3ed852e2009-09-05 21:47:34 +0000378 number_colors;
379
380 Image
381 *sparse_image;
382
383 MagickPixelPacket
384 color;
385
386 MagickBooleanType
387 error;
388
389 assert(image != (Image *) NULL);
390 assert(image->signature == MagickSignature);
391 if (image->debug != MagickFalse)
392 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
393 assert(exception != (ExceptionInfo *) NULL);
394 assert(exception->signature == MagickSignature);
395 /*
396 Limit channels according to image - and add up number of color channel.
397 */
398 channels=channel;
399 if (image->colorspace != CMYKColorspace)
400 channels=(ChannelType) (channels & ~IndexChannel); /* no index channel */
401 if (image->matte == MagickFalse)
402 channels=(ChannelType) (channels & ~OpacityChannel); /* no alpha channel */
403 number_colors=0;
404 if ((channels & RedChannel) != 0)
405 number_colors++;
406 if ((channels & GreenChannel) != 0)
407 number_colors++;
408 if ((channels & BlueChannel) != 0)
409 number_colors++;
410 if ((channels & IndexChannel) != 0)
411 number_colors++;
412 if ((channels & OpacityChannel) != 0)
413 number_colors++;
414 /*
415 Read string, to determine number of arguments needed,
416 */
417 p=arguments;
418 x=0;
419 while( *p != '\0' )
420 {
421 GetMagickToken(p,&p,token);
422 if ( token[0] == ',' ) continue;
423 if ( isalpha((int) token[0]) || token[0] == '#' ) {
424 if ( color_from_image ) {
425 (void) ThrowMagickException(exception,GetMagickModule(),
426 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
427 "Color arg given, when colors are coming from image");
428 return( (Image *)NULL);
429 }
430 x += number_colors; /* color argument */
431 }
432 else {
433 x++; /* floating point argument */
434 }
435 }
436 error=MagickTrue;
437 if ( color_from_image ) {
438 /* just the control points are being given */
439 error = ( x % 2 != 0 ) ? MagickTrue : MagickFalse;
440 number_arguments=(x/2)*(2+number_colors);
441 }
442 else {
443 /* control points and color values */
444 error = ( x % (2+number_colors) != 0 ) ? MagickTrue : MagickFalse;
445 number_arguments=x;
446 }
447 if ( error ) {
448 (void) ThrowMagickException(exception,GetMagickModule(),
449 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
450 "Invalid number of Arguments");
451 return( (Image *)NULL);
452 }
453
454 /* Allocate and fill in the floating point arguments */
455 sparse_arguments=(double *) AcquireQuantumMemory(number_arguments,
456 sizeof(*sparse_arguments));
457 if (sparse_arguments == (double *) NULL) {
458 (void) ThrowMagickException(exception,GetMagickModule(),ResourceLimitError,
459 "MemoryAllocationFailed","%s","SparseColorOption");
460 return( (Image *)NULL);
461 }
462 (void) ResetMagickMemory(sparse_arguments,0,number_arguments*
463 sizeof(*sparse_arguments));
464 p=arguments;
465 x=0;
466 while( *p != '\0' && x < number_arguments ) {
467 /* X coordinate */
468 token[0]=','; while ( token[0] == ',' ) GetMagickToken(p,&p,token);
469 if ( token[0] == '\0' ) break;
470 if ( isalpha((int) token[0]) || token[0] == '#' ) {
471 (void) ThrowMagickException(exception,GetMagickModule(),
472 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
473 "Color found, instead of X-coord");
474 error = MagickTrue;
475 break;
476 }
cristyf2f27272009-12-17 14:48:46 +0000477 sparse_arguments[x++]=StringToDouble(token);
cristy3ed852e2009-09-05 21:47:34 +0000478 /* Y coordinate */
479 token[0]=','; while ( token[0] == ',' ) GetMagickToken(p,&p,token);
480 if ( token[0] == '\0' ) break;
481 if ( isalpha((int) token[0]) || token[0] == '#' ) {
482 (void) ThrowMagickException(exception,GetMagickModule(),
483 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
484 "Color found, instead of Y-coord");
485 error = MagickTrue;
486 break;
487 }
cristyf2f27272009-12-17 14:48:46 +0000488 sparse_arguments[x++]=StringToDouble(token);
cristy3ed852e2009-09-05 21:47:34 +0000489 /* color values for this control point */
490#if 0
491 if ( (color_from_image ) {
492 /* get color from image */
493 /* HOW??? */
494 }
495 else
496#endif
497 {
498 /* color name or function given in string argument */
499 token[0]=','; while ( token[0] == ',' ) GetMagickToken(p,&p,token);
500 if ( token[0] == '\0' ) break;
501 if ( isalpha((int) token[0]) || token[0] == '#' ) {
502 /* Color string given */
503 (void) QueryMagickColor(token,&color,exception);
504 if ( channels & RedChannel )
505 sparse_arguments[x++] = QuantumScale*color.red;
506 if ( channels & GreenChannel )
507 sparse_arguments[x++] = QuantumScale*color.green;
508 if ( channels & BlueChannel )
509 sparse_arguments[x++] = QuantumScale*color.blue;
510 if ( channels & IndexChannel )
511 sparse_arguments[x++] = QuantumScale*color.index;
512 if ( channels & OpacityChannel )
513 sparse_arguments[x++] = QuantumScale*color.opacity;
514 }
515 else {
516#if 0
517 /* the color name/function/value was not found - error */
518 break;
519#else
520 /* Colors given as a set of floating point values - experimental */
521 /* NB: token contains the first floating point value to use! */
522 if ( channels & RedChannel ) {
523 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
524 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
525 break;
cristy0f19e682009-12-17 14:55:51 +0000526 sparse_arguments[x++]=StringToDouble(token);
cristy3ed852e2009-09-05 21:47:34 +0000527 token[0] = ','; /* used this token - get another */
528 }
529 if ( channels & GreenChannel ) {
530 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
531 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
532 break;
cristy0f19e682009-12-17 14:55:51 +0000533 sparse_arguments[x++]=StringToDouble(token);
cristy3ed852e2009-09-05 21:47:34 +0000534 token[0] = ','; /* used this token - get another */
535 }
536 if ( channels & BlueChannel ) {
537 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
538 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
539 break;
cristy0f19e682009-12-17 14:55:51 +0000540 sparse_arguments[x++]=StringToDouble(token);
cristy3ed852e2009-09-05 21:47:34 +0000541 token[0] = ','; /* used this token - get another */
542 }
543 if ( channels & IndexChannel ) {
544 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
545 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
546 break;
cristy0f19e682009-12-17 14:55:51 +0000547 sparse_arguments[x++]=StringToDouble(token);
cristy3ed852e2009-09-05 21:47:34 +0000548 token[0] = ','; /* used this token - get another */
549 }
550 if ( channels & OpacityChannel ) {
551 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
552 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
553 break;
cristy0f19e682009-12-17 14:55:51 +0000554 sparse_arguments[x++]=StringToDouble(token);
cristy3ed852e2009-09-05 21:47:34 +0000555 token[0] = ','; /* used this token - get another */
556 }
557#endif
558 }
559 }
560 }
561 if ( number_arguments != x && !error ) {
562 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
563 "InvalidArgument","`%s': %s","sparse-color","Argument Parsing Error");
564 sparse_arguments=(double *) RelinquishMagickMemory(sparse_arguments);
565 return( (Image *)NULL);
566 }
567 if ( error )
568 return( (Image *)NULL);
569
570 /* Call the Interpolation function with the parsed arguments */
571 sparse_image=SparseColorImage(image,channels,method,number_arguments,
572 sparse_arguments,exception);
573 sparse_arguments=(double *) RelinquishMagickMemory(sparse_arguments);
574 return( sparse_image );
575}
576
577WandExport MagickBooleanType MogrifyImage(ImageInfo *image_info,const int argc,
578 const char **argv,Image **image,ExceptionInfo *exception)
579{
580 ChannelType
581 channel;
582
583 const char
584 *format,
585 *option;
586
587 DrawInfo
588 *draw_info;
589
590 GeometryInfo
591 geometry_info;
592
593 Image
594 *region_image;
595
cristy6b3da3a2010-06-20 02:21:46 +0000596 ImageInfo
597 *mogrify_info;
598
cristybb503372010-05-27 20:51:26 +0000599 ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000600 count;
601
602 MagickBooleanType
603 status;
604
605 MagickPixelPacket
606 fill;
607
608 MagickStatusType
609 flags;
610
611 QuantizeInfo
612 *quantize_info;
613
614 RectangleInfo
615 geometry,
616 region_geometry;
617
cristybb503372010-05-27 20:51:26 +0000618 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000619 i;
620
621 /*
622 Initialize method variables.
623 */
624 assert(image_info != (const ImageInfo *) NULL);
625 assert(image_info->signature == MagickSignature);
626 assert(image != (Image **) NULL);
627 assert((*image)->signature == MagickSignature);
628 if ((*image)->debug != MagickFalse)
629 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",(*image)->filename);
630 if (argc < 0)
631 return(MagickTrue);
cristy6b3da3a2010-06-20 02:21:46 +0000632 mogrify_info=CloneImageInfo(image_info);
633 draw_info=CloneDrawInfo(mogrify_info,(DrawInfo *) NULL);
634 quantize_info=AcquireQuantizeInfo(mogrify_info);
cristy3ed852e2009-09-05 21:47:34 +0000635 SetGeometryInfo(&geometry_info);
636 GetMagickPixelPacket(*image,&fill);
637 SetMagickPixelPacket(*image,&(*image)->background_color,(IndexPacket *) NULL,
638 &fill);
cristy6b3da3a2010-06-20 02:21:46 +0000639 channel=mogrify_info->channel;
640 format=GetImageOption(mogrify_info,"format");
cristy3ed852e2009-09-05 21:47:34 +0000641 SetGeometry(*image,&region_geometry);
642 region_image=NewImageList();
643 /*
644 Transmogrify the image.
645 */
cristybb503372010-05-27 20:51:26 +0000646 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +0000647 {
648 option=argv[i];
649 if (IsMagickOption(option) == MagickFalse)
650 continue;
651 count=MagickMax(ParseMagickOption(MagickCommandOptions,MagickFalse,option),
652 0L);
cristycee97112010-05-28 00:44:52 +0000653 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +0000654 break;
cristy6b3da3a2010-06-20 02:21:46 +0000655 status=MogrifyImageInfo(mogrify_info,(int) count+1,argv+i,exception);
cristy3ed852e2009-09-05 21:47:34 +0000656 switch (*(option+1))
657 {
658 case 'a':
659 {
660 if (LocaleCompare("adaptive-blur",option+1) == 0)
661 {
662 Image
663 *blur_image;
664
665 /*
666 Adaptive blur image.
667 */
cristy6b3da3a2010-06-20 02:21:46 +0000668 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000669 flags=ParseGeometry(argv[i+1],&geometry_info);
670 if ((flags & SigmaValue) == 0)
671 geometry_info.sigma=1.0;
672 blur_image=AdaptiveBlurImageChannel(*image,channel,
673 geometry_info.rho,geometry_info.sigma,exception);
674 if (blur_image == (Image *) NULL)
675 break;
676 *image=DestroyImage(*image);
677 *image=blur_image;
678 break;
679 }
680 if (LocaleCompare("adaptive-resize",option+1) == 0)
681 {
682 Image
683 *resize_image;
684
685 /*
686 Adaptive resize image.
687 */
cristy6b3da3a2010-06-20 02:21:46 +0000688 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000689 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
690 resize_image=AdaptiveResizeImage(*image,geometry.width,
691 geometry.height,exception);
692 if (resize_image == (Image *) NULL)
693 break;
694 *image=DestroyImage(*image);
695 *image=resize_image;
696 break;
697 }
698 if (LocaleCompare("adaptive-sharpen",option+1) == 0)
699 {
700 Image
701 *sharp_image;
702
703 /*
704 Adaptive sharpen image.
705 */
cristy6b3da3a2010-06-20 02:21:46 +0000706 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000707 flags=ParseGeometry(argv[i+1],&geometry_info);
708 if ((flags & SigmaValue) == 0)
709 geometry_info.sigma=1.0;
710 sharp_image=AdaptiveSharpenImageChannel(*image,channel,
711 geometry_info.rho,geometry_info.sigma,exception);
712 if (sharp_image == (Image *) NULL)
713 break;
714 *image=DestroyImage(*image);
715 *image=sharp_image;
716 break;
717 }
718 if (LocaleCompare("affine",option+1) == 0)
719 {
720 /*
721 Affine matrix.
722 */
723 if (*option == '+')
724 {
725 GetAffineMatrix(&draw_info->affine);
726 break;
727 }
728 (void) ParseAffineGeometry(argv[i+1],&draw_info->affine,exception);
729 break;
730 }
731 if (LocaleCompare("alpha",option+1) == 0)
732 {
733 AlphaChannelType
734 alpha_type;
735
cristy6b3da3a2010-06-20 02:21:46 +0000736 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000737 alpha_type=(AlphaChannelType) ParseMagickOption(MagickAlphaOptions,
738 MagickFalse,argv[i+1]);
739 (void) SetImageAlphaChannel(*image,alpha_type);
740 InheritException(exception,&(*image)->exception);
741 break;
742 }
743 if (LocaleCompare("annotate",option+1) == 0)
744 {
745 char
746 *text,
747 geometry[MaxTextExtent];
748
749 /*
750 Annotate image.
751 */
cristy6b3da3a2010-06-20 02:21:46 +0000752 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000753 SetGeometryInfo(&geometry_info);
754 flags=ParseGeometry(argv[i+1],&geometry_info);
755 if ((flags & SigmaValue) == 0)
756 geometry_info.sigma=geometry_info.rho;
cristy6b3da3a2010-06-20 02:21:46 +0000757 text=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
cristy3ed852e2009-09-05 21:47:34 +0000758 InheritException(exception,&(*image)->exception);
759 if (text == (char *) NULL)
760 break;
761 (void) CloneString(&draw_info->text,text);
762 text=DestroyString(text);
763 (void) FormatMagickString(geometry,MaxTextExtent,"%+f%+f",
764 geometry_info.xi,geometry_info.psi);
765 (void) CloneString(&draw_info->geometry,geometry);
766 draw_info->affine.sx=cos(DegreesToRadians(
767 fmod(geometry_info.rho,360.0)));
768 draw_info->affine.rx=sin(DegreesToRadians(
769 fmod(geometry_info.rho,360.0)));
770 draw_info->affine.ry=(-sin(DegreesToRadians(
771 fmod(geometry_info.sigma,360.0))));
772 draw_info->affine.sy=cos(DegreesToRadians(
773 fmod(geometry_info.sigma,360.0)));
774 (void) AnnotateImage(*image,draw_info);
775 InheritException(exception,&(*image)->exception);
776 break;
777 }
778 if (LocaleCompare("antialias",option+1) == 0)
779 {
780 draw_info->stroke_antialias=(*option == '-') ? MagickTrue :
781 MagickFalse;
782 draw_info->text_antialias=(*option == '-') ? MagickTrue :
783 MagickFalse;
784 break;
785 }
786 if (LocaleCompare("auto-gamma",option+1) == 0)
787 {
788 /*
789 Auto Adjust Gamma of image based on its mean
790 */
cristy6b3da3a2010-06-20 02:21:46 +0000791 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000792 (void) AutoGammaImageChannel(*image,channel);
793 break;
794 }
795 if (LocaleCompare("auto-level",option+1) == 0)
796 {
797 /*
798 Perfectly Normalize (max/min stretch) the image
799 */
cristy6b3da3a2010-06-20 02:21:46 +0000800 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000801 (void) AutoLevelImageChannel(*image,channel);
802 break;
803 }
804 if (LocaleCompare("auto-orient",option+1) == 0)
805 {
806 Image
807 *orient_image;
808
cristy6b3da3a2010-06-20 02:21:46 +0000809 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000810 orient_image=NewImageList();
811 switch ((*image)->orientation)
812 {
813 case TopRightOrientation:
814 {
815 orient_image=FlopImage(*image,exception);
816 break;
817 }
818 case BottomRightOrientation:
819 {
820 orient_image=RotateImage(*image,180.0,exception);
821 break;
822 }
823 case BottomLeftOrientation:
824 {
825 orient_image=FlipImage(*image,exception);
826 break;
827 }
828 case LeftTopOrientation:
829 {
830 orient_image=TransposeImage(*image,exception);
831 break;
832 }
833 case RightTopOrientation:
834 {
835 orient_image=RotateImage(*image,90.0,exception);
836 break;
837 }
838 case RightBottomOrientation:
839 {
840 orient_image=TransverseImage(*image,exception);
841 break;
842 }
843 case LeftBottomOrientation:
844 {
845 orient_image=RotateImage(*image,270.0,exception);
846 break;
847 }
848 default:
849 break;
850 }
851 if (orient_image == (Image *) NULL)
852 break;
853 orient_image->orientation=TopLeftOrientation;
854 *image=DestroyImage(*image);
855 *image=orient_image;
856 break;
857 }
858 break;
859 }
860 case 'b':
861 {
862 if (LocaleCompare("black-threshold",option+1) == 0)
863 {
864 /*
865 Black threshold image.
866 */
cristy6b3da3a2010-06-20 02:21:46 +0000867 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000868 (void) BlackThresholdImageChannel(*image,channel,argv[i+1],
869 exception);
870 InheritException(exception,&(*image)->exception);
871 break;
872 }
873 if (LocaleCompare("blue-shift",option+1) == 0)
874 {
875 Image
876 *shift_image;
877
878 /*
879 Blue shift image.
880 */
cristy6b3da3a2010-06-20 02:21:46 +0000881 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000882 geometry_info.rho=1.5;
883 if (*option == '-')
884 flags=ParseGeometry(argv[i+1],&geometry_info);
885 shift_image=BlueShiftImage(*image,geometry_info.rho,exception);
886 if (shift_image == (Image *) NULL)
887 break;
888 *image=DestroyImage(*image);
889 *image=shift_image;
890 break;
891 }
892 if (LocaleCompare("blur",option+1) == 0)
893 {
894 Image
895 *blur_image;
896
897 /*
898 Gaussian blur image.
899 */
cristy6b3da3a2010-06-20 02:21:46 +0000900 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000901 flags=ParseGeometry(argv[i+1],&geometry_info);
902 if ((flags & SigmaValue) == 0)
903 geometry_info.sigma=1.0;
904 blur_image=BlurImageChannel(*image,channel,geometry_info.rho,
905 geometry_info.sigma,exception);
906 if (blur_image == (Image *) NULL)
907 break;
908 *image=DestroyImage(*image);
909 *image=blur_image;
910 break;
911 }
912 if (LocaleCompare("border",option+1) == 0)
913 {
914 Image
915 *border_image;
916
917 /*
918 Surround image with a border of solid color.
919 */
cristy6b3da3a2010-06-20 02:21:46 +0000920 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000921 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
922 if ((flags & SigmaValue) == 0)
923 geometry.height=geometry.width;
924 border_image=BorderImage(*image,&geometry,exception);
925 if (border_image == (Image *) NULL)
926 break;
927 *image=DestroyImage(*image);
928 *image=border_image;
929 break;
930 }
931 if (LocaleCompare("bordercolor",option+1) == 0)
932 {
933 if (*option == '+')
934 {
935 (void) QueryColorDatabase(BorderColor,&draw_info->border_color,
936 exception);
937 break;
938 }
939 (void) QueryColorDatabase(argv[i+1],&draw_info->border_color,
940 exception);
941 break;
942 }
943 if (LocaleCompare("box",option+1) == 0)
944 {
945 (void) QueryColorDatabase(argv[i+1],&draw_info->undercolor,
946 exception);
947 break;
948 }
cristya28d6b82010-01-11 20:03:47 +0000949 if (LocaleCompare("brightness-contrast",option+1) == 0)
950 {
951 double
952 brightness,
953 contrast;
954
955 GeometryInfo
956 geometry_info;
957
958 MagickStatusType
959 flags;
960
961 /*
962 Brightness / contrast image.
963 */
cristy6b3da3a2010-06-20 02:21:46 +0000964 (void) SyncImageSettings(mogrify_info,*image);
cristya28d6b82010-01-11 20:03:47 +0000965 flags=ParseGeometry(argv[i+1],&geometry_info);
966 brightness=geometry_info.rho;
cristy81fbc8b2010-01-11 20:04:07 +0000967 contrast=0.0;
cristya28d6b82010-01-11 20:03:47 +0000968 if ((flags & SigmaValue) != 0)
969 contrast=geometry_info.sigma;
cristy02cc0f22010-01-12 00:02:32 +0000970 (void) BrightnessContrastImageChannel(*image,channel,brightness,
971 contrast);
cristya28d6b82010-01-11 20:03:47 +0000972 InheritException(exception,&(*image)->exception);
973 break;
974 }
cristy3ed852e2009-09-05 21:47:34 +0000975 break;
976 }
977 case 'c':
978 {
979 if (LocaleCompare("cdl",option+1) == 0)
980 {
981 char
982 *color_correction_collection;
983
984 /*
985 Color correct with a color decision list.
986 */
cristy6b3da3a2010-06-20 02:21:46 +0000987 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000988 color_correction_collection=FileToString(argv[i+1],~0,exception);
989 if (color_correction_collection == (char *) NULL)
990 break;
991 (void) ColorDecisionListImage(*image,color_correction_collection);
992 InheritException(exception,&(*image)->exception);
993 break;
994 }
995 if (LocaleCompare("channel",option+1) == 0)
996 {
997 if (*option == '+')
998 {
999 channel=DefaultChannels;
1000 break;
1001 }
1002 channel=(ChannelType) ParseChannelOption(argv[i+1]);
1003 break;
1004 }
1005 if (LocaleCompare("charcoal",option+1) == 0)
1006 {
1007 Image
1008 *charcoal_image;
1009
1010 /*
1011 Charcoal image.
1012 */
cristy6b3da3a2010-06-20 02:21:46 +00001013 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001014 flags=ParseGeometry(argv[i+1],&geometry_info);
1015 if ((flags & SigmaValue) == 0)
1016 geometry_info.sigma=1.0;
1017 charcoal_image=CharcoalImage(*image,geometry_info.rho,
1018 geometry_info.sigma,exception);
1019 if (charcoal_image == (Image *) NULL)
1020 break;
1021 *image=DestroyImage(*image);
1022 *image=charcoal_image;
1023 break;
1024 }
1025 if (LocaleCompare("chop",option+1) == 0)
1026 {
1027 Image
1028 *chop_image;
1029
1030 /*
1031 Chop the image.
1032 */
cristy6b3da3a2010-06-20 02:21:46 +00001033 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001034 (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1035 chop_image=ChopImage(*image,&geometry,exception);
1036 if (chop_image == (Image *) NULL)
1037 break;
1038 *image=DestroyImage(*image);
1039 *image=chop_image;
1040 break;
1041 }
cristy1eb45dd2009-09-25 16:38:06 +00001042 if (LocaleCompare("clamp",option+1) == 0)
1043 {
1044 /*
1045 Clamp image.
1046 */
cristy6b3da3a2010-06-20 02:21:46 +00001047 (void) SyncImageSettings(mogrify_info,*image);
cristy1eb45dd2009-09-25 16:38:06 +00001048 (void) ClampImageChannel(*image,channel);
1049 InheritException(exception,&(*image)->exception);
1050 break;
1051 }
cristy3ed852e2009-09-05 21:47:34 +00001052 if (LocaleCompare("clip",option+1) == 0)
1053 {
cristy6b3da3a2010-06-20 02:21:46 +00001054 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001055 if (*option == '+')
1056 {
1057 (void) SetImageClipMask(*image,(Image *) NULL);
1058 InheritException(exception,&(*image)->exception);
1059 break;
1060 }
1061 (void) ClipImage(*image);
1062 InheritException(exception,&(*image)->exception);
1063 break;
1064 }
1065 if (LocaleCompare("clip-mask",option+1) == 0)
1066 {
cristyb0d3bb92010-09-22 14:37:58 +00001067 CacheView
1068 *mask_view;
cristya01cbea2010-11-03 16:33:33 +00001069
cristy3ed852e2009-09-05 21:47:34 +00001070 Image
cristyb0d3bb92010-09-22 14:37:58 +00001071 *mask_image;
cristy3ed852e2009-09-05 21:47:34 +00001072
cristybb503372010-05-27 20:51:26 +00001073 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001074 y;
1075
cristybb503372010-05-27 20:51:26 +00001076 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001077 x;
1078
1079 register PixelPacket
cristyc47d1f82009-11-26 01:44:43 +00001080 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00001081
cristy6b3da3a2010-06-20 02:21:46 +00001082 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001083 if (*option == '+')
1084 {
1085 /*
1086 Remove a mask.
1087 */
1088 (void) SetImageMask(*image,(Image *) NULL);
1089 InheritException(exception,&(*image)->exception);
1090 break;
1091 }
1092 /*
1093 Set the image mask.
1094 */
cristyb0d3bb92010-09-22 14:37:58 +00001095 mask_image=GetImageCache(mogrify_info,argv[i+1],exception);
1096 if (mask_image == (Image *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001097 break;
cristyb0d3bb92010-09-22 14:37:58 +00001098 if (SetImageStorageClass(mask_image,DirectClass) == MagickFalse)
1099 return(MagickFalse);
1100 mask_view=AcquireCacheView(mask_image);
1101 for (y=0; y < (ssize_t) mask_image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00001102 {
cristyb0d3bb92010-09-22 14:37:58 +00001103 q=GetCacheViewAuthenticPixels(mask_view,0,y,mask_image->columns,1,
1104 exception);
cristy3ed852e2009-09-05 21:47:34 +00001105 if (q == (PixelPacket *) NULL)
1106 break;
cristyb0d3bb92010-09-22 14:37:58 +00001107 for (x=0; x < (ssize_t) mask_image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00001108 {
cristyb0d3bb92010-09-22 14:37:58 +00001109 if (mask_image->matte == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00001110 q->opacity=PixelIntensityToQuantum(q);
1111 q->red=q->opacity;
1112 q->green=q->opacity;
1113 q->blue=q->opacity;
1114 q++;
1115 }
cristyb0d3bb92010-09-22 14:37:58 +00001116 if (SyncCacheViewAuthenticPixels(mask_view,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00001117 break;
1118 }
cristyb0d3bb92010-09-22 14:37:58 +00001119 mask_view=DestroyCacheView(mask_view);
1120 mask_image->matte=MagickTrue;
1121 (void) SetImageClipMask(*image,mask_image);
1122 mask_image=DestroyImage(mask_image);
cristy3ed852e2009-09-05 21:47:34 +00001123 InheritException(exception,&(*image)->exception);
1124 break;
1125 }
1126 if (LocaleCompare("clip-path",option+1) == 0)
1127 {
cristy6b3da3a2010-06-20 02:21:46 +00001128 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001129 (void) ClipImagePath(*image,argv[i+1],*option == '-' ? MagickTrue :
1130 MagickFalse);
1131 InheritException(exception,&(*image)->exception);
1132 break;
1133 }
1134 if (LocaleCompare("colorize",option+1) == 0)
1135 {
1136 Image
1137 *colorize_image;
1138
1139 /*
1140 Colorize the image.
1141 */
cristy6b3da3a2010-06-20 02:21:46 +00001142 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001143 colorize_image=ColorizeImage(*image,argv[i+1],draw_info->fill,
1144 exception);
1145 if (colorize_image == (Image *) NULL)
1146 break;
1147 *image=DestroyImage(*image);
1148 *image=colorize_image;
1149 break;
1150 }
cristye6365592010-04-02 17:31:23 +00001151 if (LocaleCompare("color-matrix",option+1) == 0)
1152 {
1153 Image
1154 *color_image;
1155
1156 KernelInfo
1157 *kernel;
1158
cristy6b3da3a2010-06-20 02:21:46 +00001159 (void) SyncImageSettings(mogrify_info,*image);
cristye6365592010-04-02 17:31:23 +00001160 kernel=AcquireKernelInfo(argv[i+1]);
1161 if (kernel == (KernelInfo *) NULL)
1162 break;
1163 color_image=ColorMatrixImage(*image,kernel,exception);
1164 kernel=DestroyKernelInfo(kernel);
1165 if (color_image == (Image *) NULL)
1166 break;
1167 *image=DestroyImage(*image);
1168 *image=color_image;
1169 break;
1170 }
cristy3ed852e2009-09-05 21:47:34 +00001171 if (LocaleCompare("colors",option+1) == 0)
1172 {
1173 /*
1174 Reduce the number of colors in the image.
1175 */
cristy6b3da3a2010-06-20 02:21:46 +00001176 (void) SyncImageSettings(mogrify_info,*image);
cristye27293e2009-12-18 02:53:20 +00001177 quantize_info->number_colors=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00001178 if (quantize_info->number_colors == 0)
1179 break;
1180 if (((*image)->storage_class == DirectClass) ||
1181 (*image)->colors > quantize_info->number_colors)
1182 (void) QuantizeImage(quantize_info,*image);
1183 else
1184 (void) CompressImageColormap(*image);
1185 InheritException(exception,&(*image)->exception);
1186 break;
1187 }
1188 if (LocaleCompare("colorspace",option+1) == 0)
1189 {
1190 ColorspaceType
1191 colorspace;
1192
cristy6b3da3a2010-06-20 02:21:46 +00001193 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001194 if (*option == '+')
1195 {
1196 (void) TransformImageColorspace(*image,RGBColorspace);
1197 InheritException(exception,&(*image)->exception);
1198 break;
1199 }
1200 colorspace=(ColorspaceType) ParseMagickOption(
1201 MagickColorspaceOptions,MagickFalse,argv[i+1]);
1202 (void) TransformImageColorspace(*image,colorspace);
1203 InheritException(exception,&(*image)->exception);
1204 break;
1205 }
1206 if (LocaleCompare("contrast",option+1) == 0)
1207 {
cristy6b3da3a2010-06-20 02:21:46 +00001208 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001209 (void) ContrastImage(*image,(*option == '-') ? MagickTrue :
1210 MagickFalse);
1211 InheritException(exception,&(*image)->exception);
1212 break;
1213 }
1214 if (LocaleCompare("contrast-stretch",option+1) == 0)
1215 {
1216 double
1217 black_point,
1218 white_point;
1219
cristy3ed852e2009-09-05 21:47:34 +00001220 MagickStatusType
1221 flags;
1222
1223 /*
1224 Contrast stretch image.
1225 */
cristy6b3da3a2010-06-20 02:21:46 +00001226 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001227 flags=ParseGeometry(argv[i+1],&geometry_info);
1228 black_point=geometry_info.rho;
1229 white_point=(flags & SigmaValue) != 0 ? geometry_info.sigma :
1230 black_point;
1231 if ((flags & PercentValue) != 0)
1232 {
1233 black_point*=(double) (*image)->columns*(*image)->rows/100.0;
1234 white_point*=(double) (*image)->columns*(*image)->rows/100.0;
1235 }
1236 white_point=(MagickRealType) (*image)->columns*(*image)->rows-
1237 white_point;
1238 (void) ContrastStretchImageChannel(*image,channel,black_point,
1239 white_point);
1240 InheritException(exception,&(*image)->exception);
1241 break;
1242 }
1243 if (LocaleCompare("convolve",option+1) == 0)
1244 {
cristy36826ab2010-03-06 01:29:30 +00001245 double
1246 gamma;
1247
cristy3ed852e2009-09-05 21:47:34 +00001248 Image
1249 *convolve_image;
1250
cristy2be15382010-01-21 02:38:03 +00001251 KernelInfo
cristy56a9e512010-01-06 18:18:55 +00001252 *kernel;
cristy3ed852e2009-09-05 21:47:34 +00001253
cristybb503372010-05-27 20:51:26 +00001254 register ssize_t
cristy36826ab2010-03-06 01:29:30 +00001255 j;
1256
cristy6b3da3a2010-06-20 02:21:46 +00001257 (void) SyncImageSettings(mogrify_info,*image);
cristy2be15382010-01-21 02:38:03 +00001258 kernel=AcquireKernelInfo(argv[i+1]);
1259 if (kernel == (KernelInfo *) NULL)
cristy56a9e512010-01-06 18:18:55 +00001260 break;
cristy36826ab2010-03-06 01:29:30 +00001261 gamma=0.0;
cristybb503372010-05-27 20:51:26 +00001262 for (j=0; j < (ssize_t) (kernel->width*kernel->height); j++)
cristy36826ab2010-03-06 01:29:30 +00001263 gamma+=kernel->values[j];
1264 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
cristybb503372010-05-27 20:51:26 +00001265 for (j=0; j < (ssize_t) (kernel->width*kernel->height); j++)
cristy36826ab2010-03-06 01:29:30 +00001266 kernel->values[j]*=gamma;
cristy6771f1e2010-03-05 19:43:39 +00001267 convolve_image=FilterImageChannel(*image,channel,kernel,exception);
anthony83ba99b2010-01-24 08:48:15 +00001268 kernel=DestroyKernelInfo(kernel);
cristy3ed852e2009-09-05 21:47:34 +00001269 if (convolve_image == (Image *) NULL)
1270 break;
1271 *image=DestroyImage(*image);
1272 *image=convolve_image;
1273 break;
1274 }
1275 if (LocaleCompare("crop",option+1) == 0)
1276 {
cristy6b3da3a2010-06-20 02:21:46 +00001277 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001278 flags=ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1279 if (((geometry.width != 0) || (geometry.height != 0)) &&
1280 ((flags & XValue) == 0) && ((flags & YValue) == 0))
1281 break;
1282 (void) TransformImage(image,argv[i+1],(char *) NULL);
1283 InheritException(exception,&(*image)->exception);
1284 break;
1285 }
1286 if (LocaleCompare("cycle",option+1) == 0)
1287 {
1288 /*
1289 Cycle an image colormap.
1290 */
cristy6b3da3a2010-06-20 02:21:46 +00001291 (void) SyncImageSettings(mogrify_info,*image);
cristy32c2aea2010-12-01 01:00:50 +00001292 (void) CycleColormapImage(*image,(ssize_t) StringToLong(argv[i+1]));
cristy3ed852e2009-09-05 21:47:34 +00001293 InheritException(exception,&(*image)->exception);
1294 break;
1295 }
1296 break;
1297 }
1298 case 'd':
1299 {
1300 if (LocaleCompare("decipher",option+1) == 0)
1301 {
1302 StringInfo
1303 *passkey;
1304
1305 /*
1306 Decipher pixels.
1307 */
cristy6b3da3a2010-06-20 02:21:46 +00001308 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001309 passkey=FileToStringInfo(argv[i+1],~0,exception);
1310 if (passkey != (StringInfo *) NULL)
1311 {
1312 (void) PasskeyDecipherImage(*image,passkey,exception);
1313 passkey=DestroyStringInfo(passkey);
1314 }
1315 break;
1316 }
1317 if (LocaleCompare("density",option+1) == 0)
1318 {
1319 /*
1320 Set image density.
1321 */
1322 (void) CloneString(&draw_info->density,argv[i+1]);
1323 break;
1324 }
1325 if (LocaleCompare("depth",option+1) == 0)
1326 {
cristy6b3da3a2010-06-20 02:21:46 +00001327 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001328 if (*option == '+')
1329 {
1330 (void) SetImageDepth(*image,MAGICKCORE_QUANTUM_DEPTH);
1331 break;
1332 }
cristye27293e2009-12-18 02:53:20 +00001333 (void) SetImageDepth(*image,StringToUnsignedLong(argv[i+1]));
cristy3ed852e2009-09-05 21:47:34 +00001334 break;
1335 }
1336 if (LocaleCompare("deskew",option+1) == 0)
1337 {
1338 double
1339 threshold;
1340
1341 Image
1342 *deskew_image;
1343
1344 /*
1345 Straighten the image.
1346 */
cristy6b3da3a2010-06-20 02:21:46 +00001347 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001348 if (*option == '+')
1349 threshold=40.0*QuantumRange/100.0;
1350 else
cristyf2f27272009-12-17 14:48:46 +00001351 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
cristy3ed852e2009-09-05 21:47:34 +00001352 deskew_image=DeskewImage(*image,threshold,exception);
1353 if (deskew_image == (Image *) NULL)
1354 break;
1355 *image=DestroyImage(*image);
1356 *image=deskew_image;
1357 break;
1358 }
1359 if (LocaleCompare("despeckle",option+1) == 0)
1360 {
1361 Image
1362 *despeckle_image;
1363
1364 /*
1365 Reduce the speckles within an image.
1366 */
cristy6b3da3a2010-06-20 02:21:46 +00001367 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001368 despeckle_image=DespeckleImage(*image,exception);
1369 if (despeckle_image == (Image *) NULL)
1370 break;
1371 *image=DestroyImage(*image);
1372 *image=despeckle_image;
1373 break;
1374 }
1375 if (LocaleCompare("display",option+1) == 0)
1376 {
1377 (void) CloneString(&draw_info->server_name,argv[i+1]);
1378 break;
1379 }
cristy3ed852e2009-09-05 21:47:34 +00001380 if (LocaleCompare("distort",option+1) == 0)
1381 {
1382 char
1383 *args,
1384 token[MaxTextExtent];
1385
1386 const char
1387 *p;
1388
1389 DistortImageMethod
1390 method;
1391
1392 double
1393 *arguments;
1394
1395 Image
1396 *distort_image;
1397
cristybb503372010-05-27 20:51:26 +00001398 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001399 x;
1400
cristybb503372010-05-27 20:51:26 +00001401 size_t
cristy3ed852e2009-09-05 21:47:34 +00001402 number_arguments;
1403
1404 /*
1405 Distort image.
1406 */
cristy6b3da3a2010-06-20 02:21:46 +00001407 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001408 method=(DistortImageMethod) ParseMagickOption(MagickDistortOptions,
1409 MagickFalse,argv[i+1]);
cristy6b3da3a2010-06-20 02:21:46 +00001410 args=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
cristy3ed852e2009-09-05 21:47:34 +00001411 InheritException(exception,&(*image)->exception);
1412 if (args == (char *) NULL)
1413 break;
1414 p=(char *) args;
1415 for (x=0; *p != '\0'; x++)
1416 {
1417 GetMagickToken(p,&p,token);
1418 if (*token == ',')
1419 GetMagickToken(p,&p,token);
1420 }
cristybb503372010-05-27 20:51:26 +00001421 number_arguments=(size_t) x;
cristy3ed852e2009-09-05 21:47:34 +00001422 arguments=(double *) AcquireQuantumMemory(number_arguments,
1423 sizeof(*arguments));
1424 if (arguments == (double *) NULL)
1425 ThrowWandFatalException(ResourceLimitFatalError,
1426 "MemoryAllocationFailed",(*image)->filename);
1427 (void) ResetMagickMemory(arguments,0,number_arguments*
1428 sizeof(*arguments));
1429 p=(char *) args;
cristybb503372010-05-27 20:51:26 +00001430 for (x=0; (x < (ssize_t) number_arguments) && (*p != '\0'); x++)
cristy3ed852e2009-09-05 21:47:34 +00001431 {
1432 GetMagickToken(p,&p,token);
1433 if (*token == ',')
1434 GetMagickToken(p,&p,token);
cristyf2f27272009-12-17 14:48:46 +00001435 arguments[x]=StringToDouble(token);
cristy3ed852e2009-09-05 21:47:34 +00001436 }
1437 args=DestroyString(args);
1438 distort_image=DistortImage(*image,method,number_arguments,arguments,
1439 (*option == '+') ? MagickTrue : MagickFalse,exception);
1440 arguments=(double *) RelinquishMagickMemory(arguments);
1441 if (distort_image == (Image *) NULL)
1442 break;
1443 *image=DestroyImage(*image);
1444 *image=distort_image;
1445 break;
1446 }
1447 if (LocaleCompare("dither",option+1) == 0)
1448 {
1449 if (*option == '+')
1450 {
1451 quantize_info->dither=MagickFalse;
1452 break;
1453 }
1454 quantize_info->dither=MagickTrue;
1455 quantize_info->dither_method=(DitherMethod) ParseMagickOption(
1456 MagickDitherOptions,MagickFalse,argv[i+1]);
1457 if (quantize_info->dither_method == NoDitherMethod)
1458 quantize_info->dither=MagickFalse;
1459 break;
1460 }
1461 if (LocaleCompare("draw",option+1) == 0)
1462 {
1463 /*
1464 Draw image.
1465 */
cristy6b3da3a2010-06-20 02:21:46 +00001466 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001467 (void) CloneString(&draw_info->primitive,argv[i+1]);
1468 (void) DrawImage(*image,draw_info);
1469 InheritException(exception,&(*image)->exception);
1470 break;
1471 }
1472 break;
1473 }
1474 case 'e':
1475 {
1476 if (LocaleCompare("edge",option+1) == 0)
1477 {
1478 Image
1479 *edge_image;
1480
1481 /*
1482 Enhance edges in the image.
1483 */
cristy6b3da3a2010-06-20 02:21:46 +00001484 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001485 flags=ParseGeometry(argv[i+1],&geometry_info);
1486 if ((flags & SigmaValue) == 0)
1487 geometry_info.sigma=1.0;
1488 edge_image=EdgeImage(*image,geometry_info.rho,exception);
1489 if (edge_image == (Image *) NULL)
1490 break;
1491 *image=DestroyImage(*image);
1492 *image=edge_image;
1493 break;
1494 }
1495 if (LocaleCompare("emboss",option+1) == 0)
1496 {
1497 Image
1498 *emboss_image;
1499
1500 /*
1501 Gaussian embossen image.
1502 */
cristy6b3da3a2010-06-20 02:21:46 +00001503 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001504 flags=ParseGeometry(argv[i+1],&geometry_info);
1505 if ((flags & SigmaValue) == 0)
1506 geometry_info.sigma=1.0;
1507 emboss_image=EmbossImage(*image,geometry_info.rho,
1508 geometry_info.sigma,exception);
1509 if (emboss_image == (Image *) NULL)
1510 break;
1511 *image=DestroyImage(*image);
1512 *image=emboss_image;
1513 break;
1514 }
1515 if (LocaleCompare("encipher",option+1) == 0)
1516 {
1517 StringInfo
1518 *passkey;
1519
1520 /*
1521 Encipher pixels.
1522 */
cristy6b3da3a2010-06-20 02:21:46 +00001523 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001524 passkey=FileToStringInfo(argv[i+1],~0,exception);
1525 if (passkey != (StringInfo *) NULL)
1526 {
1527 (void) PasskeyEncipherImage(*image,passkey,exception);
1528 passkey=DestroyStringInfo(passkey);
1529 }
1530 break;
1531 }
1532 if (LocaleCompare("encoding",option+1) == 0)
1533 {
1534 (void) CloneString(&draw_info->encoding,argv[i+1]);
1535 break;
1536 }
1537 if (LocaleCompare("enhance",option+1) == 0)
1538 {
1539 Image
1540 *enhance_image;
1541
1542 /*
1543 Enhance image.
1544 */
cristy6b3da3a2010-06-20 02:21:46 +00001545 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001546 enhance_image=EnhanceImage(*image,exception);
1547 if (enhance_image == (Image *) NULL)
1548 break;
1549 *image=DestroyImage(*image);
1550 *image=enhance_image;
1551 break;
1552 }
1553 if (LocaleCompare("equalize",option+1) == 0)
1554 {
1555 /*
1556 Equalize image.
1557 */
cristy6b3da3a2010-06-20 02:21:46 +00001558 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001559 (void) EqualizeImageChannel(*image,channel);
1560 InheritException(exception,&(*image)->exception);
1561 break;
1562 }
1563 if (LocaleCompare("evaluate",option+1) == 0)
1564 {
1565 double
1566 constant;
1567
1568 MagickEvaluateOperator
1569 op;
1570
cristy6b3da3a2010-06-20 02:21:46 +00001571 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001572 op=(MagickEvaluateOperator) ParseMagickOption(MagickEvaluateOptions,
1573 MagickFalse,argv[i+1]);
cristyf2f27272009-12-17 14:48:46 +00001574 constant=SiPrefixToDouble(argv[i+2],QuantumRange);
cristy3ed852e2009-09-05 21:47:34 +00001575 (void) EvaluateImageChannel(*image,channel,op,constant,exception);
1576 break;
1577 }
1578 if (LocaleCompare("extent",option+1) == 0)
1579 {
1580 Image
1581 *extent_image;
1582
1583 /*
1584 Set the image extent.
1585 */
cristy6b3da3a2010-06-20 02:21:46 +00001586 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001587 flags=ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
cristyf0bbfd92009-11-25 14:12:31 +00001588 if (geometry.width == 0)
cristy2ea9a4e2009-11-25 14:30:22 +00001589 geometry.width=(*image)->columns;
cristyf0bbfd92009-11-25 14:12:31 +00001590 if (geometry.height == 0)
cristy2ea9a4e2009-11-25 14:30:22 +00001591 geometry.height=(*image)->rows;
cristy3ed852e2009-09-05 21:47:34 +00001592 extent_image=ExtentImage(*image,&geometry,exception);
1593 if (extent_image == (Image *) NULL)
1594 break;
1595 *image=DestroyImage(*image);
1596 *image=extent_image;
1597 break;
1598 }
1599 break;
1600 }
1601 case 'f':
1602 {
1603 if (LocaleCompare("family",option+1) == 0)
1604 {
1605 if (*option == '+')
1606 {
1607 if (draw_info->family != (char *) NULL)
1608 draw_info->family=DestroyString(draw_info->family);
1609 break;
1610 }
1611 (void) CloneString(&draw_info->family,argv[i+1]);
1612 break;
1613 }
cristy0fe961c2010-01-30 03:09:54 +00001614 if (LocaleCompare("features",option+1) == 0)
1615 {
1616 if (*option == '+')
1617 {
1618 (void) DeleteImageArtifact(*image,"identify:features");
1619 break;
1620 }
1621 (void) SetImageArtifact(*image,"identify:features",argv[i+1]);
1622 break;
1623 }
cristy3ed852e2009-09-05 21:47:34 +00001624 if (LocaleCompare("fill",option+1) == 0)
1625 {
1626 ExceptionInfo
1627 *sans;
1628
1629 GetMagickPixelPacket(*image,&fill);
1630 if (*option == '+')
1631 {
1632 (void) QueryMagickColor("none",&fill,exception);
1633 (void) QueryColorDatabase("none",&draw_info->fill,exception);
1634 if (draw_info->fill_pattern != (Image *) NULL)
1635 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
1636 break;
1637 }
1638 sans=AcquireExceptionInfo();
1639 (void) QueryMagickColor(argv[i+1],&fill,sans);
1640 status=QueryColorDatabase(argv[i+1],&draw_info->fill,sans);
1641 sans=DestroyExceptionInfo(sans);
1642 if (status == MagickFalse)
cristy6b3da3a2010-06-20 02:21:46 +00001643 draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1],
cristy3ed852e2009-09-05 21:47:34 +00001644 exception);
1645 break;
1646 }
1647 if (LocaleCompare("flip",option+1) == 0)
1648 {
1649 Image
1650 *flip_image;
1651
1652 /*
1653 Flip image scanlines.
1654 */
cristy6b3da3a2010-06-20 02:21:46 +00001655 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001656 flip_image=FlipImage(*image,exception);
1657 if (flip_image == (Image *) NULL)
1658 break;
1659 *image=DestroyImage(*image);
1660 *image=flip_image;
1661 break;
1662 }
1663 if (LocaleCompare("flop",option+1) == 0)
1664 {
1665 Image
1666 *flop_image;
1667
1668 /*
1669 Flop image scanlines.
1670 */
cristy6b3da3a2010-06-20 02:21:46 +00001671 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001672 flop_image=FlopImage(*image,exception);
1673 if (flop_image == (Image *) NULL)
1674 break;
1675 *image=DestroyImage(*image);
1676 *image=flop_image;
1677 break;
1678 }
1679 if (LocaleCompare("floodfill",option+1) == 0)
1680 {
1681 MagickPixelPacket
1682 target;
1683
1684 /*
1685 Floodfill image.
1686 */
cristy6b3da3a2010-06-20 02:21:46 +00001687 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001688 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
1689 (void) QueryMagickColor(argv[i+2],&target,exception);
1690 (void) FloodfillPaintImage(*image,channel,draw_info,&target,
1691 geometry.x,geometry.y,*option == '-' ? MagickFalse : MagickTrue);
1692 InheritException(exception,&(*image)->exception);
1693 break;
1694 }
1695 if (LocaleCompare("font",option+1) == 0)
1696 {
1697 if (*option == '+')
1698 {
1699 if (draw_info->font != (char *) NULL)
1700 draw_info->font=DestroyString(draw_info->font);
1701 break;
1702 }
1703 (void) CloneString(&draw_info->font,argv[i+1]);
1704 break;
1705 }
1706 if (LocaleCompare("format",option+1) == 0)
1707 {
1708 format=argv[i+1];
1709 break;
1710 }
1711 if (LocaleCompare("frame",option+1) == 0)
1712 {
1713 FrameInfo
1714 frame_info;
1715
1716 Image
1717 *frame_image;
1718
1719 /*
1720 Surround image with an ornamental border.
1721 */
cristy6b3da3a2010-06-20 02:21:46 +00001722 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001723 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
1724 frame_info.width=geometry.width;
1725 frame_info.height=geometry.height;
1726 if ((flags & HeightValue) == 0)
1727 frame_info.height=geometry.width;
1728 frame_info.outer_bevel=geometry.x;
1729 frame_info.inner_bevel=geometry.y;
cristybb503372010-05-27 20:51:26 +00001730 frame_info.x=(ssize_t) frame_info.width;
1731 frame_info.y=(ssize_t) frame_info.height;
cristy3ed852e2009-09-05 21:47:34 +00001732 frame_info.width=(*image)->columns+2*frame_info.width;
1733 frame_info.height=(*image)->rows+2*frame_info.height;
1734 frame_image=FrameImage(*image,&frame_info,exception);
1735 if (frame_image == (Image *) NULL)
1736 break;
1737 *image=DestroyImage(*image);
1738 *image=frame_image;
1739 break;
1740 }
1741 if (LocaleCompare("function",option+1) == 0)
1742 {
1743 char
1744 *arguments,
1745 token[MaxTextExtent];
1746
1747 const char
1748 *p;
1749
1750 double
1751 *parameters;
1752
1753 MagickFunction
1754 function;
1755
cristybb503372010-05-27 20:51:26 +00001756 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001757 x;
1758
cristybb503372010-05-27 20:51:26 +00001759 size_t
cristy3ed852e2009-09-05 21:47:34 +00001760 number_parameters;
1761
1762 /*
1763 Function Modify Image Values
1764 */
cristy6b3da3a2010-06-20 02:21:46 +00001765 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001766 function=(MagickFunction) ParseMagickOption(MagickFunctionOptions,
1767 MagickFalse,argv[i+1]);
cristy6b3da3a2010-06-20 02:21:46 +00001768 arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
cristy3ed852e2009-09-05 21:47:34 +00001769 InheritException(exception,&(*image)->exception);
1770 if (arguments == (char *) NULL)
1771 break;
1772 p=(char *) arguments;
1773 for (x=0; *p != '\0'; x++)
1774 {
1775 GetMagickToken(p,&p,token);
1776 if (*token == ',')
1777 GetMagickToken(p,&p,token);
1778 }
cristybb503372010-05-27 20:51:26 +00001779 number_parameters=(size_t) x;
cristy3ed852e2009-09-05 21:47:34 +00001780 parameters=(double *) AcquireQuantumMemory(number_parameters,
1781 sizeof(*parameters));
1782 if (parameters == (double *) NULL)
1783 ThrowWandFatalException(ResourceLimitFatalError,
1784 "MemoryAllocationFailed",(*image)->filename);
1785 (void) ResetMagickMemory(parameters,0,number_parameters*
1786 sizeof(*parameters));
1787 p=(char *) arguments;
cristybb503372010-05-27 20:51:26 +00001788 for (x=0; (x < (ssize_t) number_parameters) && (*p != '\0'); x++)
cristy3ed852e2009-09-05 21:47:34 +00001789 {
1790 GetMagickToken(p,&p,token);
1791 if (*token == ',')
1792 GetMagickToken(p,&p,token);
cristyf2f27272009-12-17 14:48:46 +00001793 parameters[x]=StringToDouble(token);
cristy3ed852e2009-09-05 21:47:34 +00001794 }
1795 arguments=DestroyString(arguments);
1796 (void) FunctionImageChannel(*image,channel,function,
1797 number_parameters,parameters,exception);
1798 parameters=(double *) RelinquishMagickMemory(parameters);
1799 break;
1800 }
1801 break;
1802 }
1803 case 'g':
1804 {
1805 if (LocaleCompare("gamma",option+1) == 0)
1806 {
1807 /*
1808 Gamma image.
1809 */
cristy6b3da3a2010-06-20 02:21:46 +00001810 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001811 if (*option == '+')
cristyf2f27272009-12-17 14:48:46 +00001812 (*image)->gamma=StringToDouble(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00001813 else
1814 {
1815 if (strchr(argv[i+1],',') != (char *) NULL)
1816 (void) GammaImage(*image,argv[i+1]);
1817 else
cristya5447be2010-01-11 00:20:51 +00001818 (void) GammaImageChannel(*image,channel,
1819 StringToDouble(argv[i+1]));
cristy3ed852e2009-09-05 21:47:34 +00001820 InheritException(exception,&(*image)->exception);
1821 }
1822 break;
1823 }
1824 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
1825 (LocaleCompare("gaussian",option+1) == 0))
1826 {
1827 Image
1828 *gaussian_image;
1829
1830 /*
1831 Gaussian blur image.
1832 */
cristy6b3da3a2010-06-20 02:21:46 +00001833 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001834 flags=ParseGeometry(argv[i+1],&geometry_info);
1835 if ((flags & SigmaValue) == 0)
1836 geometry_info.sigma=1.0;
1837 gaussian_image=GaussianBlurImageChannel(*image,channel,
1838 geometry_info.rho,geometry_info.sigma,exception);
1839 if (gaussian_image == (Image *) NULL)
1840 break;
1841 *image=DestroyImage(*image);
1842 *image=gaussian_image;
1843 break;
1844 }
1845 if (LocaleCompare("geometry",option+1) == 0)
1846 {
cristy6b3da3a2010-06-20 02:21:46 +00001847 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001848 if (*option == '+')
1849 {
1850 if ((*image)->geometry != (char *) NULL)
1851 (*image)->geometry=DestroyString((*image)->geometry);
1852 break;
1853 }
1854 flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
1855 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
1856 (void) CloneString(&(*image)->geometry,argv[i+1]);
1857 else
1858 {
1859 Image
cristy15b98cd2010-09-12 19:42:50 +00001860 *resize_image;
cristy3ed852e2009-09-05 21:47:34 +00001861
1862 /*
1863 Resize image.
1864 */
cristy15b98cd2010-09-12 19:42:50 +00001865 resize_image=ResizeImage(*image,geometry.width,geometry.height,
1866 (*image)->filter,(*image)->blur,exception);
1867 if (resize_image == (Image *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001868 break;
1869 *image=DestroyImage(*image);
cristy15b98cd2010-09-12 19:42:50 +00001870 *image=resize_image;
cristy3ed852e2009-09-05 21:47:34 +00001871 }
1872 break;
1873 }
1874 if (LocaleCompare("gravity",option+1) == 0)
1875 {
1876 if (*option == '+')
1877 {
1878 draw_info->gravity=UndefinedGravity;
1879 break;
1880 }
1881 draw_info->gravity=(GravityType) ParseMagickOption(
1882 MagickGravityOptions,MagickFalse,argv[i+1]);
1883 break;
1884 }
1885 break;
1886 }
1887 case 'h':
1888 {
1889 if (LocaleCompare("highlight-color",option+1) == 0)
1890 {
1891 (void) SetImageArtifact(*image,option+1,argv[i+1]);
1892 break;
1893 }
1894 break;
1895 }
1896 case 'i':
1897 {
1898 if (LocaleCompare("identify",option+1) == 0)
1899 {
1900 char
1901 *text;
1902
cristy6b3da3a2010-06-20 02:21:46 +00001903 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001904 if (format == (char *) NULL)
1905 {
cristy6b3da3a2010-06-20 02:21:46 +00001906 (void) IdentifyImage(*image,stdout,mogrify_info->verbose);
cristy3ed852e2009-09-05 21:47:34 +00001907 InheritException(exception,&(*image)->exception);
1908 break;
1909 }
cristy6b3da3a2010-06-20 02:21:46 +00001910 text=InterpretImageProperties(mogrify_info,*image,format);
cristy3ed852e2009-09-05 21:47:34 +00001911 InheritException(exception,&(*image)->exception);
1912 if (text == (char *) NULL)
1913 break;
1914 (void) fputs(text,stdout);
1915 (void) fputc('\n',stdout);
1916 text=DestroyString(text);
1917 break;
1918 }
1919 if (LocaleCompare("implode",option+1) == 0)
1920 {
1921 Image
1922 *implode_image;
1923
1924 /*
1925 Implode image.
1926 */
cristy6b3da3a2010-06-20 02:21:46 +00001927 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001928 (void) ParseGeometry(argv[i+1],&geometry_info);
1929 implode_image=ImplodeImage(*image,geometry_info.rho,exception);
1930 if (implode_image == (Image *) NULL)
1931 break;
1932 *image=DestroyImage(*image);
1933 *image=implode_image;
1934 break;
1935 }
cristyb32b90a2009-09-07 21:45:48 +00001936 if (LocaleCompare("interline-spacing",option+1) == 0)
1937 {
1938 if (*option == '+')
1939 (void) ParseGeometry("0",&geometry_info);
1940 else
1941 (void) ParseGeometry(argv[i+1],&geometry_info);
1942 draw_info->interline_spacing=geometry_info.rho;
1943 break;
1944 }
cristy3ed852e2009-09-05 21:47:34 +00001945 if (LocaleCompare("interword-spacing",option+1) == 0)
1946 {
1947 if (*option == '+')
1948 (void) ParseGeometry("0",&geometry_info);
1949 else
1950 (void) ParseGeometry(argv[i+1],&geometry_info);
1951 draw_info->interword_spacing=geometry_info.rho;
1952 break;
1953 }
1954 break;
1955 }
1956 case 'k':
1957 {
1958 if (LocaleCompare("kerning",option+1) == 0)
1959 {
1960 if (*option == '+')
1961 (void) ParseGeometry("0",&geometry_info);
1962 else
1963 (void) ParseGeometry(argv[i+1],&geometry_info);
1964 draw_info->kerning=geometry_info.rho;
1965 break;
1966 }
1967 break;
1968 }
1969 case 'l':
1970 {
1971 if (LocaleCompare("lat",option+1) == 0)
1972 {
1973 Image
1974 *threshold_image;
1975
1976 /*
1977 Local adaptive threshold image.
1978 */
cristy6b3da3a2010-06-20 02:21:46 +00001979 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001980 flags=ParseGeometry(argv[i+1],&geometry_info);
1981 if ((flags & PercentValue) != 0)
1982 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
cristybb503372010-05-27 20:51:26 +00001983 threshold_image=AdaptiveThresholdImage(*image,(size_t)
1984 geometry_info.rho,(size_t) geometry_info.sigma,
1985 (ssize_t) geometry_info.xi,exception);
cristy3ed852e2009-09-05 21:47:34 +00001986 if (threshold_image == (Image *) NULL)
1987 break;
1988 *image=DestroyImage(*image);
1989 *image=threshold_image;
1990 break;
1991 }
1992 if (LocaleCompare("level",option+1) == 0)
1993 {
cristy3ed852e2009-09-05 21:47:34 +00001994 MagickRealType
1995 black_point,
1996 gamma,
1997 white_point;
1998
1999 MagickStatusType
2000 flags;
2001
2002 /*
2003 Parse levels.
2004 */
cristy6b3da3a2010-06-20 02:21:46 +00002005 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002006 flags=ParseGeometry(argv[i+1],&geometry_info);
2007 black_point=geometry_info.rho;
2008 white_point=(MagickRealType) QuantumRange;
2009 if ((flags & SigmaValue) != 0)
2010 white_point=geometry_info.sigma;
2011 gamma=1.0;
2012 if ((flags & XiValue) != 0)
2013 gamma=geometry_info.xi;
2014 if ((flags & PercentValue) != 0)
2015 {
2016 black_point*=(MagickRealType) (QuantumRange/100.0);
2017 white_point*=(MagickRealType) (QuantumRange/100.0);
2018 }
2019 if ((flags & SigmaValue) == 0)
2020 white_point=(MagickRealType) QuantumRange-black_point;
2021 if ((*option == '+') || ((flags & AspectValue) != 0))
2022 (void) LevelizeImageChannel(*image,channel,black_point,
2023 white_point,gamma);
2024 else
2025 (void) LevelImageChannel(*image,channel,black_point,white_point,
2026 gamma);
2027 InheritException(exception,&(*image)->exception);
2028 break;
2029 }
2030 if (LocaleCompare("level-colors",option+1) == 0)
2031 {
2032 char
2033 token[MaxTextExtent];
2034
2035 const char
2036 *p;
2037
2038 MagickPixelPacket
2039 black_point,
2040 white_point;
2041
2042 p=(const char *) argv[i+1];
2043 GetMagickToken(p,&p,token); /* get black point color */
cristyee0f8d72009-09-19 00:58:29 +00002044 if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
cristy3ed852e2009-09-05 21:47:34 +00002045 (void) QueryMagickColor(token,&black_point,exception);
2046 else
cristyee0f8d72009-09-19 00:58:29 +00002047 (void) QueryMagickColor("#000000",&black_point,exception);
cristy3ed852e2009-09-05 21:47:34 +00002048 if (isalpha((int) token[0]) || (token[0] == '#'))
2049 GetMagickToken(p,&p,token);
cristyee0f8d72009-09-19 00:58:29 +00002050 if (*token == '\0')
cristy3ed852e2009-09-05 21:47:34 +00002051 white_point=black_point; /* set everything to that color */
2052 else
2053 {
2054 /*
2055 Get white point color.
2056 */
cristyee0f8d72009-09-19 00:58:29 +00002057 if ((isalpha((int) *token) == 0) && ((*token == '#') == 0))
cristy3ed852e2009-09-05 21:47:34 +00002058 GetMagickToken(p,&p,token);
cristyee0f8d72009-09-19 00:58:29 +00002059 if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
cristy3ed852e2009-09-05 21:47:34 +00002060 (void) QueryMagickColor(token,&white_point,exception);
2061 else
cristyee0f8d72009-09-19 00:58:29 +00002062 (void) QueryMagickColor("#ffffff",&white_point,exception);
cristy3ed852e2009-09-05 21:47:34 +00002063 }
cristy74fe8f12009-10-03 19:09:01 +00002064 (void) LevelColorsImageChannel(*image,channel,&black_point,
2065 &white_point,*option == '+' ? MagickTrue : MagickFalse);
cristy3ed852e2009-09-05 21:47:34 +00002066 break;
2067 }
2068 if (LocaleCompare("linear-stretch",option+1) == 0)
2069 {
2070 double
2071 black_point,
2072 white_point;
2073
cristy3ed852e2009-09-05 21:47:34 +00002074 MagickStatusType
2075 flags;
2076
cristy6b3da3a2010-06-20 02:21:46 +00002077 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002078 flags=ParseGeometry(argv[i+1],&geometry_info);
2079 black_point=geometry_info.rho;
2080 white_point=(MagickRealType) (*image)->columns*(*image)->rows;
2081 if ((flags & SigmaValue) != 0)
2082 white_point=geometry_info.sigma;
2083 if ((flags & PercentValue) != 0)
2084 {
2085 black_point*=(double) (*image)->columns*(*image)->rows/100.0;
2086 white_point*=(double) (*image)->columns*(*image)->rows/100.0;
2087 }
2088 if ((flags & SigmaValue) == 0)
2089 white_point=(MagickRealType) (*image)->columns*(*image)->rows-
2090 black_point;
2091 (void) LinearStretchImage(*image,black_point,white_point);
2092 InheritException(exception,&(*image)->exception);
2093 break;
2094 }
2095 if (LocaleCompare("linewidth",option+1) == 0)
2096 {
cristyf2f27272009-12-17 14:48:46 +00002097 draw_info->stroke_width=StringToDouble(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00002098 break;
2099 }
2100 if (LocaleCompare("liquid-rescale",option+1) == 0)
2101 {
2102 Image
2103 *resize_image;
2104
2105 /*
2106 Liquid rescale image.
2107 */
cristy6b3da3a2010-06-20 02:21:46 +00002108 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002109 flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2110 if ((flags & XValue) == 0)
2111 geometry.x=1;
2112 if ((flags & YValue) == 0)
2113 geometry.y=0;
2114 resize_image=LiquidRescaleImage(*image,geometry.width,
2115 geometry.height,1.0*geometry.x,1.0*geometry.y,exception);
2116 if (resize_image == (Image *) NULL)
2117 break;
2118 *image=DestroyImage(*image);
2119 *image=resize_image;
2120 break;
2121 }
2122 if (LocaleCompare("lowlight-color",option+1) == 0)
2123 {
2124 (void) SetImageArtifact(*image,option+1,argv[i+1]);
2125 break;
2126 }
2127 break;
2128 }
2129 case 'm':
2130 {
2131 if (LocaleCompare("map",option+1) == 0)
2132 {
2133 Image
2134 *remap_image;
2135
2136 /*
2137 Transform image colors to match this set of colors.
2138 */
cristy6b3da3a2010-06-20 02:21:46 +00002139 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002140 if (*option == '+')
2141 break;
cristy6b3da3a2010-06-20 02:21:46 +00002142 remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
cristy3ed852e2009-09-05 21:47:34 +00002143 if (remap_image == (Image *) NULL)
2144 break;
2145 (void) RemapImage(quantize_info,*image,remap_image);
2146 InheritException(exception,&(*image)->exception);
2147 remap_image=DestroyImage(remap_image);
2148 break;
2149 }
2150 if (LocaleCompare("mask",option+1) == 0)
2151 {
2152 Image
2153 *mask;
2154
cristy6b3da3a2010-06-20 02:21:46 +00002155 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002156 if (*option == '+')
2157 {
2158 /*
2159 Remove a mask.
2160 */
2161 (void) SetImageMask(*image,(Image *) NULL);
2162 InheritException(exception,&(*image)->exception);
2163 break;
2164 }
2165 /*
2166 Set the image mask.
2167 */
cristy6b3da3a2010-06-20 02:21:46 +00002168 mask=GetImageCache(mogrify_info,argv[i+1],exception);
cristy3ed852e2009-09-05 21:47:34 +00002169 if (mask == (Image *) NULL)
2170 break;
2171 (void) SetImageMask(*image,mask);
2172 mask=DestroyImage(mask);
2173 InheritException(exception,&(*image)->exception);
2174 break;
2175 }
2176 if (LocaleCompare("matte",option+1) == 0)
2177 {
2178 (void) SetImageAlphaChannel(*image,(*option == '-') ?
2179 SetAlphaChannel : DeactivateAlphaChannel );
2180 InheritException(exception,&(*image)->exception);
2181 break;
2182 }
2183 if (LocaleCompare("median",option+1) == 0)
2184 {
2185 Image
2186 *median_image;
2187
2188 /*
2189 Median filter image.
2190 */
cristy6b3da3a2010-06-20 02:21:46 +00002191 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002192 (void) ParseGeometry(argv[i+1],&geometry_info);
2193 median_image=MedianFilterImage(*image,geometry_info.rho,exception);
2194 if (median_image == (Image *) NULL)
2195 break;
2196 *image=DestroyImage(*image);
2197 *image=median_image;
2198 break;
2199 }
2200 if (LocaleCompare("modulate",option+1) == 0)
2201 {
cristy6b3da3a2010-06-20 02:21:46 +00002202 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002203 (void) ModulateImage(*image,argv[i+1]);
2204 InheritException(exception,&(*image)->exception);
2205 break;
2206 }
2207 if (LocaleCompare("monitor",option+1) == 0)
2208 {
cristy7d34ef22010-03-25 01:11:22 +00002209 if (*option == '+')
2210 {
2211 (void) SetImageProgressMonitor(*image,
2212 (MagickProgressMonitor) NULL,(void *) NULL);
2213 break;
2214 }
cristy3ed852e2009-09-05 21:47:34 +00002215 (void) SetImageProgressMonitor(*image,MonitorProgress,
2216 (void *) NULL);
2217 break;
2218 }
2219 if (LocaleCompare("monochrome",option+1) == 0)
2220 {
cristy6b3da3a2010-06-20 02:21:46 +00002221 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002222 (void) SetImageType(*image,BilevelType);
2223 InheritException(exception,&(*image)->exception);
2224 break;
2225 }
anthony29188a82010-01-22 10:12:34 +00002226 if (LocaleCompare("morphology",option+1) == 0)
2227 {
anthony29188a82010-01-22 10:12:34 +00002228 char
2229 token[MaxTextExtent];
2230
2231 const char
2232 *p;
2233
cristye96405a2010-05-19 02:24:31 +00002234 Image
2235 *morphology_image;
2236
2237 KernelInfo
2238 *kernel;
2239
cristybb503372010-05-27 20:51:26 +00002240 ssize_t
anthony29188a82010-01-22 10:12:34 +00002241 iterations;
2242
cristye96405a2010-05-19 02:24:31 +00002243 MorphologyMethod
2244 method;
2245
anthony29188a82010-01-22 10:12:34 +00002246 /*
2247 Morphological Image Operation
2248 */
cristy6b3da3a2010-06-20 02:21:46 +00002249 (void) SyncImageSettings(mogrify_info,*image);
anthony29188a82010-01-22 10:12:34 +00002250 p=argv[i+1];
2251 GetMagickToken(p,&p,token);
2252 method=(MorphologyMethod) ParseMagickOption(MagickMorphologyOptions,
cristyd2c1e1e2010-05-08 01:05:44 +00002253 MagickFalse,token);
cristyef656912010-03-05 19:54:59 +00002254 iterations=1L;
anthony29188a82010-01-22 10:12:34 +00002255 GetMagickToken(p,&p,token);
cristyef656912010-03-05 19:54:59 +00002256 if ((*p == ':') || (*p == ','))
anthony29188a82010-01-22 10:12:34 +00002257 GetMagickToken(p,&p,token);
cristyef656912010-03-05 19:54:59 +00002258 if ((*p != '\0'))
cristy32c2aea2010-12-01 01:00:50 +00002259 iterations=(ssize_t) StringToLong(p);
anthony29188a82010-01-22 10:12:34 +00002260 kernel=AcquireKernelInfo(argv[i+2]);
2261 if (kernel == (KernelInfo *) NULL)
cristye96405a2010-05-19 02:24:31 +00002262 {
2263 (void) ThrowMagickException(exception,GetMagickModule(),
2264 OptionError,"UnabletoParseKernel","morphology");
2265 status=MagickFalse;
2266 break;
2267 }
anthony29188a82010-01-22 10:12:34 +00002268 morphology_image=MorphologyImageChannel(*image,channel,method,
cristy02d5b4f2010-02-01 01:08:27 +00002269 iterations,kernel,exception);
anthony83ba99b2010-01-24 08:48:15 +00002270 kernel=DestroyKernelInfo(kernel);
anthony29188a82010-01-22 10:12:34 +00002271 if (morphology_image == (Image *) NULL)
2272 break;
2273 *image=DestroyImage(*image);
2274 *image=morphology_image;
2275 break;
2276 }
cristy3ed852e2009-09-05 21:47:34 +00002277 if (LocaleCompare("motion-blur",option+1) == 0)
2278 {
2279 Image
2280 *blur_image;
2281
2282 /*
2283 Motion blur image.
2284 */
cristy6b3da3a2010-06-20 02:21:46 +00002285 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002286 flags=ParseGeometry(argv[i+1],&geometry_info);
2287 if ((flags & SigmaValue) == 0)
2288 geometry_info.sigma=1.0;
2289 blur_image=MotionBlurImageChannel(*image,channel,geometry_info.rho,
2290 geometry_info.sigma,geometry_info.xi,exception);
2291 if (blur_image == (Image *) NULL)
2292 break;
2293 *image=DestroyImage(*image);
2294 *image=blur_image;
2295 break;
2296 }
2297 break;
2298 }
2299 case 'n':
2300 {
2301 if (LocaleCompare("negate",option+1) == 0)
2302 {
cristy6b3da3a2010-06-20 02:21:46 +00002303 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002304 (void) NegateImageChannel(*image,channel,*option == '+' ?
2305 MagickTrue : MagickFalse);
2306 InheritException(exception,&(*image)->exception);
2307 break;
2308 }
2309 if (LocaleCompare("noise",option+1) == 0)
2310 {
2311 Image
2312 *noisy_image;
2313
cristy6b3da3a2010-06-20 02:21:46 +00002314 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002315 if (*option == '-')
2316 {
2317 (void) ParseGeometry(argv[i+1],&geometry_info);
2318 noisy_image=ReduceNoiseImage(*image,geometry_info.rho,
2319 exception);
2320 }
2321 else
2322 {
2323 NoiseType
2324 noise;
2325
2326 noise=(NoiseType) ParseMagickOption(MagickNoiseOptions,
2327 MagickFalse,argv[i+1]);
2328 noisy_image=AddNoiseImageChannel(*image,channel,noise,
2329 exception);
2330 }
2331 if (noisy_image == (Image *) NULL)
2332 break;
2333 *image=DestroyImage(*image);
2334 *image=noisy_image;
2335 break;
2336 }
2337 if (LocaleCompare("normalize",option+1) == 0)
2338 {
cristy6b3da3a2010-06-20 02:21:46 +00002339 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002340 (void) NormalizeImageChannel(*image,channel);
2341 InheritException(exception,&(*image)->exception);
2342 break;
2343 }
2344 break;
2345 }
2346 case 'o':
2347 {
2348 if (LocaleCompare("opaque",option+1) == 0)
2349 {
2350 MagickPixelPacket
2351 target;
2352
cristy6b3da3a2010-06-20 02:21:46 +00002353 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002354 (void) QueryMagickColor(argv[i+1],&target,exception);
2355 (void) OpaquePaintImageChannel(*image,channel,&target,&fill,
2356 *option == '-' ? MagickFalse : MagickTrue);
2357 break;
2358 }
2359 if (LocaleCompare("ordered-dither",option+1) == 0)
2360 {
cristy6b3da3a2010-06-20 02:21:46 +00002361 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002362 (void) OrderedPosterizeImageChannel(*image,channel,argv[i+1],
2363 exception);
2364 break;
2365 }
2366 break;
2367 }
2368 case 'p':
2369 {
2370 if (LocaleCompare("paint",option+1) == 0)
2371 {
2372 Image
2373 *paint_image;
2374
2375 /*
2376 Oil paint image.
2377 */
cristy6b3da3a2010-06-20 02:21:46 +00002378 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002379 (void) ParseGeometry(argv[i+1],&geometry_info);
2380 paint_image=OilPaintImage(*image,geometry_info.rho,exception);
2381 if (paint_image == (Image *) NULL)
2382 break;
2383 *image=DestroyImage(*image);
2384 *image=paint_image;
2385 break;
2386 }
2387 if (LocaleCompare("pen",option+1) == 0)
2388 {
2389 if (*option == '+')
2390 {
2391 (void) QueryColorDatabase("none",&draw_info->fill,exception);
2392 break;
2393 }
2394 (void) QueryColorDatabase(argv[i+1],&draw_info->fill,exception);
2395 break;
2396 }
2397 if (LocaleCompare("pointsize",option+1) == 0)
2398 {
2399 if (*option == '+')
2400 (void) ParseGeometry("12",&geometry_info);
2401 else
2402 (void) ParseGeometry(argv[i+1],&geometry_info);
2403 draw_info->pointsize=geometry_info.rho;
2404 break;
2405 }
2406 if (LocaleCompare("polaroid",option+1) == 0)
2407 {
2408 double
2409 angle;
2410
2411 Image
2412 *polaroid_image;
2413
2414 RandomInfo
2415 *random_info;
2416
2417 /*
2418 Simulate a Polaroid picture.
2419 */
cristy6b3da3a2010-06-20 02:21:46 +00002420 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002421 random_info=AcquireRandomInfo();
2422 angle=22.5*(GetPseudoRandomValue(random_info)-0.5);
2423 random_info=DestroyRandomInfo(random_info);
2424 if (*option == '-')
2425 {
2426 SetGeometryInfo(&geometry_info);
2427 flags=ParseGeometry(argv[i+1],&geometry_info);
2428 angle=geometry_info.rho;
2429 }
2430 polaroid_image=PolaroidImage(*image,draw_info,angle,exception);
2431 if (polaroid_image == (Image *) NULL)
2432 break;
2433 *image=DestroyImage(*image);
2434 *image=polaroid_image;
2435 break;
2436 }
2437 if (LocaleCompare("posterize",option+1) == 0)
2438 {
2439 /*
2440 Posterize image.
2441 */
cristy6b3da3a2010-06-20 02:21:46 +00002442 (void) SyncImageSettings(mogrify_info,*image);
cristye27293e2009-12-18 02:53:20 +00002443 (void) PosterizeImage(*image,StringToUnsignedLong(argv[i+1]),
cristy3ed852e2009-09-05 21:47:34 +00002444 quantize_info->dither);
2445 InheritException(exception,&(*image)->exception);
2446 break;
2447 }
2448 if (LocaleCompare("preview",option+1) == 0)
2449 {
2450 Image
2451 *preview_image;
2452
2453 PreviewType
2454 preview_type;
2455
2456 /*
2457 Preview image.
2458 */
cristy6b3da3a2010-06-20 02:21:46 +00002459 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002460 if (*option == '+')
2461 preview_type=UndefinedPreview;
2462 else
2463 preview_type=(PreviewType) ParseMagickOption(MagickPreviewOptions,
2464 MagickFalse,argv[i+1]);
2465 preview_image=PreviewImage(*image,preview_type,exception);
2466 if (preview_image == (Image *) NULL)
2467 break;
2468 *image=DestroyImage(*image);
2469 *image=preview_image;
2470 break;
2471 }
2472 if (LocaleCompare("profile",option+1) == 0)
2473 {
2474 const char
2475 *name;
2476
2477 const StringInfo
2478 *profile;
2479
2480 Image
2481 *profile_image;
2482
2483 ImageInfo
2484 *profile_info;
2485
cristy6b3da3a2010-06-20 02:21:46 +00002486 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002487 if (*option == '+')
2488 {
2489 /*
2490 Remove a profile from the image.
2491 */
2492 (void) ProfileImage(*image,argv[i+1],(const unsigned char *)
2493 NULL,0,MagickTrue);
2494 InheritException(exception,&(*image)->exception);
2495 break;
2496 }
2497 /*
2498 Associate a profile with the image.
2499 */
cristy6b3da3a2010-06-20 02:21:46 +00002500 profile_info=CloneImageInfo(mogrify_info);
cristy3ed852e2009-09-05 21:47:34 +00002501 profile=GetImageProfile(*image,"iptc");
2502 if (profile != (StringInfo *) NULL)
2503 profile_info->profile=(void *) CloneStringInfo(profile);
2504 profile_image=GetImageCache(profile_info,argv[i+1],exception);
2505 profile_info=DestroyImageInfo(profile_info);
2506 if (profile_image == (Image *) NULL)
2507 {
cristy3ed852e2009-09-05 21:47:34 +00002508 StringInfo
2509 *profile;
2510
cristy6b3da3a2010-06-20 02:21:46 +00002511 profile_info=CloneImageInfo(mogrify_info);
cristy071dd7b2010-04-09 13:04:54 +00002512 (void) CopyMagickString(profile_info->filename,argv[i+1],
2513 MaxTextExtent);
2514 profile=FileToStringInfo(profile_info->filename,~0UL,exception);
cristy3ed852e2009-09-05 21:47:34 +00002515 if (profile != (StringInfo *) NULL)
2516 {
cristy071dd7b2010-04-09 13:04:54 +00002517 (void) ProfileImage(*image,profile_info->magick,
cristybb503372010-05-27 20:51:26 +00002518 GetStringInfoDatum(profile),(size_t)
cristy071dd7b2010-04-09 13:04:54 +00002519 GetStringInfoLength(profile),MagickFalse);
cristy3ed852e2009-09-05 21:47:34 +00002520 profile=DestroyStringInfo(profile);
2521 }
cristy071dd7b2010-04-09 13:04:54 +00002522 profile_info=DestroyImageInfo(profile_info);
cristy3ed852e2009-09-05 21:47:34 +00002523 break;
2524 }
2525 ResetImageProfileIterator(profile_image);
2526 name=GetNextImageProfile(profile_image);
2527 while (name != (const char *) NULL)
2528 {
2529 profile=GetImageProfile(profile_image,name);
2530 if (profile != (StringInfo *) NULL)
2531 (void) ProfileImage(*image,name,GetStringInfoDatum(profile),
cristybb503372010-05-27 20:51:26 +00002532 (size_t) GetStringInfoLength(profile),MagickFalse);
cristy3ed852e2009-09-05 21:47:34 +00002533 name=GetNextImageProfile(profile_image);
2534 }
2535 profile_image=DestroyImage(profile_image);
2536 break;
2537 }
2538 break;
2539 }
2540 case 'q':
2541 {
2542 if (LocaleCompare("quantize",option+1) == 0)
2543 {
2544 if (*option == '+')
2545 {
2546 quantize_info->colorspace=UndefinedColorspace;
2547 break;
2548 }
2549 quantize_info->colorspace=(ColorspaceType) ParseMagickOption(
2550 MagickColorspaceOptions,MagickFalse,argv[i+1]);
2551 break;
2552 }
2553 break;
2554 }
2555 case 'r':
2556 {
2557 if (LocaleCompare("radial-blur",option+1) == 0)
2558 {
2559 Image
2560 *blur_image;
2561
2562 /*
2563 Radial blur image.
2564 */
cristy6b3da3a2010-06-20 02:21:46 +00002565 (void) SyncImageSettings(mogrify_info,*image);
cristya5447be2010-01-11 00:20:51 +00002566 blur_image=RadialBlurImageChannel(*image,channel,
2567 StringToDouble(argv[i+1]),exception);
cristy3ed852e2009-09-05 21:47:34 +00002568 if (blur_image == (Image *) NULL)
2569 break;
2570 *image=DestroyImage(*image);
2571 *image=blur_image;
2572 break;
2573 }
2574 if (LocaleCompare("raise",option+1) == 0)
2575 {
2576 /*
2577 Surround image with a raise of solid color.
2578 */
2579 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2580 if ((flags & SigmaValue) == 0)
2581 geometry.height=geometry.width;
2582 (void) RaiseImage(*image,&geometry,*option == '-' ? MagickTrue :
2583 MagickFalse);
2584 InheritException(exception,&(*image)->exception);
2585 break;
2586 }
2587 if (LocaleCompare("random-threshold",option+1) == 0)
2588 {
2589 /*
2590 Threshold image.
2591 */
cristy6b3da3a2010-06-20 02:21:46 +00002592 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002593 (void) RandomThresholdImageChannel(*image,channel,argv[i+1],
2594 exception);
2595 break;
2596 }
2597 if (LocaleCompare("recolor",option+1) == 0)
2598 {
cristy3ed852e2009-09-05 21:47:34 +00002599 Image
cristyf055ae42010-04-02 23:01:38 +00002600 *color_image;
cristy3ed852e2009-09-05 21:47:34 +00002601
cristyf055ae42010-04-02 23:01:38 +00002602 KernelInfo
2603 *kernel;
cristy3ed852e2009-09-05 21:47:34 +00002604
cristy6b3da3a2010-06-20 02:21:46 +00002605 (void) SyncImageSettings(mogrify_info,*image);
cristyf055ae42010-04-02 23:01:38 +00002606 kernel=AcquireKernelInfo(argv[i+1]);
2607 if (kernel == (KernelInfo *) NULL)
2608 break;
2609 color_image=ColorMatrixImage(*image,kernel,exception);
2610 kernel=DestroyKernelInfo(kernel);
2611 if (color_image == (Image *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002612 break;
2613 *image=DestroyImage(*image);
cristyf055ae42010-04-02 23:01:38 +00002614 *image=color_image;
cristy3ed852e2009-09-05 21:47:34 +00002615 break;
2616 }
2617 if (LocaleCompare("region",option+1) == 0)
2618 {
2619 Image
2620 *crop_image;
2621
cristy6b3da3a2010-06-20 02:21:46 +00002622 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002623 if (region_image != (Image *) NULL)
2624 {
2625 /*
2626 Composite region.
2627 */
2628 (void) CompositeImage(region_image,(*image)->matte !=
2629 MagickFalse ? OverCompositeOp : CopyCompositeOp,*image,
2630 region_geometry.x,region_geometry.y);
2631 InheritException(exception,&region_image->exception);
2632 *image=DestroyImage(*image);
2633 *image=region_image;
2634 }
2635 if (*option == '+')
2636 {
2637 if (region_image != (Image *) NULL)
cristyb0a6e432010-10-09 13:26:15 +00002638 region_image=(Image *) NULL;
cristy3ed852e2009-09-05 21:47:34 +00002639 break;
2640 }
2641 /*
2642 Apply transformations to a selected region of the image.
2643 */
2644 (void) ParseGravityGeometry(*image,argv[i+1],&region_geometry,
2645 exception);
2646 crop_image=CropImage(*image,&region_geometry,exception);
2647 if (crop_image == (Image *) NULL)
2648 break;
2649 region_image=(*image);
2650 *image=crop_image;
2651 break;
2652 }
2653 if (LocaleCompare("render",option+1) == 0)
2654 {
cristy6b3da3a2010-06-20 02:21:46 +00002655 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002656 draw_info->render=(*option == '+') ? MagickTrue : MagickFalse;
2657 break;
2658 }
2659 if (LocaleCompare("remap",option+1) == 0)
2660 {
2661 Image
2662 *remap_image;
2663
2664 /*
2665 Transform image colors to match this set of colors.
2666 */
cristy6b3da3a2010-06-20 02:21:46 +00002667 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002668 if (*option == '+')
2669 break;
cristy6b3da3a2010-06-20 02:21:46 +00002670 remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
cristy3ed852e2009-09-05 21:47:34 +00002671 if (remap_image == (Image *) NULL)
2672 break;
2673 (void) RemapImage(quantize_info,*image,remap_image);
2674 InheritException(exception,&(*image)->exception);
2675 remap_image=DestroyImage(remap_image);
2676 break;
2677 }
2678 if (LocaleCompare("repage",option+1) == 0)
2679 {
2680 if (*option == '+')
2681 {
2682 (void) ParseAbsoluteGeometry("0x0+0+0",&(*image)->page);
2683 break;
2684 }
2685 (void) ResetImagePage(*image,argv[i+1]);
2686 InheritException(exception,&(*image)->exception);
2687 break;
2688 }
2689 if (LocaleCompare("resample",option+1) == 0)
2690 {
2691 Image
2692 *resample_image;
2693
2694 /*
2695 Resample image.
2696 */
cristy6b3da3a2010-06-20 02:21:46 +00002697 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002698 flags=ParseGeometry(argv[i+1],&geometry_info);
2699 if ((flags & SigmaValue) == 0)
2700 geometry_info.sigma=geometry_info.rho;
2701 resample_image=ResampleImage(*image,geometry_info.rho,
2702 geometry_info.sigma,(*image)->filter,(*image)->blur,exception);
2703 if (resample_image == (Image *) NULL)
2704 break;
2705 *image=DestroyImage(*image);
2706 *image=resample_image;
2707 break;
2708 }
2709 if (LocaleCompare("resize",option+1) == 0)
2710 {
2711 Image
2712 *resize_image;
2713
2714 /*
2715 Resize image.
2716 */
cristy6b3da3a2010-06-20 02:21:46 +00002717 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002718 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2719 resize_image=ResizeImage(*image,geometry.width,geometry.height,
2720 (*image)->filter,(*image)->blur,exception);
2721 if (resize_image == (Image *) NULL)
2722 break;
2723 *image=DestroyImage(*image);
2724 *image=resize_image;
2725 break;
2726 }
2727 if (LocaleNCompare("respect-parentheses",option+1,17) == 0)
2728 {
2729 respect_parenthesis=(*option == '-') ? MagickTrue : MagickFalse;
2730 break;
2731 }
2732 if (LocaleCompare("roll",option+1) == 0)
2733 {
2734 Image
2735 *roll_image;
2736
2737 /*
2738 Roll image.
2739 */
cristy6b3da3a2010-06-20 02:21:46 +00002740 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002741 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2742 roll_image=RollImage(*image,geometry.x,geometry.y,exception);
2743 if (roll_image == (Image *) NULL)
2744 break;
2745 *image=DestroyImage(*image);
2746 *image=roll_image;
2747 break;
2748 }
2749 if (LocaleCompare("rotate",option+1) == 0)
2750 {
2751 char
2752 *geometry;
2753
2754 Image
2755 *rotate_image;
2756
2757 /*
2758 Check for conditional image rotation.
2759 */
cristy6b3da3a2010-06-20 02:21:46 +00002760 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002761 if (strchr(argv[i+1],'>') != (char *) NULL)
2762 if ((*image)->columns <= (*image)->rows)
2763 break;
2764 if (strchr(argv[i+1],'<') != (char *) NULL)
2765 if ((*image)->columns >= (*image)->rows)
2766 break;
2767 /*
2768 Rotate image.
2769 */
2770 geometry=ConstantString(argv[i+1]);
2771 (void) SubstituteString(&geometry,">","");
2772 (void) SubstituteString(&geometry,"<","");
2773 (void) ParseGeometry(geometry,&geometry_info);
2774 geometry=DestroyString(geometry);
2775 rotate_image=RotateImage(*image,geometry_info.rho,exception);
2776 if (rotate_image == (Image *) NULL)
2777 break;
2778 *image=DestroyImage(*image);
2779 *image=rotate_image;
2780 break;
2781 }
2782 break;
2783 }
2784 case 's':
2785 {
2786 if (LocaleCompare("sample",option+1) == 0)
2787 {
2788 Image
2789 *sample_image;
2790
2791 /*
2792 Sample image with pixel replication.
2793 */
cristy6b3da3a2010-06-20 02:21:46 +00002794 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002795 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2796 sample_image=SampleImage(*image,geometry.width,geometry.height,
2797 exception);
2798 if (sample_image == (Image *) NULL)
2799 break;
2800 *image=DestroyImage(*image);
2801 *image=sample_image;
2802 break;
2803 }
2804 if (LocaleCompare("scale",option+1) == 0)
2805 {
2806 Image
2807 *scale_image;
2808
2809 /*
2810 Resize image.
2811 */
cristy6b3da3a2010-06-20 02:21:46 +00002812 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002813 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2814 scale_image=ScaleImage(*image,geometry.width,geometry.height,
2815 exception);
2816 if (scale_image == (Image *) NULL)
2817 break;
2818 *image=DestroyImage(*image);
2819 *image=scale_image;
2820 break;
2821 }
2822 if (LocaleCompare("selective-blur",option+1) == 0)
2823 {
2824 Image
2825 *blur_image;
2826
2827 /*
2828 Selectively blur pixels within a contrast threshold.
2829 */
cristy6b3da3a2010-06-20 02:21:46 +00002830 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002831 flags=ParseGeometry(argv[i+1],&geometry_info);
2832 if ((flags & PercentValue) != 0)
2833 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
2834 blur_image=SelectiveBlurImageChannel(*image,channel,
2835 geometry_info.rho,geometry_info.sigma,geometry_info.xi,exception);
2836 if (blur_image == (Image *) NULL)
2837 break;
2838 *image=DestroyImage(*image);
2839 *image=blur_image;
2840 break;
2841 }
2842 if (LocaleCompare("separate",option+1) == 0)
2843 {
2844 Image
2845 *separate_images;
2846
2847 /*
2848 Break channels into separate images.
2849 */
cristy6b3da3a2010-06-20 02:21:46 +00002850 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002851 separate_images=SeparateImages(*image,channel,exception);
2852 if (separate_images == (Image *) NULL)
2853 break;
2854 *image=DestroyImage(*image);
2855 *image=separate_images;
2856 break;
2857 }
2858 if (LocaleCompare("sepia-tone",option+1) == 0)
2859 {
2860 double
2861 threshold;
2862
2863 Image
2864 *sepia_image;
2865
2866 /*
2867 Sepia-tone image.
2868 */
cristy6b3da3a2010-06-20 02:21:46 +00002869 (void) SyncImageSettings(mogrify_info,*image);
cristyf2f27272009-12-17 14:48:46 +00002870 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
cristy3ed852e2009-09-05 21:47:34 +00002871 sepia_image=SepiaToneImage(*image,threshold,exception);
2872 if (sepia_image == (Image *) NULL)
2873 break;
2874 *image=DestroyImage(*image);
2875 *image=sepia_image;
2876 break;
2877 }
2878 if (LocaleCompare("segment",option+1) == 0)
2879 {
2880 /*
2881 Segment image.
2882 */
cristy6b3da3a2010-06-20 02:21:46 +00002883 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002884 flags=ParseGeometry(argv[i+1],&geometry_info);
2885 if ((flags & SigmaValue) == 0)
2886 geometry_info.sigma=1.0;
cristy7e6164a2010-07-22 20:43:57 +00002887 (void) SegmentImage(*image,(*image)->colorspace,
2888 mogrify_info->verbose,geometry_info.rho,geometry_info.sigma);
cristy3ed852e2009-09-05 21:47:34 +00002889 InheritException(exception,&(*image)->exception);
2890 break;
2891 }
2892 if (LocaleCompare("set",option+1) == 0)
2893 {
cristy6d9a1292010-05-31 14:17:06 +00002894 char
2895 *value;
2896
cristy3ed852e2009-09-05 21:47:34 +00002897 /*
2898 Set image option.
2899 */
cristy6d9a1292010-05-31 14:17:06 +00002900 if (*option == '+')
2901 {
2902 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2903 (void) DeleteImageRegistry(argv[i+1]+9);
2904 else
2905 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
cristy7e109582010-06-01 12:56:44 +00002906 {
cristy6b3da3a2010-06-20 02:21:46 +00002907 (void) DeleteImageOption(mogrify_info,argv[i+1]+7);
cristy7e109582010-06-01 12:56:44 +00002908 (void) DeleteImageArtifact(*image,argv[i+1]+7);
2909 }
cristy6d9a1292010-05-31 14:17:06 +00002910 else
2911 (void) DeleteImageProperty(*image,argv[i+1]);
2912 break;
2913 }
cristy6b3da3a2010-06-20 02:21:46 +00002914 value=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
cristy6d9a1292010-05-31 14:17:06 +00002915 if (value == (char *) NULL)
2916 break;
cristy3ed852e2009-09-05 21:47:34 +00002917 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
cristy6d9a1292010-05-31 14:17:06 +00002918 (void) SetImageRegistry(StringRegistryType,argv[i+1]+9,value,
2919 exception);
cristy3ed852e2009-09-05 21:47:34 +00002920 else
2921 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
cristy6d9a1292010-05-31 14:17:06 +00002922 {
cristy7f02ba12010-09-21 12:39:28 +00002923 (void) SetImageOption(image_info,argv[i+1]+7,value);
cristy6b3da3a2010-06-20 02:21:46 +00002924 (void) SetImageOption(mogrify_info,argv[i+1]+7,value);
cristy6d9a1292010-05-31 14:17:06 +00002925 (void) SetImageArtifact(*image,argv[i+1]+7,value);
2926 }
cristy3ed852e2009-09-05 21:47:34 +00002927 else
cristy6d9a1292010-05-31 14:17:06 +00002928 (void) SetImageProperty(*image,argv[i+1],value);
2929 value=DestroyString(value);
cristy3ed852e2009-09-05 21:47:34 +00002930 break;
2931 }
2932 if (LocaleCompare("shade",option+1) == 0)
2933 {
2934 Image
2935 *shade_image;
2936
2937 /*
2938 Shade image.
2939 */
cristy6b3da3a2010-06-20 02:21:46 +00002940 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002941 flags=ParseGeometry(argv[i+1],&geometry_info);
2942 if ((flags & SigmaValue) == 0)
2943 geometry_info.sigma=1.0;
2944 shade_image=ShadeImage(*image,(*option == '-') ? MagickTrue :
2945 MagickFalse,geometry_info.rho,geometry_info.sigma,exception);
2946 if (shade_image == (Image *) NULL)
2947 break;
2948 *image=DestroyImage(*image);
2949 *image=shade_image;
2950 break;
2951 }
2952 if (LocaleCompare("shadow",option+1) == 0)
2953 {
2954 Image
2955 *shadow_image;
2956
2957 /*
2958 Shadow image.
2959 */
cristy6b3da3a2010-06-20 02:21:46 +00002960 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002961 flags=ParseGeometry(argv[i+1],&geometry_info);
2962 if ((flags & SigmaValue) == 0)
2963 geometry_info.sigma=1.0;
2964 if ((flags & XiValue) == 0)
2965 geometry_info.xi=4.0;
2966 if ((flags & PsiValue) == 0)
2967 geometry_info.psi=4.0;
2968 shadow_image=ShadowImage(*image,geometry_info.rho,
cristybb503372010-05-27 20:51:26 +00002969 geometry_info.sigma,(ssize_t) ceil(geometry_info.xi-0.5),(ssize_t)
cristy0534a6b2010-03-18 01:19:38 +00002970 ceil(geometry_info.psi-0.5),exception);
cristy3ed852e2009-09-05 21:47:34 +00002971 if (shadow_image == (Image *) NULL)
2972 break;
2973 *image=DestroyImage(*image);
2974 *image=shadow_image;
2975 break;
2976 }
2977 if (LocaleCompare("sharpen",option+1) == 0)
2978 {
2979 Image
2980 *sharp_image;
2981
2982 /*
2983 Sharpen image.
2984 */
cristy6b3da3a2010-06-20 02:21:46 +00002985 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002986 flags=ParseGeometry(argv[i+1],&geometry_info);
2987 if ((flags & SigmaValue) == 0)
2988 geometry_info.sigma=1.0;
2989 sharp_image=SharpenImageChannel(*image,channel,geometry_info.rho,
2990 geometry_info.sigma,exception);
2991 if (sharp_image == (Image *) NULL)
2992 break;
2993 *image=DestroyImage(*image);
2994 *image=sharp_image;
2995 break;
2996 }
2997 if (LocaleCompare("shave",option+1) == 0)
2998 {
2999 Image
3000 *shave_image;
3001
3002 /*
3003 Shave the image edges.
3004 */
cristy6b3da3a2010-06-20 02:21:46 +00003005 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003006 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
3007 shave_image=ShaveImage(*image,&geometry,exception);
3008 if (shave_image == (Image *) NULL)
3009 break;
3010 *image=DestroyImage(*image);
3011 *image=shave_image;
3012 break;
3013 }
3014 if (LocaleCompare("shear",option+1) == 0)
3015 {
3016 Image
3017 *shear_image;
3018
3019 /*
3020 Shear image.
3021 */
cristy6b3da3a2010-06-20 02:21:46 +00003022 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003023 flags=ParseGeometry(argv[i+1],&geometry_info);
3024 if ((flags & SigmaValue) == 0)
3025 geometry_info.sigma=geometry_info.rho;
3026 shear_image=ShearImage(*image,geometry_info.rho,geometry_info.sigma,
3027 exception);
3028 if (shear_image == (Image *) NULL)
3029 break;
3030 *image=DestroyImage(*image);
3031 *image=shear_image;
3032 break;
3033 }
3034 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
3035 {
3036 /*
3037 Sigmoidal non-linearity contrast control.
3038 */
cristy6b3da3a2010-06-20 02:21:46 +00003039 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003040 flags=ParseGeometry(argv[i+1],&geometry_info);
3041 if ((flags & SigmaValue) == 0)
3042 geometry_info.sigma=(double) QuantumRange/2.0;
3043 if ((flags & PercentValue) != 0)
3044 geometry_info.sigma=(double) QuantumRange*geometry_info.sigma/
3045 100.0;
3046 (void) SigmoidalContrastImageChannel(*image,channel,
3047 (*option == '-') ? MagickTrue : MagickFalse,geometry_info.rho,
3048 geometry_info.sigma);
3049 InheritException(exception,&(*image)->exception);
3050 break;
3051 }
3052 if (LocaleCompare("sketch",option+1) == 0)
3053 {
3054 Image
3055 *sketch_image;
3056
3057 /*
3058 Sketch image.
3059 */
cristy6b3da3a2010-06-20 02:21:46 +00003060 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003061 flags=ParseGeometry(argv[i+1],&geometry_info);
3062 if ((flags & SigmaValue) == 0)
3063 geometry_info.sigma=1.0;
3064 sketch_image=SketchImage(*image,geometry_info.rho,
3065 geometry_info.sigma,geometry_info.xi,exception);
3066 if (sketch_image == (Image *) NULL)
3067 break;
3068 *image=DestroyImage(*image);
3069 *image=sketch_image;
3070 break;
3071 }
3072 if (LocaleCompare("solarize",option+1) == 0)
3073 {
3074 double
3075 threshold;
3076
cristy6b3da3a2010-06-20 02:21:46 +00003077 (void) SyncImageSettings(mogrify_info,*image);
cristyf2f27272009-12-17 14:48:46 +00003078 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
cristy3ed852e2009-09-05 21:47:34 +00003079 (void) SolarizeImage(*image,threshold);
3080 InheritException(exception,&(*image)->exception);
3081 break;
3082 }
3083 if (LocaleCompare("sparse-color",option+1) == 0)
3084 {
3085 Image
3086 *sparse_image;
3087
3088 SparseColorMethod
3089 method;
3090
3091 char
3092 *arguments;
3093
3094 /*
3095 Sparse Color Interpolated Gradient
3096 */
cristy6b3da3a2010-06-20 02:21:46 +00003097 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003098 method=(SparseColorMethod) ParseMagickOption(
3099 MagickSparseColorOptions,MagickFalse,argv[i+1]);
cristy6b3da3a2010-06-20 02:21:46 +00003100 arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
cristy3ed852e2009-09-05 21:47:34 +00003101 InheritException(exception,&(*image)->exception);
3102 if (arguments == (char *) NULL)
3103 break;
3104 sparse_image=SparseColorOption(*image,channel,method,arguments,
3105 option[0] == '+' ? MagickTrue : MagickFalse,exception);
3106 arguments=DestroyString(arguments);
3107 if (sparse_image == (Image *) NULL)
3108 break;
3109 *image=DestroyImage(*image);
3110 *image=sparse_image;
3111 break;
3112 }
3113 if (LocaleCompare("splice",option+1) == 0)
3114 {
3115 Image
3116 *splice_image;
3117
3118 /*
3119 Splice a solid color into the image.
3120 */
cristy6b3da3a2010-06-20 02:21:46 +00003121 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003122 (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
3123 splice_image=SpliceImage(*image,&geometry,exception);
3124 if (splice_image == (Image *) NULL)
3125 break;
3126 *image=DestroyImage(*image);
3127 *image=splice_image;
3128 break;
3129 }
3130 if (LocaleCompare("spread",option+1) == 0)
3131 {
3132 Image
3133 *spread_image;
3134
3135 /*
3136 Spread an image.
3137 */
cristy6b3da3a2010-06-20 02:21:46 +00003138 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003139 (void) ParseGeometry(argv[i+1],&geometry_info);
3140 spread_image=SpreadImage(*image,geometry_info.rho,exception);
3141 if (spread_image == (Image *) NULL)
3142 break;
3143 *image=DestroyImage(*image);
3144 *image=spread_image;
3145 break;
3146 }
3147 if (LocaleCompare("stretch",option+1) == 0)
3148 {
3149 if (*option == '+')
3150 {
3151 draw_info->stretch=UndefinedStretch;
3152 break;
3153 }
3154 draw_info->stretch=(StretchType) ParseMagickOption(
3155 MagickStretchOptions,MagickFalse,argv[i+1]);
3156 break;
3157 }
3158 if (LocaleCompare("strip",option+1) == 0)
3159 {
3160 /*
3161 Strip image of profiles and comments.
3162 */
cristy6b3da3a2010-06-20 02:21:46 +00003163 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003164 (void) StripImage(*image);
3165 InheritException(exception,&(*image)->exception);
3166 break;
3167 }
3168 if (LocaleCompare("stroke",option+1) == 0)
3169 {
3170 ExceptionInfo
3171 *sans;
3172
3173 if (*option == '+')
3174 {
3175 (void) QueryColorDatabase("none",&draw_info->stroke,exception);
3176 if (draw_info->stroke_pattern != (Image *) NULL)
3177 draw_info->stroke_pattern=DestroyImage(
3178 draw_info->stroke_pattern);
3179 break;
3180 }
3181 sans=AcquireExceptionInfo();
3182 status=QueryColorDatabase(argv[i+1],&draw_info->stroke,sans);
3183 sans=DestroyExceptionInfo(sans);
3184 if (status == MagickFalse)
cristy6b3da3a2010-06-20 02:21:46 +00003185 draw_info->stroke_pattern=GetImageCache(mogrify_info,argv[i+1],
cristy3ed852e2009-09-05 21:47:34 +00003186 exception);
3187 break;
3188 }
3189 if (LocaleCompare("strokewidth",option+1) == 0)
3190 {
cristyf2f27272009-12-17 14:48:46 +00003191 draw_info->stroke_width=StringToDouble(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00003192 break;
3193 }
3194 if (LocaleCompare("style",option+1) == 0)
3195 {
3196 if (*option == '+')
3197 {
3198 draw_info->style=UndefinedStyle;
3199 break;
3200 }
3201 draw_info->style=(StyleType) ParseMagickOption(MagickStyleOptions,
3202 MagickFalse,argv[i+1]);
3203 break;
3204 }
3205 if (LocaleCompare("swirl",option+1) == 0)
3206 {
3207 Image
3208 *swirl_image;
3209
3210 /*
3211 Swirl image.
3212 */
cristy6b3da3a2010-06-20 02:21:46 +00003213 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003214 (void) ParseGeometry(argv[i+1],&geometry_info);
3215 swirl_image=SwirlImage(*image,geometry_info.rho,exception);
3216 if (swirl_image == (Image *) NULL)
3217 break;
3218 *image=DestroyImage(*image);
3219 *image=swirl_image;
3220 break;
3221 }
3222 break;
3223 }
3224 case 't':
3225 {
3226 if (LocaleCompare("threshold",option+1) == 0)
3227 {
3228 double
3229 threshold;
3230
3231 /*
3232 Threshold image.
3233 */
cristy6b3da3a2010-06-20 02:21:46 +00003234 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003235 if (*option == '+')
3236 threshold=(double) QuantumRange/2.5;
3237 else
cristyf2f27272009-12-17 14:48:46 +00003238 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
cristy3ed852e2009-09-05 21:47:34 +00003239 (void) BilevelImageChannel(*image,channel,threshold);
3240 InheritException(exception,&(*image)->exception);
3241 break;
3242 }
3243 if (LocaleCompare("thumbnail",option+1) == 0)
3244 {
3245 Image
3246 *thumbnail_image;
3247
3248 /*
3249 Thumbnail image.
3250 */
cristy6b3da3a2010-06-20 02:21:46 +00003251 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003252 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
3253 thumbnail_image=ThumbnailImage(*image,geometry.width,
3254 geometry.height,exception);
3255 if (thumbnail_image == (Image *) NULL)
3256 break;
3257 *image=DestroyImage(*image);
3258 *image=thumbnail_image;
3259 break;
3260 }
3261 if (LocaleCompare("tile",option+1) == 0)
3262 {
3263 if (*option == '+')
3264 {
3265 if (draw_info->fill_pattern != (Image *) NULL)
3266 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
3267 break;
3268 }
cristy6b3da3a2010-06-20 02:21:46 +00003269 draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1],
cristy3ed852e2009-09-05 21:47:34 +00003270 exception);
3271 break;
3272 }
3273 if (LocaleCompare("tint",option+1) == 0)
3274 {
3275 Image
3276 *tint_image;
3277
3278 /*
3279 Tint the image.
3280 */
cristy6b3da3a2010-06-20 02:21:46 +00003281 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003282 tint_image=TintImage(*image,argv[i+1],draw_info->fill,exception);
3283 if (tint_image == (Image *) NULL)
3284 break;
3285 *image=DestroyImage(*image);
3286 *image=tint_image;
3287 break;
3288 }
3289 if (LocaleCompare("transform",option+1) == 0)
3290 {
3291 Image
3292 *transform_image;
3293
3294 /*
3295 Affine transform image.
3296 */
cristy6b3da3a2010-06-20 02:21:46 +00003297 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003298 transform_image=AffineTransformImage(*image,&draw_info->affine,
3299 exception);
3300 if (transform_image == (Image *) NULL)
3301 break;
3302 *image=DestroyImage(*image);
3303 *image=transform_image;
3304 break;
3305 }
3306 if (LocaleCompare("transparent",option+1) == 0)
3307 {
3308 MagickPixelPacket
3309 target;
3310
cristy6b3da3a2010-06-20 02:21:46 +00003311 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003312 (void) QueryMagickColor(argv[i+1],&target,exception);
3313 (void) TransparentPaintImage(*image,&target,(Quantum)
3314 TransparentOpacity,*option == '-' ? MagickFalse : MagickTrue);
3315 InheritException(exception,&(*image)->exception);
3316 break;
3317 }
3318 if (LocaleCompare("transpose",option+1) == 0)
3319 {
3320 Image
3321 *transpose_image;
3322
3323 /*
3324 Transpose image scanlines.
3325 */
cristy6b3da3a2010-06-20 02:21:46 +00003326 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003327 transpose_image=TransposeImage(*image,exception);
3328 if (transpose_image == (Image *) NULL)
3329 break;
3330 *image=DestroyImage(*image);
3331 *image=transpose_image;
3332 break;
3333 }
3334 if (LocaleCompare("transverse",option+1) == 0)
3335 {
3336 Image
3337 *transverse_image;
3338
3339 /*
3340 Transverse image scanlines.
3341 */
cristy6b3da3a2010-06-20 02:21:46 +00003342 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003343 transverse_image=TransverseImage(*image,exception);
3344 if (transverse_image == (Image *) NULL)
3345 break;
3346 *image=DestroyImage(*image);
3347 *image=transverse_image;
3348 break;
3349 }
3350 if (LocaleCompare("treedepth",option+1) == 0)
3351 {
cristye27293e2009-12-18 02:53:20 +00003352 quantize_info->tree_depth=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00003353 break;
3354 }
3355 if (LocaleCompare("trim",option+1) == 0)
3356 {
3357 Image
3358 *trim_image;
3359
3360 /*
3361 Trim image.
3362 */
cristy6b3da3a2010-06-20 02:21:46 +00003363 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003364 trim_image=TrimImage(*image,exception);
3365 if (trim_image == (Image *) NULL)
3366 break;
3367 *image=DestroyImage(*image);
3368 *image=trim_image;
3369 break;
3370 }
3371 if (LocaleCompare("type",option+1) == 0)
3372 {
3373 ImageType
3374 type;
3375
cristy6b3da3a2010-06-20 02:21:46 +00003376 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003377 if (*option == '+')
3378 type=UndefinedType;
3379 else
3380 type=(ImageType) ParseMagickOption(MagickTypeOptions,MagickFalse,
3381 argv[i+1]);
3382 (*image)->type=UndefinedType;
3383 (void) SetImageType(*image,type);
3384 InheritException(exception,&(*image)->exception);
3385 break;
3386 }
3387 break;
3388 }
3389 case 'u':
3390 {
3391 if (LocaleCompare("undercolor",option+1) == 0)
3392 {
3393 (void) QueryColorDatabase(argv[i+1],&draw_info->undercolor,
3394 exception);
3395 break;
3396 }
cristy045bd902010-01-30 18:56:24 +00003397 if (LocaleCompare("unique",option+1) == 0)
3398 {
3399 if (*option == '+')
3400 {
cristy83fae872010-04-22 15:04:16 +00003401 (void) DeleteImageArtifact(*image,"identify:unique-colors");
cristy045bd902010-01-30 18:56:24 +00003402 break;
3403 }
cristy83fae872010-04-22 15:04:16 +00003404 (void) SetImageArtifact(*image,"identify:unique-colors","true");
cristya01cbea2010-11-03 16:33:33 +00003405 (void) SetImageArtifact(*image,"verbose","true");
cristy045bd902010-01-30 18:56:24 +00003406 break;
3407 }
cristy3ed852e2009-09-05 21:47:34 +00003408 if (LocaleCompare("unique-colors",option+1) == 0)
3409 {
3410 Image
3411 *unique_image;
3412
3413 /*
3414 Unique image colors.
3415 */
cristy6b3da3a2010-06-20 02:21:46 +00003416 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003417 unique_image=UniqueImageColors(*image,exception);
3418 if (unique_image == (Image *) NULL)
3419 break;
3420 *image=DestroyImage(*image);
3421 *image=unique_image;
3422 break;
3423 }
3424 if (LocaleCompare("unsharp",option+1) == 0)
3425 {
3426 Image
3427 *unsharp_image;
3428
3429 /*
3430 Unsharp mask image.
3431 */
cristy6b3da3a2010-06-20 02:21:46 +00003432 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003433 flags=ParseGeometry(argv[i+1],&geometry_info);
3434 if ((flags & SigmaValue) == 0)
3435 geometry_info.sigma=1.0;
3436 if ((flags & XiValue) == 0)
3437 geometry_info.xi=1.0;
3438 if ((flags & PsiValue) == 0)
3439 geometry_info.psi=0.05;
3440 unsharp_image=UnsharpMaskImageChannel(*image,channel,
3441 geometry_info.rho,geometry_info.sigma,geometry_info.xi,
3442 geometry_info.psi,exception);
3443 if (unsharp_image == (Image *) NULL)
3444 break;
3445 *image=DestroyImage(*image);
3446 *image=unsharp_image;
3447 break;
3448 }
3449 break;
3450 }
3451 case 'v':
3452 {
3453 if (LocaleCompare("verbose",option+1) == 0)
3454 {
3455 (void) SetImageArtifact(*image,option+1,
3456 *option == '+' ? "false" : "true");
3457 break;
3458 }
3459 if (LocaleCompare("vignette",option+1) == 0)
3460 {
3461 Image
3462 *vignette_image;
3463
3464 /*
3465 Vignette image.
3466 */
cristy6b3da3a2010-06-20 02:21:46 +00003467 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003468 flags=ParseGeometry(argv[i+1],&geometry_info);
3469 if ((flags & SigmaValue) == 0)
3470 geometry_info.sigma=1.0;
3471 if ((flags & XiValue) == 0)
3472 geometry_info.xi=0.1*(*image)->columns;
3473 if ((flags & PsiValue) == 0)
3474 geometry_info.psi=0.1*(*image)->rows;
3475 vignette_image=VignetteImage(*image,geometry_info.rho,
cristybb503372010-05-27 20:51:26 +00003476 geometry_info.sigma,(ssize_t) ceil(geometry_info.xi-0.5),(ssize_t)
cristy0534a6b2010-03-18 01:19:38 +00003477 ceil(geometry_info.psi-0.5),exception);
cristy3ed852e2009-09-05 21:47:34 +00003478 if (vignette_image == (Image *) NULL)
3479 break;
3480 *image=DestroyImage(*image);
3481 *image=vignette_image;
3482 break;
3483 }
3484 if (LocaleCompare("virtual-pixel",option+1) == 0)
3485 {
3486 if (*option == '+')
3487 {
3488 (void) SetImageVirtualPixelMethod(*image,
3489 UndefinedVirtualPixelMethod);
3490 break;
3491 }
3492 (void) SetImageVirtualPixelMethod(*image,(VirtualPixelMethod)
3493 ParseMagickOption(MagickVirtualPixelOptions,MagickFalse,
3494 argv[i+1]));
3495 break;
3496 }
3497 break;
3498 }
3499 case 'w':
3500 {
3501 if (LocaleCompare("wave",option+1) == 0)
3502 {
3503 Image
3504 *wave_image;
3505
3506 /*
3507 Wave image.
3508 */
cristy6b3da3a2010-06-20 02:21:46 +00003509 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003510 flags=ParseGeometry(argv[i+1],&geometry_info);
3511 if ((flags & SigmaValue) == 0)
3512 geometry_info.sigma=1.0;
3513 wave_image=WaveImage(*image,geometry_info.rho,geometry_info.sigma,
3514 exception);
3515 if (wave_image == (Image *) NULL)
3516 break;
3517 *image=DestroyImage(*image);
3518 *image=wave_image;
3519 break;
3520 }
3521 if (LocaleCompare("weight",option+1) == 0)
3522 {
cristye27293e2009-12-18 02:53:20 +00003523 draw_info->weight=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00003524 if (LocaleCompare(argv[i+1],"all") == 0)
3525 draw_info->weight=0;
3526 if (LocaleCompare(argv[i+1],"bold") == 0)
3527 draw_info->weight=700;
3528 if (LocaleCompare(argv[i+1],"bolder") == 0)
3529 if (draw_info->weight <= 800)
3530 draw_info->weight+=100;
3531 if (LocaleCompare(argv[i+1],"lighter") == 0)
3532 if (draw_info->weight >= 100)
3533 draw_info->weight-=100;
3534 if (LocaleCompare(argv[i+1],"normal") == 0)
3535 draw_info->weight=400;
3536 break;
3537 }
3538 if (LocaleCompare("white-threshold",option+1) == 0)
3539 {
3540 /*
3541 White threshold image.
3542 */
cristy6b3da3a2010-06-20 02:21:46 +00003543 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003544 (void) WhiteThresholdImageChannel(*image,channel,argv[i+1],
3545 exception);
3546 InheritException(exception,&(*image)->exception);
3547 break;
3548 }
3549 break;
3550 }
3551 default:
3552 break;
3553 }
3554 i+=count;
3555 }
3556 if (region_image != (Image *) NULL)
3557 {
3558 /*
3559 Composite transformed region onto image.
3560 */
cristy6b3da3a2010-06-20 02:21:46 +00003561 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003562 (void) CompositeImage(region_image,(*image)->matte != MagickFalse ?
3563 OverCompositeOp : CopyCompositeOp,*image,region_geometry.x,
3564 region_geometry.y);
3565 InheritException(exception,&region_image->exception);
3566 *image=DestroyImage(*image);
3567 *image=region_image;
3568 }
3569 /*
3570 Free resources.
3571 */
3572 quantize_info=DestroyQuantizeInfo(quantize_info);
3573 draw_info=DestroyDrawInfo(draw_info);
cristy6b3da3a2010-06-20 02:21:46 +00003574 mogrify_info=DestroyImageInfo(mogrify_info);
3575 status=(*image)->exception.severity == UndefinedException ? MagickTrue :
3576 MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00003577 return(status);
3578}
3579
3580/*
3581%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3582% %
3583% %
3584% %
cristy5063d812010-10-19 16:28:10 +00003585+ M o g r i f y I m a g e C o m m a n d %
cristy3ed852e2009-09-05 21:47:34 +00003586% %
3587% %
3588% %
3589%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3590%
3591% MogrifyImageCommand() transforms an image or a sequence of images. These
3592% transforms include image scaling, image rotation, color reduction, and
3593% others. The transmogrified image overwrites the original image.
3594%
3595% The format of the MogrifyImageCommand method is:
3596%
3597% MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,int argc,
3598% const char **argv,char **metadata,ExceptionInfo *exception)
3599%
3600% A description of each parameter follows:
3601%
3602% o image_info: the image info.
3603%
3604% o argc: the number of elements in the argument vector.
3605%
3606% o argv: A text array containing the command line arguments.
3607%
3608% o metadata: any metadata is returned here.
3609%
3610% o exception: return any errors or warnings in this structure.
3611%
3612*/
3613
3614static MagickBooleanType MogrifyUsage(void)
3615{
3616 static const char
3617 *miscellaneous[]=
3618 {
3619 "-debug events display copious debugging information",
3620 "-help print program options",
3621 "-list type print a list of supported option arguments",
3622 "-log format format of debugging information",
3623 "-version print version information",
3624 (char *) NULL
3625 },
3626 *operators[]=
3627 {
3628 "-adaptive-blur geometry",
3629 " adaptively blur pixels; decrease effect near edges",
3630 "-adaptive-resize geometry",
3631 " adaptively resize image using 'mesh' interpolation",
3632 "-adaptive-sharpen geometry",
3633 " adaptively sharpen pixels; increase effect near edges",
3634 "-alpha option on, activate, off, deactivate, set, opaque, copy",
3635 " transparent, extract, background, or shape",
3636 "-annotate geometry text",
3637 " annotate the image with text",
3638 "-auto-gamma automagically adjust gamma level of image",
3639 "-auto-level automagically adjust color levels of image",
3640 "-auto-orient automagically orient (rotate) image",
3641 "-bench iterations measure performance",
3642 "-black-threshold value",
3643 " force all pixels below the threshold into black",
3644 "-blue-shift simulate a scene at nighttime in the moonlight",
3645 "-blur geometry reduce image noise and reduce detail levels",
3646 "-border geometry surround image with a border of color",
3647 "-bordercolor color border color",
cristya28d6b82010-01-11 20:03:47 +00003648 "-brightness-contrast geometry",
3649 " improve brightness / contrast of the image",
cristy3ed852e2009-09-05 21:47:34 +00003650 "-cdl filename color correct with a color decision list",
3651 "-charcoal radius simulate a charcoal drawing",
3652 "-chop geometry remove pixels from the image interior",
cristyecb0c6d2009-09-25 16:50:09 +00003653 "-clamp restrict pixel range from 0 to the quantum depth",
cristycee97112010-05-28 00:44:52 +00003654 "-clip clip along the first path from the 8BIM profile",
cristy3ed852e2009-09-05 21:47:34 +00003655 "-clip-mask filename associate a clip mask with the image",
cristycee97112010-05-28 00:44:52 +00003656 "-clip-path id clip along a named path from the 8BIM profile",
cristy3ed852e2009-09-05 21:47:34 +00003657 "-colorize value colorize the image with the fill color",
cristye6365592010-04-02 17:31:23 +00003658 "-color-matrix matrix apply color correction to the image",
cristy3ed852e2009-09-05 21:47:34 +00003659 "-contrast enhance or reduce the image contrast",
3660 "-contrast-stretch geometry",
3661 " improve contrast by `stretching' the intensity range",
3662 "-convolve coefficients",
3663 " apply a convolution kernel to the image",
3664 "-cycle amount cycle the image colormap",
3665 "-decipher filename convert cipher pixels to plain pixels",
3666 "-deskew threshold straighten an image",
3667 "-despeckle reduce the speckles within an image",
3668 "-distort method args",
3669 " distort images according to given method ad args",
3670 "-draw string annotate the image with a graphic primitive",
3671 "-edge radius apply a filter to detect edges in the image",
3672 "-encipher filename convert plain pixels to cipher pixels",
3673 "-emboss radius emboss an image",
3674 "-enhance apply a digital filter to enhance a noisy image",
3675 "-equalize perform histogram equalization to an image",
3676 "-evaluate operator value",
cristyd18ae7c2010-03-07 17:39:52 +00003677 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003678 "-extent geometry set the image size",
3679 "-extract geometry extract area from image",
3680 "-fft implements the discrete Fourier transform (DFT)",
3681 "-flip flip image vertically",
3682 "-floodfill geometry color",
3683 " floodfill the image with color",
3684 "-flop flop image horizontally",
3685 "-frame geometry surround image with an ornamental border",
cristyc2b730e2009-11-24 14:32:09 +00003686 "-function name parameters",
cristy3ed852e2009-09-05 21:47:34 +00003687 " apply function over image values",
3688 "-gamma value level of gamma correction",
3689 "-gaussian-blur geometry",
3690 " reduce image noise and reduce detail levels",
cristy901f09d2009-10-16 22:56:10 +00003691 "-geometry geometry preferred size or location of the image",
cristy3ed852e2009-09-05 21:47:34 +00003692 "-identify identify the format and characteristics of the image",
3693 "-ift implements the inverse discrete Fourier transform (DFT)",
3694 "-implode amount implode image pixels about the center",
3695 "-lat geometry local adaptive thresholding",
3696 "-layers method optimize, merge, or compare image layers",
3697 "-level value adjust the level of image contrast",
3698 "-level-colors color,color",
cristyee0f8d72009-09-19 00:58:29 +00003699 " level image with the given colors",
cristy3ed852e2009-09-05 21:47:34 +00003700 "-linear-stretch geometry",
3701 " improve contrast by `stretching with saturation'",
3702 "-liquid-rescale geometry",
3703 " rescale image with seam-carving",
3704 "-median radius apply a median filter to the image",
3705 "-modulate value vary the brightness, saturation, and hue",
3706 "-monochrome transform image to black and white",
cristy7c1b9fd2010-02-02 14:36:00 +00003707 "-morphology method kernel",
anthony29188a82010-01-22 10:12:34 +00003708 " apply a morphology method to the image",
cristy3ed852e2009-09-05 21:47:34 +00003709 "-motion-blur geometry",
3710 " simulate motion blur",
3711 "-negate replace every pixel with its complementary color ",
3712 "-noise radius add or reduce noise in an image",
3713 "-normalize transform image to span the full range of colors",
3714 "-opaque color change this color to the fill color",
3715 "-ordered-dither NxN",
3716 " add a noise pattern to the image with specific",
3717 " amplitudes",
3718 "-paint radius simulate an oil painting",
3719 "-polaroid angle simulate a Polaroid picture",
3720 "-posterize levels reduce the image to a limited number of color levels",
cristy3ed852e2009-09-05 21:47:34 +00003721 "-profile filename add, delete, or apply an image profile",
3722 "-quantize colorspace reduce colors in this colorspace",
3723 "-radial-blur angle radial blur the image",
3724 "-raise value lighten/darken image edges to create a 3-D effect",
3725 "-random-threshold low,high",
3726 " random threshold the image",
cristy3ed852e2009-09-05 21:47:34 +00003727 "-region geometry apply options to a portion of the image",
3728 "-render render vector graphics",
3729 "-repage geometry size and location of an image canvas",
3730 "-resample geometry change the resolution of an image",
3731 "-resize geometry resize the image",
3732 "-roll geometry roll an image vertically or horizontally",
3733 "-rotate degrees apply Paeth rotation to the image",
3734 "-sample geometry scale image with pixel sampling",
3735 "-scale geometry scale the image",
3736 "-segment values segment an image",
3737 "-selective-blur geometry",
3738 " selectively blur pixels within a contrast threshold",
3739 "-sepia-tone threshold",
3740 " simulate a sepia-toned photo",
3741 "-set property value set an image property",
3742 "-shade degrees shade the image using a distant light source",
3743 "-shadow geometry simulate an image shadow",
3744 "-sharpen geometry sharpen the image",
3745 "-shave geometry shave pixels from the image edges",
cristycee97112010-05-28 00:44:52 +00003746 "-shear geometry slide one edge of the image along the X or Y axis",
cristy3ed852e2009-09-05 21:47:34 +00003747 "-sigmoidal-contrast geometry",
3748 " increase the contrast without saturating highlights or shadows",
3749 "-sketch geometry simulate a pencil sketch",
3750 "-solarize threshold negate all pixels above the threshold level",
3751 "-sparse-color method args",
3752 " fill in a image based on a few color points",
3753 "-splice geometry splice the background color into the image",
3754 "-spread radius displace image pixels by a random amount",
3755 "-strip strip image of all profiles and comments",
3756 "-swirl degrees swirl image pixels about the center",
3757 "-threshold value threshold the image",
3758 "-thumbnail geometry create a thumbnail of the image",
3759 "-tile filename tile image when filling a graphic primitive",
3760 "-tint value tint the image with the fill color",
3761 "-transform affine transform image",
3762 "-transparent color make this color transparent within the image",
3763 "-transpose flip image vertically and rotate 90 degrees",
3764 "-transverse flop image horizontally and rotate 270 degrees",
3765 "-trim trim image edges",
3766 "-type type image type",
3767 "-unique-colors discard all but one of any pixel color",
3768 "-unsharp geometry sharpen the image",
3769 "-vignette geometry soften the edges of the image in vignette style",
cristycee97112010-05-28 00:44:52 +00003770 "-wave geometry alter an image along a sine wave",
cristy3ed852e2009-09-05 21:47:34 +00003771 "-white-threshold value",
3772 " force all pixels above the threshold into white",
3773 (char *) NULL
3774 },
3775 *sequence_operators[]=
3776 {
cristyde5f6c62010-09-13 17:16:07 +00003777 "-append append an image sequence top to bottom",
cristy3ed852e2009-09-05 21:47:34 +00003778 "-clut apply a color lookup table to the image",
3779 "-coalesce merge a sequence of images",
3780 "-combine combine a sequence of images",
3781 "-composite composite image",
3782 "-crop geometry cut out a rectangular region of the image",
3783 "-deconstruct break down an image sequence into constituent parts",
cristyd18ae7c2010-03-07 17:39:52 +00003784 "-evaluate-sequence operator",
3785 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003786 "-flatten flatten a sequence of images",
3787 "-fx expression apply mathematical expression to an image channel(s)",
3788 "-hald-clut apply a Hald color lookup table to the image",
3789 "-morph value morph an image sequence",
3790 "-mosaic create a mosaic from an image sequence",
cristy36b94822010-05-20 12:48:16 +00003791 "-print string interpret string and print to console",
cristy3ed852e2009-09-05 21:47:34 +00003792 "-process arguments process the image with a custom image filter",
3793 "-reverse reverse image sequence",
3794 "-separate separate an image channel into a grayscale image",
3795 "-write filename write images to this file",
3796 (char *) NULL
3797 },
3798 *settings[]=
3799 {
3800 "-adjoin join images into a single multi-image file",
3801 "-affine matrix affine transform matrix",
3802 "-alpha option activate, deactivate, reset, or set the alpha channel",
3803 "-antialias remove pixel-aliasing",
3804 "-authenticate password",
3805 " decipher image with this password",
3806 "-attenuate value lessen (or intensify) when adding noise to an image",
3807 "-background color background color",
3808 "-bias value add bias when convolving an image",
3809 "-black-point-compensation",
3810 " use black point compensation",
3811 "-blue-primary point chromaticity blue primary point",
3812 "-bordercolor color border color",
3813 "-caption string assign a caption to an image",
3814 "-channel type apply option to select image channels",
3815 "-colors value preferred number of colors in the image",
3816 "-colorspace type alternate image colorspace",
3817 "-comment string annotate image with comment",
3818 "-compose operator set image composite operator",
3819 "-compress type type of pixel compression when writing the image",
3820 "-define format:option",
3821 " define one or more image format options",
3822 "-delay value display the next image after pausing",
3823 "-density geometry horizontal and vertical density of the image",
3824 "-depth value image depth",
cristyc9b12952010-03-28 01:12:28 +00003825 "-direction type render text right-to-left or left-to-right",
cristy3ed852e2009-09-05 21:47:34 +00003826 "-display server get image or font from this X server",
3827 "-dispose method layer disposal method",
3828 "-dither method apply error diffusion to image",
3829 "-encoding type text encoding type",
3830 "-endian type endianness (MSB or LSB) of the image",
3831 "-family name render text with this font family",
3832 "-fill color color to use when filling a graphic primitive",
3833 "-filter type use this filter when resizing an image",
3834 "-font name render text with this font",
3835 "-format \"string\" output formatted image characteristics",
3836 "-fuzz distance colors within this distance are considered equal",
3837 "-gravity type horizontal and vertical text placement",
3838 "-green-primary point chromaticity green primary point",
3839 "-intent type type of rendering intent when managing the image color",
3840 "-interlace type type of image interlacing scheme",
cristyb32b90a2009-09-07 21:45:48 +00003841 "-interline-spacing value",
3842 " set the space between two text lines",
cristy3ed852e2009-09-05 21:47:34 +00003843 "-interpolate method pixel color interpolation method",
3844 "-interword-spacing value",
3845 " set the space between two words",
3846 "-kerning value set the space between two letters",
3847 "-label string assign a label to an image",
3848 "-limit type value pixel cache resource limit",
3849 "-loop iterations add Netscape loop extension to your GIF animation",
3850 "-mask filename associate a mask with the image",
3851 "-mattecolor color frame color",
3852 "-monitor monitor progress",
3853 "-orient type image orientation",
3854 "-page geometry size and location of an image canvas (setting)",
3855 "-ping efficiently determine image attributes",
3856 "-pointsize value font point size",
cristy7c1b9fd2010-02-02 14:36:00 +00003857 "-precision value maximum number of significant digits to print",
cristy3ed852e2009-09-05 21:47:34 +00003858 "-preview type image preview type",
3859 "-quality value JPEG/MIFF/PNG compression level",
3860 "-quiet suppress all warning messages",
3861 "-red-primary point chromaticity red primary point",
3862 "-regard-warnings pay attention to warning messages",
3863 "-remap filename transform image colors to match this set of colors",
3864 "-respect-parentheses settings remain in effect until parenthesis boundary",
3865 "-sampling-factor geometry",
3866 " horizontal and vertical sampling factor",
3867 "-scene value image scene number",
3868 "-seed value seed a new sequence of pseudo-random numbers",
3869 "-size geometry width and height of image",
3870 "-stretch type render text with this font stretch",
3871 "-stroke color graphic primitive stroke color",
3872 "-strokewidth value graphic primitive stroke width",
3873 "-style type render text with this font style",
cristyd9a29192010-10-16 16:49:53 +00003874 "-synchronize synchronize image to storage device",
3875 "-taint declare the image as modified",
cristy3ed852e2009-09-05 21:47:34 +00003876 "-texture filename name of texture to tile onto the image background",
3877 "-tile-offset geometry",
3878 " tile offset",
3879 "-treedepth value color tree depth",
3880 "-transparent-color color",
3881 " transparent color",
3882 "-undercolor color annotation bounding box color",
3883 "-units type the units of image resolution",
3884 "-verbose print detailed information about the image",
3885 "-view FlashPix viewing transforms",
3886 "-virtual-pixel method",
3887 " virtual pixel access method",
3888 "-weight type render text with this font weight",
3889 "-white-point point chromaticity white point",
3890 (char *) NULL
3891 },
3892 *stack_operators[]=
3893 {
3894 "-clone index clone an image",
3895 "-delete index delete the image from the image sequence",
3896 "-insert index insert last image into the image sequence",
3897 "-swap indexes swap two images in the image sequence",
3898 (char *) NULL
3899 };
3900
3901 const char
3902 **p;
3903
cristybb503372010-05-27 20:51:26 +00003904 (void) printf("Version: %s\n",GetMagickVersion((size_t *) NULL));
cristy610b2e22009-10-22 14:59:43 +00003905 (void) printf("Copyright: %s\n",GetMagickCopyright());
3906 (void) printf("Features: %s\n\n",GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00003907 (void) printf("Usage: %s [options ...] file [ [options ...] file ...]\n",
3908 GetClientName());
3909 (void) printf("\nImage Settings:\n");
3910 for (p=settings; *p != (char *) NULL; p++)
3911 (void) printf(" %s\n",*p);
3912 (void) printf("\nImage Operators:\n");
3913 for (p=operators; *p != (char *) NULL; p++)
3914 (void) printf(" %s\n",*p);
3915 (void) printf("\nImage Sequence Operators:\n");
3916 for (p=sequence_operators; *p != (char *) NULL; p++)
3917 (void) printf(" %s\n",*p);
3918 (void) printf("\nImage Stack Operators:\n");
3919 for (p=stack_operators; *p != (char *) NULL; p++)
3920 (void) printf(" %s\n",*p);
3921 (void) printf("\nMiscellaneous Options:\n");
3922 for (p=miscellaneous; *p != (char *) NULL; p++)
3923 (void) printf(" %s\n",*p);
3924 (void) printf(
3925 "\nBy default, the image format of `file' is determined by its magic\n");
3926 (void) printf(
3927 "number. To specify a particular image format, precede the filename\n");
3928 (void) printf(
3929 "with an image format name and a colon (i.e. ps:image) or specify the\n");
3930 (void) printf(
3931 "image type as the filename suffix (i.e. image.ps). Specify 'file' as\n");
3932 (void) printf("'-' for standard input or output.\n");
3933 return(MagickFalse);
3934}
3935
3936WandExport MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,
3937 int argc,char **argv,char **wand_unused(metadata),ExceptionInfo *exception)
3938{
3939#define DestroyMogrify() \
3940{ \
3941 if (format != (char *) NULL) \
3942 format=DestroyString(format); \
3943 if (path != (char *) NULL) \
3944 path=DestroyString(path); \
3945 DestroyImageStack(); \
cristybb503372010-05-27 20:51:26 +00003946 for (i=0; i < (ssize_t) argc; i++) \
cristy3ed852e2009-09-05 21:47:34 +00003947 argv[i]=DestroyString(argv[i]); \
3948 argv=(char **) RelinquishMagickMemory(argv); \
3949}
3950#define ThrowMogrifyException(asperity,tag,option) \
3951{ \
3952 (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag,"`%s'", \
3953 option); \
3954 DestroyMogrify(); \
3955 return(MagickFalse); \
3956}
3957#define ThrowMogrifyInvalidArgumentException(option,argument) \
3958{ \
3959 (void) ThrowMagickException(exception,GetMagickModule(),OptionError, \
3960 "InvalidArgument","`%s': %s",argument,option); \
3961 DestroyMogrify(); \
3962 return(MagickFalse); \
3963}
3964
3965 char
3966 *format,
3967 *option,
3968 *path;
3969
3970 Image
3971 *image;
3972
3973 ImageStack
3974 image_stack[MaxImageStackDepth+1];
3975
cristybb503372010-05-27 20:51:26 +00003976 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003977 j,
3978 k;
3979
cristybb503372010-05-27 20:51:26 +00003980 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003981 i;
3982
3983 MagickBooleanType
3984 global_colormap;
3985
3986 MagickBooleanType
3987 fire,
3988 pend;
3989
3990 MagickStatusType
3991 status;
3992
3993 /*
3994 Set defaults.
3995 */
3996 assert(image_info != (ImageInfo *) NULL);
3997 assert(image_info->signature == MagickSignature);
3998 if (image_info->debug != MagickFalse)
3999 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
4000 assert(exception != (ExceptionInfo *) NULL);
4001 if (argc == 2)
4002 {
4003 option=argv[1];
4004 if ((LocaleCompare("version",option+1) == 0) ||
4005 (LocaleCompare("-version",option+1) == 0))
4006 {
4007 (void) fprintf(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +00004008 GetMagickVersion((size_t *) NULL));
cristy610b2e22009-10-22 14:59:43 +00004009 (void) fprintf(stdout,"Copyright: %s\n",GetMagickCopyright());
4010 (void) fprintf(stdout,"Features: %s\n\n",GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00004011 return(MagickFalse);
4012 }
4013 }
4014 if (argc < 2)
cristy13e61a12010-02-04 20:19:00 +00004015 return(MogrifyUsage());
cristy3ed852e2009-09-05 21:47:34 +00004016 format=(char *) NULL;
4017 path=(char *) NULL;
4018 global_colormap=MagickFalse;
4019 k=0;
4020 j=1;
4021 NewImageStack();
4022 option=(char *) NULL;
4023 pend=MagickFalse;
4024 status=MagickTrue;
4025 /*
4026 Parse command line.
4027 */
4028 ReadCommandlLine(argc,&argv);
4029 status=ExpandFilenames(&argc,&argv);
4030 if (status == MagickFalse)
4031 ThrowMogrifyException(ResourceLimitError,"MemoryAllocationFailed",
4032 GetExceptionMessage(errno));
cristybb503372010-05-27 20:51:26 +00004033 for (i=1; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00004034 {
4035 option=argv[i];
4036 if (LocaleCompare(option,"(") == 0)
4037 {
4038 FireImageStack(MagickFalse,MagickTrue,pend);
4039 if (k == MaxImageStackDepth)
4040 ThrowMogrifyException(OptionError,"ParenthesisNestedTooDeeply",
4041 option);
4042 PushImageStack();
4043 continue;
4044 }
4045 if (LocaleCompare(option,")") == 0)
4046 {
4047 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
4048 if (k == 0)
4049 ThrowMogrifyException(OptionError,"UnableToParseExpression",option);
4050 PopImageStack();
4051 continue;
4052 }
4053 if (IsMagickOption(option) == MagickFalse)
4054 {
4055 char
4056 backup_filename[MaxTextExtent],
4057 *filename;
4058
4059 Image
4060 *images;
4061
4062 /*
4063 Option is a file name: begin by reading image from specified file.
4064 */
4065 FireImageStack(MagickFalse,MagickFalse,pend);
4066 filename=argv[i];
cristycee97112010-05-28 00:44:52 +00004067 if ((LocaleCompare(filename,"--") == 0) && (i < (ssize_t) (argc-1)))
cristy3ed852e2009-09-05 21:47:34 +00004068 filename=argv[++i];
4069 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
4070 images=ReadImages(image_info,exception);
4071 status&=(images != (Image *) NULL) &&
4072 (exception->severity < ErrorException);
4073 if (images == (Image *) NULL)
4074 continue;
cristydaa76602010-06-30 13:05:11 +00004075 if (format != (char *) NULL)
4076 (void) CopyMagickString(images->filename,images->magick_filename,
4077 MaxTextExtent);
cristy3ed852e2009-09-05 21:47:34 +00004078 if (path != (char *) NULL)
4079 {
4080 GetPathComponent(option,TailPath,filename);
4081 (void) FormatMagickString(images->filename,MaxTextExtent,"%s%c%s",
4082 path,*DirectorySeparator,filename);
4083 }
4084 if (format != (char *) NULL)
cristydaa76602010-06-30 13:05:11 +00004085 AppendImageFormat(format,images->filename);
cristy3ed852e2009-09-05 21:47:34 +00004086 AppendImageStack(images);
4087 FinalizeImageSettings(image_info,image,MagickFalse);
4088 if (global_colormap != MagickFalse)
4089 {
4090 QuantizeInfo
4091 *quantize_info;
4092
4093 quantize_info=AcquireQuantizeInfo(image_info);
4094 (void) RemapImages(quantize_info,images,(Image *) NULL);
4095 quantize_info=DestroyQuantizeInfo(quantize_info);
4096 }
4097 *backup_filename='\0';
4098 if ((LocaleCompare(image->filename,"-") != 0) &&
4099 (IsPathWritable(image->filename) != MagickFalse))
4100 {
cristybb503372010-05-27 20:51:26 +00004101 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004102 i;
4103
4104 /*
4105 Rename image file as backup.
4106 */
4107 (void) CopyMagickString(backup_filename,image->filename,
4108 MaxTextExtent);
4109 for (i=0; i < 6; i++)
4110 {
4111 (void) ConcatenateMagickString(backup_filename,"~",MaxTextExtent);
4112 if (IsPathAccessible(backup_filename) == MagickFalse)
4113 break;
4114 }
4115 if ((IsPathAccessible(backup_filename) != MagickFalse) ||
4116 (rename(image->filename,backup_filename) != 0))
4117 *backup_filename='\0';
4118 }
4119 /*
4120 Write transmogrified image to disk.
4121 */
4122 image_info->synchronize=MagickTrue;
4123 status&=WriteImages(image_info,image,image->filename,exception);
4124 if ((status == MagickFalse) && (*backup_filename != '\0'))
4125 (void) remove(backup_filename);
4126 RemoveAllImageStack();
4127 continue;
4128 }
4129 pend=image != (Image *) NULL ? MagickTrue : MagickFalse;
4130 switch (*(option+1))
4131 {
4132 case 'a':
4133 {
4134 if (LocaleCompare("adaptive-blur",option+1) == 0)
4135 {
4136 i++;
cristybb503372010-05-27 20:51:26 +00004137 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004138 ThrowMogrifyException(OptionError,"MissingArgument",option);
4139 if (IsGeometry(argv[i]) == MagickFalse)
4140 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4141 break;
4142 }
4143 if (LocaleCompare("adaptive-resize",option+1) == 0)
4144 {
4145 i++;
cristybb503372010-05-27 20:51:26 +00004146 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004147 ThrowMogrifyException(OptionError,"MissingArgument",option);
4148 if (IsGeometry(argv[i]) == MagickFalse)
4149 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4150 break;
4151 }
4152 if (LocaleCompare("adaptive-sharpen",option+1) == 0)
4153 {
4154 i++;
cristybb503372010-05-27 20:51:26 +00004155 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004156 ThrowMogrifyException(OptionError,"MissingArgument",option);
4157 if (IsGeometry(argv[i]) == MagickFalse)
4158 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4159 break;
4160 }
4161 if (LocaleCompare("affine",option+1) == 0)
4162 {
4163 if (*option == '+')
4164 break;
4165 i++;
cristybb503372010-05-27 20:51:26 +00004166 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004167 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy3ed852e2009-09-05 21:47:34 +00004168 break;
4169 }
4170 if (LocaleCompare("alpha",option+1) == 0)
4171 {
cristybb503372010-05-27 20:51:26 +00004172 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004173 type;
4174
4175 if (*option == '+')
4176 break;
4177 i++;
cristybb503372010-05-27 20:51:26 +00004178 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004179 ThrowMogrifyException(OptionError,"MissingArgument",option);
4180 type=ParseMagickOption(MagickAlphaOptions,MagickFalse,argv[i]);
4181 if (type < 0)
4182 ThrowMogrifyException(OptionError,"UnrecognizedAlphaChannelType",
4183 argv[i]);
4184 break;
4185 }
4186 if (LocaleCompare("annotate",option+1) == 0)
4187 {
4188 if (*option == '+')
4189 break;
4190 i++;
cristybb503372010-05-27 20:51:26 +00004191 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004192 ThrowMogrifyException(OptionError,"MissingArgument",option);
4193 if (IsGeometry(argv[i]) == MagickFalse)
4194 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristybb503372010-05-27 20:51:26 +00004195 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004196 ThrowMogrifyException(OptionError,"MissingArgument",option);
4197 i++;
4198 break;
4199 }
4200 if (LocaleCompare("antialias",option+1) == 0)
4201 break;
4202 if (LocaleCompare("append",option+1) == 0)
4203 break;
4204 if (LocaleCompare("attenuate",option+1) == 0)
4205 {
4206 if (*option == '+')
4207 break;
4208 i++;
cristybb503372010-05-27 20:51:26 +00004209 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004210 ThrowMogrifyException(OptionError,"MissingArgument",option);
4211 if (IsGeometry(argv[i]) == MagickFalse)
4212 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4213 break;
4214 }
4215 if (LocaleCompare("authenticate",option+1) == 0)
4216 {
4217 if (*option == '+')
4218 break;
4219 i++;
cristybb503372010-05-27 20:51:26 +00004220 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004221 ThrowMogrifyException(OptionError,"MissingArgument",option);
4222 break;
4223 }
4224 if (LocaleCompare("auto-gamma",option+1) == 0)
4225 break;
4226 if (LocaleCompare("auto-level",option+1) == 0)
4227 break;
4228 if (LocaleCompare("auto-orient",option+1) == 0)
4229 break;
4230 if (LocaleCompare("average",option+1) == 0)
4231 break;
4232 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4233 }
4234 case 'b':
4235 {
4236 if (LocaleCompare("background",option+1) == 0)
4237 {
4238 if (*option == '+')
4239 break;
4240 i++;
cristybb503372010-05-27 20:51:26 +00004241 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004242 ThrowMogrifyException(OptionError,"MissingArgument",option);
4243 break;
4244 }
4245 if (LocaleCompare("bias",option+1) == 0)
4246 {
4247 if (*option == '+')
4248 break;
4249 i++;
cristybb503372010-05-27 20:51:26 +00004250 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004251 ThrowMogrifyException(OptionError,"MissingArgument",option);
4252 if (IsGeometry(argv[i]) == MagickFalse)
4253 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4254 break;
4255 }
4256 if (LocaleCompare("black-point-compensation",option+1) == 0)
4257 break;
4258 if (LocaleCompare("black-threshold",option+1) == 0)
4259 {
4260 if (*option == '+')
4261 break;
4262 i++;
cristybb503372010-05-27 20:51:26 +00004263 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004264 ThrowMogrifyException(OptionError,"MissingArgument",option);
4265 if (IsGeometry(argv[i]) == MagickFalse)
4266 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4267 break;
4268 }
4269 if (LocaleCompare("blue-primary",option+1) == 0)
4270 {
4271 if (*option == '+')
4272 break;
4273 i++;
cristybb503372010-05-27 20:51:26 +00004274 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004275 ThrowMogrifyException(OptionError,"MissingArgument",option);
4276 if (IsGeometry(argv[i]) == MagickFalse)
4277 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4278 break;
4279 }
4280 if (LocaleCompare("blue-shift",option+1) == 0)
4281 {
4282 i++;
cristybb503372010-05-27 20:51:26 +00004283 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004284 ThrowMogrifyException(OptionError,"MissingArgument",option);
4285 if (IsGeometry(argv[i]) == MagickFalse)
4286 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4287 break;
4288 }
4289 if (LocaleCompare("blur",option+1) == 0)
4290 {
4291 i++;
cristybb503372010-05-27 20:51:26 +00004292 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004293 ThrowMogrifyException(OptionError,"MissingArgument",option);
4294 if (IsGeometry(argv[i]) == MagickFalse)
4295 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4296 break;
4297 }
4298 if (LocaleCompare("border",option+1) == 0)
4299 {
4300 if (*option == '+')
4301 break;
4302 i++;
cristybb503372010-05-27 20:51:26 +00004303 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004304 ThrowMogrifyException(OptionError,"MissingArgument",option);
4305 if (IsGeometry(argv[i]) == MagickFalse)
4306 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4307 break;
4308 }
4309 if (LocaleCompare("bordercolor",option+1) == 0)
4310 {
4311 if (*option == '+')
4312 break;
4313 i++;
cristybb503372010-05-27 20:51:26 +00004314 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004315 ThrowMogrifyException(OptionError,"MissingArgument",option);
4316 break;
4317 }
4318 if (LocaleCompare("box",option+1) == 0)
4319 {
4320 if (*option == '+')
4321 break;
4322 i++;
cristybb503372010-05-27 20:51:26 +00004323 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004324 ThrowMogrifyException(OptionError,"MissingArgument",option);
4325 break;
4326 }
cristya28d6b82010-01-11 20:03:47 +00004327 if (LocaleCompare("brightness-contrast",option+1) == 0)
4328 {
4329 i++;
cristybb503372010-05-27 20:51:26 +00004330 if (i == (ssize_t) argc)
cristya28d6b82010-01-11 20:03:47 +00004331 ThrowMogrifyException(OptionError,"MissingArgument",option);
4332 if (IsGeometry(argv[i]) == MagickFalse)
4333 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4334 break;
4335 }
cristy3ed852e2009-09-05 21:47:34 +00004336 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4337 }
4338 case 'c':
4339 {
4340 if (LocaleCompare("cache",option+1) == 0)
4341 {
4342 if (*option == '+')
4343 break;
4344 i++;
cristybb503372010-05-27 20:51:26 +00004345 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004346 ThrowMogrifyException(OptionError,"MissingArgument",option);
4347 if (IsGeometry(argv[i]) == MagickFalse)
4348 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4349 break;
4350 }
4351 if (LocaleCompare("caption",option+1) == 0)
4352 {
4353 if (*option == '+')
4354 break;
4355 i++;
cristybb503372010-05-27 20:51:26 +00004356 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004357 ThrowMogrifyException(OptionError,"MissingArgument",option);
4358 break;
4359 }
4360 if (LocaleCompare("channel",option+1) == 0)
4361 {
cristybb503372010-05-27 20:51:26 +00004362 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004363 channel;
4364
4365 if (*option == '+')
4366 break;
4367 i++;
cristybb503372010-05-27 20:51:26 +00004368 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004369 ThrowMogrifyException(OptionError,"MissingArgument",option);
4370 channel=ParseChannelOption(argv[i]);
4371 if (channel < 0)
4372 ThrowMogrifyException(OptionError,"UnrecognizedChannelType",
4373 argv[i]);
4374 break;
4375 }
4376 if (LocaleCompare("cdl",option+1) == 0)
4377 {
4378 if (*option == '+')
4379 break;
4380 i++;
cristybb503372010-05-27 20:51:26 +00004381 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004382 ThrowMogrifyException(OptionError,"MissingArgument",option);
4383 break;
4384 }
4385 if (LocaleCompare("charcoal",option+1) == 0)
4386 {
4387 if (*option == '+')
4388 break;
4389 i++;
cristybb503372010-05-27 20:51:26 +00004390 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004391 ThrowMogrifyException(OptionError,"MissingArgument",option);
4392 if (IsGeometry(argv[i]) == MagickFalse)
4393 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4394 break;
4395 }
4396 if (LocaleCompare("chop",option+1) == 0)
4397 {
4398 if (*option == '+')
4399 break;
4400 i++;
cristybb503372010-05-27 20:51:26 +00004401 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004402 ThrowMogrifyException(OptionError,"MissingArgument",option);
4403 if (IsGeometry(argv[i]) == MagickFalse)
4404 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4405 break;
4406 }
cristy1eb45dd2009-09-25 16:38:06 +00004407 if (LocaleCompare("clamp",option+1) == 0)
4408 break;
4409 if (LocaleCompare("clip",option+1) == 0)
4410 break;
cristy3ed852e2009-09-05 21:47:34 +00004411 if (LocaleCompare("clip-mask",option+1) == 0)
4412 {
4413 if (*option == '+')
4414 break;
4415 i++;
cristybb503372010-05-27 20:51:26 +00004416 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004417 ThrowMogrifyException(OptionError,"MissingArgument",option);
4418 break;
4419 }
4420 if (LocaleCompare("clut",option+1) == 0)
4421 break;
4422 if (LocaleCompare("coalesce",option+1) == 0)
4423 break;
4424 if (LocaleCompare("colorize",option+1) == 0)
4425 {
4426 if (*option == '+')
4427 break;
4428 i++;
cristybb503372010-05-27 20:51:26 +00004429 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004430 ThrowMogrifyException(OptionError,"MissingArgument",option);
4431 if (IsGeometry(argv[i]) == MagickFalse)
4432 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4433 break;
4434 }
cristye6365592010-04-02 17:31:23 +00004435 if (LocaleCompare("color-matrix",option+1) == 0)
4436 {
cristyb6bd4ad2010-08-08 01:12:27 +00004437 KernelInfo
4438 *kernel_info;
4439
cristye6365592010-04-02 17:31:23 +00004440 if (*option == '+')
4441 break;
4442 i++;
cristybb503372010-05-27 20:51:26 +00004443 if (i == (ssize_t) (argc-1))
cristye6365592010-04-02 17:31:23 +00004444 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00004445 kernel_info=AcquireKernelInfo(argv[i]);
4446 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00004447 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00004448 kernel_info=DestroyKernelInfo(kernel_info);
cristye6365592010-04-02 17:31:23 +00004449 break;
4450 }
cristy3ed852e2009-09-05 21:47:34 +00004451 if (LocaleCompare("colors",option+1) == 0)
4452 {
4453 if (*option == '+')
4454 break;
4455 i++;
cristybb503372010-05-27 20:51:26 +00004456 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004457 ThrowMogrifyException(OptionError,"MissingArgument",option);
4458 if (IsGeometry(argv[i]) == MagickFalse)
4459 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4460 break;
4461 }
4462 if (LocaleCompare("colorspace",option+1) == 0)
4463 {
cristybb503372010-05-27 20:51:26 +00004464 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004465 colorspace;
4466
4467 if (*option == '+')
4468 break;
4469 i++;
cristybb503372010-05-27 20:51:26 +00004470 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004471 ThrowMogrifyException(OptionError,"MissingArgument",option);
4472 colorspace=ParseMagickOption(MagickColorspaceOptions,MagickFalse,
4473 argv[i]);
4474 if (colorspace < 0)
4475 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
4476 argv[i]);
4477 break;
4478 }
4479 if (LocaleCompare("combine",option+1) == 0)
4480 break;
4481 if (LocaleCompare("comment",option+1) == 0)
4482 {
4483 if (*option == '+')
4484 break;
4485 i++;
cristybb503372010-05-27 20:51:26 +00004486 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004487 ThrowMogrifyException(OptionError,"MissingArgument",option);
4488 break;
4489 }
4490 if (LocaleCompare("composite",option+1) == 0)
4491 break;
4492 if (LocaleCompare("compress",option+1) == 0)
4493 {
cristybb503372010-05-27 20:51:26 +00004494 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004495 compress;
4496
4497 if (*option == '+')
4498 break;
4499 i++;
cristybb503372010-05-27 20:51:26 +00004500 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004501 ThrowMogrifyException(OptionError,"MissingArgument",option);
4502 compress=ParseMagickOption(MagickCompressOptions,MagickFalse,
4503 argv[i]);
4504 if (compress < 0)
4505 ThrowMogrifyException(OptionError,"UnrecognizedImageCompression",
4506 argv[i]);
4507 break;
4508 }
cristy22879752009-10-25 23:55:40 +00004509 if (LocaleCompare("concurrent",option+1) == 0)
4510 break;
cristy3ed852e2009-09-05 21:47:34 +00004511 if (LocaleCompare("contrast",option+1) == 0)
4512 break;
4513 if (LocaleCompare("contrast-stretch",option+1) == 0)
4514 {
4515 i++;
cristybb503372010-05-27 20:51:26 +00004516 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004517 ThrowMogrifyException(OptionError,"MissingArgument",option);
4518 if (IsGeometry(argv[i]) == MagickFalse)
4519 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4520 break;
4521 }
4522 if (LocaleCompare("convolve",option+1) == 0)
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)
cristyf4e8c912010-08-08 01:51:19 +00004534 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00004535 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)
cristyf4e8c912010-08-08 01:51:19 +00005427 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00005428 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 }
cristyd9a29192010-10-16 16:49:53 +00006071 if (LocaleCompare("synchronize",option+1) == 0)
6072 break;
cristy3ed852e2009-09-05 21:47:34 +00006073 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6074 }
6075 case 't':
6076 {
6077 if (LocaleCompare("taint",option+1) == 0)
6078 break;
6079 if (LocaleCompare("texture",option+1) == 0)
6080 {
6081 if (*option == '+')
6082 break;
6083 i++;
cristybb503372010-05-27 20:51:26 +00006084 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006085 ThrowMogrifyException(OptionError,"MissingArgument",option);
6086 break;
6087 }
6088 if (LocaleCompare("tile",option+1) == 0)
6089 {
6090 if (*option == '+')
6091 break;
6092 i++;
cristybb503372010-05-27 20:51:26 +00006093 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006094 ThrowMogrifyException(OptionError,"MissingArgument",option);
6095 break;
6096 }
6097 if (LocaleCompare("tile-offset",option+1) == 0)
6098 {
6099 if (*option == '+')
6100 break;
6101 i++;
cristybb503372010-05-27 20:51:26 +00006102 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006103 ThrowMogrifyException(OptionError,"MissingArgument",option);
6104 if (IsGeometry(argv[i]) == MagickFalse)
6105 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6106 break;
6107 }
6108 if (LocaleCompare("tint",option+1) == 0)
6109 {
6110 if (*option == '+')
6111 break;
6112 i++;
cristybb503372010-05-27 20:51:26 +00006113 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006114 ThrowMogrifyException(OptionError,"MissingArgument",option);
6115 if (IsGeometry(argv[i]) == MagickFalse)
6116 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6117 break;
6118 }
6119 if (LocaleCompare("transform",option+1) == 0)
6120 break;
6121 if (LocaleCompare("transpose",option+1) == 0)
6122 break;
6123 if (LocaleCompare("transverse",option+1) == 0)
6124 break;
6125 if (LocaleCompare("threshold",option+1) == 0)
6126 {
6127 if (*option == '+')
6128 break;
6129 i++;
cristybb503372010-05-27 20:51:26 +00006130 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006131 ThrowMogrifyException(OptionError,"MissingArgument",option);
6132 if (IsGeometry(argv[i]) == MagickFalse)
6133 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6134 break;
6135 }
6136 if (LocaleCompare("thumbnail",option+1) == 0)
6137 {
6138 if (*option == '+')
6139 break;
6140 i++;
cristybb503372010-05-27 20:51:26 +00006141 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006142 ThrowMogrifyException(OptionError,"MissingArgument",option);
6143 if (IsGeometry(argv[i]) == MagickFalse)
6144 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6145 break;
6146 }
6147 if (LocaleCompare("transparent",option+1) == 0)
6148 {
6149 i++;
cristybb503372010-05-27 20:51:26 +00006150 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006151 ThrowMogrifyException(OptionError,"MissingArgument",option);
6152 break;
6153 }
6154 if (LocaleCompare("transparent-color",option+1) == 0)
6155 {
6156 if (*option == '+')
6157 break;
6158 i++;
cristybb503372010-05-27 20:51:26 +00006159 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006160 ThrowMogrifyException(OptionError,"MissingArgument",option);
6161 break;
6162 }
6163 if (LocaleCompare("treedepth",option+1) == 0)
6164 {
6165 if (*option == '+')
6166 break;
6167 i++;
cristybb503372010-05-27 20:51:26 +00006168 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006169 ThrowMogrifyException(OptionError,"MissingArgument",option);
6170 if (IsGeometry(argv[i]) == MagickFalse)
6171 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6172 break;
6173 }
6174 if (LocaleCompare("trim",option+1) == 0)
6175 break;
6176 if (LocaleCompare("type",option+1) == 0)
6177 {
cristybb503372010-05-27 20:51:26 +00006178 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006179 type;
6180
6181 if (*option == '+')
6182 break;
6183 i++;
cristybb503372010-05-27 20:51:26 +00006184 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006185 ThrowMogrifyException(OptionError,"MissingArgument",option);
6186 type=ParseMagickOption(MagickTypeOptions,MagickFalse,argv[i]);
6187 if (type < 0)
6188 ThrowMogrifyException(OptionError,"UnrecognizedImageType",
6189 argv[i]);
6190 break;
6191 }
6192 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6193 }
6194 case 'u':
6195 {
6196 if (LocaleCompare("undercolor",option+1) == 0)
6197 {
6198 if (*option == '+')
6199 break;
6200 i++;
cristybb503372010-05-27 20:51:26 +00006201 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006202 ThrowMogrifyException(OptionError,"MissingArgument",option);
6203 break;
6204 }
6205 if (LocaleCompare("unique-colors",option+1) == 0)
6206 break;
6207 if (LocaleCompare("units",option+1) == 0)
6208 {
cristybb503372010-05-27 20:51:26 +00006209 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006210 units;
6211
6212 if (*option == '+')
6213 break;
6214 i++;
cristybb503372010-05-27 20:51:26 +00006215 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006216 ThrowMogrifyException(OptionError,"MissingArgument",option);
6217 units=ParseMagickOption(MagickResolutionOptions,MagickFalse,
6218 argv[i]);
6219 if (units < 0)
6220 ThrowMogrifyException(OptionError,"UnrecognizedUnitsType",
6221 argv[i]);
6222 break;
6223 }
6224 if (LocaleCompare("unsharp",option+1) == 0)
6225 {
6226 i++;
cristybb503372010-05-27 20:51:26 +00006227 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006228 ThrowMogrifyException(OptionError,"MissingArgument",option);
6229 if (IsGeometry(argv[i]) == MagickFalse)
6230 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6231 break;
6232 }
6233 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6234 }
6235 case 'v':
6236 {
6237 if (LocaleCompare("verbose",option+1) == 0)
6238 {
6239 image_info->verbose=(*option == '-') ? MagickTrue : MagickFalse;
6240 break;
6241 }
6242 if ((LocaleCompare("version",option+1) == 0) ||
6243 (LocaleCompare("-version",option+1) == 0))
6244 {
6245 (void) fprintf(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +00006246 GetMagickVersion((size_t *) NULL));
cristy610b2e22009-10-22 14:59:43 +00006247 (void) fprintf(stdout,"Copyright: %s\n",GetMagickCopyright());
6248 (void) fprintf(stdout,"Features: %s\n\n",GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00006249 break;
6250 }
6251 if (LocaleCompare("view",option+1) == 0)
6252 {
6253 if (*option == '+')
6254 break;
6255 i++;
cristybb503372010-05-27 20:51:26 +00006256 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006257 ThrowMogrifyException(OptionError,"MissingArgument",option);
6258 break;
6259 }
6260 if (LocaleCompare("vignette",option+1) == 0)
6261 {
6262 if (*option == '+')
6263 break;
6264 i++;
cristybb503372010-05-27 20:51:26 +00006265 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006266 ThrowMogrifyException(OptionError,"MissingArgument",option);
6267 if (IsGeometry(argv[i]) == MagickFalse)
6268 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6269 break;
6270 }
6271 if (LocaleCompare("virtual-pixel",option+1) == 0)
6272 {
cristybb503372010-05-27 20:51:26 +00006273 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006274 method;
6275
6276 if (*option == '+')
6277 break;
6278 i++;
cristybb503372010-05-27 20:51:26 +00006279 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006280 ThrowMogrifyException(OptionError,"MissingArgument",option);
6281 method=ParseMagickOption(MagickVirtualPixelOptions,MagickFalse,
6282 argv[i]);
6283 if (method < 0)
6284 ThrowMogrifyException(OptionError,
6285 "UnrecognizedVirtualPixelMethod",argv[i]);
6286 break;
6287 }
6288 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6289 }
6290 case 'w':
6291 {
6292 if (LocaleCompare("wave",option+1) == 0)
6293 {
6294 i++;
cristybb503372010-05-27 20:51:26 +00006295 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006296 ThrowMogrifyException(OptionError,"MissingArgument",option);
6297 if (IsGeometry(argv[i]) == MagickFalse)
6298 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6299 break;
6300 }
6301 if (LocaleCompare("weight",option+1) == 0)
6302 {
6303 if (*option == '+')
6304 break;
6305 i++;
cristybb503372010-05-27 20:51:26 +00006306 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006307 ThrowMogrifyException(OptionError,"MissingArgument",option);
6308 break;
6309 }
6310 if (LocaleCompare("white-point",option+1) == 0)
6311 {
6312 if (*option == '+')
6313 break;
6314 i++;
cristybb503372010-05-27 20:51:26 +00006315 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006316 ThrowMogrifyException(OptionError,"MissingArgument",option);
6317 if (IsGeometry(argv[i]) == MagickFalse)
6318 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6319 break;
6320 }
6321 if (LocaleCompare("white-threshold",option+1) == 0)
6322 {
6323 if (*option == '+')
6324 break;
6325 i++;
cristybb503372010-05-27 20:51:26 +00006326 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006327 ThrowMogrifyException(OptionError,"MissingArgument",option);
6328 if (IsGeometry(argv[i]) == MagickFalse)
6329 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6330 break;
6331 }
6332 if (LocaleCompare("write",option+1) == 0)
6333 {
6334 i++;
cristybb503372010-05-27 20:51:26 +00006335 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006336 ThrowMogrifyException(OptionError,"MissingArgument",option);
6337 break;
6338 }
6339 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6340 }
6341 case '?':
6342 break;
6343 default:
6344 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6345 }
6346 fire=ParseMagickOption(MagickImageListOptions,MagickFalse,option+1) < 0 ?
6347 MagickFalse : MagickTrue;
6348 if (fire != MagickFalse)
6349 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
6350 }
6351 if (k != 0)
6352 ThrowMogrifyException(OptionError,"UnbalancedParenthesis",argv[i]);
cristycee97112010-05-28 00:44:52 +00006353 if (i != (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006354 ThrowMogrifyException(OptionError,"MissingAnImageFilename",argv[i]);
6355 DestroyMogrify();
6356 return(status != 0 ? MagickTrue : MagickFalse);
6357}
6358
6359/*
6360%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6361% %
6362% %
6363% %
6364+ M o g r i f y I m a g e I n f o %
6365% %
6366% %
6367% %
6368%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6369%
6370% MogrifyImageInfo() applies image processing settings to the image as
6371% prescribed by command line options.
6372%
6373% The format of the MogrifyImageInfo method is:
6374%
6375% MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,const int argc,
6376% const char **argv,ExceptionInfo *exception)
6377%
6378% A description of each parameter follows:
6379%
6380% o image_info: the image info..
6381%
6382% o argc: Specifies a pointer to an integer describing the number of
6383% elements in the argument vector.
6384%
6385% o argv: Specifies a pointer to a text array containing the command line
6386% arguments.
6387%
6388% o exception: return any errors or warnings in this structure.
6389%
6390*/
6391WandExport MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,
6392 const int argc,const char **argv,ExceptionInfo *exception)
6393{
6394 const char
6395 *option;
6396
6397 GeometryInfo
6398 geometry_info;
6399
cristybb503372010-05-27 20:51:26 +00006400 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006401 count;
6402
cristybb503372010-05-27 20:51:26 +00006403 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006404 i;
6405
6406 /*
6407 Initialize method variables.
6408 */
6409 assert(image_info != (ImageInfo *) NULL);
6410 assert(image_info->signature == MagickSignature);
6411 if (image_info->debug != MagickFalse)
6412 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
6413 image_info->filename);
6414 if (argc < 0)
6415 return(MagickTrue);
6416 /*
6417 Set the image settings.
6418 */
cristybb503372010-05-27 20:51:26 +00006419 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00006420 {
6421 option=argv[i];
6422 if (IsMagickOption(option) == MagickFalse)
6423 continue;
6424 count=MagickMax(ParseMagickOption(MagickCommandOptions,MagickFalse,option),
6425 0L);
cristycee97112010-05-28 00:44:52 +00006426 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006427 break;
6428 switch (*(option+1))
6429 {
6430 case 'a':
6431 {
6432 if (LocaleCompare("adjoin",option+1) == 0)
6433 {
6434 image_info->adjoin=(*option == '-') ? MagickTrue : MagickFalse;
6435 break;
6436 }
6437 if (LocaleCompare("antialias",option+1) == 0)
6438 {
6439 image_info->antialias=(*option == '-') ? MagickTrue : MagickFalse;
6440 break;
6441 }
6442 if (LocaleCompare("attenuate",option+1) == 0)
6443 {
6444 if (*option == '+')
6445 {
6446 (void) DeleteImageOption(image_info,option+1);
6447 break;
6448 }
6449 (void) SetImageOption(image_info,option+1,argv[i+1]);
6450 break;
6451 }
6452 if (LocaleCompare("authenticate",option+1) == 0)
6453 {
6454 if (*option == '+')
6455 (void) CloneString(&image_info->authenticate,(char *) NULL);
6456 else
6457 (void) CloneString(&image_info->authenticate,argv[i+1]);
6458 break;
6459 }
6460 break;
6461 }
6462 case 'b':
6463 {
6464 if (LocaleCompare("background",option+1) == 0)
6465 {
6466 if (*option == '+')
6467 {
6468 (void) DeleteImageOption(image_info,option+1);
6469 (void) QueryColorDatabase(BackgroundColor,
6470 &image_info->background_color,exception);
6471 break;
6472 }
6473 (void) SetImageOption(image_info,option+1,argv[i+1]);
6474 (void) QueryColorDatabase(argv[i+1],&image_info->background_color,
6475 exception);
6476 break;
6477 }
6478 if (LocaleCompare("bias",option+1) == 0)
6479 {
6480 if (*option == '+')
6481 {
6482 (void) SetImageOption(image_info,option+1,"0.0");
6483 break;
6484 }
6485 (void) SetImageOption(image_info,option+1,argv[i+1]);
6486 break;
6487 }
6488 if (LocaleCompare("black-point-compensation",option+1) == 0)
6489 {
6490 if (*option == '+')
6491 {
6492 (void) SetImageOption(image_info,option+1,"false");
6493 break;
6494 }
6495 (void) SetImageOption(image_info,option+1,"true");
6496 break;
6497 }
6498 if (LocaleCompare("blue-primary",option+1) == 0)
6499 {
6500 if (*option == '+')
6501 {
6502 (void) SetImageOption(image_info,option+1,"0.0");
6503 break;
6504 }
6505 (void) SetImageOption(image_info,option+1,argv[i+1]);
6506 break;
6507 }
6508 if (LocaleCompare("bordercolor",option+1) == 0)
6509 {
6510 if (*option == '+')
6511 {
6512 (void) DeleteImageOption(image_info,option+1);
6513 (void) QueryColorDatabase(BorderColor,&image_info->border_color,
6514 exception);
6515 break;
6516 }
6517 (void) QueryColorDatabase(argv[i+1],&image_info->border_color,
6518 exception);
6519 (void) SetImageOption(image_info,option+1,argv[i+1]);
6520 break;
6521 }
6522 if (LocaleCompare("box",option+1) == 0)
6523 {
6524 if (*option == '+')
6525 {
6526 (void) SetImageOption(image_info,"undercolor","none");
6527 break;
6528 }
6529 (void) SetImageOption(image_info,"undercolor",argv[i+1]);
6530 break;
6531 }
6532 break;
6533 }
6534 case 'c':
6535 {
6536 if (LocaleCompare("cache",option+1) == 0)
6537 {
6538 MagickSizeType
6539 limit;
6540
6541 limit=MagickResourceInfinity;
6542 if (LocaleCompare("unlimited",argv[i+1]) != 0)
cristyf2f27272009-12-17 14:48:46 +00006543 limit=(MagickSizeType) SiPrefixToDouble(argv[i+1],100.0);
cristy3ed852e2009-09-05 21:47:34 +00006544 (void) SetMagickResourceLimit(MemoryResource,limit);
6545 (void) SetMagickResourceLimit(MapResource,2*limit);
6546 break;
6547 }
6548 if (LocaleCompare("caption",option+1) == 0)
6549 {
6550 if (*option == '+')
6551 {
6552 (void) DeleteImageOption(image_info,option+1);
6553 break;
6554 }
6555 (void) SetImageOption(image_info,option+1,argv[i+1]);
6556 break;
6557 }
6558 if (LocaleCompare("channel",option+1) == 0)
6559 {
6560 if (*option == '+')
6561 {
6562 image_info->channel=DefaultChannels;
6563 break;
6564 }
6565 image_info->channel=(ChannelType) ParseChannelOption(argv[i+1]);
6566 break;
6567 }
6568 if (LocaleCompare("colors",option+1) == 0)
6569 {
cristye27293e2009-12-18 02:53:20 +00006570 image_info->colors=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006571 break;
6572 }
6573 if (LocaleCompare("colorspace",option+1) == 0)
6574 {
6575 if (*option == '+')
6576 {
6577 image_info->colorspace=UndefinedColorspace;
6578 (void) SetImageOption(image_info,option+1,"undefined");
6579 break;
6580 }
6581 image_info->colorspace=(ColorspaceType) ParseMagickOption(
6582 MagickColorspaceOptions,MagickFalse,argv[i+1]);
6583 (void) SetImageOption(image_info,option+1,argv[i+1]);
6584 break;
6585 }
6586 if (LocaleCompare("compress",option+1) == 0)
6587 {
6588 if (*option == '+')
6589 {
6590 image_info->compression=UndefinedCompression;
6591 (void) SetImageOption(image_info,option+1,"undefined");
6592 break;
6593 }
6594 image_info->compression=(CompressionType) ParseMagickOption(
6595 MagickCompressOptions,MagickFalse,argv[i+1]);
6596 (void) SetImageOption(image_info,option+1,argv[i+1]);
6597 break;
6598 }
6599 if (LocaleCompare("comment",option+1) == 0)
6600 {
6601 if (*option == '+')
6602 {
6603 (void) DeleteImageOption(image_info,option+1);
6604 break;
6605 }
6606 (void) SetImageOption(image_info,option+1,argv[i+1]);
6607 break;
6608 }
6609 if (LocaleCompare("compose",option+1) == 0)
6610 {
6611 if (*option == '+')
6612 {
6613 (void) SetImageOption(image_info,option+1,"undefined");
6614 break;
6615 }
6616 (void) SetImageOption(image_info,option+1,argv[i+1]);
6617 break;
6618 }
6619 if (LocaleCompare("compress",option+1) == 0)
6620 {
6621 if (*option == '+')
6622 {
6623 image_info->compression=UndefinedCompression;
6624 (void) SetImageOption(image_info,option+1,"undefined");
6625 break;
6626 }
6627 image_info->compression=(CompressionType) ParseMagickOption(
6628 MagickCompressOptions,MagickFalse,argv[i+1]);
6629 (void) SetImageOption(image_info,option+1,argv[i+1]);
6630 break;
6631 }
6632 break;
6633 }
6634 case 'd':
6635 {
6636 if (LocaleCompare("debug",option+1) == 0)
6637 {
6638 if (*option == '+')
6639 (void) SetLogEventMask("none");
6640 else
6641 (void) SetLogEventMask(argv[i+1]);
6642 image_info->debug=IsEventLogging();
6643 break;
6644 }
6645 if (LocaleCompare("define",option+1) == 0)
6646 {
6647 if (*option == '+')
6648 {
6649 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6650 (void) DeleteImageRegistry(argv[i+1]+9);
6651 else
6652 (void) DeleteImageOption(image_info,argv[i+1]);
6653 break;
6654 }
6655 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6656 {
6657 (void) DefineImageRegistry(StringRegistryType,argv[i+1]+9,
6658 exception);
6659 break;
6660 }
6661 (void) DefineImageOption(image_info,argv[i+1]);
6662 break;
6663 }
6664 if (LocaleCompare("delay",option+1) == 0)
6665 {
6666 if (*option == '+')
6667 {
6668 (void) SetImageOption(image_info,option+1,"0");
6669 break;
6670 }
6671 (void) SetImageOption(image_info,option+1,argv[i+1]);
6672 break;
6673 }
6674 if (LocaleCompare("density",option+1) == 0)
6675 {
6676 /*
6677 Set image density.
6678 */
6679 if (*option == '+')
6680 {
6681 if (image_info->density != (char *) NULL)
6682 image_info->density=DestroyString(image_info->density);
6683 (void) SetImageOption(image_info,option+1,"72");
6684 break;
6685 }
6686 (void) CloneString(&image_info->density,argv[i+1]);
6687 (void) SetImageOption(image_info,option+1,argv[i+1]);
6688 break;
6689 }
6690 if (LocaleCompare("depth",option+1) == 0)
6691 {
6692 if (*option == '+')
6693 {
6694 image_info->depth=MAGICKCORE_QUANTUM_DEPTH;
6695 break;
6696 }
cristye27293e2009-12-18 02:53:20 +00006697 image_info->depth=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006698 break;
6699 }
cristyc9b12952010-03-28 01:12:28 +00006700 if (LocaleCompare("direction",option+1) == 0)
6701 {
6702 if (*option == '+')
6703 {
6704 (void) SetImageOption(image_info,option+1,"undefined");
6705 break;
6706 }
6707 (void) SetImageOption(image_info,option+1,argv[i+1]);
6708 break;
6709 }
cristy3ed852e2009-09-05 21:47:34 +00006710 if (LocaleCompare("display",option+1) == 0)
6711 {
6712 if (*option == '+')
6713 {
6714 if (image_info->server_name != (char *) NULL)
6715 image_info->server_name=DestroyString(
6716 image_info->server_name);
6717 break;
6718 }
6719 (void) CloneString(&image_info->server_name,argv[i+1]);
6720 break;
6721 }
6722 if (LocaleCompare("dispose",option+1) == 0)
6723 {
6724 if (*option == '+')
6725 {
6726 (void) SetImageOption(image_info,option+1,"undefined");
6727 break;
6728 }
6729 (void) SetImageOption(image_info,option+1,argv[i+1]);
6730 break;
6731 }
6732 if (LocaleCompare("dither",option+1) == 0)
6733 {
6734 if (*option == '+')
6735 {
6736 image_info->dither=MagickFalse;
cristyd5acfd12010-06-15 00:11:38 +00006737 (void) SetImageOption(image_info,option+1,"none");
cristy3ed852e2009-09-05 21:47:34 +00006738 break;
6739 }
6740 (void) SetImageOption(image_info,option+1,argv[i+1]);
6741 image_info->dither=MagickTrue;
6742 break;
6743 }
6744 break;
6745 }
6746 case 'e':
6747 {
6748 if (LocaleCompare("encoding",option+1) == 0)
6749 {
6750 if (*option == '+')
6751 {
6752 (void) SetImageOption(image_info,option+1,"undefined");
6753 break;
6754 }
6755 (void) SetImageOption(image_info,option+1,argv[i+1]);
6756 break;
6757 }
6758 if (LocaleCompare("endian",option+1) == 0)
6759 {
6760 if (*option == '+')
6761 {
6762 image_info->endian=UndefinedEndian;
6763 (void) SetImageOption(image_info,option+1,"undefined");
6764 break;
6765 }
6766 image_info->endian=(EndianType) ParseMagickOption(
6767 MagickEndianOptions,MagickFalse,argv[i+1]);
6768 (void) SetImageOption(image_info,option+1,argv[i+1]);
6769 break;
6770 }
6771 if (LocaleCompare("extract",option+1) == 0)
6772 {
6773 /*
6774 Set image extract geometry.
6775 */
6776 if (*option == '+')
6777 {
6778 if (image_info->extract != (char *) NULL)
6779 image_info->extract=DestroyString(image_info->extract);
6780 break;
6781 }
6782 (void) CloneString(&image_info->extract,argv[i+1]);
6783 break;
6784 }
6785 break;
6786 }
6787 case 'f':
6788 {
6789 if (LocaleCompare("fill",option+1) == 0)
6790 {
6791 if (*option == '+')
6792 {
6793 (void) SetImageOption(image_info,option+1,"none");
6794 break;
6795 }
6796 (void) SetImageOption(image_info,option+1,argv[i+1]);
6797 break;
6798 }
6799 if (LocaleCompare("filter",option+1) == 0)
6800 {
6801 if (*option == '+')
6802 {
6803 (void) SetImageOption(image_info,option+1,"undefined");
6804 break;
6805 }
6806 (void) SetImageOption(image_info,option+1,argv[i+1]);
6807 break;
6808 }
6809 if (LocaleCompare("font",option+1) == 0)
6810 {
6811 if (*option == '+')
6812 {
6813 if (image_info->font != (char *) NULL)
6814 image_info->font=DestroyString(image_info->font);
6815 break;
6816 }
6817 (void) CloneString(&image_info->font,argv[i+1]);
6818 break;
6819 }
6820 if (LocaleCompare("format",option+1) == 0)
6821 {
6822 register const char
6823 *q;
6824
6825 for (q=strchr(argv[i+1],'%'); q != (char *) NULL; q=strchr(q+1,'%'))
6826 if (strchr("gkrz@[#",*(q+1)) != (char *) NULL)
6827 image_info->ping=MagickFalse;
6828 (void) SetImageOption(image_info,option+1,argv[i+1]);
6829 break;
6830 }
6831 if (LocaleCompare("fuzz",option+1) == 0)
6832 {
6833 if (*option == '+')
6834 {
6835 image_info->fuzz=0.0;
6836 (void) SetImageOption(image_info,option+1,"0");
6837 break;
6838 }
cristyf2f27272009-12-17 14:48:46 +00006839 image_info->fuzz=SiPrefixToDouble(argv[i+1],(double) QuantumRange+
cristy3ed852e2009-09-05 21:47:34 +00006840 1.0);
6841 (void) SetImageOption(image_info,option+1,argv[i+1]);
6842 break;
6843 }
6844 break;
6845 }
6846 case 'g':
6847 {
6848 if (LocaleCompare("gravity",option+1) == 0)
6849 {
6850 if (*option == '+')
6851 {
6852 (void) SetImageOption(image_info,option+1,"undefined");
6853 break;
6854 }
6855 (void) SetImageOption(image_info,option+1,argv[i+1]);
6856 break;
6857 }
6858 if (LocaleCompare("green-primary",option+1) == 0)
6859 {
6860 if (*option == '+')
6861 {
6862 (void) SetImageOption(image_info,option+1,"0.0");
6863 break;
6864 }
6865 (void) SetImageOption(image_info,option+1,argv[i+1]);
6866 break;
6867 }
6868 break;
6869 }
6870 case 'i':
6871 {
6872 if (LocaleCompare("intent",option+1) == 0)
6873 {
6874 if (*option == '+')
6875 {
6876 (void) SetImageOption(image_info,option+1,"undefined");
6877 break;
6878 }
6879 (void) SetImageOption(image_info,option+1,argv[i+1]);
6880 break;
6881 }
6882 if (LocaleCompare("interlace",option+1) == 0)
6883 {
6884 if (*option == '+')
6885 {
6886 image_info->interlace=UndefinedInterlace;
6887 (void) SetImageOption(image_info,option+1,"undefined");
6888 break;
6889 }
6890 image_info->interlace=(InterlaceType) ParseMagickOption(
6891 MagickInterlaceOptions,MagickFalse,argv[i+1]);
6892 (void) SetImageOption(image_info,option+1,argv[i+1]);
6893 break;
6894 }
cristyb32b90a2009-09-07 21:45:48 +00006895 if (LocaleCompare("interline-spacing",option+1) == 0)
6896 {
6897 if (*option == '+')
6898 {
6899 (void) SetImageOption(image_info,option+1,"undefined");
6900 break;
6901 }
6902 (void) SetImageOption(image_info,option+1,argv[i+1]);
6903 break;
6904 }
cristy3ed852e2009-09-05 21:47:34 +00006905 if (LocaleCompare("interpolate",option+1) == 0)
6906 {
6907 if (*option == '+')
6908 {
6909 (void) SetImageOption(image_info,option+1,"undefined");
6910 break;
6911 }
6912 (void) SetImageOption(image_info,option+1,argv[i+1]);
6913 break;
6914 }
6915 if (LocaleCompare("interword-spacing",option+1) == 0)
6916 {
6917 if (*option == '+')
6918 {
6919 (void) SetImageOption(image_info,option+1,"undefined");
6920 break;
6921 }
6922 (void) SetImageOption(image_info,option+1,argv[i+1]);
6923 break;
6924 }
6925 break;
6926 }
6927 case 'k':
6928 {
6929 if (LocaleCompare("kerning",option+1) == 0)
6930 {
6931 if (*option == '+')
6932 {
6933 (void) SetImageOption(image_info,option+1,"undefined");
6934 break;
6935 }
6936 (void) SetImageOption(image_info,option+1,argv[i+1]);
6937 break;
6938 }
6939 break;
6940 }
6941 case 'l':
6942 {
6943 if (LocaleCompare("label",option+1) == 0)
6944 {
6945 if (*option == '+')
6946 {
6947 (void) DeleteImageOption(image_info,option+1);
6948 break;
6949 }
6950 (void) SetImageOption(image_info,option+1,argv[i+1]);
6951 break;
6952 }
6953 if (LocaleCompare("limit",option+1) == 0)
6954 {
6955 MagickSizeType
6956 limit;
6957
6958 ResourceType
6959 type;
6960
6961 if (*option == '+')
6962 break;
6963 type=(ResourceType) ParseMagickOption(MagickResourceOptions,
6964 MagickFalse,argv[i+1]);
6965 limit=MagickResourceInfinity;
6966 if (LocaleCompare("unlimited",argv[i+2]) != 0)
cristyf2f27272009-12-17 14:48:46 +00006967 limit=(MagickSizeType) SiPrefixToDouble(argv[i+2],100.0);
cristy3ed852e2009-09-05 21:47:34 +00006968 (void) SetMagickResourceLimit(type,limit);
6969 break;
6970 }
6971 if (LocaleCompare("list",option+1) == 0)
6972 {
cristybb503372010-05-27 20:51:26 +00006973 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006974 list;
6975
6976 /*
6977 Display configuration list.
6978 */
6979 list=ParseMagickOption(MagickListOptions,MagickFalse,argv[i+1]);
6980 switch (list)
6981 {
6982 case MagickCoderOptions:
6983 {
6984 (void) ListCoderInfo((FILE *) NULL,exception);
6985 break;
6986 }
6987 case MagickColorOptions:
6988 {
6989 (void) ListColorInfo((FILE *) NULL,exception);
6990 break;
6991 }
6992 case MagickConfigureOptions:
6993 {
6994 (void) ListConfigureInfo((FILE *) NULL,exception);
6995 break;
6996 }
6997 case MagickDelegateOptions:
6998 {
6999 (void) ListDelegateInfo((FILE *) NULL,exception);
7000 break;
7001 }
7002 case MagickFontOptions:
7003 {
7004 (void) ListTypeInfo((FILE *) NULL,exception);
7005 break;
7006 }
7007 case MagickFormatOptions:
7008 {
7009 (void) ListMagickInfo((FILE *) NULL,exception);
7010 break;
7011 }
7012 case MagickLocaleOptions:
7013 {
7014 (void) ListLocaleInfo((FILE *) NULL,exception);
7015 break;
7016 }
7017 case MagickLogOptions:
7018 {
7019 (void) ListLogInfo((FILE *) NULL,exception);
7020 break;
7021 }
7022 case MagickMagicOptions:
7023 {
7024 (void) ListMagicInfo((FILE *) NULL,exception);
7025 break;
7026 }
7027 case MagickMimeOptions:
7028 {
7029 (void) ListMimeInfo((FILE *) NULL,exception);
7030 break;
7031 }
7032 case MagickModuleOptions:
7033 {
7034 (void) ListModuleInfo((FILE *) NULL,exception);
7035 break;
7036 }
7037 case MagickPolicyOptions:
7038 {
7039 (void) ListPolicyInfo((FILE *) NULL,exception);
7040 break;
7041 }
7042 case MagickResourceOptions:
7043 {
7044 (void) ListMagickResourceInfo((FILE *) NULL,exception);
7045 break;
7046 }
7047 case MagickThresholdOptions:
7048 {
7049 (void) ListThresholdMaps((FILE *) NULL,exception);
7050 break;
7051 }
7052 default:
7053 {
7054 (void) ListMagickOptions((FILE *) NULL,(MagickOption) list,
7055 exception);
7056 break;
7057 }
7058 }
cristyaeb2cbc2010-05-07 13:28:58 +00007059 break;
cristy3ed852e2009-09-05 21:47:34 +00007060 }
7061 if (LocaleCompare("log",option+1) == 0)
7062 {
7063 if (*option == '+')
7064 break;
7065 (void) SetLogFormat(argv[i+1]);
7066 break;
7067 }
7068 if (LocaleCompare("loop",option+1) == 0)
7069 {
7070 if (*option == '+')
7071 {
7072 (void) SetImageOption(image_info,option+1,"0");
7073 break;
7074 }
7075 (void) SetImageOption(image_info,option+1,argv[i+1]);
7076 break;
7077 }
7078 break;
7079 }
7080 case 'm':
7081 {
7082 if (LocaleCompare("matte",option+1) == 0)
7083 {
7084 if (*option == '+')
7085 {
7086 (void) SetImageOption(image_info,option+1,"false");
7087 break;
7088 }
7089 (void) SetImageOption(image_info,option+1,"true");
7090 break;
7091 }
7092 if (LocaleCompare("mattecolor",option+1) == 0)
7093 {
7094 if (*option == '+')
7095 {
7096 (void) SetImageOption(image_info,option+1,argv[i+1]);
7097 (void) QueryColorDatabase(MatteColor,&image_info->matte_color,
7098 exception);
7099 break;
7100 }
7101 (void) SetImageOption(image_info,option+1,argv[i+1]);
7102 (void) QueryColorDatabase(argv[i+1],&image_info->matte_color,
7103 exception);
7104 break;
7105 }
7106 if (LocaleCompare("monitor",option+1) == 0)
7107 {
7108 (void) SetImageInfoProgressMonitor(image_info,MonitorProgress,
7109 (void *) NULL);
7110 break;
7111 }
7112 if (LocaleCompare("monochrome",option+1) == 0)
7113 {
7114 image_info->monochrome=(*option == '-') ? MagickTrue : MagickFalse;
7115 break;
7116 }
7117 break;
7118 }
7119 case 'o':
7120 {
7121 if (LocaleCompare("orient",option+1) == 0)
7122 {
7123 if (*option == '+')
7124 {
7125 image_info->orientation=UndefinedOrientation;
7126 (void) SetImageOption(image_info,option+1,"undefined");
7127 break;
7128 }
7129 image_info->orientation=(OrientationType) ParseMagickOption(
7130 MagickOrientationOptions,MagickFalse,argv[i+1]);
cristyc6e214d2010-08-08 00:31:08 +00007131 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007132 break;
7133 }
7134 }
7135 case 'p':
7136 {
7137 if (LocaleCompare("page",option+1) == 0)
7138 {
7139 char
7140 *canonical_page,
7141 page[MaxTextExtent];
7142
7143 const char
7144 *image_option;
7145
7146 MagickStatusType
7147 flags;
7148
7149 RectangleInfo
7150 geometry;
7151
7152 if (*option == '+')
7153 {
7154 (void) DeleteImageOption(image_info,option+1);
7155 (void) CloneString(&image_info->page,(char *) NULL);
7156 break;
7157 }
7158 (void) ResetMagickMemory(&geometry,0,sizeof(geometry));
7159 image_option=GetImageOption(image_info,"page");
7160 if (image_option != (const char *) NULL)
7161 flags=ParseAbsoluteGeometry(image_option,&geometry);
7162 canonical_page=GetPageGeometry(argv[i+1]);
7163 flags=ParseAbsoluteGeometry(canonical_page,&geometry);
7164 canonical_page=DestroyString(canonical_page);
7165 (void) FormatMagickString(page,MaxTextExtent,"%lux%lu",
cristyf2faecf2010-05-28 19:19:36 +00007166 (unsigned long) geometry.width,(unsigned long) geometry.height);
cristy3ed852e2009-09-05 21:47:34 +00007167 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
7168 (void) FormatMagickString(page,MaxTextExtent,"%lux%lu%+ld%+ld",
cristyf2faecf2010-05-28 19:19:36 +00007169 (unsigned long) geometry.width,(unsigned long) geometry.height,
7170 (long) geometry.x,(long) geometry.y);
cristy3ed852e2009-09-05 21:47:34 +00007171 (void) SetImageOption(image_info,option+1,page);
7172 (void) CloneString(&image_info->page,page);
7173 break;
7174 }
7175 if (LocaleCompare("pen",option+1) == 0)
7176 {
7177 if (*option == '+')
7178 {
7179 (void) SetImageOption(image_info,option+1,"none");
7180 break;
7181 }
7182 (void) SetImageOption(image_info,option+1,argv[i+1]);
7183 break;
7184 }
7185 if (LocaleCompare("ping",option+1) == 0)
7186 {
7187 image_info->ping=(*option == '-') ? MagickTrue : MagickFalse;
7188 break;
7189 }
7190 if (LocaleCompare("pointsize",option+1) == 0)
7191 {
7192 if (*option == '+')
7193 geometry_info.rho=0.0;
7194 else
7195 (void) ParseGeometry(argv[i+1],&geometry_info);
7196 image_info->pointsize=geometry_info.rho;
7197 break;
7198 }
cristye7f51092010-01-17 00:39:37 +00007199 if (LocaleCompare("precision",option+1) == 0)
7200 {
cristybf2766a2010-01-17 03:33:23 +00007201 (void) SetMagickPrecision(StringToInteger(argv[i+1]));
cristye7f51092010-01-17 00:39:37 +00007202 break;
7203 }
cristy3ed852e2009-09-05 21:47:34 +00007204 if (LocaleCompare("preview",option+1) == 0)
7205 {
7206 /*
7207 Preview image.
7208 */
7209 if (*option == '+')
7210 {
7211 image_info->preview_type=UndefinedPreview;
7212 break;
7213 }
7214 image_info->preview_type=(PreviewType) ParseMagickOption(
7215 MagickPreviewOptions,MagickFalse,argv[i+1]);
7216 break;
7217 }
7218 break;
7219 }
7220 case 'q':
7221 {
7222 if (LocaleCompare("quality",option+1) == 0)
7223 {
7224 /*
7225 Set image compression quality.
7226 */
7227 if (*option == '+')
7228 {
7229 image_info->quality=UndefinedCompressionQuality;
7230 (void) SetImageOption(image_info,option+1,"0");
7231 break;
7232 }
cristye27293e2009-12-18 02:53:20 +00007233 image_info->quality=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007234 (void) SetImageOption(image_info,option+1,argv[i+1]);
7235 break;
7236 }
7237 if (LocaleCompare("quiet",option+1) == 0)
7238 {
7239 static WarningHandler
7240 warning_handler = (WarningHandler) NULL;
7241
7242 if (*option == '+')
7243 {
7244 /*
7245 Restore error or warning messages.
7246 */
7247 warning_handler=SetWarningHandler(warning_handler);
7248 break;
7249 }
7250 /*
7251 Suppress error or warning messages.
7252 */
7253 warning_handler=SetWarningHandler((WarningHandler) NULL);
7254 break;
7255 }
7256 break;
7257 }
7258 case 'r':
7259 {
7260 if (LocaleCompare("red-primary",option+1) == 0)
7261 {
7262 if (*option == '+')
7263 {
7264 (void) SetImageOption(image_info,option+1,"0.0");
7265 break;
7266 }
7267 (void) SetImageOption(image_info,option+1,argv[i+1]);
7268 break;
7269 }
7270 break;
7271 }
7272 case 's':
7273 {
7274 if (LocaleCompare("sampling-factor",option+1) == 0)
7275 {
7276 /*
7277 Set image sampling factor.
7278 */
7279 if (*option == '+')
7280 {
7281 if (image_info->sampling_factor != (char *) NULL)
7282 image_info->sampling_factor=DestroyString(
7283 image_info->sampling_factor);
7284 break;
7285 }
7286 (void) CloneString(&image_info->sampling_factor,argv[i+1]);
7287 break;
7288 }
7289 if (LocaleCompare("scene",option+1) == 0)
7290 {
7291 /*
7292 Set image scene.
7293 */
7294 if (*option == '+')
7295 {
7296 image_info->scene=0;
7297 (void) SetImageOption(image_info,option+1,"0");
7298 break;
7299 }
cristye27293e2009-12-18 02:53:20 +00007300 image_info->scene=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007301 (void) SetImageOption(image_info,option+1,argv[i+1]);
7302 break;
7303 }
7304 if (LocaleCompare("seed",option+1) == 0)
7305 {
cristybb503372010-05-27 20:51:26 +00007306 size_t
cristy3ed852e2009-09-05 21:47:34 +00007307 seed;
7308
7309 if (*option == '+')
7310 {
cristybb503372010-05-27 20:51:26 +00007311 seed=(size_t) time((time_t *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00007312 SeedPseudoRandomGenerator(seed);
7313 break;
7314 }
cristye27293e2009-12-18 02:53:20 +00007315 seed=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007316 SeedPseudoRandomGenerator(seed);
7317 break;
7318 }
7319 if (LocaleCompare("size",option+1) == 0)
7320 {
7321 if (*option == '+')
7322 {
7323 if (image_info->size != (char *) NULL)
7324 image_info->size=DestroyString(image_info->size);
7325 break;
7326 }
7327 (void) CloneString(&image_info->size,argv[i+1]);
7328 break;
7329 }
7330 if (LocaleCompare("stroke",option+1) == 0)
7331 {
7332 if (*option == '+')
7333 {
7334 (void) SetImageOption(image_info,option+1,"none");
7335 break;
7336 }
7337 (void) SetImageOption(image_info,option+1,argv[i+1]);
7338 break;
7339 }
7340 if (LocaleCompare("strokewidth",option+1) == 0)
7341 {
7342 if (*option == '+')
7343 {
7344 (void) SetImageOption(image_info,option+1,"0");
7345 break;
7346 }
7347 (void) SetImageOption(image_info,option+1,argv[i+1]);
7348 break;
7349 }
cristyd9a29192010-10-16 16:49:53 +00007350 if (LocaleCompare("synchronize",option+1) == 0)
7351 {
7352 if (*option == '+')
7353 {
7354 image_info->synchronize=MagickFalse;
7355 break;
7356 }
7357 image_info->synchronize=MagickTrue;
7358 break;
7359 }
cristy3ed852e2009-09-05 21:47:34 +00007360 break;
7361 }
7362 case 't':
7363 {
7364 if (LocaleCompare("taint",option+1) == 0)
7365 {
7366 if (*option == '+')
7367 {
7368 (void) SetImageOption(image_info,option+1,"false");
7369 break;
7370 }
7371 (void) SetImageOption(image_info,option+1,"true");
7372 break;
7373 }
7374 if (LocaleCompare("texture",option+1) == 0)
7375 {
7376 if (*option == '+')
7377 {
7378 if (image_info->texture != (char *) NULL)
7379 image_info->texture=DestroyString(image_info->texture);
7380 break;
7381 }
7382 (void) CloneString(&image_info->texture,argv[i+1]);
7383 break;
7384 }
7385 if (LocaleCompare("tile-offset",option+1) == 0)
7386 {
7387 if (*option == '+')
7388 {
7389 (void) SetImageOption(image_info,option+1,"0");
7390 break;
7391 }
7392 (void) SetImageOption(image_info,option+1,argv[i+1]);
7393 break;
7394 }
7395 if (LocaleCompare("transparent-color",option+1) == 0)
7396 {
7397 if (*option == '+')
7398 {
7399 (void) QueryColorDatabase("none",&image_info->transparent_color, exception);
7400 (void) SetImageOption(image_info,option+1,"none");
7401 break;
7402 }
7403 (void) QueryColorDatabase(argv[i+1],&image_info->transparent_color,
7404 exception);
7405 (void) SetImageOption(image_info,option+1,argv[i+1]);
7406 break;
7407 }
7408 if (LocaleCompare("type",option+1) == 0)
7409 {
7410 if (*option == '+')
7411 {
7412 image_info->type=UndefinedType;
7413 (void) SetImageOption(image_info,option+1,"undefined");
7414 break;
7415 }
7416 image_info->type=(ImageType) ParseMagickOption(MagickTypeOptions,
7417 MagickFalse,argv[i+1]);
7418 (void) SetImageOption(image_info,option+1,argv[i+1]);
7419 break;
7420 }
7421 break;
7422 }
7423 case 'u':
7424 {
7425 if (LocaleCompare("undercolor",option+1) == 0)
7426 {
7427 if (*option == '+')
7428 {
7429 (void) DeleteImageOption(image_info,option+1);
7430 break;
7431 }
7432 (void) SetImageOption(image_info,option+1,argv[i+1]);
7433 break;
7434 }
7435 if (LocaleCompare("units",option+1) == 0)
7436 {
7437 if (*option == '+')
7438 {
7439 image_info->units=UndefinedResolution;
7440 (void) SetImageOption(image_info,option+1,"undefined");
7441 break;
7442 }
7443 image_info->units=(ResolutionType) ParseMagickOption(
7444 MagickResolutionOptions,MagickFalse,argv[i+1]);
7445 (void) SetImageOption(image_info,option+1,argv[i+1]);
7446 break;
7447 }
7448 break;
7449 }
7450 case 'v':
7451 {
7452 if (LocaleCompare("verbose",option+1) == 0)
7453 {
7454 if (*option == '+')
7455 {
7456 image_info->verbose=MagickFalse;
7457 break;
7458 }
7459 image_info->verbose=MagickTrue;
7460 image_info->ping=MagickFalse;
7461 break;
7462 }
7463 if (LocaleCompare("view",option+1) == 0)
7464 {
7465 if (*option == '+')
7466 {
7467 if (image_info->view != (char *) NULL)
7468 image_info->view=DestroyString(image_info->view);
7469 break;
7470 }
7471 (void) CloneString(&image_info->view,argv[i+1]);
7472 break;
7473 }
7474 if (LocaleCompare("virtual-pixel",option+1) == 0)
7475 {
7476 if (*option == '+')
7477 {
7478 image_info->virtual_pixel_method=UndefinedVirtualPixelMethod;
7479 (void) SetImageOption(image_info,option+1,"undefined");
7480 break;
7481 }
7482 image_info->virtual_pixel_method=(VirtualPixelMethod)
7483 ParseMagickOption(MagickVirtualPixelOptions,MagickFalse,
7484 argv[i+1]);
7485 (void) SetImageOption(image_info,option+1,argv[i+1]);
7486 break;
7487 }
7488 break;
7489 }
7490 case 'w':
7491 {
7492 if (LocaleCompare("white-point",option+1) == 0)
7493 {
7494 if (*option == '+')
7495 {
7496 (void) SetImageOption(image_info,option+1,"0.0");
7497 break;
7498 }
7499 (void) SetImageOption(image_info,option+1,argv[i+1]);
7500 break;
7501 }
7502 break;
7503 }
7504 default:
7505 break;
7506 }
7507 i+=count;
7508 }
7509 return(MagickTrue);
7510}
7511
7512/*
7513%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7514% %
7515% %
7516% %
7517+ M o g r i f y I m a g e L i s t %
7518% %
7519% %
7520% %
7521%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7522%
7523% MogrifyImageList() applies any command line options that might affect the
7524% entire image list (e.g. -append, -coalesce, etc.).
7525%
7526% The format of the MogrifyImage method is:
7527%
7528% MagickBooleanType MogrifyImageList(ImageInfo *image_info,const int argc,
7529% const char **argv,Image **images,ExceptionInfo *exception)
7530%
7531% A description of each parameter follows:
7532%
7533% o image_info: the image info..
7534%
7535% o argc: Specifies a pointer to an integer describing the number of
7536% elements in the argument vector.
7537%
7538% o argv: Specifies a pointer to a text array containing the command line
7539% arguments.
7540%
7541% o images: the images.
7542%
7543% o exception: return any errors or warnings in this structure.
7544%
7545*/
7546WandExport MagickBooleanType MogrifyImageList(ImageInfo *image_info,
7547 const int argc,const char **argv,Image **images,ExceptionInfo *exception)
7548{
7549 ChannelType
7550 channel;
7551
7552 const char
7553 *option;
7554
cristy6b3da3a2010-06-20 02:21:46 +00007555 ImageInfo
7556 *mogrify_info;
cristy3ed852e2009-09-05 21:47:34 +00007557
7558 MagickStatusType
7559 status;
7560
7561 QuantizeInfo
7562 *quantize_info;
7563
cristybb503372010-05-27 20:51:26 +00007564 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00007565 i;
7566
cristy6b3da3a2010-06-20 02:21:46 +00007567 ssize_t
7568 count,
7569 index;
7570
cristy3ed852e2009-09-05 21:47:34 +00007571 /*
7572 Apply options to the image list.
7573 */
7574 assert(image_info != (ImageInfo *) NULL);
7575 assert(image_info->signature == MagickSignature);
7576 assert(images != (Image **) NULL);
7577 assert((*images)->signature == MagickSignature);
7578 if ((*images)->debug != MagickFalse)
7579 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
7580 (*images)->filename);
7581 if ((argc <= 0) || (*argv == (char *) NULL))
7582 return(MagickTrue);
cristy6b3da3a2010-06-20 02:21:46 +00007583 mogrify_info=CloneImageInfo(image_info);
7584 quantize_info=AcquireQuantizeInfo(mogrify_info);
7585 channel=mogrify_info->channel;
cristy3ed852e2009-09-05 21:47:34 +00007586 status=MagickTrue;
cristybb503372010-05-27 20:51:26 +00007587 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00007588 {
cristy74fe8f12009-10-03 19:09:01 +00007589 if (*images == (Image *) NULL)
7590 break;
cristy3ed852e2009-09-05 21:47:34 +00007591 option=argv[i];
7592 if (IsMagickOption(option) == MagickFalse)
7593 continue;
7594 count=MagickMax(ParseMagickOption(MagickCommandOptions,MagickFalse,option),
7595 0L);
cristycee97112010-05-28 00:44:52 +00007596 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00007597 break;
cristy6b3da3a2010-06-20 02:21:46 +00007598 status=MogrifyImageInfo(mogrify_info,(int) count+1,argv+i,exception);
cristy3ed852e2009-09-05 21:47:34 +00007599 switch (*(option+1))
7600 {
7601 case 'a':
7602 {
7603 if (LocaleCompare("affinity",option+1) == 0)
7604 {
cristy6b3da3a2010-06-20 02:21:46 +00007605 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007606 if (*option == '+')
7607 {
7608 (void) RemapImages(quantize_info,*images,(Image *) NULL);
7609 InheritException(exception,&(*images)->exception);
7610 break;
7611 }
7612 i++;
7613 break;
7614 }
7615 if (LocaleCompare("append",option+1) == 0)
7616 {
7617 Image
7618 *append_image;
7619
cristy6b3da3a2010-06-20 02:21:46 +00007620 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007621 append_image=AppendImages(*images,*option == '-' ? MagickTrue :
7622 MagickFalse,exception);
7623 if (append_image == (Image *) NULL)
7624 {
7625 status=MagickFalse;
7626 break;
7627 }
7628 *images=DestroyImageList(*images);
7629 *images=append_image;
7630 break;
7631 }
7632 if (LocaleCompare("average",option+1) == 0)
7633 {
7634 Image
7635 *average_image;
7636
cristyd18ae7c2010-03-07 17:39:52 +00007637 /*
7638 Average an image sequence (deprecated).
7639 */
cristy6b3da3a2010-06-20 02:21:46 +00007640 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007641 average_image=EvaluateImages(*images,MeanEvaluateOperator,
7642 exception);
cristy3ed852e2009-09-05 21:47:34 +00007643 if (average_image == (Image *) NULL)
7644 {
7645 status=MagickFalse;
7646 break;
7647 }
7648 *images=DestroyImageList(*images);
7649 *images=average_image;
7650 break;
7651 }
7652 break;
7653 }
7654 case 'c':
7655 {
7656 if (LocaleCompare("channel",option+1) == 0)
7657 {
7658 if (*option == '+')
7659 {
7660 channel=DefaultChannels;
7661 break;
7662 }
7663 channel=(ChannelType) ParseChannelOption(argv[i+1]);
7664 break;
7665 }
7666 if (LocaleCompare("clut",option+1) == 0)
7667 {
7668 Image
7669 *clut_image,
7670 *image;
7671
cristy6b3da3a2010-06-20 02:21:46 +00007672 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007673 image=RemoveFirstImageFromList(images);
7674 clut_image=RemoveFirstImageFromList(images);
7675 if (clut_image == (Image *) NULL)
7676 {
7677 status=MagickFalse;
7678 break;
7679 }
7680 (void) ClutImageChannel(image,channel,clut_image);
7681 clut_image=DestroyImage(clut_image);
7682 InheritException(exception,&image->exception);
7683 *images=DestroyImageList(*images);
7684 *images=image;
7685 break;
7686 }
7687 if (LocaleCompare("coalesce",option+1) == 0)
7688 {
7689 Image
7690 *coalesce_image;
7691
cristy6b3da3a2010-06-20 02:21:46 +00007692 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007693 coalesce_image=CoalesceImages(*images,exception);
7694 if (coalesce_image == (Image *) NULL)
7695 {
7696 status=MagickFalse;
7697 break;
7698 }
7699 *images=DestroyImageList(*images);
7700 *images=coalesce_image;
7701 break;
7702 }
7703 if (LocaleCompare("combine",option+1) == 0)
7704 {
7705 Image
7706 *combine_image;
7707
cristy6b3da3a2010-06-20 02:21:46 +00007708 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007709 combine_image=CombineImages(*images,channel,exception);
7710 if (combine_image == (Image *) NULL)
7711 {
7712 status=MagickFalse;
7713 break;
7714 }
7715 *images=DestroyImageList(*images);
7716 *images=combine_image;
7717 break;
7718 }
7719 if (LocaleCompare("composite",option+1) == 0)
7720 {
7721 Image
7722 *mask_image,
7723 *composite_image,
7724 *image;
7725
7726 RectangleInfo
7727 geometry;
7728
cristy6b3da3a2010-06-20 02:21:46 +00007729 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007730 image=RemoveFirstImageFromList(images);
7731 composite_image=RemoveFirstImageFromList(images);
7732 if (composite_image == (Image *) NULL)
7733 {
7734 status=MagickFalse;
7735 break;
7736 }
7737 (void) TransformImage(&composite_image,(char *) NULL,
7738 composite_image->geometry);
7739 SetGeometry(composite_image,&geometry);
7740 (void) ParseAbsoluteGeometry(composite_image->geometry,&geometry);
7741 GravityAdjustGeometry(image->columns,image->rows,image->gravity,
7742 &geometry);
7743 mask_image=RemoveFirstImageFromList(images);
7744 if (mask_image != (Image *) NULL)
7745 {
7746 if ((image->compose == DisplaceCompositeOp) ||
7747 (image->compose == DistortCompositeOp))
7748 {
7749 /*
7750 Merge Y displacement into X displacement image.
7751 */
7752 (void) CompositeImage(composite_image,CopyGreenCompositeOp,
7753 mask_image,0,0);
7754 mask_image=DestroyImage(mask_image);
7755 }
7756 else
7757 {
7758 /*
7759 Set a blending mask for the composition.
7760 */
7761 image->mask=mask_image;
7762 (void) NegateImage(image->mask,MagickFalse);
7763 }
7764 }
7765 (void) CompositeImageChannel(image,channel,image->compose,
7766 composite_image,geometry.x,geometry.y);
7767 if (image->mask != (Image *) NULL)
7768 image->mask=DestroyImage(image->mask);
7769 composite_image=DestroyImage(composite_image);
7770 InheritException(exception,&image->exception);
7771 *images=DestroyImageList(*images);
7772 *images=image;
7773 break;
7774 }
7775 if (LocaleCompare("crop",option+1) == 0)
7776 {
7777 MagickStatusType
7778 flags;
7779
7780 RectangleInfo
7781 geometry;
7782
cristy6b3da3a2010-06-20 02:21:46 +00007783 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007784 flags=ParseGravityGeometry(*images,argv[i+1],&geometry,exception);
7785 if (((geometry.width == 0) && (geometry.height == 0)) ||
7786 ((flags & XValue) != 0) || ((flags & YValue) != 0))
7787 break;
7788 (void) TransformImages(images,argv[i+1],(char *) NULL);
7789 InheritException(exception,&(*images)->exception);
7790 break;
7791 }
7792 break;
7793 }
7794 case 'd':
7795 {
7796 if (LocaleCompare("deconstruct",option+1) == 0)
7797 {
7798 Image
7799 *deconstruct_image;
7800
cristy6b3da3a2010-06-20 02:21:46 +00007801 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007802 deconstruct_image=DeconstructImages(*images,exception);
7803 if (deconstruct_image == (Image *) NULL)
7804 {
7805 status=MagickFalse;
7806 break;
7807 }
7808 *images=DestroyImageList(*images);
7809 *images=deconstruct_image;
7810 break;
7811 }
7812 if (LocaleCompare("delete",option+1) == 0)
7813 {
7814 if (*option == '+')
7815 DeleteImages(images,"-1",exception);
7816 else
7817 DeleteImages(images,argv[i+1],exception);
7818 break;
7819 }
7820 if (LocaleCompare("dither",option+1) == 0)
7821 {
7822 if (*option == '+')
7823 {
7824 quantize_info->dither=MagickFalse;
7825 break;
7826 }
7827 quantize_info->dither=MagickTrue;
7828 quantize_info->dither_method=(DitherMethod) ParseMagickOption(
7829 MagickDitherOptions,MagickFalse,argv[i+1]);
7830 break;
7831 }
7832 break;
7833 }
cristyd18ae7c2010-03-07 17:39:52 +00007834 case 'e':
7835 {
7836 if (LocaleCompare("evaluate-sequence",option+1) == 0)
7837 {
7838 Image
7839 *evaluate_image;
7840
7841 MagickEvaluateOperator
7842 op;
7843
cristy6b3da3a2010-06-20 02:21:46 +00007844 (void) SyncImageSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007845 op=(MagickEvaluateOperator) ParseMagickOption(MagickEvaluateOptions,
7846 MagickFalse,argv[i+1]);
7847 evaluate_image=EvaluateImages(*images,op,exception);
7848 if (evaluate_image == (Image *) NULL)
7849 {
7850 status=MagickFalse;
7851 break;
7852 }
7853 *images=DestroyImageList(*images);
7854 *images=evaluate_image;
7855 break;
7856 }
7857 break;
7858 }
cristy3ed852e2009-09-05 21:47:34 +00007859 case 'f':
7860 {
cristyf0a247f2009-10-04 00:20:03 +00007861 if (LocaleCompare("fft",option+1) == 0)
7862 {
7863 Image
7864 *fourier_image;
7865
7866 /*
7867 Implements the discrete Fourier transform (DFT).
7868 */
cristy6b3da3a2010-06-20 02:21:46 +00007869 (void) SyncImageSettings(mogrify_info,*images);
cristyf0a247f2009-10-04 00:20:03 +00007870 fourier_image=ForwardFourierTransformImage(*images,*option == '-' ?
7871 MagickTrue : MagickFalse,exception);
7872 if (fourier_image == (Image *) NULL)
7873 break;
7874 *images=DestroyImage(*images);
7875 *images=fourier_image;
7876 break;
7877 }
cristy3ed852e2009-09-05 21:47:34 +00007878 if (LocaleCompare("flatten",option+1) == 0)
7879 {
7880 Image
7881 *flatten_image;
7882
cristy6b3da3a2010-06-20 02:21:46 +00007883 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007884 flatten_image=MergeImageLayers(*images,FlattenLayer,exception);
7885 if (flatten_image == (Image *) NULL)
7886 break;
7887 *images=DestroyImageList(*images);
7888 *images=flatten_image;
7889 break;
7890 }
7891 if (LocaleCompare("fx",option+1) == 0)
7892 {
7893 Image
7894 *fx_image;
7895
cristy6b3da3a2010-06-20 02:21:46 +00007896 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007897 fx_image=FxImageChannel(*images,channel,argv[i+1],exception);
7898 if (fx_image == (Image *) NULL)
7899 {
7900 status=MagickFalse;
7901 break;
7902 }
7903 *images=DestroyImageList(*images);
7904 *images=fx_image;
7905 break;
7906 }
7907 break;
7908 }
7909 case 'h':
7910 {
7911 if (LocaleCompare("hald-clut",option+1) == 0)
7912 {
7913 Image
7914 *hald_image,
7915 *image;
7916
cristy6b3da3a2010-06-20 02:21:46 +00007917 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007918 image=RemoveFirstImageFromList(images);
7919 hald_image=RemoveFirstImageFromList(images);
7920 if (hald_image == (Image *) NULL)
7921 {
7922 status=MagickFalse;
7923 break;
7924 }
7925 (void) HaldClutImageChannel(image,channel,hald_image);
7926 hald_image=DestroyImage(hald_image);
7927 InheritException(exception,&image->exception);
cristy0aff6ea2009-11-14 01:40:53 +00007928 if (*images != (Image *) NULL)
7929 *images=DestroyImageList(*images);
cristy3ed852e2009-09-05 21:47:34 +00007930 *images=image;
7931 break;
7932 }
7933 break;
7934 }
7935 case 'i':
7936 {
7937 if (LocaleCompare("ift",option+1) == 0)
7938 {
7939 Image
cristy8587f882009-11-13 20:28:49 +00007940 *fourier_image,
7941 *magnitude_image,
7942 *phase_image;
cristy3ed852e2009-09-05 21:47:34 +00007943
7944 /*
7945 Implements the inverse fourier discrete Fourier transform (DFT).
7946 */
cristy6b3da3a2010-06-20 02:21:46 +00007947 (void) SyncImagesSettings(mogrify_info,*images);
cristy8587f882009-11-13 20:28:49 +00007948 magnitude_image=RemoveFirstImageFromList(images);
7949 phase_image=RemoveFirstImageFromList(images);
7950 if (phase_image == (Image *) NULL)
7951 {
7952 status=MagickFalse;
7953 break;
7954 }
7955 fourier_image=InverseFourierTransformImage(magnitude_image,
7956 phase_image,*option == '-' ? MagickTrue : MagickFalse,exception);
cristy3ed852e2009-09-05 21:47:34 +00007957 if (fourier_image == (Image *) NULL)
7958 break;
cristy0aff6ea2009-11-14 01:40:53 +00007959 if (*images != (Image *) NULL)
7960 *images=DestroyImage(*images);
cristy3ed852e2009-09-05 21:47:34 +00007961 *images=fourier_image;
7962 break;
7963 }
7964 if (LocaleCompare("insert",option+1) == 0)
7965 {
7966 Image
7967 *p,
7968 *q;
7969
7970 index=0;
7971 if (*option != '+')
cristy32c2aea2010-12-01 01:00:50 +00007972 index=(ssize_t) StringToLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007973 p=RemoveLastImageFromList(images);
7974 if (p == (Image *) NULL)
7975 {
7976 (void) ThrowMagickException(exception,GetMagickModule(),
7977 OptionError,"NoSuchImage","`%s'",argv[i+1]);
7978 status=MagickFalse;
7979 break;
7980 }
7981 q=p;
7982 if (index == 0)
7983 PrependImageToList(images,q);
7984 else
cristybb503372010-05-27 20:51:26 +00007985 if (index == (ssize_t) GetImageListLength(*images))
cristy3ed852e2009-09-05 21:47:34 +00007986 AppendImageToList(images,q);
7987 else
7988 {
7989 q=GetImageFromList(*images,index-1);
7990 if (q == (Image *) NULL)
7991 {
7992 (void) ThrowMagickException(exception,GetMagickModule(),
7993 OptionError,"NoSuchImage","`%s'",argv[i+1]);
7994 status=MagickFalse;
7995 break;
7996 }
7997 InsertImageInList(&q,p);
7998 }
7999 *images=GetFirstImageInList(q);
8000 break;
8001 }
8002 break;
8003 }
8004 case 'l':
8005 {
8006 if (LocaleCompare("layers",option+1) == 0)
8007 {
8008 Image
8009 *layers;
8010
8011 ImageLayerMethod
8012 method;
8013
cristy6b3da3a2010-06-20 02:21:46 +00008014 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00008015 layers=(Image *) NULL;
8016 method=(ImageLayerMethod) ParseMagickOption(MagickLayerOptions,
8017 MagickFalse,argv[i+1]);
8018 switch (method)
8019 {
8020 case CoalesceLayer:
8021 {
8022 layers=CoalesceImages(*images,exception);
8023 break;
8024 }
8025 case CompareAnyLayer:
8026 case CompareClearLayer:
8027 case CompareOverlayLayer:
8028 default:
8029 {
8030 layers=CompareImageLayers(*images,method,exception);
8031 break;
8032 }
8033 case MergeLayer:
8034 case FlattenLayer:
8035 case MosaicLayer:
8036 case TrimBoundsLayer:
8037 {
8038 layers=MergeImageLayers(*images,method,exception);
8039 break;
8040 }
8041 case DisposeLayer:
8042 {
8043 layers=DisposeImages(*images,exception);
8044 break;
8045 }
8046 case OptimizeImageLayer:
8047 {
8048 layers=OptimizeImageLayers(*images,exception);
8049 break;
8050 }
8051 case OptimizePlusLayer:
8052 {
8053 layers=OptimizePlusImageLayers(*images,exception);
8054 break;
8055 }
8056 case OptimizeTransLayer:
8057 {
8058 OptimizeImageTransparency(*images,exception);
8059 break;
8060 }
8061 case RemoveDupsLayer:
8062 {
8063 RemoveDuplicateLayers(images,exception);
8064 break;
8065 }
8066 case RemoveZeroLayer:
8067 {
8068 RemoveZeroDelayLayers(images,exception);
8069 break;
8070 }
8071 case OptimizeLayer:
8072 {
8073 /*
8074 General Purpose, GIF Animation Optimizer.
8075 */
8076 layers=CoalesceImages(*images,exception);
8077 if (layers == (Image *) NULL)
8078 {
8079 status=MagickFalse;
8080 break;
8081 }
8082 InheritException(exception,&layers->exception);
8083 *images=DestroyImageList(*images);
8084 *images=layers;
8085 layers=OptimizeImageLayers(*images,exception);
8086 if (layers == (Image *) NULL)
8087 {
8088 status=MagickFalse;
8089 break;
8090 }
8091 InheritException(exception,&layers->exception);
8092 *images=DestroyImageList(*images);
8093 *images=layers;
8094 layers=(Image *) NULL;
8095 OptimizeImageTransparency(*images,exception);
8096 InheritException(exception,&(*images)->exception);
8097 (void) RemapImages(quantize_info,*images,(Image *) NULL);
8098 break;
8099 }
8100 case CompositeLayer:
8101 {
8102 CompositeOperator
8103 compose;
8104
8105 Image
8106 *source;
8107
8108 RectangleInfo
8109 geometry;
8110
8111 /*
8112 Split image sequence at the first 'NULL:' image.
8113 */
8114 source=(*images);
8115 while (source != (Image *) NULL)
8116 {
8117 source=GetNextImageInList(source);
8118 if ((source != (Image *) NULL) &&
8119 (LocaleCompare(source->magick,"NULL") == 0))
8120 break;
8121 }
8122 if (source != (Image *) NULL)
8123 {
8124 if ((GetPreviousImageInList(source) == (Image *) NULL) ||
8125 (GetNextImageInList(source) == (Image *) NULL))
8126 source=(Image *) NULL;
8127 else
8128 {
8129 /*
8130 Separate the two lists, junk the null: image.
8131 */
8132 source=SplitImageList(source->previous);
8133 DeleteImageFromList(&source);
8134 }
8135 }
8136 if (source == (Image *) NULL)
8137 {
8138 (void) ThrowMagickException(exception,GetMagickModule(),
8139 OptionError,"MissingNullSeparator","layers Composite");
8140 status=MagickFalse;
8141 break;
8142 }
8143 /*
8144 Adjust offset with gravity and virtual canvas.
8145 */
8146 SetGeometry(*images,&geometry);
8147 (void) ParseAbsoluteGeometry((*images)->geometry,&geometry);
8148 geometry.width=source->page.width != 0 ?
8149 source->page.width : source->columns;
8150 geometry.height=source->page.height != 0 ?
8151 source->page.height : source->rows;
8152 GravityAdjustGeometry((*images)->page.width != 0 ?
8153 (*images)->page.width : (*images)->columns,
8154 (*images)->page.height != 0 ? (*images)->page.height :
8155 (*images)->rows,(*images)->gravity,&geometry);
8156 compose=OverCompositeOp;
cristy6b3da3a2010-06-20 02:21:46 +00008157 option=GetImageOption(mogrify_info,"compose");
cristy3ed852e2009-09-05 21:47:34 +00008158 if (option != (const char *) NULL)
8159 compose=(CompositeOperator) ParseMagickOption(
8160 MagickComposeOptions,MagickFalse,option);
8161 CompositeLayers(*images,compose,source,geometry.x,geometry.y,
8162 exception);
8163 source=DestroyImageList(source);
8164 break;
8165 }
8166 }
8167 if (layers == (Image *) NULL)
8168 break;
8169 InheritException(exception,&layers->exception);
8170 *images=DestroyImageList(*images);
8171 *images=layers;
8172 break;
8173 }
8174 break;
8175 }
8176 case 'm':
8177 {
8178 if (LocaleCompare("map",option+1) == 0)
8179 {
cristy6b3da3a2010-06-20 02:21:46 +00008180 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00008181 if (*option == '+')
8182 {
8183 (void) RemapImages(quantize_info,*images,(Image *) NULL);
8184 InheritException(exception,&(*images)->exception);
8185 break;
8186 }
8187 i++;
8188 break;
8189 }
cristyf40785b2010-03-06 02:27:27 +00008190 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00008191 {
8192 Image
cristyf40785b2010-03-06 02:27:27 +00008193 *maximum_image;
cristy1c274c92010-03-06 02:06:45 +00008194
cristyd18ae7c2010-03-07 17:39:52 +00008195 /*
8196 Maximum image sequence (deprecated).
8197 */
cristy6b3da3a2010-06-20 02:21:46 +00008198 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00008199 maximum_image=EvaluateImages(*images,MaxEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00008200 if (maximum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00008201 {
8202 status=MagickFalse;
8203 break;
8204 }
8205 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00008206 *images=maximum_image;
cristy1c274c92010-03-06 02:06:45 +00008207 break;
8208 }
cristyf40785b2010-03-06 02:27:27 +00008209 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00008210 {
8211 Image
cristyf40785b2010-03-06 02:27:27 +00008212 *minimum_image;
cristy1c274c92010-03-06 02:06:45 +00008213
cristyd18ae7c2010-03-07 17:39:52 +00008214 /*
8215 Minimum image sequence (deprecated).
8216 */
cristy6b3da3a2010-06-20 02:21:46 +00008217 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00008218 minimum_image=EvaluateImages(*images,MinEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00008219 if (minimum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00008220 {
8221 status=MagickFalse;
8222 break;
8223 }
8224 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00008225 *images=minimum_image;
cristy1c274c92010-03-06 02:06:45 +00008226 break;
8227 }
cristy3ed852e2009-09-05 21:47:34 +00008228 if (LocaleCompare("morph",option+1) == 0)
8229 {
8230 Image
8231 *morph_image;
8232
cristy6b3da3a2010-06-20 02:21:46 +00008233 (void) SyncImagesSettings(mogrify_info,*images);
cristye27293e2009-12-18 02:53:20 +00008234 morph_image=MorphImages(*images,StringToUnsignedLong(argv[i+1]),
cristy3ed852e2009-09-05 21:47:34 +00008235 exception);
8236 if (morph_image == (Image *) NULL)
8237 {
8238 status=MagickFalse;
8239 break;
8240 }
8241 *images=DestroyImageList(*images);
8242 *images=morph_image;
8243 break;
8244 }
8245 if (LocaleCompare("mosaic",option+1) == 0)
8246 {
8247 Image
8248 *mosaic_image;
8249
cristy6b3da3a2010-06-20 02:21:46 +00008250 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00008251 mosaic_image=MergeImageLayers(*images,MosaicLayer,exception);
8252 if (mosaic_image == (Image *) NULL)
8253 {
8254 status=MagickFalse;
8255 break;
8256 }
8257 *images=DestroyImageList(*images);
8258 *images=mosaic_image;
8259 break;
8260 }
8261 break;
8262 }
8263 case 'p':
8264 {
8265 if (LocaleCompare("print",option+1) == 0)
8266 {
8267 char
8268 *string;
8269
cristy6b3da3a2010-06-20 02:21:46 +00008270 (void) SyncImagesSettings(mogrify_info,*images);
8271 string=InterpretImageProperties(mogrify_info,*images,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00008272 if (string == (char *) NULL)
8273 break;
8274 InheritException(exception,&(*images)->exception);
8275 (void) fprintf(stdout,"%s",string);
8276 string=DestroyString(string);
8277 }
8278 if (LocaleCompare("process",option+1) == 0)
8279 {
8280 char
8281 **arguments;
8282
8283 int
8284 j,
8285 number_arguments;
8286
cristy6b3da3a2010-06-20 02:21:46 +00008287 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00008288 arguments=StringToArgv(argv[i+1],&number_arguments);
8289 if (arguments == (char **) NULL)
8290 break;
8291 if ((argc > 1) && (strchr(arguments[1],'=') != (char *) NULL))
8292 {
8293 char
8294 breaker,
8295 quote,
8296 *token;
8297
8298 const char
8299 *arguments;
8300
8301 int
8302 next,
8303 status;
8304
8305 size_t
8306 length;
8307
8308 TokenInfo
8309 *token_info;
8310
8311 /*
8312 Support old style syntax, filter="-option arg".
8313 */
8314 length=strlen(argv[i+1]);
8315 token=(char *) NULL;
8316 if (~length >= MaxTextExtent)
8317 token=(char *) AcquireQuantumMemory(length+MaxTextExtent,
8318 sizeof(*token));
8319 if (token == (char *) NULL)
8320 break;
8321 next=0;
8322 arguments=argv[i+1];
8323 token_info=AcquireTokenInfo();
8324 status=Tokenizer(token_info,0,token,length,arguments,"","=",
8325 "\"",'\0',&breaker,&next,&quote);
8326 token_info=DestroyTokenInfo(token_info);
8327 if (status == 0)
8328 {
8329 const char
8330 *argv;
8331
8332 argv=(&(arguments[next]));
8333 (void) InvokeDynamicImageFilter(token,&(*images),1,&argv,
8334 exception);
8335 }
8336 token=DestroyString(token);
8337 break;
8338 }
cristy91c0da22010-05-02 01:44:07 +00008339 (void) SubstituteString(&arguments[1],"-","");
cristy3ed852e2009-09-05 21:47:34 +00008340 (void) InvokeDynamicImageFilter(arguments[1],&(*images),
8341 number_arguments-2,(const char **) arguments+2,exception);
8342 for (j=0; j < number_arguments; j++)
8343 arguments[j]=DestroyString(arguments[j]);
8344 arguments=(char **) RelinquishMagickMemory(arguments);
8345 break;
8346 }
8347 break;
8348 }
8349 case 'r':
8350 {
8351 if (LocaleCompare("reverse",option+1) == 0)
8352 {
8353 ReverseImageList(images);
8354 InheritException(exception,&(*images)->exception);
8355 break;
8356 }
8357 break;
8358 }
8359 case 's':
8360 {
8361 if (LocaleCompare("swap",option+1) == 0)
8362 {
8363 Image
8364 *p,
8365 *q,
8366 *swap;
8367
cristybb503372010-05-27 20:51:26 +00008368 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00008369 swap_index;
8370
8371 index=(-1);
8372 swap_index=(-2);
8373 if (*option != '+')
8374 {
8375 GeometryInfo
8376 geometry_info;
8377
8378 MagickStatusType
8379 flags;
8380
8381 swap_index=(-1);
8382 flags=ParseGeometry(argv[i+1],&geometry_info);
cristybb503372010-05-27 20:51:26 +00008383 index=(ssize_t) geometry_info.rho;
cristy3ed852e2009-09-05 21:47:34 +00008384 if ((flags & SigmaValue) != 0)
cristybb503372010-05-27 20:51:26 +00008385 swap_index=(ssize_t) geometry_info.sigma;
cristy3ed852e2009-09-05 21:47:34 +00008386 }
8387 p=GetImageFromList(*images,index);
8388 q=GetImageFromList(*images,swap_index);
8389 if ((p == (Image *) NULL) || (q == (Image *) NULL))
8390 {
8391 (void) ThrowMagickException(exception,GetMagickModule(),
8392 OptionError,"NoSuchImage","`%s'",(*images)->filename);
8393 status=MagickFalse;
8394 break;
8395 }
8396 if (p == q)
8397 break;
8398 swap=CloneImage(p,0,0,MagickTrue,exception);
8399 ReplaceImageInList(&p,CloneImage(q,0,0,MagickTrue,exception));
8400 ReplaceImageInList(&q,swap);
8401 *images=GetFirstImageInList(q);
8402 break;
8403 }
8404 break;
8405 }
8406 case 'w':
8407 {
8408 if (LocaleCompare("write",option+1) == 0)
8409 {
cristy071dd7b2010-04-09 13:04:54 +00008410 char
cristy06609ee2010-03-17 20:21:27 +00008411 key[MaxTextExtent];
8412
cristy3ed852e2009-09-05 21:47:34 +00008413 Image
8414 *write_images;
8415
8416 ImageInfo
8417 *write_info;
8418
cristy6b3da3a2010-06-20 02:21:46 +00008419 (void) SyncImagesSettings(mogrify_info,*images);
cristy06609ee2010-03-17 20:21:27 +00008420 (void) FormatMagickString(key,MaxTextExtent,"cache:%s",argv[i+1]);
8421 (void) DeleteImageRegistry(key);
cristy3ed852e2009-09-05 21:47:34 +00008422 write_images=(*images);
8423 if (*option == '+')
8424 write_images=CloneImageList(*images,exception);
cristy6b3da3a2010-06-20 02:21:46 +00008425 write_info=CloneImageInfo(mogrify_info);
cristy3ed852e2009-09-05 21:47:34 +00008426 status&=WriteImages(write_info,write_images,argv[i+1],exception);
8427 write_info=DestroyImageInfo(write_info);
8428 if (*option == '+')
8429 write_images=DestroyImageList(write_images);
8430 break;
8431 }
8432 break;
8433 }
8434 default:
8435 break;
8436 }
8437 i+=count;
8438 }
8439 quantize_info=DestroyQuantizeInfo(quantize_info);
cristy6b3da3a2010-06-20 02:21:46 +00008440 mogrify_info=DestroyImageInfo(mogrify_info);
8441 status&=MogrifyImageInfo(image_info,argc,argv,exception);
cristy3ed852e2009-09-05 21:47:34 +00008442 return(status != 0 ? MagickTrue : MagickFalse);
8443}
8444
8445/*
8446%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8447% %
8448% %
8449% %
8450+ M o g r i f y I m a g e s %
8451% %
8452% %
8453% %
8454%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8455%
8456% MogrifyImages() applies image processing options to a sequence of images as
8457% prescribed by command line options.
8458%
8459% The format of the MogrifyImage method is:
8460%
8461% MagickBooleanType MogrifyImages(ImageInfo *image_info,
8462% const MagickBooleanType post,const int argc,const char **argv,
8463% Image **images,Exceptioninfo *exception)
8464%
8465% A description of each parameter follows:
8466%
8467% o image_info: the image info..
8468%
8469% o post: If true, post process image list operators otherwise pre-process.
8470%
8471% o argc: Specifies a pointer to an integer describing the number of
8472% elements in the argument vector.
8473%
8474% o argv: Specifies a pointer to a text array containing the command line
8475% arguments.
8476%
8477% o images: the images.
8478%
8479% o exception: return any errors or warnings in this structure.
8480%
8481*/
8482WandExport MagickBooleanType MogrifyImages(ImageInfo *image_info,
8483 const MagickBooleanType post,const int argc,const char **argv,
8484 Image **images,ExceptionInfo *exception)
8485{
8486#define MogrifyImageTag "Mogrify/Image"
8487
8488 Image
8489 *image,
8490 *mogrify_images;
8491
cristy0e9f9c12010-02-11 03:00:47 +00008492 MagickBooleanType
8493 proceed;
8494
8495 MagickSizeType
8496 number_images;
8497
cristy3ed852e2009-09-05 21:47:34 +00008498 MagickStatusType
8499 status;
8500
cristybb503372010-05-27 20:51:26 +00008501 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00008502 i;
8503
cristy3ed852e2009-09-05 21:47:34 +00008504 /*
8505 Apply options to individual images in the list.
8506 */
8507 assert(image_info != (ImageInfo *) NULL);
8508 assert(image_info->signature == MagickSignature);
8509 if (images == (Image **) NULL)
8510 return(MogrifyImage(image_info,argc,argv,images,exception));
8511 assert((*images)->signature == MagickSignature);
8512 if ((*images)->debug != MagickFalse)
8513 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
8514 (*images)->filename);
8515 if ((argc <= 0) || (*argv == (char *) NULL))
8516 return(MagickTrue);
8517 (void) SetImageInfoProgressMonitor(image_info,(MagickProgressMonitor) NULL,
8518 (void *) NULL);
8519 mogrify_images=NewImageList();
8520 number_images=GetImageListLength(*images);
8521 status=0;
8522 if (post == MagickFalse)
8523 status&=MogrifyImageList(image_info,argc,argv,images,exception);
cristybb503372010-05-27 20:51:26 +00008524 for (i=0; i < (ssize_t) number_images; i++)
cristy3ed852e2009-09-05 21:47:34 +00008525 {
8526 image=RemoveFirstImageFromList(images);
8527 if (image == (Image *) NULL)
8528 continue;
8529 status&=MogrifyImage(image_info,argc,argv,&image,exception);
8530 AppendImageToList(&mogrify_images,image);
cristy0e9f9c12010-02-11 03:00:47 +00008531 proceed=SetImageProgress(image,MogrifyImageTag,(MagickOffsetType) i,
8532 number_images);
8533 if (proceed == MagickFalse)
8534 break;
cristy3ed852e2009-09-05 21:47:34 +00008535 }
8536 if (post != MagickFalse)
8537 status&=MogrifyImageList(image_info,argc,argv,&mogrify_images,exception);
8538 *images=mogrify_images;
8539 return(status != 0 ? MagickTrue : MagickFalse);
8540}