blob: 8f1ffbc27a3e2ece27a785b6fcf234c349e4c5e3 [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% %
cristy7e41fe82010-12-04 23:12:08 +000020% Copyright 1999-2011 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
cristyebbcfea2011-02-25 02:43:54 +0000599 MagickStatusType
cristy3ed852e2009-09-05 21:47:34 +0000600 status;
601
602 MagickPixelPacket
603 fill;
604
605 MagickStatusType
606 flags;
607
608 QuantizeInfo
609 *quantize_info;
610
611 RectangleInfo
612 geometry,
613 region_geometry;
614
cristybb503372010-05-27 20:51:26 +0000615 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000616 i;
617
cristyebbcfea2011-02-25 02:43:54 +0000618 ssize_t
619 count;
620
cristy3ed852e2009-09-05 21:47:34 +0000621 /*
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 }
cristydf81b992011-02-27 14:33:24 +00001206 if (LocaleCompare("comment",option+1) == 0)
1207 {
1208 if (*option == '+')
1209 {
cristy3fb6d772011-02-27 15:13:43 +00001210 (void) DeleteImageProperty(*image,option+1);
cristydf81b992011-02-27 14:33:24 +00001211 break;
1212 }
cristy3fb6d772011-02-27 15:13:43 +00001213 (void) SetImageProperty(*image,option+1,argv[i+1]);
cristydf81b992011-02-27 14:33:24 +00001214 break;
1215 }
cristy3ed852e2009-09-05 21:47:34 +00001216 if (LocaleCompare("contrast",option+1) == 0)
1217 {
cristy6b3da3a2010-06-20 02:21:46 +00001218 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001219 (void) ContrastImage(*image,(*option == '-') ? MagickTrue :
1220 MagickFalse);
1221 InheritException(exception,&(*image)->exception);
1222 break;
1223 }
1224 if (LocaleCompare("contrast-stretch",option+1) == 0)
1225 {
1226 double
1227 black_point,
1228 white_point;
1229
cristy3ed852e2009-09-05 21:47:34 +00001230 MagickStatusType
1231 flags;
1232
1233 /*
1234 Contrast stretch image.
1235 */
cristy6b3da3a2010-06-20 02:21:46 +00001236 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001237 flags=ParseGeometry(argv[i+1],&geometry_info);
1238 black_point=geometry_info.rho;
1239 white_point=(flags & SigmaValue) != 0 ? geometry_info.sigma :
1240 black_point;
1241 if ((flags & PercentValue) != 0)
1242 {
1243 black_point*=(double) (*image)->columns*(*image)->rows/100.0;
1244 white_point*=(double) (*image)->columns*(*image)->rows/100.0;
1245 }
1246 white_point=(MagickRealType) (*image)->columns*(*image)->rows-
1247 white_point;
1248 (void) ContrastStretchImageChannel(*image,channel,black_point,
1249 white_point);
1250 InheritException(exception,&(*image)->exception);
1251 break;
1252 }
1253 if (LocaleCompare("convolve",option+1) == 0)
1254 {
cristy36826ab2010-03-06 01:29:30 +00001255 double
1256 gamma;
1257
cristy3ed852e2009-09-05 21:47:34 +00001258 Image
1259 *convolve_image;
1260
cristy2be15382010-01-21 02:38:03 +00001261 KernelInfo
cristy56a9e512010-01-06 18:18:55 +00001262 *kernel;
cristy3ed852e2009-09-05 21:47:34 +00001263
cristybb503372010-05-27 20:51:26 +00001264 register ssize_t
cristy36826ab2010-03-06 01:29:30 +00001265 j;
1266
cristy6b3da3a2010-06-20 02:21:46 +00001267 (void) SyncImageSettings(mogrify_info,*image);
cristy2be15382010-01-21 02:38:03 +00001268 kernel=AcquireKernelInfo(argv[i+1]);
1269 if (kernel == (KernelInfo *) NULL)
cristy56a9e512010-01-06 18:18:55 +00001270 break;
cristy36826ab2010-03-06 01:29:30 +00001271 gamma=0.0;
cristybb503372010-05-27 20:51:26 +00001272 for (j=0; j < (ssize_t) (kernel->width*kernel->height); j++)
cristy36826ab2010-03-06 01:29:30 +00001273 gamma+=kernel->values[j];
1274 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
cristybb503372010-05-27 20:51:26 +00001275 for (j=0; j < (ssize_t) (kernel->width*kernel->height); j++)
cristy36826ab2010-03-06 01:29:30 +00001276 kernel->values[j]*=gamma;
cristy6771f1e2010-03-05 19:43:39 +00001277 convolve_image=FilterImageChannel(*image,channel,kernel,exception);
anthony83ba99b2010-01-24 08:48:15 +00001278 kernel=DestroyKernelInfo(kernel);
cristy3ed852e2009-09-05 21:47:34 +00001279 if (convolve_image == (Image *) NULL)
1280 break;
1281 *image=DestroyImage(*image);
1282 *image=convolve_image;
1283 break;
1284 }
1285 if (LocaleCompare("crop",option+1) == 0)
1286 {
cristy6b3da3a2010-06-20 02:21:46 +00001287 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001288 flags=ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1289 if (((geometry.width != 0) || (geometry.height != 0)) &&
1290 ((flags & XValue) == 0) && ((flags & YValue) == 0))
1291 break;
1292 (void) TransformImage(image,argv[i+1],(char *) NULL);
1293 InheritException(exception,&(*image)->exception);
1294 break;
1295 }
1296 if (LocaleCompare("cycle",option+1) == 0)
1297 {
1298 /*
1299 Cycle an image colormap.
1300 */
cristy6b3da3a2010-06-20 02:21:46 +00001301 (void) SyncImageSettings(mogrify_info,*image);
cristy32c2aea2010-12-01 01:00:50 +00001302 (void) CycleColormapImage(*image,(ssize_t) StringToLong(argv[i+1]));
cristy3ed852e2009-09-05 21:47:34 +00001303 InheritException(exception,&(*image)->exception);
1304 break;
1305 }
1306 break;
1307 }
1308 case 'd':
1309 {
1310 if (LocaleCompare("decipher",option+1) == 0)
1311 {
1312 StringInfo
1313 *passkey;
1314
1315 /*
1316 Decipher pixels.
1317 */
cristy6b3da3a2010-06-20 02:21:46 +00001318 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001319 passkey=FileToStringInfo(argv[i+1],~0,exception);
1320 if (passkey != (StringInfo *) NULL)
1321 {
1322 (void) PasskeyDecipherImage(*image,passkey,exception);
1323 passkey=DestroyStringInfo(passkey);
1324 }
1325 break;
1326 }
1327 if (LocaleCompare("density",option+1) == 0)
1328 {
1329 /*
1330 Set image density.
1331 */
1332 (void) CloneString(&draw_info->density,argv[i+1]);
1333 break;
1334 }
1335 if (LocaleCompare("depth",option+1) == 0)
1336 {
cristy6b3da3a2010-06-20 02:21:46 +00001337 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001338 if (*option == '+')
1339 {
1340 (void) SetImageDepth(*image,MAGICKCORE_QUANTUM_DEPTH);
1341 break;
1342 }
cristye27293e2009-12-18 02:53:20 +00001343 (void) SetImageDepth(*image,StringToUnsignedLong(argv[i+1]));
cristy3ed852e2009-09-05 21:47:34 +00001344 break;
1345 }
1346 if (LocaleCompare("deskew",option+1) == 0)
1347 {
1348 double
1349 threshold;
1350
1351 Image
1352 *deskew_image;
1353
1354 /*
1355 Straighten the image.
1356 */
cristy6b3da3a2010-06-20 02:21:46 +00001357 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001358 if (*option == '+')
1359 threshold=40.0*QuantumRange/100.0;
1360 else
cristyf2f27272009-12-17 14:48:46 +00001361 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
cristy3ed852e2009-09-05 21:47:34 +00001362 deskew_image=DeskewImage(*image,threshold,exception);
1363 if (deskew_image == (Image *) NULL)
1364 break;
1365 *image=DestroyImage(*image);
1366 *image=deskew_image;
1367 break;
1368 }
1369 if (LocaleCompare("despeckle",option+1) == 0)
1370 {
1371 Image
1372 *despeckle_image;
1373
1374 /*
1375 Reduce the speckles within an image.
1376 */
cristy6b3da3a2010-06-20 02:21:46 +00001377 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001378 despeckle_image=DespeckleImage(*image,exception);
1379 if (despeckle_image == (Image *) NULL)
1380 break;
1381 *image=DestroyImage(*image);
1382 *image=despeckle_image;
1383 break;
1384 }
1385 if (LocaleCompare("display",option+1) == 0)
1386 {
1387 (void) CloneString(&draw_info->server_name,argv[i+1]);
1388 break;
1389 }
cristy3ed852e2009-09-05 21:47:34 +00001390 if (LocaleCompare("distort",option+1) == 0)
1391 {
1392 char
1393 *args,
1394 token[MaxTextExtent];
1395
1396 const char
1397 *p;
1398
1399 DistortImageMethod
1400 method;
1401
1402 double
1403 *arguments;
1404
1405 Image
1406 *distort_image;
1407
cristybb503372010-05-27 20:51:26 +00001408 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001409 x;
1410
cristybb503372010-05-27 20:51:26 +00001411 size_t
cristy3ed852e2009-09-05 21:47:34 +00001412 number_arguments;
1413
1414 /*
1415 Distort image.
1416 */
cristy6b3da3a2010-06-20 02:21:46 +00001417 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001418 method=(DistortImageMethod) ParseMagickOption(MagickDistortOptions,
1419 MagickFalse,argv[i+1]);
cristy6b3da3a2010-06-20 02:21:46 +00001420 args=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
cristy3ed852e2009-09-05 21:47:34 +00001421 InheritException(exception,&(*image)->exception);
1422 if (args == (char *) NULL)
1423 break;
1424 p=(char *) args;
1425 for (x=0; *p != '\0'; x++)
1426 {
1427 GetMagickToken(p,&p,token);
1428 if (*token == ',')
1429 GetMagickToken(p,&p,token);
1430 }
cristybb503372010-05-27 20:51:26 +00001431 number_arguments=(size_t) x;
cristy3ed852e2009-09-05 21:47:34 +00001432 arguments=(double *) AcquireQuantumMemory(number_arguments,
1433 sizeof(*arguments));
1434 if (arguments == (double *) NULL)
1435 ThrowWandFatalException(ResourceLimitFatalError,
1436 "MemoryAllocationFailed",(*image)->filename);
1437 (void) ResetMagickMemory(arguments,0,number_arguments*
1438 sizeof(*arguments));
1439 p=(char *) args;
cristybb503372010-05-27 20:51:26 +00001440 for (x=0; (x < (ssize_t) number_arguments) && (*p != '\0'); x++)
cristy3ed852e2009-09-05 21:47:34 +00001441 {
1442 GetMagickToken(p,&p,token);
1443 if (*token == ',')
1444 GetMagickToken(p,&p,token);
cristyf2f27272009-12-17 14:48:46 +00001445 arguments[x]=StringToDouble(token);
cristy3ed852e2009-09-05 21:47:34 +00001446 }
1447 args=DestroyString(args);
1448 distort_image=DistortImage(*image,method,number_arguments,arguments,
1449 (*option == '+') ? MagickTrue : MagickFalse,exception);
1450 arguments=(double *) RelinquishMagickMemory(arguments);
1451 if (distort_image == (Image *) NULL)
1452 break;
1453 *image=DestroyImage(*image);
1454 *image=distort_image;
1455 break;
1456 }
1457 if (LocaleCompare("dither",option+1) == 0)
1458 {
1459 if (*option == '+')
1460 {
1461 quantize_info->dither=MagickFalse;
1462 break;
1463 }
1464 quantize_info->dither=MagickTrue;
1465 quantize_info->dither_method=(DitherMethod) ParseMagickOption(
1466 MagickDitherOptions,MagickFalse,argv[i+1]);
1467 if (quantize_info->dither_method == NoDitherMethod)
1468 quantize_info->dither=MagickFalse;
1469 break;
1470 }
1471 if (LocaleCompare("draw",option+1) == 0)
1472 {
1473 /*
1474 Draw image.
1475 */
cristy6b3da3a2010-06-20 02:21:46 +00001476 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001477 (void) CloneString(&draw_info->primitive,argv[i+1]);
1478 (void) DrawImage(*image,draw_info);
1479 InheritException(exception,&(*image)->exception);
1480 break;
1481 }
1482 break;
1483 }
1484 case 'e':
1485 {
1486 if (LocaleCompare("edge",option+1) == 0)
1487 {
1488 Image
1489 *edge_image;
1490
1491 /*
1492 Enhance edges in the image.
1493 */
cristy6b3da3a2010-06-20 02:21:46 +00001494 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001495 flags=ParseGeometry(argv[i+1],&geometry_info);
1496 if ((flags & SigmaValue) == 0)
1497 geometry_info.sigma=1.0;
1498 edge_image=EdgeImage(*image,geometry_info.rho,exception);
1499 if (edge_image == (Image *) NULL)
1500 break;
1501 *image=DestroyImage(*image);
1502 *image=edge_image;
1503 break;
1504 }
1505 if (LocaleCompare("emboss",option+1) == 0)
1506 {
1507 Image
1508 *emboss_image;
1509
1510 /*
1511 Gaussian embossen image.
1512 */
cristy6b3da3a2010-06-20 02:21:46 +00001513 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001514 flags=ParseGeometry(argv[i+1],&geometry_info);
1515 if ((flags & SigmaValue) == 0)
1516 geometry_info.sigma=1.0;
1517 emboss_image=EmbossImage(*image,geometry_info.rho,
1518 geometry_info.sigma,exception);
1519 if (emboss_image == (Image *) NULL)
1520 break;
1521 *image=DestroyImage(*image);
1522 *image=emboss_image;
1523 break;
1524 }
1525 if (LocaleCompare("encipher",option+1) == 0)
1526 {
1527 StringInfo
1528 *passkey;
1529
1530 /*
1531 Encipher pixels.
1532 */
cristy6b3da3a2010-06-20 02:21:46 +00001533 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001534 passkey=FileToStringInfo(argv[i+1],~0,exception);
1535 if (passkey != (StringInfo *) NULL)
1536 {
1537 (void) PasskeyEncipherImage(*image,passkey,exception);
1538 passkey=DestroyStringInfo(passkey);
1539 }
1540 break;
1541 }
1542 if (LocaleCompare("encoding",option+1) == 0)
1543 {
1544 (void) CloneString(&draw_info->encoding,argv[i+1]);
1545 break;
1546 }
1547 if (LocaleCompare("enhance",option+1) == 0)
1548 {
1549 Image
1550 *enhance_image;
1551
1552 /*
1553 Enhance image.
1554 */
cristy6b3da3a2010-06-20 02:21:46 +00001555 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001556 enhance_image=EnhanceImage(*image,exception);
1557 if (enhance_image == (Image *) NULL)
1558 break;
1559 *image=DestroyImage(*image);
1560 *image=enhance_image;
1561 break;
1562 }
1563 if (LocaleCompare("equalize",option+1) == 0)
1564 {
1565 /*
1566 Equalize image.
1567 */
cristy6b3da3a2010-06-20 02:21:46 +00001568 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001569 (void) EqualizeImageChannel(*image,channel);
1570 InheritException(exception,&(*image)->exception);
1571 break;
1572 }
1573 if (LocaleCompare("evaluate",option+1) == 0)
1574 {
1575 double
1576 constant;
1577
1578 MagickEvaluateOperator
1579 op;
1580
cristy6b3da3a2010-06-20 02:21:46 +00001581 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001582 op=(MagickEvaluateOperator) ParseMagickOption(MagickEvaluateOptions,
1583 MagickFalse,argv[i+1]);
cristyf2f27272009-12-17 14:48:46 +00001584 constant=SiPrefixToDouble(argv[i+2],QuantumRange);
cristy3ed852e2009-09-05 21:47:34 +00001585 (void) EvaluateImageChannel(*image,channel,op,constant,exception);
1586 break;
1587 }
1588 if (LocaleCompare("extent",option+1) == 0)
1589 {
1590 Image
1591 *extent_image;
1592
1593 /*
1594 Set the image extent.
1595 */
cristy6b3da3a2010-06-20 02:21:46 +00001596 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001597 flags=ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
cristyf0bbfd92009-11-25 14:12:31 +00001598 if (geometry.width == 0)
cristy2ea9a4e2009-11-25 14:30:22 +00001599 geometry.width=(*image)->columns;
cristyf0bbfd92009-11-25 14:12:31 +00001600 if (geometry.height == 0)
cristy2ea9a4e2009-11-25 14:30:22 +00001601 geometry.height=(*image)->rows;
cristy3ed852e2009-09-05 21:47:34 +00001602 extent_image=ExtentImage(*image,&geometry,exception);
1603 if (extent_image == (Image *) NULL)
1604 break;
1605 *image=DestroyImage(*image);
1606 *image=extent_image;
1607 break;
1608 }
1609 break;
1610 }
1611 case 'f':
1612 {
1613 if (LocaleCompare("family",option+1) == 0)
1614 {
1615 if (*option == '+')
1616 {
1617 if (draw_info->family != (char *) NULL)
1618 draw_info->family=DestroyString(draw_info->family);
1619 break;
1620 }
1621 (void) CloneString(&draw_info->family,argv[i+1]);
1622 break;
1623 }
cristy0fe961c2010-01-30 03:09:54 +00001624 if (LocaleCompare("features",option+1) == 0)
1625 {
1626 if (*option == '+')
1627 {
1628 (void) DeleteImageArtifact(*image,"identify:features");
1629 break;
1630 }
1631 (void) SetImageArtifact(*image,"identify:features",argv[i+1]);
1632 break;
1633 }
cristy3ed852e2009-09-05 21:47:34 +00001634 if (LocaleCompare("fill",option+1) == 0)
1635 {
1636 ExceptionInfo
1637 *sans;
1638
1639 GetMagickPixelPacket(*image,&fill);
1640 if (*option == '+')
1641 {
1642 (void) QueryMagickColor("none",&fill,exception);
1643 (void) QueryColorDatabase("none",&draw_info->fill,exception);
1644 if (draw_info->fill_pattern != (Image *) NULL)
1645 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
1646 break;
1647 }
1648 sans=AcquireExceptionInfo();
1649 (void) QueryMagickColor(argv[i+1],&fill,sans);
1650 status=QueryColorDatabase(argv[i+1],&draw_info->fill,sans);
1651 sans=DestroyExceptionInfo(sans);
1652 if (status == MagickFalse)
cristy6b3da3a2010-06-20 02:21:46 +00001653 draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1],
cristy3ed852e2009-09-05 21:47:34 +00001654 exception);
1655 break;
1656 }
1657 if (LocaleCompare("flip",option+1) == 0)
1658 {
1659 Image
1660 *flip_image;
1661
1662 /*
1663 Flip image scanlines.
1664 */
cristy6b3da3a2010-06-20 02:21:46 +00001665 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001666 flip_image=FlipImage(*image,exception);
1667 if (flip_image == (Image *) NULL)
1668 break;
1669 *image=DestroyImage(*image);
1670 *image=flip_image;
1671 break;
1672 }
1673 if (LocaleCompare("flop",option+1) == 0)
1674 {
1675 Image
1676 *flop_image;
1677
1678 /*
1679 Flop image scanlines.
1680 */
cristy6b3da3a2010-06-20 02:21:46 +00001681 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001682 flop_image=FlopImage(*image,exception);
1683 if (flop_image == (Image *) NULL)
1684 break;
1685 *image=DestroyImage(*image);
1686 *image=flop_image;
1687 break;
1688 }
1689 if (LocaleCompare("floodfill",option+1) == 0)
1690 {
1691 MagickPixelPacket
1692 target;
1693
1694 /*
1695 Floodfill image.
1696 */
cristy6b3da3a2010-06-20 02:21:46 +00001697 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001698 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
1699 (void) QueryMagickColor(argv[i+2],&target,exception);
1700 (void) FloodfillPaintImage(*image,channel,draw_info,&target,
1701 geometry.x,geometry.y,*option == '-' ? MagickFalse : MagickTrue);
1702 InheritException(exception,&(*image)->exception);
1703 break;
1704 }
1705 if (LocaleCompare("font",option+1) == 0)
1706 {
1707 if (*option == '+')
1708 {
1709 if (draw_info->font != (char *) NULL)
1710 draw_info->font=DestroyString(draw_info->font);
1711 break;
1712 }
1713 (void) CloneString(&draw_info->font,argv[i+1]);
1714 break;
1715 }
1716 if (LocaleCompare("format",option+1) == 0)
1717 {
1718 format=argv[i+1];
1719 break;
1720 }
1721 if (LocaleCompare("frame",option+1) == 0)
1722 {
1723 FrameInfo
1724 frame_info;
1725
1726 Image
1727 *frame_image;
1728
1729 /*
1730 Surround image with an ornamental border.
1731 */
cristy6b3da3a2010-06-20 02:21:46 +00001732 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001733 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
1734 frame_info.width=geometry.width;
1735 frame_info.height=geometry.height;
1736 if ((flags & HeightValue) == 0)
1737 frame_info.height=geometry.width;
1738 frame_info.outer_bevel=geometry.x;
1739 frame_info.inner_bevel=geometry.y;
cristybb503372010-05-27 20:51:26 +00001740 frame_info.x=(ssize_t) frame_info.width;
1741 frame_info.y=(ssize_t) frame_info.height;
cristy3ed852e2009-09-05 21:47:34 +00001742 frame_info.width=(*image)->columns+2*frame_info.width;
1743 frame_info.height=(*image)->rows+2*frame_info.height;
1744 frame_image=FrameImage(*image,&frame_info,exception);
1745 if (frame_image == (Image *) NULL)
1746 break;
1747 *image=DestroyImage(*image);
1748 *image=frame_image;
1749 break;
1750 }
1751 if (LocaleCompare("function",option+1) == 0)
1752 {
1753 char
1754 *arguments,
1755 token[MaxTextExtent];
1756
1757 const char
1758 *p;
1759
1760 double
1761 *parameters;
1762
1763 MagickFunction
1764 function;
1765
cristybb503372010-05-27 20:51:26 +00001766 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001767 x;
1768
cristybb503372010-05-27 20:51:26 +00001769 size_t
cristy3ed852e2009-09-05 21:47:34 +00001770 number_parameters;
1771
1772 /*
1773 Function Modify Image Values
1774 */
cristy6b3da3a2010-06-20 02:21:46 +00001775 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001776 function=(MagickFunction) ParseMagickOption(MagickFunctionOptions,
1777 MagickFalse,argv[i+1]);
cristy6b3da3a2010-06-20 02:21:46 +00001778 arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
cristy3ed852e2009-09-05 21:47:34 +00001779 InheritException(exception,&(*image)->exception);
1780 if (arguments == (char *) NULL)
1781 break;
1782 p=(char *) arguments;
1783 for (x=0; *p != '\0'; x++)
1784 {
1785 GetMagickToken(p,&p,token);
1786 if (*token == ',')
1787 GetMagickToken(p,&p,token);
1788 }
cristybb503372010-05-27 20:51:26 +00001789 number_parameters=(size_t) x;
cristy3ed852e2009-09-05 21:47:34 +00001790 parameters=(double *) AcquireQuantumMemory(number_parameters,
1791 sizeof(*parameters));
1792 if (parameters == (double *) NULL)
1793 ThrowWandFatalException(ResourceLimitFatalError,
1794 "MemoryAllocationFailed",(*image)->filename);
1795 (void) ResetMagickMemory(parameters,0,number_parameters*
1796 sizeof(*parameters));
1797 p=(char *) arguments;
cristybb503372010-05-27 20:51:26 +00001798 for (x=0; (x < (ssize_t) number_parameters) && (*p != '\0'); x++)
cristy3ed852e2009-09-05 21:47:34 +00001799 {
1800 GetMagickToken(p,&p,token);
1801 if (*token == ',')
1802 GetMagickToken(p,&p,token);
cristyf2f27272009-12-17 14:48:46 +00001803 parameters[x]=StringToDouble(token);
cristy3ed852e2009-09-05 21:47:34 +00001804 }
1805 arguments=DestroyString(arguments);
1806 (void) FunctionImageChannel(*image,channel,function,
1807 number_parameters,parameters,exception);
1808 parameters=(double *) RelinquishMagickMemory(parameters);
1809 break;
1810 }
1811 break;
1812 }
1813 case 'g':
1814 {
1815 if (LocaleCompare("gamma",option+1) == 0)
1816 {
1817 /*
1818 Gamma image.
1819 */
cristy6b3da3a2010-06-20 02:21:46 +00001820 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001821 if (*option == '+')
cristyf2f27272009-12-17 14:48:46 +00001822 (*image)->gamma=StringToDouble(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00001823 else
1824 {
1825 if (strchr(argv[i+1],',') != (char *) NULL)
1826 (void) GammaImage(*image,argv[i+1]);
1827 else
cristya5447be2010-01-11 00:20:51 +00001828 (void) GammaImageChannel(*image,channel,
1829 StringToDouble(argv[i+1]));
cristy3ed852e2009-09-05 21:47:34 +00001830 InheritException(exception,&(*image)->exception);
1831 }
1832 break;
1833 }
1834 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
1835 (LocaleCompare("gaussian",option+1) == 0))
1836 {
1837 Image
1838 *gaussian_image;
1839
1840 /*
1841 Gaussian blur image.
1842 */
cristy6b3da3a2010-06-20 02:21:46 +00001843 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001844 flags=ParseGeometry(argv[i+1],&geometry_info);
1845 if ((flags & SigmaValue) == 0)
1846 geometry_info.sigma=1.0;
1847 gaussian_image=GaussianBlurImageChannel(*image,channel,
1848 geometry_info.rho,geometry_info.sigma,exception);
1849 if (gaussian_image == (Image *) NULL)
1850 break;
1851 *image=DestroyImage(*image);
1852 *image=gaussian_image;
1853 break;
1854 }
1855 if (LocaleCompare("geometry",option+1) == 0)
1856 {
cristy6b3da3a2010-06-20 02:21:46 +00001857 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001858 if (*option == '+')
1859 {
1860 if ((*image)->geometry != (char *) NULL)
1861 (*image)->geometry=DestroyString((*image)->geometry);
1862 break;
1863 }
1864 flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
1865 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
1866 (void) CloneString(&(*image)->geometry,argv[i+1]);
1867 else
1868 {
1869 Image
cristy15b98cd2010-09-12 19:42:50 +00001870 *resize_image;
cristy3ed852e2009-09-05 21:47:34 +00001871
1872 /*
1873 Resize image.
1874 */
cristy15b98cd2010-09-12 19:42:50 +00001875 resize_image=ResizeImage(*image,geometry.width,geometry.height,
1876 (*image)->filter,(*image)->blur,exception);
1877 if (resize_image == (Image *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001878 break;
1879 *image=DestroyImage(*image);
cristy15b98cd2010-09-12 19:42:50 +00001880 *image=resize_image;
cristy3ed852e2009-09-05 21:47:34 +00001881 }
1882 break;
1883 }
1884 if (LocaleCompare("gravity",option+1) == 0)
1885 {
1886 if (*option == '+')
1887 {
1888 draw_info->gravity=UndefinedGravity;
1889 break;
1890 }
1891 draw_info->gravity=(GravityType) ParseMagickOption(
1892 MagickGravityOptions,MagickFalse,argv[i+1]);
1893 break;
1894 }
1895 break;
1896 }
1897 case 'h':
1898 {
1899 if (LocaleCompare("highlight-color",option+1) == 0)
1900 {
1901 (void) SetImageArtifact(*image,option+1,argv[i+1]);
1902 break;
1903 }
1904 break;
1905 }
1906 case 'i':
1907 {
1908 if (LocaleCompare("identify",option+1) == 0)
1909 {
1910 char
1911 *text;
1912
cristy6b3da3a2010-06-20 02:21:46 +00001913 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001914 if (format == (char *) NULL)
1915 {
cristy6b3da3a2010-06-20 02:21:46 +00001916 (void) IdentifyImage(*image,stdout,mogrify_info->verbose);
cristy3ed852e2009-09-05 21:47:34 +00001917 InheritException(exception,&(*image)->exception);
1918 break;
1919 }
cristy6b3da3a2010-06-20 02:21:46 +00001920 text=InterpretImageProperties(mogrify_info,*image,format);
cristy3ed852e2009-09-05 21:47:34 +00001921 InheritException(exception,&(*image)->exception);
1922 if (text == (char *) NULL)
1923 break;
1924 (void) fputs(text,stdout);
1925 (void) fputc('\n',stdout);
1926 text=DestroyString(text);
1927 break;
1928 }
1929 if (LocaleCompare("implode",option+1) == 0)
1930 {
1931 Image
1932 *implode_image;
1933
1934 /*
1935 Implode image.
1936 */
cristy6b3da3a2010-06-20 02:21:46 +00001937 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001938 (void) ParseGeometry(argv[i+1],&geometry_info);
1939 implode_image=ImplodeImage(*image,geometry_info.rho,exception);
1940 if (implode_image == (Image *) NULL)
1941 break;
1942 *image=DestroyImage(*image);
1943 *image=implode_image;
1944 break;
1945 }
cristyb32b90a2009-09-07 21:45:48 +00001946 if (LocaleCompare("interline-spacing",option+1) == 0)
1947 {
1948 if (*option == '+')
1949 (void) ParseGeometry("0",&geometry_info);
1950 else
1951 (void) ParseGeometry(argv[i+1],&geometry_info);
1952 draw_info->interline_spacing=geometry_info.rho;
1953 break;
1954 }
cristy3ed852e2009-09-05 21:47:34 +00001955 if (LocaleCompare("interword-spacing",option+1) == 0)
1956 {
1957 if (*option == '+')
1958 (void) ParseGeometry("0",&geometry_info);
1959 else
1960 (void) ParseGeometry(argv[i+1],&geometry_info);
1961 draw_info->interword_spacing=geometry_info.rho;
1962 break;
1963 }
1964 break;
1965 }
1966 case 'k':
1967 {
1968 if (LocaleCompare("kerning",option+1) == 0)
1969 {
1970 if (*option == '+')
1971 (void) ParseGeometry("0",&geometry_info);
1972 else
1973 (void) ParseGeometry(argv[i+1],&geometry_info);
1974 draw_info->kerning=geometry_info.rho;
1975 break;
1976 }
1977 break;
1978 }
1979 case 'l':
1980 {
cristydf81b992011-02-27 14:33:24 +00001981 if (LocaleCompare("label",option+1) == 0)
1982 {
1983 if (*option == '+')
1984 {
cristy3fb6d772011-02-27 15:13:43 +00001985 (void) DeleteImageProperty(*image,option+1);
cristydf81b992011-02-27 14:33:24 +00001986 break;
1987 }
cristy3fb6d772011-02-27 15:13:43 +00001988 (void) SetImageProperty(*image,option+1,argv[i+1]);
cristydf81b992011-02-27 14:33:24 +00001989 break;
1990 }
cristy3ed852e2009-09-05 21:47:34 +00001991 if (LocaleCompare("lat",option+1) == 0)
1992 {
1993 Image
1994 *threshold_image;
1995
1996 /*
1997 Local adaptive threshold image.
1998 */
cristy6b3da3a2010-06-20 02:21:46 +00001999 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002000 flags=ParseGeometry(argv[i+1],&geometry_info);
2001 if ((flags & PercentValue) != 0)
2002 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
cristybb503372010-05-27 20:51:26 +00002003 threshold_image=AdaptiveThresholdImage(*image,(size_t)
2004 geometry_info.rho,(size_t) geometry_info.sigma,
2005 (ssize_t) geometry_info.xi,exception);
cristy3ed852e2009-09-05 21:47:34 +00002006 if (threshold_image == (Image *) NULL)
2007 break;
2008 *image=DestroyImage(*image);
2009 *image=threshold_image;
2010 break;
2011 }
2012 if (LocaleCompare("level",option+1) == 0)
2013 {
cristy3ed852e2009-09-05 21:47:34 +00002014 MagickRealType
2015 black_point,
2016 gamma,
2017 white_point;
2018
2019 MagickStatusType
2020 flags;
2021
2022 /*
2023 Parse levels.
2024 */
cristy6b3da3a2010-06-20 02:21:46 +00002025 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002026 flags=ParseGeometry(argv[i+1],&geometry_info);
2027 black_point=geometry_info.rho;
2028 white_point=(MagickRealType) QuantumRange;
2029 if ((flags & SigmaValue) != 0)
2030 white_point=geometry_info.sigma;
2031 gamma=1.0;
2032 if ((flags & XiValue) != 0)
2033 gamma=geometry_info.xi;
2034 if ((flags & PercentValue) != 0)
2035 {
2036 black_point*=(MagickRealType) (QuantumRange/100.0);
2037 white_point*=(MagickRealType) (QuantumRange/100.0);
2038 }
2039 if ((flags & SigmaValue) == 0)
2040 white_point=(MagickRealType) QuantumRange-black_point;
2041 if ((*option == '+') || ((flags & AspectValue) != 0))
2042 (void) LevelizeImageChannel(*image,channel,black_point,
2043 white_point,gamma);
2044 else
2045 (void) LevelImageChannel(*image,channel,black_point,white_point,
2046 gamma);
2047 InheritException(exception,&(*image)->exception);
2048 break;
2049 }
2050 if (LocaleCompare("level-colors",option+1) == 0)
2051 {
2052 char
2053 token[MaxTextExtent];
2054
2055 const char
2056 *p;
2057
2058 MagickPixelPacket
2059 black_point,
2060 white_point;
2061
2062 p=(const char *) argv[i+1];
2063 GetMagickToken(p,&p,token); /* get black point color */
cristyee0f8d72009-09-19 00:58:29 +00002064 if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
cristy3ed852e2009-09-05 21:47:34 +00002065 (void) QueryMagickColor(token,&black_point,exception);
2066 else
cristyee0f8d72009-09-19 00:58:29 +00002067 (void) QueryMagickColor("#000000",&black_point,exception);
cristy3ed852e2009-09-05 21:47:34 +00002068 if (isalpha((int) token[0]) || (token[0] == '#'))
2069 GetMagickToken(p,&p,token);
cristyee0f8d72009-09-19 00:58:29 +00002070 if (*token == '\0')
cristy3ed852e2009-09-05 21:47:34 +00002071 white_point=black_point; /* set everything to that color */
2072 else
2073 {
2074 /*
2075 Get white point color.
2076 */
cristyee0f8d72009-09-19 00:58:29 +00002077 if ((isalpha((int) *token) == 0) && ((*token == '#') == 0))
cristy3ed852e2009-09-05 21:47:34 +00002078 GetMagickToken(p,&p,token);
cristyee0f8d72009-09-19 00:58:29 +00002079 if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
cristy3ed852e2009-09-05 21:47:34 +00002080 (void) QueryMagickColor(token,&white_point,exception);
2081 else
cristyee0f8d72009-09-19 00:58:29 +00002082 (void) QueryMagickColor("#ffffff",&white_point,exception);
cristy3ed852e2009-09-05 21:47:34 +00002083 }
cristy74fe8f12009-10-03 19:09:01 +00002084 (void) LevelColorsImageChannel(*image,channel,&black_point,
2085 &white_point,*option == '+' ? MagickTrue : MagickFalse);
cristy3ed852e2009-09-05 21:47:34 +00002086 break;
2087 }
2088 if (LocaleCompare("linear-stretch",option+1) == 0)
2089 {
2090 double
2091 black_point,
2092 white_point;
2093
cristy3ed852e2009-09-05 21:47:34 +00002094 MagickStatusType
2095 flags;
2096
cristy6b3da3a2010-06-20 02:21:46 +00002097 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002098 flags=ParseGeometry(argv[i+1],&geometry_info);
2099 black_point=geometry_info.rho;
2100 white_point=(MagickRealType) (*image)->columns*(*image)->rows;
2101 if ((flags & SigmaValue) != 0)
2102 white_point=geometry_info.sigma;
2103 if ((flags & PercentValue) != 0)
2104 {
2105 black_point*=(double) (*image)->columns*(*image)->rows/100.0;
2106 white_point*=(double) (*image)->columns*(*image)->rows/100.0;
2107 }
2108 if ((flags & SigmaValue) == 0)
2109 white_point=(MagickRealType) (*image)->columns*(*image)->rows-
2110 black_point;
2111 (void) LinearStretchImage(*image,black_point,white_point);
2112 InheritException(exception,&(*image)->exception);
2113 break;
2114 }
2115 if (LocaleCompare("linewidth",option+1) == 0)
2116 {
cristyf2f27272009-12-17 14:48:46 +00002117 draw_info->stroke_width=StringToDouble(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00002118 break;
2119 }
2120 if (LocaleCompare("liquid-rescale",option+1) == 0)
2121 {
2122 Image
2123 *resize_image;
2124
2125 /*
2126 Liquid rescale image.
2127 */
cristy6b3da3a2010-06-20 02:21:46 +00002128 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002129 flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2130 if ((flags & XValue) == 0)
2131 geometry.x=1;
2132 if ((flags & YValue) == 0)
2133 geometry.y=0;
2134 resize_image=LiquidRescaleImage(*image,geometry.width,
2135 geometry.height,1.0*geometry.x,1.0*geometry.y,exception);
2136 if (resize_image == (Image *) NULL)
2137 break;
2138 *image=DestroyImage(*image);
2139 *image=resize_image;
2140 break;
2141 }
2142 if (LocaleCompare("lowlight-color",option+1) == 0)
2143 {
2144 (void) SetImageArtifact(*image,option+1,argv[i+1]);
2145 break;
2146 }
2147 break;
2148 }
2149 case 'm':
2150 {
2151 if (LocaleCompare("map",option+1) == 0)
2152 {
2153 Image
2154 *remap_image;
2155
2156 /*
2157 Transform image colors to match this set of colors.
2158 */
cristy6b3da3a2010-06-20 02:21:46 +00002159 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002160 if (*option == '+')
2161 break;
cristy6b3da3a2010-06-20 02:21:46 +00002162 remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
cristy3ed852e2009-09-05 21:47:34 +00002163 if (remap_image == (Image *) NULL)
2164 break;
2165 (void) RemapImage(quantize_info,*image,remap_image);
2166 InheritException(exception,&(*image)->exception);
2167 remap_image=DestroyImage(remap_image);
2168 break;
2169 }
2170 if (LocaleCompare("mask",option+1) == 0)
2171 {
2172 Image
2173 *mask;
2174
cristy6b3da3a2010-06-20 02:21:46 +00002175 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002176 if (*option == '+')
2177 {
2178 /*
2179 Remove a mask.
2180 */
2181 (void) SetImageMask(*image,(Image *) NULL);
2182 InheritException(exception,&(*image)->exception);
2183 break;
2184 }
2185 /*
2186 Set the image mask.
2187 */
cristy6b3da3a2010-06-20 02:21:46 +00002188 mask=GetImageCache(mogrify_info,argv[i+1],exception);
cristy3ed852e2009-09-05 21:47:34 +00002189 if (mask == (Image *) NULL)
2190 break;
2191 (void) SetImageMask(*image,mask);
2192 mask=DestroyImage(mask);
2193 InheritException(exception,&(*image)->exception);
2194 break;
2195 }
2196 if (LocaleCompare("matte",option+1) == 0)
2197 {
2198 (void) SetImageAlphaChannel(*image,(*option == '-') ?
2199 SetAlphaChannel : DeactivateAlphaChannel );
2200 InheritException(exception,&(*image)->exception);
2201 break;
2202 }
2203 if (LocaleCompare("median",option+1) == 0)
2204 {
2205 Image
2206 *median_image;
2207
2208 /*
2209 Median filter image.
2210 */
cristy6b3da3a2010-06-20 02:21:46 +00002211 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002212 (void) ParseGeometry(argv[i+1],&geometry_info);
2213 median_image=MedianFilterImage(*image,geometry_info.rho,exception);
2214 if (median_image == (Image *) NULL)
2215 break;
2216 *image=DestroyImage(*image);
2217 *image=median_image;
2218 break;
2219 }
cristy69ec32d2011-02-27 23:57:09 +00002220 if (LocaleCompare("mode",option+1) == 0)
2221 {
2222 Image
2223 *mode_image;
2224
2225 /*
2226 Mode image.
2227 */
2228 (void) SyncImageSettings(mogrify_info,*image);
2229 (void) ParseGeometry(argv[i+1],&geometry_info);
2230 mode_image=ModeImage(*image,geometry_info.rho,exception);
2231 if (mode_image == (Image *) NULL)
2232 break;
2233 *image=DestroyImage(*image);
2234 *image=mode_image;
2235 break;
2236 }
cristy3ed852e2009-09-05 21:47:34 +00002237 if (LocaleCompare("modulate",option+1) == 0)
2238 {
cristy6b3da3a2010-06-20 02:21:46 +00002239 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002240 (void) ModulateImage(*image,argv[i+1]);
2241 InheritException(exception,&(*image)->exception);
2242 break;
2243 }
2244 if (LocaleCompare("monitor",option+1) == 0)
2245 {
cristy7d34ef22010-03-25 01:11:22 +00002246 if (*option == '+')
2247 {
2248 (void) SetImageProgressMonitor(*image,
2249 (MagickProgressMonitor) NULL,(void *) NULL);
2250 break;
2251 }
cristy3ed852e2009-09-05 21:47:34 +00002252 (void) SetImageProgressMonitor(*image,MonitorProgress,
2253 (void *) NULL);
2254 break;
2255 }
2256 if (LocaleCompare("monochrome",option+1) == 0)
2257 {
cristy6b3da3a2010-06-20 02:21:46 +00002258 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002259 (void) SetImageType(*image,BilevelType);
2260 InheritException(exception,&(*image)->exception);
2261 break;
2262 }
anthony29188a82010-01-22 10:12:34 +00002263 if (LocaleCompare("morphology",option+1) == 0)
2264 {
anthony29188a82010-01-22 10:12:34 +00002265 char
2266 token[MaxTextExtent];
2267
2268 const char
2269 *p;
2270
cristye96405a2010-05-19 02:24:31 +00002271 Image
2272 *morphology_image;
2273
2274 KernelInfo
2275 *kernel;
2276
cristybb503372010-05-27 20:51:26 +00002277 ssize_t
anthony29188a82010-01-22 10:12:34 +00002278 iterations;
2279
cristye96405a2010-05-19 02:24:31 +00002280 MorphologyMethod
2281 method;
2282
anthony29188a82010-01-22 10:12:34 +00002283 /*
2284 Morphological Image Operation
2285 */
cristy6b3da3a2010-06-20 02:21:46 +00002286 (void) SyncImageSettings(mogrify_info,*image);
anthony29188a82010-01-22 10:12:34 +00002287 p=argv[i+1];
2288 GetMagickToken(p,&p,token);
2289 method=(MorphologyMethod) ParseMagickOption(MagickMorphologyOptions,
cristyd2c1e1e2010-05-08 01:05:44 +00002290 MagickFalse,token);
cristyef656912010-03-05 19:54:59 +00002291 iterations=1L;
anthony29188a82010-01-22 10:12:34 +00002292 GetMagickToken(p,&p,token);
cristyef656912010-03-05 19:54:59 +00002293 if ((*p == ':') || (*p == ','))
anthony29188a82010-01-22 10:12:34 +00002294 GetMagickToken(p,&p,token);
cristyef656912010-03-05 19:54:59 +00002295 if ((*p != '\0'))
cristy32c2aea2010-12-01 01:00:50 +00002296 iterations=(ssize_t) StringToLong(p);
anthony29188a82010-01-22 10:12:34 +00002297 kernel=AcquireKernelInfo(argv[i+2]);
2298 if (kernel == (KernelInfo *) NULL)
cristye96405a2010-05-19 02:24:31 +00002299 {
2300 (void) ThrowMagickException(exception,GetMagickModule(),
2301 OptionError,"UnabletoParseKernel","morphology");
2302 status=MagickFalse;
2303 break;
2304 }
anthony29188a82010-01-22 10:12:34 +00002305 morphology_image=MorphologyImageChannel(*image,channel,method,
cristy02d5b4f2010-02-01 01:08:27 +00002306 iterations,kernel,exception);
anthony83ba99b2010-01-24 08:48:15 +00002307 kernel=DestroyKernelInfo(kernel);
anthony29188a82010-01-22 10:12:34 +00002308 if (morphology_image == (Image *) NULL)
2309 break;
2310 *image=DestroyImage(*image);
2311 *image=morphology_image;
2312 break;
2313 }
cristy3ed852e2009-09-05 21:47:34 +00002314 if (LocaleCompare("motion-blur",option+1) == 0)
2315 {
2316 Image
2317 *blur_image;
2318
2319 /*
2320 Motion blur image.
2321 */
cristy6b3da3a2010-06-20 02:21:46 +00002322 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002323 flags=ParseGeometry(argv[i+1],&geometry_info);
2324 if ((flags & SigmaValue) == 0)
2325 geometry_info.sigma=1.0;
2326 blur_image=MotionBlurImageChannel(*image,channel,geometry_info.rho,
2327 geometry_info.sigma,geometry_info.xi,exception);
2328 if (blur_image == (Image *) NULL)
2329 break;
2330 *image=DestroyImage(*image);
2331 *image=blur_image;
2332 break;
2333 }
2334 break;
2335 }
2336 case 'n':
2337 {
2338 if (LocaleCompare("negate",option+1) == 0)
2339 {
cristy6b3da3a2010-06-20 02:21:46 +00002340 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002341 (void) NegateImageChannel(*image,channel,*option == '+' ?
2342 MagickTrue : MagickFalse);
2343 InheritException(exception,&(*image)->exception);
2344 break;
2345 }
2346 if (LocaleCompare("noise",option+1) == 0)
2347 {
2348 Image
2349 *noisy_image;
2350
cristy6b3da3a2010-06-20 02:21:46 +00002351 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002352 if (*option == '-')
2353 {
2354 (void) ParseGeometry(argv[i+1],&geometry_info);
2355 noisy_image=ReduceNoiseImage(*image,geometry_info.rho,
2356 exception);
2357 }
2358 else
2359 {
2360 NoiseType
2361 noise;
2362
2363 noise=(NoiseType) ParseMagickOption(MagickNoiseOptions,
2364 MagickFalse,argv[i+1]);
2365 noisy_image=AddNoiseImageChannel(*image,channel,noise,
2366 exception);
2367 }
2368 if (noisy_image == (Image *) NULL)
2369 break;
2370 *image=DestroyImage(*image);
2371 *image=noisy_image;
2372 break;
2373 }
2374 if (LocaleCompare("normalize",option+1) == 0)
2375 {
cristy6b3da3a2010-06-20 02:21:46 +00002376 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002377 (void) NormalizeImageChannel(*image,channel);
2378 InheritException(exception,&(*image)->exception);
2379 break;
2380 }
2381 break;
2382 }
2383 case 'o':
2384 {
2385 if (LocaleCompare("opaque",option+1) == 0)
2386 {
2387 MagickPixelPacket
2388 target;
2389
cristy6b3da3a2010-06-20 02:21:46 +00002390 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002391 (void) QueryMagickColor(argv[i+1],&target,exception);
2392 (void) OpaquePaintImageChannel(*image,channel,&target,&fill,
2393 *option == '-' ? MagickFalse : MagickTrue);
2394 break;
2395 }
2396 if (LocaleCompare("ordered-dither",option+1) == 0)
2397 {
cristy6b3da3a2010-06-20 02:21:46 +00002398 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002399 (void) OrderedPosterizeImageChannel(*image,channel,argv[i+1],
2400 exception);
2401 break;
2402 }
2403 break;
2404 }
2405 case 'p':
2406 {
2407 if (LocaleCompare("paint",option+1) == 0)
2408 {
2409 Image
2410 *paint_image;
2411
2412 /*
2413 Oil paint image.
2414 */
cristy6b3da3a2010-06-20 02:21:46 +00002415 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002416 (void) ParseGeometry(argv[i+1],&geometry_info);
2417 paint_image=OilPaintImage(*image,geometry_info.rho,exception);
2418 if (paint_image == (Image *) NULL)
2419 break;
2420 *image=DestroyImage(*image);
2421 *image=paint_image;
2422 break;
2423 }
2424 if (LocaleCompare("pen",option+1) == 0)
2425 {
2426 if (*option == '+')
2427 {
2428 (void) QueryColorDatabase("none",&draw_info->fill,exception);
2429 break;
2430 }
2431 (void) QueryColorDatabase(argv[i+1],&draw_info->fill,exception);
2432 break;
2433 }
2434 if (LocaleCompare("pointsize",option+1) == 0)
2435 {
2436 if (*option == '+')
2437 (void) ParseGeometry("12",&geometry_info);
2438 else
2439 (void) ParseGeometry(argv[i+1],&geometry_info);
2440 draw_info->pointsize=geometry_info.rho;
2441 break;
2442 }
2443 if (LocaleCompare("polaroid",option+1) == 0)
2444 {
2445 double
2446 angle;
2447
2448 Image
2449 *polaroid_image;
2450
2451 RandomInfo
2452 *random_info;
2453
2454 /*
2455 Simulate a Polaroid picture.
2456 */
cristy6b3da3a2010-06-20 02:21:46 +00002457 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002458 random_info=AcquireRandomInfo();
2459 angle=22.5*(GetPseudoRandomValue(random_info)-0.5);
2460 random_info=DestroyRandomInfo(random_info);
2461 if (*option == '-')
2462 {
2463 SetGeometryInfo(&geometry_info);
2464 flags=ParseGeometry(argv[i+1],&geometry_info);
2465 angle=geometry_info.rho;
2466 }
2467 polaroid_image=PolaroidImage(*image,draw_info,angle,exception);
2468 if (polaroid_image == (Image *) NULL)
2469 break;
2470 *image=DestroyImage(*image);
2471 *image=polaroid_image;
2472 break;
2473 }
2474 if (LocaleCompare("posterize",option+1) == 0)
2475 {
2476 /*
2477 Posterize image.
2478 */
cristy6b3da3a2010-06-20 02:21:46 +00002479 (void) SyncImageSettings(mogrify_info,*image);
cristye27293e2009-12-18 02:53:20 +00002480 (void) PosterizeImage(*image,StringToUnsignedLong(argv[i+1]),
cristy3ed852e2009-09-05 21:47:34 +00002481 quantize_info->dither);
2482 InheritException(exception,&(*image)->exception);
2483 break;
2484 }
2485 if (LocaleCompare("preview",option+1) == 0)
2486 {
2487 Image
2488 *preview_image;
2489
2490 PreviewType
2491 preview_type;
2492
2493 /*
2494 Preview image.
2495 */
cristy6b3da3a2010-06-20 02:21:46 +00002496 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002497 if (*option == '+')
2498 preview_type=UndefinedPreview;
2499 else
2500 preview_type=(PreviewType) ParseMagickOption(MagickPreviewOptions,
2501 MagickFalse,argv[i+1]);
2502 preview_image=PreviewImage(*image,preview_type,exception);
2503 if (preview_image == (Image *) NULL)
2504 break;
2505 *image=DestroyImage(*image);
2506 *image=preview_image;
2507 break;
2508 }
2509 if (LocaleCompare("profile",option+1) == 0)
2510 {
2511 const char
2512 *name;
2513
2514 const StringInfo
2515 *profile;
2516
2517 Image
2518 *profile_image;
2519
2520 ImageInfo
2521 *profile_info;
2522
cristy6b3da3a2010-06-20 02:21:46 +00002523 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002524 if (*option == '+')
2525 {
2526 /*
2527 Remove a profile from the image.
2528 */
2529 (void) ProfileImage(*image,argv[i+1],(const unsigned char *)
2530 NULL,0,MagickTrue);
2531 InheritException(exception,&(*image)->exception);
2532 break;
2533 }
2534 /*
2535 Associate a profile with the image.
2536 */
cristy6b3da3a2010-06-20 02:21:46 +00002537 profile_info=CloneImageInfo(mogrify_info);
cristy3ed852e2009-09-05 21:47:34 +00002538 profile=GetImageProfile(*image,"iptc");
2539 if (profile != (StringInfo *) NULL)
2540 profile_info->profile=(void *) CloneStringInfo(profile);
2541 profile_image=GetImageCache(profile_info,argv[i+1],exception);
2542 profile_info=DestroyImageInfo(profile_info);
2543 if (profile_image == (Image *) NULL)
2544 {
cristy3ed852e2009-09-05 21:47:34 +00002545 StringInfo
2546 *profile;
2547
cristy6b3da3a2010-06-20 02:21:46 +00002548 profile_info=CloneImageInfo(mogrify_info);
cristy071dd7b2010-04-09 13:04:54 +00002549 (void) CopyMagickString(profile_info->filename,argv[i+1],
2550 MaxTextExtent);
2551 profile=FileToStringInfo(profile_info->filename,~0UL,exception);
cristy3ed852e2009-09-05 21:47:34 +00002552 if (profile != (StringInfo *) NULL)
2553 {
cristy071dd7b2010-04-09 13:04:54 +00002554 (void) ProfileImage(*image,profile_info->magick,
cristybb503372010-05-27 20:51:26 +00002555 GetStringInfoDatum(profile),(size_t)
cristy071dd7b2010-04-09 13:04:54 +00002556 GetStringInfoLength(profile),MagickFalse);
cristy3ed852e2009-09-05 21:47:34 +00002557 profile=DestroyStringInfo(profile);
2558 }
cristy071dd7b2010-04-09 13:04:54 +00002559 profile_info=DestroyImageInfo(profile_info);
cristy3ed852e2009-09-05 21:47:34 +00002560 break;
2561 }
2562 ResetImageProfileIterator(profile_image);
2563 name=GetNextImageProfile(profile_image);
2564 while (name != (const char *) NULL)
2565 {
2566 profile=GetImageProfile(profile_image,name);
2567 if (profile != (StringInfo *) NULL)
2568 (void) ProfileImage(*image,name,GetStringInfoDatum(profile),
cristybb503372010-05-27 20:51:26 +00002569 (size_t) GetStringInfoLength(profile),MagickFalse);
cristy3ed852e2009-09-05 21:47:34 +00002570 name=GetNextImageProfile(profile_image);
2571 }
2572 profile_image=DestroyImage(profile_image);
2573 break;
2574 }
2575 break;
2576 }
2577 case 'q':
2578 {
2579 if (LocaleCompare("quantize",option+1) == 0)
2580 {
2581 if (*option == '+')
2582 {
2583 quantize_info->colorspace=UndefinedColorspace;
2584 break;
2585 }
2586 quantize_info->colorspace=(ColorspaceType) ParseMagickOption(
2587 MagickColorspaceOptions,MagickFalse,argv[i+1]);
2588 break;
2589 }
2590 break;
2591 }
2592 case 'r':
2593 {
2594 if (LocaleCompare("radial-blur",option+1) == 0)
2595 {
2596 Image
2597 *blur_image;
2598
2599 /*
2600 Radial blur image.
2601 */
cristy6b3da3a2010-06-20 02:21:46 +00002602 (void) SyncImageSettings(mogrify_info,*image);
cristya5447be2010-01-11 00:20:51 +00002603 blur_image=RadialBlurImageChannel(*image,channel,
2604 StringToDouble(argv[i+1]),exception);
cristy3ed852e2009-09-05 21:47:34 +00002605 if (blur_image == (Image *) NULL)
2606 break;
2607 *image=DestroyImage(*image);
2608 *image=blur_image;
2609 break;
2610 }
2611 if (LocaleCompare("raise",option+1) == 0)
2612 {
2613 /*
2614 Surround image with a raise of solid color.
2615 */
2616 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2617 if ((flags & SigmaValue) == 0)
2618 geometry.height=geometry.width;
2619 (void) RaiseImage(*image,&geometry,*option == '-' ? MagickTrue :
2620 MagickFalse);
2621 InheritException(exception,&(*image)->exception);
2622 break;
2623 }
2624 if (LocaleCompare("random-threshold",option+1) == 0)
2625 {
2626 /*
2627 Threshold image.
2628 */
cristy6b3da3a2010-06-20 02:21:46 +00002629 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002630 (void) RandomThresholdImageChannel(*image,channel,argv[i+1],
2631 exception);
2632 break;
2633 }
2634 if (LocaleCompare("recolor",option+1) == 0)
2635 {
cristy3ed852e2009-09-05 21:47:34 +00002636 Image
cristyf055ae42010-04-02 23:01:38 +00002637 *color_image;
cristy3ed852e2009-09-05 21:47:34 +00002638
cristyf055ae42010-04-02 23:01:38 +00002639 KernelInfo
2640 *kernel;
cristy3ed852e2009-09-05 21:47:34 +00002641
cristy6b3da3a2010-06-20 02:21:46 +00002642 (void) SyncImageSettings(mogrify_info,*image);
cristyf055ae42010-04-02 23:01:38 +00002643 kernel=AcquireKernelInfo(argv[i+1]);
2644 if (kernel == (KernelInfo *) NULL)
2645 break;
2646 color_image=ColorMatrixImage(*image,kernel,exception);
2647 kernel=DestroyKernelInfo(kernel);
2648 if (color_image == (Image *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002649 break;
2650 *image=DestroyImage(*image);
cristyf055ae42010-04-02 23:01:38 +00002651 *image=color_image;
cristy3ed852e2009-09-05 21:47:34 +00002652 break;
2653 }
2654 if (LocaleCompare("region",option+1) == 0)
2655 {
2656 Image
2657 *crop_image;
2658
cristy6b3da3a2010-06-20 02:21:46 +00002659 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002660 if (region_image != (Image *) NULL)
2661 {
2662 /*
2663 Composite region.
2664 */
2665 (void) CompositeImage(region_image,(*image)->matte !=
2666 MagickFalse ? OverCompositeOp : CopyCompositeOp,*image,
2667 region_geometry.x,region_geometry.y);
2668 InheritException(exception,&region_image->exception);
2669 *image=DestroyImage(*image);
2670 *image=region_image;
2671 }
2672 if (*option == '+')
2673 {
2674 if (region_image != (Image *) NULL)
cristyb0a6e432010-10-09 13:26:15 +00002675 region_image=(Image *) NULL;
cristy3ed852e2009-09-05 21:47:34 +00002676 break;
2677 }
2678 /*
2679 Apply transformations to a selected region of the image.
2680 */
2681 (void) ParseGravityGeometry(*image,argv[i+1],&region_geometry,
2682 exception);
2683 crop_image=CropImage(*image,&region_geometry,exception);
2684 if (crop_image == (Image *) NULL)
2685 break;
2686 region_image=(*image);
2687 *image=crop_image;
2688 break;
2689 }
2690 if (LocaleCompare("render",option+1) == 0)
2691 {
cristy6b3da3a2010-06-20 02:21:46 +00002692 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002693 draw_info->render=(*option == '+') ? MagickTrue : MagickFalse;
2694 break;
2695 }
2696 if (LocaleCompare("remap",option+1) == 0)
2697 {
2698 Image
2699 *remap_image;
2700
2701 /*
2702 Transform image colors to match this set of colors.
2703 */
cristy6b3da3a2010-06-20 02:21:46 +00002704 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002705 if (*option == '+')
2706 break;
cristy6b3da3a2010-06-20 02:21:46 +00002707 remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
cristy3ed852e2009-09-05 21:47:34 +00002708 if (remap_image == (Image *) NULL)
2709 break;
2710 (void) RemapImage(quantize_info,*image,remap_image);
2711 InheritException(exception,&(*image)->exception);
2712 remap_image=DestroyImage(remap_image);
2713 break;
2714 }
2715 if (LocaleCompare("repage",option+1) == 0)
2716 {
2717 if (*option == '+')
2718 {
2719 (void) ParseAbsoluteGeometry("0x0+0+0",&(*image)->page);
2720 break;
2721 }
2722 (void) ResetImagePage(*image,argv[i+1]);
2723 InheritException(exception,&(*image)->exception);
2724 break;
2725 }
2726 if (LocaleCompare("resample",option+1) == 0)
2727 {
2728 Image
2729 *resample_image;
2730
2731 /*
2732 Resample image.
2733 */
cristy6b3da3a2010-06-20 02:21:46 +00002734 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002735 flags=ParseGeometry(argv[i+1],&geometry_info);
2736 if ((flags & SigmaValue) == 0)
2737 geometry_info.sigma=geometry_info.rho;
2738 resample_image=ResampleImage(*image,geometry_info.rho,
2739 geometry_info.sigma,(*image)->filter,(*image)->blur,exception);
2740 if (resample_image == (Image *) NULL)
2741 break;
2742 *image=DestroyImage(*image);
2743 *image=resample_image;
2744 break;
2745 }
2746 if (LocaleCompare("resize",option+1) == 0)
2747 {
2748 Image
2749 *resize_image;
2750
2751 /*
2752 Resize image.
2753 */
cristy6b3da3a2010-06-20 02:21:46 +00002754 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002755 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2756 resize_image=ResizeImage(*image,geometry.width,geometry.height,
2757 (*image)->filter,(*image)->blur,exception);
2758 if (resize_image == (Image *) NULL)
2759 break;
2760 *image=DestroyImage(*image);
2761 *image=resize_image;
2762 break;
2763 }
cristy3ed852e2009-09-05 21:47:34 +00002764 if (LocaleCompare("roll",option+1) == 0)
2765 {
2766 Image
2767 *roll_image;
2768
2769 /*
2770 Roll image.
2771 */
cristy6b3da3a2010-06-20 02:21:46 +00002772 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002773 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2774 roll_image=RollImage(*image,geometry.x,geometry.y,exception);
2775 if (roll_image == (Image *) NULL)
2776 break;
2777 *image=DestroyImage(*image);
2778 *image=roll_image;
2779 break;
2780 }
2781 if (LocaleCompare("rotate",option+1) == 0)
2782 {
2783 char
2784 *geometry;
2785
2786 Image
2787 *rotate_image;
2788
2789 /*
2790 Check for conditional image rotation.
2791 */
cristy6b3da3a2010-06-20 02:21:46 +00002792 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002793 if (strchr(argv[i+1],'>') != (char *) NULL)
2794 if ((*image)->columns <= (*image)->rows)
2795 break;
2796 if (strchr(argv[i+1],'<') != (char *) NULL)
2797 if ((*image)->columns >= (*image)->rows)
2798 break;
2799 /*
2800 Rotate image.
2801 */
2802 geometry=ConstantString(argv[i+1]);
2803 (void) SubstituteString(&geometry,">","");
2804 (void) SubstituteString(&geometry,"<","");
2805 (void) ParseGeometry(geometry,&geometry_info);
2806 geometry=DestroyString(geometry);
2807 rotate_image=RotateImage(*image,geometry_info.rho,exception);
2808 if (rotate_image == (Image *) NULL)
2809 break;
2810 *image=DestroyImage(*image);
2811 *image=rotate_image;
2812 break;
2813 }
2814 break;
2815 }
2816 case 's':
2817 {
2818 if (LocaleCompare("sample",option+1) == 0)
2819 {
2820 Image
2821 *sample_image;
2822
2823 /*
2824 Sample image with pixel replication.
2825 */
cristy6b3da3a2010-06-20 02:21:46 +00002826 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002827 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2828 sample_image=SampleImage(*image,geometry.width,geometry.height,
2829 exception);
2830 if (sample_image == (Image *) NULL)
2831 break;
2832 *image=DestroyImage(*image);
2833 *image=sample_image;
2834 break;
2835 }
2836 if (LocaleCompare("scale",option+1) == 0)
2837 {
2838 Image
2839 *scale_image;
2840
2841 /*
2842 Resize image.
2843 */
cristy6b3da3a2010-06-20 02:21:46 +00002844 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002845 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2846 scale_image=ScaleImage(*image,geometry.width,geometry.height,
2847 exception);
2848 if (scale_image == (Image *) NULL)
2849 break;
2850 *image=DestroyImage(*image);
2851 *image=scale_image;
2852 break;
2853 }
2854 if (LocaleCompare("selective-blur",option+1) == 0)
2855 {
2856 Image
2857 *blur_image;
2858
2859 /*
2860 Selectively blur pixels within a contrast threshold.
2861 */
cristy6b3da3a2010-06-20 02:21:46 +00002862 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002863 flags=ParseGeometry(argv[i+1],&geometry_info);
2864 if ((flags & PercentValue) != 0)
2865 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
2866 blur_image=SelectiveBlurImageChannel(*image,channel,
2867 geometry_info.rho,geometry_info.sigma,geometry_info.xi,exception);
2868 if (blur_image == (Image *) NULL)
2869 break;
2870 *image=DestroyImage(*image);
2871 *image=blur_image;
2872 break;
2873 }
2874 if (LocaleCompare("separate",option+1) == 0)
2875 {
2876 Image
2877 *separate_images;
2878
2879 /*
2880 Break channels into separate images.
2881 */
cristy6b3da3a2010-06-20 02:21:46 +00002882 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002883 separate_images=SeparateImages(*image,channel,exception);
2884 if (separate_images == (Image *) NULL)
2885 break;
2886 *image=DestroyImage(*image);
2887 *image=separate_images;
2888 break;
2889 }
2890 if (LocaleCompare("sepia-tone",option+1) == 0)
2891 {
2892 double
2893 threshold;
2894
2895 Image
2896 *sepia_image;
2897
2898 /*
2899 Sepia-tone image.
2900 */
cristy6b3da3a2010-06-20 02:21:46 +00002901 (void) SyncImageSettings(mogrify_info,*image);
cristyf2f27272009-12-17 14:48:46 +00002902 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
cristy3ed852e2009-09-05 21:47:34 +00002903 sepia_image=SepiaToneImage(*image,threshold,exception);
2904 if (sepia_image == (Image *) NULL)
2905 break;
2906 *image=DestroyImage(*image);
2907 *image=sepia_image;
2908 break;
2909 }
2910 if (LocaleCompare("segment",option+1) == 0)
2911 {
2912 /*
2913 Segment image.
2914 */
cristy6b3da3a2010-06-20 02:21:46 +00002915 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002916 flags=ParseGeometry(argv[i+1],&geometry_info);
2917 if ((flags & SigmaValue) == 0)
2918 geometry_info.sigma=1.0;
cristy7e6164a2010-07-22 20:43:57 +00002919 (void) SegmentImage(*image,(*image)->colorspace,
2920 mogrify_info->verbose,geometry_info.rho,geometry_info.sigma);
cristy3ed852e2009-09-05 21:47:34 +00002921 InheritException(exception,&(*image)->exception);
2922 break;
2923 }
2924 if (LocaleCompare("set",option+1) == 0)
2925 {
cristy6d9a1292010-05-31 14:17:06 +00002926 char
2927 *value;
2928
cristy3ed852e2009-09-05 21:47:34 +00002929 /*
2930 Set image option.
2931 */
cristy6d9a1292010-05-31 14:17:06 +00002932 if (*option == '+')
2933 {
2934 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2935 (void) DeleteImageRegistry(argv[i+1]+9);
2936 else
2937 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
cristy7e109582010-06-01 12:56:44 +00002938 {
cristy6b3da3a2010-06-20 02:21:46 +00002939 (void) DeleteImageOption(mogrify_info,argv[i+1]+7);
cristy7e109582010-06-01 12:56:44 +00002940 (void) DeleteImageArtifact(*image,argv[i+1]+7);
2941 }
cristy6d9a1292010-05-31 14:17:06 +00002942 else
2943 (void) DeleteImageProperty(*image,argv[i+1]);
2944 break;
2945 }
cristy6b3da3a2010-06-20 02:21:46 +00002946 value=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
cristy6d9a1292010-05-31 14:17:06 +00002947 if (value == (char *) NULL)
2948 break;
cristy3ed852e2009-09-05 21:47:34 +00002949 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
cristy6d9a1292010-05-31 14:17:06 +00002950 (void) SetImageRegistry(StringRegistryType,argv[i+1]+9,value,
2951 exception);
cristy3ed852e2009-09-05 21:47:34 +00002952 else
2953 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
cristy6d9a1292010-05-31 14:17:06 +00002954 {
cristy7f02ba12010-09-21 12:39:28 +00002955 (void) SetImageOption(image_info,argv[i+1]+7,value);
cristy6b3da3a2010-06-20 02:21:46 +00002956 (void) SetImageOption(mogrify_info,argv[i+1]+7,value);
cristy6d9a1292010-05-31 14:17:06 +00002957 (void) SetImageArtifact(*image,argv[i+1]+7,value);
2958 }
cristy3ed852e2009-09-05 21:47:34 +00002959 else
cristy6d9a1292010-05-31 14:17:06 +00002960 (void) SetImageProperty(*image,argv[i+1],value);
2961 value=DestroyString(value);
cristy3ed852e2009-09-05 21:47:34 +00002962 break;
2963 }
2964 if (LocaleCompare("shade",option+1) == 0)
2965 {
2966 Image
2967 *shade_image;
2968
2969 /*
2970 Shade image.
2971 */
cristy6b3da3a2010-06-20 02:21:46 +00002972 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002973 flags=ParseGeometry(argv[i+1],&geometry_info);
2974 if ((flags & SigmaValue) == 0)
2975 geometry_info.sigma=1.0;
2976 shade_image=ShadeImage(*image,(*option == '-') ? MagickTrue :
2977 MagickFalse,geometry_info.rho,geometry_info.sigma,exception);
2978 if (shade_image == (Image *) NULL)
2979 break;
2980 *image=DestroyImage(*image);
2981 *image=shade_image;
2982 break;
2983 }
2984 if (LocaleCompare("shadow",option+1) == 0)
2985 {
2986 Image
2987 *shadow_image;
2988
2989 /*
2990 Shadow image.
2991 */
cristy6b3da3a2010-06-20 02:21:46 +00002992 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002993 flags=ParseGeometry(argv[i+1],&geometry_info);
2994 if ((flags & SigmaValue) == 0)
2995 geometry_info.sigma=1.0;
2996 if ((flags & XiValue) == 0)
2997 geometry_info.xi=4.0;
2998 if ((flags & PsiValue) == 0)
2999 geometry_info.psi=4.0;
3000 shadow_image=ShadowImage(*image,geometry_info.rho,
cristybb503372010-05-27 20:51:26 +00003001 geometry_info.sigma,(ssize_t) ceil(geometry_info.xi-0.5),(ssize_t)
cristy0534a6b2010-03-18 01:19:38 +00003002 ceil(geometry_info.psi-0.5),exception);
cristy3ed852e2009-09-05 21:47:34 +00003003 if (shadow_image == (Image *) NULL)
3004 break;
3005 *image=DestroyImage(*image);
3006 *image=shadow_image;
3007 break;
3008 }
3009 if (LocaleCompare("sharpen",option+1) == 0)
3010 {
3011 Image
3012 *sharp_image;
3013
3014 /*
3015 Sharpen image.
3016 */
cristy6b3da3a2010-06-20 02:21:46 +00003017 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003018 flags=ParseGeometry(argv[i+1],&geometry_info);
3019 if ((flags & SigmaValue) == 0)
3020 geometry_info.sigma=1.0;
3021 sharp_image=SharpenImageChannel(*image,channel,geometry_info.rho,
3022 geometry_info.sigma,exception);
3023 if (sharp_image == (Image *) NULL)
3024 break;
3025 *image=DestroyImage(*image);
3026 *image=sharp_image;
3027 break;
3028 }
3029 if (LocaleCompare("shave",option+1) == 0)
3030 {
3031 Image
3032 *shave_image;
3033
3034 /*
3035 Shave the image edges.
3036 */
cristy6b3da3a2010-06-20 02:21:46 +00003037 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003038 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
3039 shave_image=ShaveImage(*image,&geometry,exception);
3040 if (shave_image == (Image *) NULL)
3041 break;
3042 *image=DestroyImage(*image);
3043 *image=shave_image;
3044 break;
3045 }
3046 if (LocaleCompare("shear",option+1) == 0)
3047 {
3048 Image
3049 *shear_image;
3050
3051 /*
3052 Shear image.
3053 */
cristy6b3da3a2010-06-20 02:21:46 +00003054 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003055 flags=ParseGeometry(argv[i+1],&geometry_info);
3056 if ((flags & SigmaValue) == 0)
3057 geometry_info.sigma=geometry_info.rho;
3058 shear_image=ShearImage(*image,geometry_info.rho,geometry_info.sigma,
3059 exception);
3060 if (shear_image == (Image *) NULL)
3061 break;
3062 *image=DestroyImage(*image);
3063 *image=shear_image;
3064 break;
3065 }
3066 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
3067 {
3068 /*
3069 Sigmoidal non-linearity contrast control.
3070 */
cristy6b3da3a2010-06-20 02:21:46 +00003071 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003072 flags=ParseGeometry(argv[i+1],&geometry_info);
3073 if ((flags & SigmaValue) == 0)
3074 geometry_info.sigma=(double) QuantumRange/2.0;
3075 if ((flags & PercentValue) != 0)
3076 geometry_info.sigma=(double) QuantumRange*geometry_info.sigma/
3077 100.0;
3078 (void) SigmoidalContrastImageChannel(*image,channel,
3079 (*option == '-') ? MagickTrue : MagickFalse,geometry_info.rho,
3080 geometry_info.sigma);
3081 InheritException(exception,&(*image)->exception);
3082 break;
3083 }
3084 if (LocaleCompare("sketch",option+1) == 0)
3085 {
3086 Image
3087 *sketch_image;
3088
3089 /*
3090 Sketch image.
3091 */
cristy6b3da3a2010-06-20 02:21:46 +00003092 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003093 flags=ParseGeometry(argv[i+1],&geometry_info);
3094 if ((flags & SigmaValue) == 0)
3095 geometry_info.sigma=1.0;
3096 sketch_image=SketchImage(*image,geometry_info.rho,
3097 geometry_info.sigma,geometry_info.xi,exception);
3098 if (sketch_image == (Image *) NULL)
3099 break;
3100 *image=DestroyImage(*image);
3101 *image=sketch_image;
3102 break;
3103 }
3104 if (LocaleCompare("solarize",option+1) == 0)
3105 {
3106 double
3107 threshold;
3108
cristy6b3da3a2010-06-20 02:21:46 +00003109 (void) SyncImageSettings(mogrify_info,*image);
cristyf2f27272009-12-17 14:48:46 +00003110 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
cristy3ed852e2009-09-05 21:47:34 +00003111 (void) SolarizeImage(*image,threshold);
3112 InheritException(exception,&(*image)->exception);
3113 break;
3114 }
3115 if (LocaleCompare("sparse-color",option+1) == 0)
3116 {
3117 Image
3118 *sparse_image;
3119
3120 SparseColorMethod
3121 method;
3122
3123 char
3124 *arguments;
3125
3126 /*
3127 Sparse Color Interpolated Gradient
3128 */
cristy6b3da3a2010-06-20 02:21:46 +00003129 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003130 method=(SparseColorMethod) ParseMagickOption(
3131 MagickSparseColorOptions,MagickFalse,argv[i+1]);
cristy6b3da3a2010-06-20 02:21:46 +00003132 arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
cristy3ed852e2009-09-05 21:47:34 +00003133 InheritException(exception,&(*image)->exception);
3134 if (arguments == (char *) NULL)
3135 break;
3136 sparse_image=SparseColorOption(*image,channel,method,arguments,
3137 option[0] == '+' ? MagickTrue : MagickFalse,exception);
3138 arguments=DestroyString(arguments);
3139 if (sparse_image == (Image *) NULL)
3140 break;
3141 *image=DestroyImage(*image);
3142 *image=sparse_image;
3143 break;
3144 }
3145 if (LocaleCompare("splice",option+1) == 0)
3146 {
3147 Image
3148 *splice_image;
3149
3150 /*
3151 Splice a solid color into the image.
3152 */
cristy6b3da3a2010-06-20 02:21:46 +00003153 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003154 (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
3155 splice_image=SpliceImage(*image,&geometry,exception);
3156 if (splice_image == (Image *) NULL)
3157 break;
3158 *image=DestroyImage(*image);
3159 *image=splice_image;
3160 break;
3161 }
3162 if (LocaleCompare("spread",option+1) == 0)
3163 {
3164 Image
3165 *spread_image;
3166
3167 /*
3168 Spread an image.
3169 */
cristy6b3da3a2010-06-20 02:21:46 +00003170 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003171 (void) ParseGeometry(argv[i+1],&geometry_info);
3172 spread_image=SpreadImage(*image,geometry_info.rho,exception);
3173 if (spread_image == (Image *) NULL)
3174 break;
3175 *image=DestroyImage(*image);
3176 *image=spread_image;
3177 break;
3178 }
3179 if (LocaleCompare("stretch",option+1) == 0)
3180 {
3181 if (*option == '+')
3182 {
3183 draw_info->stretch=UndefinedStretch;
3184 break;
3185 }
3186 draw_info->stretch=(StretchType) ParseMagickOption(
3187 MagickStretchOptions,MagickFalse,argv[i+1]);
3188 break;
3189 }
3190 if (LocaleCompare("strip",option+1) == 0)
3191 {
3192 /*
3193 Strip image of profiles and comments.
3194 */
cristy6b3da3a2010-06-20 02:21:46 +00003195 (void) SyncImageSettings(mogrify_info,*image);
glennrp3dae5ae2010-12-23 22:42:52 +00003196 (void) StripImage(*image);
cristy3ed852e2009-09-05 21:47:34 +00003197 InheritException(exception,&(*image)->exception);
3198 break;
3199 }
3200 if (LocaleCompare("stroke",option+1) == 0)
3201 {
3202 ExceptionInfo
3203 *sans;
3204
3205 if (*option == '+')
3206 {
3207 (void) QueryColorDatabase("none",&draw_info->stroke,exception);
3208 if (draw_info->stroke_pattern != (Image *) NULL)
3209 draw_info->stroke_pattern=DestroyImage(
3210 draw_info->stroke_pattern);
3211 break;
3212 }
3213 sans=AcquireExceptionInfo();
3214 status=QueryColorDatabase(argv[i+1],&draw_info->stroke,sans);
3215 sans=DestroyExceptionInfo(sans);
3216 if (status == MagickFalse)
cristy6b3da3a2010-06-20 02:21:46 +00003217 draw_info->stroke_pattern=GetImageCache(mogrify_info,argv[i+1],
cristy3ed852e2009-09-05 21:47:34 +00003218 exception);
3219 break;
3220 }
3221 if (LocaleCompare("strokewidth",option+1) == 0)
3222 {
cristyf2f27272009-12-17 14:48:46 +00003223 draw_info->stroke_width=StringToDouble(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00003224 break;
3225 }
3226 if (LocaleCompare("style",option+1) == 0)
3227 {
3228 if (*option == '+')
3229 {
3230 draw_info->style=UndefinedStyle;
3231 break;
3232 }
3233 draw_info->style=(StyleType) ParseMagickOption(MagickStyleOptions,
3234 MagickFalse,argv[i+1]);
3235 break;
3236 }
3237 if (LocaleCompare("swirl",option+1) == 0)
3238 {
3239 Image
3240 *swirl_image;
3241
3242 /*
3243 Swirl image.
3244 */
cristy6b3da3a2010-06-20 02:21:46 +00003245 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003246 (void) ParseGeometry(argv[i+1],&geometry_info);
3247 swirl_image=SwirlImage(*image,geometry_info.rho,exception);
3248 if (swirl_image == (Image *) NULL)
3249 break;
3250 *image=DestroyImage(*image);
3251 *image=swirl_image;
3252 break;
3253 }
3254 break;
3255 }
3256 case 't':
3257 {
3258 if (LocaleCompare("threshold",option+1) == 0)
3259 {
3260 double
3261 threshold;
3262
3263 /*
3264 Threshold image.
3265 */
cristy6b3da3a2010-06-20 02:21:46 +00003266 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003267 if (*option == '+')
3268 threshold=(double) QuantumRange/2.5;
3269 else
cristyf2f27272009-12-17 14:48:46 +00003270 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
cristy3ed852e2009-09-05 21:47:34 +00003271 (void) BilevelImageChannel(*image,channel,threshold);
3272 InheritException(exception,&(*image)->exception);
3273 break;
3274 }
3275 if (LocaleCompare("thumbnail",option+1) == 0)
3276 {
3277 Image
3278 *thumbnail_image;
3279
3280 /*
3281 Thumbnail image.
3282 */
cristy6b3da3a2010-06-20 02:21:46 +00003283 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003284 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
3285 thumbnail_image=ThumbnailImage(*image,geometry.width,
3286 geometry.height,exception);
3287 if (thumbnail_image == (Image *) NULL)
3288 break;
3289 *image=DestroyImage(*image);
3290 *image=thumbnail_image;
3291 break;
3292 }
3293 if (LocaleCompare("tile",option+1) == 0)
3294 {
3295 if (*option == '+')
3296 {
3297 if (draw_info->fill_pattern != (Image *) NULL)
3298 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
3299 break;
3300 }
cristy6b3da3a2010-06-20 02:21:46 +00003301 draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1],
cristy3ed852e2009-09-05 21:47:34 +00003302 exception);
3303 break;
3304 }
3305 if (LocaleCompare("tint",option+1) == 0)
3306 {
3307 Image
3308 *tint_image;
3309
3310 /*
3311 Tint the image.
3312 */
cristy6b3da3a2010-06-20 02:21:46 +00003313 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003314 tint_image=TintImage(*image,argv[i+1],draw_info->fill,exception);
3315 if (tint_image == (Image *) NULL)
3316 break;
3317 *image=DestroyImage(*image);
3318 *image=tint_image;
3319 break;
3320 }
3321 if (LocaleCompare("transform",option+1) == 0)
3322 {
3323 Image
3324 *transform_image;
3325
3326 /*
3327 Affine transform image.
3328 */
cristy6b3da3a2010-06-20 02:21:46 +00003329 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003330 transform_image=AffineTransformImage(*image,&draw_info->affine,
3331 exception);
3332 if (transform_image == (Image *) NULL)
3333 break;
3334 *image=DestroyImage(*image);
3335 *image=transform_image;
3336 break;
3337 }
3338 if (LocaleCompare("transparent",option+1) == 0)
3339 {
3340 MagickPixelPacket
3341 target;
3342
cristy6b3da3a2010-06-20 02:21:46 +00003343 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003344 (void) QueryMagickColor(argv[i+1],&target,exception);
3345 (void) TransparentPaintImage(*image,&target,(Quantum)
3346 TransparentOpacity,*option == '-' ? MagickFalse : MagickTrue);
3347 InheritException(exception,&(*image)->exception);
3348 break;
3349 }
3350 if (LocaleCompare("transpose",option+1) == 0)
3351 {
3352 Image
3353 *transpose_image;
3354
3355 /*
3356 Transpose image scanlines.
3357 */
cristy6b3da3a2010-06-20 02:21:46 +00003358 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003359 transpose_image=TransposeImage(*image,exception);
3360 if (transpose_image == (Image *) NULL)
3361 break;
3362 *image=DestroyImage(*image);
3363 *image=transpose_image;
3364 break;
3365 }
3366 if (LocaleCompare("transverse",option+1) == 0)
3367 {
3368 Image
3369 *transverse_image;
3370
3371 /*
3372 Transverse image scanlines.
3373 */
cristy6b3da3a2010-06-20 02:21:46 +00003374 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003375 transverse_image=TransverseImage(*image,exception);
3376 if (transverse_image == (Image *) NULL)
3377 break;
3378 *image=DestroyImage(*image);
3379 *image=transverse_image;
3380 break;
3381 }
3382 if (LocaleCompare("treedepth",option+1) == 0)
3383 {
cristye27293e2009-12-18 02:53:20 +00003384 quantize_info->tree_depth=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00003385 break;
3386 }
3387 if (LocaleCompare("trim",option+1) == 0)
3388 {
3389 Image
3390 *trim_image;
3391
3392 /*
3393 Trim image.
3394 */
cristy6b3da3a2010-06-20 02:21:46 +00003395 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003396 trim_image=TrimImage(*image,exception);
3397 if (trim_image == (Image *) NULL)
3398 break;
3399 *image=DestroyImage(*image);
3400 *image=trim_image;
3401 break;
3402 }
3403 if (LocaleCompare("type",option+1) == 0)
3404 {
3405 ImageType
3406 type;
3407
cristy6b3da3a2010-06-20 02:21:46 +00003408 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003409 if (*option == '+')
cristy5f1c1ff2010-12-23 21:38:06 +00003410 type=UndefinedType;
cristy3ed852e2009-09-05 21:47:34 +00003411 else
3412 type=(ImageType) ParseMagickOption(MagickTypeOptions,MagickFalse,
3413 argv[i+1]);
cristy5f1c1ff2010-12-23 21:38:06 +00003414 (*image)->type=UndefinedType;
cristy3ed852e2009-09-05 21:47:34 +00003415 (void) SetImageType(*image,type);
3416 InheritException(exception,&(*image)->exception);
3417 break;
3418 }
3419 break;
3420 }
3421 case 'u':
3422 {
3423 if (LocaleCompare("undercolor",option+1) == 0)
3424 {
3425 (void) QueryColorDatabase(argv[i+1],&draw_info->undercolor,
3426 exception);
3427 break;
3428 }
cristy045bd902010-01-30 18:56:24 +00003429 if (LocaleCompare("unique",option+1) == 0)
3430 {
3431 if (*option == '+')
3432 {
cristy83fae872010-04-22 15:04:16 +00003433 (void) DeleteImageArtifact(*image,"identify:unique-colors");
cristy045bd902010-01-30 18:56:24 +00003434 break;
3435 }
cristy83fae872010-04-22 15:04:16 +00003436 (void) SetImageArtifact(*image,"identify:unique-colors","true");
cristya01cbea2010-11-03 16:33:33 +00003437 (void) SetImageArtifact(*image,"verbose","true");
cristy045bd902010-01-30 18:56:24 +00003438 break;
3439 }
cristy3ed852e2009-09-05 21:47:34 +00003440 if (LocaleCompare("unique-colors",option+1) == 0)
3441 {
3442 Image
3443 *unique_image;
3444
3445 /*
3446 Unique image colors.
3447 */
cristy6b3da3a2010-06-20 02:21:46 +00003448 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003449 unique_image=UniqueImageColors(*image,exception);
3450 if (unique_image == (Image *) NULL)
3451 break;
3452 *image=DestroyImage(*image);
3453 *image=unique_image;
3454 break;
3455 }
3456 if (LocaleCompare("unsharp",option+1) == 0)
3457 {
3458 Image
3459 *unsharp_image;
3460
3461 /*
3462 Unsharp mask image.
3463 */
cristy6b3da3a2010-06-20 02:21:46 +00003464 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003465 flags=ParseGeometry(argv[i+1],&geometry_info);
3466 if ((flags & SigmaValue) == 0)
3467 geometry_info.sigma=1.0;
3468 if ((flags & XiValue) == 0)
3469 geometry_info.xi=1.0;
3470 if ((flags & PsiValue) == 0)
3471 geometry_info.psi=0.05;
3472 unsharp_image=UnsharpMaskImageChannel(*image,channel,
3473 geometry_info.rho,geometry_info.sigma,geometry_info.xi,
3474 geometry_info.psi,exception);
3475 if (unsharp_image == (Image *) NULL)
3476 break;
3477 *image=DestroyImage(*image);
3478 *image=unsharp_image;
3479 break;
3480 }
3481 break;
3482 }
3483 case 'v':
3484 {
3485 if (LocaleCompare("verbose",option+1) == 0)
3486 {
3487 (void) SetImageArtifact(*image,option+1,
3488 *option == '+' ? "false" : "true");
3489 break;
3490 }
3491 if (LocaleCompare("vignette",option+1) == 0)
3492 {
3493 Image
3494 *vignette_image;
3495
3496 /*
3497 Vignette image.
3498 */
cristy6b3da3a2010-06-20 02:21:46 +00003499 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003500 flags=ParseGeometry(argv[i+1],&geometry_info);
3501 if ((flags & SigmaValue) == 0)
3502 geometry_info.sigma=1.0;
3503 if ((flags & XiValue) == 0)
3504 geometry_info.xi=0.1*(*image)->columns;
3505 if ((flags & PsiValue) == 0)
3506 geometry_info.psi=0.1*(*image)->rows;
3507 vignette_image=VignetteImage(*image,geometry_info.rho,
cristybb503372010-05-27 20:51:26 +00003508 geometry_info.sigma,(ssize_t) ceil(geometry_info.xi-0.5),(ssize_t)
cristy0534a6b2010-03-18 01:19:38 +00003509 ceil(geometry_info.psi-0.5),exception);
cristy3ed852e2009-09-05 21:47:34 +00003510 if (vignette_image == (Image *) NULL)
3511 break;
3512 *image=DestroyImage(*image);
3513 *image=vignette_image;
3514 break;
3515 }
3516 if (LocaleCompare("virtual-pixel",option+1) == 0)
3517 {
3518 if (*option == '+')
3519 {
3520 (void) SetImageVirtualPixelMethod(*image,
3521 UndefinedVirtualPixelMethod);
3522 break;
3523 }
3524 (void) SetImageVirtualPixelMethod(*image,(VirtualPixelMethod)
3525 ParseMagickOption(MagickVirtualPixelOptions,MagickFalse,
3526 argv[i+1]));
3527 break;
3528 }
3529 break;
3530 }
3531 case 'w':
3532 {
3533 if (LocaleCompare("wave",option+1) == 0)
3534 {
3535 Image
3536 *wave_image;
3537
3538 /*
3539 Wave image.
3540 */
cristy6b3da3a2010-06-20 02:21:46 +00003541 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003542 flags=ParseGeometry(argv[i+1],&geometry_info);
3543 if ((flags & SigmaValue) == 0)
3544 geometry_info.sigma=1.0;
3545 wave_image=WaveImage(*image,geometry_info.rho,geometry_info.sigma,
3546 exception);
3547 if (wave_image == (Image *) NULL)
3548 break;
3549 *image=DestroyImage(*image);
3550 *image=wave_image;
3551 break;
3552 }
3553 if (LocaleCompare("weight",option+1) == 0)
3554 {
cristye27293e2009-12-18 02:53:20 +00003555 draw_info->weight=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00003556 if (LocaleCompare(argv[i+1],"all") == 0)
3557 draw_info->weight=0;
3558 if (LocaleCompare(argv[i+1],"bold") == 0)
3559 draw_info->weight=700;
3560 if (LocaleCompare(argv[i+1],"bolder") == 0)
3561 if (draw_info->weight <= 800)
3562 draw_info->weight+=100;
3563 if (LocaleCompare(argv[i+1],"lighter") == 0)
3564 if (draw_info->weight >= 100)
3565 draw_info->weight-=100;
3566 if (LocaleCompare(argv[i+1],"normal") == 0)
3567 draw_info->weight=400;
3568 break;
3569 }
3570 if (LocaleCompare("white-threshold",option+1) == 0)
3571 {
3572 /*
3573 White threshold image.
3574 */
cristy6b3da3a2010-06-20 02:21:46 +00003575 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003576 (void) WhiteThresholdImageChannel(*image,channel,argv[i+1],
3577 exception);
3578 InheritException(exception,&(*image)->exception);
3579 break;
3580 }
3581 break;
3582 }
3583 default:
3584 break;
3585 }
3586 i+=count;
3587 }
3588 if (region_image != (Image *) NULL)
3589 {
3590 /*
3591 Composite transformed region onto image.
3592 */
cristy6b3da3a2010-06-20 02:21:46 +00003593 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003594 (void) CompositeImage(region_image,(*image)->matte != MagickFalse ?
3595 OverCompositeOp : CopyCompositeOp,*image,region_geometry.x,
3596 region_geometry.y);
3597 InheritException(exception,&region_image->exception);
3598 *image=DestroyImage(*image);
3599 *image=region_image;
3600 }
3601 /*
3602 Free resources.
3603 */
3604 quantize_info=DestroyQuantizeInfo(quantize_info);
3605 draw_info=DestroyDrawInfo(draw_info);
cristy6b3da3a2010-06-20 02:21:46 +00003606 mogrify_info=DestroyImageInfo(mogrify_info);
3607 status=(*image)->exception.severity == UndefinedException ? MagickTrue :
3608 MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00003609 return(status);
3610}
3611
3612/*
3613%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3614% %
3615% %
3616% %
cristy5063d812010-10-19 16:28:10 +00003617+ 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 +00003618% %
3619% %
3620% %
3621%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3622%
3623% MogrifyImageCommand() transforms an image or a sequence of images. These
3624% transforms include image scaling, image rotation, color reduction, and
3625% others. The transmogrified image overwrites the original image.
3626%
3627% The format of the MogrifyImageCommand method is:
3628%
3629% MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,int argc,
3630% const char **argv,char **metadata,ExceptionInfo *exception)
3631%
3632% A description of each parameter follows:
3633%
3634% o image_info: the image info.
3635%
3636% o argc: the number of elements in the argument vector.
3637%
3638% o argv: A text array containing the command line arguments.
3639%
3640% o metadata: any metadata is returned here.
3641%
3642% o exception: return any errors or warnings in this structure.
3643%
3644*/
3645
3646static MagickBooleanType MogrifyUsage(void)
3647{
3648 static const char
3649 *miscellaneous[]=
3650 {
3651 "-debug events display copious debugging information",
3652 "-help print program options",
3653 "-list type print a list of supported option arguments",
3654 "-log format format of debugging information",
3655 "-version print version information",
3656 (char *) NULL
3657 },
3658 *operators[]=
3659 {
3660 "-adaptive-blur geometry",
3661 " adaptively blur pixels; decrease effect near edges",
3662 "-adaptive-resize geometry",
3663 " adaptively resize image using 'mesh' interpolation",
3664 "-adaptive-sharpen geometry",
3665 " adaptively sharpen pixels; increase effect near edges",
3666 "-alpha option on, activate, off, deactivate, set, opaque, copy",
3667 " transparent, extract, background, or shape",
3668 "-annotate geometry text",
3669 " annotate the image with text",
3670 "-auto-gamma automagically adjust gamma level of image",
3671 "-auto-level automagically adjust color levels of image",
3672 "-auto-orient automagically orient (rotate) image",
3673 "-bench iterations measure performance",
3674 "-black-threshold value",
3675 " force all pixels below the threshold into black",
3676 "-blue-shift simulate a scene at nighttime in the moonlight",
3677 "-blur geometry reduce image noise and reduce detail levels",
3678 "-border geometry surround image with a border of color",
3679 "-bordercolor color border color",
cristya28d6b82010-01-11 20:03:47 +00003680 "-brightness-contrast geometry",
3681 " improve brightness / contrast of the image",
cristy3ed852e2009-09-05 21:47:34 +00003682 "-cdl filename color correct with a color decision list",
3683 "-charcoal radius simulate a charcoal drawing",
3684 "-chop geometry remove pixels from the image interior",
cristyecb0c6d2009-09-25 16:50:09 +00003685 "-clamp restrict pixel range from 0 to the quantum depth",
cristycee97112010-05-28 00:44:52 +00003686 "-clip clip along the first path from the 8BIM profile",
cristy3ed852e2009-09-05 21:47:34 +00003687 "-clip-mask filename associate a clip mask with the image",
cristycee97112010-05-28 00:44:52 +00003688 "-clip-path id clip along a named path from the 8BIM profile",
cristy3ed852e2009-09-05 21:47:34 +00003689 "-colorize value colorize the image with the fill color",
cristye6365592010-04-02 17:31:23 +00003690 "-color-matrix matrix apply color correction to the image",
cristy3ed852e2009-09-05 21:47:34 +00003691 "-contrast enhance or reduce the image contrast",
3692 "-contrast-stretch geometry",
3693 " improve contrast by `stretching' the intensity range",
3694 "-convolve coefficients",
3695 " apply a convolution kernel to the image",
3696 "-cycle amount cycle the image colormap",
3697 "-decipher filename convert cipher pixels to plain pixels",
3698 "-deskew threshold straighten an image",
3699 "-despeckle reduce the speckles within an image",
3700 "-distort method args",
3701 " distort images according to given method ad args",
3702 "-draw string annotate the image with a graphic primitive",
3703 "-edge radius apply a filter to detect edges in the image",
3704 "-encipher filename convert plain pixels to cipher pixels",
3705 "-emboss radius emboss an image",
3706 "-enhance apply a digital filter to enhance a noisy image",
3707 "-equalize perform histogram equalization to an image",
3708 "-evaluate operator value",
cristyd18ae7c2010-03-07 17:39:52 +00003709 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003710 "-extent geometry set the image size",
3711 "-extract geometry extract area from image",
3712 "-fft implements the discrete Fourier transform (DFT)",
3713 "-flip flip image vertically",
3714 "-floodfill geometry color",
3715 " floodfill the image with color",
3716 "-flop flop image horizontally",
3717 "-frame geometry surround image with an ornamental border",
cristyc2b730e2009-11-24 14:32:09 +00003718 "-function name parameters",
cristy3ed852e2009-09-05 21:47:34 +00003719 " apply function over image values",
3720 "-gamma value level of gamma correction",
3721 "-gaussian-blur geometry",
3722 " reduce image noise and reduce detail levels",
cristy901f09d2009-10-16 22:56:10 +00003723 "-geometry geometry preferred size or location of the image",
cristy3ed852e2009-09-05 21:47:34 +00003724 "-identify identify the format and characteristics of the image",
3725 "-ift implements the inverse discrete Fourier transform (DFT)",
3726 "-implode amount implode image pixels about the center",
3727 "-lat geometry local adaptive thresholding",
3728 "-layers method optimize, merge, or compare image layers",
3729 "-level value adjust the level of image contrast",
3730 "-level-colors color,color",
cristyee0f8d72009-09-19 00:58:29 +00003731 " level image with the given colors",
cristy3ed852e2009-09-05 21:47:34 +00003732 "-linear-stretch geometry",
3733 " improve contrast by `stretching with saturation'",
3734 "-liquid-rescale geometry",
3735 " rescale image with seam-carving",
3736 "-median radius apply a median filter to the image",
cristy2ecd9be2011-02-28 01:17:26 +00003737 "-mode radius make each pixel the 'predominate color' of the neighborhood",
cristy3ed852e2009-09-05 21:47:34 +00003738 "-modulate value vary the brightness, saturation, and hue",
3739 "-monochrome transform image to black and white",
cristy7c1b9fd2010-02-02 14:36:00 +00003740 "-morphology method kernel",
anthony29188a82010-01-22 10:12:34 +00003741 " apply a morphology method to the image",
cristy3ed852e2009-09-05 21:47:34 +00003742 "-motion-blur geometry",
3743 " simulate motion blur",
3744 "-negate replace every pixel with its complementary color ",
3745 "-noise radius add or reduce noise in an image",
3746 "-normalize transform image to span the full range of colors",
3747 "-opaque color change this color to the fill color",
3748 "-ordered-dither NxN",
3749 " add a noise pattern to the image with specific",
3750 " amplitudes",
3751 "-paint radius simulate an oil painting",
3752 "-polaroid angle simulate a Polaroid picture",
3753 "-posterize levels reduce the image to a limited number of color levels",
cristy3ed852e2009-09-05 21:47:34 +00003754 "-profile filename add, delete, or apply an image profile",
3755 "-quantize colorspace reduce colors in this colorspace",
3756 "-radial-blur angle radial blur the image",
3757 "-raise value lighten/darken image edges to create a 3-D effect",
3758 "-random-threshold low,high",
3759 " random threshold the image",
cristy3ed852e2009-09-05 21:47:34 +00003760 "-region geometry apply options to a portion of the image",
3761 "-render render vector graphics",
3762 "-repage geometry size and location of an image canvas",
3763 "-resample geometry change the resolution of an image",
3764 "-resize geometry resize the image",
3765 "-roll geometry roll an image vertically or horizontally",
3766 "-rotate degrees apply Paeth rotation to the image",
3767 "-sample geometry scale image with pixel sampling",
3768 "-scale geometry scale the image",
3769 "-segment values segment an image",
3770 "-selective-blur geometry",
3771 " selectively blur pixels within a contrast threshold",
3772 "-sepia-tone threshold",
3773 " simulate a sepia-toned photo",
3774 "-set property value set an image property",
3775 "-shade degrees shade the image using a distant light source",
3776 "-shadow geometry simulate an image shadow",
3777 "-sharpen geometry sharpen the image",
3778 "-shave geometry shave pixels from the image edges",
cristycee97112010-05-28 00:44:52 +00003779 "-shear geometry slide one edge of the image along the X or Y axis",
cristy3ed852e2009-09-05 21:47:34 +00003780 "-sigmoidal-contrast geometry",
3781 " increase the contrast without saturating highlights or shadows",
3782 "-sketch geometry simulate a pencil sketch",
3783 "-solarize threshold negate all pixels above the threshold level",
3784 "-sparse-color method args",
3785 " fill in a image based on a few color points",
3786 "-splice geometry splice the background color into the image",
3787 "-spread radius displace image pixels by a random amount",
3788 "-strip strip image of all profiles and comments",
3789 "-swirl degrees swirl image pixels about the center",
3790 "-threshold value threshold the image",
3791 "-thumbnail geometry create a thumbnail of the image",
3792 "-tile filename tile image when filling a graphic primitive",
3793 "-tint value tint the image with the fill color",
3794 "-transform affine transform image",
3795 "-transparent color make this color transparent within the image",
3796 "-transpose flip image vertically and rotate 90 degrees",
3797 "-transverse flop image horizontally and rotate 270 degrees",
3798 "-trim trim image edges",
3799 "-type type image type",
3800 "-unique-colors discard all but one of any pixel color",
3801 "-unsharp geometry sharpen the image",
3802 "-vignette geometry soften the edges of the image in vignette style",
cristycee97112010-05-28 00:44:52 +00003803 "-wave geometry alter an image along a sine wave",
cristy3ed852e2009-09-05 21:47:34 +00003804 "-white-threshold value",
3805 " force all pixels above the threshold into white",
3806 (char *) NULL
3807 },
3808 *sequence_operators[]=
3809 {
cristy4285d782011-02-09 20:12:28 +00003810 "-append append an image sequence",
cristy3ed852e2009-09-05 21:47:34 +00003811 "-clut apply a color lookup table to the image",
3812 "-coalesce merge a sequence of images",
3813 "-combine combine a sequence of images",
3814 "-composite composite image",
3815 "-crop geometry cut out a rectangular region of the image",
3816 "-deconstruct break down an image sequence into constituent parts",
cristyd18ae7c2010-03-07 17:39:52 +00003817 "-evaluate-sequence operator",
3818 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003819 "-flatten flatten a sequence of images",
3820 "-fx expression apply mathematical expression to an image channel(s)",
3821 "-hald-clut apply a Hald color lookup table to the image",
3822 "-morph value morph an image sequence",
3823 "-mosaic create a mosaic from an image sequence",
cristy36b94822010-05-20 12:48:16 +00003824 "-print string interpret string and print to console",
cristy3ed852e2009-09-05 21:47:34 +00003825 "-process arguments process the image with a custom image filter",
3826 "-reverse reverse image sequence",
3827 "-separate separate an image channel into a grayscale image",
cristy4285d782011-02-09 20:12:28 +00003828 "-smush geometry smush an image sequence together",
cristy3ed852e2009-09-05 21:47:34 +00003829 "-write filename write images to this file",
3830 (char *) NULL
3831 },
3832 *settings[]=
3833 {
3834 "-adjoin join images into a single multi-image file",
3835 "-affine matrix affine transform matrix",
3836 "-alpha option activate, deactivate, reset, or set the alpha channel",
3837 "-antialias remove pixel-aliasing",
3838 "-authenticate password",
3839 " decipher image with this password",
3840 "-attenuate value lessen (or intensify) when adding noise to an image",
3841 "-background color background color",
3842 "-bias value add bias when convolving an image",
3843 "-black-point-compensation",
3844 " use black point compensation",
3845 "-blue-primary point chromaticity blue primary point",
3846 "-bordercolor color border color",
3847 "-caption string assign a caption to an image",
3848 "-channel type apply option to select image channels",
3849 "-colors value preferred number of colors in the image",
3850 "-colorspace type alternate image colorspace",
3851 "-comment string annotate image with comment",
3852 "-compose operator set image composite operator",
3853 "-compress type type of pixel compression when writing the image",
3854 "-define format:option",
3855 " define one or more image format options",
3856 "-delay value display the next image after pausing",
3857 "-density geometry horizontal and vertical density of the image",
3858 "-depth value image depth",
cristyc9b12952010-03-28 01:12:28 +00003859 "-direction type render text right-to-left or left-to-right",
cristy3ed852e2009-09-05 21:47:34 +00003860 "-display server get image or font from this X server",
3861 "-dispose method layer disposal method",
3862 "-dither method apply error diffusion to image",
3863 "-encoding type text encoding type",
3864 "-endian type endianness (MSB or LSB) of the image",
3865 "-family name render text with this font family",
3866 "-fill color color to use when filling a graphic primitive",
3867 "-filter type use this filter when resizing an image",
3868 "-font name render text with this font",
3869 "-format \"string\" output formatted image characteristics",
3870 "-fuzz distance colors within this distance are considered equal",
3871 "-gravity type horizontal and vertical text placement",
3872 "-green-primary point chromaticity green primary point",
3873 "-intent type type of rendering intent when managing the image color",
3874 "-interlace type type of image interlacing scheme",
cristyb32b90a2009-09-07 21:45:48 +00003875 "-interline-spacing value",
3876 " set the space between two text lines",
cristy3ed852e2009-09-05 21:47:34 +00003877 "-interpolate method pixel color interpolation method",
3878 "-interword-spacing value",
3879 " set the space between two words",
3880 "-kerning value set the space between two letters",
3881 "-label string assign a label to an image",
3882 "-limit type value pixel cache resource limit",
3883 "-loop iterations add Netscape loop extension to your GIF animation",
3884 "-mask filename associate a mask with the image",
3885 "-mattecolor color frame color",
3886 "-monitor monitor progress",
3887 "-orient type image orientation",
3888 "-page geometry size and location of an image canvas (setting)",
3889 "-ping efficiently determine image attributes",
3890 "-pointsize value font point size",
cristy7c1b9fd2010-02-02 14:36:00 +00003891 "-precision value maximum number of significant digits to print",
cristy3ed852e2009-09-05 21:47:34 +00003892 "-preview type image preview type",
3893 "-quality value JPEG/MIFF/PNG compression level",
3894 "-quiet suppress all warning messages",
3895 "-red-primary point chromaticity red primary point",
3896 "-regard-warnings pay attention to warning messages",
3897 "-remap filename transform image colors to match this set of colors",
3898 "-respect-parentheses settings remain in effect until parenthesis boundary",
3899 "-sampling-factor geometry",
3900 " horizontal and vertical sampling factor",
3901 "-scene value image scene number",
3902 "-seed value seed a new sequence of pseudo-random numbers",
3903 "-size geometry width and height of image",
3904 "-stretch type render text with this font stretch",
3905 "-stroke color graphic primitive stroke color",
3906 "-strokewidth value graphic primitive stroke width",
3907 "-style type render text with this font style",
cristyd9a29192010-10-16 16:49:53 +00003908 "-synchronize synchronize image to storage device",
3909 "-taint declare the image as modified",
cristy3ed852e2009-09-05 21:47:34 +00003910 "-texture filename name of texture to tile onto the image background",
3911 "-tile-offset geometry",
3912 " tile offset",
3913 "-treedepth value color tree depth",
3914 "-transparent-color color",
3915 " transparent color",
3916 "-undercolor color annotation bounding box color",
3917 "-units type the units of image resolution",
3918 "-verbose print detailed information about the image",
3919 "-view FlashPix viewing transforms",
3920 "-virtual-pixel method",
3921 " virtual pixel access method",
3922 "-weight type render text with this font weight",
3923 "-white-point point chromaticity white point",
3924 (char *) NULL
3925 },
3926 *stack_operators[]=
3927 {
3928 "-clone index clone an image",
3929 "-delete index delete the image from the image sequence",
3930 "-insert index insert last image into the image sequence",
3931 "-swap indexes swap two images in the image sequence",
3932 (char *) NULL
3933 };
3934
3935 const char
3936 **p;
3937
cristybb503372010-05-27 20:51:26 +00003938 (void) printf("Version: %s\n",GetMagickVersion((size_t *) NULL));
cristy610b2e22009-10-22 14:59:43 +00003939 (void) printf("Copyright: %s\n",GetMagickCopyright());
3940 (void) printf("Features: %s\n\n",GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00003941 (void) printf("Usage: %s [options ...] file [ [options ...] file ...]\n",
3942 GetClientName());
3943 (void) printf("\nImage Settings:\n");
3944 for (p=settings; *p != (char *) NULL; p++)
3945 (void) printf(" %s\n",*p);
3946 (void) printf("\nImage Operators:\n");
3947 for (p=operators; *p != (char *) NULL; p++)
3948 (void) printf(" %s\n",*p);
3949 (void) printf("\nImage Sequence Operators:\n");
3950 for (p=sequence_operators; *p != (char *) NULL; p++)
3951 (void) printf(" %s\n",*p);
3952 (void) printf("\nImage Stack Operators:\n");
3953 for (p=stack_operators; *p != (char *) NULL; p++)
3954 (void) printf(" %s\n",*p);
3955 (void) printf("\nMiscellaneous Options:\n");
3956 for (p=miscellaneous; *p != (char *) NULL; p++)
3957 (void) printf(" %s\n",*p);
3958 (void) printf(
3959 "\nBy default, the image format of `file' is determined by its magic\n");
3960 (void) printf(
3961 "number. To specify a particular image format, precede the filename\n");
3962 (void) printf(
3963 "with an image format name and a colon (i.e. ps:image) or specify the\n");
3964 (void) printf(
3965 "image type as the filename suffix (i.e. image.ps). Specify 'file' as\n");
3966 (void) printf("'-' for standard input or output.\n");
3967 return(MagickFalse);
3968}
3969
3970WandExport MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,
3971 int argc,char **argv,char **wand_unused(metadata),ExceptionInfo *exception)
3972{
3973#define DestroyMogrify() \
3974{ \
3975 if (format != (char *) NULL) \
3976 format=DestroyString(format); \
3977 if (path != (char *) NULL) \
3978 path=DestroyString(path); \
3979 DestroyImageStack(); \
cristybb503372010-05-27 20:51:26 +00003980 for (i=0; i < (ssize_t) argc; i++) \
cristy3ed852e2009-09-05 21:47:34 +00003981 argv[i]=DestroyString(argv[i]); \
3982 argv=(char **) RelinquishMagickMemory(argv); \
3983}
3984#define ThrowMogrifyException(asperity,tag,option) \
3985{ \
3986 (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag,"`%s'", \
3987 option); \
3988 DestroyMogrify(); \
3989 return(MagickFalse); \
3990}
3991#define ThrowMogrifyInvalidArgumentException(option,argument) \
3992{ \
3993 (void) ThrowMagickException(exception,GetMagickModule(),OptionError, \
3994 "InvalidArgument","`%s': %s",argument,option); \
3995 DestroyMogrify(); \
3996 return(MagickFalse); \
3997}
3998
3999 char
4000 *format,
4001 *option,
4002 *path;
4003
4004 Image
4005 *image;
4006
4007 ImageStack
4008 image_stack[MaxImageStackDepth+1];
4009
cristy3ed852e2009-09-05 21:47:34 +00004010 MagickBooleanType
4011 global_colormap;
4012
4013 MagickBooleanType
4014 fire,
cristyebbcfea2011-02-25 02:43:54 +00004015 pend,
4016 respect_parenthesis;
cristy3ed852e2009-09-05 21:47:34 +00004017
4018 MagickStatusType
4019 status;
4020
cristyebbcfea2011-02-25 02:43:54 +00004021 register ssize_t
4022 i;
4023
4024 ssize_t
4025 j,
4026 k;
4027
cristy3ed852e2009-09-05 21:47:34 +00004028 /*
4029 Set defaults.
4030 */
4031 assert(image_info != (ImageInfo *) NULL);
4032 assert(image_info->signature == MagickSignature);
4033 if (image_info->debug != MagickFalse)
4034 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
4035 assert(exception != (ExceptionInfo *) NULL);
4036 if (argc == 2)
4037 {
4038 option=argv[1];
4039 if ((LocaleCompare("version",option+1) == 0) ||
4040 (LocaleCompare("-version",option+1) == 0))
4041 {
4042 (void) fprintf(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +00004043 GetMagickVersion((size_t *) NULL));
cristy610b2e22009-10-22 14:59:43 +00004044 (void) fprintf(stdout,"Copyright: %s\n",GetMagickCopyright());
4045 (void) fprintf(stdout,"Features: %s\n\n",GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00004046 return(MagickFalse);
4047 }
4048 }
4049 if (argc < 2)
cristy13e61a12010-02-04 20:19:00 +00004050 return(MogrifyUsage());
cristy3ed852e2009-09-05 21:47:34 +00004051 format=(char *) NULL;
4052 path=(char *) NULL;
4053 global_colormap=MagickFalse;
4054 k=0;
4055 j=1;
4056 NewImageStack();
4057 option=(char *) NULL;
4058 pend=MagickFalse;
cristyebbcfea2011-02-25 02:43:54 +00004059 respect_parenthesis=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00004060 status=MagickTrue;
4061 /*
4062 Parse command line.
4063 */
4064 ReadCommandlLine(argc,&argv);
4065 status=ExpandFilenames(&argc,&argv);
4066 if (status == MagickFalse)
4067 ThrowMogrifyException(ResourceLimitError,"MemoryAllocationFailed",
4068 GetExceptionMessage(errno));
cristybb503372010-05-27 20:51:26 +00004069 for (i=1; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00004070 {
4071 option=argv[i];
4072 if (LocaleCompare(option,"(") == 0)
4073 {
4074 FireImageStack(MagickFalse,MagickTrue,pend);
4075 if (k == MaxImageStackDepth)
4076 ThrowMogrifyException(OptionError,"ParenthesisNestedTooDeeply",
4077 option);
4078 PushImageStack();
4079 continue;
4080 }
4081 if (LocaleCompare(option,")") == 0)
4082 {
4083 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
4084 if (k == 0)
4085 ThrowMogrifyException(OptionError,"UnableToParseExpression",option);
4086 PopImageStack();
4087 continue;
4088 }
4089 if (IsMagickOption(option) == MagickFalse)
4090 {
4091 char
4092 backup_filename[MaxTextExtent],
4093 *filename;
4094
4095 Image
4096 *images;
4097
4098 /*
4099 Option is a file name: begin by reading image from specified file.
4100 */
4101 FireImageStack(MagickFalse,MagickFalse,pend);
4102 filename=argv[i];
cristycee97112010-05-28 00:44:52 +00004103 if ((LocaleCompare(filename,"--") == 0) && (i < (ssize_t) (argc-1)))
cristy3ed852e2009-09-05 21:47:34 +00004104 filename=argv[++i];
4105 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
4106 images=ReadImages(image_info,exception);
4107 status&=(images != (Image *) NULL) &&
4108 (exception->severity < ErrorException);
4109 if (images == (Image *) NULL)
4110 continue;
cristydaa76602010-06-30 13:05:11 +00004111 if (format != (char *) NULL)
4112 (void) CopyMagickString(images->filename,images->magick_filename,
4113 MaxTextExtent);
cristy3ed852e2009-09-05 21:47:34 +00004114 if (path != (char *) NULL)
4115 {
4116 GetPathComponent(option,TailPath,filename);
4117 (void) FormatMagickString(images->filename,MaxTextExtent,"%s%c%s",
4118 path,*DirectorySeparator,filename);
4119 }
4120 if (format != (char *) NULL)
cristydaa76602010-06-30 13:05:11 +00004121 AppendImageFormat(format,images->filename);
cristy3ed852e2009-09-05 21:47:34 +00004122 AppendImageStack(images);
4123 FinalizeImageSettings(image_info,image,MagickFalse);
4124 if (global_colormap != MagickFalse)
4125 {
4126 QuantizeInfo
4127 *quantize_info;
4128
4129 quantize_info=AcquireQuantizeInfo(image_info);
4130 (void) RemapImages(quantize_info,images,(Image *) NULL);
4131 quantize_info=DestroyQuantizeInfo(quantize_info);
4132 }
4133 *backup_filename='\0';
4134 if ((LocaleCompare(image->filename,"-") != 0) &&
4135 (IsPathWritable(image->filename) != MagickFalse))
4136 {
cristybb503372010-05-27 20:51:26 +00004137 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004138 i;
4139
4140 /*
4141 Rename image file as backup.
4142 */
4143 (void) CopyMagickString(backup_filename,image->filename,
4144 MaxTextExtent);
4145 for (i=0; i < 6; i++)
4146 {
4147 (void) ConcatenateMagickString(backup_filename,"~",MaxTextExtent);
4148 if (IsPathAccessible(backup_filename) == MagickFalse)
4149 break;
4150 }
4151 if ((IsPathAccessible(backup_filename) != MagickFalse) ||
4152 (rename(image->filename,backup_filename) != 0))
4153 *backup_filename='\0';
4154 }
4155 /*
4156 Write transmogrified image to disk.
4157 */
4158 image_info->synchronize=MagickTrue;
4159 status&=WriteImages(image_info,image,image->filename,exception);
4160 if ((status == MagickFalse) && (*backup_filename != '\0'))
4161 (void) remove(backup_filename);
4162 RemoveAllImageStack();
4163 continue;
4164 }
4165 pend=image != (Image *) NULL ? MagickTrue : MagickFalse;
4166 switch (*(option+1))
4167 {
4168 case 'a':
4169 {
4170 if (LocaleCompare("adaptive-blur",option+1) == 0)
4171 {
4172 i++;
cristybb503372010-05-27 20:51:26 +00004173 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004174 ThrowMogrifyException(OptionError,"MissingArgument",option);
4175 if (IsGeometry(argv[i]) == MagickFalse)
4176 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4177 break;
4178 }
4179 if (LocaleCompare("adaptive-resize",option+1) == 0)
4180 {
4181 i++;
cristybb503372010-05-27 20:51:26 +00004182 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004183 ThrowMogrifyException(OptionError,"MissingArgument",option);
4184 if (IsGeometry(argv[i]) == MagickFalse)
4185 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4186 break;
4187 }
4188 if (LocaleCompare("adaptive-sharpen",option+1) == 0)
4189 {
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]);
4195 break;
4196 }
4197 if (LocaleCompare("affine",option+1) == 0)
4198 {
4199 if (*option == '+')
4200 break;
4201 i++;
cristybb503372010-05-27 20:51:26 +00004202 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004203 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy3ed852e2009-09-05 21:47:34 +00004204 break;
4205 }
4206 if (LocaleCompare("alpha",option+1) == 0)
4207 {
cristybb503372010-05-27 20:51:26 +00004208 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004209 type;
4210
4211 if (*option == '+')
4212 break;
4213 i++;
cristybb503372010-05-27 20:51:26 +00004214 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004215 ThrowMogrifyException(OptionError,"MissingArgument",option);
4216 type=ParseMagickOption(MagickAlphaOptions,MagickFalse,argv[i]);
4217 if (type < 0)
4218 ThrowMogrifyException(OptionError,"UnrecognizedAlphaChannelType",
4219 argv[i]);
4220 break;
4221 }
4222 if (LocaleCompare("annotate",option+1) == 0)
4223 {
4224 if (*option == '+')
4225 break;
4226 i++;
cristybb503372010-05-27 20:51:26 +00004227 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004228 ThrowMogrifyException(OptionError,"MissingArgument",option);
4229 if (IsGeometry(argv[i]) == MagickFalse)
4230 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristybb503372010-05-27 20:51:26 +00004231 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004232 ThrowMogrifyException(OptionError,"MissingArgument",option);
4233 i++;
4234 break;
4235 }
4236 if (LocaleCompare("antialias",option+1) == 0)
4237 break;
4238 if (LocaleCompare("append",option+1) == 0)
4239 break;
4240 if (LocaleCompare("attenuate",option+1) == 0)
4241 {
4242 if (*option == '+')
4243 break;
4244 i++;
cristybb503372010-05-27 20:51:26 +00004245 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004246 ThrowMogrifyException(OptionError,"MissingArgument",option);
4247 if (IsGeometry(argv[i]) == MagickFalse)
4248 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4249 break;
4250 }
4251 if (LocaleCompare("authenticate",option+1) == 0)
4252 {
4253 if (*option == '+')
4254 break;
4255 i++;
cristybb503372010-05-27 20:51:26 +00004256 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004257 ThrowMogrifyException(OptionError,"MissingArgument",option);
4258 break;
4259 }
4260 if (LocaleCompare("auto-gamma",option+1) == 0)
4261 break;
4262 if (LocaleCompare("auto-level",option+1) == 0)
4263 break;
4264 if (LocaleCompare("auto-orient",option+1) == 0)
4265 break;
4266 if (LocaleCompare("average",option+1) == 0)
4267 break;
4268 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4269 }
4270 case 'b':
4271 {
4272 if (LocaleCompare("background",option+1) == 0)
4273 {
4274 if (*option == '+')
4275 break;
4276 i++;
cristybb503372010-05-27 20:51:26 +00004277 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004278 ThrowMogrifyException(OptionError,"MissingArgument",option);
4279 break;
4280 }
4281 if (LocaleCompare("bias",option+1) == 0)
4282 {
4283 if (*option == '+')
4284 break;
4285 i++;
cristybb503372010-05-27 20:51:26 +00004286 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004287 ThrowMogrifyException(OptionError,"MissingArgument",option);
4288 if (IsGeometry(argv[i]) == MagickFalse)
4289 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4290 break;
4291 }
4292 if (LocaleCompare("black-point-compensation",option+1) == 0)
4293 break;
4294 if (LocaleCompare("black-threshold",option+1) == 0)
4295 {
4296 if (*option == '+')
4297 break;
4298 i++;
cristybb503372010-05-27 20:51:26 +00004299 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004300 ThrowMogrifyException(OptionError,"MissingArgument",option);
4301 if (IsGeometry(argv[i]) == MagickFalse)
4302 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4303 break;
4304 }
4305 if (LocaleCompare("blue-primary",option+1) == 0)
4306 {
4307 if (*option == '+')
4308 break;
4309 i++;
cristybb503372010-05-27 20:51:26 +00004310 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004311 ThrowMogrifyException(OptionError,"MissingArgument",option);
4312 if (IsGeometry(argv[i]) == MagickFalse)
4313 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4314 break;
4315 }
4316 if (LocaleCompare("blue-shift",option+1) == 0)
4317 {
4318 i++;
cristybb503372010-05-27 20:51:26 +00004319 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004320 ThrowMogrifyException(OptionError,"MissingArgument",option);
4321 if (IsGeometry(argv[i]) == MagickFalse)
4322 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4323 break;
4324 }
4325 if (LocaleCompare("blur",option+1) == 0)
4326 {
4327 i++;
cristybb503372010-05-27 20:51:26 +00004328 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004329 ThrowMogrifyException(OptionError,"MissingArgument",option);
4330 if (IsGeometry(argv[i]) == MagickFalse)
4331 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4332 break;
4333 }
4334 if (LocaleCompare("border",option+1) == 0)
4335 {
4336 if (*option == '+')
4337 break;
4338 i++;
cristybb503372010-05-27 20:51:26 +00004339 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004340 ThrowMogrifyException(OptionError,"MissingArgument",option);
4341 if (IsGeometry(argv[i]) == MagickFalse)
4342 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4343 break;
4344 }
4345 if (LocaleCompare("bordercolor",option+1) == 0)
4346 {
4347 if (*option == '+')
4348 break;
4349 i++;
cristybb503372010-05-27 20:51:26 +00004350 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004351 ThrowMogrifyException(OptionError,"MissingArgument",option);
4352 break;
4353 }
4354 if (LocaleCompare("box",option+1) == 0)
4355 {
4356 if (*option == '+')
4357 break;
4358 i++;
cristybb503372010-05-27 20:51:26 +00004359 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004360 ThrowMogrifyException(OptionError,"MissingArgument",option);
4361 break;
4362 }
cristya28d6b82010-01-11 20:03:47 +00004363 if (LocaleCompare("brightness-contrast",option+1) == 0)
4364 {
4365 i++;
cristybb503372010-05-27 20:51:26 +00004366 if (i == (ssize_t) argc)
cristya28d6b82010-01-11 20:03:47 +00004367 ThrowMogrifyException(OptionError,"MissingArgument",option);
4368 if (IsGeometry(argv[i]) == MagickFalse)
4369 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4370 break;
4371 }
cristy3ed852e2009-09-05 21:47:34 +00004372 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4373 }
4374 case 'c':
4375 {
4376 if (LocaleCompare("cache",option+1) == 0)
4377 {
4378 if (*option == '+')
4379 break;
4380 i++;
cristybb503372010-05-27 20:51:26 +00004381 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004382 ThrowMogrifyException(OptionError,"MissingArgument",option);
4383 if (IsGeometry(argv[i]) == MagickFalse)
4384 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4385 break;
4386 }
4387 if (LocaleCompare("caption",option+1) == 0)
4388 {
4389 if (*option == '+')
4390 break;
4391 i++;
cristybb503372010-05-27 20:51:26 +00004392 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004393 ThrowMogrifyException(OptionError,"MissingArgument",option);
4394 break;
4395 }
4396 if (LocaleCompare("channel",option+1) == 0)
4397 {
cristybb503372010-05-27 20:51:26 +00004398 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004399 channel;
4400
4401 if (*option == '+')
4402 break;
4403 i++;
cristybb503372010-05-27 20:51:26 +00004404 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004405 ThrowMogrifyException(OptionError,"MissingArgument",option);
4406 channel=ParseChannelOption(argv[i]);
4407 if (channel < 0)
4408 ThrowMogrifyException(OptionError,"UnrecognizedChannelType",
4409 argv[i]);
4410 break;
4411 }
4412 if (LocaleCompare("cdl",option+1) == 0)
4413 {
4414 if (*option == '+')
4415 break;
4416 i++;
cristybb503372010-05-27 20:51:26 +00004417 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004418 ThrowMogrifyException(OptionError,"MissingArgument",option);
4419 break;
4420 }
4421 if (LocaleCompare("charcoal",option+1) == 0)
4422 {
4423 if (*option == '+')
4424 break;
4425 i++;
cristybb503372010-05-27 20:51:26 +00004426 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004427 ThrowMogrifyException(OptionError,"MissingArgument",option);
4428 if (IsGeometry(argv[i]) == MagickFalse)
4429 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4430 break;
4431 }
4432 if (LocaleCompare("chop",option+1) == 0)
4433 {
4434 if (*option == '+')
4435 break;
4436 i++;
cristybb503372010-05-27 20:51:26 +00004437 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004438 ThrowMogrifyException(OptionError,"MissingArgument",option);
4439 if (IsGeometry(argv[i]) == MagickFalse)
4440 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4441 break;
4442 }
cristy1eb45dd2009-09-25 16:38:06 +00004443 if (LocaleCompare("clamp",option+1) == 0)
4444 break;
4445 if (LocaleCompare("clip",option+1) == 0)
4446 break;
cristy3ed852e2009-09-05 21:47:34 +00004447 if (LocaleCompare("clip-mask",option+1) == 0)
4448 {
4449 if (*option == '+')
4450 break;
4451 i++;
cristybb503372010-05-27 20:51:26 +00004452 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004453 ThrowMogrifyException(OptionError,"MissingArgument",option);
4454 break;
4455 }
4456 if (LocaleCompare("clut",option+1) == 0)
4457 break;
4458 if (LocaleCompare("coalesce",option+1) == 0)
4459 break;
4460 if (LocaleCompare("colorize",option+1) == 0)
4461 {
4462 if (*option == '+')
4463 break;
4464 i++;
cristybb503372010-05-27 20:51:26 +00004465 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004466 ThrowMogrifyException(OptionError,"MissingArgument",option);
4467 if (IsGeometry(argv[i]) == MagickFalse)
4468 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4469 break;
4470 }
cristye6365592010-04-02 17:31:23 +00004471 if (LocaleCompare("color-matrix",option+1) == 0)
4472 {
cristyb6bd4ad2010-08-08 01:12:27 +00004473 KernelInfo
4474 *kernel_info;
4475
cristye6365592010-04-02 17:31:23 +00004476 if (*option == '+')
4477 break;
4478 i++;
cristybb503372010-05-27 20:51:26 +00004479 if (i == (ssize_t) (argc-1))
cristye6365592010-04-02 17:31:23 +00004480 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00004481 kernel_info=AcquireKernelInfo(argv[i]);
4482 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00004483 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00004484 kernel_info=DestroyKernelInfo(kernel_info);
cristye6365592010-04-02 17:31:23 +00004485 break;
4486 }
cristy3ed852e2009-09-05 21:47:34 +00004487 if (LocaleCompare("colors",option+1) == 0)
4488 {
4489 if (*option == '+')
4490 break;
4491 i++;
cristybb503372010-05-27 20:51:26 +00004492 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004493 ThrowMogrifyException(OptionError,"MissingArgument",option);
4494 if (IsGeometry(argv[i]) == MagickFalse)
4495 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4496 break;
4497 }
4498 if (LocaleCompare("colorspace",option+1) == 0)
4499 {
cristybb503372010-05-27 20:51:26 +00004500 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004501 colorspace;
4502
4503 if (*option == '+')
4504 break;
4505 i++;
cristybb503372010-05-27 20:51:26 +00004506 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004507 ThrowMogrifyException(OptionError,"MissingArgument",option);
4508 colorspace=ParseMagickOption(MagickColorspaceOptions,MagickFalse,
4509 argv[i]);
4510 if (colorspace < 0)
4511 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
4512 argv[i]);
4513 break;
4514 }
4515 if (LocaleCompare("combine",option+1) == 0)
4516 break;
4517 if (LocaleCompare("comment",option+1) == 0)
4518 {
4519 if (*option == '+')
4520 break;
4521 i++;
cristybb503372010-05-27 20:51:26 +00004522 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004523 ThrowMogrifyException(OptionError,"MissingArgument",option);
4524 break;
4525 }
4526 if (LocaleCompare("composite",option+1) == 0)
4527 break;
4528 if (LocaleCompare("compress",option+1) == 0)
4529 {
cristybb503372010-05-27 20:51:26 +00004530 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004531 compress;
4532
4533 if (*option == '+')
4534 break;
4535 i++;
cristybb503372010-05-27 20:51:26 +00004536 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004537 ThrowMogrifyException(OptionError,"MissingArgument",option);
4538 compress=ParseMagickOption(MagickCompressOptions,MagickFalse,
4539 argv[i]);
4540 if (compress < 0)
4541 ThrowMogrifyException(OptionError,"UnrecognizedImageCompression",
4542 argv[i]);
4543 break;
4544 }
cristy22879752009-10-25 23:55:40 +00004545 if (LocaleCompare("concurrent",option+1) == 0)
4546 break;
cristy3ed852e2009-09-05 21:47:34 +00004547 if (LocaleCompare("contrast",option+1) == 0)
4548 break;
4549 if (LocaleCompare("contrast-stretch",option+1) == 0)
4550 {
4551 i++;
cristybb503372010-05-27 20:51:26 +00004552 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004553 ThrowMogrifyException(OptionError,"MissingArgument",option);
4554 if (IsGeometry(argv[i]) == MagickFalse)
4555 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4556 break;
4557 }
4558 if (LocaleCompare("convolve",option+1) == 0)
4559 {
cristyb6bd4ad2010-08-08 01:12:27 +00004560 KernelInfo
4561 *kernel_info;
4562
cristy3ed852e2009-09-05 21:47:34 +00004563 if (*option == '+')
4564 break;
4565 i++;
cristybb503372010-05-27 20:51:26 +00004566 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004567 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00004568 kernel_info=AcquireKernelInfo(argv[i]);
4569 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00004570 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00004571 kernel_info=DestroyKernelInfo(kernel_info);
cristy3ed852e2009-09-05 21:47:34 +00004572 break;
4573 }
4574 if (LocaleCompare("crop",option+1) == 0)
4575 {
4576 if (*option == '+')
4577 break;
4578 i++;
cristybb503372010-05-27 20:51:26 +00004579 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004580 ThrowMogrifyException(OptionError,"MissingArgument",option);
4581 if (IsGeometry(argv[i]) == MagickFalse)
4582 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4583 break;
4584 }
4585 if (LocaleCompare("cycle",option+1) == 0)
4586 {
4587 if (*option == '+')
4588 break;
4589 i++;
cristybb503372010-05-27 20:51:26 +00004590 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004591 ThrowMogrifyException(OptionError,"MissingArgument",option);
4592 if (IsGeometry(argv[i]) == MagickFalse)
4593 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4594 break;
4595 }
4596 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4597 }
4598 case 'd':
4599 {
4600 if (LocaleCompare("decipher",option+1) == 0)
4601 {
4602 if (*option == '+')
4603 break;
4604 i++;
cristybb503372010-05-27 20:51:26 +00004605 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004606 ThrowMogrifyException(OptionError,"MissingArgument",option);
4607 break;
4608 }
4609 if (LocaleCompare("deconstruct",option+1) == 0)
4610 break;
4611 if (LocaleCompare("debug",option+1) == 0)
4612 {
cristybb503372010-05-27 20:51:26 +00004613 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004614 event;
4615
4616 if (*option == '+')
4617 break;
4618 i++;
cristybb503372010-05-27 20:51:26 +00004619 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004620 ThrowMogrifyException(OptionError,"MissingArgument",option);
4621 event=ParseMagickOption(MagickLogEventOptions,MagickFalse,argv[i]);
4622 if (event < 0)
4623 ThrowMogrifyException(OptionError,"UnrecognizedEventType",
4624 argv[i]);
4625 (void) SetLogEventMask(argv[i]);
4626 break;
4627 }
4628 if (LocaleCompare("define",option+1) == 0)
4629 {
4630 i++;
cristybb503372010-05-27 20:51:26 +00004631 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004632 ThrowMogrifyException(OptionError,"MissingArgument",option);
4633 if (*option == '+')
4634 {
4635 const char
4636 *define;
4637
4638 define=GetImageOption(image_info,argv[i]);
4639 if (define == (const char *) NULL)
4640 ThrowMogrifyException(OptionError,"NoSuchOption",argv[i]);
4641 break;
4642 }
4643 break;
4644 }
4645 if (LocaleCompare("delay",option+1) == 0)
4646 {
4647 if (*option == '+')
4648 break;
4649 i++;
cristybb503372010-05-27 20:51:26 +00004650 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004651 ThrowMogrifyException(OptionError,"MissingArgument",option);
4652 if (IsGeometry(argv[i]) == MagickFalse)
4653 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4654 break;
4655 }
4656 if (LocaleCompare("density",option+1) == 0)
4657 {
4658 if (*option == '+')
4659 break;
4660 i++;
cristybb503372010-05-27 20:51:26 +00004661 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004662 ThrowMogrifyException(OptionError,"MissingArgument",option);
4663 if (IsGeometry(argv[i]) == MagickFalse)
4664 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4665 break;
4666 }
4667 if (LocaleCompare("depth",option+1) == 0)
4668 {
4669 if (*option == '+')
4670 break;
4671 i++;
cristybb503372010-05-27 20:51:26 +00004672 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004673 ThrowMogrifyException(OptionError,"MissingArgument",option);
4674 if (IsGeometry(argv[i]) == MagickFalse)
4675 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4676 break;
4677 }
4678 if (LocaleCompare("deskew",option+1) == 0)
4679 {
4680 if (*option == '+')
4681 break;
4682 i++;
cristybb503372010-05-27 20:51:26 +00004683 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004684 ThrowMogrifyException(OptionError,"MissingArgument",option);
4685 if (IsGeometry(argv[i]) == MagickFalse)
4686 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4687 break;
4688 }
4689 if (LocaleCompare("despeckle",option+1) == 0)
4690 break;
4691 if (LocaleCompare("dft",option+1) == 0)
4692 break;
cristyc9b12952010-03-28 01:12:28 +00004693 if (LocaleCompare("direction",option+1) == 0)
4694 {
cristybb503372010-05-27 20:51:26 +00004695 ssize_t
cristyc9b12952010-03-28 01:12:28 +00004696 direction;
4697
4698 if (*option == '+')
4699 break;
4700 i++;
cristybb503372010-05-27 20:51:26 +00004701 if (i == (ssize_t) argc)
cristyc9b12952010-03-28 01:12:28 +00004702 ThrowMogrifyException(OptionError,"MissingArgument",option);
4703 direction=ParseMagickOption(MagickDirectionOptions,MagickFalse,
4704 argv[i]);
4705 if (direction < 0)
4706 ThrowMogrifyException(OptionError,"UnrecognizedDirectionType",
4707 argv[i]);
4708 break;
4709 }
cristy3ed852e2009-09-05 21:47:34 +00004710 if (LocaleCompare("display",option+1) == 0)
4711 {
4712 if (*option == '+')
4713 break;
4714 i++;
cristybb503372010-05-27 20:51:26 +00004715 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004716 ThrowMogrifyException(OptionError,"MissingArgument",option);
4717 break;
4718 }
4719 if (LocaleCompare("dispose",option+1) == 0)
4720 {
cristybb503372010-05-27 20:51:26 +00004721 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004722 dispose;
4723
4724 if (*option == '+')
4725 break;
4726 i++;
cristybb503372010-05-27 20:51:26 +00004727 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004728 ThrowMogrifyException(OptionError,"MissingArgument",option);
4729 dispose=ParseMagickOption(MagickDisposeOptions,MagickFalse,argv[i]);
4730 if (dispose < 0)
4731 ThrowMogrifyException(OptionError,"UnrecognizedDisposeMethod",
4732 argv[i]);
4733 break;
4734 }
4735 if (LocaleCompare("distort",option+1) == 0)
4736 {
cristybb503372010-05-27 20:51:26 +00004737 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004738 op;
4739
4740 i++;
cristybb503372010-05-27 20:51:26 +00004741 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004742 ThrowMogrifyException(OptionError,"MissingArgument",option);
4743 op=ParseMagickOption(MagickDistortOptions,MagickFalse,argv[i]);
4744 if (op < 0)
4745 ThrowMogrifyException(OptionError,"UnrecognizedDistortMethod",
4746 argv[i]);
4747 i++;
cristybb503372010-05-27 20:51:26 +00004748 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004749 ThrowMogrifyException(OptionError,"MissingArgument",option);
4750 break;
4751 }
4752 if (LocaleCompare("dither",option+1) == 0)
4753 {
cristybb503372010-05-27 20:51:26 +00004754 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004755 method;
4756
4757 if (*option == '+')
4758 break;
4759 i++;
cristybb503372010-05-27 20:51:26 +00004760 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004761 ThrowMogrifyException(OptionError,"MissingArgument",option);
4762 method=ParseMagickOption(MagickDitherOptions,MagickFalse,argv[i]);
4763 if (method < 0)
4764 ThrowMogrifyException(OptionError,"UnrecognizedDitherMethod",
4765 argv[i]);
4766 break;
4767 }
4768 if (LocaleCompare("draw",option+1) == 0)
4769 {
4770 if (*option == '+')
4771 break;
4772 i++;
cristybb503372010-05-27 20:51:26 +00004773 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004774 ThrowMogrifyException(OptionError,"MissingArgument",option);
4775 break;
4776 }
cristy22879752009-10-25 23:55:40 +00004777 if (LocaleCompare("duration",option+1) == 0)
4778 {
4779 if (*option == '+')
4780 break;
4781 i++;
cristybb503372010-05-27 20:51:26 +00004782 if (i == (ssize_t) (argc-1))
cristy22879752009-10-25 23:55:40 +00004783 ThrowMogrifyException(OptionError,"MissingArgument",option);
4784 if (IsGeometry(argv[i]) == MagickFalse)
4785 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4786 break;
4787 }
cristy3ed852e2009-09-05 21:47:34 +00004788 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4789 }
4790 case 'e':
4791 {
4792 if (LocaleCompare("edge",option+1) == 0)
4793 {
4794 if (*option == '+')
4795 break;
4796 i++;
cristybb503372010-05-27 20:51:26 +00004797 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004798 ThrowMogrifyException(OptionError,"MissingArgument",option);
4799 if (IsGeometry(argv[i]) == MagickFalse)
4800 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4801 break;
4802 }
4803 if (LocaleCompare("emboss",option+1) == 0)
4804 {
4805 if (*option == '+')
4806 break;
4807 i++;
cristybb503372010-05-27 20:51:26 +00004808 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004809 ThrowMogrifyException(OptionError,"MissingArgument",option);
4810 if (IsGeometry(argv[i]) == MagickFalse)
4811 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4812 break;
4813 }
4814 if (LocaleCompare("encipher",option+1) == 0)
4815 {
4816 if (*option == '+')
4817 break;
4818 i++;
cristybb503372010-05-27 20:51:26 +00004819 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004820 ThrowMogrifyException(OptionError,"MissingArgument",option);
4821 break;
4822 }
4823 if (LocaleCompare("encoding",option+1) == 0)
4824 {
4825 if (*option == '+')
4826 break;
4827 i++;
cristybb503372010-05-27 20:51:26 +00004828 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004829 ThrowMogrifyException(OptionError,"MissingArgument",option);
4830 break;
4831 }
4832 if (LocaleCompare("endian",option+1) == 0)
4833 {
cristybb503372010-05-27 20:51:26 +00004834 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004835 endian;
4836
4837 if (*option == '+')
4838 break;
4839 i++;
cristybb503372010-05-27 20:51:26 +00004840 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004841 ThrowMogrifyException(OptionError,"MissingArgument",option);
4842 endian=ParseMagickOption(MagickEndianOptions,MagickFalse,argv[i]);
4843 if (endian < 0)
4844 ThrowMogrifyException(OptionError,"UnrecognizedEndianType",
4845 argv[i]);
4846 break;
4847 }
4848 if (LocaleCompare("enhance",option+1) == 0)
4849 break;
4850 if (LocaleCompare("equalize",option+1) == 0)
4851 break;
4852 if (LocaleCompare("evaluate",option+1) == 0)
4853 {
cristybb503372010-05-27 20:51:26 +00004854 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004855 op;
4856
4857 if (*option == '+')
4858 break;
4859 i++;
cristybb503372010-05-27 20:51:26 +00004860 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004861 ThrowMogrifyException(OptionError,"MissingArgument",option);
4862 op=ParseMagickOption(MagickEvaluateOptions,MagickFalse,argv[i]);
4863 if (op < 0)
4864 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4865 argv[i]);
4866 i++;
cristybb503372010-05-27 20:51:26 +00004867 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004868 ThrowMogrifyException(OptionError,"MissingArgument",option);
4869 if (IsGeometry(argv[i]) == MagickFalse)
4870 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4871 break;
4872 }
cristyd18ae7c2010-03-07 17:39:52 +00004873 if (LocaleCompare("evaluate-sequence",option+1) == 0)
4874 {
cristybb503372010-05-27 20:51:26 +00004875 ssize_t
cristyd18ae7c2010-03-07 17:39:52 +00004876 op;
4877
4878 if (*option == '+')
4879 break;
4880 i++;
cristybb503372010-05-27 20:51:26 +00004881 if (i == (ssize_t) argc)
cristyd18ae7c2010-03-07 17:39:52 +00004882 ThrowMogrifyException(OptionError,"MissingArgument",option);
4883 op=ParseMagickOption(MagickEvaluateOptions,MagickFalse,argv[i]);
4884 if (op < 0)
4885 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4886 argv[i]);
4887 break;
4888 }
cristy3ed852e2009-09-05 21:47:34 +00004889 if (LocaleCompare("extent",option+1) == 0)
4890 {
4891 if (*option == '+')
4892 break;
4893 i++;
cristybb503372010-05-27 20:51:26 +00004894 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004895 ThrowMogrifyException(OptionError,"MissingArgument",option);
4896 if (IsGeometry(argv[i]) == MagickFalse)
4897 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4898 break;
4899 }
4900 if (LocaleCompare("extract",option+1) == 0)
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 if (IsGeometry(argv[i]) == MagickFalse)
4908 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4909 break;
4910 }
4911 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4912 }
4913 case 'f':
4914 {
4915 if (LocaleCompare("family",option+1) == 0)
4916 {
4917 if (*option == '+')
4918 break;
4919 i++;
cristybb503372010-05-27 20:51:26 +00004920 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004921 ThrowMogrifyException(OptionError,"MissingArgument",option);
4922 break;
4923 }
4924 if (LocaleCompare("fill",option+1) == 0)
4925 {
4926 if (*option == '+')
4927 break;
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("filter",option+1) == 0)
4934 {
cristybb503372010-05-27 20:51:26 +00004935 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004936 filter;
4937
4938 if (*option == '+')
4939 break;
4940 i++;
cristybb503372010-05-27 20:51:26 +00004941 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004942 ThrowMogrifyException(OptionError,"MissingArgument",option);
4943 filter=ParseMagickOption(MagickFilterOptions,MagickFalse,argv[i]);
4944 if (filter < 0)
4945 ThrowMogrifyException(OptionError,"UnrecognizedImageFilter",
4946 argv[i]);
4947 break;
4948 }
4949 if (LocaleCompare("flatten",option+1) == 0)
4950 break;
4951 if (LocaleCompare("flip",option+1) == 0)
4952 break;
4953 if (LocaleCompare("flop",option+1) == 0)
4954 break;
4955 if (LocaleCompare("floodfill",option+1) == 0)
4956 {
4957 if (*option == '+')
4958 break;
4959 i++;
cristybb503372010-05-27 20:51:26 +00004960 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004961 ThrowMogrifyException(OptionError,"MissingArgument",option);
4962 if (IsGeometry(argv[i]) == MagickFalse)
4963 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4964 i++;
cristybb503372010-05-27 20:51:26 +00004965 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004966 ThrowMogrifyException(OptionError,"MissingArgument",option);
4967 break;
4968 }
4969 if (LocaleCompare("font",option+1) == 0)
4970 {
4971 if (*option == '+')
4972 break;
4973 i++;
cristybb503372010-05-27 20:51:26 +00004974 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004975 ThrowMogrifyException(OptionError,"MissingArgument",option);
4976 break;
4977 }
4978 if (LocaleCompare("format",option+1) == 0)
4979 {
4980 (void) CopyMagickString(argv[i]+1,"sans",MaxTextExtent);
4981 (void) CloneString(&format,(char *) NULL);
4982 if (*option == '+')
4983 break;
4984 i++;
cristybb503372010-05-27 20:51:26 +00004985 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004986 ThrowMogrifyException(OptionError,"MissingArgument",option);
4987 (void) CloneString(&format,argv[i]);
4988 (void) CopyMagickString(image_info->filename,format,MaxTextExtent);
4989 (void) ConcatenateMagickString(image_info->filename,":",
4990 MaxTextExtent);
cristyd965a422010-03-03 17:47:35 +00004991 (void) SetImageInfo(image_info,0,exception);
cristy3ed852e2009-09-05 21:47:34 +00004992 if (*image_info->magick == '\0')
4993 ThrowMogrifyException(OptionError,"UnrecognizedImageFormat",
4994 format);
4995 break;
4996 }
4997 if (LocaleCompare("frame",option+1) == 0)
4998 {
4999 if (*option == '+')
5000 break;
5001 i++;
cristybb503372010-05-27 20:51:26 +00005002 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005003 ThrowMogrifyException(OptionError,"MissingArgument",option);
5004 if (IsGeometry(argv[i]) == MagickFalse)
5005 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5006 break;
5007 }
5008 if (LocaleCompare("function",option+1) == 0)
5009 {
cristybb503372010-05-27 20:51:26 +00005010 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005011 op;
5012
5013 if (*option == '+')
5014 break;
5015 i++;
cristybb503372010-05-27 20:51:26 +00005016 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005017 ThrowMogrifyException(OptionError,"MissingArgument",option);
5018 op=ParseMagickOption(MagickFunctionOptions,MagickFalse,argv[i]);
5019 if (op < 0)
5020 ThrowMogrifyException(OptionError,"UnrecognizedFunction",argv[i]);
5021 i++;
cristybb503372010-05-27 20:51:26 +00005022 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005023 ThrowMogrifyException(OptionError,"MissingArgument",option);
5024 break;
5025 }
5026 if (LocaleCompare("fuzz",option+1) == 0)
5027 {
5028 if (*option == '+')
5029 break;
5030 i++;
cristybb503372010-05-27 20:51:26 +00005031 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005032 ThrowMogrifyException(OptionError,"MissingArgument",option);
5033 if (IsGeometry(argv[i]) == MagickFalse)
5034 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5035 break;
5036 }
5037 if (LocaleCompare("fx",option+1) == 0)
5038 {
5039 if (*option == '+')
5040 break;
5041 i++;
cristybb503372010-05-27 20:51:26 +00005042 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005043 ThrowMogrifyException(OptionError,"MissingArgument",option);
5044 break;
5045 }
5046 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5047 }
5048 case 'g':
5049 {
5050 if (LocaleCompare("gamma",option+1) == 0)
5051 {
5052 i++;
cristybb503372010-05-27 20:51:26 +00005053 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005054 ThrowMogrifyException(OptionError,"MissingArgument",option);
5055 if (IsGeometry(argv[i]) == MagickFalse)
5056 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5057 break;
5058 }
5059 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
5060 (LocaleCompare("gaussian",option+1) == 0))
5061 {
5062 i++;
cristybb503372010-05-27 20:51:26 +00005063 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005064 ThrowMogrifyException(OptionError,"MissingArgument",option);
5065 if (IsGeometry(argv[i]) == MagickFalse)
5066 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5067 break;
5068 }
5069 if (LocaleCompare("geometry",option+1) == 0)
5070 {
5071 if (*option == '+')
5072 break;
5073 i++;
cristybb503372010-05-27 20:51:26 +00005074 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005075 ThrowMogrifyException(OptionError,"MissingArgument",option);
5076 if (IsGeometry(argv[i]) == MagickFalse)
5077 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5078 break;
5079 }
5080 if (LocaleCompare("gravity",option+1) == 0)
5081 {
cristybb503372010-05-27 20:51:26 +00005082 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005083 gravity;
5084
5085 if (*option == '+')
5086 break;
5087 i++;
cristybb503372010-05-27 20:51:26 +00005088 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005089 ThrowMogrifyException(OptionError,"MissingArgument",option);
5090 gravity=ParseMagickOption(MagickGravityOptions,MagickFalse,argv[i]);
5091 if (gravity < 0)
5092 ThrowMogrifyException(OptionError,"UnrecognizedGravityType",
5093 argv[i]);
5094 break;
5095 }
5096 if (LocaleCompare("green-primary",option+1) == 0)
5097 {
5098 if (*option == '+')
5099 break;
5100 i++;
cristybb503372010-05-27 20:51:26 +00005101 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005102 ThrowMogrifyException(OptionError,"MissingArgument",option);
5103 if (IsGeometry(argv[i]) == MagickFalse)
5104 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5105 break;
5106 }
5107 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5108 }
5109 case 'h':
5110 {
5111 if (LocaleCompare("hald-clut",option+1) == 0)
5112 break;
5113 if ((LocaleCompare("help",option+1) == 0) ||
5114 (LocaleCompare("-help",option+1) == 0))
5115 return(MogrifyUsage());
5116 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5117 }
5118 case 'i':
5119 {
5120 if (LocaleCompare("identify",option+1) == 0)
5121 break;
5122 if (LocaleCompare("idft",option+1) == 0)
5123 break;
5124 if (LocaleCompare("implode",option+1) == 0)
5125 {
5126 if (*option == '+')
5127 break;
5128 i++;
cristybb503372010-05-27 20:51:26 +00005129 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005130 ThrowMogrifyException(OptionError,"MissingArgument",option);
5131 if (IsGeometry(argv[i]) == MagickFalse)
5132 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5133 break;
5134 }
5135 if (LocaleCompare("intent",option+1) == 0)
5136 {
cristybb503372010-05-27 20:51:26 +00005137 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005138 intent;
5139
5140 if (*option == '+')
5141 break;
5142 i++;
cristybb503372010-05-27 20:51:26 +00005143 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005144 ThrowMogrifyException(OptionError,"MissingArgument",option);
5145 intent=ParseMagickOption(MagickIntentOptions,MagickFalse,argv[i]);
5146 if (intent < 0)
5147 ThrowMogrifyException(OptionError,"UnrecognizedIntentType",
5148 argv[i]);
5149 break;
5150 }
5151 if (LocaleCompare("interlace",option+1) == 0)
5152 {
cristybb503372010-05-27 20:51:26 +00005153 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005154 interlace;
5155
5156 if (*option == '+')
5157 break;
5158 i++;
cristybb503372010-05-27 20:51:26 +00005159 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005160 ThrowMogrifyException(OptionError,"MissingArgument",option);
5161 interlace=ParseMagickOption(MagickInterlaceOptions,MagickFalse,
5162 argv[i]);
5163 if (interlace < 0)
5164 ThrowMogrifyException(OptionError,"UnrecognizedInterlaceType",
5165 argv[i]);
5166 break;
5167 }
cristyb32b90a2009-09-07 21:45:48 +00005168 if (LocaleCompare("interline-spacing",option+1) == 0)
5169 {
5170 if (*option == '+')
5171 break;
5172 i++;
cristybb503372010-05-27 20:51:26 +00005173 if (i == (ssize_t) (argc-1))
cristyb32b90a2009-09-07 21:45:48 +00005174 ThrowMogrifyException(OptionError,"MissingArgument",option);
5175 if (IsGeometry(argv[i]) == MagickFalse)
5176 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5177 break;
5178 }
cristy3ed852e2009-09-05 21:47:34 +00005179 if (LocaleCompare("interpolate",option+1) == 0)
5180 {
cristybb503372010-05-27 20:51:26 +00005181 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005182 interpolate;
5183
5184 if (*option == '+')
5185 break;
5186 i++;
cristybb503372010-05-27 20:51:26 +00005187 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005188 ThrowMogrifyException(OptionError,"MissingArgument",option);
5189 interpolate=ParseMagickOption(MagickInterpolateOptions,MagickFalse,
5190 argv[i]);
5191 if (interpolate < 0)
5192 ThrowMogrifyException(OptionError,"UnrecognizedInterpolateMethod",
5193 argv[i]);
5194 break;
5195 }
5196 if (LocaleCompare("interword-spacing",option+1) == 0)
5197 {
5198 if (*option == '+')
5199 break;
5200 i++;
cristybb503372010-05-27 20:51:26 +00005201 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005202 ThrowMogrifyException(OptionError,"MissingArgument",option);
5203 if (IsGeometry(argv[i]) == MagickFalse)
5204 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5205 break;
5206 }
5207 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5208 }
5209 case 'k':
5210 {
5211 if (LocaleCompare("kerning",option+1) == 0)
5212 {
5213 if (*option == '+')
5214 break;
5215 i++;
cristybb503372010-05-27 20:51:26 +00005216 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005217 ThrowMogrifyException(OptionError,"MissingArgument",option);
5218 if (IsGeometry(argv[i]) == MagickFalse)
5219 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5220 break;
5221 }
5222 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5223 }
5224 case 'l':
5225 {
5226 if (LocaleCompare("label",option+1) == 0)
5227 {
5228 if (*option == '+')
5229 break;
5230 i++;
cristybb503372010-05-27 20:51:26 +00005231 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005232 ThrowMogrifyException(OptionError,"MissingArgument",option);
5233 break;
5234 }
5235 if (LocaleCompare("lat",option+1) == 0)
5236 {
5237 if (*option == '+')
5238 break;
5239 i++;
cristybb503372010-05-27 20:51:26 +00005240 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005241 ThrowMogrifyException(OptionError,"MissingArgument",option);
5242 if (IsGeometry(argv[i]) == MagickFalse)
5243 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5244 }
5245 if (LocaleCompare("layers",option+1) == 0)
5246 {
cristybb503372010-05-27 20:51:26 +00005247 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005248 type;
5249
5250 if (*option == '+')
5251 break;
5252 i++;
cristybb503372010-05-27 20:51:26 +00005253 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005254 ThrowMogrifyException(OptionError,"MissingArgument",option);
5255 type=ParseMagickOption(MagickLayerOptions,MagickFalse,argv[i]);
5256 if (type < 0)
5257 ThrowMogrifyException(OptionError,"UnrecognizedLayerMethod",
5258 argv[i]);
5259 break;
5260 }
5261 if (LocaleCompare("level",option+1) == 0)
5262 {
5263 i++;
cristybb503372010-05-27 20:51:26 +00005264 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005265 ThrowMogrifyException(OptionError,"MissingArgument",option);
5266 if (IsGeometry(argv[i]) == MagickFalse)
5267 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5268 break;
5269 }
5270 if (LocaleCompare("level-colors",option+1) == 0)
5271 {
5272 i++;
cristybb503372010-05-27 20:51:26 +00005273 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005274 ThrowMogrifyException(OptionError,"MissingArgument",option);
5275 break;
5276 }
5277 if (LocaleCompare("linewidth",option+1) == 0)
5278 {
5279 if (*option == '+')
5280 break;
5281 i++;
cristybb503372010-05-27 20:51:26 +00005282 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005283 ThrowMogrifyException(OptionError,"MissingArgument",option);
5284 if (IsGeometry(argv[i]) == MagickFalse)
5285 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5286 break;
5287 }
5288 if (LocaleCompare("limit",option+1) == 0)
5289 {
5290 char
5291 *p;
5292
5293 double
5294 value;
5295
cristybb503372010-05-27 20:51:26 +00005296 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005297 resource;
5298
5299 if (*option == '+')
5300 break;
5301 i++;
cristybb503372010-05-27 20:51:26 +00005302 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005303 ThrowMogrifyException(OptionError,"MissingArgument",option);
5304 resource=ParseMagickOption(MagickResourceOptions,MagickFalse,
5305 argv[i]);
5306 if (resource < 0)
5307 ThrowMogrifyException(OptionError,"UnrecognizedResourceType",
5308 argv[i]);
5309 i++;
cristybb503372010-05-27 20:51:26 +00005310 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005311 ThrowMogrifyException(OptionError,"MissingArgument",option);
5312 value=strtod(argv[i],&p);
cristyda16f162011-02-19 23:52:17 +00005313 (void) value;
cristy3ed852e2009-09-05 21:47:34 +00005314 if ((p == argv[i]) && (LocaleCompare("unlimited",argv[i]) != 0))
5315 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5316 break;
5317 }
5318 if (LocaleCompare("liquid-rescale",option+1) == 0)
5319 {
5320 i++;
cristybb503372010-05-27 20:51:26 +00005321 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005322 ThrowMogrifyException(OptionError,"MissingArgument",option);
5323 if (IsGeometry(argv[i]) == MagickFalse)
5324 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5325 break;
5326 }
5327 if (LocaleCompare("list",option+1) == 0)
5328 {
cristybb503372010-05-27 20:51:26 +00005329 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005330 list;
5331
5332 if (*option == '+')
5333 break;
5334 i++;
cristybb503372010-05-27 20:51:26 +00005335 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005336 ThrowMogrifyException(OptionError,"MissingArgument",option);
5337 list=ParseMagickOption(MagickListOptions,MagickFalse,argv[i]);
5338 if (list < 0)
5339 ThrowMogrifyException(OptionError,"UnrecognizedListType",argv[i]);
cristyaeb2cbc2010-05-07 13:28:58 +00005340 status=MogrifyImageInfo(image_info,(int) (i-j+1),(const char **)
cristy3ed852e2009-09-05 21:47:34 +00005341 argv+j,exception);
cristyaeb2cbc2010-05-07 13:28:58 +00005342 return(status != 0 ? MagickFalse : MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00005343 }
5344 if (LocaleCompare("log",option+1) == 0)
5345 {
5346 if (*option == '+')
5347 break;
5348 i++;
cristybb503372010-05-27 20:51:26 +00005349 if ((i == (ssize_t) argc) ||
cristy3ed852e2009-09-05 21:47:34 +00005350 (strchr(argv[i],'%') == (char *) NULL))
5351 ThrowMogrifyException(OptionError,"MissingArgument",option);
5352 break;
5353 }
5354 if (LocaleCompare("loop",option+1) == 0)
5355 {
5356 if (*option == '+')
5357 break;
5358 i++;
cristybb503372010-05-27 20:51:26 +00005359 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005360 ThrowMogrifyException(OptionError,"MissingArgument",option);
5361 if (IsGeometry(argv[i]) == MagickFalse)
5362 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5363 break;
5364 }
5365 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5366 }
5367 case 'm':
5368 {
5369 if (LocaleCompare("map",option+1) == 0)
5370 {
5371 global_colormap=(*option == '+') ? MagickTrue : MagickFalse;
5372 if (*option == '+')
5373 break;
5374 i++;
cristybb503372010-05-27 20:51:26 +00005375 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005376 ThrowMogrifyException(OptionError,"MissingArgument",option);
5377 break;
5378 }
5379 if (LocaleCompare("mask",option+1) == 0)
5380 {
5381 if (*option == '+')
5382 break;
5383 i++;
cristybb503372010-05-27 20:51:26 +00005384 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005385 ThrowMogrifyException(OptionError,"MissingArgument",option);
5386 break;
5387 }
5388 if (LocaleCompare("matte",option+1) == 0)
5389 break;
5390 if (LocaleCompare("mattecolor",option+1) == 0)
5391 {
5392 if (*option == '+')
5393 break;
5394 i++;
cristybb503372010-05-27 20:51:26 +00005395 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005396 ThrowMogrifyException(OptionError,"MissingArgument",option);
5397 break;
5398 }
cristyf40785b2010-03-06 02:27:27 +00005399 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00005400 break;
cristyf40785b2010-03-06 02:27:27 +00005401 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00005402 break;
cristy3ed852e2009-09-05 21:47:34 +00005403 if (LocaleCompare("modulate",option+1) == 0)
5404 {
5405 if (*option == '+')
5406 break;
5407 i++;
cristybb503372010-05-27 20:51:26 +00005408 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005409 ThrowMogrifyException(OptionError,"MissingArgument",option);
5410 if (IsGeometry(argv[i]) == MagickFalse)
5411 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5412 break;
5413 }
5414 if (LocaleCompare("median",option+1) == 0)
5415 {
5416 if (*option == '+')
5417 break;
5418 i++;
cristybb503372010-05-27 20:51:26 +00005419 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005420 ThrowMogrifyException(OptionError,"MissingArgument",option);
5421 if (IsGeometry(argv[i]) == MagickFalse)
5422 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5423 break;
5424 }
cristy69ec32d2011-02-27 23:57:09 +00005425 if (LocaleCompare("mode",option+1) == 0)
5426 {
5427 if (*option == '+')
5428 break;
5429 i++;
5430 if (i == (ssize_t) argc)
5431 ThrowMogrifyException(OptionError,"MissingArgument",option);
5432 if (IsGeometry(argv[i]) == MagickFalse)
5433 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5434 break;
5435 }
cristy3ed852e2009-09-05 21:47:34 +00005436 if (LocaleCompare("monitor",option+1) == 0)
5437 break;
5438 if (LocaleCompare("monochrome",option+1) == 0)
5439 break;
5440 if (LocaleCompare("morph",option+1) == 0)
5441 {
5442 if (*option == '+')
5443 break;
5444 i++;
cristybb503372010-05-27 20:51:26 +00005445 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005446 ThrowMogrifyException(OptionError,"MissingArgument",option);
5447 if (IsGeometry(argv[i]) == MagickFalse)
5448 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5449 break;
5450 }
anthony29188a82010-01-22 10:12:34 +00005451 if (LocaleCompare("morphology",option+1) == 0)
5452 {
anthony29188a82010-01-22 10:12:34 +00005453 char
5454 token[MaxTextExtent];
5455
cristyb6bd4ad2010-08-08 01:12:27 +00005456 KernelInfo
5457 *kernel_info;
5458
5459 ssize_t
5460 op;
5461
anthony29188a82010-01-22 10:12:34 +00005462 i++;
cristybb503372010-05-27 20:51:26 +00005463 if (i == (ssize_t) argc)
anthony29188a82010-01-22 10:12:34 +00005464 ThrowMogrifyException(OptionError,"MissingArgument",option);
5465 GetMagickToken(argv[i],NULL,token);
5466 op=ParseMagickOption(MagickMorphologyOptions,MagickFalse,token);
5467 if (op < 0)
5468 ThrowMogrifyException(OptionError,"UnrecognizedMorphologyMethod",
cristyf0c78232010-03-15 12:53:40 +00005469 token);
anthony29188a82010-01-22 10:12:34 +00005470 i++;
cristybb503372010-05-27 20:51:26 +00005471 if (i == (ssize_t) (argc-1))
anthony29188a82010-01-22 10:12:34 +00005472 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00005473 kernel_info=AcquireKernelInfo(argv[i]);
5474 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00005475 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00005476 kernel_info=DestroyKernelInfo(kernel_info);
anthony29188a82010-01-22 10:12:34 +00005477 break;
5478 }
cristy3ed852e2009-09-05 21:47:34 +00005479 if (LocaleCompare("mosaic",option+1) == 0)
5480 break;
5481 if (LocaleCompare("motion-blur",option+1) == 0)
5482 {
5483 if (*option == '+')
5484 break;
5485 i++;
cristybb503372010-05-27 20:51:26 +00005486 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005487 ThrowMogrifyException(OptionError,"MissingArgument",option);
5488 if (IsGeometry(argv[i]) == MagickFalse)
5489 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5490 break;
5491 }
5492 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5493 }
5494 case 'n':
5495 {
5496 if (LocaleCompare("negate",option+1) == 0)
5497 break;
5498 if (LocaleCompare("noise",option+1) == 0)
5499 {
5500 i++;
cristybb503372010-05-27 20:51:26 +00005501 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005502 ThrowMogrifyException(OptionError,"MissingArgument",option);
5503 if (*option == '+')
5504 {
cristybb503372010-05-27 20:51:26 +00005505 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005506 noise;
5507
5508 noise=ParseMagickOption(MagickNoiseOptions,MagickFalse,argv[i]);
5509 if (noise < 0)
5510 ThrowMogrifyException(OptionError,"UnrecognizedNoiseType",
5511 argv[i]);
5512 break;
5513 }
5514 if (IsGeometry(argv[i]) == MagickFalse)
5515 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5516 break;
5517 }
5518 if (LocaleCompare("noop",option+1) == 0)
5519 break;
5520 if (LocaleCompare("normalize",option+1) == 0)
5521 break;
5522 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5523 }
5524 case 'o':
5525 {
5526 if (LocaleCompare("opaque",option+1) == 0)
5527 {
cristy3ed852e2009-09-05 21:47:34 +00005528 i++;
cristybb503372010-05-27 20:51:26 +00005529 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005530 ThrowMogrifyException(OptionError,"MissingArgument",option);
5531 break;
5532 }
5533 if (LocaleCompare("ordered-dither",option+1) == 0)
5534 {
5535 if (*option == '+')
5536 break;
5537 i++;
cristybb503372010-05-27 20:51:26 +00005538 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005539 ThrowMogrifyException(OptionError,"MissingArgument",option);
5540 break;
5541 }
5542 if (LocaleCompare("orient",option+1) == 0)
5543 {
cristybb503372010-05-27 20:51:26 +00005544 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005545 orientation;
5546
5547 orientation=UndefinedOrientation;
5548 if (*option == '+')
5549 break;
5550 i++;
cristybb503372010-05-27 20:51:26 +00005551 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005552 ThrowMogrifyException(OptionError,"MissingArgument",option);
5553 orientation=ParseMagickOption(MagickOrientationOptions,MagickFalse,
5554 argv[i]);
5555 if (orientation < 0)
5556 ThrowMogrifyException(OptionError,"UnrecognizedImageOrientation",
5557 argv[i]);
5558 break;
5559 }
5560 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5561 }
5562 case 'p':
5563 {
5564 if (LocaleCompare("page",option+1) == 0)
5565 {
5566 if (*option == '+')
5567 break;
5568 i++;
cristybb503372010-05-27 20:51:26 +00005569 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005570 ThrowMogrifyException(OptionError,"MissingArgument",option);
5571 break;
5572 }
5573 if (LocaleCompare("paint",option+1) == 0)
5574 {
5575 if (*option == '+')
5576 break;
5577 i++;
cristybb503372010-05-27 20:51:26 +00005578 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005579 ThrowMogrifyException(OptionError,"MissingArgument",option);
5580 if (IsGeometry(argv[i]) == MagickFalse)
5581 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5582 break;
5583 }
5584 if (LocaleCompare("path",option+1) == 0)
5585 {
5586 (void) CloneString(&path,(char *) NULL);
5587 if (*option == '+')
5588 break;
5589 i++;
cristybb503372010-05-27 20:51:26 +00005590 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005591 ThrowMogrifyException(OptionError,"MissingArgument",option);
5592 (void) CloneString(&path,argv[i]);
5593 break;
5594 }
5595 if (LocaleCompare("pointsize",option+1) == 0)
5596 {
5597 if (*option == '+')
5598 break;
5599 i++;
cristybb503372010-05-27 20:51:26 +00005600 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005601 ThrowMogrifyException(OptionError,"MissingArgument",option);
5602 if (IsGeometry(argv[i]) == MagickFalse)
5603 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5604 break;
5605 }
5606 if (LocaleCompare("polaroid",option+1) == 0)
5607 {
5608 if (*option == '+')
5609 break;
5610 i++;
cristybb503372010-05-27 20:51:26 +00005611 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005612 ThrowMogrifyException(OptionError,"MissingArgument",option);
5613 if (IsGeometry(argv[i]) == MagickFalse)
5614 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5615 break;
5616 }
5617 if (LocaleCompare("posterize",option+1) == 0)
5618 {
5619 if (*option == '+')
5620 break;
5621 i++;
cristybb503372010-05-27 20:51:26 +00005622 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005623 ThrowMogrifyException(OptionError,"MissingArgument",option);
5624 if (IsGeometry(argv[i]) == MagickFalse)
5625 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5626 break;
5627 }
cristye7f51092010-01-17 00:39:37 +00005628 if (LocaleCompare("precision",option+1) == 0)
5629 {
5630 if (*option == '+')
5631 break;
5632 i++;
cristybb503372010-05-27 20:51:26 +00005633 if (i == (ssize_t) argc)
cristye7f51092010-01-17 00:39:37 +00005634 ThrowMogrifyException(OptionError,"MissingArgument",option);
5635 if (IsGeometry(argv[i]) == MagickFalse)
5636 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5637 break;
5638 }
cristy3ed852e2009-09-05 21:47:34 +00005639 if (LocaleCompare("print",option+1) == 0)
5640 {
5641 if (*option == '+')
5642 break;
5643 i++;
cristybb503372010-05-27 20:51:26 +00005644 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005645 ThrowMogrifyException(OptionError,"MissingArgument",option);
5646 break;
5647 }
5648 if (LocaleCompare("process",option+1) == 0)
5649 {
5650 if (*option == '+')
5651 break;
5652 i++;
cristybb503372010-05-27 20:51:26 +00005653 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005654 ThrowMogrifyException(OptionError,"MissingArgument",option);
5655 break;
5656 }
5657 if (LocaleCompare("profile",option+1) == 0)
5658 {
5659 i++;
cristybb503372010-05-27 20:51:26 +00005660 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005661 ThrowMogrifyException(OptionError,"MissingArgument",option);
5662 break;
5663 }
5664 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5665 }
5666 case 'q':
5667 {
5668 if (LocaleCompare("quality",option+1) == 0)
5669 {
5670 if (*option == '+')
5671 break;
5672 i++;
cristybb503372010-05-27 20:51:26 +00005673 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005674 ThrowMogrifyException(OptionError,"MissingArgument",option);
5675 if (IsGeometry(argv[i]) == MagickFalse)
5676 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5677 break;
5678 }
5679 if (LocaleCompare("quantize",option+1) == 0)
5680 {
cristybb503372010-05-27 20:51:26 +00005681 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005682 colorspace;
5683
5684 if (*option == '+')
5685 break;
5686 i++;
cristybb503372010-05-27 20:51:26 +00005687 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005688 ThrowMogrifyException(OptionError,"MissingArgument",option);
5689 colorspace=ParseMagickOption(MagickColorspaceOptions,MagickFalse,
5690 argv[i]);
5691 if (colorspace < 0)
5692 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
5693 argv[i]);
5694 break;
5695 }
5696 if (LocaleCompare("quiet",option+1) == 0)
5697 break;
5698 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5699 }
5700 case 'r':
5701 {
5702 if (LocaleCompare("radial-blur",option+1) == 0)
5703 {
5704 i++;
cristybb503372010-05-27 20:51:26 +00005705 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005706 ThrowMogrifyException(OptionError,"MissingArgument",option);
5707 if (IsGeometry(argv[i]) == MagickFalse)
5708 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5709 break;
5710 }
5711 if (LocaleCompare("raise",option+1) == 0)
5712 {
5713 i++;
cristybb503372010-05-27 20:51:26 +00005714 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005715 ThrowMogrifyException(OptionError,"MissingArgument",option);
5716 if (IsGeometry(argv[i]) == MagickFalse)
5717 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5718 break;
5719 }
5720 if (LocaleCompare("random-threshold",option+1) == 0)
5721 {
5722 if (*option == '+')
5723 break;
5724 i++;
cristybb503372010-05-27 20:51:26 +00005725 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005726 ThrowMogrifyException(OptionError,"MissingArgument",option);
5727 if (IsGeometry(argv[i]) == MagickFalse)
5728 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5729 break;
5730 }
cristye6365592010-04-02 17:31:23 +00005731 if (LocaleCompare("recolor",option+1) == 0)
5732 {
5733 if (*option == '+')
5734 break;
5735 i++;
cristybb503372010-05-27 20:51:26 +00005736 if (i == (ssize_t) (argc-1))
cristye6365592010-04-02 17:31:23 +00005737 ThrowMogrifyException(OptionError,"MissingArgument",option);
5738 if (IsGeometry(argv[i]) == MagickFalse)
5739 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5740 break;
5741 }
cristy3ed852e2009-09-05 21:47:34 +00005742 if (LocaleCompare("red-primary",option+1) == 0)
5743 {
5744 if (*option == '+')
5745 break;
5746 i++;
cristybb503372010-05-27 20:51:26 +00005747 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005748 ThrowMogrifyException(OptionError,"MissingArgument",option);
5749 if (IsGeometry(argv[i]) == MagickFalse)
5750 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5751 }
cristy9f2083a2010-04-22 19:48:05 +00005752 if (LocaleCompare("regard-warnings",option+1) == 0)
5753 break;
cristy3ed852e2009-09-05 21:47:34 +00005754 if (LocaleCompare("region",option+1) == 0)
5755 {
5756 if (*option == '+')
5757 break;
5758 i++;
cristybb503372010-05-27 20:51:26 +00005759 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005760 ThrowMogrifyException(OptionError,"MissingArgument",option);
5761 if (IsGeometry(argv[i]) == MagickFalse)
5762 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5763 break;
5764 }
cristyf0c78232010-03-15 12:53:40 +00005765 if (LocaleCompare("remap",option+1) == 0)
5766 {
5767 if (*option == '+')
5768 break;
5769 i++;
cristybb503372010-05-27 20:51:26 +00005770 if (i == (ssize_t) (argc-1))
cristyf0c78232010-03-15 12:53:40 +00005771 ThrowMogrifyException(OptionError,"MissingArgument",option);
5772 break;
5773 }
cristy3ed852e2009-09-05 21:47:34 +00005774 if (LocaleCompare("render",option+1) == 0)
5775 break;
5776 if (LocaleCompare("repage",option+1) == 0)
5777 {
5778 if (*option == '+')
5779 break;
5780 i++;
cristybb503372010-05-27 20:51:26 +00005781 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005782 ThrowMogrifyException(OptionError,"MissingArgument",option);
5783 if (IsGeometry(argv[i]) == MagickFalse)
5784 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5785 break;
5786 }
5787 if (LocaleCompare("resample",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("resize",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 }
cristyebbcfea2011-02-25 02:43:54 +00005809 if (LocaleNCompare("respect-parentheses",option+1,17) == 0)
5810 {
5811 respect_parenthesis=(*option == '-') ? MagickTrue : MagickFalse;
5812 break;
5813 }
cristy3ed852e2009-09-05 21:47:34 +00005814 if (LocaleCompare("reverse",option+1) == 0)
5815 break;
5816 if (LocaleCompare("roll",option+1) == 0)
5817 {
5818 if (*option == '+')
5819 break;
5820 i++;
cristybb503372010-05-27 20:51:26 +00005821 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005822 ThrowMogrifyException(OptionError,"MissingArgument",option);
5823 if (IsGeometry(argv[i]) == MagickFalse)
5824 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5825 break;
5826 }
5827 if (LocaleCompare("rotate",option+1) == 0)
5828 {
5829 i++;
cristybb503372010-05-27 20:51:26 +00005830 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005831 ThrowMogrifyException(OptionError,"MissingArgument",option);
5832 if (IsGeometry(argv[i]) == MagickFalse)
5833 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5834 break;
5835 }
5836 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5837 }
5838 case 's':
5839 {
5840 if (LocaleCompare("sample",option+1) == 0)
5841 {
5842 if (*option == '+')
5843 break;
5844 i++;
cristybb503372010-05-27 20:51:26 +00005845 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005846 ThrowMogrifyException(OptionError,"MissingArgument",option);
5847 if (IsGeometry(argv[i]) == MagickFalse)
5848 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5849 break;
5850 }
5851 if (LocaleCompare("sampling-factor",option+1) == 0)
5852 {
5853 if (*option == '+')
5854 break;
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("scale",option+1) == 0)
5863 {
5864 if (*option == '+')
5865 break;
5866 i++;
cristybb503372010-05-27 20:51:26 +00005867 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005868 ThrowMogrifyException(OptionError,"MissingArgument",option);
5869 if (IsGeometry(argv[i]) == MagickFalse)
5870 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5871 break;
5872 }
5873 if (LocaleCompare("scene",option+1) == 0)
5874 {
5875 if (*option == '+')
5876 break;
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 (IsGeometry(argv[i]) == MagickFalse)
5881 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5882 break;
5883 }
5884 if (LocaleCompare("seed",option+1) == 0)
5885 {
5886 if (*option == '+')
5887 break;
5888 i++;
cristybb503372010-05-27 20:51:26 +00005889 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005890 ThrowMogrifyException(OptionError,"MissingArgument",option);
5891 if (IsGeometry(argv[i]) == MagickFalse)
5892 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5893 break;
5894 }
5895 if (LocaleCompare("segment",option+1) == 0)
5896 {
5897 if (*option == '+')
5898 break;
5899 i++;
cristybb503372010-05-27 20:51:26 +00005900 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005901 ThrowMogrifyException(OptionError,"MissingArgument",option);
5902 if (IsGeometry(argv[i]) == MagickFalse)
5903 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5904 break;
5905 }
5906 if (LocaleCompare("selective-blur",option+1) == 0)
5907 {
5908 i++;
cristybb503372010-05-27 20:51:26 +00005909 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005910 ThrowMogrifyException(OptionError,"MissingArgument",option);
5911 if (IsGeometry(argv[i]) == MagickFalse)
5912 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5913 break;
5914 }
5915 if (LocaleCompare("separate",option+1) == 0)
5916 break;
5917 if (LocaleCompare("sepia-tone",option+1) == 0)
5918 {
5919 if (*option == '+')
5920 break;
5921 i++;
cristybb503372010-05-27 20:51:26 +00005922 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005923 ThrowMogrifyException(OptionError,"MissingArgument",option);
5924 if (IsGeometry(argv[i]) == MagickFalse)
5925 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5926 break;
5927 }
5928 if (LocaleCompare("set",option+1) == 0)
5929 {
5930 i++;
cristybb503372010-05-27 20:51:26 +00005931 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005932 ThrowMogrifyException(OptionError,"MissingArgument",option);
5933 if (*option == '+')
5934 break;
5935 i++;
cristybb503372010-05-27 20:51:26 +00005936 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005937 ThrowMogrifyException(OptionError,"MissingArgument",option);
5938 break;
5939 }
5940 if (LocaleCompare("shade",option+1) == 0)
5941 {
5942 i++;
cristybb503372010-05-27 20:51:26 +00005943 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005944 ThrowMogrifyException(OptionError,"MissingArgument",option);
5945 if (IsGeometry(argv[i]) == MagickFalse)
5946 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5947 break;
5948 }
5949 if (LocaleCompare("shadow",option+1) == 0)
5950 {
5951 if (*option == '+')
5952 break;
5953 i++;
cristybb503372010-05-27 20:51:26 +00005954 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005955 ThrowMogrifyException(OptionError,"MissingArgument",option);
5956 if (IsGeometry(argv[i]) == MagickFalse)
5957 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5958 break;
5959 }
5960 if (LocaleCompare("sharpen",option+1) == 0)
5961 {
5962 i++;
cristybb503372010-05-27 20:51:26 +00005963 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005964 ThrowMogrifyException(OptionError,"MissingArgument",option);
5965 if (IsGeometry(argv[i]) == MagickFalse)
5966 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5967 break;
5968 }
5969 if (LocaleCompare("shave",option+1) == 0)
5970 {
5971 if (*option == '+')
5972 break;
5973 i++;
cristybb503372010-05-27 20:51:26 +00005974 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005975 ThrowMogrifyException(OptionError,"MissingArgument",option);
5976 if (IsGeometry(argv[i]) == MagickFalse)
5977 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5978 break;
5979 }
5980 if (LocaleCompare("shear",option+1) == 0)
5981 {
5982 i++;
cristybb503372010-05-27 20:51:26 +00005983 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005984 ThrowMogrifyException(OptionError,"MissingArgument",option);
5985 if (IsGeometry(argv[i]) == MagickFalse)
5986 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5987 break;
5988 }
5989 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
5990 {
5991 i++;
cristybb503372010-05-27 20:51:26 +00005992 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005993 ThrowMogrifyException(OptionError,"MissingArgument",option);
5994 if (IsGeometry(argv[i]) == MagickFalse)
5995 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5996 break;
5997 }
5998 if (LocaleCompare("size",option+1) == 0)
5999 {
6000 if (*option == '+')
6001 break;
6002 i++;
cristybb503372010-05-27 20:51:26 +00006003 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006004 ThrowMogrifyException(OptionError,"MissingArgument",option);
6005 if (IsGeometry(argv[i]) == MagickFalse)
6006 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6007 break;
6008 }
6009 if (LocaleCompare("sketch",option+1) == 0)
6010 {
6011 if (*option == '+')
6012 break;
6013 i++;
cristybb503372010-05-27 20:51:26 +00006014 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006015 ThrowMogrifyException(OptionError,"MissingArgument",option);
6016 if (IsGeometry(argv[i]) == MagickFalse)
6017 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6018 break;
6019 }
cristy4285d782011-02-09 20:12:28 +00006020 if (LocaleCompare("smush",option+1) == 0)
6021 {
cristy4285d782011-02-09 20:12:28 +00006022 i++;
6023 if (i == (ssize_t) argc)
6024 ThrowMogrifyException(OptionError,"MissingArgument",option);
6025 if (IsGeometry(argv[i]) == MagickFalse)
6026 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristy4285d782011-02-09 20:12:28 +00006027 i++;
6028 break;
6029 }
cristy3ed852e2009-09-05 21:47:34 +00006030 if (LocaleCompare("solarize",option+1) == 0)
6031 {
6032 if (*option == '+')
6033 break;
6034 i++;
cristybb503372010-05-27 20:51:26 +00006035 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006036 ThrowMogrifyException(OptionError,"MissingArgument",option);
6037 if (IsGeometry(argv[i]) == MagickFalse)
6038 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6039 break;
6040 }
6041 if (LocaleCompare("sparse-color",option+1) == 0)
6042 {
cristybb503372010-05-27 20:51:26 +00006043 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006044 op;
6045
6046 i++;
cristybb503372010-05-27 20:51:26 +00006047 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006048 ThrowMogrifyException(OptionError,"MissingArgument",option);
6049 op=ParseMagickOption(MagickSparseColorOptions,MagickFalse,argv[i]);
6050 if (op < 0)
6051 ThrowMogrifyException(OptionError,"UnrecognizedSparseColorMethod",
6052 argv[i]);
6053 i++;
cristybb503372010-05-27 20:51:26 +00006054 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006055 ThrowMogrifyException(OptionError,"MissingArgument",option);
6056 break;
6057 }
6058 if (LocaleCompare("spread",option+1) == 0)
6059 {
6060 if (*option == '+')
6061 break;
6062 i++;
cristybb503372010-05-27 20:51:26 +00006063 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006064 ThrowMogrifyException(OptionError,"MissingArgument",option);
6065 if (IsGeometry(argv[i]) == MagickFalse)
6066 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6067 break;
6068 }
6069 if (LocaleCompare("stretch",option+1) == 0)
6070 {
cristybb503372010-05-27 20:51:26 +00006071 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006072 stretch;
6073
6074 if (*option == '+')
6075 break;
6076 i++;
cristybb503372010-05-27 20:51:26 +00006077 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006078 ThrowMogrifyException(OptionError,"MissingArgument",option);
6079 stretch=ParseMagickOption(MagickStretchOptions,MagickFalse,argv[i]);
6080 if (stretch < 0)
6081 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
6082 argv[i]);
6083 break;
6084 }
6085 if (LocaleCompare("strip",option+1) == 0)
6086 break;
6087 if (LocaleCompare("stroke",option+1) == 0)
6088 {
6089 if (*option == '+')
6090 break;
6091 i++;
cristybb503372010-05-27 20:51:26 +00006092 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006093 ThrowMogrifyException(OptionError,"MissingArgument",option);
6094 break;
6095 }
6096 if (LocaleCompare("strokewidth",option+1) == 0)
6097 {
6098 if (*option == '+')
6099 break;
6100 i++;
cristybb503372010-05-27 20:51:26 +00006101 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006102 ThrowMogrifyException(OptionError,"MissingArgument",option);
6103 if (IsGeometry(argv[i]) == MagickFalse)
6104 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6105 break;
6106 }
6107 if (LocaleCompare("style",option+1) == 0)
6108 {
cristybb503372010-05-27 20:51:26 +00006109 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006110 style;
6111
6112 if (*option == '+')
6113 break;
6114 i++;
cristybb503372010-05-27 20:51:26 +00006115 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006116 ThrowMogrifyException(OptionError,"MissingArgument",option);
6117 style=ParseMagickOption(MagickStyleOptions,MagickFalse,argv[i]);
6118 if (style < 0)
6119 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
6120 argv[i]);
6121 break;
6122 }
6123 if (LocaleCompare("swirl",option+1) == 0)
6124 {
6125 if (*option == '+')
6126 break;
6127 i++;
cristybb503372010-05-27 20:51:26 +00006128 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006129 ThrowMogrifyException(OptionError,"MissingArgument",option);
6130 if (IsGeometry(argv[i]) == MagickFalse)
6131 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6132 break;
6133 }
cristyd9a29192010-10-16 16:49:53 +00006134 if (LocaleCompare("synchronize",option+1) == 0)
6135 break;
cristy3ed852e2009-09-05 21:47:34 +00006136 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6137 }
6138 case 't':
6139 {
6140 if (LocaleCompare("taint",option+1) == 0)
6141 break;
6142 if (LocaleCompare("texture",option+1) == 0)
6143 {
6144 if (*option == '+')
6145 break;
6146 i++;
cristybb503372010-05-27 20:51:26 +00006147 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006148 ThrowMogrifyException(OptionError,"MissingArgument",option);
6149 break;
6150 }
6151 if (LocaleCompare("tile",option+1) == 0)
6152 {
6153 if (*option == '+')
6154 break;
6155 i++;
cristybb503372010-05-27 20:51:26 +00006156 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006157 ThrowMogrifyException(OptionError,"MissingArgument",option);
6158 break;
6159 }
6160 if (LocaleCompare("tile-offset",option+1) == 0)
6161 {
6162 if (*option == '+')
6163 break;
6164 i++;
cristybb503372010-05-27 20:51:26 +00006165 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006166 ThrowMogrifyException(OptionError,"MissingArgument",option);
6167 if (IsGeometry(argv[i]) == MagickFalse)
6168 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6169 break;
6170 }
6171 if (LocaleCompare("tint",option+1) == 0)
6172 {
6173 if (*option == '+')
6174 break;
6175 i++;
cristybb503372010-05-27 20:51:26 +00006176 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006177 ThrowMogrifyException(OptionError,"MissingArgument",option);
6178 if (IsGeometry(argv[i]) == MagickFalse)
6179 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6180 break;
6181 }
6182 if (LocaleCompare("transform",option+1) == 0)
6183 break;
6184 if (LocaleCompare("transpose",option+1) == 0)
6185 break;
6186 if (LocaleCompare("transverse",option+1) == 0)
6187 break;
6188 if (LocaleCompare("threshold",option+1) == 0)
6189 {
6190 if (*option == '+')
6191 break;
6192 i++;
cristybb503372010-05-27 20:51:26 +00006193 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006194 ThrowMogrifyException(OptionError,"MissingArgument",option);
6195 if (IsGeometry(argv[i]) == MagickFalse)
6196 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6197 break;
6198 }
6199 if (LocaleCompare("thumbnail",option+1) == 0)
6200 {
6201 if (*option == '+')
6202 break;
6203 i++;
cristybb503372010-05-27 20:51:26 +00006204 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006205 ThrowMogrifyException(OptionError,"MissingArgument",option);
6206 if (IsGeometry(argv[i]) == MagickFalse)
6207 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6208 break;
6209 }
6210 if (LocaleCompare("transparent",option+1) == 0)
6211 {
6212 i++;
cristybb503372010-05-27 20:51:26 +00006213 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006214 ThrowMogrifyException(OptionError,"MissingArgument",option);
6215 break;
6216 }
6217 if (LocaleCompare("transparent-color",option+1) == 0)
6218 {
6219 if (*option == '+')
6220 break;
6221 i++;
cristybb503372010-05-27 20:51:26 +00006222 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006223 ThrowMogrifyException(OptionError,"MissingArgument",option);
6224 break;
6225 }
6226 if (LocaleCompare("treedepth",option+1) == 0)
6227 {
6228 if (*option == '+')
6229 break;
6230 i++;
cristybb503372010-05-27 20:51:26 +00006231 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006232 ThrowMogrifyException(OptionError,"MissingArgument",option);
6233 if (IsGeometry(argv[i]) == MagickFalse)
6234 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6235 break;
6236 }
6237 if (LocaleCompare("trim",option+1) == 0)
6238 break;
6239 if (LocaleCompare("type",option+1) == 0)
6240 {
cristybb503372010-05-27 20:51:26 +00006241 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006242 type;
6243
6244 if (*option == '+')
6245 break;
6246 i++;
cristybb503372010-05-27 20:51:26 +00006247 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006248 ThrowMogrifyException(OptionError,"MissingArgument",option);
6249 type=ParseMagickOption(MagickTypeOptions,MagickFalse,argv[i]);
6250 if (type < 0)
6251 ThrowMogrifyException(OptionError,"UnrecognizedImageType",
6252 argv[i]);
6253 break;
6254 }
6255 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6256 }
6257 case 'u':
6258 {
6259 if (LocaleCompare("undercolor",option+1) == 0)
6260 {
6261 if (*option == '+')
6262 break;
6263 i++;
cristybb503372010-05-27 20:51:26 +00006264 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006265 ThrowMogrifyException(OptionError,"MissingArgument",option);
6266 break;
6267 }
6268 if (LocaleCompare("unique-colors",option+1) == 0)
6269 break;
6270 if (LocaleCompare("units",option+1) == 0)
6271 {
cristybb503372010-05-27 20:51:26 +00006272 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006273 units;
6274
6275 if (*option == '+')
6276 break;
6277 i++;
cristybb503372010-05-27 20:51:26 +00006278 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006279 ThrowMogrifyException(OptionError,"MissingArgument",option);
6280 units=ParseMagickOption(MagickResolutionOptions,MagickFalse,
6281 argv[i]);
6282 if (units < 0)
6283 ThrowMogrifyException(OptionError,"UnrecognizedUnitsType",
6284 argv[i]);
6285 break;
6286 }
6287 if (LocaleCompare("unsharp",option+1) == 0)
6288 {
6289 i++;
cristybb503372010-05-27 20:51:26 +00006290 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006291 ThrowMogrifyException(OptionError,"MissingArgument",option);
6292 if (IsGeometry(argv[i]) == MagickFalse)
6293 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6294 break;
6295 }
6296 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6297 }
6298 case 'v':
6299 {
6300 if (LocaleCompare("verbose",option+1) == 0)
6301 {
6302 image_info->verbose=(*option == '-') ? MagickTrue : MagickFalse;
6303 break;
6304 }
6305 if ((LocaleCompare("version",option+1) == 0) ||
6306 (LocaleCompare("-version",option+1) == 0))
6307 {
6308 (void) fprintf(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +00006309 GetMagickVersion((size_t *) NULL));
cristy610b2e22009-10-22 14:59:43 +00006310 (void) fprintf(stdout,"Copyright: %s\n",GetMagickCopyright());
6311 (void) fprintf(stdout,"Features: %s\n\n",GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00006312 break;
6313 }
6314 if (LocaleCompare("view",option+1) == 0)
6315 {
6316 if (*option == '+')
6317 break;
6318 i++;
cristybb503372010-05-27 20:51:26 +00006319 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006320 ThrowMogrifyException(OptionError,"MissingArgument",option);
6321 break;
6322 }
6323 if (LocaleCompare("vignette",option+1) == 0)
6324 {
6325 if (*option == '+')
6326 break;
6327 i++;
cristybb503372010-05-27 20:51:26 +00006328 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006329 ThrowMogrifyException(OptionError,"MissingArgument",option);
6330 if (IsGeometry(argv[i]) == MagickFalse)
6331 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6332 break;
6333 }
6334 if (LocaleCompare("virtual-pixel",option+1) == 0)
6335 {
cristybb503372010-05-27 20:51:26 +00006336 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006337 method;
6338
6339 if (*option == '+')
6340 break;
6341 i++;
cristybb503372010-05-27 20:51:26 +00006342 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006343 ThrowMogrifyException(OptionError,"MissingArgument",option);
6344 method=ParseMagickOption(MagickVirtualPixelOptions,MagickFalse,
6345 argv[i]);
6346 if (method < 0)
6347 ThrowMogrifyException(OptionError,
6348 "UnrecognizedVirtualPixelMethod",argv[i]);
6349 break;
6350 }
6351 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6352 }
6353 case 'w':
6354 {
6355 if (LocaleCompare("wave",option+1) == 0)
6356 {
6357 i++;
cristybb503372010-05-27 20:51:26 +00006358 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006359 ThrowMogrifyException(OptionError,"MissingArgument",option);
6360 if (IsGeometry(argv[i]) == MagickFalse)
6361 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6362 break;
6363 }
6364 if (LocaleCompare("weight",option+1) == 0)
6365 {
6366 if (*option == '+')
6367 break;
6368 i++;
cristybb503372010-05-27 20:51:26 +00006369 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006370 ThrowMogrifyException(OptionError,"MissingArgument",option);
6371 break;
6372 }
6373 if (LocaleCompare("white-point",option+1) == 0)
6374 {
6375 if (*option == '+')
6376 break;
6377 i++;
cristybb503372010-05-27 20:51:26 +00006378 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006379 ThrowMogrifyException(OptionError,"MissingArgument",option);
6380 if (IsGeometry(argv[i]) == MagickFalse)
6381 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6382 break;
6383 }
6384 if (LocaleCompare("white-threshold",option+1) == 0)
6385 {
6386 if (*option == '+')
6387 break;
6388 i++;
cristybb503372010-05-27 20:51:26 +00006389 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006390 ThrowMogrifyException(OptionError,"MissingArgument",option);
6391 if (IsGeometry(argv[i]) == MagickFalse)
6392 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6393 break;
6394 }
6395 if (LocaleCompare("write",option+1) == 0)
6396 {
6397 i++;
cristybb503372010-05-27 20:51:26 +00006398 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006399 ThrowMogrifyException(OptionError,"MissingArgument",option);
6400 break;
6401 }
6402 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6403 }
6404 case '?':
6405 break;
6406 default:
6407 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6408 }
6409 fire=ParseMagickOption(MagickImageListOptions,MagickFalse,option+1) < 0 ?
6410 MagickFalse : MagickTrue;
6411 if (fire != MagickFalse)
6412 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
6413 }
6414 if (k != 0)
6415 ThrowMogrifyException(OptionError,"UnbalancedParenthesis",argv[i]);
cristycee97112010-05-28 00:44:52 +00006416 if (i != (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006417 ThrowMogrifyException(OptionError,"MissingAnImageFilename",argv[i]);
6418 DestroyMogrify();
6419 return(status != 0 ? MagickTrue : MagickFalse);
6420}
6421
6422/*
6423%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6424% %
6425% %
6426% %
6427+ M o g r i f y I m a g e I n f o %
6428% %
6429% %
6430% %
6431%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6432%
6433% MogrifyImageInfo() applies image processing settings to the image as
6434% prescribed by command line options.
6435%
6436% The format of the MogrifyImageInfo method is:
6437%
6438% MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,const int argc,
6439% const char **argv,ExceptionInfo *exception)
6440%
6441% A description of each parameter follows:
6442%
6443% o image_info: the image info..
6444%
6445% o argc: Specifies a pointer to an integer describing the number of
6446% elements in the argument vector.
6447%
6448% o argv: Specifies a pointer to a text array containing the command line
6449% arguments.
6450%
6451% o exception: return any errors or warnings in this structure.
6452%
6453*/
6454WandExport MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,
6455 const int argc,const char **argv,ExceptionInfo *exception)
6456{
6457 const char
6458 *option;
6459
6460 GeometryInfo
6461 geometry_info;
6462
cristybb503372010-05-27 20:51:26 +00006463 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006464 count;
6465
cristybb503372010-05-27 20:51:26 +00006466 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006467 i;
6468
6469 /*
6470 Initialize method variables.
6471 */
6472 assert(image_info != (ImageInfo *) NULL);
6473 assert(image_info->signature == MagickSignature);
6474 if (image_info->debug != MagickFalse)
6475 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
6476 image_info->filename);
6477 if (argc < 0)
6478 return(MagickTrue);
6479 /*
6480 Set the image settings.
6481 */
cristybb503372010-05-27 20:51:26 +00006482 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00006483 {
6484 option=argv[i];
6485 if (IsMagickOption(option) == MagickFalse)
6486 continue;
6487 count=MagickMax(ParseMagickOption(MagickCommandOptions,MagickFalse,option),
6488 0L);
cristycee97112010-05-28 00:44:52 +00006489 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006490 break;
6491 switch (*(option+1))
6492 {
6493 case 'a':
6494 {
6495 if (LocaleCompare("adjoin",option+1) == 0)
6496 {
6497 image_info->adjoin=(*option == '-') ? MagickTrue : MagickFalse;
6498 break;
6499 }
6500 if (LocaleCompare("antialias",option+1) == 0)
6501 {
6502 image_info->antialias=(*option == '-') ? MagickTrue : MagickFalse;
6503 break;
6504 }
6505 if (LocaleCompare("attenuate",option+1) == 0)
6506 {
6507 if (*option == '+')
6508 {
6509 (void) DeleteImageOption(image_info,option+1);
6510 break;
6511 }
6512 (void) SetImageOption(image_info,option+1,argv[i+1]);
6513 break;
6514 }
6515 if (LocaleCompare("authenticate",option+1) == 0)
6516 {
6517 if (*option == '+')
6518 (void) CloneString(&image_info->authenticate,(char *) NULL);
6519 else
6520 (void) CloneString(&image_info->authenticate,argv[i+1]);
6521 break;
6522 }
6523 break;
6524 }
6525 case 'b':
6526 {
6527 if (LocaleCompare("background",option+1) == 0)
6528 {
6529 if (*option == '+')
6530 {
6531 (void) DeleteImageOption(image_info,option+1);
6532 (void) QueryColorDatabase(BackgroundColor,
6533 &image_info->background_color,exception);
6534 break;
6535 }
6536 (void) SetImageOption(image_info,option+1,argv[i+1]);
6537 (void) QueryColorDatabase(argv[i+1],&image_info->background_color,
6538 exception);
6539 break;
6540 }
6541 if (LocaleCompare("bias",option+1) == 0)
6542 {
6543 if (*option == '+')
6544 {
6545 (void) SetImageOption(image_info,option+1,"0.0");
6546 break;
6547 }
6548 (void) SetImageOption(image_info,option+1,argv[i+1]);
6549 break;
6550 }
6551 if (LocaleCompare("black-point-compensation",option+1) == 0)
6552 {
6553 if (*option == '+')
6554 {
6555 (void) SetImageOption(image_info,option+1,"false");
6556 break;
6557 }
6558 (void) SetImageOption(image_info,option+1,"true");
6559 break;
6560 }
6561 if (LocaleCompare("blue-primary",option+1) == 0)
6562 {
6563 if (*option == '+')
6564 {
6565 (void) SetImageOption(image_info,option+1,"0.0");
6566 break;
6567 }
6568 (void) SetImageOption(image_info,option+1,argv[i+1]);
6569 break;
6570 }
6571 if (LocaleCompare("bordercolor",option+1) == 0)
6572 {
6573 if (*option == '+')
6574 {
6575 (void) DeleteImageOption(image_info,option+1);
6576 (void) QueryColorDatabase(BorderColor,&image_info->border_color,
6577 exception);
6578 break;
6579 }
6580 (void) QueryColorDatabase(argv[i+1],&image_info->border_color,
6581 exception);
6582 (void) SetImageOption(image_info,option+1,argv[i+1]);
6583 break;
6584 }
6585 if (LocaleCompare("box",option+1) == 0)
6586 {
6587 if (*option == '+')
6588 {
6589 (void) SetImageOption(image_info,"undercolor","none");
6590 break;
6591 }
6592 (void) SetImageOption(image_info,"undercolor",argv[i+1]);
6593 break;
6594 }
6595 break;
6596 }
6597 case 'c':
6598 {
6599 if (LocaleCompare("cache",option+1) == 0)
6600 {
6601 MagickSizeType
6602 limit;
6603
6604 limit=MagickResourceInfinity;
6605 if (LocaleCompare("unlimited",argv[i+1]) != 0)
cristyf2f27272009-12-17 14:48:46 +00006606 limit=(MagickSizeType) SiPrefixToDouble(argv[i+1],100.0);
cristy3ed852e2009-09-05 21:47:34 +00006607 (void) SetMagickResourceLimit(MemoryResource,limit);
6608 (void) SetMagickResourceLimit(MapResource,2*limit);
6609 break;
6610 }
6611 if (LocaleCompare("caption",option+1) == 0)
6612 {
6613 if (*option == '+')
6614 {
6615 (void) DeleteImageOption(image_info,option+1);
6616 break;
6617 }
6618 (void) SetImageOption(image_info,option+1,argv[i+1]);
6619 break;
6620 }
6621 if (LocaleCompare("channel",option+1) == 0)
6622 {
6623 if (*option == '+')
6624 {
6625 image_info->channel=DefaultChannels;
6626 break;
6627 }
6628 image_info->channel=(ChannelType) ParseChannelOption(argv[i+1]);
6629 break;
6630 }
6631 if (LocaleCompare("colors",option+1) == 0)
6632 {
cristye27293e2009-12-18 02:53:20 +00006633 image_info->colors=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006634 break;
6635 }
6636 if (LocaleCompare("colorspace",option+1) == 0)
6637 {
6638 if (*option == '+')
6639 {
6640 image_info->colorspace=UndefinedColorspace;
6641 (void) SetImageOption(image_info,option+1,"undefined");
6642 break;
6643 }
6644 image_info->colorspace=(ColorspaceType) ParseMagickOption(
6645 MagickColorspaceOptions,MagickFalse,argv[i+1]);
6646 (void) SetImageOption(image_info,option+1,argv[i+1]);
6647 break;
6648 }
6649 if (LocaleCompare("compress",option+1) == 0)
6650 {
6651 if (*option == '+')
6652 {
6653 image_info->compression=UndefinedCompression;
6654 (void) SetImageOption(image_info,option+1,"undefined");
6655 break;
6656 }
6657 image_info->compression=(CompressionType) ParseMagickOption(
6658 MagickCompressOptions,MagickFalse,argv[i+1]);
6659 (void) SetImageOption(image_info,option+1,argv[i+1]);
6660 break;
6661 }
6662 if (LocaleCompare("comment",option+1) == 0)
6663 {
6664 if (*option == '+')
6665 {
6666 (void) DeleteImageOption(image_info,option+1);
6667 break;
6668 }
6669 (void) SetImageOption(image_info,option+1,argv[i+1]);
6670 break;
6671 }
6672 if (LocaleCompare("compose",option+1) == 0)
6673 {
6674 if (*option == '+')
6675 {
6676 (void) SetImageOption(image_info,option+1,"undefined");
6677 break;
6678 }
6679 (void) SetImageOption(image_info,option+1,argv[i+1]);
6680 break;
6681 }
6682 if (LocaleCompare("compress",option+1) == 0)
6683 {
6684 if (*option == '+')
6685 {
6686 image_info->compression=UndefinedCompression;
6687 (void) SetImageOption(image_info,option+1,"undefined");
6688 break;
6689 }
6690 image_info->compression=(CompressionType) ParseMagickOption(
6691 MagickCompressOptions,MagickFalse,argv[i+1]);
6692 (void) SetImageOption(image_info,option+1,argv[i+1]);
6693 break;
6694 }
6695 break;
6696 }
6697 case 'd':
6698 {
6699 if (LocaleCompare("debug",option+1) == 0)
6700 {
6701 if (*option == '+')
6702 (void) SetLogEventMask("none");
6703 else
6704 (void) SetLogEventMask(argv[i+1]);
6705 image_info->debug=IsEventLogging();
6706 break;
6707 }
6708 if (LocaleCompare("define",option+1) == 0)
6709 {
6710 if (*option == '+')
6711 {
6712 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6713 (void) DeleteImageRegistry(argv[i+1]+9);
6714 else
6715 (void) DeleteImageOption(image_info,argv[i+1]);
6716 break;
6717 }
6718 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6719 {
6720 (void) DefineImageRegistry(StringRegistryType,argv[i+1]+9,
6721 exception);
6722 break;
6723 }
6724 (void) DefineImageOption(image_info,argv[i+1]);
6725 break;
6726 }
6727 if (LocaleCompare("delay",option+1) == 0)
6728 {
6729 if (*option == '+')
6730 {
6731 (void) SetImageOption(image_info,option+1,"0");
6732 break;
6733 }
6734 (void) SetImageOption(image_info,option+1,argv[i+1]);
6735 break;
6736 }
6737 if (LocaleCompare("density",option+1) == 0)
6738 {
6739 /*
6740 Set image density.
6741 */
6742 if (*option == '+')
6743 {
6744 if (image_info->density != (char *) NULL)
6745 image_info->density=DestroyString(image_info->density);
6746 (void) SetImageOption(image_info,option+1,"72");
6747 break;
6748 }
6749 (void) CloneString(&image_info->density,argv[i+1]);
6750 (void) SetImageOption(image_info,option+1,argv[i+1]);
6751 break;
6752 }
6753 if (LocaleCompare("depth",option+1) == 0)
6754 {
6755 if (*option == '+')
6756 {
6757 image_info->depth=MAGICKCORE_QUANTUM_DEPTH;
6758 break;
6759 }
cristye27293e2009-12-18 02:53:20 +00006760 image_info->depth=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006761 break;
6762 }
cristyc9b12952010-03-28 01:12:28 +00006763 if (LocaleCompare("direction",option+1) == 0)
6764 {
6765 if (*option == '+')
6766 {
6767 (void) SetImageOption(image_info,option+1,"undefined");
6768 break;
6769 }
6770 (void) SetImageOption(image_info,option+1,argv[i+1]);
6771 break;
6772 }
cristy3ed852e2009-09-05 21:47:34 +00006773 if (LocaleCompare("display",option+1) == 0)
6774 {
6775 if (*option == '+')
6776 {
6777 if (image_info->server_name != (char *) NULL)
6778 image_info->server_name=DestroyString(
6779 image_info->server_name);
6780 break;
6781 }
6782 (void) CloneString(&image_info->server_name,argv[i+1]);
6783 break;
6784 }
6785 if (LocaleCompare("dispose",option+1) == 0)
6786 {
6787 if (*option == '+')
6788 {
6789 (void) SetImageOption(image_info,option+1,"undefined");
6790 break;
6791 }
6792 (void) SetImageOption(image_info,option+1,argv[i+1]);
6793 break;
6794 }
6795 if (LocaleCompare("dither",option+1) == 0)
6796 {
6797 if (*option == '+')
6798 {
6799 image_info->dither=MagickFalse;
cristyd5acfd12010-06-15 00:11:38 +00006800 (void) SetImageOption(image_info,option+1,"none");
cristy3ed852e2009-09-05 21:47:34 +00006801 break;
6802 }
6803 (void) SetImageOption(image_info,option+1,argv[i+1]);
6804 image_info->dither=MagickTrue;
6805 break;
6806 }
6807 break;
6808 }
6809 case 'e':
6810 {
6811 if (LocaleCompare("encoding",option+1) == 0)
6812 {
6813 if (*option == '+')
6814 {
6815 (void) SetImageOption(image_info,option+1,"undefined");
6816 break;
6817 }
6818 (void) SetImageOption(image_info,option+1,argv[i+1]);
6819 break;
6820 }
6821 if (LocaleCompare("endian",option+1) == 0)
6822 {
6823 if (*option == '+')
6824 {
6825 image_info->endian=UndefinedEndian;
6826 (void) SetImageOption(image_info,option+1,"undefined");
6827 break;
6828 }
6829 image_info->endian=(EndianType) ParseMagickOption(
6830 MagickEndianOptions,MagickFalse,argv[i+1]);
6831 (void) SetImageOption(image_info,option+1,argv[i+1]);
6832 break;
6833 }
6834 if (LocaleCompare("extract",option+1) == 0)
6835 {
6836 /*
6837 Set image extract geometry.
6838 */
6839 if (*option == '+')
6840 {
6841 if (image_info->extract != (char *) NULL)
6842 image_info->extract=DestroyString(image_info->extract);
6843 break;
6844 }
6845 (void) CloneString(&image_info->extract,argv[i+1]);
6846 break;
6847 }
6848 break;
6849 }
6850 case 'f':
6851 {
6852 if (LocaleCompare("fill",option+1) == 0)
6853 {
6854 if (*option == '+')
6855 {
6856 (void) SetImageOption(image_info,option+1,"none");
6857 break;
6858 }
6859 (void) SetImageOption(image_info,option+1,argv[i+1]);
6860 break;
6861 }
6862 if (LocaleCompare("filter",option+1) == 0)
6863 {
6864 if (*option == '+')
6865 {
6866 (void) SetImageOption(image_info,option+1,"undefined");
6867 break;
6868 }
6869 (void) SetImageOption(image_info,option+1,argv[i+1]);
6870 break;
6871 }
6872 if (LocaleCompare("font",option+1) == 0)
6873 {
6874 if (*option == '+')
6875 {
6876 if (image_info->font != (char *) NULL)
6877 image_info->font=DestroyString(image_info->font);
6878 break;
6879 }
6880 (void) CloneString(&image_info->font,argv[i+1]);
6881 break;
6882 }
6883 if (LocaleCompare("format",option+1) == 0)
6884 {
6885 register const char
6886 *q;
6887
6888 for (q=strchr(argv[i+1],'%'); q != (char *) NULL; q=strchr(q+1,'%'))
cristy9ed85672011-03-02 00:19:13 +00006889 if (strchr("Agkrz@[#",*(q+1)) != (char *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00006890 image_info->ping=MagickFalse;
6891 (void) SetImageOption(image_info,option+1,argv[i+1]);
6892 break;
6893 }
6894 if (LocaleCompare("fuzz",option+1) == 0)
6895 {
6896 if (*option == '+')
6897 {
6898 image_info->fuzz=0.0;
6899 (void) SetImageOption(image_info,option+1,"0");
6900 break;
6901 }
cristyf2f27272009-12-17 14:48:46 +00006902 image_info->fuzz=SiPrefixToDouble(argv[i+1],(double) QuantumRange+
cristy3ed852e2009-09-05 21:47:34 +00006903 1.0);
6904 (void) SetImageOption(image_info,option+1,argv[i+1]);
6905 break;
6906 }
6907 break;
6908 }
6909 case 'g':
6910 {
6911 if (LocaleCompare("gravity",option+1) == 0)
6912 {
6913 if (*option == '+')
6914 {
6915 (void) SetImageOption(image_info,option+1,"undefined");
6916 break;
6917 }
6918 (void) SetImageOption(image_info,option+1,argv[i+1]);
6919 break;
6920 }
6921 if (LocaleCompare("green-primary",option+1) == 0)
6922 {
6923 if (*option == '+')
6924 {
6925 (void) SetImageOption(image_info,option+1,"0.0");
6926 break;
6927 }
6928 (void) SetImageOption(image_info,option+1,argv[i+1]);
6929 break;
6930 }
6931 break;
6932 }
6933 case 'i':
6934 {
6935 if (LocaleCompare("intent",option+1) == 0)
6936 {
6937 if (*option == '+')
6938 {
6939 (void) SetImageOption(image_info,option+1,"undefined");
6940 break;
6941 }
6942 (void) SetImageOption(image_info,option+1,argv[i+1]);
6943 break;
6944 }
6945 if (LocaleCompare("interlace",option+1) == 0)
6946 {
6947 if (*option == '+')
6948 {
6949 image_info->interlace=UndefinedInterlace;
6950 (void) SetImageOption(image_info,option+1,"undefined");
6951 break;
6952 }
6953 image_info->interlace=(InterlaceType) ParseMagickOption(
6954 MagickInterlaceOptions,MagickFalse,argv[i+1]);
6955 (void) SetImageOption(image_info,option+1,argv[i+1]);
6956 break;
6957 }
cristyb32b90a2009-09-07 21:45:48 +00006958 if (LocaleCompare("interline-spacing",option+1) == 0)
6959 {
6960 if (*option == '+')
6961 {
6962 (void) SetImageOption(image_info,option+1,"undefined");
6963 break;
6964 }
6965 (void) SetImageOption(image_info,option+1,argv[i+1]);
6966 break;
6967 }
cristy3ed852e2009-09-05 21:47:34 +00006968 if (LocaleCompare("interpolate",option+1) == 0)
6969 {
6970 if (*option == '+')
6971 {
6972 (void) SetImageOption(image_info,option+1,"undefined");
6973 break;
6974 }
6975 (void) SetImageOption(image_info,option+1,argv[i+1]);
6976 break;
6977 }
6978 if (LocaleCompare("interword-spacing",option+1) == 0)
6979 {
6980 if (*option == '+')
6981 {
6982 (void) SetImageOption(image_info,option+1,"undefined");
6983 break;
6984 }
6985 (void) SetImageOption(image_info,option+1,argv[i+1]);
6986 break;
6987 }
6988 break;
6989 }
6990 case 'k':
6991 {
6992 if (LocaleCompare("kerning",option+1) == 0)
6993 {
6994 if (*option == '+')
6995 {
6996 (void) SetImageOption(image_info,option+1,"undefined");
6997 break;
6998 }
6999 (void) SetImageOption(image_info,option+1,argv[i+1]);
7000 break;
7001 }
7002 break;
7003 }
7004 case 'l':
7005 {
7006 if (LocaleCompare("label",option+1) == 0)
7007 {
7008 if (*option == '+')
7009 {
7010 (void) DeleteImageOption(image_info,option+1);
7011 break;
7012 }
7013 (void) SetImageOption(image_info,option+1,argv[i+1]);
7014 break;
7015 }
7016 if (LocaleCompare("limit",option+1) == 0)
7017 {
7018 MagickSizeType
7019 limit;
7020
7021 ResourceType
7022 type;
7023
7024 if (*option == '+')
7025 break;
7026 type=(ResourceType) ParseMagickOption(MagickResourceOptions,
7027 MagickFalse,argv[i+1]);
7028 limit=MagickResourceInfinity;
7029 if (LocaleCompare("unlimited",argv[i+2]) != 0)
cristyf2f27272009-12-17 14:48:46 +00007030 limit=(MagickSizeType) SiPrefixToDouble(argv[i+2],100.0);
cristy3ed852e2009-09-05 21:47:34 +00007031 (void) SetMagickResourceLimit(type,limit);
7032 break;
7033 }
7034 if (LocaleCompare("list",option+1) == 0)
7035 {
cristybb503372010-05-27 20:51:26 +00007036 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00007037 list;
7038
7039 /*
7040 Display configuration list.
7041 */
7042 list=ParseMagickOption(MagickListOptions,MagickFalse,argv[i+1]);
7043 switch (list)
7044 {
7045 case MagickCoderOptions:
7046 {
7047 (void) ListCoderInfo((FILE *) NULL,exception);
7048 break;
7049 }
7050 case MagickColorOptions:
7051 {
7052 (void) ListColorInfo((FILE *) NULL,exception);
7053 break;
7054 }
7055 case MagickConfigureOptions:
7056 {
7057 (void) ListConfigureInfo((FILE *) NULL,exception);
7058 break;
7059 }
7060 case MagickDelegateOptions:
7061 {
7062 (void) ListDelegateInfo((FILE *) NULL,exception);
7063 break;
7064 }
7065 case MagickFontOptions:
7066 {
7067 (void) ListTypeInfo((FILE *) NULL,exception);
7068 break;
7069 }
7070 case MagickFormatOptions:
7071 {
7072 (void) ListMagickInfo((FILE *) NULL,exception);
7073 break;
7074 }
7075 case MagickLocaleOptions:
7076 {
7077 (void) ListLocaleInfo((FILE *) NULL,exception);
7078 break;
7079 }
7080 case MagickLogOptions:
7081 {
7082 (void) ListLogInfo((FILE *) NULL,exception);
7083 break;
7084 }
7085 case MagickMagicOptions:
7086 {
7087 (void) ListMagicInfo((FILE *) NULL,exception);
7088 break;
7089 }
7090 case MagickMimeOptions:
7091 {
7092 (void) ListMimeInfo((FILE *) NULL,exception);
7093 break;
7094 }
7095 case MagickModuleOptions:
7096 {
7097 (void) ListModuleInfo((FILE *) NULL,exception);
7098 break;
7099 }
7100 case MagickPolicyOptions:
7101 {
7102 (void) ListPolicyInfo((FILE *) NULL,exception);
7103 break;
7104 }
7105 case MagickResourceOptions:
7106 {
7107 (void) ListMagickResourceInfo((FILE *) NULL,exception);
7108 break;
7109 }
7110 case MagickThresholdOptions:
7111 {
7112 (void) ListThresholdMaps((FILE *) NULL,exception);
7113 break;
7114 }
7115 default:
7116 {
7117 (void) ListMagickOptions((FILE *) NULL,(MagickOption) list,
7118 exception);
7119 break;
7120 }
7121 }
cristyaeb2cbc2010-05-07 13:28:58 +00007122 break;
cristy3ed852e2009-09-05 21:47:34 +00007123 }
7124 if (LocaleCompare("log",option+1) == 0)
7125 {
7126 if (*option == '+')
7127 break;
7128 (void) SetLogFormat(argv[i+1]);
7129 break;
7130 }
7131 if (LocaleCompare("loop",option+1) == 0)
7132 {
7133 if (*option == '+')
7134 {
7135 (void) SetImageOption(image_info,option+1,"0");
7136 break;
7137 }
7138 (void) SetImageOption(image_info,option+1,argv[i+1]);
7139 break;
7140 }
7141 break;
7142 }
7143 case 'm':
7144 {
7145 if (LocaleCompare("matte",option+1) == 0)
7146 {
7147 if (*option == '+')
7148 {
7149 (void) SetImageOption(image_info,option+1,"false");
7150 break;
7151 }
7152 (void) SetImageOption(image_info,option+1,"true");
7153 break;
7154 }
7155 if (LocaleCompare("mattecolor",option+1) == 0)
7156 {
7157 if (*option == '+')
7158 {
7159 (void) SetImageOption(image_info,option+1,argv[i+1]);
7160 (void) QueryColorDatabase(MatteColor,&image_info->matte_color,
7161 exception);
7162 break;
7163 }
7164 (void) SetImageOption(image_info,option+1,argv[i+1]);
7165 (void) QueryColorDatabase(argv[i+1],&image_info->matte_color,
7166 exception);
7167 break;
7168 }
7169 if (LocaleCompare("monitor",option+1) == 0)
7170 {
7171 (void) SetImageInfoProgressMonitor(image_info,MonitorProgress,
7172 (void *) NULL);
7173 break;
7174 }
7175 if (LocaleCompare("monochrome",option+1) == 0)
7176 {
7177 image_info->monochrome=(*option == '-') ? MagickTrue : MagickFalse;
7178 break;
7179 }
7180 break;
7181 }
7182 case 'o':
7183 {
7184 if (LocaleCompare("orient",option+1) == 0)
7185 {
7186 if (*option == '+')
7187 {
7188 image_info->orientation=UndefinedOrientation;
7189 (void) SetImageOption(image_info,option+1,"undefined");
7190 break;
7191 }
7192 image_info->orientation=(OrientationType) ParseMagickOption(
7193 MagickOrientationOptions,MagickFalse,argv[i+1]);
cristyc6e214d2010-08-08 00:31:08 +00007194 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007195 break;
7196 }
7197 }
7198 case 'p':
7199 {
7200 if (LocaleCompare("page",option+1) == 0)
7201 {
7202 char
7203 *canonical_page,
7204 page[MaxTextExtent];
7205
7206 const char
7207 *image_option;
7208
7209 MagickStatusType
7210 flags;
7211
7212 RectangleInfo
7213 geometry;
7214
7215 if (*option == '+')
7216 {
7217 (void) DeleteImageOption(image_info,option+1);
7218 (void) CloneString(&image_info->page,(char *) NULL);
7219 break;
7220 }
7221 (void) ResetMagickMemory(&geometry,0,sizeof(geometry));
7222 image_option=GetImageOption(image_info,"page");
7223 if (image_option != (const char *) NULL)
7224 flags=ParseAbsoluteGeometry(image_option,&geometry);
7225 canonical_page=GetPageGeometry(argv[i+1]);
7226 flags=ParseAbsoluteGeometry(canonical_page,&geometry);
7227 canonical_page=DestroyString(canonical_page);
7228 (void) FormatMagickString(page,MaxTextExtent,"%lux%lu",
cristyf2faecf2010-05-28 19:19:36 +00007229 (unsigned long) geometry.width,(unsigned long) geometry.height);
cristy3ed852e2009-09-05 21:47:34 +00007230 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
7231 (void) FormatMagickString(page,MaxTextExtent,"%lux%lu%+ld%+ld",
cristyf2faecf2010-05-28 19:19:36 +00007232 (unsigned long) geometry.width,(unsigned long) geometry.height,
7233 (long) geometry.x,(long) geometry.y);
cristy3ed852e2009-09-05 21:47:34 +00007234 (void) SetImageOption(image_info,option+1,page);
7235 (void) CloneString(&image_info->page,page);
7236 break;
7237 }
7238 if (LocaleCompare("pen",option+1) == 0)
7239 {
7240 if (*option == '+')
7241 {
7242 (void) SetImageOption(image_info,option+1,"none");
7243 break;
7244 }
7245 (void) SetImageOption(image_info,option+1,argv[i+1]);
7246 break;
7247 }
7248 if (LocaleCompare("ping",option+1) == 0)
7249 {
7250 image_info->ping=(*option == '-') ? MagickTrue : MagickFalse;
7251 break;
7252 }
7253 if (LocaleCompare("pointsize",option+1) == 0)
7254 {
7255 if (*option == '+')
7256 geometry_info.rho=0.0;
7257 else
7258 (void) ParseGeometry(argv[i+1],&geometry_info);
7259 image_info->pointsize=geometry_info.rho;
7260 break;
7261 }
cristye7f51092010-01-17 00:39:37 +00007262 if (LocaleCompare("precision",option+1) == 0)
7263 {
cristybf2766a2010-01-17 03:33:23 +00007264 (void) SetMagickPrecision(StringToInteger(argv[i+1]));
cristye7f51092010-01-17 00:39:37 +00007265 break;
7266 }
cristy3ed852e2009-09-05 21:47:34 +00007267 if (LocaleCompare("preview",option+1) == 0)
7268 {
7269 /*
7270 Preview image.
7271 */
7272 if (*option == '+')
7273 {
7274 image_info->preview_type=UndefinedPreview;
7275 break;
7276 }
7277 image_info->preview_type=(PreviewType) ParseMagickOption(
7278 MagickPreviewOptions,MagickFalse,argv[i+1]);
7279 break;
7280 }
7281 break;
7282 }
7283 case 'q':
7284 {
7285 if (LocaleCompare("quality",option+1) == 0)
7286 {
7287 /*
7288 Set image compression quality.
7289 */
7290 if (*option == '+')
7291 {
7292 image_info->quality=UndefinedCompressionQuality;
7293 (void) SetImageOption(image_info,option+1,"0");
7294 break;
7295 }
cristye27293e2009-12-18 02:53:20 +00007296 image_info->quality=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007297 (void) SetImageOption(image_info,option+1,argv[i+1]);
7298 break;
7299 }
7300 if (LocaleCompare("quiet",option+1) == 0)
7301 {
7302 static WarningHandler
7303 warning_handler = (WarningHandler) NULL;
7304
7305 if (*option == '+')
7306 {
7307 /*
7308 Restore error or warning messages.
7309 */
7310 warning_handler=SetWarningHandler(warning_handler);
7311 break;
7312 }
7313 /*
7314 Suppress error or warning messages.
7315 */
7316 warning_handler=SetWarningHandler((WarningHandler) NULL);
7317 break;
7318 }
7319 break;
7320 }
7321 case 'r':
7322 {
7323 if (LocaleCompare("red-primary",option+1) == 0)
7324 {
7325 if (*option == '+')
7326 {
7327 (void) SetImageOption(image_info,option+1,"0.0");
7328 break;
7329 }
7330 (void) SetImageOption(image_info,option+1,argv[i+1]);
7331 break;
7332 }
7333 break;
7334 }
7335 case 's':
7336 {
7337 if (LocaleCompare("sampling-factor",option+1) == 0)
7338 {
7339 /*
7340 Set image sampling factor.
7341 */
7342 if (*option == '+')
7343 {
7344 if (image_info->sampling_factor != (char *) NULL)
7345 image_info->sampling_factor=DestroyString(
7346 image_info->sampling_factor);
7347 break;
7348 }
7349 (void) CloneString(&image_info->sampling_factor,argv[i+1]);
7350 break;
7351 }
7352 if (LocaleCompare("scene",option+1) == 0)
7353 {
7354 /*
7355 Set image scene.
7356 */
7357 if (*option == '+')
7358 {
7359 image_info->scene=0;
7360 (void) SetImageOption(image_info,option+1,"0");
7361 break;
7362 }
cristye27293e2009-12-18 02:53:20 +00007363 image_info->scene=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007364 (void) SetImageOption(image_info,option+1,argv[i+1]);
7365 break;
7366 }
7367 if (LocaleCompare("seed",option+1) == 0)
7368 {
cristybb503372010-05-27 20:51:26 +00007369 size_t
cristy3ed852e2009-09-05 21:47:34 +00007370 seed;
7371
7372 if (*option == '+')
7373 {
cristybb503372010-05-27 20:51:26 +00007374 seed=(size_t) time((time_t *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00007375 SeedPseudoRandomGenerator(seed);
7376 break;
7377 }
cristye27293e2009-12-18 02:53:20 +00007378 seed=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007379 SeedPseudoRandomGenerator(seed);
7380 break;
7381 }
7382 if (LocaleCompare("size",option+1) == 0)
7383 {
7384 if (*option == '+')
7385 {
7386 if (image_info->size != (char *) NULL)
7387 image_info->size=DestroyString(image_info->size);
7388 break;
7389 }
7390 (void) CloneString(&image_info->size,argv[i+1]);
7391 break;
7392 }
7393 if (LocaleCompare("stroke",option+1) == 0)
7394 {
7395 if (*option == '+')
7396 {
7397 (void) SetImageOption(image_info,option+1,"none");
7398 break;
7399 }
7400 (void) SetImageOption(image_info,option+1,argv[i+1]);
7401 break;
7402 }
7403 if (LocaleCompare("strokewidth",option+1) == 0)
7404 {
7405 if (*option == '+')
7406 {
7407 (void) SetImageOption(image_info,option+1,"0");
7408 break;
7409 }
7410 (void) SetImageOption(image_info,option+1,argv[i+1]);
7411 break;
7412 }
cristyd9a29192010-10-16 16:49:53 +00007413 if (LocaleCompare("synchronize",option+1) == 0)
7414 {
7415 if (*option == '+')
7416 {
7417 image_info->synchronize=MagickFalse;
7418 break;
7419 }
7420 image_info->synchronize=MagickTrue;
7421 break;
7422 }
cristy3ed852e2009-09-05 21:47:34 +00007423 break;
7424 }
7425 case 't':
7426 {
7427 if (LocaleCompare("taint",option+1) == 0)
7428 {
7429 if (*option == '+')
7430 {
7431 (void) SetImageOption(image_info,option+1,"false");
7432 break;
7433 }
7434 (void) SetImageOption(image_info,option+1,"true");
7435 break;
7436 }
7437 if (LocaleCompare("texture",option+1) == 0)
7438 {
7439 if (*option == '+')
7440 {
7441 if (image_info->texture != (char *) NULL)
7442 image_info->texture=DestroyString(image_info->texture);
7443 break;
7444 }
7445 (void) CloneString(&image_info->texture,argv[i+1]);
7446 break;
7447 }
7448 if (LocaleCompare("tile-offset",option+1) == 0)
7449 {
7450 if (*option == '+')
7451 {
7452 (void) SetImageOption(image_info,option+1,"0");
7453 break;
7454 }
7455 (void) SetImageOption(image_info,option+1,argv[i+1]);
7456 break;
7457 }
7458 if (LocaleCompare("transparent-color",option+1) == 0)
7459 {
7460 if (*option == '+')
7461 {
7462 (void) QueryColorDatabase("none",&image_info->transparent_color, exception);
7463 (void) SetImageOption(image_info,option+1,"none");
7464 break;
7465 }
7466 (void) QueryColorDatabase(argv[i+1],&image_info->transparent_color,
7467 exception);
7468 (void) SetImageOption(image_info,option+1,argv[i+1]);
7469 break;
7470 }
7471 if (LocaleCompare("type",option+1) == 0)
7472 {
7473 if (*option == '+')
7474 {
cristy5f1c1ff2010-12-23 21:38:06 +00007475 image_info->type=UndefinedType;
cristy3ed852e2009-09-05 21:47:34 +00007476 (void) SetImageOption(image_info,option+1,"undefined");
7477 break;
7478 }
7479 image_info->type=(ImageType) ParseMagickOption(MagickTypeOptions,
7480 MagickFalse,argv[i+1]);
7481 (void) SetImageOption(image_info,option+1,argv[i+1]);
7482 break;
7483 }
7484 break;
7485 }
7486 case 'u':
7487 {
7488 if (LocaleCompare("undercolor",option+1) == 0)
7489 {
7490 if (*option == '+')
7491 {
7492 (void) DeleteImageOption(image_info,option+1);
7493 break;
7494 }
7495 (void) SetImageOption(image_info,option+1,argv[i+1]);
7496 break;
7497 }
7498 if (LocaleCompare("units",option+1) == 0)
7499 {
7500 if (*option == '+')
7501 {
7502 image_info->units=UndefinedResolution;
7503 (void) SetImageOption(image_info,option+1,"undefined");
7504 break;
7505 }
7506 image_info->units=(ResolutionType) ParseMagickOption(
7507 MagickResolutionOptions,MagickFalse,argv[i+1]);
7508 (void) SetImageOption(image_info,option+1,argv[i+1]);
7509 break;
7510 }
7511 break;
7512 }
7513 case 'v':
7514 {
7515 if (LocaleCompare("verbose",option+1) == 0)
7516 {
7517 if (*option == '+')
7518 {
7519 image_info->verbose=MagickFalse;
7520 break;
7521 }
7522 image_info->verbose=MagickTrue;
7523 image_info->ping=MagickFalse;
7524 break;
7525 }
7526 if (LocaleCompare("view",option+1) == 0)
7527 {
7528 if (*option == '+')
7529 {
7530 if (image_info->view != (char *) NULL)
7531 image_info->view=DestroyString(image_info->view);
7532 break;
7533 }
7534 (void) CloneString(&image_info->view,argv[i+1]);
7535 break;
7536 }
7537 if (LocaleCompare("virtual-pixel",option+1) == 0)
7538 {
7539 if (*option == '+')
7540 {
7541 image_info->virtual_pixel_method=UndefinedVirtualPixelMethod;
7542 (void) SetImageOption(image_info,option+1,"undefined");
7543 break;
7544 }
7545 image_info->virtual_pixel_method=(VirtualPixelMethod)
7546 ParseMagickOption(MagickVirtualPixelOptions,MagickFalse,
7547 argv[i+1]);
7548 (void) SetImageOption(image_info,option+1,argv[i+1]);
7549 break;
7550 }
7551 break;
7552 }
7553 case 'w':
7554 {
7555 if (LocaleCompare("white-point",option+1) == 0)
7556 {
7557 if (*option == '+')
7558 {
7559 (void) SetImageOption(image_info,option+1,"0.0");
7560 break;
7561 }
7562 (void) SetImageOption(image_info,option+1,argv[i+1]);
7563 break;
7564 }
7565 break;
7566 }
7567 default:
7568 break;
7569 }
7570 i+=count;
7571 }
7572 return(MagickTrue);
7573}
7574
7575/*
7576%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7577% %
7578% %
7579% %
7580+ M o g r i f y I m a g e L i s t %
7581% %
7582% %
7583% %
7584%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7585%
7586% MogrifyImageList() applies any command line options that might affect the
7587% entire image list (e.g. -append, -coalesce, etc.).
7588%
7589% The format of the MogrifyImage method is:
7590%
7591% MagickBooleanType MogrifyImageList(ImageInfo *image_info,const int argc,
7592% const char **argv,Image **images,ExceptionInfo *exception)
7593%
7594% A description of each parameter follows:
7595%
7596% o image_info: the image info..
7597%
7598% o argc: Specifies a pointer to an integer describing the number of
7599% elements in the argument vector.
7600%
7601% o argv: Specifies a pointer to a text array containing the command line
7602% arguments.
7603%
7604% o images: the images.
7605%
7606% o exception: return any errors or warnings in this structure.
7607%
7608*/
7609WandExport MagickBooleanType MogrifyImageList(ImageInfo *image_info,
7610 const int argc,const char **argv,Image **images,ExceptionInfo *exception)
7611{
7612 ChannelType
7613 channel;
7614
7615 const char
7616 *option;
7617
cristy6b3da3a2010-06-20 02:21:46 +00007618 ImageInfo
7619 *mogrify_info;
cristy3ed852e2009-09-05 21:47:34 +00007620
7621 MagickStatusType
7622 status;
7623
7624 QuantizeInfo
7625 *quantize_info;
7626
cristybb503372010-05-27 20:51:26 +00007627 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00007628 i;
7629
cristy6b3da3a2010-06-20 02:21:46 +00007630 ssize_t
7631 count,
7632 index;
7633
cristy3ed852e2009-09-05 21:47:34 +00007634 /*
7635 Apply options to the image list.
7636 */
7637 assert(image_info != (ImageInfo *) NULL);
7638 assert(image_info->signature == MagickSignature);
7639 assert(images != (Image **) NULL);
7640 assert((*images)->signature == MagickSignature);
7641 if ((*images)->debug != MagickFalse)
7642 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
7643 (*images)->filename);
7644 if ((argc <= 0) || (*argv == (char *) NULL))
7645 return(MagickTrue);
cristy6b3da3a2010-06-20 02:21:46 +00007646 mogrify_info=CloneImageInfo(image_info);
7647 quantize_info=AcquireQuantizeInfo(mogrify_info);
7648 channel=mogrify_info->channel;
cristy3ed852e2009-09-05 21:47:34 +00007649 status=MagickTrue;
cristybb503372010-05-27 20:51:26 +00007650 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00007651 {
cristy74fe8f12009-10-03 19:09:01 +00007652 if (*images == (Image *) NULL)
7653 break;
cristy3ed852e2009-09-05 21:47:34 +00007654 option=argv[i];
7655 if (IsMagickOption(option) == MagickFalse)
7656 continue;
7657 count=MagickMax(ParseMagickOption(MagickCommandOptions,MagickFalse,option),
7658 0L);
cristycee97112010-05-28 00:44:52 +00007659 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00007660 break;
cristy6b3da3a2010-06-20 02:21:46 +00007661 status=MogrifyImageInfo(mogrify_info,(int) count+1,argv+i,exception);
cristy3ed852e2009-09-05 21:47:34 +00007662 switch (*(option+1))
7663 {
7664 case 'a':
7665 {
7666 if (LocaleCompare("affinity",option+1) == 0)
7667 {
cristy6b3da3a2010-06-20 02:21:46 +00007668 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007669 if (*option == '+')
7670 {
7671 (void) RemapImages(quantize_info,*images,(Image *) NULL);
7672 InheritException(exception,&(*images)->exception);
7673 break;
7674 }
7675 i++;
7676 break;
7677 }
7678 if (LocaleCompare("append",option+1) == 0)
7679 {
7680 Image
7681 *append_image;
7682
cristy6b3da3a2010-06-20 02:21:46 +00007683 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007684 append_image=AppendImages(*images,*option == '-' ? MagickTrue :
7685 MagickFalse,exception);
7686 if (append_image == (Image *) NULL)
7687 {
7688 status=MagickFalse;
7689 break;
7690 }
7691 *images=DestroyImageList(*images);
7692 *images=append_image;
7693 break;
7694 }
7695 if (LocaleCompare("average",option+1) == 0)
7696 {
7697 Image
7698 *average_image;
7699
cristyd18ae7c2010-03-07 17:39:52 +00007700 /*
7701 Average an image sequence (deprecated).
7702 */
cristy6b3da3a2010-06-20 02:21:46 +00007703 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007704 average_image=EvaluateImages(*images,MeanEvaluateOperator,
7705 exception);
cristy3ed852e2009-09-05 21:47:34 +00007706 if (average_image == (Image *) NULL)
7707 {
7708 status=MagickFalse;
7709 break;
7710 }
7711 *images=DestroyImageList(*images);
7712 *images=average_image;
7713 break;
7714 }
7715 break;
7716 }
7717 case 'c':
7718 {
7719 if (LocaleCompare("channel",option+1) == 0)
7720 {
7721 if (*option == '+')
7722 {
7723 channel=DefaultChannels;
7724 break;
7725 }
7726 channel=(ChannelType) ParseChannelOption(argv[i+1]);
7727 break;
7728 }
7729 if (LocaleCompare("clut",option+1) == 0)
7730 {
7731 Image
7732 *clut_image,
7733 *image;
7734
cristy6b3da3a2010-06-20 02:21:46 +00007735 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007736 image=RemoveFirstImageFromList(images);
7737 clut_image=RemoveFirstImageFromList(images);
7738 if (clut_image == (Image *) NULL)
7739 {
7740 status=MagickFalse;
7741 break;
7742 }
7743 (void) ClutImageChannel(image,channel,clut_image);
7744 clut_image=DestroyImage(clut_image);
7745 InheritException(exception,&image->exception);
7746 *images=DestroyImageList(*images);
7747 *images=image;
7748 break;
7749 }
7750 if (LocaleCompare("coalesce",option+1) == 0)
7751 {
7752 Image
7753 *coalesce_image;
7754
cristy6b3da3a2010-06-20 02:21:46 +00007755 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007756 coalesce_image=CoalesceImages(*images,exception);
7757 if (coalesce_image == (Image *) NULL)
7758 {
7759 status=MagickFalse;
7760 break;
7761 }
7762 *images=DestroyImageList(*images);
7763 *images=coalesce_image;
7764 break;
7765 }
7766 if (LocaleCompare("combine",option+1) == 0)
7767 {
7768 Image
7769 *combine_image;
7770
cristy6b3da3a2010-06-20 02:21:46 +00007771 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007772 combine_image=CombineImages(*images,channel,exception);
7773 if (combine_image == (Image *) NULL)
7774 {
7775 status=MagickFalse;
7776 break;
7777 }
7778 *images=DestroyImageList(*images);
7779 *images=combine_image;
7780 break;
7781 }
7782 if (LocaleCompare("composite",option+1) == 0)
7783 {
7784 Image
7785 *mask_image,
7786 *composite_image,
7787 *image;
7788
7789 RectangleInfo
7790 geometry;
7791
cristy6b3da3a2010-06-20 02:21:46 +00007792 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007793 image=RemoveFirstImageFromList(images);
7794 composite_image=RemoveFirstImageFromList(images);
7795 if (composite_image == (Image *) NULL)
7796 {
7797 status=MagickFalse;
7798 break;
7799 }
7800 (void) TransformImage(&composite_image,(char *) NULL,
7801 composite_image->geometry);
7802 SetGeometry(composite_image,&geometry);
7803 (void) ParseAbsoluteGeometry(composite_image->geometry,&geometry);
7804 GravityAdjustGeometry(image->columns,image->rows,image->gravity,
7805 &geometry);
7806 mask_image=RemoveFirstImageFromList(images);
7807 if (mask_image != (Image *) NULL)
7808 {
7809 if ((image->compose == DisplaceCompositeOp) ||
7810 (image->compose == DistortCompositeOp))
7811 {
7812 /*
7813 Merge Y displacement into X displacement image.
7814 */
7815 (void) CompositeImage(composite_image,CopyGreenCompositeOp,
7816 mask_image,0,0);
7817 mask_image=DestroyImage(mask_image);
7818 }
7819 else
7820 {
7821 /*
7822 Set a blending mask for the composition.
7823 */
7824 image->mask=mask_image;
7825 (void) NegateImage(image->mask,MagickFalse);
7826 }
7827 }
7828 (void) CompositeImageChannel(image,channel,image->compose,
7829 composite_image,geometry.x,geometry.y);
7830 if (image->mask != (Image *) NULL)
7831 image->mask=DestroyImage(image->mask);
7832 composite_image=DestroyImage(composite_image);
7833 InheritException(exception,&image->exception);
7834 *images=DestroyImageList(*images);
7835 *images=image;
7836 break;
7837 }
7838 if (LocaleCompare("crop",option+1) == 0)
7839 {
7840 MagickStatusType
7841 flags;
7842
7843 RectangleInfo
7844 geometry;
7845
cristy6b3da3a2010-06-20 02:21:46 +00007846 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007847 flags=ParseGravityGeometry(*images,argv[i+1],&geometry,exception);
7848 if (((geometry.width == 0) && (geometry.height == 0)) ||
7849 ((flags & XValue) != 0) || ((flags & YValue) != 0))
7850 break;
7851 (void) TransformImages(images,argv[i+1],(char *) NULL);
7852 InheritException(exception,&(*images)->exception);
7853 break;
7854 }
7855 break;
7856 }
7857 case 'd':
7858 {
7859 if (LocaleCompare("deconstruct",option+1) == 0)
7860 {
7861 Image
7862 *deconstruct_image;
7863
cristy6b3da3a2010-06-20 02:21:46 +00007864 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007865 deconstruct_image=DeconstructImages(*images,exception);
7866 if (deconstruct_image == (Image *) NULL)
7867 {
7868 status=MagickFalse;
7869 break;
7870 }
7871 *images=DestroyImageList(*images);
7872 *images=deconstruct_image;
7873 break;
7874 }
7875 if (LocaleCompare("delete",option+1) == 0)
7876 {
7877 if (*option == '+')
7878 DeleteImages(images,"-1",exception);
7879 else
7880 DeleteImages(images,argv[i+1],exception);
7881 break;
7882 }
7883 if (LocaleCompare("dither",option+1) == 0)
7884 {
7885 if (*option == '+')
7886 {
7887 quantize_info->dither=MagickFalse;
7888 break;
7889 }
7890 quantize_info->dither=MagickTrue;
7891 quantize_info->dither_method=(DitherMethod) ParseMagickOption(
7892 MagickDitherOptions,MagickFalse,argv[i+1]);
7893 break;
7894 }
7895 break;
7896 }
cristyd18ae7c2010-03-07 17:39:52 +00007897 case 'e':
7898 {
7899 if (LocaleCompare("evaluate-sequence",option+1) == 0)
7900 {
7901 Image
7902 *evaluate_image;
7903
7904 MagickEvaluateOperator
7905 op;
7906
cristy6b3da3a2010-06-20 02:21:46 +00007907 (void) SyncImageSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007908 op=(MagickEvaluateOperator) ParseMagickOption(MagickEvaluateOptions,
7909 MagickFalse,argv[i+1]);
7910 evaluate_image=EvaluateImages(*images,op,exception);
7911 if (evaluate_image == (Image *) NULL)
7912 {
7913 status=MagickFalse;
7914 break;
7915 }
7916 *images=DestroyImageList(*images);
7917 *images=evaluate_image;
7918 break;
7919 }
7920 break;
7921 }
cristy3ed852e2009-09-05 21:47:34 +00007922 case 'f':
7923 {
cristyf0a247f2009-10-04 00:20:03 +00007924 if (LocaleCompare("fft",option+1) == 0)
7925 {
7926 Image
7927 *fourier_image;
7928
7929 /*
7930 Implements the discrete Fourier transform (DFT).
7931 */
cristy6b3da3a2010-06-20 02:21:46 +00007932 (void) SyncImageSettings(mogrify_info,*images);
cristyf0a247f2009-10-04 00:20:03 +00007933 fourier_image=ForwardFourierTransformImage(*images,*option == '-' ?
7934 MagickTrue : MagickFalse,exception);
7935 if (fourier_image == (Image *) NULL)
7936 break;
7937 *images=DestroyImage(*images);
7938 *images=fourier_image;
7939 break;
7940 }
cristy3ed852e2009-09-05 21:47:34 +00007941 if (LocaleCompare("flatten",option+1) == 0)
7942 {
7943 Image
7944 *flatten_image;
7945
cristy6b3da3a2010-06-20 02:21:46 +00007946 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007947 flatten_image=MergeImageLayers(*images,FlattenLayer,exception);
7948 if (flatten_image == (Image *) NULL)
7949 break;
7950 *images=DestroyImageList(*images);
7951 *images=flatten_image;
7952 break;
7953 }
7954 if (LocaleCompare("fx",option+1) == 0)
7955 {
7956 Image
7957 *fx_image;
7958
cristy6b3da3a2010-06-20 02:21:46 +00007959 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007960 fx_image=FxImageChannel(*images,channel,argv[i+1],exception);
7961 if (fx_image == (Image *) NULL)
7962 {
7963 status=MagickFalse;
7964 break;
7965 }
7966 *images=DestroyImageList(*images);
7967 *images=fx_image;
7968 break;
7969 }
7970 break;
7971 }
7972 case 'h':
7973 {
7974 if (LocaleCompare("hald-clut",option+1) == 0)
7975 {
7976 Image
7977 *hald_image,
7978 *image;
7979
cristy6b3da3a2010-06-20 02:21:46 +00007980 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007981 image=RemoveFirstImageFromList(images);
7982 hald_image=RemoveFirstImageFromList(images);
7983 if (hald_image == (Image *) NULL)
7984 {
7985 status=MagickFalse;
7986 break;
7987 }
7988 (void) HaldClutImageChannel(image,channel,hald_image);
7989 hald_image=DestroyImage(hald_image);
7990 InheritException(exception,&image->exception);
cristy0aff6ea2009-11-14 01:40:53 +00007991 if (*images != (Image *) NULL)
7992 *images=DestroyImageList(*images);
cristy3ed852e2009-09-05 21:47:34 +00007993 *images=image;
7994 break;
7995 }
7996 break;
7997 }
7998 case 'i':
7999 {
8000 if (LocaleCompare("ift",option+1) == 0)
8001 {
8002 Image
cristy8587f882009-11-13 20:28:49 +00008003 *fourier_image,
8004 *magnitude_image,
8005 *phase_image;
cristy3ed852e2009-09-05 21:47:34 +00008006
8007 /*
8008 Implements the inverse fourier discrete Fourier transform (DFT).
8009 */
cristy6b3da3a2010-06-20 02:21:46 +00008010 (void) SyncImagesSettings(mogrify_info,*images);
cristy8587f882009-11-13 20:28:49 +00008011 magnitude_image=RemoveFirstImageFromList(images);
8012 phase_image=RemoveFirstImageFromList(images);
8013 if (phase_image == (Image *) NULL)
8014 {
8015 status=MagickFalse;
8016 break;
8017 }
8018 fourier_image=InverseFourierTransformImage(magnitude_image,
8019 phase_image,*option == '-' ? MagickTrue : MagickFalse,exception);
cristy3ed852e2009-09-05 21:47:34 +00008020 if (fourier_image == (Image *) NULL)
8021 break;
cristy0aff6ea2009-11-14 01:40:53 +00008022 if (*images != (Image *) NULL)
8023 *images=DestroyImage(*images);
cristy3ed852e2009-09-05 21:47:34 +00008024 *images=fourier_image;
8025 break;
8026 }
8027 if (LocaleCompare("insert",option+1) == 0)
8028 {
8029 Image
8030 *p,
8031 *q;
8032
8033 index=0;
8034 if (*option != '+')
cristy32c2aea2010-12-01 01:00:50 +00008035 index=(ssize_t) StringToLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00008036 p=RemoveLastImageFromList(images);
8037 if (p == (Image *) NULL)
8038 {
8039 (void) ThrowMagickException(exception,GetMagickModule(),
8040 OptionError,"NoSuchImage","`%s'",argv[i+1]);
8041 status=MagickFalse;
8042 break;
8043 }
8044 q=p;
8045 if (index == 0)
8046 PrependImageToList(images,q);
8047 else
cristybb503372010-05-27 20:51:26 +00008048 if (index == (ssize_t) GetImageListLength(*images))
cristy3ed852e2009-09-05 21:47:34 +00008049 AppendImageToList(images,q);
8050 else
8051 {
8052 q=GetImageFromList(*images,index-1);
8053 if (q == (Image *) NULL)
8054 {
8055 (void) ThrowMagickException(exception,GetMagickModule(),
8056 OptionError,"NoSuchImage","`%s'",argv[i+1]);
8057 status=MagickFalse;
8058 break;
8059 }
8060 InsertImageInList(&q,p);
8061 }
8062 *images=GetFirstImageInList(q);
8063 break;
8064 }
8065 break;
8066 }
8067 case 'l':
8068 {
8069 if (LocaleCompare("layers",option+1) == 0)
8070 {
8071 Image
8072 *layers;
8073
8074 ImageLayerMethod
8075 method;
8076
cristy6b3da3a2010-06-20 02:21:46 +00008077 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00008078 layers=(Image *) NULL;
8079 method=(ImageLayerMethod) ParseMagickOption(MagickLayerOptions,
8080 MagickFalse,argv[i+1]);
8081 switch (method)
8082 {
8083 case CoalesceLayer:
8084 {
8085 layers=CoalesceImages(*images,exception);
8086 break;
8087 }
8088 case CompareAnyLayer:
8089 case CompareClearLayer:
8090 case CompareOverlayLayer:
8091 default:
8092 {
8093 layers=CompareImageLayers(*images,method,exception);
8094 break;
8095 }
8096 case MergeLayer:
8097 case FlattenLayer:
8098 case MosaicLayer:
8099 case TrimBoundsLayer:
8100 {
8101 layers=MergeImageLayers(*images,method,exception);
8102 break;
8103 }
8104 case DisposeLayer:
8105 {
8106 layers=DisposeImages(*images,exception);
8107 break;
8108 }
8109 case OptimizeImageLayer:
8110 {
8111 layers=OptimizeImageLayers(*images,exception);
8112 break;
8113 }
8114 case OptimizePlusLayer:
8115 {
8116 layers=OptimizePlusImageLayers(*images,exception);
8117 break;
8118 }
8119 case OptimizeTransLayer:
8120 {
8121 OptimizeImageTransparency(*images,exception);
8122 break;
8123 }
8124 case RemoveDupsLayer:
8125 {
8126 RemoveDuplicateLayers(images,exception);
8127 break;
8128 }
8129 case RemoveZeroLayer:
8130 {
8131 RemoveZeroDelayLayers(images,exception);
8132 break;
8133 }
8134 case OptimizeLayer:
8135 {
8136 /*
8137 General Purpose, GIF Animation Optimizer.
8138 */
8139 layers=CoalesceImages(*images,exception);
8140 if (layers == (Image *) NULL)
8141 {
8142 status=MagickFalse;
8143 break;
8144 }
8145 InheritException(exception,&layers->exception);
8146 *images=DestroyImageList(*images);
8147 *images=layers;
8148 layers=OptimizeImageLayers(*images,exception);
8149 if (layers == (Image *) NULL)
8150 {
8151 status=MagickFalse;
8152 break;
8153 }
8154 InheritException(exception,&layers->exception);
8155 *images=DestroyImageList(*images);
8156 *images=layers;
8157 layers=(Image *) NULL;
8158 OptimizeImageTransparency(*images,exception);
8159 InheritException(exception,&(*images)->exception);
8160 (void) RemapImages(quantize_info,*images,(Image *) NULL);
8161 break;
8162 }
8163 case CompositeLayer:
8164 {
8165 CompositeOperator
8166 compose;
8167
8168 Image
8169 *source;
8170
8171 RectangleInfo
8172 geometry;
8173
8174 /*
8175 Split image sequence at the first 'NULL:' image.
8176 */
8177 source=(*images);
8178 while (source != (Image *) NULL)
8179 {
8180 source=GetNextImageInList(source);
8181 if ((source != (Image *) NULL) &&
8182 (LocaleCompare(source->magick,"NULL") == 0))
8183 break;
8184 }
8185 if (source != (Image *) NULL)
8186 {
8187 if ((GetPreviousImageInList(source) == (Image *) NULL) ||
8188 (GetNextImageInList(source) == (Image *) NULL))
8189 source=(Image *) NULL;
8190 else
8191 {
8192 /*
8193 Separate the two lists, junk the null: image.
8194 */
8195 source=SplitImageList(source->previous);
8196 DeleteImageFromList(&source);
8197 }
8198 }
8199 if (source == (Image *) NULL)
8200 {
8201 (void) ThrowMagickException(exception,GetMagickModule(),
8202 OptionError,"MissingNullSeparator","layers Composite");
8203 status=MagickFalse;
8204 break;
8205 }
8206 /*
8207 Adjust offset with gravity and virtual canvas.
8208 */
8209 SetGeometry(*images,&geometry);
8210 (void) ParseAbsoluteGeometry((*images)->geometry,&geometry);
8211 geometry.width=source->page.width != 0 ?
8212 source->page.width : source->columns;
8213 geometry.height=source->page.height != 0 ?
8214 source->page.height : source->rows;
8215 GravityAdjustGeometry((*images)->page.width != 0 ?
8216 (*images)->page.width : (*images)->columns,
8217 (*images)->page.height != 0 ? (*images)->page.height :
8218 (*images)->rows,(*images)->gravity,&geometry);
8219 compose=OverCompositeOp;
cristy6b3da3a2010-06-20 02:21:46 +00008220 option=GetImageOption(mogrify_info,"compose");
cristy3ed852e2009-09-05 21:47:34 +00008221 if (option != (const char *) NULL)
8222 compose=(CompositeOperator) ParseMagickOption(
8223 MagickComposeOptions,MagickFalse,option);
8224 CompositeLayers(*images,compose,source,geometry.x,geometry.y,
8225 exception);
8226 source=DestroyImageList(source);
8227 break;
8228 }
8229 }
8230 if (layers == (Image *) NULL)
8231 break;
8232 InheritException(exception,&layers->exception);
8233 *images=DestroyImageList(*images);
8234 *images=layers;
8235 break;
8236 }
8237 break;
8238 }
8239 case 'm':
8240 {
8241 if (LocaleCompare("map",option+1) == 0)
8242 {
cristy6b3da3a2010-06-20 02:21:46 +00008243 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00008244 if (*option == '+')
8245 {
8246 (void) RemapImages(quantize_info,*images,(Image *) NULL);
8247 InheritException(exception,&(*images)->exception);
8248 break;
8249 }
8250 i++;
8251 break;
8252 }
cristyf40785b2010-03-06 02:27:27 +00008253 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00008254 {
8255 Image
cristyf40785b2010-03-06 02:27:27 +00008256 *maximum_image;
cristy1c274c92010-03-06 02:06:45 +00008257
cristyd18ae7c2010-03-07 17:39:52 +00008258 /*
8259 Maximum image sequence (deprecated).
8260 */
cristy6b3da3a2010-06-20 02:21:46 +00008261 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00008262 maximum_image=EvaluateImages(*images,MaxEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00008263 if (maximum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00008264 {
8265 status=MagickFalse;
8266 break;
8267 }
8268 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00008269 *images=maximum_image;
cristy1c274c92010-03-06 02:06:45 +00008270 break;
8271 }
cristyf40785b2010-03-06 02:27:27 +00008272 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00008273 {
8274 Image
cristyf40785b2010-03-06 02:27:27 +00008275 *minimum_image;
cristy1c274c92010-03-06 02:06:45 +00008276
cristyd18ae7c2010-03-07 17:39:52 +00008277 /*
8278 Minimum image sequence (deprecated).
8279 */
cristy6b3da3a2010-06-20 02:21:46 +00008280 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00008281 minimum_image=EvaluateImages(*images,MinEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00008282 if (minimum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00008283 {
8284 status=MagickFalse;
8285 break;
8286 }
8287 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00008288 *images=minimum_image;
cristy1c274c92010-03-06 02:06:45 +00008289 break;
8290 }
cristy3ed852e2009-09-05 21:47:34 +00008291 if (LocaleCompare("morph",option+1) == 0)
8292 {
8293 Image
8294 *morph_image;
8295
cristy6b3da3a2010-06-20 02:21:46 +00008296 (void) SyncImagesSettings(mogrify_info,*images);
cristye27293e2009-12-18 02:53:20 +00008297 morph_image=MorphImages(*images,StringToUnsignedLong(argv[i+1]),
cristy3ed852e2009-09-05 21:47:34 +00008298 exception);
8299 if (morph_image == (Image *) NULL)
8300 {
8301 status=MagickFalse;
8302 break;
8303 }
8304 *images=DestroyImageList(*images);
8305 *images=morph_image;
8306 break;
8307 }
8308 if (LocaleCompare("mosaic",option+1) == 0)
8309 {
8310 Image
8311 *mosaic_image;
8312
cristy6b3da3a2010-06-20 02:21:46 +00008313 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00008314 mosaic_image=MergeImageLayers(*images,MosaicLayer,exception);
8315 if (mosaic_image == (Image *) NULL)
8316 {
8317 status=MagickFalse;
8318 break;
8319 }
8320 *images=DestroyImageList(*images);
8321 *images=mosaic_image;
8322 break;
8323 }
8324 break;
8325 }
8326 case 'p':
8327 {
8328 if (LocaleCompare("print",option+1) == 0)
8329 {
8330 char
8331 *string;
8332
cristy6b3da3a2010-06-20 02:21:46 +00008333 (void) SyncImagesSettings(mogrify_info,*images);
8334 string=InterpretImageProperties(mogrify_info,*images,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00008335 if (string == (char *) NULL)
8336 break;
8337 InheritException(exception,&(*images)->exception);
8338 (void) fprintf(stdout,"%s",string);
8339 string=DestroyString(string);
8340 }
8341 if (LocaleCompare("process",option+1) == 0)
8342 {
8343 char
8344 **arguments;
8345
8346 int
8347 j,
8348 number_arguments;
8349
cristy6b3da3a2010-06-20 02:21:46 +00008350 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00008351 arguments=StringToArgv(argv[i+1],&number_arguments);
8352 if (arguments == (char **) NULL)
8353 break;
8354 if ((argc > 1) && (strchr(arguments[1],'=') != (char *) NULL))
8355 {
8356 char
8357 breaker,
8358 quote,
8359 *token;
8360
8361 const char
8362 *arguments;
8363
8364 int
8365 next,
8366 status;
8367
8368 size_t
8369 length;
8370
8371 TokenInfo
8372 *token_info;
8373
8374 /*
8375 Support old style syntax, filter="-option arg".
8376 */
8377 length=strlen(argv[i+1]);
8378 token=(char *) NULL;
8379 if (~length >= MaxTextExtent)
8380 token=(char *) AcquireQuantumMemory(length+MaxTextExtent,
8381 sizeof(*token));
8382 if (token == (char *) NULL)
8383 break;
8384 next=0;
8385 arguments=argv[i+1];
8386 token_info=AcquireTokenInfo();
8387 status=Tokenizer(token_info,0,token,length,arguments,"","=",
8388 "\"",'\0',&breaker,&next,&quote);
8389 token_info=DestroyTokenInfo(token_info);
8390 if (status == 0)
8391 {
8392 const char
8393 *argv;
8394
8395 argv=(&(arguments[next]));
8396 (void) InvokeDynamicImageFilter(token,&(*images),1,&argv,
8397 exception);
8398 }
8399 token=DestroyString(token);
8400 break;
8401 }
cristy91c0da22010-05-02 01:44:07 +00008402 (void) SubstituteString(&arguments[1],"-","");
cristy3ed852e2009-09-05 21:47:34 +00008403 (void) InvokeDynamicImageFilter(arguments[1],&(*images),
8404 number_arguments-2,(const char **) arguments+2,exception);
8405 for (j=0; j < number_arguments; j++)
8406 arguments[j]=DestroyString(arguments[j]);
8407 arguments=(char **) RelinquishMagickMemory(arguments);
8408 break;
8409 }
8410 break;
8411 }
8412 case 'r':
8413 {
8414 if (LocaleCompare("reverse",option+1) == 0)
8415 {
8416 ReverseImageList(images);
8417 InheritException(exception,&(*images)->exception);
8418 break;
8419 }
8420 break;
8421 }
8422 case 's':
8423 {
cristy4285d782011-02-09 20:12:28 +00008424 if (LocaleCompare("smush",option+1) == 0)
8425 {
8426 Image
8427 *smush_image;
8428
8429 ssize_t
8430 offset;
8431
8432 (void) SyncImagesSettings(mogrify_info,*images);
8433 offset=(ssize_t) StringToLong(argv[i+1]);
8434 smush_image=SmushImages(*images,*option == '-' ? MagickTrue :
8435 MagickFalse,offset,exception);
8436 if (smush_image == (Image *) NULL)
8437 {
8438 status=MagickFalse;
8439 break;
8440 }
8441 *images=DestroyImageList(*images);
8442 *images=smush_image;
8443 break;
8444 }
cristy3ed852e2009-09-05 21:47:34 +00008445 if (LocaleCompare("swap",option+1) == 0)
8446 {
8447 Image
8448 *p,
8449 *q,
8450 *swap;
8451
cristybb503372010-05-27 20:51:26 +00008452 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00008453 swap_index;
8454
8455 index=(-1);
8456 swap_index=(-2);
8457 if (*option != '+')
8458 {
8459 GeometryInfo
8460 geometry_info;
8461
8462 MagickStatusType
8463 flags;
8464
8465 swap_index=(-1);
8466 flags=ParseGeometry(argv[i+1],&geometry_info);
cristybb503372010-05-27 20:51:26 +00008467 index=(ssize_t) geometry_info.rho;
cristy3ed852e2009-09-05 21:47:34 +00008468 if ((flags & SigmaValue) != 0)
cristybb503372010-05-27 20:51:26 +00008469 swap_index=(ssize_t) geometry_info.sigma;
cristy3ed852e2009-09-05 21:47:34 +00008470 }
8471 p=GetImageFromList(*images,index);
8472 q=GetImageFromList(*images,swap_index);
8473 if ((p == (Image *) NULL) || (q == (Image *) NULL))
8474 {
8475 (void) ThrowMagickException(exception,GetMagickModule(),
8476 OptionError,"NoSuchImage","`%s'",(*images)->filename);
8477 status=MagickFalse;
8478 break;
8479 }
8480 if (p == q)
8481 break;
8482 swap=CloneImage(p,0,0,MagickTrue,exception);
8483 ReplaceImageInList(&p,CloneImage(q,0,0,MagickTrue,exception));
8484 ReplaceImageInList(&q,swap);
8485 *images=GetFirstImageInList(q);
8486 break;
8487 }
8488 break;
8489 }
8490 case 'w':
8491 {
8492 if (LocaleCompare("write",option+1) == 0)
8493 {
cristy071dd7b2010-04-09 13:04:54 +00008494 char
cristy06609ee2010-03-17 20:21:27 +00008495 key[MaxTextExtent];
8496
cristy3ed852e2009-09-05 21:47:34 +00008497 Image
8498 *write_images;
8499
8500 ImageInfo
8501 *write_info;
8502
cristy6b3da3a2010-06-20 02:21:46 +00008503 (void) SyncImagesSettings(mogrify_info,*images);
cristy06609ee2010-03-17 20:21:27 +00008504 (void) FormatMagickString(key,MaxTextExtent,"cache:%s",argv[i+1]);
8505 (void) DeleteImageRegistry(key);
cristy3ed852e2009-09-05 21:47:34 +00008506 write_images=(*images);
8507 if (*option == '+')
8508 write_images=CloneImageList(*images,exception);
cristy6b3da3a2010-06-20 02:21:46 +00008509 write_info=CloneImageInfo(mogrify_info);
cristy3ed852e2009-09-05 21:47:34 +00008510 status&=WriteImages(write_info,write_images,argv[i+1],exception);
8511 write_info=DestroyImageInfo(write_info);
8512 if (*option == '+')
8513 write_images=DestroyImageList(write_images);
8514 break;
8515 }
8516 break;
8517 }
8518 default:
8519 break;
8520 }
8521 i+=count;
8522 }
8523 quantize_info=DestroyQuantizeInfo(quantize_info);
cristy6b3da3a2010-06-20 02:21:46 +00008524 mogrify_info=DestroyImageInfo(mogrify_info);
8525 status&=MogrifyImageInfo(image_info,argc,argv,exception);
cristy3ed852e2009-09-05 21:47:34 +00008526 return(status != 0 ? MagickTrue : MagickFalse);
8527}
8528
8529/*
8530%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8531% %
8532% %
8533% %
8534+ M o g r i f y I m a g e s %
8535% %
8536% %
8537% %
8538%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8539%
8540% MogrifyImages() applies image processing options to a sequence of images as
8541% prescribed by command line options.
8542%
8543% The format of the MogrifyImage method is:
8544%
8545% MagickBooleanType MogrifyImages(ImageInfo *image_info,
8546% const MagickBooleanType post,const int argc,const char **argv,
8547% Image **images,Exceptioninfo *exception)
8548%
8549% A description of each parameter follows:
8550%
8551% o image_info: the image info..
8552%
8553% o post: If true, post process image list operators otherwise pre-process.
8554%
8555% o argc: Specifies a pointer to an integer describing the number of
8556% elements in the argument vector.
8557%
8558% o argv: Specifies a pointer to a text array containing the command line
8559% arguments.
8560%
8561% o images: the images.
8562%
8563% o exception: return any errors or warnings in this structure.
8564%
8565*/
8566WandExport MagickBooleanType MogrifyImages(ImageInfo *image_info,
8567 const MagickBooleanType post,const int argc,const char **argv,
8568 Image **images,ExceptionInfo *exception)
8569{
8570#define MogrifyImageTag "Mogrify/Image"
8571
8572 Image
8573 *image,
8574 *mogrify_images;
8575
cristy0e9f9c12010-02-11 03:00:47 +00008576 MagickBooleanType
8577 proceed;
8578
8579 MagickSizeType
8580 number_images;
8581
cristy3ed852e2009-09-05 21:47:34 +00008582 MagickStatusType
8583 status;
8584
cristybb503372010-05-27 20:51:26 +00008585 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00008586 i;
8587
cristy3ed852e2009-09-05 21:47:34 +00008588 /*
8589 Apply options to individual images in the list.
8590 */
8591 assert(image_info != (ImageInfo *) NULL);
8592 assert(image_info->signature == MagickSignature);
8593 if (images == (Image **) NULL)
8594 return(MogrifyImage(image_info,argc,argv,images,exception));
8595 assert((*images)->signature == MagickSignature);
8596 if ((*images)->debug != MagickFalse)
8597 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
8598 (*images)->filename);
8599 if ((argc <= 0) || (*argv == (char *) NULL))
8600 return(MagickTrue);
8601 (void) SetImageInfoProgressMonitor(image_info,(MagickProgressMonitor) NULL,
8602 (void *) NULL);
8603 mogrify_images=NewImageList();
8604 number_images=GetImageListLength(*images);
8605 status=0;
8606 if (post == MagickFalse)
8607 status&=MogrifyImageList(image_info,argc,argv,images,exception);
cristybb503372010-05-27 20:51:26 +00008608 for (i=0; i < (ssize_t) number_images; i++)
cristy3ed852e2009-09-05 21:47:34 +00008609 {
8610 image=RemoveFirstImageFromList(images);
8611 if (image == (Image *) NULL)
8612 continue;
8613 status&=MogrifyImage(image_info,argc,argv,&image,exception);
8614 AppendImageToList(&mogrify_images,image);
cristy0e9f9c12010-02-11 03:00:47 +00008615 proceed=SetImageProgress(image,MogrifyImageTag,(MagickOffsetType) i,
8616 number_images);
8617 if (proceed == MagickFalse)
8618 break;
cristy3ed852e2009-09-05 21:47:34 +00008619 }
8620 if (post != MagickFalse)
8621 status&=MogrifyImageList(image_info,argc,argv,&mogrify_images,exception);
8622 *images=mogrify_images;
8623 return(status != 0 ? MagickTrue : MagickFalse);
8624}