blob: 40d037d6877108ebf3ecfde280b016dea6ccd714 [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
cristy9d314ff2011-03-09 01:30:28 +00001073 register PixelPacket
1074 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00001075
cristybb503372010-05-27 20:51:26 +00001076 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001077 x;
1078
cristy9d314ff2011-03-09 01:30:28 +00001079 ssize_t
1080 y;
cristy3ed852e2009-09-05 21:47:34 +00001081
cristy6b3da3a2010-06-20 02:21:46 +00001082 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001083 if (*option == '+')
1084 {
1085 /*
1086 Remove a mask.
1087 */
1088 (void) SetImageMask(*image,(Image *) NULL);
1089 InheritException(exception,&(*image)->exception);
1090 break;
1091 }
1092 /*
1093 Set the image mask.
1094 */
cristyb0d3bb92010-09-22 14:37:58 +00001095 mask_image=GetImageCache(mogrify_info,argv[i+1],exception);
1096 if (mask_image == (Image *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001097 break;
cristyb0d3bb92010-09-22 14:37:58 +00001098 if (SetImageStorageClass(mask_image,DirectClass) == MagickFalse)
1099 return(MagickFalse);
1100 mask_view=AcquireCacheView(mask_image);
1101 for (y=0; y < (ssize_t) mask_image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00001102 {
cristyb0d3bb92010-09-22 14:37:58 +00001103 q=GetCacheViewAuthenticPixels(mask_view,0,y,mask_image->columns,1,
1104 exception);
cristy3ed852e2009-09-05 21:47:34 +00001105 if (q == (PixelPacket *) NULL)
1106 break;
cristyb0d3bb92010-09-22 14:37:58 +00001107 for (x=0; x < (ssize_t) mask_image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00001108 {
cristyb0d3bb92010-09-22 14:37:58 +00001109 if (mask_image->matte == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00001110 q->opacity=PixelIntensityToQuantum(q);
1111 q->red=q->opacity;
1112 q->green=q->opacity;
1113 q->blue=q->opacity;
1114 q++;
1115 }
cristyb0d3bb92010-09-22 14:37:58 +00001116 if (SyncCacheViewAuthenticPixels(mask_view,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00001117 break;
1118 }
cristyb0d3bb92010-09-22 14:37:58 +00001119 mask_view=DestroyCacheView(mask_view);
1120 mask_image->matte=MagickTrue;
1121 (void) SetImageClipMask(*image,mask_image);
1122 mask_image=DestroyImage(mask_image);
cristy3ed852e2009-09-05 21:47:34 +00001123 InheritException(exception,&(*image)->exception);
1124 break;
1125 }
1126 if (LocaleCompare("clip-path",option+1) == 0)
1127 {
cristy6b3da3a2010-06-20 02:21:46 +00001128 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001129 (void) ClipImagePath(*image,argv[i+1],*option == '-' ? MagickTrue :
1130 MagickFalse);
1131 InheritException(exception,&(*image)->exception);
1132 break;
1133 }
1134 if (LocaleCompare("colorize",option+1) == 0)
1135 {
1136 Image
1137 *colorize_image;
1138
1139 /*
1140 Colorize the image.
1141 */
cristy6b3da3a2010-06-20 02:21:46 +00001142 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001143 colorize_image=ColorizeImage(*image,argv[i+1],draw_info->fill,
1144 exception);
1145 if (colorize_image == (Image *) NULL)
1146 break;
1147 *image=DestroyImage(*image);
1148 *image=colorize_image;
1149 break;
1150 }
cristye6365592010-04-02 17:31:23 +00001151 if (LocaleCompare("color-matrix",option+1) == 0)
1152 {
1153 Image
1154 *color_image;
1155
1156 KernelInfo
1157 *kernel;
1158
cristy6b3da3a2010-06-20 02:21:46 +00001159 (void) SyncImageSettings(mogrify_info,*image);
cristye6365592010-04-02 17:31:23 +00001160 kernel=AcquireKernelInfo(argv[i+1]);
1161 if (kernel == (KernelInfo *) NULL)
1162 break;
1163 color_image=ColorMatrixImage(*image,kernel,exception);
1164 kernel=DestroyKernelInfo(kernel);
1165 if (color_image == (Image *) NULL)
1166 break;
1167 *image=DestroyImage(*image);
1168 *image=color_image;
1169 break;
1170 }
cristy3ed852e2009-09-05 21:47:34 +00001171 if (LocaleCompare("colors",option+1) == 0)
1172 {
1173 /*
1174 Reduce the number of colors in the image.
1175 */
cristy6b3da3a2010-06-20 02:21:46 +00001176 (void) SyncImageSettings(mogrify_info,*image);
cristye27293e2009-12-18 02:53:20 +00001177 quantize_info->number_colors=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00001178 if (quantize_info->number_colors == 0)
1179 break;
1180 if (((*image)->storage_class == DirectClass) ||
1181 (*image)->colors > quantize_info->number_colors)
1182 (void) QuantizeImage(quantize_info,*image);
1183 else
1184 (void) CompressImageColormap(*image);
1185 InheritException(exception,&(*image)->exception);
1186 break;
1187 }
1188 if (LocaleCompare("colorspace",option+1) == 0)
1189 {
1190 ColorspaceType
1191 colorspace;
1192
cristy6b3da3a2010-06-20 02:21:46 +00001193 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001194 if (*option == '+')
1195 {
1196 (void) TransformImageColorspace(*image,RGBColorspace);
1197 InheritException(exception,&(*image)->exception);
1198 break;
1199 }
1200 colorspace=(ColorspaceType) ParseMagickOption(
1201 MagickColorspaceOptions,MagickFalse,argv[i+1]);
1202 (void) TransformImageColorspace(*image,colorspace);
1203 InheritException(exception,&(*image)->exception);
1204 break;
1205 }
1206 if (LocaleCompare("contrast",option+1) == 0)
1207 {
cristy6b3da3a2010-06-20 02:21:46 +00001208 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001209 (void) ContrastImage(*image,(*option == '-') ? MagickTrue :
1210 MagickFalse);
1211 InheritException(exception,&(*image)->exception);
1212 break;
1213 }
1214 if (LocaleCompare("contrast-stretch",option+1) == 0)
1215 {
1216 double
1217 black_point,
1218 white_point;
1219
cristy3ed852e2009-09-05 21:47:34 +00001220 MagickStatusType
1221 flags;
1222
1223 /*
1224 Contrast stretch image.
1225 */
cristy6b3da3a2010-06-20 02:21:46 +00001226 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001227 flags=ParseGeometry(argv[i+1],&geometry_info);
1228 black_point=geometry_info.rho;
1229 white_point=(flags & SigmaValue) != 0 ? geometry_info.sigma :
1230 black_point;
1231 if ((flags & PercentValue) != 0)
1232 {
1233 black_point*=(double) (*image)->columns*(*image)->rows/100.0;
1234 white_point*=(double) (*image)->columns*(*image)->rows/100.0;
1235 }
1236 white_point=(MagickRealType) (*image)->columns*(*image)->rows-
1237 white_point;
1238 (void) ContrastStretchImageChannel(*image,channel,black_point,
1239 white_point);
1240 InheritException(exception,&(*image)->exception);
1241 break;
1242 }
1243 if (LocaleCompare("convolve",option+1) == 0)
1244 {
cristy36826ab2010-03-06 01:29:30 +00001245 double
1246 gamma;
1247
cristy3ed852e2009-09-05 21:47:34 +00001248 Image
1249 *convolve_image;
1250
cristy2be15382010-01-21 02:38:03 +00001251 KernelInfo
cristy56a9e512010-01-06 18:18:55 +00001252 *kernel;
cristy3ed852e2009-09-05 21:47:34 +00001253
cristybb503372010-05-27 20:51:26 +00001254 register ssize_t
cristy36826ab2010-03-06 01:29:30 +00001255 j;
1256
cristy6b3da3a2010-06-20 02:21:46 +00001257 (void) SyncImageSettings(mogrify_info,*image);
cristy2be15382010-01-21 02:38:03 +00001258 kernel=AcquireKernelInfo(argv[i+1]);
1259 if (kernel == (KernelInfo *) NULL)
cristy56a9e512010-01-06 18:18:55 +00001260 break;
cristy36826ab2010-03-06 01:29:30 +00001261 gamma=0.0;
cristybb503372010-05-27 20:51:26 +00001262 for (j=0; j < (ssize_t) (kernel->width*kernel->height); j++)
cristy36826ab2010-03-06 01:29:30 +00001263 gamma+=kernel->values[j];
1264 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
cristybb503372010-05-27 20:51:26 +00001265 for (j=0; j < (ssize_t) (kernel->width*kernel->height); j++)
cristy36826ab2010-03-06 01:29:30 +00001266 kernel->values[j]*=gamma;
cristy6771f1e2010-03-05 19:43:39 +00001267 convolve_image=FilterImageChannel(*image,channel,kernel,exception);
anthony83ba99b2010-01-24 08:48:15 +00001268 kernel=DestroyKernelInfo(kernel);
cristy3ed852e2009-09-05 21:47:34 +00001269 if (convolve_image == (Image *) NULL)
1270 break;
1271 *image=DestroyImage(*image);
1272 *image=convolve_image;
1273 break;
1274 }
1275 if (LocaleCompare("crop",option+1) == 0)
1276 {
cristy6b3da3a2010-06-20 02:21:46 +00001277 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001278 flags=ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1279 if (((geometry.width != 0) || (geometry.height != 0)) &&
1280 ((flags & XValue) == 0) && ((flags & YValue) == 0))
1281 break;
1282 (void) TransformImage(image,argv[i+1],(char *) NULL);
1283 InheritException(exception,&(*image)->exception);
1284 break;
1285 }
1286 if (LocaleCompare("cycle",option+1) == 0)
1287 {
1288 /*
1289 Cycle an image colormap.
1290 */
cristy6b3da3a2010-06-20 02:21:46 +00001291 (void) SyncImageSettings(mogrify_info,*image);
cristy32c2aea2010-12-01 01:00:50 +00001292 (void) CycleColormapImage(*image,(ssize_t) StringToLong(argv[i+1]));
cristy3ed852e2009-09-05 21:47:34 +00001293 InheritException(exception,&(*image)->exception);
1294 break;
1295 }
1296 break;
1297 }
1298 case 'd':
1299 {
1300 if (LocaleCompare("decipher",option+1) == 0)
1301 {
1302 StringInfo
1303 *passkey;
1304
1305 /*
1306 Decipher pixels.
1307 */
cristy6b3da3a2010-06-20 02:21:46 +00001308 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001309 passkey=FileToStringInfo(argv[i+1],~0,exception);
1310 if (passkey != (StringInfo *) NULL)
1311 {
1312 (void) PasskeyDecipherImage(*image,passkey,exception);
1313 passkey=DestroyStringInfo(passkey);
1314 }
1315 break;
1316 }
1317 if (LocaleCompare("density",option+1) == 0)
1318 {
1319 /*
1320 Set image density.
1321 */
1322 (void) CloneString(&draw_info->density,argv[i+1]);
1323 break;
1324 }
1325 if (LocaleCompare("depth",option+1) == 0)
1326 {
cristy6b3da3a2010-06-20 02:21:46 +00001327 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001328 if (*option == '+')
1329 {
1330 (void) SetImageDepth(*image,MAGICKCORE_QUANTUM_DEPTH);
1331 break;
1332 }
cristye27293e2009-12-18 02:53:20 +00001333 (void) SetImageDepth(*image,StringToUnsignedLong(argv[i+1]));
cristy3ed852e2009-09-05 21:47:34 +00001334 break;
1335 }
1336 if (LocaleCompare("deskew",option+1) == 0)
1337 {
1338 double
1339 threshold;
1340
1341 Image
1342 *deskew_image;
1343
1344 /*
1345 Straighten the image.
1346 */
cristy6b3da3a2010-06-20 02:21:46 +00001347 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001348 if (*option == '+')
1349 threshold=40.0*QuantumRange/100.0;
1350 else
cristyf2f27272009-12-17 14:48:46 +00001351 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
cristy3ed852e2009-09-05 21:47:34 +00001352 deskew_image=DeskewImage(*image,threshold,exception);
1353 if (deskew_image == (Image *) NULL)
1354 break;
1355 *image=DestroyImage(*image);
1356 *image=deskew_image;
1357 break;
1358 }
1359 if (LocaleCompare("despeckle",option+1) == 0)
1360 {
1361 Image
1362 *despeckle_image;
1363
1364 /*
1365 Reduce the speckles within an image.
1366 */
cristy6b3da3a2010-06-20 02:21:46 +00001367 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001368 despeckle_image=DespeckleImage(*image,exception);
1369 if (despeckle_image == (Image *) NULL)
1370 break;
1371 *image=DestroyImage(*image);
1372 *image=despeckle_image;
1373 break;
1374 }
1375 if (LocaleCompare("display",option+1) == 0)
1376 {
1377 (void) CloneString(&draw_info->server_name,argv[i+1]);
1378 break;
1379 }
cristy3ed852e2009-09-05 21:47:34 +00001380 if (LocaleCompare("distort",option+1) == 0)
1381 {
1382 char
1383 *args,
1384 token[MaxTextExtent];
1385
1386 const char
1387 *p;
1388
1389 DistortImageMethod
1390 method;
1391
1392 double
1393 *arguments;
1394
1395 Image
1396 *distort_image;
1397
cristybb503372010-05-27 20:51:26 +00001398 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001399 x;
1400
cristybb503372010-05-27 20:51:26 +00001401 size_t
cristy3ed852e2009-09-05 21:47:34 +00001402 number_arguments;
1403
1404 /*
1405 Distort image.
1406 */
cristy6b3da3a2010-06-20 02:21:46 +00001407 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001408 method=(DistortImageMethod) ParseMagickOption(MagickDistortOptions,
1409 MagickFalse,argv[i+1]);
cristy6b3da3a2010-06-20 02:21:46 +00001410 args=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
cristy3ed852e2009-09-05 21:47:34 +00001411 InheritException(exception,&(*image)->exception);
1412 if (args == (char *) NULL)
1413 break;
1414 p=(char *) args;
1415 for (x=0; *p != '\0'; x++)
1416 {
1417 GetMagickToken(p,&p,token);
1418 if (*token == ',')
1419 GetMagickToken(p,&p,token);
1420 }
cristybb503372010-05-27 20:51:26 +00001421 number_arguments=(size_t) x;
cristy3ed852e2009-09-05 21:47:34 +00001422 arguments=(double *) AcquireQuantumMemory(number_arguments,
1423 sizeof(*arguments));
1424 if (arguments == (double *) NULL)
1425 ThrowWandFatalException(ResourceLimitFatalError,
1426 "MemoryAllocationFailed",(*image)->filename);
1427 (void) ResetMagickMemory(arguments,0,number_arguments*
1428 sizeof(*arguments));
1429 p=(char *) args;
cristybb503372010-05-27 20:51:26 +00001430 for (x=0; (x < (ssize_t) number_arguments) && (*p != '\0'); x++)
cristy3ed852e2009-09-05 21:47:34 +00001431 {
1432 GetMagickToken(p,&p,token);
1433 if (*token == ',')
1434 GetMagickToken(p,&p,token);
cristyf2f27272009-12-17 14:48:46 +00001435 arguments[x]=StringToDouble(token);
cristy3ed852e2009-09-05 21:47:34 +00001436 }
1437 args=DestroyString(args);
1438 distort_image=DistortImage(*image,method,number_arguments,arguments,
1439 (*option == '+') ? MagickTrue : MagickFalse,exception);
1440 arguments=(double *) RelinquishMagickMemory(arguments);
1441 if (distort_image == (Image *) NULL)
1442 break;
1443 *image=DestroyImage(*image);
1444 *image=distort_image;
1445 break;
1446 }
1447 if (LocaleCompare("dither",option+1) == 0)
1448 {
1449 if (*option == '+')
1450 {
1451 quantize_info->dither=MagickFalse;
1452 break;
1453 }
1454 quantize_info->dither=MagickTrue;
1455 quantize_info->dither_method=(DitherMethod) ParseMagickOption(
1456 MagickDitherOptions,MagickFalse,argv[i+1]);
1457 if (quantize_info->dither_method == NoDitherMethod)
1458 quantize_info->dither=MagickFalse;
1459 break;
1460 }
1461 if (LocaleCompare("draw",option+1) == 0)
1462 {
1463 /*
1464 Draw image.
1465 */
cristy6b3da3a2010-06-20 02:21:46 +00001466 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001467 (void) CloneString(&draw_info->primitive,argv[i+1]);
1468 (void) DrawImage(*image,draw_info);
1469 InheritException(exception,&(*image)->exception);
1470 break;
1471 }
1472 break;
1473 }
1474 case 'e':
1475 {
1476 if (LocaleCompare("edge",option+1) == 0)
1477 {
1478 Image
1479 *edge_image;
1480
1481 /*
1482 Enhance edges in the image.
1483 */
cristy6b3da3a2010-06-20 02:21:46 +00001484 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001485 flags=ParseGeometry(argv[i+1],&geometry_info);
1486 if ((flags & SigmaValue) == 0)
1487 geometry_info.sigma=1.0;
1488 edge_image=EdgeImage(*image,geometry_info.rho,exception);
1489 if (edge_image == (Image *) NULL)
1490 break;
1491 *image=DestroyImage(*image);
1492 *image=edge_image;
1493 break;
1494 }
1495 if (LocaleCompare("emboss",option+1) == 0)
1496 {
1497 Image
1498 *emboss_image;
1499
1500 /*
1501 Gaussian embossen image.
1502 */
cristy6b3da3a2010-06-20 02:21:46 +00001503 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001504 flags=ParseGeometry(argv[i+1],&geometry_info);
1505 if ((flags & SigmaValue) == 0)
1506 geometry_info.sigma=1.0;
1507 emboss_image=EmbossImage(*image,geometry_info.rho,
1508 geometry_info.sigma,exception);
1509 if (emboss_image == (Image *) NULL)
1510 break;
1511 *image=DestroyImage(*image);
1512 *image=emboss_image;
1513 break;
1514 }
1515 if (LocaleCompare("encipher",option+1) == 0)
1516 {
1517 StringInfo
1518 *passkey;
1519
1520 /*
1521 Encipher pixels.
1522 */
cristy6b3da3a2010-06-20 02:21:46 +00001523 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001524 passkey=FileToStringInfo(argv[i+1],~0,exception);
1525 if (passkey != (StringInfo *) NULL)
1526 {
1527 (void) PasskeyEncipherImage(*image,passkey,exception);
1528 passkey=DestroyStringInfo(passkey);
1529 }
1530 break;
1531 }
1532 if (LocaleCompare("encoding",option+1) == 0)
1533 {
1534 (void) CloneString(&draw_info->encoding,argv[i+1]);
1535 break;
1536 }
1537 if (LocaleCompare("enhance",option+1) == 0)
1538 {
1539 Image
1540 *enhance_image;
1541
1542 /*
1543 Enhance image.
1544 */
cristy6b3da3a2010-06-20 02:21:46 +00001545 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001546 enhance_image=EnhanceImage(*image,exception);
1547 if (enhance_image == (Image *) NULL)
1548 break;
1549 *image=DestroyImage(*image);
1550 *image=enhance_image;
1551 break;
1552 }
1553 if (LocaleCompare("equalize",option+1) == 0)
1554 {
1555 /*
1556 Equalize image.
1557 */
cristy6b3da3a2010-06-20 02:21:46 +00001558 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001559 (void) EqualizeImageChannel(*image,channel);
1560 InheritException(exception,&(*image)->exception);
1561 break;
1562 }
1563 if (LocaleCompare("evaluate",option+1) == 0)
1564 {
1565 double
1566 constant;
1567
1568 MagickEvaluateOperator
1569 op;
1570
cristy6b3da3a2010-06-20 02:21:46 +00001571 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001572 op=(MagickEvaluateOperator) ParseMagickOption(MagickEvaluateOptions,
1573 MagickFalse,argv[i+1]);
cristyf2f27272009-12-17 14:48:46 +00001574 constant=SiPrefixToDouble(argv[i+2],QuantumRange);
cristy3ed852e2009-09-05 21:47:34 +00001575 (void) EvaluateImageChannel(*image,channel,op,constant,exception);
1576 break;
1577 }
1578 if (LocaleCompare("extent",option+1) == 0)
1579 {
1580 Image
1581 *extent_image;
1582
1583 /*
1584 Set the image extent.
1585 */
cristy6b3da3a2010-06-20 02:21:46 +00001586 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001587 flags=ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
cristyf0bbfd92009-11-25 14:12:31 +00001588 if (geometry.width == 0)
cristy2ea9a4e2009-11-25 14:30:22 +00001589 geometry.width=(*image)->columns;
cristyf0bbfd92009-11-25 14:12:31 +00001590 if (geometry.height == 0)
cristy2ea9a4e2009-11-25 14:30:22 +00001591 geometry.height=(*image)->rows;
cristy3ed852e2009-09-05 21:47:34 +00001592 extent_image=ExtentImage(*image,&geometry,exception);
1593 if (extent_image == (Image *) NULL)
1594 break;
1595 *image=DestroyImage(*image);
1596 *image=extent_image;
1597 break;
1598 }
1599 break;
1600 }
1601 case 'f':
1602 {
1603 if (LocaleCompare("family",option+1) == 0)
1604 {
1605 if (*option == '+')
1606 {
1607 if (draw_info->family != (char *) NULL)
1608 draw_info->family=DestroyString(draw_info->family);
1609 break;
1610 }
1611 (void) CloneString(&draw_info->family,argv[i+1]);
1612 break;
1613 }
cristy0fe961c2010-01-30 03:09:54 +00001614 if (LocaleCompare("features",option+1) == 0)
1615 {
1616 if (*option == '+')
1617 {
1618 (void) DeleteImageArtifact(*image,"identify:features");
1619 break;
1620 }
1621 (void) SetImageArtifact(*image,"identify:features",argv[i+1]);
1622 break;
1623 }
cristy3ed852e2009-09-05 21:47:34 +00001624 if (LocaleCompare("fill",option+1) == 0)
1625 {
1626 ExceptionInfo
1627 *sans;
1628
1629 GetMagickPixelPacket(*image,&fill);
1630 if (*option == '+')
1631 {
1632 (void) QueryMagickColor("none",&fill,exception);
1633 (void) QueryColorDatabase("none",&draw_info->fill,exception);
1634 if (draw_info->fill_pattern != (Image *) NULL)
1635 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
1636 break;
1637 }
1638 sans=AcquireExceptionInfo();
1639 (void) QueryMagickColor(argv[i+1],&fill,sans);
1640 status=QueryColorDatabase(argv[i+1],&draw_info->fill,sans);
1641 sans=DestroyExceptionInfo(sans);
1642 if (status == MagickFalse)
cristy6b3da3a2010-06-20 02:21:46 +00001643 draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1],
cristy3ed852e2009-09-05 21:47:34 +00001644 exception);
1645 break;
1646 }
1647 if (LocaleCompare("flip",option+1) == 0)
1648 {
1649 Image
1650 *flip_image;
1651
1652 /*
1653 Flip image scanlines.
1654 */
cristy6b3da3a2010-06-20 02:21:46 +00001655 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001656 flip_image=FlipImage(*image,exception);
1657 if (flip_image == (Image *) NULL)
1658 break;
1659 *image=DestroyImage(*image);
1660 *image=flip_image;
1661 break;
1662 }
1663 if (LocaleCompare("flop",option+1) == 0)
1664 {
1665 Image
1666 *flop_image;
1667
1668 /*
1669 Flop image scanlines.
1670 */
cristy6b3da3a2010-06-20 02:21:46 +00001671 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001672 flop_image=FlopImage(*image,exception);
1673 if (flop_image == (Image *) NULL)
1674 break;
1675 *image=DestroyImage(*image);
1676 *image=flop_image;
1677 break;
1678 }
1679 if (LocaleCompare("floodfill",option+1) == 0)
1680 {
1681 MagickPixelPacket
1682 target;
1683
1684 /*
1685 Floodfill image.
1686 */
cristy6b3da3a2010-06-20 02:21:46 +00001687 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001688 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
1689 (void) QueryMagickColor(argv[i+2],&target,exception);
1690 (void) FloodfillPaintImage(*image,channel,draw_info,&target,
1691 geometry.x,geometry.y,*option == '-' ? MagickFalse : MagickTrue);
1692 InheritException(exception,&(*image)->exception);
1693 break;
1694 }
1695 if (LocaleCompare("font",option+1) == 0)
1696 {
1697 if (*option == '+')
1698 {
1699 if (draw_info->font != (char *) NULL)
1700 draw_info->font=DestroyString(draw_info->font);
1701 break;
1702 }
1703 (void) CloneString(&draw_info->font,argv[i+1]);
1704 break;
1705 }
1706 if (LocaleCompare("format",option+1) == 0)
1707 {
1708 format=argv[i+1];
1709 break;
1710 }
1711 if (LocaleCompare("frame",option+1) == 0)
1712 {
1713 FrameInfo
1714 frame_info;
1715
1716 Image
1717 *frame_image;
1718
1719 /*
1720 Surround image with an ornamental border.
1721 */
cristy6b3da3a2010-06-20 02:21:46 +00001722 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001723 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
1724 frame_info.width=geometry.width;
1725 frame_info.height=geometry.height;
1726 if ((flags & HeightValue) == 0)
1727 frame_info.height=geometry.width;
1728 frame_info.outer_bevel=geometry.x;
1729 frame_info.inner_bevel=geometry.y;
cristybb503372010-05-27 20:51:26 +00001730 frame_info.x=(ssize_t) frame_info.width;
1731 frame_info.y=(ssize_t) frame_info.height;
cristy3ed852e2009-09-05 21:47:34 +00001732 frame_info.width=(*image)->columns+2*frame_info.width;
1733 frame_info.height=(*image)->rows+2*frame_info.height;
1734 frame_image=FrameImage(*image,&frame_info,exception);
1735 if (frame_image == (Image *) NULL)
1736 break;
1737 *image=DestroyImage(*image);
1738 *image=frame_image;
1739 break;
1740 }
1741 if (LocaleCompare("function",option+1) == 0)
1742 {
1743 char
1744 *arguments,
1745 token[MaxTextExtent];
1746
1747 const char
1748 *p;
1749
1750 double
1751 *parameters;
1752
1753 MagickFunction
1754 function;
1755
cristybb503372010-05-27 20:51:26 +00001756 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001757 x;
1758
cristybb503372010-05-27 20:51:26 +00001759 size_t
cristy3ed852e2009-09-05 21:47:34 +00001760 number_parameters;
1761
1762 /*
1763 Function Modify Image Values
1764 */
cristy6b3da3a2010-06-20 02:21:46 +00001765 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001766 function=(MagickFunction) ParseMagickOption(MagickFunctionOptions,
1767 MagickFalse,argv[i+1]);
cristy6b3da3a2010-06-20 02:21:46 +00001768 arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
cristy3ed852e2009-09-05 21:47:34 +00001769 InheritException(exception,&(*image)->exception);
1770 if (arguments == (char *) NULL)
1771 break;
1772 p=(char *) arguments;
1773 for (x=0; *p != '\0'; x++)
1774 {
1775 GetMagickToken(p,&p,token);
1776 if (*token == ',')
1777 GetMagickToken(p,&p,token);
1778 }
cristybb503372010-05-27 20:51:26 +00001779 number_parameters=(size_t) x;
cristy3ed852e2009-09-05 21:47:34 +00001780 parameters=(double *) AcquireQuantumMemory(number_parameters,
1781 sizeof(*parameters));
1782 if (parameters == (double *) NULL)
1783 ThrowWandFatalException(ResourceLimitFatalError,
1784 "MemoryAllocationFailed",(*image)->filename);
1785 (void) ResetMagickMemory(parameters,0,number_parameters*
1786 sizeof(*parameters));
1787 p=(char *) arguments;
cristybb503372010-05-27 20:51:26 +00001788 for (x=0; (x < (ssize_t) number_parameters) && (*p != '\0'); x++)
cristy3ed852e2009-09-05 21:47:34 +00001789 {
1790 GetMagickToken(p,&p,token);
1791 if (*token == ',')
1792 GetMagickToken(p,&p,token);
cristyf2f27272009-12-17 14:48:46 +00001793 parameters[x]=StringToDouble(token);
cristy3ed852e2009-09-05 21:47:34 +00001794 }
1795 arguments=DestroyString(arguments);
1796 (void) FunctionImageChannel(*image,channel,function,
1797 number_parameters,parameters,exception);
1798 parameters=(double *) RelinquishMagickMemory(parameters);
1799 break;
1800 }
1801 break;
1802 }
1803 case 'g':
1804 {
1805 if (LocaleCompare("gamma",option+1) == 0)
1806 {
1807 /*
1808 Gamma image.
1809 */
cristy6b3da3a2010-06-20 02:21:46 +00001810 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001811 if (*option == '+')
cristyf2f27272009-12-17 14:48:46 +00001812 (*image)->gamma=StringToDouble(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00001813 else
1814 {
1815 if (strchr(argv[i+1],',') != (char *) NULL)
1816 (void) GammaImage(*image,argv[i+1]);
1817 else
cristya5447be2010-01-11 00:20:51 +00001818 (void) GammaImageChannel(*image,channel,
1819 StringToDouble(argv[i+1]));
cristy3ed852e2009-09-05 21:47:34 +00001820 InheritException(exception,&(*image)->exception);
1821 }
1822 break;
1823 }
1824 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
1825 (LocaleCompare("gaussian",option+1) == 0))
1826 {
1827 Image
1828 *gaussian_image;
1829
1830 /*
1831 Gaussian blur image.
1832 */
cristy6b3da3a2010-06-20 02:21:46 +00001833 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001834 flags=ParseGeometry(argv[i+1],&geometry_info);
1835 if ((flags & SigmaValue) == 0)
1836 geometry_info.sigma=1.0;
1837 gaussian_image=GaussianBlurImageChannel(*image,channel,
1838 geometry_info.rho,geometry_info.sigma,exception);
1839 if (gaussian_image == (Image *) NULL)
1840 break;
1841 *image=DestroyImage(*image);
1842 *image=gaussian_image;
1843 break;
1844 }
1845 if (LocaleCompare("geometry",option+1) == 0)
1846 {
cristy6b3da3a2010-06-20 02:21:46 +00001847 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001848 if (*option == '+')
1849 {
1850 if ((*image)->geometry != (char *) NULL)
1851 (*image)->geometry=DestroyString((*image)->geometry);
1852 break;
1853 }
1854 flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
1855 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
1856 (void) CloneString(&(*image)->geometry,argv[i+1]);
1857 else
1858 {
1859 Image
cristy15b98cd2010-09-12 19:42:50 +00001860 *resize_image;
cristy3ed852e2009-09-05 21:47:34 +00001861
1862 /*
1863 Resize image.
1864 */
cristy15b98cd2010-09-12 19:42:50 +00001865 resize_image=ResizeImage(*image,geometry.width,geometry.height,
1866 (*image)->filter,(*image)->blur,exception);
1867 if (resize_image == (Image *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001868 break;
1869 *image=DestroyImage(*image);
cristy15b98cd2010-09-12 19:42:50 +00001870 *image=resize_image;
cristy3ed852e2009-09-05 21:47:34 +00001871 }
1872 break;
1873 }
1874 if (LocaleCompare("gravity",option+1) == 0)
1875 {
1876 if (*option == '+')
1877 {
1878 draw_info->gravity=UndefinedGravity;
1879 break;
1880 }
1881 draw_info->gravity=(GravityType) ParseMagickOption(
1882 MagickGravityOptions,MagickFalse,argv[i+1]);
1883 break;
1884 }
1885 break;
1886 }
1887 case 'h':
1888 {
1889 if (LocaleCompare("highlight-color",option+1) == 0)
1890 {
1891 (void) SetImageArtifact(*image,option+1,argv[i+1]);
1892 break;
1893 }
1894 break;
1895 }
1896 case 'i':
1897 {
1898 if (LocaleCompare("identify",option+1) == 0)
1899 {
1900 char
1901 *text;
1902
cristy6b3da3a2010-06-20 02:21:46 +00001903 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001904 if (format == (char *) NULL)
1905 {
cristy6b3da3a2010-06-20 02:21:46 +00001906 (void) IdentifyImage(*image,stdout,mogrify_info->verbose);
cristy3ed852e2009-09-05 21:47:34 +00001907 InheritException(exception,&(*image)->exception);
1908 break;
1909 }
cristy6b3da3a2010-06-20 02:21:46 +00001910 text=InterpretImageProperties(mogrify_info,*image,format);
cristy3ed852e2009-09-05 21:47:34 +00001911 InheritException(exception,&(*image)->exception);
1912 if (text == (char *) NULL)
1913 break;
1914 (void) fputs(text,stdout);
1915 (void) fputc('\n',stdout);
1916 text=DestroyString(text);
1917 break;
1918 }
1919 if (LocaleCompare("implode",option+1) == 0)
1920 {
1921 Image
1922 *implode_image;
1923
1924 /*
1925 Implode image.
1926 */
cristy6b3da3a2010-06-20 02:21:46 +00001927 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001928 (void) ParseGeometry(argv[i+1],&geometry_info);
1929 implode_image=ImplodeImage(*image,geometry_info.rho,exception);
1930 if (implode_image == (Image *) NULL)
1931 break;
1932 *image=DestroyImage(*image);
1933 *image=implode_image;
1934 break;
1935 }
cristyb32b90a2009-09-07 21:45:48 +00001936 if (LocaleCompare("interline-spacing",option+1) == 0)
1937 {
1938 if (*option == '+')
1939 (void) ParseGeometry("0",&geometry_info);
1940 else
1941 (void) ParseGeometry(argv[i+1],&geometry_info);
1942 draw_info->interline_spacing=geometry_info.rho;
1943 break;
1944 }
cristy3ed852e2009-09-05 21:47:34 +00001945 if (LocaleCompare("interword-spacing",option+1) == 0)
1946 {
1947 if (*option == '+')
1948 (void) ParseGeometry("0",&geometry_info);
1949 else
1950 (void) ParseGeometry(argv[i+1],&geometry_info);
1951 draw_info->interword_spacing=geometry_info.rho;
1952 break;
1953 }
1954 break;
1955 }
1956 case 'k':
1957 {
1958 if (LocaleCompare("kerning",option+1) == 0)
1959 {
1960 if (*option == '+')
1961 (void) ParseGeometry("0",&geometry_info);
1962 else
1963 (void) ParseGeometry(argv[i+1],&geometry_info);
1964 draw_info->kerning=geometry_info.rho;
1965 break;
1966 }
1967 break;
1968 }
1969 case 'l':
1970 {
1971 if (LocaleCompare("lat",option+1) == 0)
1972 {
1973 Image
1974 *threshold_image;
1975
1976 /*
1977 Local adaptive threshold image.
1978 */
cristy6b3da3a2010-06-20 02:21:46 +00001979 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001980 flags=ParseGeometry(argv[i+1],&geometry_info);
1981 if ((flags & PercentValue) != 0)
1982 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
cristybb503372010-05-27 20:51:26 +00001983 threshold_image=AdaptiveThresholdImage(*image,(size_t)
1984 geometry_info.rho,(size_t) geometry_info.sigma,
1985 (ssize_t) geometry_info.xi,exception);
cristy3ed852e2009-09-05 21:47:34 +00001986 if (threshold_image == (Image *) NULL)
1987 break;
1988 *image=DestroyImage(*image);
1989 *image=threshold_image;
1990 break;
1991 }
1992 if (LocaleCompare("level",option+1) == 0)
1993 {
cristy3ed852e2009-09-05 21:47:34 +00001994 MagickRealType
1995 black_point,
1996 gamma,
1997 white_point;
1998
1999 MagickStatusType
2000 flags;
2001
2002 /*
2003 Parse levels.
2004 */
cristy6b3da3a2010-06-20 02:21:46 +00002005 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002006 flags=ParseGeometry(argv[i+1],&geometry_info);
2007 black_point=geometry_info.rho;
2008 white_point=(MagickRealType) QuantumRange;
2009 if ((flags & SigmaValue) != 0)
2010 white_point=geometry_info.sigma;
2011 gamma=1.0;
2012 if ((flags & XiValue) != 0)
2013 gamma=geometry_info.xi;
2014 if ((flags & PercentValue) != 0)
2015 {
2016 black_point*=(MagickRealType) (QuantumRange/100.0);
2017 white_point*=(MagickRealType) (QuantumRange/100.0);
2018 }
2019 if ((flags & SigmaValue) == 0)
2020 white_point=(MagickRealType) QuantumRange-black_point;
2021 if ((*option == '+') || ((flags & AspectValue) != 0))
2022 (void) LevelizeImageChannel(*image,channel,black_point,
2023 white_point,gamma);
2024 else
2025 (void) LevelImageChannel(*image,channel,black_point,white_point,
2026 gamma);
2027 InheritException(exception,&(*image)->exception);
2028 break;
2029 }
2030 if (LocaleCompare("level-colors",option+1) == 0)
2031 {
2032 char
2033 token[MaxTextExtent];
2034
2035 const char
2036 *p;
2037
2038 MagickPixelPacket
2039 black_point,
2040 white_point;
2041
2042 p=(const char *) argv[i+1];
2043 GetMagickToken(p,&p,token); /* get black point color */
cristyee0f8d72009-09-19 00:58:29 +00002044 if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
cristy3ed852e2009-09-05 21:47:34 +00002045 (void) QueryMagickColor(token,&black_point,exception);
2046 else
cristyee0f8d72009-09-19 00:58:29 +00002047 (void) QueryMagickColor("#000000",&black_point,exception);
cristy3ed852e2009-09-05 21:47:34 +00002048 if (isalpha((int) token[0]) || (token[0] == '#'))
2049 GetMagickToken(p,&p,token);
cristyee0f8d72009-09-19 00:58:29 +00002050 if (*token == '\0')
cristy3ed852e2009-09-05 21:47:34 +00002051 white_point=black_point; /* set everything to that color */
2052 else
2053 {
2054 /*
2055 Get white point color.
2056 */
cristyee0f8d72009-09-19 00:58:29 +00002057 if ((isalpha((int) *token) == 0) && ((*token == '#') == 0))
cristy3ed852e2009-09-05 21:47:34 +00002058 GetMagickToken(p,&p,token);
cristyee0f8d72009-09-19 00:58:29 +00002059 if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
cristy3ed852e2009-09-05 21:47:34 +00002060 (void) QueryMagickColor(token,&white_point,exception);
2061 else
cristyee0f8d72009-09-19 00:58:29 +00002062 (void) QueryMagickColor("#ffffff",&white_point,exception);
cristy3ed852e2009-09-05 21:47:34 +00002063 }
cristy74fe8f12009-10-03 19:09:01 +00002064 (void) LevelColorsImageChannel(*image,channel,&black_point,
2065 &white_point,*option == '+' ? MagickTrue : MagickFalse);
cristy3ed852e2009-09-05 21:47:34 +00002066 break;
2067 }
2068 if (LocaleCompare("linear-stretch",option+1) == 0)
2069 {
2070 double
2071 black_point,
2072 white_point;
2073
cristy3ed852e2009-09-05 21:47:34 +00002074 MagickStatusType
2075 flags;
2076
cristy6b3da3a2010-06-20 02:21:46 +00002077 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002078 flags=ParseGeometry(argv[i+1],&geometry_info);
2079 black_point=geometry_info.rho;
2080 white_point=(MagickRealType) (*image)->columns*(*image)->rows;
2081 if ((flags & SigmaValue) != 0)
2082 white_point=geometry_info.sigma;
2083 if ((flags & PercentValue) != 0)
2084 {
2085 black_point*=(double) (*image)->columns*(*image)->rows/100.0;
2086 white_point*=(double) (*image)->columns*(*image)->rows/100.0;
2087 }
2088 if ((flags & SigmaValue) == 0)
2089 white_point=(MagickRealType) (*image)->columns*(*image)->rows-
2090 black_point;
2091 (void) LinearStretchImage(*image,black_point,white_point);
2092 InheritException(exception,&(*image)->exception);
2093 break;
2094 }
2095 if (LocaleCompare("linewidth",option+1) == 0)
2096 {
cristyf2f27272009-12-17 14:48:46 +00002097 draw_info->stroke_width=StringToDouble(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00002098 break;
2099 }
2100 if (LocaleCompare("liquid-rescale",option+1) == 0)
2101 {
2102 Image
2103 *resize_image;
2104
2105 /*
2106 Liquid rescale image.
2107 */
cristy6b3da3a2010-06-20 02:21:46 +00002108 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002109 flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2110 if ((flags & XValue) == 0)
2111 geometry.x=1;
2112 if ((flags & YValue) == 0)
2113 geometry.y=0;
2114 resize_image=LiquidRescaleImage(*image,geometry.width,
2115 geometry.height,1.0*geometry.x,1.0*geometry.y,exception);
2116 if (resize_image == (Image *) NULL)
2117 break;
2118 *image=DestroyImage(*image);
2119 *image=resize_image;
2120 break;
2121 }
2122 if (LocaleCompare("lowlight-color",option+1) == 0)
2123 {
2124 (void) SetImageArtifact(*image,option+1,argv[i+1]);
2125 break;
2126 }
2127 break;
2128 }
2129 case 'm':
2130 {
2131 if (LocaleCompare("map",option+1) == 0)
2132 {
2133 Image
2134 *remap_image;
2135
2136 /*
2137 Transform image colors to match this set of colors.
2138 */
cristy6b3da3a2010-06-20 02:21:46 +00002139 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002140 if (*option == '+')
2141 break;
cristy6b3da3a2010-06-20 02:21:46 +00002142 remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
cristy3ed852e2009-09-05 21:47:34 +00002143 if (remap_image == (Image *) NULL)
2144 break;
2145 (void) RemapImage(quantize_info,*image,remap_image);
2146 InheritException(exception,&(*image)->exception);
2147 remap_image=DestroyImage(remap_image);
2148 break;
2149 }
2150 if (LocaleCompare("mask",option+1) == 0)
2151 {
2152 Image
2153 *mask;
2154
cristy6b3da3a2010-06-20 02:21:46 +00002155 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002156 if (*option == '+')
2157 {
2158 /*
2159 Remove a mask.
2160 */
2161 (void) SetImageMask(*image,(Image *) NULL);
2162 InheritException(exception,&(*image)->exception);
2163 break;
2164 }
2165 /*
2166 Set the image mask.
2167 */
cristy6b3da3a2010-06-20 02:21:46 +00002168 mask=GetImageCache(mogrify_info,argv[i+1],exception);
cristy3ed852e2009-09-05 21:47:34 +00002169 if (mask == (Image *) NULL)
2170 break;
2171 (void) SetImageMask(*image,mask);
2172 mask=DestroyImage(mask);
2173 InheritException(exception,&(*image)->exception);
2174 break;
2175 }
2176 if (LocaleCompare("matte",option+1) == 0)
2177 {
2178 (void) SetImageAlphaChannel(*image,(*option == '-') ?
2179 SetAlphaChannel : DeactivateAlphaChannel );
2180 InheritException(exception,&(*image)->exception);
2181 break;
2182 }
2183 if (LocaleCompare("median",option+1) == 0)
2184 {
2185 Image
2186 *median_image;
2187
2188 /*
2189 Median filter image.
2190 */
cristy6b3da3a2010-06-20 02:21:46 +00002191 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002192 (void) ParseGeometry(argv[i+1],&geometry_info);
2193 median_image=MedianFilterImage(*image,geometry_info.rho,exception);
2194 if (median_image == (Image *) NULL)
2195 break;
2196 *image=DestroyImage(*image);
2197 *image=median_image;
2198 break;
2199 }
cristy69ec32d2011-02-27 23:57:09 +00002200 if (LocaleCompare("mode",option+1) == 0)
2201 {
2202 Image
2203 *mode_image;
2204
2205 /*
2206 Mode image.
2207 */
2208 (void) SyncImageSettings(mogrify_info,*image);
2209 (void) ParseGeometry(argv[i+1],&geometry_info);
2210 mode_image=ModeImage(*image,geometry_info.rho,exception);
2211 if (mode_image == (Image *) NULL)
2212 break;
2213 *image=DestroyImage(*image);
2214 *image=mode_image;
2215 break;
2216 }
cristy3ed852e2009-09-05 21:47:34 +00002217 if (LocaleCompare("modulate",option+1) == 0)
2218 {
cristy6b3da3a2010-06-20 02:21:46 +00002219 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002220 (void) ModulateImage(*image,argv[i+1]);
2221 InheritException(exception,&(*image)->exception);
2222 break;
2223 }
2224 if (LocaleCompare("monitor",option+1) == 0)
2225 {
cristy7d34ef22010-03-25 01:11:22 +00002226 if (*option == '+')
2227 {
2228 (void) SetImageProgressMonitor(*image,
2229 (MagickProgressMonitor) NULL,(void *) NULL);
2230 break;
2231 }
cristy3ed852e2009-09-05 21:47:34 +00002232 (void) SetImageProgressMonitor(*image,MonitorProgress,
2233 (void *) NULL);
2234 break;
2235 }
2236 if (LocaleCompare("monochrome",option+1) == 0)
2237 {
cristy6b3da3a2010-06-20 02:21:46 +00002238 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002239 (void) SetImageType(*image,BilevelType);
2240 InheritException(exception,&(*image)->exception);
2241 break;
2242 }
anthony29188a82010-01-22 10:12:34 +00002243 if (LocaleCompare("morphology",option+1) == 0)
2244 {
anthony29188a82010-01-22 10:12:34 +00002245 char
2246 token[MaxTextExtent];
2247
2248 const char
2249 *p;
2250
cristye96405a2010-05-19 02:24:31 +00002251 Image
2252 *morphology_image;
2253
2254 KernelInfo
2255 *kernel;
2256
cristye96405a2010-05-19 02:24:31 +00002257 MorphologyMethod
2258 method;
2259
cristy9d314ff2011-03-09 01:30:28 +00002260 ssize_t
2261 iterations;
2262
anthony29188a82010-01-22 10:12:34 +00002263 /*
2264 Morphological Image Operation
2265 */
cristy6b3da3a2010-06-20 02:21:46 +00002266 (void) SyncImageSettings(mogrify_info,*image);
anthony29188a82010-01-22 10:12:34 +00002267 p=argv[i+1];
2268 GetMagickToken(p,&p,token);
2269 method=(MorphologyMethod) ParseMagickOption(MagickMorphologyOptions,
cristyd2c1e1e2010-05-08 01:05:44 +00002270 MagickFalse,token);
cristyef656912010-03-05 19:54:59 +00002271 iterations=1L;
anthony29188a82010-01-22 10:12:34 +00002272 GetMagickToken(p,&p,token);
cristyef656912010-03-05 19:54:59 +00002273 if ((*p == ':') || (*p == ','))
anthony29188a82010-01-22 10:12:34 +00002274 GetMagickToken(p,&p,token);
cristyef656912010-03-05 19:54:59 +00002275 if ((*p != '\0'))
cristy32c2aea2010-12-01 01:00:50 +00002276 iterations=(ssize_t) StringToLong(p);
anthony29188a82010-01-22 10:12:34 +00002277 kernel=AcquireKernelInfo(argv[i+2]);
2278 if (kernel == (KernelInfo *) NULL)
cristye96405a2010-05-19 02:24:31 +00002279 {
2280 (void) ThrowMagickException(exception,GetMagickModule(),
2281 OptionError,"UnabletoParseKernel","morphology");
2282 status=MagickFalse;
2283 break;
2284 }
anthony29188a82010-01-22 10:12:34 +00002285 morphology_image=MorphologyImageChannel(*image,channel,method,
cristy02d5b4f2010-02-01 01:08:27 +00002286 iterations,kernel,exception);
anthony83ba99b2010-01-24 08:48:15 +00002287 kernel=DestroyKernelInfo(kernel);
anthony29188a82010-01-22 10:12:34 +00002288 if (morphology_image == (Image *) NULL)
2289 break;
2290 *image=DestroyImage(*image);
2291 *image=morphology_image;
2292 break;
2293 }
cristy3ed852e2009-09-05 21:47:34 +00002294 if (LocaleCompare("motion-blur",option+1) == 0)
2295 {
2296 Image
2297 *blur_image;
2298
2299 /*
2300 Motion blur image.
2301 */
cristy6b3da3a2010-06-20 02:21:46 +00002302 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002303 flags=ParseGeometry(argv[i+1],&geometry_info);
2304 if ((flags & SigmaValue) == 0)
2305 geometry_info.sigma=1.0;
2306 blur_image=MotionBlurImageChannel(*image,channel,geometry_info.rho,
2307 geometry_info.sigma,geometry_info.xi,exception);
2308 if (blur_image == (Image *) NULL)
2309 break;
2310 *image=DestroyImage(*image);
2311 *image=blur_image;
2312 break;
2313 }
2314 break;
2315 }
2316 case 'n':
2317 {
2318 if (LocaleCompare("negate",option+1) == 0)
2319 {
cristy6b3da3a2010-06-20 02:21:46 +00002320 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002321 (void) NegateImageChannel(*image,channel,*option == '+' ?
2322 MagickTrue : MagickFalse);
2323 InheritException(exception,&(*image)->exception);
2324 break;
2325 }
2326 if (LocaleCompare("noise",option+1) == 0)
2327 {
2328 Image
2329 *noisy_image;
2330
cristy6b3da3a2010-06-20 02:21:46 +00002331 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002332 if (*option == '-')
2333 {
2334 (void) ParseGeometry(argv[i+1],&geometry_info);
2335 noisy_image=ReduceNoiseImage(*image,geometry_info.rho,
2336 exception);
2337 }
2338 else
2339 {
2340 NoiseType
2341 noise;
2342
2343 noise=(NoiseType) ParseMagickOption(MagickNoiseOptions,
2344 MagickFalse,argv[i+1]);
2345 noisy_image=AddNoiseImageChannel(*image,channel,noise,
2346 exception);
2347 }
2348 if (noisy_image == (Image *) NULL)
2349 break;
2350 *image=DestroyImage(*image);
2351 *image=noisy_image;
2352 break;
2353 }
2354 if (LocaleCompare("normalize",option+1) == 0)
2355 {
cristy6b3da3a2010-06-20 02:21:46 +00002356 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002357 (void) NormalizeImageChannel(*image,channel);
2358 InheritException(exception,&(*image)->exception);
2359 break;
2360 }
2361 break;
2362 }
2363 case 'o':
2364 {
2365 if (LocaleCompare("opaque",option+1) == 0)
2366 {
2367 MagickPixelPacket
2368 target;
2369
cristy6b3da3a2010-06-20 02:21:46 +00002370 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002371 (void) QueryMagickColor(argv[i+1],&target,exception);
2372 (void) OpaquePaintImageChannel(*image,channel,&target,&fill,
2373 *option == '-' ? MagickFalse : MagickTrue);
2374 break;
2375 }
2376 if (LocaleCompare("ordered-dither",option+1) == 0)
2377 {
cristy6b3da3a2010-06-20 02:21:46 +00002378 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002379 (void) OrderedPosterizeImageChannel(*image,channel,argv[i+1],
2380 exception);
2381 break;
2382 }
2383 break;
2384 }
2385 case 'p':
2386 {
2387 if (LocaleCompare("paint",option+1) == 0)
2388 {
2389 Image
2390 *paint_image;
2391
2392 /*
2393 Oil paint image.
2394 */
cristy6b3da3a2010-06-20 02:21:46 +00002395 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002396 (void) ParseGeometry(argv[i+1],&geometry_info);
2397 paint_image=OilPaintImage(*image,geometry_info.rho,exception);
2398 if (paint_image == (Image *) NULL)
2399 break;
2400 *image=DestroyImage(*image);
2401 *image=paint_image;
2402 break;
2403 }
2404 if (LocaleCompare("pen",option+1) == 0)
2405 {
2406 if (*option == '+')
2407 {
2408 (void) QueryColorDatabase("none",&draw_info->fill,exception);
2409 break;
2410 }
2411 (void) QueryColorDatabase(argv[i+1],&draw_info->fill,exception);
2412 break;
2413 }
2414 if (LocaleCompare("pointsize",option+1) == 0)
2415 {
2416 if (*option == '+')
2417 (void) ParseGeometry("12",&geometry_info);
2418 else
2419 (void) ParseGeometry(argv[i+1],&geometry_info);
2420 draw_info->pointsize=geometry_info.rho;
2421 break;
2422 }
2423 if (LocaleCompare("polaroid",option+1) == 0)
2424 {
2425 double
2426 angle;
2427
2428 Image
2429 *polaroid_image;
2430
2431 RandomInfo
2432 *random_info;
2433
2434 /*
2435 Simulate a Polaroid picture.
2436 */
cristy6b3da3a2010-06-20 02:21:46 +00002437 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002438 random_info=AcquireRandomInfo();
2439 angle=22.5*(GetPseudoRandomValue(random_info)-0.5);
2440 random_info=DestroyRandomInfo(random_info);
2441 if (*option == '-')
2442 {
2443 SetGeometryInfo(&geometry_info);
2444 flags=ParseGeometry(argv[i+1],&geometry_info);
2445 angle=geometry_info.rho;
2446 }
2447 polaroid_image=PolaroidImage(*image,draw_info,angle,exception);
2448 if (polaroid_image == (Image *) NULL)
2449 break;
2450 *image=DestroyImage(*image);
2451 *image=polaroid_image;
2452 break;
2453 }
2454 if (LocaleCompare("posterize",option+1) == 0)
2455 {
2456 /*
2457 Posterize image.
2458 */
cristy6b3da3a2010-06-20 02:21:46 +00002459 (void) SyncImageSettings(mogrify_info,*image);
cristye27293e2009-12-18 02:53:20 +00002460 (void) PosterizeImage(*image,StringToUnsignedLong(argv[i+1]),
cristy3ed852e2009-09-05 21:47:34 +00002461 quantize_info->dither);
2462 InheritException(exception,&(*image)->exception);
2463 break;
2464 }
2465 if (LocaleCompare("preview",option+1) == 0)
2466 {
2467 Image
2468 *preview_image;
2469
2470 PreviewType
2471 preview_type;
2472
2473 /*
2474 Preview image.
2475 */
cristy6b3da3a2010-06-20 02:21:46 +00002476 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002477 if (*option == '+')
2478 preview_type=UndefinedPreview;
2479 else
2480 preview_type=(PreviewType) ParseMagickOption(MagickPreviewOptions,
2481 MagickFalse,argv[i+1]);
2482 preview_image=PreviewImage(*image,preview_type,exception);
2483 if (preview_image == (Image *) NULL)
2484 break;
2485 *image=DestroyImage(*image);
2486 *image=preview_image;
2487 break;
2488 }
2489 if (LocaleCompare("profile",option+1) == 0)
2490 {
2491 const char
2492 *name;
2493
2494 const StringInfo
2495 *profile;
2496
2497 Image
2498 *profile_image;
2499
2500 ImageInfo
2501 *profile_info;
2502
cristy6b3da3a2010-06-20 02:21:46 +00002503 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002504 if (*option == '+')
2505 {
2506 /*
2507 Remove a profile from the image.
2508 */
2509 (void) ProfileImage(*image,argv[i+1],(const unsigned char *)
2510 NULL,0,MagickTrue);
2511 InheritException(exception,&(*image)->exception);
2512 break;
2513 }
2514 /*
2515 Associate a profile with the image.
2516 */
cristy6b3da3a2010-06-20 02:21:46 +00002517 profile_info=CloneImageInfo(mogrify_info);
cristy3ed852e2009-09-05 21:47:34 +00002518 profile=GetImageProfile(*image,"iptc");
2519 if (profile != (StringInfo *) NULL)
2520 profile_info->profile=(void *) CloneStringInfo(profile);
2521 profile_image=GetImageCache(profile_info,argv[i+1],exception);
2522 profile_info=DestroyImageInfo(profile_info);
2523 if (profile_image == (Image *) NULL)
2524 {
cristy3ed852e2009-09-05 21:47:34 +00002525 StringInfo
2526 *profile;
2527
cristy6b3da3a2010-06-20 02:21:46 +00002528 profile_info=CloneImageInfo(mogrify_info);
cristy071dd7b2010-04-09 13:04:54 +00002529 (void) CopyMagickString(profile_info->filename,argv[i+1],
2530 MaxTextExtent);
2531 profile=FileToStringInfo(profile_info->filename,~0UL,exception);
cristy3ed852e2009-09-05 21:47:34 +00002532 if (profile != (StringInfo *) NULL)
2533 {
cristy071dd7b2010-04-09 13:04:54 +00002534 (void) ProfileImage(*image,profile_info->magick,
cristybb503372010-05-27 20:51:26 +00002535 GetStringInfoDatum(profile),(size_t)
cristy071dd7b2010-04-09 13:04:54 +00002536 GetStringInfoLength(profile),MagickFalse);
cristy3ed852e2009-09-05 21:47:34 +00002537 profile=DestroyStringInfo(profile);
2538 }
cristy071dd7b2010-04-09 13:04:54 +00002539 profile_info=DestroyImageInfo(profile_info);
cristy3ed852e2009-09-05 21:47:34 +00002540 break;
2541 }
2542 ResetImageProfileIterator(profile_image);
2543 name=GetNextImageProfile(profile_image);
2544 while (name != (const char *) NULL)
2545 {
2546 profile=GetImageProfile(profile_image,name);
2547 if (profile != (StringInfo *) NULL)
2548 (void) ProfileImage(*image,name,GetStringInfoDatum(profile),
cristybb503372010-05-27 20:51:26 +00002549 (size_t) GetStringInfoLength(profile),MagickFalse);
cristy3ed852e2009-09-05 21:47:34 +00002550 name=GetNextImageProfile(profile_image);
2551 }
2552 profile_image=DestroyImage(profile_image);
2553 break;
2554 }
2555 break;
2556 }
2557 case 'q':
2558 {
2559 if (LocaleCompare("quantize",option+1) == 0)
2560 {
2561 if (*option == '+')
2562 {
2563 quantize_info->colorspace=UndefinedColorspace;
2564 break;
2565 }
2566 quantize_info->colorspace=(ColorspaceType) ParseMagickOption(
2567 MagickColorspaceOptions,MagickFalse,argv[i+1]);
2568 break;
2569 }
2570 break;
2571 }
2572 case 'r':
2573 {
2574 if (LocaleCompare("radial-blur",option+1) == 0)
2575 {
2576 Image
2577 *blur_image;
2578
2579 /*
2580 Radial blur image.
2581 */
cristy6b3da3a2010-06-20 02:21:46 +00002582 (void) SyncImageSettings(mogrify_info,*image);
cristya5447be2010-01-11 00:20:51 +00002583 blur_image=RadialBlurImageChannel(*image,channel,
2584 StringToDouble(argv[i+1]),exception);
cristy3ed852e2009-09-05 21:47:34 +00002585 if (blur_image == (Image *) NULL)
2586 break;
2587 *image=DestroyImage(*image);
2588 *image=blur_image;
2589 break;
2590 }
2591 if (LocaleCompare("raise",option+1) == 0)
2592 {
2593 /*
2594 Surround image with a raise of solid color.
2595 */
2596 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2597 if ((flags & SigmaValue) == 0)
2598 geometry.height=geometry.width;
2599 (void) RaiseImage(*image,&geometry,*option == '-' ? MagickTrue :
2600 MagickFalse);
2601 InheritException(exception,&(*image)->exception);
2602 break;
2603 }
2604 if (LocaleCompare("random-threshold",option+1) == 0)
2605 {
2606 /*
2607 Threshold image.
2608 */
cristy6b3da3a2010-06-20 02:21:46 +00002609 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002610 (void) RandomThresholdImageChannel(*image,channel,argv[i+1],
2611 exception);
2612 break;
2613 }
2614 if (LocaleCompare("recolor",option+1) == 0)
2615 {
cristy3ed852e2009-09-05 21:47:34 +00002616 Image
cristyf055ae42010-04-02 23:01:38 +00002617 *color_image;
cristy3ed852e2009-09-05 21:47:34 +00002618
cristyf055ae42010-04-02 23:01:38 +00002619 KernelInfo
2620 *kernel;
cristy3ed852e2009-09-05 21:47:34 +00002621
cristy6b3da3a2010-06-20 02:21:46 +00002622 (void) SyncImageSettings(mogrify_info,*image);
cristyf055ae42010-04-02 23:01:38 +00002623 kernel=AcquireKernelInfo(argv[i+1]);
2624 if (kernel == (KernelInfo *) NULL)
2625 break;
2626 color_image=ColorMatrixImage(*image,kernel,exception);
2627 kernel=DestroyKernelInfo(kernel);
2628 if (color_image == (Image *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002629 break;
2630 *image=DestroyImage(*image);
cristyf055ae42010-04-02 23:01:38 +00002631 *image=color_image;
cristy3ed852e2009-09-05 21:47:34 +00002632 break;
2633 }
2634 if (LocaleCompare("region",option+1) == 0)
2635 {
2636 Image
2637 *crop_image;
2638
cristy6b3da3a2010-06-20 02:21:46 +00002639 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002640 if (region_image != (Image *) NULL)
2641 {
2642 /*
2643 Composite region.
2644 */
2645 (void) CompositeImage(region_image,(*image)->matte !=
2646 MagickFalse ? OverCompositeOp : CopyCompositeOp,*image,
2647 region_geometry.x,region_geometry.y);
2648 InheritException(exception,&region_image->exception);
2649 *image=DestroyImage(*image);
2650 *image=region_image;
2651 }
2652 if (*option == '+')
2653 {
2654 if (region_image != (Image *) NULL)
cristyb0a6e432010-10-09 13:26:15 +00002655 region_image=(Image *) NULL;
cristy3ed852e2009-09-05 21:47:34 +00002656 break;
2657 }
2658 /*
2659 Apply transformations to a selected region of the image.
2660 */
2661 (void) ParseGravityGeometry(*image,argv[i+1],&region_geometry,
2662 exception);
2663 crop_image=CropImage(*image,&region_geometry,exception);
2664 if (crop_image == (Image *) NULL)
2665 break;
2666 region_image=(*image);
2667 *image=crop_image;
2668 break;
2669 }
2670 if (LocaleCompare("render",option+1) == 0)
2671 {
cristy6b3da3a2010-06-20 02:21:46 +00002672 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002673 draw_info->render=(*option == '+') ? MagickTrue : MagickFalse;
2674 break;
2675 }
2676 if (LocaleCompare("remap",option+1) == 0)
2677 {
2678 Image
2679 *remap_image;
2680
2681 /*
2682 Transform image colors to match this set of colors.
2683 */
cristy6b3da3a2010-06-20 02:21:46 +00002684 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002685 if (*option == '+')
2686 break;
cristy6b3da3a2010-06-20 02:21:46 +00002687 remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
cristy3ed852e2009-09-05 21:47:34 +00002688 if (remap_image == (Image *) NULL)
2689 break;
2690 (void) RemapImage(quantize_info,*image,remap_image);
2691 InheritException(exception,&(*image)->exception);
2692 remap_image=DestroyImage(remap_image);
2693 break;
2694 }
2695 if (LocaleCompare("repage",option+1) == 0)
2696 {
2697 if (*option == '+')
2698 {
2699 (void) ParseAbsoluteGeometry("0x0+0+0",&(*image)->page);
2700 break;
2701 }
2702 (void) ResetImagePage(*image,argv[i+1]);
2703 InheritException(exception,&(*image)->exception);
2704 break;
2705 }
2706 if (LocaleCompare("resample",option+1) == 0)
2707 {
2708 Image
2709 *resample_image;
2710
2711 /*
2712 Resample image.
2713 */
cristy6b3da3a2010-06-20 02:21:46 +00002714 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002715 flags=ParseGeometry(argv[i+1],&geometry_info);
2716 if ((flags & SigmaValue) == 0)
2717 geometry_info.sigma=geometry_info.rho;
2718 resample_image=ResampleImage(*image,geometry_info.rho,
2719 geometry_info.sigma,(*image)->filter,(*image)->blur,exception);
2720 if (resample_image == (Image *) NULL)
2721 break;
2722 *image=DestroyImage(*image);
2723 *image=resample_image;
2724 break;
2725 }
2726 if (LocaleCompare("resize",option+1) == 0)
2727 {
2728 Image
2729 *resize_image;
2730
2731 /*
2732 Resize image.
2733 */
cristy6b3da3a2010-06-20 02:21:46 +00002734 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002735 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2736 resize_image=ResizeImage(*image,geometry.width,geometry.height,
2737 (*image)->filter,(*image)->blur,exception);
2738 if (resize_image == (Image *) NULL)
2739 break;
2740 *image=DestroyImage(*image);
2741 *image=resize_image;
2742 break;
2743 }
cristy3ed852e2009-09-05 21:47:34 +00002744 if (LocaleCompare("roll",option+1) == 0)
2745 {
2746 Image
2747 *roll_image;
2748
2749 /*
2750 Roll image.
2751 */
cristy6b3da3a2010-06-20 02:21:46 +00002752 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002753 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2754 roll_image=RollImage(*image,geometry.x,geometry.y,exception);
2755 if (roll_image == (Image *) NULL)
2756 break;
2757 *image=DestroyImage(*image);
2758 *image=roll_image;
2759 break;
2760 }
2761 if (LocaleCompare("rotate",option+1) == 0)
2762 {
2763 char
2764 *geometry;
2765
2766 Image
2767 *rotate_image;
2768
2769 /*
2770 Check for conditional image rotation.
2771 */
cristy6b3da3a2010-06-20 02:21:46 +00002772 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002773 if (strchr(argv[i+1],'>') != (char *) NULL)
2774 if ((*image)->columns <= (*image)->rows)
2775 break;
2776 if (strchr(argv[i+1],'<') != (char *) NULL)
2777 if ((*image)->columns >= (*image)->rows)
2778 break;
2779 /*
2780 Rotate image.
2781 */
2782 geometry=ConstantString(argv[i+1]);
2783 (void) SubstituteString(&geometry,">","");
2784 (void) SubstituteString(&geometry,"<","");
2785 (void) ParseGeometry(geometry,&geometry_info);
2786 geometry=DestroyString(geometry);
2787 rotate_image=RotateImage(*image,geometry_info.rho,exception);
2788 if (rotate_image == (Image *) NULL)
2789 break;
2790 *image=DestroyImage(*image);
2791 *image=rotate_image;
2792 break;
2793 }
2794 break;
2795 }
2796 case 's':
2797 {
2798 if (LocaleCompare("sample",option+1) == 0)
2799 {
2800 Image
2801 *sample_image;
2802
2803 /*
2804 Sample image with pixel replication.
2805 */
cristy6b3da3a2010-06-20 02:21:46 +00002806 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002807 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2808 sample_image=SampleImage(*image,geometry.width,geometry.height,
2809 exception);
2810 if (sample_image == (Image *) NULL)
2811 break;
2812 *image=DestroyImage(*image);
2813 *image=sample_image;
2814 break;
2815 }
2816 if (LocaleCompare("scale",option+1) == 0)
2817 {
2818 Image
2819 *scale_image;
2820
2821 /*
2822 Resize image.
2823 */
cristy6b3da3a2010-06-20 02:21:46 +00002824 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002825 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2826 scale_image=ScaleImage(*image,geometry.width,geometry.height,
2827 exception);
2828 if (scale_image == (Image *) NULL)
2829 break;
2830 *image=DestroyImage(*image);
2831 *image=scale_image;
2832 break;
2833 }
2834 if (LocaleCompare("selective-blur",option+1) == 0)
2835 {
2836 Image
2837 *blur_image;
2838
2839 /*
2840 Selectively blur pixels within a contrast threshold.
2841 */
cristy6b3da3a2010-06-20 02:21:46 +00002842 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002843 flags=ParseGeometry(argv[i+1],&geometry_info);
2844 if ((flags & PercentValue) != 0)
2845 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
2846 blur_image=SelectiveBlurImageChannel(*image,channel,
2847 geometry_info.rho,geometry_info.sigma,geometry_info.xi,exception);
2848 if (blur_image == (Image *) NULL)
2849 break;
2850 *image=DestroyImage(*image);
2851 *image=blur_image;
2852 break;
2853 }
2854 if (LocaleCompare("separate",option+1) == 0)
2855 {
2856 Image
2857 *separate_images;
2858
2859 /*
2860 Break channels into separate images.
2861 */
cristy6b3da3a2010-06-20 02:21:46 +00002862 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002863 separate_images=SeparateImages(*image,channel,exception);
2864 if (separate_images == (Image *) NULL)
2865 break;
2866 *image=DestroyImage(*image);
2867 *image=separate_images;
2868 break;
2869 }
2870 if (LocaleCompare("sepia-tone",option+1) == 0)
2871 {
2872 double
2873 threshold;
2874
2875 Image
2876 *sepia_image;
2877
2878 /*
2879 Sepia-tone image.
2880 */
cristy6b3da3a2010-06-20 02:21:46 +00002881 (void) SyncImageSettings(mogrify_info,*image);
cristyf2f27272009-12-17 14:48:46 +00002882 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
cristy3ed852e2009-09-05 21:47:34 +00002883 sepia_image=SepiaToneImage(*image,threshold,exception);
2884 if (sepia_image == (Image *) NULL)
2885 break;
2886 *image=DestroyImage(*image);
2887 *image=sepia_image;
2888 break;
2889 }
2890 if (LocaleCompare("segment",option+1) == 0)
2891 {
2892 /*
2893 Segment image.
2894 */
cristy6b3da3a2010-06-20 02:21:46 +00002895 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002896 flags=ParseGeometry(argv[i+1],&geometry_info);
2897 if ((flags & SigmaValue) == 0)
2898 geometry_info.sigma=1.0;
cristy7e6164a2010-07-22 20:43:57 +00002899 (void) SegmentImage(*image,(*image)->colorspace,
2900 mogrify_info->verbose,geometry_info.rho,geometry_info.sigma);
cristy3ed852e2009-09-05 21:47:34 +00002901 InheritException(exception,&(*image)->exception);
2902 break;
2903 }
2904 if (LocaleCompare("set",option+1) == 0)
2905 {
cristy6d9a1292010-05-31 14:17:06 +00002906 char
2907 *value;
2908
cristy3ed852e2009-09-05 21:47:34 +00002909 /*
2910 Set image option.
2911 */
cristy6d9a1292010-05-31 14:17:06 +00002912 if (*option == '+')
2913 {
2914 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2915 (void) DeleteImageRegistry(argv[i+1]+9);
2916 else
2917 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
cristy7e109582010-06-01 12:56:44 +00002918 {
cristy6b3da3a2010-06-20 02:21:46 +00002919 (void) DeleteImageOption(mogrify_info,argv[i+1]+7);
cristy7e109582010-06-01 12:56:44 +00002920 (void) DeleteImageArtifact(*image,argv[i+1]+7);
2921 }
cristy6d9a1292010-05-31 14:17:06 +00002922 else
2923 (void) DeleteImageProperty(*image,argv[i+1]);
2924 break;
2925 }
cristy6b3da3a2010-06-20 02:21:46 +00002926 value=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
cristy6d9a1292010-05-31 14:17:06 +00002927 if (value == (char *) NULL)
2928 break;
cristy3ed852e2009-09-05 21:47:34 +00002929 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
cristy6d9a1292010-05-31 14:17:06 +00002930 (void) SetImageRegistry(StringRegistryType,argv[i+1]+9,value,
2931 exception);
cristy3ed852e2009-09-05 21:47:34 +00002932 else
2933 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
cristy6d9a1292010-05-31 14:17:06 +00002934 {
cristy7f02ba12010-09-21 12:39:28 +00002935 (void) SetImageOption(image_info,argv[i+1]+7,value);
cristy6b3da3a2010-06-20 02:21:46 +00002936 (void) SetImageOption(mogrify_info,argv[i+1]+7,value);
cristy6d9a1292010-05-31 14:17:06 +00002937 (void) SetImageArtifact(*image,argv[i+1]+7,value);
2938 }
cristy3ed852e2009-09-05 21:47:34 +00002939 else
cristy6d9a1292010-05-31 14:17:06 +00002940 (void) SetImageProperty(*image,argv[i+1],value);
2941 value=DestroyString(value);
cristy3ed852e2009-09-05 21:47:34 +00002942 break;
2943 }
2944 if (LocaleCompare("shade",option+1) == 0)
2945 {
2946 Image
2947 *shade_image;
2948
2949 /*
2950 Shade image.
2951 */
cristy6b3da3a2010-06-20 02:21:46 +00002952 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002953 flags=ParseGeometry(argv[i+1],&geometry_info);
2954 if ((flags & SigmaValue) == 0)
2955 geometry_info.sigma=1.0;
2956 shade_image=ShadeImage(*image,(*option == '-') ? MagickTrue :
2957 MagickFalse,geometry_info.rho,geometry_info.sigma,exception);
2958 if (shade_image == (Image *) NULL)
2959 break;
2960 *image=DestroyImage(*image);
2961 *image=shade_image;
2962 break;
2963 }
2964 if (LocaleCompare("shadow",option+1) == 0)
2965 {
2966 Image
2967 *shadow_image;
2968
2969 /*
2970 Shadow 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 if ((flags & XiValue) == 0)
2977 geometry_info.xi=4.0;
2978 if ((flags & PsiValue) == 0)
2979 geometry_info.psi=4.0;
2980 shadow_image=ShadowImage(*image,geometry_info.rho,
cristybb503372010-05-27 20:51:26 +00002981 geometry_info.sigma,(ssize_t) ceil(geometry_info.xi-0.5),(ssize_t)
cristy0534a6b2010-03-18 01:19:38 +00002982 ceil(geometry_info.psi-0.5),exception);
cristy3ed852e2009-09-05 21:47:34 +00002983 if (shadow_image == (Image *) NULL)
2984 break;
2985 *image=DestroyImage(*image);
2986 *image=shadow_image;
2987 break;
2988 }
2989 if (LocaleCompare("sharpen",option+1) == 0)
2990 {
2991 Image
2992 *sharp_image;
2993
2994 /*
2995 Sharpen image.
2996 */
cristy6b3da3a2010-06-20 02:21:46 +00002997 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002998 flags=ParseGeometry(argv[i+1],&geometry_info);
2999 if ((flags & SigmaValue) == 0)
3000 geometry_info.sigma=1.0;
3001 sharp_image=SharpenImageChannel(*image,channel,geometry_info.rho,
3002 geometry_info.sigma,exception);
3003 if (sharp_image == (Image *) NULL)
3004 break;
3005 *image=DestroyImage(*image);
3006 *image=sharp_image;
3007 break;
3008 }
3009 if (LocaleCompare("shave",option+1) == 0)
3010 {
3011 Image
3012 *shave_image;
3013
3014 /*
3015 Shave the image edges.
3016 */
cristy6b3da3a2010-06-20 02:21:46 +00003017 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003018 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
3019 shave_image=ShaveImage(*image,&geometry,exception);
3020 if (shave_image == (Image *) NULL)
3021 break;
3022 *image=DestroyImage(*image);
3023 *image=shave_image;
3024 break;
3025 }
3026 if (LocaleCompare("shear",option+1) == 0)
3027 {
3028 Image
3029 *shear_image;
3030
3031 /*
3032 Shear image.
3033 */
cristy6b3da3a2010-06-20 02:21:46 +00003034 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003035 flags=ParseGeometry(argv[i+1],&geometry_info);
3036 if ((flags & SigmaValue) == 0)
3037 geometry_info.sigma=geometry_info.rho;
3038 shear_image=ShearImage(*image,geometry_info.rho,geometry_info.sigma,
3039 exception);
3040 if (shear_image == (Image *) NULL)
3041 break;
3042 *image=DestroyImage(*image);
3043 *image=shear_image;
3044 break;
3045 }
3046 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
3047 {
3048 /*
3049 Sigmoidal non-linearity contrast control.
3050 */
cristy6b3da3a2010-06-20 02:21:46 +00003051 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003052 flags=ParseGeometry(argv[i+1],&geometry_info);
3053 if ((flags & SigmaValue) == 0)
3054 geometry_info.sigma=(double) QuantumRange/2.0;
3055 if ((flags & PercentValue) != 0)
3056 geometry_info.sigma=(double) QuantumRange*geometry_info.sigma/
3057 100.0;
3058 (void) SigmoidalContrastImageChannel(*image,channel,
3059 (*option == '-') ? MagickTrue : MagickFalse,geometry_info.rho,
3060 geometry_info.sigma);
3061 InheritException(exception,&(*image)->exception);
3062 break;
3063 }
3064 if (LocaleCompare("sketch",option+1) == 0)
3065 {
3066 Image
3067 *sketch_image;
3068
3069 /*
3070 Sketch image.
3071 */
cristy6b3da3a2010-06-20 02:21:46 +00003072 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003073 flags=ParseGeometry(argv[i+1],&geometry_info);
3074 if ((flags & SigmaValue) == 0)
3075 geometry_info.sigma=1.0;
3076 sketch_image=SketchImage(*image,geometry_info.rho,
3077 geometry_info.sigma,geometry_info.xi,exception);
3078 if (sketch_image == (Image *) NULL)
3079 break;
3080 *image=DestroyImage(*image);
3081 *image=sketch_image;
3082 break;
3083 }
3084 if (LocaleCompare("solarize",option+1) == 0)
3085 {
3086 double
3087 threshold;
3088
cristy6b3da3a2010-06-20 02:21:46 +00003089 (void) SyncImageSettings(mogrify_info,*image);
cristyf2f27272009-12-17 14:48:46 +00003090 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
cristy3ed852e2009-09-05 21:47:34 +00003091 (void) SolarizeImage(*image,threshold);
3092 InheritException(exception,&(*image)->exception);
3093 break;
3094 }
3095 if (LocaleCompare("sparse-color",option+1) == 0)
3096 {
3097 Image
3098 *sparse_image;
3099
3100 SparseColorMethod
3101 method;
3102
3103 char
3104 *arguments;
3105
3106 /*
3107 Sparse Color Interpolated Gradient
3108 */
cristy6b3da3a2010-06-20 02:21:46 +00003109 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003110 method=(SparseColorMethod) ParseMagickOption(
3111 MagickSparseColorOptions,MagickFalse,argv[i+1]);
cristy6b3da3a2010-06-20 02:21:46 +00003112 arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
cristy3ed852e2009-09-05 21:47:34 +00003113 InheritException(exception,&(*image)->exception);
3114 if (arguments == (char *) NULL)
3115 break;
3116 sparse_image=SparseColorOption(*image,channel,method,arguments,
3117 option[0] == '+' ? MagickTrue : MagickFalse,exception);
3118 arguments=DestroyString(arguments);
3119 if (sparse_image == (Image *) NULL)
3120 break;
3121 *image=DestroyImage(*image);
3122 *image=sparse_image;
3123 break;
3124 }
3125 if (LocaleCompare("splice",option+1) == 0)
3126 {
3127 Image
3128 *splice_image;
3129
3130 /*
3131 Splice a solid color into the image.
3132 */
cristy6b3da3a2010-06-20 02:21:46 +00003133 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003134 (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
3135 splice_image=SpliceImage(*image,&geometry,exception);
3136 if (splice_image == (Image *) NULL)
3137 break;
3138 *image=DestroyImage(*image);
3139 *image=splice_image;
3140 break;
3141 }
3142 if (LocaleCompare("spread",option+1) == 0)
3143 {
3144 Image
3145 *spread_image;
3146
3147 /*
3148 Spread an image.
3149 */
cristy6b3da3a2010-06-20 02:21:46 +00003150 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003151 (void) ParseGeometry(argv[i+1],&geometry_info);
3152 spread_image=SpreadImage(*image,geometry_info.rho,exception);
3153 if (spread_image == (Image *) NULL)
3154 break;
3155 *image=DestroyImage(*image);
3156 *image=spread_image;
3157 break;
3158 }
cristy0834d642011-03-18 18:26:08 +00003159 if (LocaleCompare("statistic",option+1) == 0)
3160 {
3161 Image
3162 *statistic_image;
3163
3164 StatisticType
3165 type;
3166
3167 (void) SyncImageSettings(mogrify_info,*image);
3168 type=(StatisticType) ParseMagickOption(MagickStatisticOptions,
3169 MagickFalse,argv[i+1]);
3170 (void) ParseGeometry(argv[i+2],&geometry_info);
3171 statistic_image=StatisticImageChannel(*image,channel,type,
3172 geometry_info.rho,exception);
3173 if (statistic_image == (Image *) NULL)
3174 break;
3175 *image=DestroyImage(*image);
3176 *image=statistic_image;
3177 break;
3178 }
cristy3ed852e2009-09-05 21:47:34 +00003179 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",
cristy0834d642011-03-18 18:26:08 +00003788 "-statistic type radius",
3789 " replace each pixel with corresponding statistic from the neighborhood",
cristy3ed852e2009-09-05 21:47:34 +00003790 "-strip strip image of all profiles and comments",
3791 "-swirl degrees swirl image pixels about the center",
3792 "-threshold value threshold the image",
3793 "-thumbnail geometry create a thumbnail of the image",
3794 "-tile filename tile image when filling a graphic primitive",
3795 "-tint value tint the image with the fill color",
3796 "-transform affine transform image",
3797 "-transparent color make this color transparent within the image",
3798 "-transpose flip image vertically and rotate 90 degrees",
3799 "-transverse flop image horizontally and rotate 270 degrees",
3800 "-trim trim image edges",
3801 "-type type image type",
3802 "-unique-colors discard all but one of any pixel color",
3803 "-unsharp geometry sharpen the image",
3804 "-vignette geometry soften the edges of the image in vignette style",
cristycee97112010-05-28 00:44:52 +00003805 "-wave geometry alter an image along a sine wave",
cristy3ed852e2009-09-05 21:47:34 +00003806 "-white-threshold value",
3807 " force all pixels above the threshold into white",
3808 (char *) NULL
3809 },
3810 *sequence_operators[]=
3811 {
cristy4285d782011-02-09 20:12:28 +00003812 "-append append an image sequence",
cristy3ed852e2009-09-05 21:47:34 +00003813 "-clut apply a color lookup table to the image",
3814 "-coalesce merge a sequence of images",
3815 "-combine combine a sequence of images",
3816 "-composite composite image",
3817 "-crop geometry cut out a rectangular region of the image",
3818 "-deconstruct break down an image sequence into constituent parts",
cristyd18ae7c2010-03-07 17:39:52 +00003819 "-evaluate-sequence operator",
3820 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003821 "-flatten flatten a sequence of images",
3822 "-fx expression apply mathematical expression to an image channel(s)",
3823 "-hald-clut apply a Hald color lookup table to the image",
3824 "-morph value morph an image sequence",
3825 "-mosaic create a mosaic from an image sequence",
cristy36b94822010-05-20 12:48:16 +00003826 "-print string interpret string and print to console",
cristy3ed852e2009-09-05 21:47:34 +00003827 "-process arguments process the image with a custom image filter",
3828 "-reverse reverse image sequence",
3829 "-separate separate an image channel into a grayscale image",
cristy4285d782011-02-09 20:12:28 +00003830 "-smush geometry smush an image sequence together",
cristy3ed852e2009-09-05 21:47:34 +00003831 "-write filename write images to this file",
3832 (char *) NULL
3833 },
3834 *settings[]=
3835 {
3836 "-adjoin join images into a single multi-image file",
3837 "-affine matrix affine transform matrix",
3838 "-alpha option activate, deactivate, reset, or set the alpha channel",
3839 "-antialias remove pixel-aliasing",
3840 "-authenticate password",
3841 " decipher image with this password",
3842 "-attenuate value lessen (or intensify) when adding noise to an image",
3843 "-background color background color",
3844 "-bias value add bias when convolving an image",
3845 "-black-point-compensation",
3846 " use black point compensation",
3847 "-blue-primary point chromaticity blue primary point",
3848 "-bordercolor color border color",
3849 "-caption string assign a caption to an image",
3850 "-channel type apply option to select image channels",
3851 "-colors value preferred number of colors in the image",
3852 "-colorspace type alternate image colorspace",
3853 "-comment string annotate image with comment",
3854 "-compose operator set image composite operator",
3855 "-compress type type of pixel compression when writing the image",
3856 "-define format:option",
3857 " define one or more image format options",
3858 "-delay value display the next image after pausing",
3859 "-density geometry horizontal and vertical density of the image",
3860 "-depth value image depth",
cristyc9b12952010-03-28 01:12:28 +00003861 "-direction type render text right-to-left or left-to-right",
cristy3ed852e2009-09-05 21:47:34 +00003862 "-display server get image or font from this X server",
3863 "-dispose method layer disposal method",
3864 "-dither method apply error diffusion to image",
3865 "-encoding type text encoding type",
3866 "-endian type endianness (MSB or LSB) of the image",
3867 "-family name render text with this font family",
3868 "-fill color color to use when filling a graphic primitive",
3869 "-filter type use this filter when resizing an image",
3870 "-font name render text with this font",
3871 "-format \"string\" output formatted image characteristics",
3872 "-fuzz distance colors within this distance are considered equal",
3873 "-gravity type horizontal and vertical text placement",
3874 "-green-primary point chromaticity green primary point",
3875 "-intent type type of rendering intent when managing the image color",
3876 "-interlace type type of image interlacing scheme",
cristyb32b90a2009-09-07 21:45:48 +00003877 "-interline-spacing value",
3878 " set the space between two text lines",
cristy3ed852e2009-09-05 21:47:34 +00003879 "-interpolate method pixel color interpolation method",
3880 "-interword-spacing value",
3881 " set the space between two words",
3882 "-kerning value set the space between two letters",
3883 "-label string assign a label to an image",
3884 "-limit type value pixel cache resource limit",
3885 "-loop iterations add Netscape loop extension to your GIF animation",
3886 "-mask filename associate a mask with the image",
3887 "-mattecolor color frame color",
3888 "-monitor monitor progress",
3889 "-orient type image orientation",
3890 "-page geometry size and location of an image canvas (setting)",
3891 "-ping efficiently determine image attributes",
3892 "-pointsize value font point size",
cristy7c1b9fd2010-02-02 14:36:00 +00003893 "-precision value maximum number of significant digits to print",
cristy3ed852e2009-09-05 21:47:34 +00003894 "-preview type image preview type",
3895 "-quality value JPEG/MIFF/PNG compression level",
3896 "-quiet suppress all warning messages",
3897 "-red-primary point chromaticity red primary point",
3898 "-regard-warnings pay attention to warning messages",
3899 "-remap filename transform image colors to match this set of colors",
3900 "-respect-parentheses settings remain in effect until parenthesis boundary",
3901 "-sampling-factor geometry",
3902 " horizontal and vertical sampling factor",
3903 "-scene value image scene number",
3904 "-seed value seed a new sequence of pseudo-random numbers",
3905 "-size geometry width and height of image",
3906 "-stretch type render text with this font stretch",
3907 "-stroke color graphic primitive stroke color",
3908 "-strokewidth value graphic primitive stroke width",
3909 "-style type render text with this font style",
cristyd9a29192010-10-16 16:49:53 +00003910 "-synchronize synchronize image to storage device",
3911 "-taint declare the image as modified",
cristy3ed852e2009-09-05 21:47:34 +00003912 "-texture filename name of texture to tile onto the image background",
3913 "-tile-offset geometry",
3914 " tile offset",
3915 "-treedepth value color tree depth",
3916 "-transparent-color color",
3917 " transparent color",
3918 "-undercolor color annotation bounding box color",
3919 "-units type the units of image resolution",
3920 "-verbose print detailed information about the image",
3921 "-view FlashPix viewing transforms",
3922 "-virtual-pixel method",
3923 " virtual pixel access method",
3924 "-weight type render text with this font weight",
3925 "-white-point point chromaticity white point",
3926 (char *) NULL
3927 },
3928 *stack_operators[]=
3929 {
3930 "-clone index clone an image",
3931 "-delete index delete the image from the image sequence",
3932 "-insert index insert last image into the image sequence",
3933 "-swap indexes swap two images in the image sequence",
3934 (char *) NULL
3935 };
3936
3937 const char
3938 **p;
3939
cristybb503372010-05-27 20:51:26 +00003940 (void) printf("Version: %s\n",GetMagickVersion((size_t *) NULL));
cristy610b2e22009-10-22 14:59:43 +00003941 (void) printf("Copyright: %s\n",GetMagickCopyright());
3942 (void) printf("Features: %s\n\n",GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00003943 (void) printf("Usage: %s [options ...] file [ [options ...] file ...]\n",
3944 GetClientName());
3945 (void) printf("\nImage Settings:\n");
3946 for (p=settings; *p != (char *) NULL; p++)
3947 (void) printf(" %s\n",*p);
3948 (void) printf("\nImage Operators:\n");
3949 for (p=operators; *p != (char *) NULL; p++)
3950 (void) printf(" %s\n",*p);
3951 (void) printf("\nImage Sequence Operators:\n");
3952 for (p=sequence_operators; *p != (char *) NULL; p++)
3953 (void) printf(" %s\n",*p);
3954 (void) printf("\nImage Stack Operators:\n");
3955 for (p=stack_operators; *p != (char *) NULL; p++)
3956 (void) printf(" %s\n",*p);
3957 (void) printf("\nMiscellaneous Options:\n");
3958 for (p=miscellaneous; *p != (char *) NULL; p++)
3959 (void) printf(" %s\n",*p);
3960 (void) printf(
3961 "\nBy default, the image format of `file' is determined by its magic\n");
3962 (void) printf(
3963 "number. To specify a particular image format, precede the filename\n");
3964 (void) printf(
3965 "with an image format name and a colon (i.e. ps:image) or specify the\n");
3966 (void) printf(
3967 "image type as the filename suffix (i.e. image.ps). Specify 'file' as\n");
3968 (void) printf("'-' for standard input or output.\n");
3969 return(MagickFalse);
3970}
3971
3972WandExport MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,
3973 int argc,char **argv,char **wand_unused(metadata),ExceptionInfo *exception)
3974{
3975#define DestroyMogrify() \
3976{ \
3977 if (format != (char *) NULL) \
3978 format=DestroyString(format); \
3979 if (path != (char *) NULL) \
3980 path=DestroyString(path); \
3981 DestroyImageStack(); \
cristybb503372010-05-27 20:51:26 +00003982 for (i=0; i < (ssize_t) argc; i++) \
cristy3ed852e2009-09-05 21:47:34 +00003983 argv[i]=DestroyString(argv[i]); \
3984 argv=(char **) RelinquishMagickMemory(argv); \
3985}
3986#define ThrowMogrifyException(asperity,tag,option) \
3987{ \
3988 (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag,"`%s'", \
3989 option); \
3990 DestroyMogrify(); \
3991 return(MagickFalse); \
3992}
3993#define ThrowMogrifyInvalidArgumentException(option,argument) \
3994{ \
3995 (void) ThrowMagickException(exception,GetMagickModule(),OptionError, \
3996 "InvalidArgument","`%s': %s",argument,option); \
3997 DestroyMogrify(); \
3998 return(MagickFalse); \
3999}
4000
4001 char
4002 *format,
4003 *option,
4004 *path;
4005
4006 Image
4007 *image;
4008
4009 ImageStack
4010 image_stack[MaxImageStackDepth+1];
4011
cristy3ed852e2009-09-05 21:47:34 +00004012 MagickBooleanType
4013 global_colormap;
4014
4015 MagickBooleanType
4016 fire,
cristyebbcfea2011-02-25 02:43:54 +00004017 pend,
4018 respect_parenthesis;
cristy3ed852e2009-09-05 21:47:34 +00004019
4020 MagickStatusType
4021 status;
4022
cristyebbcfea2011-02-25 02:43:54 +00004023 register ssize_t
4024 i;
4025
4026 ssize_t
4027 j,
4028 k;
4029
cristy3ed852e2009-09-05 21:47:34 +00004030 /*
4031 Set defaults.
4032 */
4033 assert(image_info != (ImageInfo *) NULL);
4034 assert(image_info->signature == MagickSignature);
4035 if (image_info->debug != MagickFalse)
4036 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
4037 assert(exception != (ExceptionInfo *) NULL);
4038 if (argc == 2)
4039 {
4040 option=argv[1];
4041 if ((LocaleCompare("version",option+1) == 0) ||
4042 (LocaleCompare("-version",option+1) == 0))
4043 {
4044 (void) fprintf(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +00004045 GetMagickVersion((size_t *) NULL));
cristy610b2e22009-10-22 14:59:43 +00004046 (void) fprintf(stdout,"Copyright: %s\n",GetMagickCopyright());
4047 (void) fprintf(stdout,"Features: %s\n\n",GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00004048 return(MagickFalse);
4049 }
4050 }
4051 if (argc < 2)
cristy13e61a12010-02-04 20:19:00 +00004052 return(MogrifyUsage());
cristy3ed852e2009-09-05 21:47:34 +00004053 format=(char *) NULL;
4054 path=(char *) NULL;
4055 global_colormap=MagickFalse;
4056 k=0;
4057 j=1;
4058 NewImageStack();
4059 option=(char *) NULL;
4060 pend=MagickFalse;
cristyebbcfea2011-02-25 02:43:54 +00004061 respect_parenthesis=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00004062 status=MagickTrue;
4063 /*
4064 Parse command line.
4065 */
4066 ReadCommandlLine(argc,&argv);
4067 status=ExpandFilenames(&argc,&argv);
4068 if (status == MagickFalse)
4069 ThrowMogrifyException(ResourceLimitError,"MemoryAllocationFailed",
4070 GetExceptionMessage(errno));
cristybb503372010-05-27 20:51:26 +00004071 for (i=1; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00004072 {
4073 option=argv[i];
4074 if (LocaleCompare(option,"(") == 0)
4075 {
4076 FireImageStack(MagickFalse,MagickTrue,pend);
4077 if (k == MaxImageStackDepth)
4078 ThrowMogrifyException(OptionError,"ParenthesisNestedTooDeeply",
4079 option);
4080 PushImageStack();
4081 continue;
4082 }
4083 if (LocaleCompare(option,")") == 0)
4084 {
4085 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
4086 if (k == 0)
4087 ThrowMogrifyException(OptionError,"UnableToParseExpression",option);
4088 PopImageStack();
4089 continue;
4090 }
4091 if (IsMagickOption(option) == MagickFalse)
4092 {
4093 char
4094 backup_filename[MaxTextExtent],
4095 *filename;
4096
4097 Image
4098 *images;
4099
4100 /*
4101 Option is a file name: begin by reading image from specified file.
4102 */
4103 FireImageStack(MagickFalse,MagickFalse,pend);
4104 filename=argv[i];
cristycee97112010-05-28 00:44:52 +00004105 if ((LocaleCompare(filename,"--") == 0) && (i < (ssize_t) (argc-1)))
cristy3ed852e2009-09-05 21:47:34 +00004106 filename=argv[++i];
4107 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
4108 images=ReadImages(image_info,exception);
4109 status&=(images != (Image *) NULL) &&
4110 (exception->severity < ErrorException);
4111 if (images == (Image *) NULL)
4112 continue;
cristydaa76602010-06-30 13:05:11 +00004113 if (format != (char *) NULL)
4114 (void) CopyMagickString(images->filename,images->magick_filename,
4115 MaxTextExtent);
cristy3ed852e2009-09-05 21:47:34 +00004116 if (path != (char *) NULL)
4117 {
4118 GetPathComponent(option,TailPath,filename);
4119 (void) FormatMagickString(images->filename,MaxTextExtent,"%s%c%s",
4120 path,*DirectorySeparator,filename);
4121 }
4122 if (format != (char *) NULL)
cristydaa76602010-06-30 13:05:11 +00004123 AppendImageFormat(format,images->filename);
cristy3ed852e2009-09-05 21:47:34 +00004124 AppendImageStack(images);
4125 FinalizeImageSettings(image_info,image,MagickFalse);
4126 if (global_colormap != MagickFalse)
4127 {
4128 QuantizeInfo
4129 *quantize_info;
4130
4131 quantize_info=AcquireQuantizeInfo(image_info);
4132 (void) RemapImages(quantize_info,images,(Image *) NULL);
4133 quantize_info=DestroyQuantizeInfo(quantize_info);
4134 }
4135 *backup_filename='\0';
4136 if ((LocaleCompare(image->filename,"-") != 0) &&
4137 (IsPathWritable(image->filename) != MagickFalse))
4138 {
cristybb503372010-05-27 20:51:26 +00004139 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004140 i;
4141
4142 /*
4143 Rename image file as backup.
4144 */
4145 (void) CopyMagickString(backup_filename,image->filename,
4146 MaxTextExtent);
4147 for (i=0; i < 6; i++)
4148 {
4149 (void) ConcatenateMagickString(backup_filename,"~",MaxTextExtent);
4150 if (IsPathAccessible(backup_filename) == MagickFalse)
4151 break;
4152 }
4153 if ((IsPathAccessible(backup_filename) != MagickFalse) ||
4154 (rename(image->filename,backup_filename) != 0))
4155 *backup_filename='\0';
4156 }
4157 /*
4158 Write transmogrified image to disk.
4159 */
4160 image_info->synchronize=MagickTrue;
4161 status&=WriteImages(image_info,image,image->filename,exception);
4162 if ((status == MagickFalse) && (*backup_filename != '\0'))
4163 (void) remove(backup_filename);
4164 RemoveAllImageStack();
4165 continue;
4166 }
4167 pend=image != (Image *) NULL ? MagickTrue : MagickFalse;
4168 switch (*(option+1))
4169 {
4170 case 'a':
4171 {
4172 if (LocaleCompare("adaptive-blur",option+1) == 0)
4173 {
4174 i++;
cristybb503372010-05-27 20:51:26 +00004175 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004176 ThrowMogrifyException(OptionError,"MissingArgument",option);
4177 if (IsGeometry(argv[i]) == MagickFalse)
4178 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4179 break;
4180 }
4181 if (LocaleCompare("adaptive-resize",option+1) == 0)
4182 {
4183 i++;
cristybb503372010-05-27 20:51:26 +00004184 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004185 ThrowMogrifyException(OptionError,"MissingArgument",option);
4186 if (IsGeometry(argv[i]) == MagickFalse)
4187 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4188 break;
4189 }
4190 if (LocaleCompare("adaptive-sharpen",option+1) == 0)
4191 {
4192 i++;
cristybb503372010-05-27 20:51:26 +00004193 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004194 ThrowMogrifyException(OptionError,"MissingArgument",option);
4195 if (IsGeometry(argv[i]) == MagickFalse)
4196 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4197 break;
4198 }
4199 if (LocaleCompare("affine",option+1) == 0)
4200 {
4201 if (*option == '+')
4202 break;
4203 i++;
cristybb503372010-05-27 20:51:26 +00004204 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004205 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy3ed852e2009-09-05 21:47:34 +00004206 break;
4207 }
4208 if (LocaleCompare("alpha",option+1) == 0)
4209 {
cristybb503372010-05-27 20:51:26 +00004210 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004211 type;
4212
4213 if (*option == '+')
4214 break;
4215 i++;
cristybb503372010-05-27 20:51:26 +00004216 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004217 ThrowMogrifyException(OptionError,"MissingArgument",option);
4218 type=ParseMagickOption(MagickAlphaOptions,MagickFalse,argv[i]);
4219 if (type < 0)
4220 ThrowMogrifyException(OptionError,"UnrecognizedAlphaChannelType",
4221 argv[i]);
4222 break;
4223 }
4224 if (LocaleCompare("annotate",option+1) == 0)
4225 {
4226 if (*option == '+')
4227 break;
4228 i++;
cristybb503372010-05-27 20:51:26 +00004229 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004230 ThrowMogrifyException(OptionError,"MissingArgument",option);
4231 if (IsGeometry(argv[i]) == MagickFalse)
4232 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristybb503372010-05-27 20:51:26 +00004233 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004234 ThrowMogrifyException(OptionError,"MissingArgument",option);
4235 i++;
4236 break;
4237 }
4238 if (LocaleCompare("antialias",option+1) == 0)
4239 break;
4240 if (LocaleCompare("append",option+1) == 0)
4241 break;
4242 if (LocaleCompare("attenuate",option+1) == 0)
4243 {
4244 if (*option == '+')
4245 break;
4246 i++;
cristybb503372010-05-27 20:51:26 +00004247 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004248 ThrowMogrifyException(OptionError,"MissingArgument",option);
4249 if (IsGeometry(argv[i]) == MagickFalse)
4250 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4251 break;
4252 }
4253 if (LocaleCompare("authenticate",option+1) == 0)
4254 {
4255 if (*option == '+')
4256 break;
4257 i++;
cristybb503372010-05-27 20:51:26 +00004258 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004259 ThrowMogrifyException(OptionError,"MissingArgument",option);
4260 break;
4261 }
4262 if (LocaleCompare("auto-gamma",option+1) == 0)
4263 break;
4264 if (LocaleCompare("auto-level",option+1) == 0)
4265 break;
4266 if (LocaleCompare("auto-orient",option+1) == 0)
4267 break;
4268 if (LocaleCompare("average",option+1) == 0)
4269 break;
4270 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4271 }
4272 case 'b':
4273 {
4274 if (LocaleCompare("background",option+1) == 0)
4275 {
4276 if (*option == '+')
4277 break;
4278 i++;
cristybb503372010-05-27 20:51:26 +00004279 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004280 ThrowMogrifyException(OptionError,"MissingArgument",option);
4281 break;
4282 }
4283 if (LocaleCompare("bias",option+1) == 0)
4284 {
4285 if (*option == '+')
4286 break;
4287 i++;
cristybb503372010-05-27 20:51:26 +00004288 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004289 ThrowMogrifyException(OptionError,"MissingArgument",option);
4290 if (IsGeometry(argv[i]) == MagickFalse)
4291 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4292 break;
4293 }
4294 if (LocaleCompare("black-point-compensation",option+1) == 0)
4295 break;
4296 if (LocaleCompare("black-threshold",option+1) == 0)
4297 {
4298 if (*option == '+')
4299 break;
4300 i++;
cristybb503372010-05-27 20:51:26 +00004301 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004302 ThrowMogrifyException(OptionError,"MissingArgument",option);
4303 if (IsGeometry(argv[i]) == MagickFalse)
4304 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4305 break;
4306 }
4307 if (LocaleCompare("blue-primary",option+1) == 0)
4308 {
4309 if (*option == '+')
4310 break;
4311 i++;
cristybb503372010-05-27 20:51:26 +00004312 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004313 ThrowMogrifyException(OptionError,"MissingArgument",option);
4314 if (IsGeometry(argv[i]) == MagickFalse)
4315 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4316 break;
4317 }
4318 if (LocaleCompare("blue-shift",option+1) == 0)
4319 {
4320 i++;
cristybb503372010-05-27 20:51:26 +00004321 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004322 ThrowMogrifyException(OptionError,"MissingArgument",option);
4323 if (IsGeometry(argv[i]) == MagickFalse)
4324 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4325 break;
4326 }
4327 if (LocaleCompare("blur",option+1) == 0)
4328 {
4329 i++;
cristybb503372010-05-27 20:51:26 +00004330 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004331 ThrowMogrifyException(OptionError,"MissingArgument",option);
4332 if (IsGeometry(argv[i]) == MagickFalse)
4333 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4334 break;
4335 }
4336 if (LocaleCompare("border",option+1) == 0)
4337 {
4338 if (*option == '+')
4339 break;
4340 i++;
cristybb503372010-05-27 20:51:26 +00004341 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004342 ThrowMogrifyException(OptionError,"MissingArgument",option);
4343 if (IsGeometry(argv[i]) == MagickFalse)
4344 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4345 break;
4346 }
4347 if (LocaleCompare("bordercolor",option+1) == 0)
4348 {
4349 if (*option == '+')
4350 break;
4351 i++;
cristybb503372010-05-27 20:51:26 +00004352 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004353 ThrowMogrifyException(OptionError,"MissingArgument",option);
4354 break;
4355 }
4356 if (LocaleCompare("box",option+1) == 0)
4357 {
4358 if (*option == '+')
4359 break;
4360 i++;
cristybb503372010-05-27 20:51:26 +00004361 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004362 ThrowMogrifyException(OptionError,"MissingArgument",option);
4363 break;
4364 }
cristya28d6b82010-01-11 20:03:47 +00004365 if (LocaleCompare("brightness-contrast",option+1) == 0)
4366 {
4367 i++;
cristybb503372010-05-27 20:51:26 +00004368 if (i == (ssize_t) argc)
cristya28d6b82010-01-11 20:03:47 +00004369 ThrowMogrifyException(OptionError,"MissingArgument",option);
4370 if (IsGeometry(argv[i]) == MagickFalse)
4371 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4372 break;
4373 }
cristy3ed852e2009-09-05 21:47:34 +00004374 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4375 }
4376 case 'c':
4377 {
4378 if (LocaleCompare("cache",option+1) == 0)
4379 {
4380 if (*option == '+')
4381 break;
4382 i++;
cristybb503372010-05-27 20:51:26 +00004383 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004384 ThrowMogrifyException(OptionError,"MissingArgument",option);
4385 if (IsGeometry(argv[i]) == MagickFalse)
4386 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4387 break;
4388 }
4389 if (LocaleCompare("caption",option+1) == 0)
4390 {
4391 if (*option == '+')
4392 break;
4393 i++;
cristybb503372010-05-27 20:51:26 +00004394 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004395 ThrowMogrifyException(OptionError,"MissingArgument",option);
4396 break;
4397 }
4398 if (LocaleCompare("channel",option+1) == 0)
4399 {
cristybb503372010-05-27 20:51:26 +00004400 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004401 channel;
4402
4403 if (*option == '+')
4404 break;
4405 i++;
cristybb503372010-05-27 20:51:26 +00004406 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004407 ThrowMogrifyException(OptionError,"MissingArgument",option);
4408 channel=ParseChannelOption(argv[i]);
4409 if (channel < 0)
4410 ThrowMogrifyException(OptionError,"UnrecognizedChannelType",
4411 argv[i]);
4412 break;
4413 }
4414 if (LocaleCompare("cdl",option+1) == 0)
4415 {
4416 if (*option == '+')
4417 break;
4418 i++;
cristybb503372010-05-27 20:51:26 +00004419 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004420 ThrowMogrifyException(OptionError,"MissingArgument",option);
4421 break;
4422 }
4423 if (LocaleCompare("charcoal",option+1) == 0)
4424 {
4425 if (*option == '+')
4426 break;
4427 i++;
cristybb503372010-05-27 20:51:26 +00004428 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004429 ThrowMogrifyException(OptionError,"MissingArgument",option);
4430 if (IsGeometry(argv[i]) == MagickFalse)
4431 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4432 break;
4433 }
4434 if (LocaleCompare("chop",option+1) == 0)
4435 {
4436 if (*option == '+')
4437 break;
4438 i++;
cristybb503372010-05-27 20:51:26 +00004439 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004440 ThrowMogrifyException(OptionError,"MissingArgument",option);
4441 if (IsGeometry(argv[i]) == MagickFalse)
4442 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4443 break;
4444 }
cristy1eb45dd2009-09-25 16:38:06 +00004445 if (LocaleCompare("clamp",option+1) == 0)
4446 break;
4447 if (LocaleCompare("clip",option+1) == 0)
4448 break;
cristy3ed852e2009-09-05 21:47:34 +00004449 if (LocaleCompare("clip-mask",option+1) == 0)
4450 {
4451 if (*option == '+')
4452 break;
4453 i++;
cristybb503372010-05-27 20:51:26 +00004454 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004455 ThrowMogrifyException(OptionError,"MissingArgument",option);
4456 break;
4457 }
4458 if (LocaleCompare("clut",option+1) == 0)
4459 break;
4460 if (LocaleCompare("coalesce",option+1) == 0)
4461 break;
4462 if (LocaleCompare("colorize",option+1) == 0)
4463 {
4464 if (*option == '+')
4465 break;
4466 i++;
cristybb503372010-05-27 20:51:26 +00004467 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004468 ThrowMogrifyException(OptionError,"MissingArgument",option);
4469 if (IsGeometry(argv[i]) == MagickFalse)
4470 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4471 break;
4472 }
cristye6365592010-04-02 17:31:23 +00004473 if (LocaleCompare("color-matrix",option+1) == 0)
4474 {
cristyb6bd4ad2010-08-08 01:12:27 +00004475 KernelInfo
4476 *kernel_info;
4477
cristye6365592010-04-02 17:31:23 +00004478 if (*option == '+')
4479 break;
4480 i++;
cristybb503372010-05-27 20:51:26 +00004481 if (i == (ssize_t) (argc-1))
cristye6365592010-04-02 17:31:23 +00004482 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00004483 kernel_info=AcquireKernelInfo(argv[i]);
4484 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00004485 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00004486 kernel_info=DestroyKernelInfo(kernel_info);
cristye6365592010-04-02 17:31:23 +00004487 break;
4488 }
cristy3ed852e2009-09-05 21:47:34 +00004489 if (LocaleCompare("colors",option+1) == 0)
4490 {
4491 if (*option == '+')
4492 break;
4493 i++;
cristybb503372010-05-27 20:51:26 +00004494 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004495 ThrowMogrifyException(OptionError,"MissingArgument",option);
4496 if (IsGeometry(argv[i]) == MagickFalse)
4497 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4498 break;
4499 }
4500 if (LocaleCompare("colorspace",option+1) == 0)
4501 {
cristybb503372010-05-27 20:51:26 +00004502 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004503 colorspace;
4504
4505 if (*option == '+')
4506 break;
4507 i++;
cristybb503372010-05-27 20:51:26 +00004508 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004509 ThrowMogrifyException(OptionError,"MissingArgument",option);
4510 colorspace=ParseMagickOption(MagickColorspaceOptions,MagickFalse,
4511 argv[i]);
4512 if (colorspace < 0)
4513 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
4514 argv[i]);
4515 break;
4516 }
4517 if (LocaleCompare("combine",option+1) == 0)
4518 break;
4519 if (LocaleCompare("comment",option+1) == 0)
4520 {
4521 if (*option == '+')
4522 break;
4523 i++;
cristybb503372010-05-27 20:51:26 +00004524 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004525 ThrowMogrifyException(OptionError,"MissingArgument",option);
4526 break;
4527 }
4528 if (LocaleCompare("composite",option+1) == 0)
4529 break;
4530 if (LocaleCompare("compress",option+1) == 0)
4531 {
cristybb503372010-05-27 20:51:26 +00004532 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004533 compress;
4534
4535 if (*option == '+')
4536 break;
4537 i++;
cristybb503372010-05-27 20:51:26 +00004538 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004539 ThrowMogrifyException(OptionError,"MissingArgument",option);
4540 compress=ParseMagickOption(MagickCompressOptions,MagickFalse,
4541 argv[i]);
4542 if (compress < 0)
4543 ThrowMogrifyException(OptionError,"UnrecognizedImageCompression",
4544 argv[i]);
4545 break;
4546 }
cristy22879752009-10-25 23:55:40 +00004547 if (LocaleCompare("concurrent",option+1) == 0)
4548 break;
cristy3ed852e2009-09-05 21:47:34 +00004549 if (LocaleCompare("contrast",option+1) == 0)
4550 break;
4551 if (LocaleCompare("contrast-stretch",option+1) == 0)
4552 {
4553 i++;
cristybb503372010-05-27 20:51:26 +00004554 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004555 ThrowMogrifyException(OptionError,"MissingArgument",option);
4556 if (IsGeometry(argv[i]) == MagickFalse)
4557 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4558 break;
4559 }
4560 if (LocaleCompare("convolve",option+1) == 0)
4561 {
cristyb6bd4ad2010-08-08 01:12:27 +00004562 KernelInfo
4563 *kernel_info;
4564
cristy3ed852e2009-09-05 21:47:34 +00004565 if (*option == '+')
4566 break;
4567 i++;
cristybb503372010-05-27 20:51:26 +00004568 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004569 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00004570 kernel_info=AcquireKernelInfo(argv[i]);
4571 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00004572 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00004573 kernel_info=DestroyKernelInfo(kernel_info);
cristy3ed852e2009-09-05 21:47:34 +00004574 break;
4575 }
4576 if (LocaleCompare("crop",option+1) == 0)
4577 {
4578 if (*option == '+')
4579 break;
4580 i++;
cristybb503372010-05-27 20:51:26 +00004581 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004582 ThrowMogrifyException(OptionError,"MissingArgument",option);
4583 if (IsGeometry(argv[i]) == MagickFalse)
4584 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4585 break;
4586 }
4587 if (LocaleCompare("cycle",option+1) == 0)
4588 {
4589 if (*option == '+')
4590 break;
4591 i++;
cristybb503372010-05-27 20:51:26 +00004592 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004593 ThrowMogrifyException(OptionError,"MissingArgument",option);
4594 if (IsGeometry(argv[i]) == MagickFalse)
4595 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4596 break;
4597 }
4598 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4599 }
4600 case 'd':
4601 {
4602 if (LocaleCompare("decipher",option+1) == 0)
4603 {
4604 if (*option == '+')
4605 break;
4606 i++;
cristybb503372010-05-27 20:51:26 +00004607 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004608 ThrowMogrifyException(OptionError,"MissingArgument",option);
4609 break;
4610 }
4611 if (LocaleCompare("deconstruct",option+1) == 0)
4612 break;
4613 if (LocaleCompare("debug",option+1) == 0)
4614 {
cristybb503372010-05-27 20:51:26 +00004615 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004616 event;
4617
4618 if (*option == '+')
4619 break;
4620 i++;
cristybb503372010-05-27 20:51:26 +00004621 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004622 ThrowMogrifyException(OptionError,"MissingArgument",option);
4623 event=ParseMagickOption(MagickLogEventOptions,MagickFalse,argv[i]);
4624 if (event < 0)
4625 ThrowMogrifyException(OptionError,"UnrecognizedEventType",
4626 argv[i]);
4627 (void) SetLogEventMask(argv[i]);
4628 break;
4629 }
4630 if (LocaleCompare("define",option+1) == 0)
4631 {
4632 i++;
cristybb503372010-05-27 20:51:26 +00004633 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004634 ThrowMogrifyException(OptionError,"MissingArgument",option);
4635 if (*option == '+')
4636 {
4637 const char
4638 *define;
4639
4640 define=GetImageOption(image_info,argv[i]);
4641 if (define == (const char *) NULL)
4642 ThrowMogrifyException(OptionError,"NoSuchOption",argv[i]);
4643 break;
4644 }
4645 break;
4646 }
4647 if (LocaleCompare("delay",option+1) == 0)
4648 {
4649 if (*option == '+')
4650 break;
4651 i++;
cristybb503372010-05-27 20:51:26 +00004652 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004653 ThrowMogrifyException(OptionError,"MissingArgument",option);
4654 if (IsGeometry(argv[i]) == MagickFalse)
4655 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4656 break;
4657 }
4658 if (LocaleCompare("density",option+1) == 0)
4659 {
4660 if (*option == '+')
4661 break;
4662 i++;
cristybb503372010-05-27 20:51:26 +00004663 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004664 ThrowMogrifyException(OptionError,"MissingArgument",option);
4665 if (IsGeometry(argv[i]) == MagickFalse)
4666 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4667 break;
4668 }
4669 if (LocaleCompare("depth",option+1) == 0)
4670 {
4671 if (*option == '+')
4672 break;
4673 i++;
cristybb503372010-05-27 20:51:26 +00004674 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004675 ThrowMogrifyException(OptionError,"MissingArgument",option);
4676 if (IsGeometry(argv[i]) == MagickFalse)
4677 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4678 break;
4679 }
4680 if (LocaleCompare("deskew",option+1) == 0)
4681 {
4682 if (*option == '+')
4683 break;
4684 i++;
cristybb503372010-05-27 20:51:26 +00004685 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004686 ThrowMogrifyException(OptionError,"MissingArgument",option);
4687 if (IsGeometry(argv[i]) == MagickFalse)
4688 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4689 break;
4690 }
4691 if (LocaleCompare("despeckle",option+1) == 0)
4692 break;
4693 if (LocaleCompare("dft",option+1) == 0)
4694 break;
cristyc9b12952010-03-28 01:12:28 +00004695 if (LocaleCompare("direction",option+1) == 0)
4696 {
cristybb503372010-05-27 20:51:26 +00004697 ssize_t
cristyc9b12952010-03-28 01:12:28 +00004698 direction;
4699
4700 if (*option == '+')
4701 break;
4702 i++;
cristybb503372010-05-27 20:51:26 +00004703 if (i == (ssize_t) argc)
cristyc9b12952010-03-28 01:12:28 +00004704 ThrowMogrifyException(OptionError,"MissingArgument",option);
4705 direction=ParseMagickOption(MagickDirectionOptions,MagickFalse,
4706 argv[i]);
4707 if (direction < 0)
4708 ThrowMogrifyException(OptionError,"UnrecognizedDirectionType",
4709 argv[i]);
4710 break;
4711 }
cristy3ed852e2009-09-05 21:47:34 +00004712 if (LocaleCompare("display",option+1) == 0)
4713 {
4714 if (*option == '+')
4715 break;
4716 i++;
cristybb503372010-05-27 20:51:26 +00004717 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004718 ThrowMogrifyException(OptionError,"MissingArgument",option);
4719 break;
4720 }
4721 if (LocaleCompare("dispose",option+1) == 0)
4722 {
cristybb503372010-05-27 20:51:26 +00004723 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004724 dispose;
4725
4726 if (*option == '+')
4727 break;
4728 i++;
cristybb503372010-05-27 20:51:26 +00004729 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004730 ThrowMogrifyException(OptionError,"MissingArgument",option);
4731 dispose=ParseMagickOption(MagickDisposeOptions,MagickFalse,argv[i]);
4732 if (dispose < 0)
4733 ThrowMogrifyException(OptionError,"UnrecognizedDisposeMethod",
4734 argv[i]);
4735 break;
4736 }
4737 if (LocaleCompare("distort",option+1) == 0)
4738 {
cristybb503372010-05-27 20:51:26 +00004739 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004740 op;
4741
4742 i++;
cristybb503372010-05-27 20:51:26 +00004743 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004744 ThrowMogrifyException(OptionError,"MissingArgument",option);
4745 op=ParseMagickOption(MagickDistortOptions,MagickFalse,argv[i]);
4746 if (op < 0)
4747 ThrowMogrifyException(OptionError,"UnrecognizedDistortMethod",
4748 argv[i]);
4749 i++;
cristybb503372010-05-27 20:51:26 +00004750 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004751 ThrowMogrifyException(OptionError,"MissingArgument",option);
4752 break;
4753 }
4754 if (LocaleCompare("dither",option+1) == 0)
4755 {
cristybb503372010-05-27 20:51:26 +00004756 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004757 method;
4758
4759 if (*option == '+')
4760 break;
4761 i++;
cristybb503372010-05-27 20:51:26 +00004762 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004763 ThrowMogrifyException(OptionError,"MissingArgument",option);
4764 method=ParseMagickOption(MagickDitherOptions,MagickFalse,argv[i]);
4765 if (method < 0)
4766 ThrowMogrifyException(OptionError,"UnrecognizedDitherMethod",
4767 argv[i]);
4768 break;
4769 }
4770 if (LocaleCompare("draw",option+1) == 0)
4771 {
4772 if (*option == '+')
4773 break;
4774 i++;
cristybb503372010-05-27 20:51:26 +00004775 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004776 ThrowMogrifyException(OptionError,"MissingArgument",option);
4777 break;
4778 }
cristy22879752009-10-25 23:55:40 +00004779 if (LocaleCompare("duration",option+1) == 0)
4780 {
4781 if (*option == '+')
4782 break;
4783 i++;
cristybb503372010-05-27 20:51:26 +00004784 if (i == (ssize_t) (argc-1))
cristy22879752009-10-25 23:55:40 +00004785 ThrowMogrifyException(OptionError,"MissingArgument",option);
4786 if (IsGeometry(argv[i]) == MagickFalse)
4787 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4788 break;
4789 }
cristy3ed852e2009-09-05 21:47:34 +00004790 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4791 }
4792 case 'e':
4793 {
4794 if (LocaleCompare("edge",option+1) == 0)
4795 {
4796 if (*option == '+')
4797 break;
4798 i++;
cristybb503372010-05-27 20:51:26 +00004799 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004800 ThrowMogrifyException(OptionError,"MissingArgument",option);
4801 if (IsGeometry(argv[i]) == MagickFalse)
4802 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4803 break;
4804 }
4805 if (LocaleCompare("emboss",option+1) == 0)
4806 {
4807 if (*option == '+')
4808 break;
4809 i++;
cristybb503372010-05-27 20:51:26 +00004810 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004811 ThrowMogrifyException(OptionError,"MissingArgument",option);
4812 if (IsGeometry(argv[i]) == MagickFalse)
4813 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4814 break;
4815 }
4816 if (LocaleCompare("encipher",option+1) == 0)
4817 {
4818 if (*option == '+')
4819 break;
4820 i++;
cristybb503372010-05-27 20:51:26 +00004821 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004822 ThrowMogrifyException(OptionError,"MissingArgument",option);
4823 break;
4824 }
4825 if (LocaleCompare("encoding",option+1) == 0)
4826 {
4827 if (*option == '+')
4828 break;
4829 i++;
cristybb503372010-05-27 20:51:26 +00004830 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004831 ThrowMogrifyException(OptionError,"MissingArgument",option);
4832 break;
4833 }
4834 if (LocaleCompare("endian",option+1) == 0)
4835 {
cristybb503372010-05-27 20:51:26 +00004836 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004837 endian;
4838
4839 if (*option == '+')
4840 break;
4841 i++;
cristybb503372010-05-27 20:51:26 +00004842 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004843 ThrowMogrifyException(OptionError,"MissingArgument",option);
4844 endian=ParseMagickOption(MagickEndianOptions,MagickFalse,argv[i]);
4845 if (endian < 0)
4846 ThrowMogrifyException(OptionError,"UnrecognizedEndianType",
4847 argv[i]);
4848 break;
4849 }
4850 if (LocaleCompare("enhance",option+1) == 0)
4851 break;
4852 if (LocaleCompare("equalize",option+1) == 0)
4853 break;
4854 if (LocaleCompare("evaluate",option+1) == 0)
4855 {
cristybb503372010-05-27 20:51:26 +00004856 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004857 op;
4858
4859 if (*option == '+')
4860 break;
4861 i++;
cristybb503372010-05-27 20:51:26 +00004862 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004863 ThrowMogrifyException(OptionError,"MissingArgument",option);
4864 op=ParseMagickOption(MagickEvaluateOptions,MagickFalse,argv[i]);
4865 if (op < 0)
4866 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4867 argv[i]);
4868 i++;
cristybb503372010-05-27 20:51:26 +00004869 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004870 ThrowMogrifyException(OptionError,"MissingArgument",option);
4871 if (IsGeometry(argv[i]) == MagickFalse)
4872 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4873 break;
4874 }
cristyd18ae7c2010-03-07 17:39:52 +00004875 if (LocaleCompare("evaluate-sequence",option+1) == 0)
4876 {
cristybb503372010-05-27 20:51:26 +00004877 ssize_t
cristyd18ae7c2010-03-07 17:39:52 +00004878 op;
4879
4880 if (*option == '+')
4881 break;
4882 i++;
cristybb503372010-05-27 20:51:26 +00004883 if (i == (ssize_t) argc)
cristyd18ae7c2010-03-07 17:39:52 +00004884 ThrowMogrifyException(OptionError,"MissingArgument",option);
4885 op=ParseMagickOption(MagickEvaluateOptions,MagickFalse,argv[i]);
4886 if (op < 0)
4887 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4888 argv[i]);
4889 break;
4890 }
cristy3ed852e2009-09-05 21:47:34 +00004891 if (LocaleCompare("extent",option+1) == 0)
4892 {
4893 if (*option == '+')
4894 break;
4895 i++;
cristybb503372010-05-27 20:51:26 +00004896 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004897 ThrowMogrifyException(OptionError,"MissingArgument",option);
4898 if (IsGeometry(argv[i]) == MagickFalse)
4899 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4900 break;
4901 }
4902 if (LocaleCompare("extract",option+1) == 0)
4903 {
4904 if (*option == '+')
4905 break;
4906 i++;
cristybb503372010-05-27 20:51:26 +00004907 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004908 ThrowMogrifyException(OptionError,"MissingArgument",option);
4909 if (IsGeometry(argv[i]) == MagickFalse)
4910 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4911 break;
4912 }
4913 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4914 }
4915 case 'f':
4916 {
4917 if (LocaleCompare("family",option+1) == 0)
4918 {
4919 if (*option == '+')
4920 break;
4921 i++;
cristybb503372010-05-27 20:51:26 +00004922 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004923 ThrowMogrifyException(OptionError,"MissingArgument",option);
4924 break;
4925 }
4926 if (LocaleCompare("fill",option+1) == 0)
4927 {
4928 if (*option == '+')
4929 break;
4930 i++;
cristybb503372010-05-27 20:51:26 +00004931 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004932 ThrowMogrifyException(OptionError,"MissingArgument",option);
4933 break;
4934 }
4935 if (LocaleCompare("filter",option+1) == 0)
4936 {
cristybb503372010-05-27 20:51:26 +00004937 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004938 filter;
4939
4940 if (*option == '+')
4941 break;
4942 i++;
cristybb503372010-05-27 20:51:26 +00004943 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004944 ThrowMogrifyException(OptionError,"MissingArgument",option);
4945 filter=ParseMagickOption(MagickFilterOptions,MagickFalse,argv[i]);
4946 if (filter < 0)
4947 ThrowMogrifyException(OptionError,"UnrecognizedImageFilter",
4948 argv[i]);
4949 break;
4950 }
4951 if (LocaleCompare("flatten",option+1) == 0)
4952 break;
4953 if (LocaleCompare("flip",option+1) == 0)
4954 break;
4955 if (LocaleCompare("flop",option+1) == 0)
4956 break;
4957 if (LocaleCompare("floodfill",option+1) == 0)
4958 {
4959 if (*option == '+')
4960 break;
4961 i++;
cristybb503372010-05-27 20:51:26 +00004962 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004963 ThrowMogrifyException(OptionError,"MissingArgument",option);
4964 if (IsGeometry(argv[i]) == MagickFalse)
4965 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4966 i++;
cristybb503372010-05-27 20:51:26 +00004967 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004968 ThrowMogrifyException(OptionError,"MissingArgument",option);
4969 break;
4970 }
4971 if (LocaleCompare("font",option+1) == 0)
4972 {
4973 if (*option == '+')
4974 break;
4975 i++;
cristybb503372010-05-27 20:51:26 +00004976 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004977 ThrowMogrifyException(OptionError,"MissingArgument",option);
4978 break;
4979 }
4980 if (LocaleCompare("format",option+1) == 0)
4981 {
4982 (void) CopyMagickString(argv[i]+1,"sans",MaxTextExtent);
4983 (void) CloneString(&format,(char *) NULL);
4984 if (*option == '+')
4985 break;
4986 i++;
cristybb503372010-05-27 20:51:26 +00004987 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004988 ThrowMogrifyException(OptionError,"MissingArgument",option);
4989 (void) CloneString(&format,argv[i]);
4990 (void) CopyMagickString(image_info->filename,format,MaxTextExtent);
4991 (void) ConcatenateMagickString(image_info->filename,":",
4992 MaxTextExtent);
cristyd965a422010-03-03 17:47:35 +00004993 (void) SetImageInfo(image_info,0,exception);
cristy3ed852e2009-09-05 21:47:34 +00004994 if (*image_info->magick == '\0')
4995 ThrowMogrifyException(OptionError,"UnrecognizedImageFormat",
4996 format);
4997 break;
4998 }
4999 if (LocaleCompare("frame",option+1) == 0)
5000 {
5001 if (*option == '+')
5002 break;
5003 i++;
cristybb503372010-05-27 20:51:26 +00005004 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005005 ThrowMogrifyException(OptionError,"MissingArgument",option);
5006 if (IsGeometry(argv[i]) == MagickFalse)
5007 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5008 break;
5009 }
5010 if (LocaleCompare("function",option+1) == 0)
5011 {
cristybb503372010-05-27 20:51:26 +00005012 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005013 op;
5014
5015 if (*option == '+')
5016 break;
5017 i++;
cristybb503372010-05-27 20:51:26 +00005018 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005019 ThrowMogrifyException(OptionError,"MissingArgument",option);
5020 op=ParseMagickOption(MagickFunctionOptions,MagickFalse,argv[i]);
5021 if (op < 0)
5022 ThrowMogrifyException(OptionError,"UnrecognizedFunction",argv[i]);
5023 i++;
cristybb503372010-05-27 20:51:26 +00005024 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005025 ThrowMogrifyException(OptionError,"MissingArgument",option);
5026 break;
5027 }
5028 if (LocaleCompare("fuzz",option+1) == 0)
5029 {
5030 if (*option == '+')
5031 break;
5032 i++;
cristybb503372010-05-27 20:51:26 +00005033 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005034 ThrowMogrifyException(OptionError,"MissingArgument",option);
5035 if (IsGeometry(argv[i]) == MagickFalse)
5036 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5037 break;
5038 }
5039 if (LocaleCompare("fx",option+1) == 0)
5040 {
5041 if (*option == '+')
5042 break;
5043 i++;
cristybb503372010-05-27 20:51:26 +00005044 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005045 ThrowMogrifyException(OptionError,"MissingArgument",option);
5046 break;
5047 }
5048 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5049 }
5050 case 'g':
5051 {
5052 if (LocaleCompare("gamma",option+1) == 0)
5053 {
5054 i++;
cristybb503372010-05-27 20:51:26 +00005055 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005056 ThrowMogrifyException(OptionError,"MissingArgument",option);
5057 if (IsGeometry(argv[i]) == MagickFalse)
5058 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5059 break;
5060 }
5061 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
5062 (LocaleCompare("gaussian",option+1) == 0))
5063 {
5064 i++;
cristybb503372010-05-27 20:51:26 +00005065 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005066 ThrowMogrifyException(OptionError,"MissingArgument",option);
5067 if (IsGeometry(argv[i]) == MagickFalse)
5068 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5069 break;
5070 }
5071 if (LocaleCompare("geometry",option+1) == 0)
5072 {
5073 if (*option == '+')
5074 break;
5075 i++;
cristybb503372010-05-27 20:51:26 +00005076 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005077 ThrowMogrifyException(OptionError,"MissingArgument",option);
5078 if (IsGeometry(argv[i]) == MagickFalse)
5079 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5080 break;
5081 }
5082 if (LocaleCompare("gravity",option+1) == 0)
5083 {
cristybb503372010-05-27 20:51:26 +00005084 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005085 gravity;
5086
5087 if (*option == '+')
5088 break;
5089 i++;
cristybb503372010-05-27 20:51:26 +00005090 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005091 ThrowMogrifyException(OptionError,"MissingArgument",option);
5092 gravity=ParseMagickOption(MagickGravityOptions,MagickFalse,argv[i]);
5093 if (gravity < 0)
5094 ThrowMogrifyException(OptionError,"UnrecognizedGravityType",
5095 argv[i]);
5096 break;
5097 }
5098 if (LocaleCompare("green-primary",option+1) == 0)
5099 {
5100 if (*option == '+')
5101 break;
5102 i++;
cristybb503372010-05-27 20:51:26 +00005103 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005104 ThrowMogrifyException(OptionError,"MissingArgument",option);
5105 if (IsGeometry(argv[i]) == MagickFalse)
5106 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5107 break;
5108 }
5109 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5110 }
5111 case 'h':
5112 {
5113 if (LocaleCompare("hald-clut",option+1) == 0)
5114 break;
5115 if ((LocaleCompare("help",option+1) == 0) ||
5116 (LocaleCompare("-help",option+1) == 0))
5117 return(MogrifyUsage());
5118 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5119 }
5120 case 'i':
5121 {
5122 if (LocaleCompare("identify",option+1) == 0)
5123 break;
5124 if (LocaleCompare("idft",option+1) == 0)
5125 break;
5126 if (LocaleCompare("implode",option+1) == 0)
5127 {
5128 if (*option == '+')
5129 break;
5130 i++;
cristybb503372010-05-27 20:51:26 +00005131 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005132 ThrowMogrifyException(OptionError,"MissingArgument",option);
5133 if (IsGeometry(argv[i]) == MagickFalse)
5134 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5135 break;
5136 }
5137 if (LocaleCompare("intent",option+1) == 0)
5138 {
cristybb503372010-05-27 20:51:26 +00005139 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005140 intent;
5141
5142 if (*option == '+')
5143 break;
5144 i++;
cristybb503372010-05-27 20:51:26 +00005145 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005146 ThrowMogrifyException(OptionError,"MissingArgument",option);
5147 intent=ParseMagickOption(MagickIntentOptions,MagickFalse,argv[i]);
5148 if (intent < 0)
5149 ThrowMogrifyException(OptionError,"UnrecognizedIntentType",
5150 argv[i]);
5151 break;
5152 }
5153 if (LocaleCompare("interlace",option+1) == 0)
5154 {
cristybb503372010-05-27 20:51:26 +00005155 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005156 interlace;
5157
5158 if (*option == '+')
5159 break;
5160 i++;
cristybb503372010-05-27 20:51:26 +00005161 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005162 ThrowMogrifyException(OptionError,"MissingArgument",option);
5163 interlace=ParseMagickOption(MagickInterlaceOptions,MagickFalse,
5164 argv[i]);
5165 if (interlace < 0)
5166 ThrowMogrifyException(OptionError,"UnrecognizedInterlaceType",
5167 argv[i]);
5168 break;
5169 }
cristyb32b90a2009-09-07 21:45:48 +00005170 if (LocaleCompare("interline-spacing",option+1) == 0)
5171 {
5172 if (*option == '+')
5173 break;
5174 i++;
cristybb503372010-05-27 20:51:26 +00005175 if (i == (ssize_t) (argc-1))
cristyb32b90a2009-09-07 21:45:48 +00005176 ThrowMogrifyException(OptionError,"MissingArgument",option);
5177 if (IsGeometry(argv[i]) == MagickFalse)
5178 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5179 break;
5180 }
cristy3ed852e2009-09-05 21:47:34 +00005181 if (LocaleCompare("interpolate",option+1) == 0)
5182 {
cristybb503372010-05-27 20:51:26 +00005183 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005184 interpolate;
5185
5186 if (*option == '+')
5187 break;
5188 i++;
cristybb503372010-05-27 20:51:26 +00005189 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005190 ThrowMogrifyException(OptionError,"MissingArgument",option);
5191 interpolate=ParseMagickOption(MagickInterpolateOptions,MagickFalse,
5192 argv[i]);
5193 if (interpolate < 0)
5194 ThrowMogrifyException(OptionError,"UnrecognizedInterpolateMethod",
5195 argv[i]);
5196 break;
5197 }
5198 if (LocaleCompare("interword-spacing",option+1) == 0)
5199 {
5200 if (*option == '+')
5201 break;
5202 i++;
cristybb503372010-05-27 20:51:26 +00005203 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005204 ThrowMogrifyException(OptionError,"MissingArgument",option);
5205 if (IsGeometry(argv[i]) == MagickFalse)
5206 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5207 break;
5208 }
5209 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5210 }
5211 case 'k':
5212 {
5213 if (LocaleCompare("kerning",option+1) == 0)
5214 {
5215 if (*option == '+')
5216 break;
5217 i++;
cristybb503372010-05-27 20:51:26 +00005218 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005219 ThrowMogrifyException(OptionError,"MissingArgument",option);
5220 if (IsGeometry(argv[i]) == MagickFalse)
5221 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5222 break;
5223 }
5224 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5225 }
5226 case 'l':
5227 {
5228 if (LocaleCompare("label",option+1) == 0)
5229 {
5230 if (*option == '+')
5231 break;
5232 i++;
cristybb503372010-05-27 20:51:26 +00005233 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005234 ThrowMogrifyException(OptionError,"MissingArgument",option);
5235 break;
5236 }
5237 if (LocaleCompare("lat",option+1) == 0)
5238 {
5239 if (*option == '+')
5240 break;
5241 i++;
cristybb503372010-05-27 20:51:26 +00005242 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005243 ThrowMogrifyException(OptionError,"MissingArgument",option);
5244 if (IsGeometry(argv[i]) == MagickFalse)
5245 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5246 }
5247 if (LocaleCompare("layers",option+1) == 0)
5248 {
cristybb503372010-05-27 20:51:26 +00005249 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005250 type;
5251
5252 if (*option == '+')
5253 break;
5254 i++;
cristybb503372010-05-27 20:51:26 +00005255 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005256 ThrowMogrifyException(OptionError,"MissingArgument",option);
5257 type=ParseMagickOption(MagickLayerOptions,MagickFalse,argv[i]);
5258 if (type < 0)
5259 ThrowMogrifyException(OptionError,"UnrecognizedLayerMethod",
5260 argv[i]);
5261 break;
5262 }
5263 if (LocaleCompare("level",option+1) == 0)
5264 {
5265 i++;
cristybb503372010-05-27 20:51:26 +00005266 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005267 ThrowMogrifyException(OptionError,"MissingArgument",option);
5268 if (IsGeometry(argv[i]) == MagickFalse)
5269 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5270 break;
5271 }
5272 if (LocaleCompare("level-colors",option+1) == 0)
5273 {
5274 i++;
cristybb503372010-05-27 20:51:26 +00005275 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005276 ThrowMogrifyException(OptionError,"MissingArgument",option);
5277 break;
5278 }
5279 if (LocaleCompare("linewidth",option+1) == 0)
5280 {
5281 if (*option == '+')
5282 break;
5283 i++;
cristybb503372010-05-27 20:51:26 +00005284 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005285 ThrowMogrifyException(OptionError,"MissingArgument",option);
5286 if (IsGeometry(argv[i]) == MagickFalse)
5287 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5288 break;
5289 }
5290 if (LocaleCompare("limit",option+1) == 0)
5291 {
5292 char
5293 *p;
5294
5295 double
5296 value;
5297
cristybb503372010-05-27 20:51:26 +00005298 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005299 resource;
5300
5301 if (*option == '+')
5302 break;
5303 i++;
cristybb503372010-05-27 20:51:26 +00005304 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005305 ThrowMogrifyException(OptionError,"MissingArgument",option);
5306 resource=ParseMagickOption(MagickResourceOptions,MagickFalse,
5307 argv[i]);
5308 if (resource < 0)
5309 ThrowMogrifyException(OptionError,"UnrecognizedResourceType",
5310 argv[i]);
5311 i++;
cristybb503372010-05-27 20:51:26 +00005312 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005313 ThrowMogrifyException(OptionError,"MissingArgument",option);
5314 value=strtod(argv[i],&p);
cristyda16f162011-02-19 23:52:17 +00005315 (void) value;
cristy3ed852e2009-09-05 21:47:34 +00005316 if ((p == argv[i]) && (LocaleCompare("unlimited",argv[i]) != 0))
5317 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5318 break;
5319 }
5320 if (LocaleCompare("liquid-rescale",option+1) == 0)
5321 {
5322 i++;
cristybb503372010-05-27 20:51:26 +00005323 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005324 ThrowMogrifyException(OptionError,"MissingArgument",option);
5325 if (IsGeometry(argv[i]) == MagickFalse)
5326 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5327 break;
5328 }
5329 if (LocaleCompare("list",option+1) == 0)
5330 {
cristybb503372010-05-27 20:51:26 +00005331 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005332 list;
5333
5334 if (*option == '+')
5335 break;
5336 i++;
cristybb503372010-05-27 20:51:26 +00005337 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005338 ThrowMogrifyException(OptionError,"MissingArgument",option);
5339 list=ParseMagickOption(MagickListOptions,MagickFalse,argv[i]);
5340 if (list < 0)
5341 ThrowMogrifyException(OptionError,"UnrecognizedListType",argv[i]);
cristyaeb2cbc2010-05-07 13:28:58 +00005342 status=MogrifyImageInfo(image_info,(int) (i-j+1),(const char **)
cristy3ed852e2009-09-05 21:47:34 +00005343 argv+j,exception);
cristyaeb2cbc2010-05-07 13:28:58 +00005344 return(status != 0 ? MagickFalse : MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00005345 }
5346 if (LocaleCompare("log",option+1) == 0)
5347 {
5348 if (*option == '+')
5349 break;
5350 i++;
cristybb503372010-05-27 20:51:26 +00005351 if ((i == (ssize_t) argc) ||
cristy3ed852e2009-09-05 21:47:34 +00005352 (strchr(argv[i],'%') == (char *) NULL))
5353 ThrowMogrifyException(OptionError,"MissingArgument",option);
5354 break;
5355 }
5356 if (LocaleCompare("loop",option+1) == 0)
5357 {
5358 if (*option == '+')
5359 break;
5360 i++;
cristybb503372010-05-27 20:51:26 +00005361 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005362 ThrowMogrifyException(OptionError,"MissingArgument",option);
5363 if (IsGeometry(argv[i]) == MagickFalse)
5364 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5365 break;
5366 }
5367 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5368 }
5369 case 'm':
5370 {
5371 if (LocaleCompare("map",option+1) == 0)
5372 {
5373 global_colormap=(*option == '+') ? MagickTrue : MagickFalse;
5374 if (*option == '+')
5375 break;
5376 i++;
cristybb503372010-05-27 20:51:26 +00005377 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005378 ThrowMogrifyException(OptionError,"MissingArgument",option);
5379 break;
5380 }
5381 if (LocaleCompare("mask",option+1) == 0)
5382 {
5383 if (*option == '+')
5384 break;
5385 i++;
cristybb503372010-05-27 20:51:26 +00005386 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005387 ThrowMogrifyException(OptionError,"MissingArgument",option);
5388 break;
5389 }
5390 if (LocaleCompare("matte",option+1) == 0)
5391 break;
5392 if (LocaleCompare("mattecolor",option+1) == 0)
5393 {
5394 if (*option == '+')
5395 break;
5396 i++;
cristybb503372010-05-27 20:51:26 +00005397 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005398 ThrowMogrifyException(OptionError,"MissingArgument",option);
5399 break;
5400 }
cristyf40785b2010-03-06 02:27:27 +00005401 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00005402 break;
cristyf40785b2010-03-06 02:27:27 +00005403 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00005404 break;
cristy3ed852e2009-09-05 21:47:34 +00005405 if (LocaleCompare("modulate",option+1) == 0)
5406 {
5407 if (*option == '+')
5408 break;
5409 i++;
cristybb503372010-05-27 20:51:26 +00005410 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005411 ThrowMogrifyException(OptionError,"MissingArgument",option);
5412 if (IsGeometry(argv[i]) == MagickFalse)
5413 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5414 break;
5415 }
5416 if (LocaleCompare("median",option+1) == 0)
5417 {
5418 if (*option == '+')
5419 break;
5420 i++;
cristybb503372010-05-27 20:51:26 +00005421 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005422 ThrowMogrifyException(OptionError,"MissingArgument",option);
5423 if (IsGeometry(argv[i]) == MagickFalse)
5424 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5425 break;
5426 }
cristy69ec32d2011-02-27 23:57:09 +00005427 if (LocaleCompare("mode",option+1) == 0)
5428 {
5429 if (*option == '+')
5430 break;
5431 i++;
5432 if (i == (ssize_t) argc)
5433 ThrowMogrifyException(OptionError,"MissingArgument",option);
5434 if (IsGeometry(argv[i]) == MagickFalse)
5435 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5436 break;
5437 }
cristy3ed852e2009-09-05 21:47:34 +00005438 if (LocaleCompare("monitor",option+1) == 0)
5439 break;
5440 if (LocaleCompare("monochrome",option+1) == 0)
5441 break;
5442 if (LocaleCompare("morph",option+1) == 0)
5443 {
5444 if (*option == '+')
5445 break;
5446 i++;
cristybb503372010-05-27 20:51:26 +00005447 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005448 ThrowMogrifyException(OptionError,"MissingArgument",option);
5449 if (IsGeometry(argv[i]) == MagickFalse)
5450 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5451 break;
5452 }
anthony29188a82010-01-22 10:12:34 +00005453 if (LocaleCompare("morphology",option+1) == 0)
5454 {
anthony29188a82010-01-22 10:12:34 +00005455 char
5456 token[MaxTextExtent];
5457
cristyb6bd4ad2010-08-08 01:12:27 +00005458 KernelInfo
5459 *kernel_info;
5460
5461 ssize_t
5462 op;
5463
anthony29188a82010-01-22 10:12:34 +00005464 i++;
cristybb503372010-05-27 20:51:26 +00005465 if (i == (ssize_t) argc)
anthony29188a82010-01-22 10:12:34 +00005466 ThrowMogrifyException(OptionError,"MissingArgument",option);
5467 GetMagickToken(argv[i],NULL,token);
5468 op=ParseMagickOption(MagickMorphologyOptions,MagickFalse,token);
5469 if (op < 0)
5470 ThrowMogrifyException(OptionError,"UnrecognizedMorphologyMethod",
cristyf0c78232010-03-15 12:53:40 +00005471 token);
anthony29188a82010-01-22 10:12:34 +00005472 i++;
cristybb503372010-05-27 20:51:26 +00005473 if (i == (ssize_t) (argc-1))
anthony29188a82010-01-22 10:12:34 +00005474 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00005475 kernel_info=AcquireKernelInfo(argv[i]);
5476 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00005477 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00005478 kernel_info=DestroyKernelInfo(kernel_info);
anthony29188a82010-01-22 10:12:34 +00005479 break;
5480 }
cristy3ed852e2009-09-05 21:47:34 +00005481 if (LocaleCompare("mosaic",option+1) == 0)
5482 break;
5483 if (LocaleCompare("motion-blur",option+1) == 0)
5484 {
5485 if (*option == '+')
5486 break;
5487 i++;
cristybb503372010-05-27 20:51:26 +00005488 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005489 ThrowMogrifyException(OptionError,"MissingArgument",option);
5490 if (IsGeometry(argv[i]) == MagickFalse)
5491 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5492 break;
5493 }
5494 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5495 }
5496 case 'n':
5497 {
5498 if (LocaleCompare("negate",option+1) == 0)
5499 break;
5500 if (LocaleCompare("noise",option+1) == 0)
5501 {
5502 i++;
cristybb503372010-05-27 20:51:26 +00005503 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005504 ThrowMogrifyException(OptionError,"MissingArgument",option);
5505 if (*option == '+')
5506 {
cristybb503372010-05-27 20:51:26 +00005507 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005508 noise;
5509
5510 noise=ParseMagickOption(MagickNoiseOptions,MagickFalse,argv[i]);
5511 if (noise < 0)
5512 ThrowMogrifyException(OptionError,"UnrecognizedNoiseType",
5513 argv[i]);
5514 break;
5515 }
5516 if (IsGeometry(argv[i]) == MagickFalse)
5517 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5518 break;
5519 }
5520 if (LocaleCompare("noop",option+1) == 0)
5521 break;
5522 if (LocaleCompare("normalize",option+1) == 0)
5523 break;
5524 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5525 }
5526 case 'o':
5527 {
5528 if (LocaleCompare("opaque",option+1) == 0)
5529 {
cristy3ed852e2009-09-05 21:47:34 +00005530 i++;
cristybb503372010-05-27 20:51:26 +00005531 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005532 ThrowMogrifyException(OptionError,"MissingArgument",option);
5533 break;
5534 }
5535 if (LocaleCompare("ordered-dither",option+1) == 0)
5536 {
5537 if (*option == '+')
5538 break;
5539 i++;
cristybb503372010-05-27 20:51:26 +00005540 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005541 ThrowMogrifyException(OptionError,"MissingArgument",option);
5542 break;
5543 }
5544 if (LocaleCompare("orient",option+1) == 0)
5545 {
cristybb503372010-05-27 20:51:26 +00005546 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005547 orientation;
5548
5549 orientation=UndefinedOrientation;
5550 if (*option == '+')
5551 break;
5552 i++;
cristybb503372010-05-27 20:51:26 +00005553 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005554 ThrowMogrifyException(OptionError,"MissingArgument",option);
5555 orientation=ParseMagickOption(MagickOrientationOptions,MagickFalse,
5556 argv[i]);
5557 if (orientation < 0)
5558 ThrowMogrifyException(OptionError,"UnrecognizedImageOrientation",
5559 argv[i]);
5560 break;
5561 }
5562 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5563 }
5564 case 'p':
5565 {
5566 if (LocaleCompare("page",option+1) == 0)
5567 {
5568 if (*option == '+')
5569 break;
5570 i++;
cristybb503372010-05-27 20:51:26 +00005571 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005572 ThrowMogrifyException(OptionError,"MissingArgument",option);
5573 break;
5574 }
5575 if (LocaleCompare("paint",option+1) == 0)
5576 {
5577 if (*option == '+')
5578 break;
5579 i++;
cristybb503372010-05-27 20:51:26 +00005580 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005581 ThrowMogrifyException(OptionError,"MissingArgument",option);
5582 if (IsGeometry(argv[i]) == MagickFalse)
5583 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5584 break;
5585 }
5586 if (LocaleCompare("path",option+1) == 0)
5587 {
5588 (void) CloneString(&path,(char *) NULL);
5589 if (*option == '+')
5590 break;
5591 i++;
cristybb503372010-05-27 20:51:26 +00005592 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005593 ThrowMogrifyException(OptionError,"MissingArgument",option);
5594 (void) CloneString(&path,argv[i]);
5595 break;
5596 }
5597 if (LocaleCompare("pointsize",option+1) == 0)
5598 {
5599 if (*option == '+')
5600 break;
5601 i++;
cristybb503372010-05-27 20:51:26 +00005602 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005603 ThrowMogrifyException(OptionError,"MissingArgument",option);
5604 if (IsGeometry(argv[i]) == MagickFalse)
5605 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5606 break;
5607 }
5608 if (LocaleCompare("polaroid",option+1) == 0)
5609 {
5610 if (*option == '+')
5611 break;
5612 i++;
cristybb503372010-05-27 20:51:26 +00005613 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005614 ThrowMogrifyException(OptionError,"MissingArgument",option);
5615 if (IsGeometry(argv[i]) == MagickFalse)
5616 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5617 break;
5618 }
5619 if (LocaleCompare("posterize",option+1) == 0)
5620 {
5621 if (*option == '+')
5622 break;
5623 i++;
cristybb503372010-05-27 20:51:26 +00005624 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005625 ThrowMogrifyException(OptionError,"MissingArgument",option);
5626 if (IsGeometry(argv[i]) == MagickFalse)
5627 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5628 break;
5629 }
cristye7f51092010-01-17 00:39:37 +00005630 if (LocaleCompare("precision",option+1) == 0)
5631 {
5632 if (*option == '+')
5633 break;
5634 i++;
cristybb503372010-05-27 20:51:26 +00005635 if (i == (ssize_t) argc)
cristye7f51092010-01-17 00:39:37 +00005636 ThrowMogrifyException(OptionError,"MissingArgument",option);
5637 if (IsGeometry(argv[i]) == MagickFalse)
5638 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5639 break;
5640 }
cristy3ed852e2009-09-05 21:47:34 +00005641 if (LocaleCompare("print",option+1) == 0)
5642 {
5643 if (*option == '+')
5644 break;
5645 i++;
cristybb503372010-05-27 20:51:26 +00005646 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005647 ThrowMogrifyException(OptionError,"MissingArgument",option);
5648 break;
5649 }
5650 if (LocaleCompare("process",option+1) == 0)
5651 {
5652 if (*option == '+')
5653 break;
5654 i++;
cristybb503372010-05-27 20:51:26 +00005655 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005656 ThrowMogrifyException(OptionError,"MissingArgument",option);
5657 break;
5658 }
5659 if (LocaleCompare("profile",option+1) == 0)
5660 {
5661 i++;
cristybb503372010-05-27 20:51:26 +00005662 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005663 ThrowMogrifyException(OptionError,"MissingArgument",option);
5664 break;
5665 }
5666 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5667 }
5668 case 'q':
5669 {
5670 if (LocaleCompare("quality",option+1) == 0)
5671 {
5672 if (*option == '+')
5673 break;
5674 i++;
cristybb503372010-05-27 20:51:26 +00005675 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005676 ThrowMogrifyException(OptionError,"MissingArgument",option);
5677 if (IsGeometry(argv[i]) == MagickFalse)
5678 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5679 break;
5680 }
5681 if (LocaleCompare("quantize",option+1) == 0)
5682 {
cristybb503372010-05-27 20:51:26 +00005683 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005684 colorspace;
5685
5686 if (*option == '+')
5687 break;
5688 i++;
cristybb503372010-05-27 20:51:26 +00005689 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005690 ThrowMogrifyException(OptionError,"MissingArgument",option);
5691 colorspace=ParseMagickOption(MagickColorspaceOptions,MagickFalse,
5692 argv[i]);
5693 if (colorspace < 0)
5694 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
5695 argv[i]);
5696 break;
5697 }
5698 if (LocaleCompare("quiet",option+1) == 0)
5699 break;
5700 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5701 }
5702 case 'r':
5703 {
5704 if (LocaleCompare("radial-blur",option+1) == 0)
5705 {
5706 i++;
cristybb503372010-05-27 20:51:26 +00005707 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005708 ThrowMogrifyException(OptionError,"MissingArgument",option);
5709 if (IsGeometry(argv[i]) == MagickFalse)
5710 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5711 break;
5712 }
5713 if (LocaleCompare("raise",option+1) == 0)
5714 {
5715 i++;
cristybb503372010-05-27 20:51:26 +00005716 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005717 ThrowMogrifyException(OptionError,"MissingArgument",option);
5718 if (IsGeometry(argv[i]) == MagickFalse)
5719 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5720 break;
5721 }
5722 if (LocaleCompare("random-threshold",option+1) == 0)
5723 {
5724 if (*option == '+')
5725 break;
5726 i++;
cristybb503372010-05-27 20:51:26 +00005727 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005728 ThrowMogrifyException(OptionError,"MissingArgument",option);
5729 if (IsGeometry(argv[i]) == MagickFalse)
5730 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5731 break;
5732 }
cristye6365592010-04-02 17:31:23 +00005733 if (LocaleCompare("recolor",option+1) == 0)
5734 {
5735 if (*option == '+')
5736 break;
5737 i++;
cristybb503372010-05-27 20:51:26 +00005738 if (i == (ssize_t) (argc-1))
cristye6365592010-04-02 17:31:23 +00005739 ThrowMogrifyException(OptionError,"MissingArgument",option);
5740 if (IsGeometry(argv[i]) == MagickFalse)
5741 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5742 break;
5743 }
cristy3ed852e2009-09-05 21:47:34 +00005744 if (LocaleCompare("red-primary",option+1) == 0)
5745 {
5746 if (*option == '+')
5747 break;
5748 i++;
cristybb503372010-05-27 20:51:26 +00005749 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005750 ThrowMogrifyException(OptionError,"MissingArgument",option);
5751 if (IsGeometry(argv[i]) == MagickFalse)
5752 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5753 }
cristy9f2083a2010-04-22 19:48:05 +00005754 if (LocaleCompare("regard-warnings",option+1) == 0)
5755 break;
cristy3ed852e2009-09-05 21:47:34 +00005756 if (LocaleCompare("region",option+1) == 0)
5757 {
5758 if (*option == '+')
5759 break;
5760 i++;
cristybb503372010-05-27 20:51:26 +00005761 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005762 ThrowMogrifyException(OptionError,"MissingArgument",option);
5763 if (IsGeometry(argv[i]) == MagickFalse)
5764 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5765 break;
5766 }
cristyf0c78232010-03-15 12:53:40 +00005767 if (LocaleCompare("remap",option+1) == 0)
5768 {
5769 if (*option == '+')
5770 break;
5771 i++;
cristybb503372010-05-27 20:51:26 +00005772 if (i == (ssize_t) (argc-1))
cristyf0c78232010-03-15 12:53:40 +00005773 ThrowMogrifyException(OptionError,"MissingArgument",option);
5774 break;
5775 }
cristy3ed852e2009-09-05 21:47:34 +00005776 if (LocaleCompare("render",option+1) == 0)
5777 break;
5778 if (LocaleCompare("repage",option+1) == 0)
5779 {
5780 if (*option == '+')
5781 break;
5782 i++;
cristybb503372010-05-27 20:51:26 +00005783 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005784 ThrowMogrifyException(OptionError,"MissingArgument",option);
5785 if (IsGeometry(argv[i]) == MagickFalse)
5786 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5787 break;
5788 }
5789 if (LocaleCompare("resample",option+1) == 0)
5790 {
5791 if (*option == '+')
5792 break;
5793 i++;
cristybb503372010-05-27 20:51:26 +00005794 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005795 ThrowMogrifyException(OptionError,"MissingArgument",option);
5796 if (IsGeometry(argv[i]) == MagickFalse)
5797 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5798 break;
5799 }
5800 if (LocaleCompare("resize",option+1) == 0)
5801 {
5802 if (*option == '+')
5803 break;
5804 i++;
cristybb503372010-05-27 20:51:26 +00005805 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005806 ThrowMogrifyException(OptionError,"MissingArgument",option);
5807 if (IsGeometry(argv[i]) == MagickFalse)
5808 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5809 break;
5810 }
cristyebbcfea2011-02-25 02:43:54 +00005811 if (LocaleNCompare("respect-parentheses",option+1,17) == 0)
5812 {
5813 respect_parenthesis=(*option == '-') ? MagickTrue : MagickFalse;
5814 break;
5815 }
cristy3ed852e2009-09-05 21:47:34 +00005816 if (LocaleCompare("reverse",option+1) == 0)
5817 break;
5818 if (LocaleCompare("roll",option+1) == 0)
5819 {
5820 if (*option == '+')
5821 break;
5822 i++;
cristybb503372010-05-27 20:51:26 +00005823 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005824 ThrowMogrifyException(OptionError,"MissingArgument",option);
5825 if (IsGeometry(argv[i]) == MagickFalse)
5826 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5827 break;
5828 }
5829 if (LocaleCompare("rotate",option+1) == 0)
5830 {
5831 i++;
cristybb503372010-05-27 20:51:26 +00005832 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005833 ThrowMogrifyException(OptionError,"MissingArgument",option);
5834 if (IsGeometry(argv[i]) == MagickFalse)
5835 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5836 break;
5837 }
5838 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5839 }
5840 case 's':
5841 {
5842 if (LocaleCompare("sample",option+1) == 0)
5843 {
5844 if (*option == '+')
5845 break;
5846 i++;
cristybb503372010-05-27 20:51:26 +00005847 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005848 ThrowMogrifyException(OptionError,"MissingArgument",option);
5849 if (IsGeometry(argv[i]) == MagickFalse)
5850 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5851 break;
5852 }
5853 if (LocaleCompare("sampling-factor",option+1) == 0)
5854 {
5855 if (*option == '+')
5856 break;
5857 i++;
cristybb503372010-05-27 20:51:26 +00005858 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005859 ThrowMogrifyException(OptionError,"MissingArgument",option);
5860 if (IsGeometry(argv[i]) == MagickFalse)
5861 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5862 break;
5863 }
5864 if (LocaleCompare("scale",option+1) == 0)
5865 {
5866 if (*option == '+')
5867 break;
5868 i++;
cristybb503372010-05-27 20:51:26 +00005869 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005870 ThrowMogrifyException(OptionError,"MissingArgument",option);
5871 if (IsGeometry(argv[i]) == MagickFalse)
5872 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5873 break;
5874 }
5875 if (LocaleCompare("scene",option+1) == 0)
5876 {
5877 if (*option == '+')
5878 break;
5879 i++;
cristybb503372010-05-27 20:51:26 +00005880 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005881 ThrowMogrifyException(OptionError,"MissingArgument",option);
5882 if (IsGeometry(argv[i]) == MagickFalse)
5883 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5884 break;
5885 }
5886 if (LocaleCompare("seed",option+1) == 0)
5887 {
5888 if (*option == '+')
5889 break;
5890 i++;
cristybb503372010-05-27 20:51:26 +00005891 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005892 ThrowMogrifyException(OptionError,"MissingArgument",option);
5893 if (IsGeometry(argv[i]) == MagickFalse)
5894 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5895 break;
5896 }
5897 if (LocaleCompare("segment",option+1) == 0)
5898 {
5899 if (*option == '+')
5900 break;
5901 i++;
cristybb503372010-05-27 20:51:26 +00005902 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005903 ThrowMogrifyException(OptionError,"MissingArgument",option);
5904 if (IsGeometry(argv[i]) == MagickFalse)
5905 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5906 break;
5907 }
5908 if (LocaleCompare("selective-blur",option+1) == 0)
5909 {
5910 i++;
cristybb503372010-05-27 20:51:26 +00005911 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005912 ThrowMogrifyException(OptionError,"MissingArgument",option);
5913 if (IsGeometry(argv[i]) == MagickFalse)
5914 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5915 break;
5916 }
5917 if (LocaleCompare("separate",option+1) == 0)
5918 break;
5919 if (LocaleCompare("sepia-tone",option+1) == 0)
5920 {
5921 if (*option == '+')
5922 break;
5923 i++;
cristybb503372010-05-27 20:51:26 +00005924 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005925 ThrowMogrifyException(OptionError,"MissingArgument",option);
5926 if (IsGeometry(argv[i]) == MagickFalse)
5927 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5928 break;
5929 }
5930 if (LocaleCompare("set",option+1) == 0)
5931 {
5932 i++;
cristybb503372010-05-27 20:51:26 +00005933 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005934 ThrowMogrifyException(OptionError,"MissingArgument",option);
5935 if (*option == '+')
5936 break;
5937 i++;
cristybb503372010-05-27 20:51:26 +00005938 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005939 ThrowMogrifyException(OptionError,"MissingArgument",option);
5940 break;
5941 }
5942 if (LocaleCompare("shade",option+1) == 0)
5943 {
5944 i++;
cristybb503372010-05-27 20:51:26 +00005945 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005946 ThrowMogrifyException(OptionError,"MissingArgument",option);
5947 if (IsGeometry(argv[i]) == MagickFalse)
5948 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5949 break;
5950 }
5951 if (LocaleCompare("shadow",option+1) == 0)
5952 {
5953 if (*option == '+')
5954 break;
5955 i++;
cristybb503372010-05-27 20:51:26 +00005956 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005957 ThrowMogrifyException(OptionError,"MissingArgument",option);
5958 if (IsGeometry(argv[i]) == MagickFalse)
5959 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5960 break;
5961 }
5962 if (LocaleCompare("sharpen",option+1) == 0)
5963 {
5964 i++;
cristybb503372010-05-27 20:51:26 +00005965 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005966 ThrowMogrifyException(OptionError,"MissingArgument",option);
5967 if (IsGeometry(argv[i]) == MagickFalse)
5968 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5969 break;
5970 }
5971 if (LocaleCompare("shave",option+1) == 0)
5972 {
5973 if (*option == '+')
5974 break;
5975 i++;
cristybb503372010-05-27 20:51:26 +00005976 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005977 ThrowMogrifyException(OptionError,"MissingArgument",option);
5978 if (IsGeometry(argv[i]) == MagickFalse)
5979 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5980 break;
5981 }
5982 if (LocaleCompare("shear",option+1) == 0)
5983 {
5984 i++;
cristybb503372010-05-27 20:51:26 +00005985 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005986 ThrowMogrifyException(OptionError,"MissingArgument",option);
5987 if (IsGeometry(argv[i]) == MagickFalse)
5988 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5989 break;
5990 }
5991 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
5992 {
5993 i++;
cristybb503372010-05-27 20:51:26 +00005994 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005995 ThrowMogrifyException(OptionError,"MissingArgument",option);
5996 if (IsGeometry(argv[i]) == MagickFalse)
5997 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5998 break;
5999 }
6000 if (LocaleCompare("size",option+1) == 0)
6001 {
6002 if (*option == '+')
6003 break;
6004 i++;
cristybb503372010-05-27 20:51:26 +00006005 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006006 ThrowMogrifyException(OptionError,"MissingArgument",option);
6007 if (IsGeometry(argv[i]) == MagickFalse)
6008 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6009 break;
6010 }
6011 if (LocaleCompare("sketch",option+1) == 0)
6012 {
6013 if (*option == '+')
6014 break;
6015 i++;
cristybb503372010-05-27 20:51:26 +00006016 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006017 ThrowMogrifyException(OptionError,"MissingArgument",option);
6018 if (IsGeometry(argv[i]) == MagickFalse)
6019 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6020 break;
6021 }
cristy4285d782011-02-09 20:12:28 +00006022 if (LocaleCompare("smush",option+1) == 0)
6023 {
cristy4285d782011-02-09 20:12:28 +00006024 i++;
6025 if (i == (ssize_t) argc)
6026 ThrowMogrifyException(OptionError,"MissingArgument",option);
6027 if (IsGeometry(argv[i]) == MagickFalse)
6028 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristy4285d782011-02-09 20:12:28 +00006029 i++;
6030 break;
6031 }
cristy3ed852e2009-09-05 21:47:34 +00006032 if (LocaleCompare("solarize",option+1) == 0)
6033 {
6034 if (*option == '+')
6035 break;
6036 i++;
cristybb503372010-05-27 20:51:26 +00006037 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006038 ThrowMogrifyException(OptionError,"MissingArgument",option);
6039 if (IsGeometry(argv[i]) == MagickFalse)
6040 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6041 break;
6042 }
6043 if (LocaleCompare("sparse-color",option+1) == 0)
6044 {
cristybb503372010-05-27 20:51:26 +00006045 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006046 op;
6047
6048 i++;
cristybb503372010-05-27 20:51:26 +00006049 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006050 ThrowMogrifyException(OptionError,"MissingArgument",option);
6051 op=ParseMagickOption(MagickSparseColorOptions,MagickFalse,argv[i]);
6052 if (op < 0)
6053 ThrowMogrifyException(OptionError,"UnrecognizedSparseColorMethod",
6054 argv[i]);
6055 i++;
cristybb503372010-05-27 20:51:26 +00006056 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006057 ThrowMogrifyException(OptionError,"MissingArgument",option);
6058 break;
6059 }
6060 if (LocaleCompare("spread",option+1) == 0)
6061 {
6062 if (*option == '+')
6063 break;
6064 i++;
cristybb503372010-05-27 20:51:26 +00006065 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006066 ThrowMogrifyException(OptionError,"MissingArgument",option);
6067 if (IsGeometry(argv[i]) == MagickFalse)
6068 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6069 break;
6070 }
cristy0834d642011-03-18 18:26:08 +00006071 if (LocaleCompare("statistic",option+1) == 0)
6072 {
6073 ssize_t
6074 op;
6075
6076 if (*option == '+')
6077 break;
6078 i++;
6079 if (i == (ssize_t) argc)
6080 ThrowMogrifyException(OptionError,"MissingArgument",option);
6081 op=ParseMagickOption(MagickStatisticOptions,MagickFalse,argv[i]);
6082 if (op < 0)
6083 ThrowMogrifyException(OptionError,"UnrecognizedStatisticType",
6084 argv[i]);
6085 i++;
6086 if (i == (ssize_t) (argc-1))
6087 ThrowMogrifyException(OptionError,"MissingArgument",option);
6088 if (IsGeometry(argv[i]) == MagickFalse)
6089 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6090 break;
6091 }
cristy3ed852e2009-09-05 21:47:34 +00006092 if (LocaleCompare("stretch",option+1) == 0)
6093 {
cristybb503372010-05-27 20:51:26 +00006094 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006095 stretch;
6096
6097 if (*option == '+')
6098 break;
6099 i++;
cristybb503372010-05-27 20:51:26 +00006100 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006101 ThrowMogrifyException(OptionError,"MissingArgument",option);
6102 stretch=ParseMagickOption(MagickStretchOptions,MagickFalse,argv[i]);
6103 if (stretch < 0)
6104 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
6105 argv[i]);
6106 break;
6107 }
6108 if (LocaleCompare("strip",option+1) == 0)
6109 break;
6110 if (LocaleCompare("stroke",option+1) == 0)
6111 {
6112 if (*option == '+')
6113 break;
6114 i++;
cristybb503372010-05-27 20:51:26 +00006115 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006116 ThrowMogrifyException(OptionError,"MissingArgument",option);
6117 break;
6118 }
6119 if (LocaleCompare("strokewidth",option+1) == 0)
6120 {
6121 if (*option == '+')
6122 break;
6123 i++;
cristybb503372010-05-27 20:51:26 +00006124 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006125 ThrowMogrifyException(OptionError,"MissingArgument",option);
6126 if (IsGeometry(argv[i]) == MagickFalse)
6127 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6128 break;
6129 }
6130 if (LocaleCompare("style",option+1) == 0)
6131 {
cristybb503372010-05-27 20:51:26 +00006132 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006133 style;
6134
6135 if (*option == '+')
6136 break;
6137 i++;
cristybb503372010-05-27 20:51:26 +00006138 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006139 ThrowMogrifyException(OptionError,"MissingArgument",option);
6140 style=ParseMagickOption(MagickStyleOptions,MagickFalse,argv[i]);
6141 if (style < 0)
6142 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
6143 argv[i]);
6144 break;
6145 }
6146 if (LocaleCompare("swirl",option+1) == 0)
6147 {
6148 if (*option == '+')
6149 break;
6150 i++;
cristybb503372010-05-27 20:51:26 +00006151 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006152 ThrowMogrifyException(OptionError,"MissingArgument",option);
6153 if (IsGeometry(argv[i]) == MagickFalse)
6154 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6155 break;
6156 }
cristyd9a29192010-10-16 16:49:53 +00006157 if (LocaleCompare("synchronize",option+1) == 0)
6158 break;
cristy3ed852e2009-09-05 21:47:34 +00006159 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6160 }
6161 case 't':
6162 {
6163 if (LocaleCompare("taint",option+1) == 0)
6164 break;
6165 if (LocaleCompare("texture",option+1) == 0)
6166 {
6167 if (*option == '+')
6168 break;
6169 i++;
cristybb503372010-05-27 20:51:26 +00006170 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006171 ThrowMogrifyException(OptionError,"MissingArgument",option);
6172 break;
6173 }
6174 if (LocaleCompare("tile",option+1) == 0)
6175 {
6176 if (*option == '+')
6177 break;
6178 i++;
cristybb503372010-05-27 20:51:26 +00006179 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006180 ThrowMogrifyException(OptionError,"MissingArgument",option);
6181 break;
6182 }
6183 if (LocaleCompare("tile-offset",option+1) == 0)
6184 {
6185 if (*option == '+')
6186 break;
6187 i++;
cristybb503372010-05-27 20:51:26 +00006188 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006189 ThrowMogrifyException(OptionError,"MissingArgument",option);
6190 if (IsGeometry(argv[i]) == MagickFalse)
6191 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6192 break;
6193 }
6194 if (LocaleCompare("tint",option+1) == 0)
6195 {
6196 if (*option == '+')
6197 break;
6198 i++;
cristybb503372010-05-27 20:51:26 +00006199 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006200 ThrowMogrifyException(OptionError,"MissingArgument",option);
6201 if (IsGeometry(argv[i]) == MagickFalse)
6202 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6203 break;
6204 }
6205 if (LocaleCompare("transform",option+1) == 0)
6206 break;
6207 if (LocaleCompare("transpose",option+1) == 0)
6208 break;
6209 if (LocaleCompare("transverse",option+1) == 0)
6210 break;
6211 if (LocaleCompare("threshold",option+1) == 0)
6212 {
6213 if (*option == '+')
6214 break;
6215 i++;
cristybb503372010-05-27 20:51:26 +00006216 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006217 ThrowMogrifyException(OptionError,"MissingArgument",option);
6218 if (IsGeometry(argv[i]) == MagickFalse)
6219 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6220 break;
6221 }
6222 if (LocaleCompare("thumbnail",option+1) == 0)
6223 {
6224 if (*option == '+')
6225 break;
6226 i++;
cristybb503372010-05-27 20:51:26 +00006227 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006228 ThrowMogrifyException(OptionError,"MissingArgument",option);
6229 if (IsGeometry(argv[i]) == MagickFalse)
6230 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6231 break;
6232 }
6233 if (LocaleCompare("transparent",option+1) == 0)
6234 {
6235 i++;
cristybb503372010-05-27 20:51:26 +00006236 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006237 ThrowMogrifyException(OptionError,"MissingArgument",option);
6238 break;
6239 }
6240 if (LocaleCompare("transparent-color",option+1) == 0)
6241 {
6242 if (*option == '+')
6243 break;
6244 i++;
cristybb503372010-05-27 20:51:26 +00006245 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006246 ThrowMogrifyException(OptionError,"MissingArgument",option);
6247 break;
6248 }
6249 if (LocaleCompare("treedepth",option+1) == 0)
6250 {
6251 if (*option == '+')
6252 break;
6253 i++;
cristybb503372010-05-27 20:51:26 +00006254 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006255 ThrowMogrifyException(OptionError,"MissingArgument",option);
6256 if (IsGeometry(argv[i]) == MagickFalse)
6257 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6258 break;
6259 }
6260 if (LocaleCompare("trim",option+1) == 0)
6261 break;
6262 if (LocaleCompare("type",option+1) == 0)
6263 {
cristybb503372010-05-27 20:51:26 +00006264 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006265 type;
6266
6267 if (*option == '+')
6268 break;
6269 i++;
cristybb503372010-05-27 20:51:26 +00006270 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006271 ThrowMogrifyException(OptionError,"MissingArgument",option);
6272 type=ParseMagickOption(MagickTypeOptions,MagickFalse,argv[i]);
6273 if (type < 0)
6274 ThrowMogrifyException(OptionError,"UnrecognizedImageType",
6275 argv[i]);
6276 break;
6277 }
6278 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6279 }
6280 case 'u':
6281 {
6282 if (LocaleCompare("undercolor",option+1) == 0)
6283 {
6284 if (*option == '+')
6285 break;
6286 i++;
cristybb503372010-05-27 20:51:26 +00006287 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006288 ThrowMogrifyException(OptionError,"MissingArgument",option);
6289 break;
6290 }
6291 if (LocaleCompare("unique-colors",option+1) == 0)
6292 break;
6293 if (LocaleCompare("units",option+1) == 0)
6294 {
cristybb503372010-05-27 20:51:26 +00006295 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006296 units;
6297
6298 if (*option == '+')
6299 break;
6300 i++;
cristybb503372010-05-27 20:51:26 +00006301 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006302 ThrowMogrifyException(OptionError,"MissingArgument",option);
6303 units=ParseMagickOption(MagickResolutionOptions,MagickFalse,
6304 argv[i]);
6305 if (units < 0)
6306 ThrowMogrifyException(OptionError,"UnrecognizedUnitsType",
6307 argv[i]);
6308 break;
6309 }
6310 if (LocaleCompare("unsharp",option+1) == 0)
6311 {
6312 i++;
cristybb503372010-05-27 20:51:26 +00006313 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006314 ThrowMogrifyException(OptionError,"MissingArgument",option);
6315 if (IsGeometry(argv[i]) == MagickFalse)
6316 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6317 break;
6318 }
6319 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6320 }
6321 case 'v':
6322 {
6323 if (LocaleCompare("verbose",option+1) == 0)
6324 {
6325 image_info->verbose=(*option == '-') ? MagickTrue : MagickFalse;
6326 break;
6327 }
6328 if ((LocaleCompare("version",option+1) == 0) ||
6329 (LocaleCompare("-version",option+1) == 0))
6330 {
6331 (void) fprintf(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +00006332 GetMagickVersion((size_t *) NULL));
cristy610b2e22009-10-22 14:59:43 +00006333 (void) fprintf(stdout,"Copyright: %s\n",GetMagickCopyright());
6334 (void) fprintf(stdout,"Features: %s\n\n",GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00006335 break;
6336 }
6337 if (LocaleCompare("view",option+1) == 0)
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 break;
6345 }
6346 if (LocaleCompare("vignette",option+1) == 0)
6347 {
6348 if (*option == '+')
6349 break;
6350 i++;
cristybb503372010-05-27 20:51:26 +00006351 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006352 ThrowMogrifyException(OptionError,"MissingArgument",option);
6353 if (IsGeometry(argv[i]) == MagickFalse)
6354 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6355 break;
6356 }
6357 if (LocaleCompare("virtual-pixel",option+1) == 0)
6358 {
cristybb503372010-05-27 20:51:26 +00006359 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006360 method;
6361
6362 if (*option == '+')
6363 break;
6364 i++;
cristybb503372010-05-27 20:51:26 +00006365 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006366 ThrowMogrifyException(OptionError,"MissingArgument",option);
6367 method=ParseMagickOption(MagickVirtualPixelOptions,MagickFalse,
6368 argv[i]);
6369 if (method < 0)
6370 ThrowMogrifyException(OptionError,
6371 "UnrecognizedVirtualPixelMethod",argv[i]);
6372 break;
6373 }
6374 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6375 }
6376 case 'w':
6377 {
6378 if (LocaleCompare("wave",option+1) == 0)
6379 {
6380 i++;
cristybb503372010-05-27 20:51:26 +00006381 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006382 ThrowMogrifyException(OptionError,"MissingArgument",option);
6383 if (IsGeometry(argv[i]) == MagickFalse)
6384 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6385 break;
6386 }
6387 if (LocaleCompare("weight",option+1) == 0)
6388 {
6389 if (*option == '+')
6390 break;
6391 i++;
cristybb503372010-05-27 20:51:26 +00006392 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006393 ThrowMogrifyException(OptionError,"MissingArgument",option);
6394 break;
6395 }
6396 if (LocaleCompare("white-point",option+1) == 0)
6397 {
6398 if (*option == '+')
6399 break;
6400 i++;
cristybb503372010-05-27 20:51:26 +00006401 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006402 ThrowMogrifyException(OptionError,"MissingArgument",option);
6403 if (IsGeometry(argv[i]) == MagickFalse)
6404 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6405 break;
6406 }
6407 if (LocaleCompare("white-threshold",option+1) == 0)
6408 {
6409 if (*option == '+')
6410 break;
6411 i++;
cristybb503372010-05-27 20:51:26 +00006412 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006413 ThrowMogrifyException(OptionError,"MissingArgument",option);
6414 if (IsGeometry(argv[i]) == MagickFalse)
6415 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6416 break;
6417 }
6418 if (LocaleCompare("write",option+1) == 0)
6419 {
6420 i++;
cristybb503372010-05-27 20:51:26 +00006421 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006422 ThrowMogrifyException(OptionError,"MissingArgument",option);
6423 break;
6424 }
6425 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6426 }
6427 case '?':
6428 break;
6429 default:
6430 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6431 }
6432 fire=ParseMagickOption(MagickImageListOptions,MagickFalse,option+1) < 0 ?
6433 MagickFalse : MagickTrue;
6434 if (fire != MagickFalse)
6435 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
6436 }
6437 if (k != 0)
6438 ThrowMogrifyException(OptionError,"UnbalancedParenthesis",argv[i]);
cristycee97112010-05-28 00:44:52 +00006439 if (i != (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006440 ThrowMogrifyException(OptionError,"MissingAnImageFilename",argv[i]);
6441 DestroyMogrify();
6442 return(status != 0 ? MagickTrue : MagickFalse);
6443}
6444
6445/*
6446%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6447% %
6448% %
6449% %
6450+ M o g r i f y I m a g e I n f o %
6451% %
6452% %
6453% %
6454%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6455%
6456% MogrifyImageInfo() applies image processing settings to the image as
6457% prescribed by command line options.
6458%
6459% The format of the MogrifyImageInfo method is:
6460%
6461% MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,const int argc,
6462% const char **argv,ExceptionInfo *exception)
6463%
6464% A description of each parameter follows:
6465%
6466% o image_info: the image info..
6467%
6468% o argc: Specifies a pointer to an integer describing the number of
6469% elements in the argument vector.
6470%
6471% o argv: Specifies a pointer to a text array containing the command line
6472% arguments.
6473%
6474% o exception: return any errors or warnings in this structure.
6475%
6476*/
6477WandExport MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,
6478 const int argc,const char **argv,ExceptionInfo *exception)
6479{
6480 const char
6481 *option;
6482
6483 GeometryInfo
6484 geometry_info;
6485
cristybb503372010-05-27 20:51:26 +00006486 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006487 count;
6488
cristybb503372010-05-27 20:51:26 +00006489 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006490 i;
6491
6492 /*
6493 Initialize method variables.
6494 */
6495 assert(image_info != (ImageInfo *) NULL);
6496 assert(image_info->signature == MagickSignature);
6497 if (image_info->debug != MagickFalse)
6498 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
6499 image_info->filename);
6500 if (argc < 0)
6501 return(MagickTrue);
6502 /*
6503 Set the image settings.
6504 */
cristybb503372010-05-27 20:51:26 +00006505 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00006506 {
6507 option=argv[i];
6508 if (IsMagickOption(option) == MagickFalse)
6509 continue;
6510 count=MagickMax(ParseMagickOption(MagickCommandOptions,MagickFalse,option),
6511 0L);
cristycee97112010-05-28 00:44:52 +00006512 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006513 break;
6514 switch (*(option+1))
6515 {
6516 case 'a':
6517 {
6518 if (LocaleCompare("adjoin",option+1) == 0)
6519 {
6520 image_info->adjoin=(*option == '-') ? MagickTrue : MagickFalse;
6521 break;
6522 }
6523 if (LocaleCompare("antialias",option+1) == 0)
6524 {
6525 image_info->antialias=(*option == '-') ? MagickTrue : MagickFalse;
6526 break;
6527 }
6528 if (LocaleCompare("attenuate",option+1) == 0)
6529 {
6530 if (*option == '+')
6531 {
6532 (void) DeleteImageOption(image_info,option+1);
6533 break;
6534 }
6535 (void) SetImageOption(image_info,option+1,argv[i+1]);
6536 break;
6537 }
6538 if (LocaleCompare("authenticate",option+1) == 0)
6539 {
6540 if (*option == '+')
6541 (void) CloneString(&image_info->authenticate,(char *) NULL);
6542 else
6543 (void) CloneString(&image_info->authenticate,argv[i+1]);
6544 break;
6545 }
6546 break;
6547 }
6548 case 'b':
6549 {
6550 if (LocaleCompare("background",option+1) == 0)
6551 {
6552 if (*option == '+')
6553 {
6554 (void) DeleteImageOption(image_info,option+1);
6555 (void) QueryColorDatabase(BackgroundColor,
6556 &image_info->background_color,exception);
6557 break;
6558 }
6559 (void) SetImageOption(image_info,option+1,argv[i+1]);
6560 (void) QueryColorDatabase(argv[i+1],&image_info->background_color,
6561 exception);
6562 break;
6563 }
6564 if (LocaleCompare("bias",option+1) == 0)
6565 {
6566 if (*option == '+')
6567 {
6568 (void) SetImageOption(image_info,option+1,"0.0");
6569 break;
6570 }
6571 (void) SetImageOption(image_info,option+1,argv[i+1]);
6572 break;
6573 }
6574 if (LocaleCompare("black-point-compensation",option+1) == 0)
6575 {
6576 if (*option == '+')
6577 {
6578 (void) SetImageOption(image_info,option+1,"false");
6579 break;
6580 }
6581 (void) SetImageOption(image_info,option+1,"true");
6582 break;
6583 }
6584 if (LocaleCompare("blue-primary",option+1) == 0)
6585 {
6586 if (*option == '+')
6587 {
6588 (void) SetImageOption(image_info,option+1,"0.0");
6589 break;
6590 }
6591 (void) SetImageOption(image_info,option+1,argv[i+1]);
6592 break;
6593 }
6594 if (LocaleCompare("bordercolor",option+1) == 0)
6595 {
6596 if (*option == '+')
6597 {
6598 (void) DeleteImageOption(image_info,option+1);
6599 (void) QueryColorDatabase(BorderColor,&image_info->border_color,
6600 exception);
6601 break;
6602 }
6603 (void) QueryColorDatabase(argv[i+1],&image_info->border_color,
6604 exception);
6605 (void) SetImageOption(image_info,option+1,argv[i+1]);
6606 break;
6607 }
6608 if (LocaleCompare("box",option+1) == 0)
6609 {
6610 if (*option == '+')
6611 {
6612 (void) SetImageOption(image_info,"undercolor","none");
6613 break;
6614 }
6615 (void) SetImageOption(image_info,"undercolor",argv[i+1]);
6616 break;
6617 }
6618 break;
6619 }
6620 case 'c':
6621 {
6622 if (LocaleCompare("cache",option+1) == 0)
6623 {
6624 MagickSizeType
6625 limit;
6626
6627 limit=MagickResourceInfinity;
6628 if (LocaleCompare("unlimited",argv[i+1]) != 0)
cristyf2f27272009-12-17 14:48:46 +00006629 limit=(MagickSizeType) SiPrefixToDouble(argv[i+1],100.0);
cristy3ed852e2009-09-05 21:47:34 +00006630 (void) SetMagickResourceLimit(MemoryResource,limit);
6631 (void) SetMagickResourceLimit(MapResource,2*limit);
6632 break;
6633 }
6634 if (LocaleCompare("caption",option+1) == 0)
6635 {
6636 if (*option == '+')
6637 {
6638 (void) DeleteImageOption(image_info,option+1);
6639 break;
6640 }
6641 (void) SetImageOption(image_info,option+1,argv[i+1]);
6642 break;
6643 }
6644 if (LocaleCompare("channel",option+1) == 0)
6645 {
6646 if (*option == '+')
6647 {
6648 image_info->channel=DefaultChannels;
6649 break;
6650 }
6651 image_info->channel=(ChannelType) ParseChannelOption(argv[i+1]);
6652 break;
6653 }
6654 if (LocaleCompare("colors",option+1) == 0)
6655 {
cristye27293e2009-12-18 02:53:20 +00006656 image_info->colors=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006657 break;
6658 }
6659 if (LocaleCompare("colorspace",option+1) == 0)
6660 {
6661 if (*option == '+')
6662 {
6663 image_info->colorspace=UndefinedColorspace;
6664 (void) SetImageOption(image_info,option+1,"undefined");
6665 break;
6666 }
6667 image_info->colorspace=(ColorspaceType) ParseMagickOption(
6668 MagickColorspaceOptions,MagickFalse,argv[i+1]);
6669 (void) SetImageOption(image_info,option+1,argv[i+1]);
6670 break;
6671 }
6672 if (LocaleCompare("compress",option+1) == 0)
6673 {
6674 if (*option == '+')
6675 {
6676 image_info->compression=UndefinedCompression;
6677 (void) SetImageOption(image_info,option+1,"undefined");
6678 break;
6679 }
6680 image_info->compression=(CompressionType) ParseMagickOption(
6681 MagickCompressOptions,MagickFalse,argv[i+1]);
6682 (void) SetImageOption(image_info,option+1,argv[i+1]);
6683 break;
6684 }
6685 if (LocaleCompare("comment",option+1) == 0)
6686 {
6687 if (*option == '+')
6688 {
6689 (void) DeleteImageOption(image_info,option+1);
6690 break;
6691 }
6692 (void) SetImageOption(image_info,option+1,argv[i+1]);
6693 break;
6694 }
6695 if (LocaleCompare("compose",option+1) == 0)
6696 {
6697 if (*option == '+')
6698 {
6699 (void) SetImageOption(image_info,option+1,"undefined");
6700 break;
6701 }
6702 (void) SetImageOption(image_info,option+1,argv[i+1]);
6703 break;
6704 }
6705 if (LocaleCompare("compress",option+1) == 0)
6706 {
6707 if (*option == '+')
6708 {
6709 image_info->compression=UndefinedCompression;
6710 (void) SetImageOption(image_info,option+1,"undefined");
6711 break;
6712 }
6713 image_info->compression=(CompressionType) ParseMagickOption(
6714 MagickCompressOptions,MagickFalse,argv[i+1]);
6715 (void) SetImageOption(image_info,option+1,argv[i+1]);
6716 break;
6717 }
6718 break;
6719 }
6720 case 'd':
6721 {
6722 if (LocaleCompare("debug",option+1) == 0)
6723 {
6724 if (*option == '+')
6725 (void) SetLogEventMask("none");
6726 else
6727 (void) SetLogEventMask(argv[i+1]);
6728 image_info->debug=IsEventLogging();
6729 break;
6730 }
6731 if (LocaleCompare("define",option+1) == 0)
6732 {
6733 if (*option == '+')
6734 {
6735 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6736 (void) DeleteImageRegistry(argv[i+1]+9);
6737 else
6738 (void) DeleteImageOption(image_info,argv[i+1]);
6739 break;
6740 }
6741 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6742 {
6743 (void) DefineImageRegistry(StringRegistryType,argv[i+1]+9,
6744 exception);
6745 break;
6746 }
6747 (void) DefineImageOption(image_info,argv[i+1]);
6748 break;
6749 }
6750 if (LocaleCompare("delay",option+1) == 0)
6751 {
6752 if (*option == '+')
6753 {
6754 (void) SetImageOption(image_info,option+1,"0");
6755 break;
6756 }
6757 (void) SetImageOption(image_info,option+1,argv[i+1]);
6758 break;
6759 }
6760 if (LocaleCompare("density",option+1) == 0)
6761 {
6762 /*
6763 Set image density.
6764 */
6765 if (*option == '+')
6766 {
6767 if (image_info->density != (char *) NULL)
6768 image_info->density=DestroyString(image_info->density);
6769 (void) SetImageOption(image_info,option+1,"72");
6770 break;
6771 }
6772 (void) CloneString(&image_info->density,argv[i+1]);
6773 (void) SetImageOption(image_info,option+1,argv[i+1]);
6774 break;
6775 }
6776 if (LocaleCompare("depth",option+1) == 0)
6777 {
6778 if (*option == '+')
6779 {
6780 image_info->depth=MAGICKCORE_QUANTUM_DEPTH;
6781 break;
6782 }
cristye27293e2009-12-18 02:53:20 +00006783 image_info->depth=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006784 break;
6785 }
cristyc9b12952010-03-28 01:12:28 +00006786 if (LocaleCompare("direction",option+1) == 0)
6787 {
6788 if (*option == '+')
6789 {
6790 (void) SetImageOption(image_info,option+1,"undefined");
6791 break;
6792 }
6793 (void) SetImageOption(image_info,option+1,argv[i+1]);
6794 break;
6795 }
cristy3ed852e2009-09-05 21:47:34 +00006796 if (LocaleCompare("display",option+1) == 0)
6797 {
6798 if (*option == '+')
6799 {
6800 if (image_info->server_name != (char *) NULL)
6801 image_info->server_name=DestroyString(
6802 image_info->server_name);
6803 break;
6804 }
6805 (void) CloneString(&image_info->server_name,argv[i+1]);
6806 break;
6807 }
6808 if (LocaleCompare("dispose",option+1) == 0)
6809 {
6810 if (*option == '+')
6811 {
6812 (void) SetImageOption(image_info,option+1,"undefined");
6813 break;
6814 }
6815 (void) SetImageOption(image_info,option+1,argv[i+1]);
6816 break;
6817 }
6818 if (LocaleCompare("dither",option+1) == 0)
6819 {
6820 if (*option == '+')
6821 {
6822 image_info->dither=MagickFalse;
cristyd5acfd12010-06-15 00:11:38 +00006823 (void) SetImageOption(image_info,option+1,"none");
cristy3ed852e2009-09-05 21:47:34 +00006824 break;
6825 }
6826 (void) SetImageOption(image_info,option+1,argv[i+1]);
6827 image_info->dither=MagickTrue;
6828 break;
6829 }
6830 break;
6831 }
6832 case 'e':
6833 {
6834 if (LocaleCompare("encoding",option+1) == 0)
6835 {
6836 if (*option == '+')
6837 {
6838 (void) SetImageOption(image_info,option+1,"undefined");
6839 break;
6840 }
6841 (void) SetImageOption(image_info,option+1,argv[i+1]);
6842 break;
6843 }
6844 if (LocaleCompare("endian",option+1) == 0)
6845 {
6846 if (*option == '+')
6847 {
6848 image_info->endian=UndefinedEndian;
6849 (void) SetImageOption(image_info,option+1,"undefined");
6850 break;
6851 }
6852 image_info->endian=(EndianType) ParseMagickOption(
6853 MagickEndianOptions,MagickFalse,argv[i+1]);
6854 (void) SetImageOption(image_info,option+1,argv[i+1]);
6855 break;
6856 }
6857 if (LocaleCompare("extract",option+1) == 0)
6858 {
6859 /*
6860 Set image extract geometry.
6861 */
6862 if (*option == '+')
6863 {
6864 if (image_info->extract != (char *) NULL)
6865 image_info->extract=DestroyString(image_info->extract);
6866 break;
6867 }
6868 (void) CloneString(&image_info->extract,argv[i+1]);
6869 break;
6870 }
6871 break;
6872 }
6873 case 'f':
6874 {
6875 if (LocaleCompare("fill",option+1) == 0)
6876 {
6877 if (*option == '+')
6878 {
6879 (void) SetImageOption(image_info,option+1,"none");
6880 break;
6881 }
6882 (void) SetImageOption(image_info,option+1,argv[i+1]);
6883 break;
6884 }
6885 if (LocaleCompare("filter",option+1) == 0)
6886 {
6887 if (*option == '+')
6888 {
6889 (void) SetImageOption(image_info,option+1,"undefined");
6890 break;
6891 }
6892 (void) SetImageOption(image_info,option+1,argv[i+1]);
6893 break;
6894 }
6895 if (LocaleCompare("font",option+1) == 0)
6896 {
6897 if (*option == '+')
6898 {
6899 if (image_info->font != (char *) NULL)
6900 image_info->font=DestroyString(image_info->font);
6901 break;
6902 }
6903 (void) CloneString(&image_info->font,argv[i+1]);
6904 break;
6905 }
6906 if (LocaleCompare("format",option+1) == 0)
6907 {
6908 register const char
6909 *q;
6910
6911 for (q=strchr(argv[i+1],'%'); q != (char *) NULL; q=strchr(q+1,'%'))
cristy9ed85672011-03-02 00:19:13 +00006912 if (strchr("Agkrz@[#",*(q+1)) != (char *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00006913 image_info->ping=MagickFalse;
6914 (void) SetImageOption(image_info,option+1,argv[i+1]);
6915 break;
6916 }
6917 if (LocaleCompare("fuzz",option+1) == 0)
6918 {
6919 if (*option == '+')
6920 {
6921 image_info->fuzz=0.0;
6922 (void) SetImageOption(image_info,option+1,"0");
6923 break;
6924 }
cristyf2f27272009-12-17 14:48:46 +00006925 image_info->fuzz=SiPrefixToDouble(argv[i+1],(double) QuantumRange+
cristy3ed852e2009-09-05 21:47:34 +00006926 1.0);
6927 (void) SetImageOption(image_info,option+1,argv[i+1]);
6928 break;
6929 }
6930 break;
6931 }
6932 case 'g':
6933 {
6934 if (LocaleCompare("gravity",option+1) == 0)
6935 {
6936 if (*option == '+')
6937 {
6938 (void) SetImageOption(image_info,option+1,"undefined");
6939 break;
6940 }
6941 (void) SetImageOption(image_info,option+1,argv[i+1]);
6942 break;
6943 }
6944 if (LocaleCompare("green-primary",option+1) == 0)
6945 {
6946 if (*option == '+')
6947 {
6948 (void) SetImageOption(image_info,option+1,"0.0");
6949 break;
6950 }
6951 (void) SetImageOption(image_info,option+1,argv[i+1]);
6952 break;
6953 }
6954 break;
6955 }
6956 case 'i':
6957 {
6958 if (LocaleCompare("intent",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 }
6968 if (LocaleCompare("interlace",option+1) == 0)
6969 {
6970 if (*option == '+')
6971 {
6972 image_info->interlace=UndefinedInterlace;
6973 (void) SetImageOption(image_info,option+1,"undefined");
6974 break;
6975 }
6976 image_info->interlace=(InterlaceType) ParseMagickOption(
6977 MagickInterlaceOptions,MagickFalse,argv[i+1]);
6978 (void) SetImageOption(image_info,option+1,argv[i+1]);
6979 break;
6980 }
cristyb32b90a2009-09-07 21:45:48 +00006981 if (LocaleCompare("interline-spacing",option+1) == 0)
6982 {
6983 if (*option == '+')
6984 {
6985 (void) SetImageOption(image_info,option+1,"undefined");
6986 break;
6987 }
6988 (void) SetImageOption(image_info,option+1,argv[i+1]);
6989 break;
6990 }
cristy3ed852e2009-09-05 21:47:34 +00006991 if (LocaleCompare("interpolate",option+1) == 0)
6992 {
6993 if (*option == '+')
6994 {
6995 (void) SetImageOption(image_info,option+1,"undefined");
6996 break;
6997 }
6998 (void) SetImageOption(image_info,option+1,argv[i+1]);
6999 break;
7000 }
7001 if (LocaleCompare("interword-spacing",option+1) == 0)
7002 {
7003 if (*option == '+')
7004 {
7005 (void) SetImageOption(image_info,option+1,"undefined");
7006 break;
7007 }
7008 (void) SetImageOption(image_info,option+1,argv[i+1]);
7009 break;
7010 }
7011 break;
7012 }
7013 case 'k':
7014 {
7015 if (LocaleCompare("kerning",option+1) == 0)
7016 {
7017 if (*option == '+')
7018 {
7019 (void) SetImageOption(image_info,option+1,"undefined");
7020 break;
7021 }
7022 (void) SetImageOption(image_info,option+1,argv[i+1]);
7023 break;
7024 }
7025 break;
7026 }
7027 case 'l':
7028 {
7029 if (LocaleCompare("label",option+1) == 0)
7030 {
7031 if (*option == '+')
7032 {
7033 (void) DeleteImageOption(image_info,option+1);
7034 break;
7035 }
7036 (void) SetImageOption(image_info,option+1,argv[i+1]);
7037 break;
7038 }
7039 if (LocaleCompare("limit",option+1) == 0)
7040 {
7041 MagickSizeType
7042 limit;
7043
7044 ResourceType
7045 type;
7046
7047 if (*option == '+')
7048 break;
7049 type=(ResourceType) ParseMagickOption(MagickResourceOptions,
7050 MagickFalse,argv[i+1]);
7051 limit=MagickResourceInfinity;
7052 if (LocaleCompare("unlimited",argv[i+2]) != 0)
cristyf2f27272009-12-17 14:48:46 +00007053 limit=(MagickSizeType) SiPrefixToDouble(argv[i+2],100.0);
cristy3ed852e2009-09-05 21:47:34 +00007054 (void) SetMagickResourceLimit(type,limit);
7055 break;
7056 }
7057 if (LocaleCompare("list",option+1) == 0)
7058 {
cristybb503372010-05-27 20:51:26 +00007059 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00007060 list;
7061
7062 /*
7063 Display configuration list.
7064 */
7065 list=ParseMagickOption(MagickListOptions,MagickFalse,argv[i+1]);
7066 switch (list)
7067 {
7068 case MagickCoderOptions:
7069 {
7070 (void) ListCoderInfo((FILE *) NULL,exception);
7071 break;
7072 }
7073 case MagickColorOptions:
7074 {
7075 (void) ListColorInfo((FILE *) NULL,exception);
7076 break;
7077 }
7078 case MagickConfigureOptions:
7079 {
7080 (void) ListConfigureInfo((FILE *) NULL,exception);
7081 break;
7082 }
7083 case MagickDelegateOptions:
7084 {
7085 (void) ListDelegateInfo((FILE *) NULL,exception);
7086 break;
7087 }
7088 case MagickFontOptions:
7089 {
7090 (void) ListTypeInfo((FILE *) NULL,exception);
7091 break;
7092 }
7093 case MagickFormatOptions:
7094 {
7095 (void) ListMagickInfo((FILE *) NULL,exception);
7096 break;
7097 }
7098 case MagickLocaleOptions:
7099 {
7100 (void) ListLocaleInfo((FILE *) NULL,exception);
7101 break;
7102 }
7103 case MagickLogOptions:
7104 {
7105 (void) ListLogInfo((FILE *) NULL,exception);
7106 break;
7107 }
7108 case MagickMagicOptions:
7109 {
7110 (void) ListMagicInfo((FILE *) NULL,exception);
7111 break;
7112 }
7113 case MagickMimeOptions:
7114 {
7115 (void) ListMimeInfo((FILE *) NULL,exception);
7116 break;
7117 }
7118 case MagickModuleOptions:
7119 {
7120 (void) ListModuleInfo((FILE *) NULL,exception);
7121 break;
7122 }
7123 case MagickPolicyOptions:
7124 {
7125 (void) ListPolicyInfo((FILE *) NULL,exception);
7126 break;
7127 }
7128 case MagickResourceOptions:
7129 {
7130 (void) ListMagickResourceInfo((FILE *) NULL,exception);
7131 break;
7132 }
7133 case MagickThresholdOptions:
7134 {
7135 (void) ListThresholdMaps((FILE *) NULL,exception);
7136 break;
7137 }
7138 default:
7139 {
7140 (void) ListMagickOptions((FILE *) NULL,(MagickOption) list,
7141 exception);
7142 break;
7143 }
7144 }
cristyaeb2cbc2010-05-07 13:28:58 +00007145 break;
cristy3ed852e2009-09-05 21:47:34 +00007146 }
7147 if (LocaleCompare("log",option+1) == 0)
7148 {
7149 if (*option == '+')
7150 break;
7151 (void) SetLogFormat(argv[i+1]);
7152 break;
7153 }
7154 if (LocaleCompare("loop",option+1) == 0)
7155 {
7156 if (*option == '+')
7157 {
7158 (void) SetImageOption(image_info,option+1,"0");
7159 break;
7160 }
7161 (void) SetImageOption(image_info,option+1,argv[i+1]);
7162 break;
7163 }
7164 break;
7165 }
7166 case 'm':
7167 {
7168 if (LocaleCompare("matte",option+1) == 0)
7169 {
7170 if (*option == '+')
7171 {
7172 (void) SetImageOption(image_info,option+1,"false");
7173 break;
7174 }
7175 (void) SetImageOption(image_info,option+1,"true");
7176 break;
7177 }
7178 if (LocaleCompare("mattecolor",option+1) == 0)
7179 {
7180 if (*option == '+')
7181 {
7182 (void) SetImageOption(image_info,option+1,argv[i+1]);
7183 (void) QueryColorDatabase(MatteColor,&image_info->matte_color,
7184 exception);
7185 break;
7186 }
7187 (void) SetImageOption(image_info,option+1,argv[i+1]);
7188 (void) QueryColorDatabase(argv[i+1],&image_info->matte_color,
7189 exception);
7190 break;
7191 }
7192 if (LocaleCompare("monitor",option+1) == 0)
7193 {
7194 (void) SetImageInfoProgressMonitor(image_info,MonitorProgress,
7195 (void *) NULL);
7196 break;
7197 }
7198 if (LocaleCompare("monochrome",option+1) == 0)
7199 {
7200 image_info->monochrome=(*option == '-') ? MagickTrue : MagickFalse;
7201 break;
7202 }
7203 break;
7204 }
7205 case 'o':
7206 {
7207 if (LocaleCompare("orient",option+1) == 0)
7208 {
7209 if (*option == '+')
7210 {
7211 image_info->orientation=UndefinedOrientation;
7212 (void) SetImageOption(image_info,option+1,"undefined");
7213 break;
7214 }
7215 image_info->orientation=(OrientationType) ParseMagickOption(
7216 MagickOrientationOptions,MagickFalse,argv[i+1]);
cristyc6e214d2010-08-08 00:31:08 +00007217 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007218 break;
7219 }
7220 }
7221 case 'p':
7222 {
7223 if (LocaleCompare("page",option+1) == 0)
7224 {
7225 char
7226 *canonical_page,
7227 page[MaxTextExtent];
7228
7229 const char
7230 *image_option;
7231
7232 MagickStatusType
7233 flags;
7234
7235 RectangleInfo
7236 geometry;
7237
7238 if (*option == '+')
7239 {
7240 (void) DeleteImageOption(image_info,option+1);
7241 (void) CloneString(&image_info->page,(char *) NULL);
7242 break;
7243 }
7244 (void) ResetMagickMemory(&geometry,0,sizeof(geometry));
7245 image_option=GetImageOption(image_info,"page");
7246 if (image_option != (const char *) NULL)
7247 flags=ParseAbsoluteGeometry(image_option,&geometry);
7248 canonical_page=GetPageGeometry(argv[i+1]);
7249 flags=ParseAbsoluteGeometry(canonical_page,&geometry);
7250 canonical_page=DestroyString(canonical_page);
7251 (void) FormatMagickString(page,MaxTextExtent,"%lux%lu",
cristyf2faecf2010-05-28 19:19:36 +00007252 (unsigned long) geometry.width,(unsigned long) geometry.height);
cristy3ed852e2009-09-05 21:47:34 +00007253 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
7254 (void) FormatMagickString(page,MaxTextExtent,"%lux%lu%+ld%+ld",
cristyf2faecf2010-05-28 19:19:36 +00007255 (unsigned long) geometry.width,(unsigned long) geometry.height,
7256 (long) geometry.x,(long) geometry.y);
cristy3ed852e2009-09-05 21:47:34 +00007257 (void) SetImageOption(image_info,option+1,page);
7258 (void) CloneString(&image_info->page,page);
7259 break;
7260 }
7261 if (LocaleCompare("pen",option+1) == 0)
7262 {
7263 if (*option == '+')
7264 {
7265 (void) SetImageOption(image_info,option+1,"none");
7266 break;
7267 }
7268 (void) SetImageOption(image_info,option+1,argv[i+1]);
7269 break;
7270 }
7271 if (LocaleCompare("ping",option+1) == 0)
7272 {
7273 image_info->ping=(*option == '-') ? MagickTrue : MagickFalse;
7274 break;
7275 }
7276 if (LocaleCompare("pointsize",option+1) == 0)
7277 {
7278 if (*option == '+')
7279 geometry_info.rho=0.0;
7280 else
7281 (void) ParseGeometry(argv[i+1],&geometry_info);
7282 image_info->pointsize=geometry_info.rho;
7283 break;
7284 }
cristye7f51092010-01-17 00:39:37 +00007285 if (LocaleCompare("precision",option+1) == 0)
7286 {
cristybf2766a2010-01-17 03:33:23 +00007287 (void) SetMagickPrecision(StringToInteger(argv[i+1]));
cristye7f51092010-01-17 00:39:37 +00007288 break;
7289 }
cristy3ed852e2009-09-05 21:47:34 +00007290 if (LocaleCompare("preview",option+1) == 0)
7291 {
7292 /*
7293 Preview image.
7294 */
7295 if (*option == '+')
7296 {
7297 image_info->preview_type=UndefinedPreview;
7298 break;
7299 }
7300 image_info->preview_type=(PreviewType) ParseMagickOption(
7301 MagickPreviewOptions,MagickFalse,argv[i+1]);
7302 break;
7303 }
7304 break;
7305 }
7306 case 'q':
7307 {
7308 if (LocaleCompare("quality",option+1) == 0)
7309 {
7310 /*
7311 Set image compression quality.
7312 */
7313 if (*option == '+')
7314 {
7315 image_info->quality=UndefinedCompressionQuality;
7316 (void) SetImageOption(image_info,option+1,"0");
7317 break;
7318 }
cristye27293e2009-12-18 02:53:20 +00007319 image_info->quality=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007320 (void) SetImageOption(image_info,option+1,argv[i+1]);
7321 break;
7322 }
7323 if (LocaleCompare("quiet",option+1) == 0)
7324 {
7325 static WarningHandler
7326 warning_handler = (WarningHandler) NULL;
7327
7328 if (*option == '+')
7329 {
7330 /*
7331 Restore error or warning messages.
7332 */
7333 warning_handler=SetWarningHandler(warning_handler);
7334 break;
7335 }
7336 /*
7337 Suppress error or warning messages.
7338 */
7339 warning_handler=SetWarningHandler((WarningHandler) NULL);
7340 break;
7341 }
7342 break;
7343 }
7344 case 'r':
7345 {
7346 if (LocaleCompare("red-primary",option+1) == 0)
7347 {
7348 if (*option == '+')
7349 {
7350 (void) SetImageOption(image_info,option+1,"0.0");
7351 break;
7352 }
7353 (void) SetImageOption(image_info,option+1,argv[i+1]);
7354 break;
7355 }
7356 break;
7357 }
7358 case 's':
7359 {
7360 if (LocaleCompare("sampling-factor",option+1) == 0)
7361 {
7362 /*
7363 Set image sampling factor.
7364 */
7365 if (*option == '+')
7366 {
7367 if (image_info->sampling_factor != (char *) NULL)
7368 image_info->sampling_factor=DestroyString(
7369 image_info->sampling_factor);
7370 break;
7371 }
7372 (void) CloneString(&image_info->sampling_factor,argv[i+1]);
7373 break;
7374 }
7375 if (LocaleCompare("scene",option+1) == 0)
7376 {
7377 /*
7378 Set image scene.
7379 */
7380 if (*option == '+')
7381 {
7382 image_info->scene=0;
7383 (void) SetImageOption(image_info,option+1,"0");
7384 break;
7385 }
cristye27293e2009-12-18 02:53:20 +00007386 image_info->scene=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007387 (void) SetImageOption(image_info,option+1,argv[i+1]);
7388 break;
7389 }
7390 if (LocaleCompare("seed",option+1) == 0)
7391 {
cristybb503372010-05-27 20:51:26 +00007392 size_t
cristy3ed852e2009-09-05 21:47:34 +00007393 seed;
7394
7395 if (*option == '+')
7396 {
cristybb503372010-05-27 20:51:26 +00007397 seed=(size_t) time((time_t *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00007398 SeedPseudoRandomGenerator(seed);
7399 break;
7400 }
cristye27293e2009-12-18 02:53:20 +00007401 seed=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007402 SeedPseudoRandomGenerator(seed);
7403 break;
7404 }
7405 if (LocaleCompare("size",option+1) == 0)
7406 {
7407 if (*option == '+')
7408 {
7409 if (image_info->size != (char *) NULL)
7410 image_info->size=DestroyString(image_info->size);
7411 break;
7412 }
7413 (void) CloneString(&image_info->size,argv[i+1]);
7414 break;
7415 }
7416 if (LocaleCompare("stroke",option+1) == 0)
7417 {
7418 if (*option == '+')
7419 {
7420 (void) SetImageOption(image_info,option+1,"none");
7421 break;
7422 }
7423 (void) SetImageOption(image_info,option+1,argv[i+1]);
7424 break;
7425 }
7426 if (LocaleCompare("strokewidth",option+1) == 0)
7427 {
7428 if (*option == '+')
7429 {
7430 (void) SetImageOption(image_info,option+1,"0");
7431 break;
7432 }
7433 (void) SetImageOption(image_info,option+1,argv[i+1]);
7434 break;
7435 }
cristyd9a29192010-10-16 16:49:53 +00007436 if (LocaleCompare("synchronize",option+1) == 0)
7437 {
7438 if (*option == '+')
7439 {
7440 image_info->synchronize=MagickFalse;
7441 break;
7442 }
7443 image_info->synchronize=MagickTrue;
7444 break;
7445 }
cristy3ed852e2009-09-05 21:47:34 +00007446 break;
7447 }
7448 case 't':
7449 {
7450 if (LocaleCompare("taint",option+1) == 0)
7451 {
7452 if (*option == '+')
7453 {
7454 (void) SetImageOption(image_info,option+1,"false");
7455 break;
7456 }
7457 (void) SetImageOption(image_info,option+1,"true");
7458 break;
7459 }
7460 if (LocaleCompare("texture",option+1) == 0)
7461 {
7462 if (*option == '+')
7463 {
7464 if (image_info->texture != (char *) NULL)
7465 image_info->texture=DestroyString(image_info->texture);
7466 break;
7467 }
7468 (void) CloneString(&image_info->texture,argv[i+1]);
7469 break;
7470 }
7471 if (LocaleCompare("tile-offset",option+1) == 0)
7472 {
7473 if (*option == '+')
7474 {
7475 (void) SetImageOption(image_info,option+1,"0");
7476 break;
7477 }
7478 (void) SetImageOption(image_info,option+1,argv[i+1]);
7479 break;
7480 }
7481 if (LocaleCompare("transparent-color",option+1) == 0)
7482 {
7483 if (*option == '+')
7484 {
7485 (void) QueryColorDatabase("none",&image_info->transparent_color, exception);
7486 (void) SetImageOption(image_info,option+1,"none");
7487 break;
7488 }
7489 (void) QueryColorDatabase(argv[i+1],&image_info->transparent_color,
7490 exception);
7491 (void) SetImageOption(image_info,option+1,argv[i+1]);
7492 break;
7493 }
7494 if (LocaleCompare("type",option+1) == 0)
7495 {
7496 if (*option == '+')
7497 {
cristy5f1c1ff2010-12-23 21:38:06 +00007498 image_info->type=UndefinedType;
cristy3ed852e2009-09-05 21:47:34 +00007499 (void) SetImageOption(image_info,option+1,"undefined");
7500 break;
7501 }
7502 image_info->type=(ImageType) ParseMagickOption(MagickTypeOptions,
7503 MagickFalse,argv[i+1]);
7504 (void) SetImageOption(image_info,option+1,argv[i+1]);
7505 break;
7506 }
7507 break;
7508 }
7509 case 'u':
7510 {
7511 if (LocaleCompare("undercolor",option+1) == 0)
7512 {
7513 if (*option == '+')
7514 {
7515 (void) DeleteImageOption(image_info,option+1);
7516 break;
7517 }
7518 (void) SetImageOption(image_info,option+1,argv[i+1]);
7519 break;
7520 }
7521 if (LocaleCompare("units",option+1) == 0)
7522 {
7523 if (*option == '+')
7524 {
7525 image_info->units=UndefinedResolution;
7526 (void) SetImageOption(image_info,option+1,"undefined");
7527 break;
7528 }
7529 image_info->units=(ResolutionType) ParseMagickOption(
7530 MagickResolutionOptions,MagickFalse,argv[i+1]);
7531 (void) SetImageOption(image_info,option+1,argv[i+1]);
7532 break;
7533 }
7534 break;
7535 }
7536 case 'v':
7537 {
7538 if (LocaleCompare("verbose",option+1) == 0)
7539 {
7540 if (*option == '+')
7541 {
7542 image_info->verbose=MagickFalse;
7543 break;
7544 }
7545 image_info->verbose=MagickTrue;
7546 image_info->ping=MagickFalse;
7547 break;
7548 }
7549 if (LocaleCompare("view",option+1) == 0)
7550 {
7551 if (*option == '+')
7552 {
7553 if (image_info->view != (char *) NULL)
7554 image_info->view=DestroyString(image_info->view);
7555 break;
7556 }
7557 (void) CloneString(&image_info->view,argv[i+1]);
7558 break;
7559 }
7560 if (LocaleCompare("virtual-pixel",option+1) == 0)
7561 {
7562 if (*option == '+')
7563 {
7564 image_info->virtual_pixel_method=UndefinedVirtualPixelMethod;
7565 (void) SetImageOption(image_info,option+1,"undefined");
7566 break;
7567 }
7568 image_info->virtual_pixel_method=(VirtualPixelMethod)
7569 ParseMagickOption(MagickVirtualPixelOptions,MagickFalse,
7570 argv[i+1]);
7571 (void) SetImageOption(image_info,option+1,argv[i+1]);
7572 break;
7573 }
7574 break;
7575 }
7576 case 'w':
7577 {
7578 if (LocaleCompare("white-point",option+1) == 0)
7579 {
7580 if (*option == '+')
7581 {
7582 (void) SetImageOption(image_info,option+1,"0.0");
7583 break;
7584 }
7585 (void) SetImageOption(image_info,option+1,argv[i+1]);
7586 break;
7587 }
7588 break;
7589 }
7590 default:
7591 break;
7592 }
7593 i+=count;
7594 }
7595 return(MagickTrue);
7596}
7597
7598/*
7599%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7600% %
7601% %
7602% %
7603+ M o g r i f y I m a g e L i s t %
7604% %
7605% %
7606% %
7607%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7608%
7609% MogrifyImageList() applies any command line options that might affect the
7610% entire image list (e.g. -append, -coalesce, etc.).
7611%
7612% The format of the MogrifyImage method is:
7613%
7614% MagickBooleanType MogrifyImageList(ImageInfo *image_info,const int argc,
7615% const char **argv,Image **images,ExceptionInfo *exception)
7616%
7617% A description of each parameter follows:
7618%
7619% o image_info: the image info..
7620%
7621% o argc: Specifies a pointer to an integer describing the number of
7622% elements in the argument vector.
7623%
7624% o argv: Specifies a pointer to a text array containing the command line
7625% arguments.
7626%
7627% o images: the images.
7628%
7629% o exception: return any errors or warnings in this structure.
7630%
7631*/
7632WandExport MagickBooleanType MogrifyImageList(ImageInfo *image_info,
7633 const int argc,const char **argv,Image **images,ExceptionInfo *exception)
7634{
7635 ChannelType
7636 channel;
7637
7638 const char
7639 *option;
7640
cristy6b3da3a2010-06-20 02:21:46 +00007641 ImageInfo
7642 *mogrify_info;
cristy3ed852e2009-09-05 21:47:34 +00007643
7644 MagickStatusType
7645 status;
7646
7647 QuantizeInfo
7648 *quantize_info;
7649
cristybb503372010-05-27 20:51:26 +00007650 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00007651 i;
7652
cristy6b3da3a2010-06-20 02:21:46 +00007653 ssize_t
7654 count,
7655 index;
7656
cristy3ed852e2009-09-05 21:47:34 +00007657 /*
7658 Apply options to the image list.
7659 */
7660 assert(image_info != (ImageInfo *) NULL);
7661 assert(image_info->signature == MagickSignature);
7662 assert(images != (Image **) NULL);
7663 assert((*images)->signature == MagickSignature);
7664 if ((*images)->debug != MagickFalse)
7665 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
7666 (*images)->filename);
7667 if ((argc <= 0) || (*argv == (char *) NULL))
7668 return(MagickTrue);
cristy6b3da3a2010-06-20 02:21:46 +00007669 mogrify_info=CloneImageInfo(image_info);
7670 quantize_info=AcquireQuantizeInfo(mogrify_info);
7671 channel=mogrify_info->channel;
cristy3ed852e2009-09-05 21:47:34 +00007672 status=MagickTrue;
cristybb503372010-05-27 20:51:26 +00007673 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00007674 {
cristy74fe8f12009-10-03 19:09:01 +00007675 if (*images == (Image *) NULL)
7676 break;
cristy3ed852e2009-09-05 21:47:34 +00007677 option=argv[i];
7678 if (IsMagickOption(option) == MagickFalse)
7679 continue;
7680 count=MagickMax(ParseMagickOption(MagickCommandOptions,MagickFalse,option),
7681 0L);
cristycee97112010-05-28 00:44:52 +00007682 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00007683 break;
cristy6b3da3a2010-06-20 02:21:46 +00007684 status=MogrifyImageInfo(mogrify_info,(int) count+1,argv+i,exception);
cristy3ed852e2009-09-05 21:47:34 +00007685 switch (*(option+1))
7686 {
7687 case 'a':
7688 {
7689 if (LocaleCompare("affinity",option+1) == 0)
7690 {
cristy6b3da3a2010-06-20 02:21:46 +00007691 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007692 if (*option == '+')
7693 {
7694 (void) RemapImages(quantize_info,*images,(Image *) NULL);
7695 InheritException(exception,&(*images)->exception);
7696 break;
7697 }
7698 i++;
7699 break;
7700 }
7701 if (LocaleCompare("append",option+1) == 0)
7702 {
7703 Image
7704 *append_image;
7705
cristy6b3da3a2010-06-20 02:21:46 +00007706 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007707 append_image=AppendImages(*images,*option == '-' ? MagickTrue :
7708 MagickFalse,exception);
7709 if (append_image == (Image *) NULL)
7710 {
7711 status=MagickFalse;
7712 break;
7713 }
7714 *images=DestroyImageList(*images);
7715 *images=append_image;
7716 break;
7717 }
7718 if (LocaleCompare("average",option+1) == 0)
7719 {
7720 Image
7721 *average_image;
7722
cristyd18ae7c2010-03-07 17:39:52 +00007723 /*
7724 Average an image sequence (deprecated).
7725 */
cristy6b3da3a2010-06-20 02:21:46 +00007726 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007727 average_image=EvaluateImages(*images,MeanEvaluateOperator,
7728 exception);
cristy3ed852e2009-09-05 21:47:34 +00007729 if (average_image == (Image *) NULL)
7730 {
7731 status=MagickFalse;
7732 break;
7733 }
7734 *images=DestroyImageList(*images);
7735 *images=average_image;
7736 break;
7737 }
7738 break;
7739 }
7740 case 'c':
7741 {
7742 if (LocaleCompare("channel",option+1) == 0)
7743 {
7744 if (*option == '+')
7745 {
7746 channel=DefaultChannels;
7747 break;
7748 }
7749 channel=(ChannelType) ParseChannelOption(argv[i+1]);
7750 break;
7751 }
7752 if (LocaleCompare("clut",option+1) == 0)
7753 {
7754 Image
7755 *clut_image,
7756 *image;
7757
cristy6b3da3a2010-06-20 02:21:46 +00007758 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007759 image=RemoveFirstImageFromList(images);
7760 clut_image=RemoveFirstImageFromList(images);
7761 if (clut_image == (Image *) NULL)
7762 {
7763 status=MagickFalse;
7764 break;
7765 }
7766 (void) ClutImageChannel(image,channel,clut_image);
7767 clut_image=DestroyImage(clut_image);
7768 InheritException(exception,&image->exception);
7769 *images=DestroyImageList(*images);
7770 *images=image;
7771 break;
7772 }
7773 if (LocaleCompare("coalesce",option+1) == 0)
7774 {
7775 Image
7776 *coalesce_image;
7777
cristy6b3da3a2010-06-20 02:21:46 +00007778 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007779 coalesce_image=CoalesceImages(*images,exception);
7780 if (coalesce_image == (Image *) NULL)
7781 {
7782 status=MagickFalse;
7783 break;
7784 }
7785 *images=DestroyImageList(*images);
7786 *images=coalesce_image;
7787 break;
7788 }
7789 if (LocaleCompare("combine",option+1) == 0)
7790 {
7791 Image
7792 *combine_image;
7793
cristy6b3da3a2010-06-20 02:21:46 +00007794 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007795 combine_image=CombineImages(*images,channel,exception);
7796 if (combine_image == (Image *) NULL)
7797 {
7798 status=MagickFalse;
7799 break;
7800 }
7801 *images=DestroyImageList(*images);
7802 *images=combine_image;
7803 break;
7804 }
7805 if (LocaleCompare("composite",option+1) == 0)
7806 {
7807 Image
7808 *mask_image,
7809 *composite_image,
7810 *image;
7811
7812 RectangleInfo
7813 geometry;
7814
cristy6b3da3a2010-06-20 02:21:46 +00007815 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007816 image=RemoveFirstImageFromList(images);
7817 composite_image=RemoveFirstImageFromList(images);
7818 if (composite_image == (Image *) NULL)
7819 {
7820 status=MagickFalse;
7821 break;
7822 }
7823 (void) TransformImage(&composite_image,(char *) NULL,
7824 composite_image->geometry);
7825 SetGeometry(composite_image,&geometry);
7826 (void) ParseAbsoluteGeometry(composite_image->geometry,&geometry);
7827 GravityAdjustGeometry(image->columns,image->rows,image->gravity,
7828 &geometry);
7829 mask_image=RemoveFirstImageFromList(images);
7830 if (mask_image != (Image *) NULL)
7831 {
7832 if ((image->compose == DisplaceCompositeOp) ||
7833 (image->compose == DistortCompositeOp))
7834 {
7835 /*
7836 Merge Y displacement into X displacement image.
7837 */
7838 (void) CompositeImage(composite_image,CopyGreenCompositeOp,
7839 mask_image,0,0);
7840 mask_image=DestroyImage(mask_image);
7841 }
7842 else
7843 {
7844 /*
7845 Set a blending mask for the composition.
7846 */
7847 image->mask=mask_image;
7848 (void) NegateImage(image->mask,MagickFalse);
7849 }
7850 }
7851 (void) CompositeImageChannel(image,channel,image->compose,
7852 composite_image,geometry.x,geometry.y);
7853 if (image->mask != (Image *) NULL)
7854 image->mask=DestroyImage(image->mask);
7855 composite_image=DestroyImage(composite_image);
7856 InheritException(exception,&image->exception);
7857 *images=DestroyImageList(*images);
7858 *images=image;
7859 break;
7860 }
7861 if (LocaleCompare("crop",option+1) == 0)
7862 {
7863 MagickStatusType
7864 flags;
7865
7866 RectangleInfo
7867 geometry;
7868
cristy6b3da3a2010-06-20 02:21:46 +00007869 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007870 flags=ParseGravityGeometry(*images,argv[i+1],&geometry,exception);
7871 if (((geometry.width == 0) && (geometry.height == 0)) ||
7872 ((flags & XValue) != 0) || ((flags & YValue) != 0))
7873 break;
7874 (void) TransformImages(images,argv[i+1],(char *) NULL);
7875 InheritException(exception,&(*images)->exception);
7876 break;
7877 }
7878 break;
7879 }
7880 case 'd':
7881 {
7882 if (LocaleCompare("deconstruct",option+1) == 0)
7883 {
7884 Image
7885 *deconstruct_image;
7886
cristy6b3da3a2010-06-20 02:21:46 +00007887 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007888 deconstruct_image=DeconstructImages(*images,exception);
7889 if (deconstruct_image == (Image *) NULL)
7890 {
7891 status=MagickFalse;
7892 break;
7893 }
7894 *images=DestroyImageList(*images);
7895 *images=deconstruct_image;
7896 break;
7897 }
7898 if (LocaleCompare("delete",option+1) == 0)
7899 {
7900 if (*option == '+')
7901 DeleteImages(images,"-1",exception);
7902 else
7903 DeleteImages(images,argv[i+1],exception);
7904 break;
7905 }
7906 if (LocaleCompare("dither",option+1) == 0)
7907 {
7908 if (*option == '+')
7909 {
7910 quantize_info->dither=MagickFalse;
7911 break;
7912 }
7913 quantize_info->dither=MagickTrue;
7914 quantize_info->dither_method=(DitherMethod) ParseMagickOption(
7915 MagickDitherOptions,MagickFalse,argv[i+1]);
7916 break;
7917 }
7918 break;
7919 }
cristyd18ae7c2010-03-07 17:39:52 +00007920 case 'e':
7921 {
7922 if (LocaleCompare("evaluate-sequence",option+1) == 0)
7923 {
7924 Image
7925 *evaluate_image;
7926
7927 MagickEvaluateOperator
7928 op;
7929
cristy6b3da3a2010-06-20 02:21:46 +00007930 (void) SyncImageSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007931 op=(MagickEvaluateOperator) ParseMagickOption(MagickEvaluateOptions,
7932 MagickFalse,argv[i+1]);
7933 evaluate_image=EvaluateImages(*images,op,exception);
7934 if (evaluate_image == (Image *) NULL)
7935 {
7936 status=MagickFalse;
7937 break;
7938 }
7939 *images=DestroyImageList(*images);
7940 *images=evaluate_image;
7941 break;
7942 }
7943 break;
7944 }
cristy3ed852e2009-09-05 21:47:34 +00007945 case 'f':
7946 {
cristyf0a247f2009-10-04 00:20:03 +00007947 if (LocaleCompare("fft",option+1) == 0)
7948 {
7949 Image
7950 *fourier_image;
7951
7952 /*
7953 Implements the discrete Fourier transform (DFT).
7954 */
cristy6b3da3a2010-06-20 02:21:46 +00007955 (void) SyncImageSettings(mogrify_info,*images);
cristyf0a247f2009-10-04 00:20:03 +00007956 fourier_image=ForwardFourierTransformImage(*images,*option == '-' ?
7957 MagickTrue : MagickFalse,exception);
7958 if (fourier_image == (Image *) NULL)
7959 break;
7960 *images=DestroyImage(*images);
7961 *images=fourier_image;
7962 break;
7963 }
cristy3ed852e2009-09-05 21:47:34 +00007964 if (LocaleCompare("flatten",option+1) == 0)
7965 {
7966 Image
7967 *flatten_image;
7968
cristy6b3da3a2010-06-20 02:21:46 +00007969 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007970 flatten_image=MergeImageLayers(*images,FlattenLayer,exception);
7971 if (flatten_image == (Image *) NULL)
7972 break;
7973 *images=DestroyImageList(*images);
7974 *images=flatten_image;
7975 break;
7976 }
7977 if (LocaleCompare("fx",option+1) == 0)
7978 {
7979 Image
7980 *fx_image;
7981
cristy6b3da3a2010-06-20 02:21:46 +00007982 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007983 fx_image=FxImageChannel(*images,channel,argv[i+1],exception);
7984 if (fx_image == (Image *) NULL)
7985 {
7986 status=MagickFalse;
7987 break;
7988 }
7989 *images=DestroyImageList(*images);
7990 *images=fx_image;
7991 break;
7992 }
7993 break;
7994 }
7995 case 'h':
7996 {
7997 if (LocaleCompare("hald-clut",option+1) == 0)
7998 {
7999 Image
8000 *hald_image,
8001 *image;
8002
cristy6b3da3a2010-06-20 02:21:46 +00008003 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00008004 image=RemoveFirstImageFromList(images);
8005 hald_image=RemoveFirstImageFromList(images);
8006 if (hald_image == (Image *) NULL)
8007 {
8008 status=MagickFalse;
8009 break;
8010 }
8011 (void) HaldClutImageChannel(image,channel,hald_image);
8012 hald_image=DestroyImage(hald_image);
8013 InheritException(exception,&image->exception);
cristy0aff6ea2009-11-14 01:40:53 +00008014 if (*images != (Image *) NULL)
8015 *images=DestroyImageList(*images);
cristy3ed852e2009-09-05 21:47:34 +00008016 *images=image;
8017 break;
8018 }
8019 break;
8020 }
8021 case 'i':
8022 {
8023 if (LocaleCompare("ift",option+1) == 0)
8024 {
8025 Image
cristy8587f882009-11-13 20:28:49 +00008026 *fourier_image,
8027 *magnitude_image,
8028 *phase_image;
cristy3ed852e2009-09-05 21:47:34 +00008029
8030 /*
8031 Implements the inverse fourier discrete Fourier transform (DFT).
8032 */
cristy6b3da3a2010-06-20 02:21:46 +00008033 (void) SyncImagesSettings(mogrify_info,*images);
cristy8587f882009-11-13 20:28:49 +00008034 magnitude_image=RemoveFirstImageFromList(images);
8035 phase_image=RemoveFirstImageFromList(images);
8036 if (phase_image == (Image *) NULL)
8037 {
8038 status=MagickFalse;
8039 break;
8040 }
8041 fourier_image=InverseFourierTransformImage(magnitude_image,
8042 phase_image,*option == '-' ? MagickTrue : MagickFalse,exception);
cristy3ed852e2009-09-05 21:47:34 +00008043 if (fourier_image == (Image *) NULL)
8044 break;
cristy0aff6ea2009-11-14 01:40:53 +00008045 if (*images != (Image *) NULL)
8046 *images=DestroyImage(*images);
cristy3ed852e2009-09-05 21:47:34 +00008047 *images=fourier_image;
8048 break;
8049 }
8050 if (LocaleCompare("insert",option+1) == 0)
8051 {
8052 Image
8053 *p,
8054 *q;
8055
8056 index=0;
8057 if (*option != '+')
cristy32c2aea2010-12-01 01:00:50 +00008058 index=(ssize_t) StringToLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00008059 p=RemoveLastImageFromList(images);
8060 if (p == (Image *) NULL)
8061 {
8062 (void) ThrowMagickException(exception,GetMagickModule(),
8063 OptionError,"NoSuchImage","`%s'",argv[i+1]);
8064 status=MagickFalse;
8065 break;
8066 }
8067 q=p;
8068 if (index == 0)
8069 PrependImageToList(images,q);
8070 else
cristybb503372010-05-27 20:51:26 +00008071 if (index == (ssize_t) GetImageListLength(*images))
cristy3ed852e2009-09-05 21:47:34 +00008072 AppendImageToList(images,q);
8073 else
8074 {
8075 q=GetImageFromList(*images,index-1);
8076 if (q == (Image *) NULL)
8077 {
8078 (void) ThrowMagickException(exception,GetMagickModule(),
8079 OptionError,"NoSuchImage","`%s'",argv[i+1]);
8080 status=MagickFalse;
8081 break;
8082 }
8083 InsertImageInList(&q,p);
8084 }
8085 *images=GetFirstImageInList(q);
8086 break;
8087 }
8088 break;
8089 }
8090 case 'l':
8091 {
8092 if (LocaleCompare("layers",option+1) == 0)
8093 {
8094 Image
8095 *layers;
8096
8097 ImageLayerMethod
8098 method;
8099
cristy6b3da3a2010-06-20 02:21:46 +00008100 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00008101 layers=(Image *) NULL;
8102 method=(ImageLayerMethod) ParseMagickOption(MagickLayerOptions,
8103 MagickFalse,argv[i+1]);
8104 switch (method)
8105 {
8106 case CoalesceLayer:
8107 {
8108 layers=CoalesceImages(*images,exception);
8109 break;
8110 }
8111 case CompareAnyLayer:
8112 case CompareClearLayer:
8113 case CompareOverlayLayer:
8114 default:
8115 {
8116 layers=CompareImageLayers(*images,method,exception);
8117 break;
8118 }
8119 case MergeLayer:
8120 case FlattenLayer:
8121 case MosaicLayer:
8122 case TrimBoundsLayer:
8123 {
8124 layers=MergeImageLayers(*images,method,exception);
8125 break;
8126 }
8127 case DisposeLayer:
8128 {
8129 layers=DisposeImages(*images,exception);
8130 break;
8131 }
8132 case OptimizeImageLayer:
8133 {
8134 layers=OptimizeImageLayers(*images,exception);
8135 break;
8136 }
8137 case OptimizePlusLayer:
8138 {
8139 layers=OptimizePlusImageLayers(*images,exception);
8140 break;
8141 }
8142 case OptimizeTransLayer:
8143 {
8144 OptimizeImageTransparency(*images,exception);
8145 break;
8146 }
8147 case RemoveDupsLayer:
8148 {
8149 RemoveDuplicateLayers(images,exception);
8150 break;
8151 }
8152 case RemoveZeroLayer:
8153 {
8154 RemoveZeroDelayLayers(images,exception);
8155 break;
8156 }
8157 case OptimizeLayer:
8158 {
8159 /*
8160 General Purpose, GIF Animation Optimizer.
8161 */
8162 layers=CoalesceImages(*images,exception);
8163 if (layers == (Image *) NULL)
8164 {
8165 status=MagickFalse;
8166 break;
8167 }
8168 InheritException(exception,&layers->exception);
8169 *images=DestroyImageList(*images);
8170 *images=layers;
8171 layers=OptimizeImageLayers(*images,exception);
8172 if (layers == (Image *) NULL)
8173 {
8174 status=MagickFalse;
8175 break;
8176 }
8177 InheritException(exception,&layers->exception);
8178 *images=DestroyImageList(*images);
8179 *images=layers;
8180 layers=(Image *) NULL;
8181 OptimizeImageTransparency(*images,exception);
8182 InheritException(exception,&(*images)->exception);
8183 (void) RemapImages(quantize_info,*images,(Image *) NULL);
8184 break;
8185 }
8186 case CompositeLayer:
8187 {
8188 CompositeOperator
8189 compose;
8190
8191 Image
8192 *source;
8193
8194 RectangleInfo
8195 geometry;
8196
8197 /*
8198 Split image sequence at the first 'NULL:' image.
8199 */
8200 source=(*images);
8201 while (source != (Image *) NULL)
8202 {
8203 source=GetNextImageInList(source);
8204 if ((source != (Image *) NULL) &&
8205 (LocaleCompare(source->magick,"NULL") == 0))
8206 break;
8207 }
8208 if (source != (Image *) NULL)
8209 {
8210 if ((GetPreviousImageInList(source) == (Image *) NULL) ||
8211 (GetNextImageInList(source) == (Image *) NULL))
8212 source=(Image *) NULL;
8213 else
8214 {
8215 /*
8216 Separate the two lists, junk the null: image.
8217 */
8218 source=SplitImageList(source->previous);
8219 DeleteImageFromList(&source);
8220 }
8221 }
8222 if (source == (Image *) NULL)
8223 {
8224 (void) ThrowMagickException(exception,GetMagickModule(),
8225 OptionError,"MissingNullSeparator","layers Composite");
8226 status=MagickFalse;
8227 break;
8228 }
8229 /*
8230 Adjust offset with gravity and virtual canvas.
8231 */
8232 SetGeometry(*images,&geometry);
8233 (void) ParseAbsoluteGeometry((*images)->geometry,&geometry);
8234 geometry.width=source->page.width != 0 ?
8235 source->page.width : source->columns;
8236 geometry.height=source->page.height != 0 ?
8237 source->page.height : source->rows;
8238 GravityAdjustGeometry((*images)->page.width != 0 ?
8239 (*images)->page.width : (*images)->columns,
8240 (*images)->page.height != 0 ? (*images)->page.height :
8241 (*images)->rows,(*images)->gravity,&geometry);
8242 compose=OverCompositeOp;
cristy6b3da3a2010-06-20 02:21:46 +00008243 option=GetImageOption(mogrify_info,"compose");
cristy3ed852e2009-09-05 21:47:34 +00008244 if (option != (const char *) NULL)
8245 compose=(CompositeOperator) ParseMagickOption(
8246 MagickComposeOptions,MagickFalse,option);
8247 CompositeLayers(*images,compose,source,geometry.x,geometry.y,
8248 exception);
8249 source=DestroyImageList(source);
8250 break;
8251 }
8252 }
8253 if (layers == (Image *) NULL)
8254 break;
8255 InheritException(exception,&layers->exception);
8256 *images=DestroyImageList(*images);
8257 *images=layers;
8258 break;
8259 }
8260 break;
8261 }
8262 case 'm':
8263 {
8264 if (LocaleCompare("map",option+1) == 0)
8265 {
cristy6b3da3a2010-06-20 02:21:46 +00008266 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00008267 if (*option == '+')
8268 {
8269 (void) RemapImages(quantize_info,*images,(Image *) NULL);
8270 InheritException(exception,&(*images)->exception);
8271 break;
8272 }
8273 i++;
8274 break;
8275 }
cristyf40785b2010-03-06 02:27:27 +00008276 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00008277 {
8278 Image
cristyf40785b2010-03-06 02:27:27 +00008279 *maximum_image;
cristy1c274c92010-03-06 02:06:45 +00008280
cristyd18ae7c2010-03-07 17:39:52 +00008281 /*
8282 Maximum image sequence (deprecated).
8283 */
cristy6b3da3a2010-06-20 02:21:46 +00008284 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00008285 maximum_image=EvaluateImages(*images,MaxEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00008286 if (maximum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00008287 {
8288 status=MagickFalse;
8289 break;
8290 }
8291 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00008292 *images=maximum_image;
cristy1c274c92010-03-06 02:06:45 +00008293 break;
8294 }
cristyf40785b2010-03-06 02:27:27 +00008295 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00008296 {
8297 Image
cristyf40785b2010-03-06 02:27:27 +00008298 *minimum_image;
cristy1c274c92010-03-06 02:06:45 +00008299
cristyd18ae7c2010-03-07 17:39:52 +00008300 /*
8301 Minimum image sequence (deprecated).
8302 */
cristy6b3da3a2010-06-20 02:21:46 +00008303 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00008304 minimum_image=EvaluateImages(*images,MinEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00008305 if (minimum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00008306 {
8307 status=MagickFalse;
8308 break;
8309 }
8310 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00008311 *images=minimum_image;
cristy1c274c92010-03-06 02:06:45 +00008312 break;
8313 }
cristy3ed852e2009-09-05 21:47:34 +00008314 if (LocaleCompare("morph",option+1) == 0)
8315 {
8316 Image
8317 *morph_image;
8318
cristy6b3da3a2010-06-20 02:21:46 +00008319 (void) SyncImagesSettings(mogrify_info,*images);
cristye27293e2009-12-18 02:53:20 +00008320 morph_image=MorphImages(*images,StringToUnsignedLong(argv[i+1]),
cristy3ed852e2009-09-05 21:47:34 +00008321 exception);
8322 if (morph_image == (Image *) NULL)
8323 {
8324 status=MagickFalse;
8325 break;
8326 }
8327 *images=DestroyImageList(*images);
8328 *images=morph_image;
8329 break;
8330 }
8331 if (LocaleCompare("mosaic",option+1) == 0)
8332 {
8333 Image
8334 *mosaic_image;
8335
cristy6b3da3a2010-06-20 02:21:46 +00008336 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00008337 mosaic_image=MergeImageLayers(*images,MosaicLayer,exception);
8338 if (mosaic_image == (Image *) NULL)
8339 {
8340 status=MagickFalse;
8341 break;
8342 }
8343 *images=DestroyImageList(*images);
8344 *images=mosaic_image;
8345 break;
8346 }
8347 break;
8348 }
8349 case 'p':
8350 {
8351 if (LocaleCompare("print",option+1) == 0)
8352 {
8353 char
8354 *string;
8355
cristy6b3da3a2010-06-20 02:21:46 +00008356 (void) SyncImagesSettings(mogrify_info,*images);
8357 string=InterpretImageProperties(mogrify_info,*images,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00008358 if (string == (char *) NULL)
8359 break;
8360 InheritException(exception,&(*images)->exception);
8361 (void) fprintf(stdout,"%s",string);
8362 string=DestroyString(string);
8363 }
8364 if (LocaleCompare("process",option+1) == 0)
8365 {
8366 char
8367 **arguments;
8368
8369 int
8370 j,
8371 number_arguments;
8372
cristy6b3da3a2010-06-20 02:21:46 +00008373 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00008374 arguments=StringToArgv(argv[i+1],&number_arguments);
8375 if (arguments == (char **) NULL)
8376 break;
8377 if ((argc > 1) && (strchr(arguments[1],'=') != (char *) NULL))
8378 {
8379 char
8380 breaker,
8381 quote,
8382 *token;
8383
8384 const char
8385 *arguments;
8386
8387 int
8388 next,
8389 status;
8390
8391 size_t
8392 length;
8393
8394 TokenInfo
8395 *token_info;
8396
8397 /*
8398 Support old style syntax, filter="-option arg".
8399 */
8400 length=strlen(argv[i+1]);
8401 token=(char *) NULL;
8402 if (~length >= MaxTextExtent)
8403 token=(char *) AcquireQuantumMemory(length+MaxTextExtent,
8404 sizeof(*token));
8405 if (token == (char *) NULL)
8406 break;
8407 next=0;
8408 arguments=argv[i+1];
8409 token_info=AcquireTokenInfo();
8410 status=Tokenizer(token_info,0,token,length,arguments,"","=",
8411 "\"",'\0',&breaker,&next,&quote);
8412 token_info=DestroyTokenInfo(token_info);
8413 if (status == 0)
8414 {
8415 const char
8416 *argv;
8417
8418 argv=(&(arguments[next]));
8419 (void) InvokeDynamicImageFilter(token,&(*images),1,&argv,
8420 exception);
8421 }
8422 token=DestroyString(token);
8423 break;
8424 }
cristy91c0da22010-05-02 01:44:07 +00008425 (void) SubstituteString(&arguments[1],"-","");
cristy3ed852e2009-09-05 21:47:34 +00008426 (void) InvokeDynamicImageFilter(arguments[1],&(*images),
8427 number_arguments-2,(const char **) arguments+2,exception);
8428 for (j=0; j < number_arguments; j++)
8429 arguments[j]=DestroyString(arguments[j]);
8430 arguments=(char **) RelinquishMagickMemory(arguments);
8431 break;
8432 }
8433 break;
8434 }
8435 case 'r':
8436 {
8437 if (LocaleCompare("reverse",option+1) == 0)
8438 {
8439 ReverseImageList(images);
8440 InheritException(exception,&(*images)->exception);
8441 break;
8442 }
8443 break;
8444 }
8445 case 's':
8446 {
cristy4285d782011-02-09 20:12:28 +00008447 if (LocaleCompare("smush",option+1) == 0)
8448 {
8449 Image
8450 *smush_image;
8451
8452 ssize_t
8453 offset;
8454
8455 (void) SyncImagesSettings(mogrify_info,*images);
8456 offset=(ssize_t) StringToLong(argv[i+1]);
8457 smush_image=SmushImages(*images,*option == '-' ? MagickTrue :
8458 MagickFalse,offset,exception);
8459 if (smush_image == (Image *) NULL)
8460 {
8461 status=MagickFalse;
8462 break;
8463 }
8464 *images=DestroyImageList(*images);
8465 *images=smush_image;
8466 break;
8467 }
cristy3ed852e2009-09-05 21:47:34 +00008468 if (LocaleCompare("swap",option+1) == 0)
8469 {
8470 Image
8471 *p,
8472 *q,
8473 *swap;
8474
cristybb503372010-05-27 20:51:26 +00008475 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00008476 swap_index;
8477
8478 index=(-1);
8479 swap_index=(-2);
8480 if (*option != '+')
8481 {
8482 GeometryInfo
8483 geometry_info;
8484
8485 MagickStatusType
8486 flags;
8487
8488 swap_index=(-1);
8489 flags=ParseGeometry(argv[i+1],&geometry_info);
cristybb503372010-05-27 20:51:26 +00008490 index=(ssize_t) geometry_info.rho;
cristy3ed852e2009-09-05 21:47:34 +00008491 if ((flags & SigmaValue) != 0)
cristybb503372010-05-27 20:51:26 +00008492 swap_index=(ssize_t) geometry_info.sigma;
cristy3ed852e2009-09-05 21:47:34 +00008493 }
8494 p=GetImageFromList(*images,index);
8495 q=GetImageFromList(*images,swap_index);
8496 if ((p == (Image *) NULL) || (q == (Image *) NULL))
8497 {
8498 (void) ThrowMagickException(exception,GetMagickModule(),
8499 OptionError,"NoSuchImage","`%s'",(*images)->filename);
8500 status=MagickFalse;
8501 break;
8502 }
8503 if (p == q)
8504 break;
8505 swap=CloneImage(p,0,0,MagickTrue,exception);
8506 ReplaceImageInList(&p,CloneImage(q,0,0,MagickTrue,exception));
8507 ReplaceImageInList(&q,swap);
8508 *images=GetFirstImageInList(q);
8509 break;
8510 }
8511 break;
8512 }
8513 case 'w':
8514 {
8515 if (LocaleCompare("write",option+1) == 0)
8516 {
cristy071dd7b2010-04-09 13:04:54 +00008517 char
cristy06609ee2010-03-17 20:21:27 +00008518 key[MaxTextExtent];
8519
cristy3ed852e2009-09-05 21:47:34 +00008520 Image
8521 *write_images;
8522
8523 ImageInfo
8524 *write_info;
8525
cristy6b3da3a2010-06-20 02:21:46 +00008526 (void) SyncImagesSettings(mogrify_info,*images);
cristy06609ee2010-03-17 20:21:27 +00008527 (void) FormatMagickString(key,MaxTextExtent,"cache:%s",argv[i+1]);
8528 (void) DeleteImageRegistry(key);
cristy3ed852e2009-09-05 21:47:34 +00008529 write_images=(*images);
8530 if (*option == '+')
8531 write_images=CloneImageList(*images,exception);
cristy6b3da3a2010-06-20 02:21:46 +00008532 write_info=CloneImageInfo(mogrify_info);
cristy3ed852e2009-09-05 21:47:34 +00008533 status&=WriteImages(write_info,write_images,argv[i+1],exception);
8534 write_info=DestroyImageInfo(write_info);
8535 if (*option == '+')
8536 write_images=DestroyImageList(write_images);
8537 break;
8538 }
8539 break;
8540 }
8541 default:
8542 break;
8543 }
8544 i+=count;
8545 }
8546 quantize_info=DestroyQuantizeInfo(quantize_info);
cristy6b3da3a2010-06-20 02:21:46 +00008547 mogrify_info=DestroyImageInfo(mogrify_info);
8548 status&=MogrifyImageInfo(image_info,argc,argv,exception);
cristy3ed852e2009-09-05 21:47:34 +00008549 return(status != 0 ? MagickTrue : MagickFalse);
8550}
8551
8552/*
8553%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8554% %
8555% %
8556% %
8557+ M o g r i f y I m a g e s %
8558% %
8559% %
8560% %
8561%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8562%
8563% MogrifyImages() applies image processing options to a sequence of images as
8564% prescribed by command line options.
8565%
8566% The format of the MogrifyImage method is:
8567%
8568% MagickBooleanType MogrifyImages(ImageInfo *image_info,
8569% const MagickBooleanType post,const int argc,const char **argv,
8570% Image **images,Exceptioninfo *exception)
8571%
8572% A description of each parameter follows:
8573%
8574% o image_info: the image info..
8575%
8576% o post: If true, post process image list operators otherwise pre-process.
8577%
8578% o argc: Specifies a pointer to an integer describing the number of
8579% elements in the argument vector.
8580%
8581% o argv: Specifies a pointer to a text array containing the command line
8582% arguments.
8583%
8584% o images: the images.
8585%
8586% o exception: return any errors or warnings in this structure.
8587%
8588*/
8589WandExport MagickBooleanType MogrifyImages(ImageInfo *image_info,
8590 const MagickBooleanType post,const int argc,const char **argv,
8591 Image **images,ExceptionInfo *exception)
8592{
8593#define MogrifyImageTag "Mogrify/Image"
8594
8595 Image
8596 *image,
8597 *mogrify_images;
8598
cristy0e9f9c12010-02-11 03:00:47 +00008599 MagickBooleanType
8600 proceed;
8601
8602 MagickSizeType
8603 number_images;
8604
cristy3ed852e2009-09-05 21:47:34 +00008605 MagickStatusType
8606 status;
8607
cristybb503372010-05-27 20:51:26 +00008608 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00008609 i;
8610
cristy3ed852e2009-09-05 21:47:34 +00008611 /*
8612 Apply options to individual images in the list.
8613 */
8614 assert(image_info != (ImageInfo *) NULL);
8615 assert(image_info->signature == MagickSignature);
8616 if (images == (Image **) NULL)
8617 return(MogrifyImage(image_info,argc,argv,images,exception));
8618 assert((*images)->signature == MagickSignature);
8619 if ((*images)->debug != MagickFalse)
8620 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
8621 (*images)->filename);
8622 if ((argc <= 0) || (*argv == (char *) NULL))
8623 return(MagickTrue);
8624 (void) SetImageInfoProgressMonitor(image_info,(MagickProgressMonitor) NULL,
8625 (void *) NULL);
8626 mogrify_images=NewImageList();
8627 number_images=GetImageListLength(*images);
8628 status=0;
8629 if (post == MagickFalse)
8630 status&=MogrifyImageList(image_info,argc,argv,images,exception);
cristybb503372010-05-27 20:51:26 +00008631 for (i=0; i < (ssize_t) number_images; i++)
cristy3ed852e2009-09-05 21:47:34 +00008632 {
8633 image=RemoveFirstImageFromList(images);
8634 if (image == (Image *) NULL)
8635 continue;
8636 status&=MogrifyImage(image_info,argc,argv,&image,exception);
8637 AppendImageToList(&mogrify_images,image);
cristy0e9f9c12010-02-11 03:00:47 +00008638 proceed=SetImageProgress(image,MogrifyImageTag,(MagickOffsetType) i,
8639 number_images);
8640 if (proceed == MagickFalse)
8641 break;
cristy3ed852e2009-09-05 21:47:34 +00008642 }
8643 if (post != MagickFalse)
8644 status&=MogrifyImageList(image_info,argc,argv,&mogrify_images,exception);
8645 *images=mogrify_images;
8646 return(status != 0 ? MagickTrue : MagickFalse);
8647}