blob: 2afefb8432dc60df94154db604216fa90521aac6 [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
cristybb503372010-05-27 20:51:26 +0000599 ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000600 count;
601
602 MagickBooleanType
603 status;
604
605 MagickPixelPacket
606 fill;
607
608 MagickStatusType
609 flags;
610
611 QuantizeInfo
612 *quantize_info;
613
614 RectangleInfo
615 geometry,
616 region_geometry;
617
cristybb503372010-05-27 20:51:26 +0000618 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000619 i;
620
621 /*
622 Initialize method variables.
623 */
624 assert(image_info != (const ImageInfo *) NULL);
625 assert(image_info->signature == MagickSignature);
626 assert(image != (Image **) NULL);
627 assert((*image)->signature == MagickSignature);
628 if ((*image)->debug != MagickFalse)
629 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",(*image)->filename);
630 if (argc < 0)
631 return(MagickTrue);
cristy6b3da3a2010-06-20 02:21:46 +0000632 mogrify_info=CloneImageInfo(image_info);
633 draw_info=CloneDrawInfo(mogrify_info,(DrawInfo *) NULL);
634 quantize_info=AcquireQuantizeInfo(mogrify_info);
cristy3ed852e2009-09-05 21:47:34 +0000635 SetGeometryInfo(&geometry_info);
636 GetMagickPixelPacket(*image,&fill);
637 SetMagickPixelPacket(*image,&(*image)->background_color,(IndexPacket *) NULL,
638 &fill);
cristy6b3da3a2010-06-20 02:21:46 +0000639 channel=mogrify_info->channel;
640 format=GetImageOption(mogrify_info,"format");
cristy3ed852e2009-09-05 21:47:34 +0000641 SetGeometry(*image,&region_geometry);
642 region_image=NewImageList();
643 /*
644 Transmogrify the image.
645 */
cristybb503372010-05-27 20:51:26 +0000646 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +0000647 {
648 option=argv[i];
649 if (IsMagickOption(option) == MagickFalse)
650 continue;
651 count=MagickMax(ParseMagickOption(MagickCommandOptions,MagickFalse,option),
652 0L);
cristycee97112010-05-28 00:44:52 +0000653 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +0000654 break;
cristy6b3da3a2010-06-20 02:21:46 +0000655 status=MogrifyImageInfo(mogrify_info,(int) count+1,argv+i,exception);
cristy3ed852e2009-09-05 21:47:34 +0000656 switch (*(option+1))
657 {
658 case 'a':
659 {
660 if (LocaleCompare("adaptive-blur",option+1) == 0)
661 {
662 Image
663 *blur_image;
664
665 /*
666 Adaptive blur image.
667 */
cristy6b3da3a2010-06-20 02:21:46 +0000668 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000669 flags=ParseGeometry(argv[i+1],&geometry_info);
670 if ((flags & SigmaValue) == 0)
671 geometry_info.sigma=1.0;
672 blur_image=AdaptiveBlurImageChannel(*image,channel,
673 geometry_info.rho,geometry_info.sigma,exception);
674 if (blur_image == (Image *) NULL)
675 break;
676 *image=DestroyImage(*image);
677 *image=blur_image;
678 break;
679 }
680 if (LocaleCompare("adaptive-resize",option+1) == 0)
681 {
682 Image
683 *resize_image;
684
685 /*
686 Adaptive resize image.
687 */
cristy6b3da3a2010-06-20 02:21:46 +0000688 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000689 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
690 resize_image=AdaptiveResizeImage(*image,geometry.width,
691 geometry.height,exception);
692 if (resize_image == (Image *) NULL)
693 break;
694 *image=DestroyImage(*image);
695 *image=resize_image;
696 break;
697 }
698 if (LocaleCompare("adaptive-sharpen",option+1) == 0)
699 {
700 Image
701 *sharp_image;
702
703 /*
704 Adaptive sharpen image.
705 */
cristy6b3da3a2010-06-20 02:21:46 +0000706 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000707 flags=ParseGeometry(argv[i+1],&geometry_info);
708 if ((flags & SigmaValue) == 0)
709 geometry_info.sigma=1.0;
710 sharp_image=AdaptiveSharpenImageChannel(*image,channel,
711 geometry_info.rho,geometry_info.sigma,exception);
712 if (sharp_image == (Image *) NULL)
713 break;
714 *image=DestroyImage(*image);
715 *image=sharp_image;
716 break;
717 }
718 if (LocaleCompare("affine",option+1) == 0)
719 {
720 /*
721 Affine matrix.
722 */
723 if (*option == '+')
724 {
725 GetAffineMatrix(&draw_info->affine);
726 break;
727 }
728 (void) ParseAffineGeometry(argv[i+1],&draw_info->affine,exception);
729 break;
730 }
731 if (LocaleCompare("alpha",option+1) == 0)
732 {
733 AlphaChannelType
734 alpha_type;
735
cristy6b3da3a2010-06-20 02:21:46 +0000736 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000737 alpha_type=(AlphaChannelType) ParseMagickOption(MagickAlphaOptions,
738 MagickFalse,argv[i+1]);
739 (void) SetImageAlphaChannel(*image,alpha_type);
740 InheritException(exception,&(*image)->exception);
741 break;
742 }
743 if (LocaleCompare("annotate",option+1) == 0)
744 {
745 char
746 *text,
747 geometry[MaxTextExtent];
748
749 /*
750 Annotate image.
751 */
cristy6b3da3a2010-06-20 02:21:46 +0000752 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000753 SetGeometryInfo(&geometry_info);
754 flags=ParseGeometry(argv[i+1],&geometry_info);
755 if ((flags & SigmaValue) == 0)
756 geometry_info.sigma=geometry_info.rho;
cristy6b3da3a2010-06-20 02:21:46 +0000757 text=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
cristy3ed852e2009-09-05 21:47:34 +0000758 InheritException(exception,&(*image)->exception);
759 if (text == (char *) NULL)
760 break;
761 (void) CloneString(&draw_info->text,text);
762 text=DestroyString(text);
763 (void) FormatMagickString(geometry,MaxTextExtent,"%+f%+f",
764 geometry_info.xi,geometry_info.psi);
765 (void) CloneString(&draw_info->geometry,geometry);
766 draw_info->affine.sx=cos(DegreesToRadians(
767 fmod(geometry_info.rho,360.0)));
768 draw_info->affine.rx=sin(DegreesToRadians(
769 fmod(geometry_info.rho,360.0)));
770 draw_info->affine.ry=(-sin(DegreesToRadians(
771 fmod(geometry_info.sigma,360.0))));
772 draw_info->affine.sy=cos(DegreesToRadians(
773 fmod(geometry_info.sigma,360.0)));
774 (void) AnnotateImage(*image,draw_info);
775 InheritException(exception,&(*image)->exception);
776 break;
777 }
778 if (LocaleCompare("antialias",option+1) == 0)
779 {
780 draw_info->stroke_antialias=(*option == '-') ? MagickTrue :
781 MagickFalse;
782 draw_info->text_antialias=(*option == '-') ? MagickTrue :
783 MagickFalse;
784 break;
785 }
786 if (LocaleCompare("auto-gamma",option+1) == 0)
787 {
788 /*
789 Auto Adjust Gamma of image based on its mean
790 */
cristy6b3da3a2010-06-20 02:21:46 +0000791 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000792 (void) AutoGammaImageChannel(*image,channel);
793 break;
794 }
795 if (LocaleCompare("auto-level",option+1) == 0)
796 {
797 /*
798 Perfectly Normalize (max/min stretch) the image
799 */
cristy6b3da3a2010-06-20 02:21:46 +0000800 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000801 (void) AutoLevelImageChannel(*image,channel);
802 break;
803 }
804 if (LocaleCompare("auto-orient",option+1) == 0)
805 {
806 Image
807 *orient_image;
808
cristy6b3da3a2010-06-20 02:21:46 +0000809 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000810 orient_image=NewImageList();
811 switch ((*image)->orientation)
812 {
813 case TopRightOrientation:
814 {
815 orient_image=FlopImage(*image,exception);
816 break;
817 }
818 case BottomRightOrientation:
819 {
820 orient_image=RotateImage(*image,180.0,exception);
821 break;
822 }
823 case BottomLeftOrientation:
824 {
825 orient_image=FlipImage(*image,exception);
826 break;
827 }
828 case LeftTopOrientation:
829 {
830 orient_image=TransposeImage(*image,exception);
831 break;
832 }
833 case RightTopOrientation:
834 {
835 orient_image=RotateImage(*image,90.0,exception);
836 break;
837 }
838 case RightBottomOrientation:
839 {
840 orient_image=TransverseImage(*image,exception);
841 break;
842 }
843 case LeftBottomOrientation:
844 {
845 orient_image=RotateImage(*image,270.0,exception);
846 break;
847 }
848 default:
849 break;
850 }
851 if (orient_image == (Image *) NULL)
852 break;
853 orient_image->orientation=TopLeftOrientation;
854 *image=DestroyImage(*image);
855 *image=orient_image;
856 break;
857 }
858 break;
859 }
860 case 'b':
861 {
862 if (LocaleCompare("black-threshold",option+1) == 0)
863 {
864 /*
865 Black threshold image.
866 */
cristy6b3da3a2010-06-20 02:21:46 +0000867 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000868 (void) BlackThresholdImageChannel(*image,channel,argv[i+1],
869 exception);
870 InheritException(exception,&(*image)->exception);
871 break;
872 }
873 if (LocaleCompare("blue-shift",option+1) == 0)
874 {
875 Image
876 *shift_image;
877
878 /*
879 Blue shift image.
880 */
cristy6b3da3a2010-06-20 02:21:46 +0000881 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000882 geometry_info.rho=1.5;
883 if (*option == '-')
884 flags=ParseGeometry(argv[i+1],&geometry_info);
885 shift_image=BlueShiftImage(*image,geometry_info.rho,exception);
886 if (shift_image == (Image *) NULL)
887 break;
888 *image=DestroyImage(*image);
889 *image=shift_image;
890 break;
891 }
892 if (LocaleCompare("blur",option+1) == 0)
893 {
894 Image
895 *blur_image;
896
897 /*
898 Gaussian blur image.
899 */
cristy6b3da3a2010-06-20 02:21:46 +0000900 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000901 flags=ParseGeometry(argv[i+1],&geometry_info);
902 if ((flags & SigmaValue) == 0)
903 geometry_info.sigma=1.0;
904 blur_image=BlurImageChannel(*image,channel,geometry_info.rho,
905 geometry_info.sigma,exception);
906 if (blur_image == (Image *) NULL)
907 break;
908 *image=DestroyImage(*image);
909 *image=blur_image;
910 break;
911 }
912 if (LocaleCompare("border",option+1) == 0)
913 {
914 Image
915 *border_image;
916
917 /*
918 Surround image with a border of solid color.
919 */
cristy6b3da3a2010-06-20 02:21:46 +0000920 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000921 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
922 if ((flags & SigmaValue) == 0)
923 geometry.height=geometry.width;
924 border_image=BorderImage(*image,&geometry,exception);
925 if (border_image == (Image *) NULL)
926 break;
927 *image=DestroyImage(*image);
928 *image=border_image;
929 break;
930 }
931 if (LocaleCompare("bordercolor",option+1) == 0)
932 {
933 if (*option == '+')
934 {
935 (void) QueryColorDatabase(BorderColor,&draw_info->border_color,
936 exception);
937 break;
938 }
939 (void) QueryColorDatabase(argv[i+1],&draw_info->border_color,
940 exception);
941 break;
942 }
943 if (LocaleCompare("box",option+1) == 0)
944 {
945 (void) QueryColorDatabase(argv[i+1],&draw_info->undercolor,
946 exception);
947 break;
948 }
cristya28d6b82010-01-11 20:03:47 +0000949 if (LocaleCompare("brightness-contrast",option+1) == 0)
950 {
951 double
952 brightness,
953 contrast;
954
955 GeometryInfo
956 geometry_info;
957
958 MagickStatusType
959 flags;
960
961 /*
962 Brightness / contrast image.
963 */
cristy6b3da3a2010-06-20 02:21:46 +0000964 (void) SyncImageSettings(mogrify_info,*image);
cristya28d6b82010-01-11 20:03:47 +0000965 flags=ParseGeometry(argv[i+1],&geometry_info);
966 brightness=geometry_info.rho;
cristy81fbc8b2010-01-11 20:04:07 +0000967 contrast=0.0;
cristya28d6b82010-01-11 20:03:47 +0000968 if ((flags & SigmaValue) != 0)
969 contrast=geometry_info.sigma;
cristy02cc0f22010-01-12 00:02:32 +0000970 (void) BrightnessContrastImageChannel(*image,channel,brightness,
971 contrast);
cristya28d6b82010-01-11 20:03:47 +0000972 InheritException(exception,&(*image)->exception);
973 break;
974 }
cristy3ed852e2009-09-05 21:47:34 +0000975 break;
976 }
977 case 'c':
978 {
979 if (LocaleCompare("cdl",option+1) == 0)
980 {
981 char
982 *color_correction_collection;
983
984 /*
985 Color correct with a color decision list.
986 */
cristy6b3da3a2010-06-20 02:21:46 +0000987 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000988 color_correction_collection=FileToString(argv[i+1],~0,exception);
989 if (color_correction_collection == (char *) NULL)
990 break;
991 (void) ColorDecisionListImage(*image,color_correction_collection);
992 InheritException(exception,&(*image)->exception);
993 break;
994 }
995 if (LocaleCompare("channel",option+1) == 0)
996 {
997 if (*option == '+')
998 {
999 channel=DefaultChannels;
1000 break;
1001 }
1002 channel=(ChannelType) ParseChannelOption(argv[i+1]);
1003 break;
1004 }
1005 if (LocaleCompare("charcoal",option+1) == 0)
1006 {
1007 Image
1008 *charcoal_image;
1009
1010 /*
1011 Charcoal image.
1012 */
cristy6b3da3a2010-06-20 02:21:46 +00001013 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001014 flags=ParseGeometry(argv[i+1],&geometry_info);
1015 if ((flags & SigmaValue) == 0)
1016 geometry_info.sigma=1.0;
1017 charcoal_image=CharcoalImage(*image,geometry_info.rho,
1018 geometry_info.sigma,exception);
1019 if (charcoal_image == (Image *) NULL)
1020 break;
1021 *image=DestroyImage(*image);
1022 *image=charcoal_image;
1023 break;
1024 }
1025 if (LocaleCompare("chop",option+1) == 0)
1026 {
1027 Image
1028 *chop_image;
1029
1030 /*
1031 Chop the image.
1032 */
cristy6b3da3a2010-06-20 02:21:46 +00001033 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001034 (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1035 chop_image=ChopImage(*image,&geometry,exception);
1036 if (chop_image == (Image *) NULL)
1037 break;
1038 *image=DestroyImage(*image);
1039 *image=chop_image;
1040 break;
1041 }
cristy1eb45dd2009-09-25 16:38:06 +00001042 if (LocaleCompare("clamp",option+1) == 0)
1043 {
1044 /*
1045 Clamp image.
1046 */
cristy6b3da3a2010-06-20 02:21:46 +00001047 (void) SyncImageSettings(mogrify_info,*image);
cristy1eb45dd2009-09-25 16:38:06 +00001048 (void) ClampImageChannel(*image,channel);
1049 InheritException(exception,&(*image)->exception);
1050 break;
1051 }
cristy3ed852e2009-09-05 21:47:34 +00001052 if (LocaleCompare("clip",option+1) == 0)
1053 {
cristy6b3da3a2010-06-20 02:21:46 +00001054 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001055 if (*option == '+')
1056 {
1057 (void) SetImageClipMask(*image,(Image *) NULL);
1058 InheritException(exception,&(*image)->exception);
1059 break;
1060 }
1061 (void) ClipImage(*image);
1062 InheritException(exception,&(*image)->exception);
1063 break;
1064 }
1065 if (LocaleCompare("clip-mask",option+1) == 0)
1066 {
cristyb0d3bb92010-09-22 14:37:58 +00001067 CacheView
1068 *mask_view;
cristya01cbea2010-11-03 16:33:33 +00001069
cristy3ed852e2009-09-05 21:47:34 +00001070 Image
cristyb0d3bb92010-09-22 14:37:58 +00001071 *mask_image;
cristy3ed852e2009-09-05 21:47:34 +00001072
cristybb503372010-05-27 20:51:26 +00001073 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001074 y;
1075
cristybb503372010-05-27 20:51:26 +00001076 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001077 x;
1078
1079 register PixelPacket
cristyc47d1f82009-11-26 01:44:43 +00001080 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00001081
cristy6b3da3a2010-06-20 02:21:46 +00001082 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001083 if (*option == '+')
1084 {
1085 /*
1086 Remove a mask.
1087 */
1088 (void) SetImageMask(*image,(Image *) NULL);
1089 InheritException(exception,&(*image)->exception);
1090 break;
1091 }
1092 /*
1093 Set the image mask.
1094 */
cristyb0d3bb92010-09-22 14:37:58 +00001095 mask_image=GetImageCache(mogrify_info,argv[i+1],exception);
1096 if (mask_image == (Image *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001097 break;
cristyb0d3bb92010-09-22 14:37:58 +00001098 if (SetImageStorageClass(mask_image,DirectClass) == MagickFalse)
1099 return(MagickFalse);
1100 mask_view=AcquireCacheView(mask_image);
1101 for (y=0; y < (ssize_t) mask_image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00001102 {
cristyb0d3bb92010-09-22 14:37:58 +00001103 q=GetCacheViewAuthenticPixels(mask_view,0,y,mask_image->columns,1,
1104 exception);
cristy3ed852e2009-09-05 21:47:34 +00001105 if (q == (PixelPacket *) NULL)
1106 break;
cristyb0d3bb92010-09-22 14:37:58 +00001107 for (x=0; x < (ssize_t) mask_image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00001108 {
cristyb0d3bb92010-09-22 14:37:58 +00001109 if (mask_image->matte == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00001110 q->opacity=PixelIntensityToQuantum(q);
1111 q->red=q->opacity;
1112 q->green=q->opacity;
1113 q->blue=q->opacity;
1114 q++;
1115 }
cristyb0d3bb92010-09-22 14:37:58 +00001116 if (SyncCacheViewAuthenticPixels(mask_view,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00001117 break;
1118 }
cristyb0d3bb92010-09-22 14:37:58 +00001119 mask_view=DestroyCacheView(mask_view);
1120 mask_image->matte=MagickTrue;
1121 (void) SetImageClipMask(*image,mask_image);
1122 mask_image=DestroyImage(mask_image);
cristy3ed852e2009-09-05 21:47:34 +00001123 InheritException(exception,&(*image)->exception);
1124 break;
1125 }
1126 if (LocaleCompare("clip-path",option+1) == 0)
1127 {
cristy6b3da3a2010-06-20 02:21:46 +00001128 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001129 (void) ClipImagePath(*image,argv[i+1],*option == '-' ? MagickTrue :
1130 MagickFalse);
1131 InheritException(exception,&(*image)->exception);
1132 break;
1133 }
1134 if (LocaleCompare("colorize",option+1) == 0)
1135 {
1136 Image
1137 *colorize_image;
1138
1139 /*
1140 Colorize the image.
1141 */
cristy6b3da3a2010-06-20 02:21:46 +00001142 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001143 colorize_image=ColorizeImage(*image,argv[i+1],draw_info->fill,
1144 exception);
1145 if (colorize_image == (Image *) NULL)
1146 break;
1147 *image=DestroyImage(*image);
1148 *image=colorize_image;
1149 break;
1150 }
cristye6365592010-04-02 17:31:23 +00001151 if (LocaleCompare("color-matrix",option+1) == 0)
1152 {
1153 Image
1154 *color_image;
1155
1156 KernelInfo
1157 *kernel;
1158
cristy6b3da3a2010-06-20 02:21:46 +00001159 (void) SyncImageSettings(mogrify_info,*image);
cristye6365592010-04-02 17:31:23 +00001160 kernel=AcquireKernelInfo(argv[i+1]);
1161 if (kernel == (KernelInfo *) NULL)
1162 break;
1163 color_image=ColorMatrixImage(*image,kernel,exception);
1164 kernel=DestroyKernelInfo(kernel);
1165 if (color_image == (Image *) NULL)
1166 break;
1167 *image=DestroyImage(*image);
1168 *image=color_image;
1169 break;
1170 }
cristy3ed852e2009-09-05 21:47:34 +00001171 if (LocaleCompare("colors",option+1) == 0)
1172 {
1173 /*
1174 Reduce the number of colors in the image.
1175 */
cristy6b3da3a2010-06-20 02:21:46 +00001176 (void) SyncImageSettings(mogrify_info,*image);
cristye27293e2009-12-18 02:53:20 +00001177 quantize_info->number_colors=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00001178 if (quantize_info->number_colors == 0)
1179 break;
1180 if (((*image)->storage_class == DirectClass) ||
1181 (*image)->colors > quantize_info->number_colors)
1182 (void) QuantizeImage(quantize_info,*image);
1183 else
1184 (void) CompressImageColormap(*image);
1185 InheritException(exception,&(*image)->exception);
1186 break;
1187 }
1188 if (LocaleCompare("colorspace",option+1) == 0)
1189 {
1190 ColorspaceType
1191 colorspace;
1192
cristy6b3da3a2010-06-20 02:21:46 +00001193 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001194 if (*option == '+')
1195 {
1196 (void) TransformImageColorspace(*image,RGBColorspace);
1197 InheritException(exception,&(*image)->exception);
1198 break;
1199 }
1200 colorspace=(ColorspaceType) ParseMagickOption(
1201 MagickColorspaceOptions,MagickFalse,argv[i+1]);
1202 (void) TransformImageColorspace(*image,colorspace);
1203 InheritException(exception,&(*image)->exception);
1204 break;
1205 }
1206 if (LocaleCompare("contrast",option+1) == 0)
1207 {
cristy6b3da3a2010-06-20 02:21:46 +00001208 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001209 (void) ContrastImage(*image,(*option == '-') ? MagickTrue :
1210 MagickFalse);
1211 InheritException(exception,&(*image)->exception);
1212 break;
1213 }
1214 if (LocaleCompare("contrast-stretch",option+1) == 0)
1215 {
1216 double
1217 black_point,
1218 white_point;
1219
cristy3ed852e2009-09-05 21:47:34 +00001220 MagickStatusType
1221 flags;
1222
1223 /*
1224 Contrast stretch image.
1225 */
cristy6b3da3a2010-06-20 02:21:46 +00001226 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001227 flags=ParseGeometry(argv[i+1],&geometry_info);
1228 black_point=geometry_info.rho;
1229 white_point=(flags & SigmaValue) != 0 ? geometry_info.sigma :
1230 black_point;
1231 if ((flags & PercentValue) != 0)
1232 {
1233 black_point*=(double) (*image)->columns*(*image)->rows/100.0;
1234 white_point*=(double) (*image)->columns*(*image)->rows/100.0;
1235 }
1236 white_point=(MagickRealType) (*image)->columns*(*image)->rows-
1237 white_point;
1238 (void) ContrastStretchImageChannel(*image,channel,black_point,
1239 white_point);
1240 InheritException(exception,&(*image)->exception);
1241 break;
1242 }
1243 if (LocaleCompare("convolve",option+1) == 0)
1244 {
cristy36826ab2010-03-06 01:29:30 +00001245 double
1246 gamma;
1247
cristy3ed852e2009-09-05 21:47:34 +00001248 Image
1249 *convolve_image;
1250
cristy2be15382010-01-21 02:38:03 +00001251 KernelInfo
cristy56a9e512010-01-06 18:18:55 +00001252 *kernel;
cristy3ed852e2009-09-05 21:47:34 +00001253
cristybb503372010-05-27 20:51:26 +00001254 register ssize_t
cristy36826ab2010-03-06 01:29:30 +00001255 j;
1256
cristy6b3da3a2010-06-20 02:21:46 +00001257 (void) SyncImageSettings(mogrify_info,*image);
cristy2be15382010-01-21 02:38:03 +00001258 kernel=AcquireKernelInfo(argv[i+1]);
1259 if (kernel == (KernelInfo *) NULL)
cristy56a9e512010-01-06 18:18:55 +00001260 break;
cristy36826ab2010-03-06 01:29:30 +00001261 gamma=0.0;
cristybb503372010-05-27 20:51:26 +00001262 for (j=0; j < (ssize_t) (kernel->width*kernel->height); j++)
cristy36826ab2010-03-06 01:29:30 +00001263 gamma+=kernel->values[j];
1264 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
cristybb503372010-05-27 20:51:26 +00001265 for (j=0; j < (ssize_t) (kernel->width*kernel->height); j++)
cristy36826ab2010-03-06 01:29:30 +00001266 kernel->values[j]*=gamma;
cristy6771f1e2010-03-05 19:43:39 +00001267 convolve_image=FilterImageChannel(*image,channel,kernel,exception);
anthony83ba99b2010-01-24 08:48:15 +00001268 kernel=DestroyKernelInfo(kernel);
cristy3ed852e2009-09-05 21:47:34 +00001269 if (convolve_image == (Image *) NULL)
1270 break;
1271 *image=DestroyImage(*image);
1272 *image=convolve_image;
1273 break;
1274 }
1275 if (LocaleCompare("crop",option+1) == 0)
1276 {
cristy6b3da3a2010-06-20 02:21:46 +00001277 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001278 flags=ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1279 if (((geometry.width != 0) || (geometry.height != 0)) &&
1280 ((flags & XValue) == 0) && ((flags & YValue) == 0))
1281 break;
1282 (void) TransformImage(image,argv[i+1],(char *) NULL);
1283 InheritException(exception,&(*image)->exception);
1284 break;
1285 }
1286 if (LocaleCompare("cycle",option+1) == 0)
1287 {
1288 /*
1289 Cycle an image colormap.
1290 */
cristy6b3da3a2010-06-20 02:21:46 +00001291 (void) SyncImageSettings(mogrify_info,*image);
cristy32c2aea2010-12-01 01:00:50 +00001292 (void) CycleColormapImage(*image,(ssize_t) StringToLong(argv[i+1]));
cristy3ed852e2009-09-05 21:47:34 +00001293 InheritException(exception,&(*image)->exception);
1294 break;
1295 }
1296 break;
1297 }
1298 case 'd':
1299 {
1300 if (LocaleCompare("decipher",option+1) == 0)
1301 {
1302 StringInfo
1303 *passkey;
1304
1305 /*
1306 Decipher pixels.
1307 */
cristy6b3da3a2010-06-20 02:21:46 +00001308 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001309 passkey=FileToStringInfo(argv[i+1],~0,exception);
1310 if (passkey != (StringInfo *) NULL)
1311 {
1312 (void) PasskeyDecipherImage(*image,passkey,exception);
1313 passkey=DestroyStringInfo(passkey);
1314 }
1315 break;
1316 }
1317 if (LocaleCompare("density",option+1) == 0)
1318 {
1319 /*
1320 Set image density.
1321 */
1322 (void) CloneString(&draw_info->density,argv[i+1]);
1323 break;
1324 }
1325 if (LocaleCompare("depth",option+1) == 0)
1326 {
cristy6b3da3a2010-06-20 02:21:46 +00001327 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001328 if (*option == '+')
1329 {
1330 (void) SetImageDepth(*image,MAGICKCORE_QUANTUM_DEPTH);
1331 break;
1332 }
cristye27293e2009-12-18 02:53:20 +00001333 (void) SetImageDepth(*image,StringToUnsignedLong(argv[i+1]));
cristy3ed852e2009-09-05 21:47:34 +00001334 break;
1335 }
1336 if (LocaleCompare("deskew",option+1) == 0)
1337 {
1338 double
1339 threshold;
1340
1341 Image
1342 *deskew_image;
1343
1344 /*
1345 Straighten the image.
1346 */
cristy6b3da3a2010-06-20 02:21:46 +00001347 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001348 if (*option == '+')
1349 threshold=40.0*QuantumRange/100.0;
1350 else
cristyf2f27272009-12-17 14:48:46 +00001351 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
cristy3ed852e2009-09-05 21:47:34 +00001352 deskew_image=DeskewImage(*image,threshold,exception);
1353 if (deskew_image == (Image *) NULL)
1354 break;
1355 *image=DestroyImage(*image);
1356 *image=deskew_image;
1357 break;
1358 }
1359 if (LocaleCompare("despeckle",option+1) == 0)
1360 {
1361 Image
1362 *despeckle_image;
1363
1364 /*
1365 Reduce the speckles within an image.
1366 */
cristy6b3da3a2010-06-20 02:21:46 +00001367 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001368 despeckle_image=DespeckleImage(*image,exception);
1369 if (despeckle_image == (Image *) NULL)
1370 break;
1371 *image=DestroyImage(*image);
1372 *image=despeckle_image;
1373 break;
1374 }
1375 if (LocaleCompare("display",option+1) == 0)
1376 {
1377 (void) CloneString(&draw_info->server_name,argv[i+1]);
1378 break;
1379 }
cristy3ed852e2009-09-05 21:47:34 +00001380 if (LocaleCompare("distort",option+1) == 0)
1381 {
1382 char
1383 *args,
1384 token[MaxTextExtent];
1385
1386 const char
1387 *p;
1388
1389 DistortImageMethod
1390 method;
1391
1392 double
1393 *arguments;
1394
1395 Image
1396 *distort_image;
1397
cristybb503372010-05-27 20:51:26 +00001398 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001399 x;
1400
cristybb503372010-05-27 20:51:26 +00001401 size_t
cristy3ed852e2009-09-05 21:47:34 +00001402 number_arguments;
1403
1404 /*
1405 Distort image.
1406 */
cristy6b3da3a2010-06-20 02:21:46 +00001407 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001408 method=(DistortImageMethod) ParseMagickOption(MagickDistortOptions,
1409 MagickFalse,argv[i+1]);
cristy6b3da3a2010-06-20 02:21:46 +00001410 args=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
cristy3ed852e2009-09-05 21:47:34 +00001411 InheritException(exception,&(*image)->exception);
1412 if (args == (char *) NULL)
1413 break;
1414 p=(char *) args;
1415 for (x=0; *p != '\0'; x++)
1416 {
1417 GetMagickToken(p,&p,token);
1418 if (*token == ',')
1419 GetMagickToken(p,&p,token);
1420 }
cristybb503372010-05-27 20:51:26 +00001421 number_arguments=(size_t) x;
cristy3ed852e2009-09-05 21:47:34 +00001422 arguments=(double *) AcquireQuantumMemory(number_arguments,
1423 sizeof(*arguments));
1424 if (arguments == (double *) NULL)
1425 ThrowWandFatalException(ResourceLimitFatalError,
1426 "MemoryAllocationFailed",(*image)->filename);
1427 (void) ResetMagickMemory(arguments,0,number_arguments*
1428 sizeof(*arguments));
1429 p=(char *) args;
cristybb503372010-05-27 20:51:26 +00001430 for (x=0; (x < (ssize_t) number_arguments) && (*p != '\0'); x++)
cristy3ed852e2009-09-05 21:47:34 +00001431 {
1432 GetMagickToken(p,&p,token);
1433 if (*token == ',')
1434 GetMagickToken(p,&p,token);
cristyf2f27272009-12-17 14:48:46 +00001435 arguments[x]=StringToDouble(token);
cristy3ed852e2009-09-05 21:47:34 +00001436 }
1437 args=DestroyString(args);
1438 distort_image=DistortImage(*image,method,number_arguments,arguments,
1439 (*option == '+') ? MagickTrue : MagickFalse,exception);
1440 arguments=(double *) RelinquishMagickMemory(arguments);
1441 if (distort_image == (Image *) NULL)
1442 break;
1443 *image=DestroyImage(*image);
1444 *image=distort_image;
1445 break;
1446 }
1447 if (LocaleCompare("dither",option+1) == 0)
1448 {
1449 if (*option == '+')
1450 {
1451 quantize_info->dither=MagickFalse;
1452 break;
1453 }
1454 quantize_info->dither=MagickTrue;
1455 quantize_info->dither_method=(DitherMethod) ParseMagickOption(
1456 MagickDitherOptions,MagickFalse,argv[i+1]);
1457 if (quantize_info->dither_method == NoDitherMethod)
1458 quantize_info->dither=MagickFalse;
1459 break;
1460 }
1461 if (LocaleCompare("draw",option+1) == 0)
1462 {
1463 /*
1464 Draw image.
1465 */
cristy6b3da3a2010-06-20 02:21:46 +00001466 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001467 (void) CloneString(&draw_info->primitive,argv[i+1]);
1468 (void) DrawImage(*image,draw_info);
1469 InheritException(exception,&(*image)->exception);
1470 break;
1471 }
1472 break;
1473 }
1474 case 'e':
1475 {
1476 if (LocaleCompare("edge",option+1) == 0)
1477 {
1478 Image
1479 *edge_image;
1480
1481 /*
1482 Enhance edges in the image.
1483 */
cristy6b3da3a2010-06-20 02:21:46 +00001484 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001485 flags=ParseGeometry(argv[i+1],&geometry_info);
1486 if ((flags & SigmaValue) == 0)
1487 geometry_info.sigma=1.0;
1488 edge_image=EdgeImage(*image,geometry_info.rho,exception);
1489 if (edge_image == (Image *) NULL)
1490 break;
1491 *image=DestroyImage(*image);
1492 *image=edge_image;
1493 break;
1494 }
1495 if (LocaleCompare("emboss",option+1) == 0)
1496 {
1497 Image
1498 *emboss_image;
1499
1500 /*
1501 Gaussian embossen image.
1502 */
cristy6b3da3a2010-06-20 02:21:46 +00001503 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001504 flags=ParseGeometry(argv[i+1],&geometry_info);
1505 if ((flags & SigmaValue) == 0)
1506 geometry_info.sigma=1.0;
1507 emboss_image=EmbossImage(*image,geometry_info.rho,
1508 geometry_info.sigma,exception);
1509 if (emboss_image == (Image *) NULL)
1510 break;
1511 *image=DestroyImage(*image);
1512 *image=emboss_image;
1513 break;
1514 }
1515 if (LocaleCompare("encipher",option+1) == 0)
1516 {
1517 StringInfo
1518 *passkey;
1519
1520 /*
1521 Encipher pixels.
1522 */
cristy6b3da3a2010-06-20 02:21:46 +00001523 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001524 passkey=FileToStringInfo(argv[i+1],~0,exception);
1525 if (passkey != (StringInfo *) NULL)
1526 {
1527 (void) PasskeyEncipherImage(*image,passkey,exception);
1528 passkey=DestroyStringInfo(passkey);
1529 }
1530 break;
1531 }
1532 if (LocaleCompare("encoding",option+1) == 0)
1533 {
1534 (void) CloneString(&draw_info->encoding,argv[i+1]);
1535 break;
1536 }
1537 if (LocaleCompare("enhance",option+1) == 0)
1538 {
1539 Image
1540 *enhance_image;
1541
1542 /*
1543 Enhance image.
1544 */
cristy6b3da3a2010-06-20 02:21:46 +00001545 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001546 enhance_image=EnhanceImage(*image,exception);
1547 if (enhance_image == (Image *) NULL)
1548 break;
1549 *image=DestroyImage(*image);
1550 *image=enhance_image;
1551 break;
1552 }
1553 if (LocaleCompare("equalize",option+1) == 0)
1554 {
1555 /*
1556 Equalize image.
1557 */
cristy6b3da3a2010-06-20 02:21:46 +00001558 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001559 (void) EqualizeImageChannel(*image,channel);
1560 InheritException(exception,&(*image)->exception);
1561 break;
1562 }
1563 if (LocaleCompare("evaluate",option+1) == 0)
1564 {
1565 double
1566 constant;
1567
1568 MagickEvaluateOperator
1569 op;
1570
cristy6b3da3a2010-06-20 02:21:46 +00001571 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001572 op=(MagickEvaluateOperator) ParseMagickOption(MagickEvaluateOptions,
1573 MagickFalse,argv[i+1]);
cristyf2f27272009-12-17 14:48:46 +00001574 constant=SiPrefixToDouble(argv[i+2],QuantumRange);
cristy3ed852e2009-09-05 21:47:34 +00001575 (void) EvaluateImageChannel(*image,channel,op,constant,exception);
1576 break;
1577 }
1578 if (LocaleCompare("extent",option+1) == 0)
1579 {
1580 Image
1581 *extent_image;
1582
1583 /*
1584 Set the image extent.
1585 */
cristy6b3da3a2010-06-20 02:21:46 +00001586 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001587 flags=ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
cristyf0bbfd92009-11-25 14:12:31 +00001588 if (geometry.width == 0)
cristy2ea9a4e2009-11-25 14:30:22 +00001589 geometry.width=(*image)->columns;
cristyf0bbfd92009-11-25 14:12:31 +00001590 if (geometry.height == 0)
cristy2ea9a4e2009-11-25 14:30:22 +00001591 geometry.height=(*image)->rows;
cristy3ed852e2009-09-05 21:47:34 +00001592 extent_image=ExtentImage(*image,&geometry,exception);
1593 if (extent_image == (Image *) NULL)
1594 break;
1595 *image=DestroyImage(*image);
1596 *image=extent_image;
1597 break;
1598 }
1599 break;
1600 }
1601 case 'f':
1602 {
1603 if (LocaleCompare("family",option+1) == 0)
1604 {
1605 if (*option == '+')
1606 {
1607 if (draw_info->family != (char *) NULL)
1608 draw_info->family=DestroyString(draw_info->family);
1609 break;
1610 }
1611 (void) CloneString(&draw_info->family,argv[i+1]);
1612 break;
1613 }
cristy0fe961c2010-01-30 03:09:54 +00001614 if (LocaleCompare("features",option+1) == 0)
1615 {
1616 if (*option == '+')
1617 {
1618 (void) DeleteImageArtifact(*image,"identify:features");
1619 break;
1620 }
1621 (void) SetImageArtifact(*image,"identify:features",argv[i+1]);
1622 break;
1623 }
cristy3ed852e2009-09-05 21:47:34 +00001624 if (LocaleCompare("fill",option+1) == 0)
1625 {
1626 ExceptionInfo
1627 *sans;
1628
1629 GetMagickPixelPacket(*image,&fill);
1630 if (*option == '+')
1631 {
1632 (void) QueryMagickColor("none",&fill,exception);
1633 (void) QueryColorDatabase("none",&draw_info->fill,exception);
1634 if (draw_info->fill_pattern != (Image *) NULL)
1635 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
1636 break;
1637 }
1638 sans=AcquireExceptionInfo();
1639 (void) QueryMagickColor(argv[i+1],&fill,sans);
1640 status=QueryColorDatabase(argv[i+1],&draw_info->fill,sans);
1641 sans=DestroyExceptionInfo(sans);
1642 if (status == MagickFalse)
cristy6b3da3a2010-06-20 02:21:46 +00001643 draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1],
cristy3ed852e2009-09-05 21:47:34 +00001644 exception);
1645 break;
1646 }
1647 if (LocaleCompare("flip",option+1) == 0)
1648 {
1649 Image
1650 *flip_image;
1651
1652 /*
1653 Flip image scanlines.
1654 */
cristy6b3da3a2010-06-20 02:21:46 +00001655 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001656 flip_image=FlipImage(*image,exception);
1657 if (flip_image == (Image *) NULL)
1658 break;
1659 *image=DestroyImage(*image);
1660 *image=flip_image;
1661 break;
1662 }
1663 if (LocaleCompare("flop",option+1) == 0)
1664 {
1665 Image
1666 *flop_image;
1667
1668 /*
1669 Flop image scanlines.
1670 */
cristy6b3da3a2010-06-20 02:21:46 +00001671 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001672 flop_image=FlopImage(*image,exception);
1673 if (flop_image == (Image *) NULL)
1674 break;
1675 *image=DestroyImage(*image);
1676 *image=flop_image;
1677 break;
1678 }
1679 if (LocaleCompare("floodfill",option+1) == 0)
1680 {
1681 MagickPixelPacket
1682 target;
1683
1684 /*
1685 Floodfill image.
1686 */
cristy6b3da3a2010-06-20 02:21:46 +00001687 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001688 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
1689 (void) QueryMagickColor(argv[i+2],&target,exception);
1690 (void) FloodfillPaintImage(*image,channel,draw_info,&target,
1691 geometry.x,geometry.y,*option == '-' ? MagickFalse : MagickTrue);
1692 InheritException(exception,&(*image)->exception);
1693 break;
1694 }
1695 if (LocaleCompare("font",option+1) == 0)
1696 {
1697 if (*option == '+')
1698 {
1699 if (draw_info->font != (char *) NULL)
1700 draw_info->font=DestroyString(draw_info->font);
1701 break;
1702 }
1703 (void) CloneString(&draw_info->font,argv[i+1]);
1704 break;
1705 }
1706 if (LocaleCompare("format",option+1) == 0)
1707 {
1708 format=argv[i+1];
1709 break;
1710 }
1711 if (LocaleCompare("frame",option+1) == 0)
1712 {
1713 FrameInfo
1714 frame_info;
1715
1716 Image
1717 *frame_image;
1718
1719 /*
1720 Surround image with an ornamental border.
1721 */
cristy6b3da3a2010-06-20 02:21:46 +00001722 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001723 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
1724 frame_info.width=geometry.width;
1725 frame_info.height=geometry.height;
1726 if ((flags & HeightValue) == 0)
1727 frame_info.height=geometry.width;
1728 frame_info.outer_bevel=geometry.x;
1729 frame_info.inner_bevel=geometry.y;
cristybb503372010-05-27 20:51:26 +00001730 frame_info.x=(ssize_t) frame_info.width;
1731 frame_info.y=(ssize_t) frame_info.height;
cristy3ed852e2009-09-05 21:47:34 +00001732 frame_info.width=(*image)->columns+2*frame_info.width;
1733 frame_info.height=(*image)->rows+2*frame_info.height;
1734 frame_image=FrameImage(*image,&frame_info,exception);
1735 if (frame_image == (Image *) NULL)
1736 break;
1737 *image=DestroyImage(*image);
1738 *image=frame_image;
1739 break;
1740 }
1741 if (LocaleCompare("function",option+1) == 0)
1742 {
1743 char
1744 *arguments,
1745 token[MaxTextExtent];
1746
1747 const char
1748 *p;
1749
1750 double
1751 *parameters;
1752
1753 MagickFunction
1754 function;
1755
cristybb503372010-05-27 20:51:26 +00001756 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001757 x;
1758
cristybb503372010-05-27 20:51:26 +00001759 size_t
cristy3ed852e2009-09-05 21:47:34 +00001760 number_parameters;
1761
1762 /*
1763 Function Modify Image Values
1764 */
cristy6b3da3a2010-06-20 02:21:46 +00001765 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001766 function=(MagickFunction) ParseMagickOption(MagickFunctionOptions,
1767 MagickFalse,argv[i+1]);
cristy6b3da3a2010-06-20 02:21:46 +00001768 arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
cristy3ed852e2009-09-05 21:47:34 +00001769 InheritException(exception,&(*image)->exception);
1770 if (arguments == (char *) NULL)
1771 break;
1772 p=(char *) arguments;
1773 for (x=0; *p != '\0'; x++)
1774 {
1775 GetMagickToken(p,&p,token);
1776 if (*token == ',')
1777 GetMagickToken(p,&p,token);
1778 }
cristybb503372010-05-27 20:51:26 +00001779 number_parameters=(size_t) x;
cristy3ed852e2009-09-05 21:47:34 +00001780 parameters=(double *) AcquireQuantumMemory(number_parameters,
1781 sizeof(*parameters));
1782 if (parameters == (double *) NULL)
1783 ThrowWandFatalException(ResourceLimitFatalError,
1784 "MemoryAllocationFailed",(*image)->filename);
1785 (void) ResetMagickMemory(parameters,0,number_parameters*
1786 sizeof(*parameters));
1787 p=(char *) arguments;
cristybb503372010-05-27 20:51:26 +00001788 for (x=0; (x < (ssize_t) number_parameters) && (*p != '\0'); x++)
cristy3ed852e2009-09-05 21:47:34 +00001789 {
1790 GetMagickToken(p,&p,token);
1791 if (*token == ',')
1792 GetMagickToken(p,&p,token);
cristyf2f27272009-12-17 14:48:46 +00001793 parameters[x]=StringToDouble(token);
cristy3ed852e2009-09-05 21:47:34 +00001794 }
1795 arguments=DestroyString(arguments);
1796 (void) FunctionImageChannel(*image,channel,function,
1797 number_parameters,parameters,exception);
1798 parameters=(double *) RelinquishMagickMemory(parameters);
1799 break;
1800 }
1801 break;
1802 }
1803 case 'g':
1804 {
1805 if (LocaleCompare("gamma",option+1) == 0)
1806 {
1807 /*
1808 Gamma image.
1809 */
cristy6b3da3a2010-06-20 02:21:46 +00001810 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001811 if (*option == '+')
cristyf2f27272009-12-17 14:48:46 +00001812 (*image)->gamma=StringToDouble(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00001813 else
1814 {
1815 if (strchr(argv[i+1],',') != (char *) NULL)
1816 (void) GammaImage(*image,argv[i+1]);
1817 else
cristya5447be2010-01-11 00:20:51 +00001818 (void) GammaImageChannel(*image,channel,
1819 StringToDouble(argv[i+1]));
cristy3ed852e2009-09-05 21:47:34 +00001820 InheritException(exception,&(*image)->exception);
1821 }
1822 break;
1823 }
1824 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
1825 (LocaleCompare("gaussian",option+1) == 0))
1826 {
1827 Image
1828 *gaussian_image;
1829
1830 /*
1831 Gaussian blur image.
1832 */
cristy6b3da3a2010-06-20 02:21:46 +00001833 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001834 flags=ParseGeometry(argv[i+1],&geometry_info);
1835 if ((flags & SigmaValue) == 0)
1836 geometry_info.sigma=1.0;
1837 gaussian_image=GaussianBlurImageChannel(*image,channel,
1838 geometry_info.rho,geometry_info.sigma,exception);
1839 if (gaussian_image == (Image *) NULL)
1840 break;
1841 *image=DestroyImage(*image);
1842 *image=gaussian_image;
1843 break;
1844 }
1845 if (LocaleCompare("geometry",option+1) == 0)
1846 {
cristy6b3da3a2010-06-20 02:21:46 +00001847 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001848 if (*option == '+')
1849 {
1850 if ((*image)->geometry != (char *) NULL)
1851 (*image)->geometry=DestroyString((*image)->geometry);
1852 break;
1853 }
1854 flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
1855 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
1856 (void) CloneString(&(*image)->geometry,argv[i+1]);
1857 else
1858 {
1859 Image
cristy15b98cd2010-09-12 19:42:50 +00001860 *resize_image;
cristy3ed852e2009-09-05 21:47:34 +00001861
1862 /*
1863 Resize image.
1864 */
cristy15b98cd2010-09-12 19:42:50 +00001865 resize_image=ResizeImage(*image,geometry.width,geometry.height,
1866 (*image)->filter,(*image)->blur,exception);
1867 if (resize_image == (Image *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001868 break;
1869 *image=DestroyImage(*image);
cristy15b98cd2010-09-12 19:42:50 +00001870 *image=resize_image;
cristy3ed852e2009-09-05 21:47:34 +00001871 }
1872 break;
1873 }
1874 if (LocaleCompare("gravity",option+1) == 0)
1875 {
1876 if (*option == '+')
1877 {
1878 draw_info->gravity=UndefinedGravity;
1879 break;
1880 }
1881 draw_info->gravity=(GravityType) ParseMagickOption(
1882 MagickGravityOptions,MagickFalse,argv[i+1]);
1883 break;
1884 }
1885 break;
1886 }
1887 case 'h':
1888 {
1889 if (LocaleCompare("highlight-color",option+1) == 0)
1890 {
1891 (void) SetImageArtifact(*image,option+1,argv[i+1]);
1892 break;
1893 }
1894 break;
1895 }
1896 case 'i':
1897 {
1898 if (LocaleCompare("identify",option+1) == 0)
1899 {
1900 char
1901 *text;
1902
cristy6b3da3a2010-06-20 02:21:46 +00001903 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001904 if (format == (char *) NULL)
1905 {
cristy6b3da3a2010-06-20 02:21:46 +00001906 (void) IdentifyImage(*image,stdout,mogrify_info->verbose);
cristy3ed852e2009-09-05 21:47:34 +00001907 InheritException(exception,&(*image)->exception);
1908 break;
1909 }
cristy6b3da3a2010-06-20 02:21:46 +00001910 text=InterpretImageProperties(mogrify_info,*image,format);
cristy3ed852e2009-09-05 21:47:34 +00001911 InheritException(exception,&(*image)->exception);
1912 if (text == (char *) NULL)
1913 break;
1914 (void) fputs(text,stdout);
1915 (void) fputc('\n',stdout);
1916 text=DestroyString(text);
1917 break;
1918 }
1919 if (LocaleCompare("implode",option+1) == 0)
1920 {
1921 Image
1922 *implode_image;
1923
1924 /*
1925 Implode image.
1926 */
cristy6b3da3a2010-06-20 02:21:46 +00001927 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001928 (void) ParseGeometry(argv[i+1],&geometry_info);
1929 implode_image=ImplodeImage(*image,geometry_info.rho,exception);
1930 if (implode_image == (Image *) NULL)
1931 break;
1932 *image=DestroyImage(*image);
1933 *image=implode_image;
1934 break;
1935 }
cristyb32b90a2009-09-07 21:45:48 +00001936 if (LocaleCompare("interline-spacing",option+1) == 0)
1937 {
1938 if (*option == '+')
1939 (void) ParseGeometry("0",&geometry_info);
1940 else
1941 (void) ParseGeometry(argv[i+1],&geometry_info);
1942 draw_info->interline_spacing=geometry_info.rho;
1943 break;
1944 }
cristy3ed852e2009-09-05 21:47:34 +00001945 if (LocaleCompare("interword-spacing",option+1) == 0)
1946 {
1947 if (*option == '+')
1948 (void) ParseGeometry("0",&geometry_info);
1949 else
1950 (void) ParseGeometry(argv[i+1],&geometry_info);
1951 draw_info->interword_spacing=geometry_info.rho;
1952 break;
1953 }
1954 break;
1955 }
1956 case 'k':
1957 {
1958 if (LocaleCompare("kerning",option+1) == 0)
1959 {
1960 if (*option == '+')
1961 (void) ParseGeometry("0",&geometry_info);
1962 else
1963 (void) ParseGeometry(argv[i+1],&geometry_info);
1964 draw_info->kerning=geometry_info.rho;
1965 break;
1966 }
1967 break;
1968 }
1969 case 'l':
1970 {
1971 if (LocaleCompare("lat",option+1) == 0)
1972 {
1973 Image
1974 *threshold_image;
1975
1976 /*
1977 Local adaptive threshold image.
1978 */
cristy6b3da3a2010-06-20 02:21:46 +00001979 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001980 flags=ParseGeometry(argv[i+1],&geometry_info);
1981 if ((flags & PercentValue) != 0)
1982 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
cristybb503372010-05-27 20:51:26 +00001983 threshold_image=AdaptiveThresholdImage(*image,(size_t)
1984 geometry_info.rho,(size_t) geometry_info.sigma,
1985 (ssize_t) geometry_info.xi,exception);
cristy3ed852e2009-09-05 21:47:34 +00001986 if (threshold_image == (Image *) NULL)
1987 break;
1988 *image=DestroyImage(*image);
1989 *image=threshold_image;
1990 break;
1991 }
1992 if (LocaleCompare("level",option+1) == 0)
1993 {
cristy3ed852e2009-09-05 21:47:34 +00001994 MagickRealType
1995 black_point,
1996 gamma,
1997 white_point;
1998
1999 MagickStatusType
2000 flags;
2001
2002 /*
2003 Parse levels.
2004 */
cristy6b3da3a2010-06-20 02:21:46 +00002005 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002006 flags=ParseGeometry(argv[i+1],&geometry_info);
2007 black_point=geometry_info.rho;
2008 white_point=(MagickRealType) QuantumRange;
2009 if ((flags & SigmaValue) != 0)
2010 white_point=geometry_info.sigma;
2011 gamma=1.0;
2012 if ((flags & XiValue) != 0)
2013 gamma=geometry_info.xi;
2014 if ((flags & PercentValue) != 0)
2015 {
2016 black_point*=(MagickRealType) (QuantumRange/100.0);
2017 white_point*=(MagickRealType) (QuantumRange/100.0);
2018 }
2019 if ((flags & SigmaValue) == 0)
2020 white_point=(MagickRealType) QuantumRange-black_point;
2021 if ((*option == '+') || ((flags & AspectValue) != 0))
2022 (void) LevelizeImageChannel(*image,channel,black_point,
2023 white_point,gamma);
2024 else
2025 (void) LevelImageChannel(*image,channel,black_point,white_point,
2026 gamma);
2027 InheritException(exception,&(*image)->exception);
2028 break;
2029 }
2030 if (LocaleCompare("level-colors",option+1) == 0)
2031 {
2032 char
2033 token[MaxTextExtent];
2034
2035 const char
2036 *p;
2037
2038 MagickPixelPacket
2039 black_point,
2040 white_point;
2041
2042 p=(const char *) argv[i+1];
2043 GetMagickToken(p,&p,token); /* get black point color */
cristyee0f8d72009-09-19 00:58:29 +00002044 if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
cristy3ed852e2009-09-05 21:47:34 +00002045 (void) QueryMagickColor(token,&black_point,exception);
2046 else
cristyee0f8d72009-09-19 00:58:29 +00002047 (void) QueryMagickColor("#000000",&black_point,exception);
cristy3ed852e2009-09-05 21:47:34 +00002048 if (isalpha((int) token[0]) || (token[0] == '#'))
2049 GetMagickToken(p,&p,token);
cristyee0f8d72009-09-19 00:58:29 +00002050 if (*token == '\0')
cristy3ed852e2009-09-05 21:47:34 +00002051 white_point=black_point; /* set everything to that color */
2052 else
2053 {
2054 /*
2055 Get white point color.
2056 */
cristyee0f8d72009-09-19 00:58:29 +00002057 if ((isalpha((int) *token) == 0) && ((*token == '#') == 0))
cristy3ed852e2009-09-05 21:47:34 +00002058 GetMagickToken(p,&p,token);
cristyee0f8d72009-09-19 00:58:29 +00002059 if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
cristy3ed852e2009-09-05 21:47:34 +00002060 (void) QueryMagickColor(token,&white_point,exception);
2061 else
cristyee0f8d72009-09-19 00:58:29 +00002062 (void) QueryMagickColor("#ffffff",&white_point,exception);
cristy3ed852e2009-09-05 21:47:34 +00002063 }
cristy74fe8f12009-10-03 19:09:01 +00002064 (void) LevelColorsImageChannel(*image,channel,&black_point,
2065 &white_point,*option == '+' ? MagickTrue : MagickFalse);
cristy3ed852e2009-09-05 21:47:34 +00002066 break;
2067 }
2068 if (LocaleCompare("linear-stretch",option+1) == 0)
2069 {
2070 double
2071 black_point,
2072 white_point;
2073
cristy3ed852e2009-09-05 21:47:34 +00002074 MagickStatusType
2075 flags;
2076
cristy6b3da3a2010-06-20 02:21:46 +00002077 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002078 flags=ParseGeometry(argv[i+1],&geometry_info);
2079 black_point=geometry_info.rho;
2080 white_point=(MagickRealType) (*image)->columns*(*image)->rows;
2081 if ((flags & SigmaValue) != 0)
2082 white_point=geometry_info.sigma;
2083 if ((flags & PercentValue) != 0)
2084 {
2085 black_point*=(double) (*image)->columns*(*image)->rows/100.0;
2086 white_point*=(double) (*image)->columns*(*image)->rows/100.0;
2087 }
2088 if ((flags & SigmaValue) == 0)
2089 white_point=(MagickRealType) (*image)->columns*(*image)->rows-
2090 black_point;
2091 (void) LinearStretchImage(*image,black_point,white_point);
2092 InheritException(exception,&(*image)->exception);
2093 break;
2094 }
2095 if (LocaleCompare("linewidth",option+1) == 0)
2096 {
cristyf2f27272009-12-17 14:48:46 +00002097 draw_info->stroke_width=StringToDouble(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00002098 break;
2099 }
2100 if (LocaleCompare("liquid-rescale",option+1) == 0)
2101 {
2102 Image
2103 *resize_image;
2104
2105 /*
2106 Liquid rescale image.
2107 */
cristy6b3da3a2010-06-20 02:21:46 +00002108 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002109 flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2110 if ((flags & XValue) == 0)
2111 geometry.x=1;
2112 if ((flags & YValue) == 0)
2113 geometry.y=0;
2114 resize_image=LiquidRescaleImage(*image,geometry.width,
2115 geometry.height,1.0*geometry.x,1.0*geometry.y,exception);
2116 if (resize_image == (Image *) NULL)
2117 break;
2118 *image=DestroyImage(*image);
2119 *image=resize_image;
2120 break;
2121 }
2122 if (LocaleCompare("lowlight-color",option+1) == 0)
2123 {
2124 (void) SetImageArtifact(*image,option+1,argv[i+1]);
2125 break;
2126 }
2127 break;
2128 }
2129 case 'm':
2130 {
2131 if (LocaleCompare("map",option+1) == 0)
2132 {
2133 Image
2134 *remap_image;
2135
2136 /*
2137 Transform image colors to match this set of colors.
2138 */
cristy6b3da3a2010-06-20 02:21:46 +00002139 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002140 if (*option == '+')
2141 break;
cristy6b3da3a2010-06-20 02:21:46 +00002142 remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
cristy3ed852e2009-09-05 21:47:34 +00002143 if (remap_image == (Image *) NULL)
2144 break;
2145 (void) RemapImage(quantize_info,*image,remap_image);
2146 InheritException(exception,&(*image)->exception);
2147 remap_image=DestroyImage(remap_image);
2148 break;
2149 }
2150 if (LocaleCompare("mask",option+1) == 0)
2151 {
2152 Image
2153 *mask;
2154
cristy6b3da3a2010-06-20 02:21:46 +00002155 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002156 if (*option == '+')
2157 {
2158 /*
2159 Remove a mask.
2160 */
2161 (void) SetImageMask(*image,(Image *) NULL);
2162 InheritException(exception,&(*image)->exception);
2163 break;
2164 }
2165 /*
2166 Set the image mask.
2167 */
cristy6b3da3a2010-06-20 02:21:46 +00002168 mask=GetImageCache(mogrify_info,argv[i+1],exception);
cristy3ed852e2009-09-05 21:47:34 +00002169 if (mask == (Image *) NULL)
2170 break;
2171 (void) SetImageMask(*image,mask);
2172 mask=DestroyImage(mask);
2173 InheritException(exception,&(*image)->exception);
2174 break;
2175 }
2176 if (LocaleCompare("matte",option+1) == 0)
2177 {
2178 (void) SetImageAlphaChannel(*image,(*option == '-') ?
2179 SetAlphaChannel : DeactivateAlphaChannel );
2180 InheritException(exception,&(*image)->exception);
2181 break;
2182 }
2183 if (LocaleCompare("median",option+1) == 0)
2184 {
2185 Image
2186 *median_image;
2187
2188 /*
2189 Median filter image.
2190 */
cristy6b3da3a2010-06-20 02:21:46 +00002191 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002192 (void) ParseGeometry(argv[i+1],&geometry_info);
2193 median_image=MedianFilterImage(*image,geometry_info.rho,exception);
2194 if (median_image == (Image *) NULL)
2195 break;
2196 *image=DestroyImage(*image);
2197 *image=median_image;
2198 break;
2199 }
2200 if (LocaleCompare("modulate",option+1) == 0)
2201 {
cristy6b3da3a2010-06-20 02:21:46 +00002202 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002203 (void) ModulateImage(*image,argv[i+1]);
2204 InheritException(exception,&(*image)->exception);
2205 break;
2206 }
2207 if (LocaleCompare("monitor",option+1) == 0)
2208 {
cristy7d34ef22010-03-25 01:11:22 +00002209 if (*option == '+')
2210 {
2211 (void) SetImageProgressMonitor(*image,
2212 (MagickProgressMonitor) NULL,(void *) NULL);
2213 break;
2214 }
cristy3ed852e2009-09-05 21:47:34 +00002215 (void) SetImageProgressMonitor(*image,MonitorProgress,
2216 (void *) NULL);
2217 break;
2218 }
2219 if (LocaleCompare("monochrome",option+1) == 0)
2220 {
cristy6b3da3a2010-06-20 02:21:46 +00002221 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002222 (void) SetImageType(*image,BilevelType);
2223 InheritException(exception,&(*image)->exception);
2224 break;
2225 }
anthony29188a82010-01-22 10:12:34 +00002226 if (LocaleCompare("morphology",option+1) == 0)
2227 {
anthony29188a82010-01-22 10:12:34 +00002228 char
2229 token[MaxTextExtent];
2230
2231 const char
2232 *p;
2233
cristye96405a2010-05-19 02:24:31 +00002234 Image
2235 *morphology_image;
2236
2237 KernelInfo
2238 *kernel;
2239
cristybb503372010-05-27 20:51:26 +00002240 ssize_t
anthony29188a82010-01-22 10:12:34 +00002241 iterations;
2242
cristye96405a2010-05-19 02:24:31 +00002243 MorphologyMethod
2244 method;
2245
anthony29188a82010-01-22 10:12:34 +00002246 /*
2247 Morphological Image Operation
2248 */
cristy6b3da3a2010-06-20 02:21:46 +00002249 (void) SyncImageSettings(mogrify_info,*image);
anthony29188a82010-01-22 10:12:34 +00002250 p=argv[i+1];
2251 GetMagickToken(p,&p,token);
2252 method=(MorphologyMethod) ParseMagickOption(MagickMorphologyOptions,
cristyd2c1e1e2010-05-08 01:05:44 +00002253 MagickFalse,token);
cristyef656912010-03-05 19:54:59 +00002254 iterations=1L;
anthony29188a82010-01-22 10:12:34 +00002255 GetMagickToken(p,&p,token);
cristyef656912010-03-05 19:54:59 +00002256 if ((*p == ':') || (*p == ','))
anthony29188a82010-01-22 10:12:34 +00002257 GetMagickToken(p,&p,token);
cristyef656912010-03-05 19:54:59 +00002258 if ((*p != '\0'))
cristy32c2aea2010-12-01 01:00:50 +00002259 iterations=(ssize_t) StringToLong(p);
anthony29188a82010-01-22 10:12:34 +00002260 kernel=AcquireKernelInfo(argv[i+2]);
2261 if (kernel == (KernelInfo *) NULL)
cristye96405a2010-05-19 02:24:31 +00002262 {
2263 (void) ThrowMagickException(exception,GetMagickModule(),
2264 OptionError,"UnabletoParseKernel","morphology");
2265 status=MagickFalse;
2266 break;
2267 }
anthony29188a82010-01-22 10:12:34 +00002268 morphology_image=MorphologyImageChannel(*image,channel,method,
cristy02d5b4f2010-02-01 01:08:27 +00002269 iterations,kernel,exception);
anthony83ba99b2010-01-24 08:48:15 +00002270 kernel=DestroyKernelInfo(kernel);
anthony29188a82010-01-22 10:12:34 +00002271 if (morphology_image == (Image *) NULL)
2272 break;
2273 *image=DestroyImage(*image);
2274 *image=morphology_image;
2275 break;
2276 }
cristy3ed852e2009-09-05 21:47:34 +00002277 if (LocaleCompare("motion-blur",option+1) == 0)
2278 {
2279 Image
2280 *blur_image;
2281
2282 /*
2283 Motion blur image.
2284 */
cristy6b3da3a2010-06-20 02:21:46 +00002285 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002286 flags=ParseGeometry(argv[i+1],&geometry_info);
2287 if ((flags & SigmaValue) == 0)
2288 geometry_info.sigma=1.0;
2289 blur_image=MotionBlurImageChannel(*image,channel,geometry_info.rho,
2290 geometry_info.sigma,geometry_info.xi,exception);
2291 if (blur_image == (Image *) NULL)
2292 break;
2293 *image=DestroyImage(*image);
2294 *image=blur_image;
2295 break;
2296 }
2297 break;
2298 }
2299 case 'n':
2300 {
2301 if (LocaleCompare("negate",option+1) == 0)
2302 {
cristy6b3da3a2010-06-20 02:21:46 +00002303 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002304 (void) NegateImageChannel(*image,channel,*option == '+' ?
2305 MagickTrue : MagickFalse);
2306 InheritException(exception,&(*image)->exception);
2307 break;
2308 }
2309 if (LocaleCompare("noise",option+1) == 0)
2310 {
2311 Image
2312 *noisy_image;
2313
cristy6b3da3a2010-06-20 02:21:46 +00002314 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002315 if (*option == '-')
2316 {
2317 (void) ParseGeometry(argv[i+1],&geometry_info);
2318 noisy_image=ReduceNoiseImage(*image,geometry_info.rho,
2319 exception);
2320 }
2321 else
2322 {
2323 NoiseType
2324 noise;
2325
2326 noise=(NoiseType) ParseMagickOption(MagickNoiseOptions,
2327 MagickFalse,argv[i+1]);
2328 noisy_image=AddNoiseImageChannel(*image,channel,noise,
2329 exception);
2330 }
2331 if (noisy_image == (Image *) NULL)
2332 break;
2333 *image=DestroyImage(*image);
2334 *image=noisy_image;
2335 break;
2336 }
2337 if (LocaleCompare("normalize",option+1) == 0)
2338 {
cristy6b3da3a2010-06-20 02:21:46 +00002339 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002340 (void) NormalizeImageChannel(*image,channel);
2341 InheritException(exception,&(*image)->exception);
2342 break;
2343 }
2344 break;
2345 }
2346 case 'o':
2347 {
2348 if (LocaleCompare("opaque",option+1) == 0)
2349 {
2350 MagickPixelPacket
2351 target;
2352
cristy6b3da3a2010-06-20 02:21:46 +00002353 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002354 (void) QueryMagickColor(argv[i+1],&target,exception);
2355 (void) OpaquePaintImageChannel(*image,channel,&target,&fill,
2356 *option == '-' ? MagickFalse : MagickTrue);
2357 break;
2358 }
2359 if (LocaleCompare("ordered-dither",option+1) == 0)
2360 {
cristy6b3da3a2010-06-20 02:21:46 +00002361 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002362 (void) OrderedPosterizeImageChannel(*image,channel,argv[i+1],
2363 exception);
2364 break;
2365 }
2366 break;
2367 }
2368 case 'p':
2369 {
2370 if (LocaleCompare("paint",option+1) == 0)
2371 {
2372 Image
2373 *paint_image;
2374
2375 /*
2376 Oil paint image.
2377 */
cristy6b3da3a2010-06-20 02:21:46 +00002378 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002379 (void) ParseGeometry(argv[i+1],&geometry_info);
2380 paint_image=OilPaintImage(*image,geometry_info.rho,exception);
2381 if (paint_image == (Image *) NULL)
2382 break;
2383 *image=DestroyImage(*image);
2384 *image=paint_image;
2385 break;
2386 }
2387 if (LocaleCompare("pen",option+1) == 0)
2388 {
2389 if (*option == '+')
2390 {
2391 (void) QueryColorDatabase("none",&draw_info->fill,exception);
2392 break;
2393 }
2394 (void) QueryColorDatabase(argv[i+1],&draw_info->fill,exception);
2395 break;
2396 }
2397 if (LocaleCompare("pointsize",option+1) == 0)
2398 {
2399 if (*option == '+')
2400 (void) ParseGeometry("12",&geometry_info);
2401 else
2402 (void) ParseGeometry(argv[i+1],&geometry_info);
2403 draw_info->pointsize=geometry_info.rho;
2404 break;
2405 }
2406 if (LocaleCompare("polaroid",option+1) == 0)
2407 {
2408 double
2409 angle;
2410
2411 Image
2412 *polaroid_image;
2413
2414 RandomInfo
2415 *random_info;
2416
2417 /*
2418 Simulate a Polaroid picture.
2419 */
cristy6b3da3a2010-06-20 02:21:46 +00002420 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002421 random_info=AcquireRandomInfo();
2422 angle=22.5*(GetPseudoRandomValue(random_info)-0.5);
2423 random_info=DestroyRandomInfo(random_info);
2424 if (*option == '-')
2425 {
2426 SetGeometryInfo(&geometry_info);
2427 flags=ParseGeometry(argv[i+1],&geometry_info);
2428 angle=geometry_info.rho;
2429 }
2430 polaroid_image=PolaroidImage(*image,draw_info,angle,exception);
2431 if (polaroid_image == (Image *) NULL)
2432 break;
2433 *image=DestroyImage(*image);
2434 *image=polaroid_image;
2435 break;
2436 }
2437 if (LocaleCompare("posterize",option+1) == 0)
2438 {
2439 /*
2440 Posterize image.
2441 */
cristy6b3da3a2010-06-20 02:21:46 +00002442 (void) SyncImageSettings(mogrify_info,*image);
cristye27293e2009-12-18 02:53:20 +00002443 (void) PosterizeImage(*image,StringToUnsignedLong(argv[i+1]),
cristy3ed852e2009-09-05 21:47:34 +00002444 quantize_info->dither);
2445 InheritException(exception,&(*image)->exception);
2446 break;
2447 }
2448 if (LocaleCompare("preview",option+1) == 0)
2449 {
2450 Image
2451 *preview_image;
2452
2453 PreviewType
2454 preview_type;
2455
2456 /*
2457 Preview image.
2458 */
cristy6b3da3a2010-06-20 02:21:46 +00002459 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002460 if (*option == '+')
2461 preview_type=UndefinedPreview;
2462 else
2463 preview_type=(PreviewType) ParseMagickOption(MagickPreviewOptions,
2464 MagickFalse,argv[i+1]);
2465 preview_image=PreviewImage(*image,preview_type,exception);
2466 if (preview_image == (Image *) NULL)
2467 break;
2468 *image=DestroyImage(*image);
2469 *image=preview_image;
2470 break;
2471 }
2472 if (LocaleCompare("profile",option+1) == 0)
2473 {
2474 const char
2475 *name;
2476
2477 const StringInfo
2478 *profile;
2479
2480 Image
2481 *profile_image;
2482
2483 ImageInfo
2484 *profile_info;
2485
cristy6b3da3a2010-06-20 02:21:46 +00002486 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002487 if (*option == '+')
2488 {
2489 /*
2490 Remove a profile from the image.
2491 */
2492 (void) ProfileImage(*image,argv[i+1],(const unsigned char *)
2493 NULL,0,MagickTrue);
2494 InheritException(exception,&(*image)->exception);
2495 break;
2496 }
2497 /*
2498 Associate a profile with the image.
2499 */
cristy6b3da3a2010-06-20 02:21:46 +00002500 profile_info=CloneImageInfo(mogrify_info);
cristy3ed852e2009-09-05 21:47:34 +00002501 profile=GetImageProfile(*image,"iptc");
2502 if (profile != (StringInfo *) NULL)
2503 profile_info->profile=(void *) CloneStringInfo(profile);
2504 profile_image=GetImageCache(profile_info,argv[i+1],exception);
2505 profile_info=DestroyImageInfo(profile_info);
2506 if (profile_image == (Image *) NULL)
2507 {
cristy3ed852e2009-09-05 21:47:34 +00002508 StringInfo
2509 *profile;
2510
cristy6b3da3a2010-06-20 02:21:46 +00002511 profile_info=CloneImageInfo(mogrify_info);
cristy071dd7b2010-04-09 13:04:54 +00002512 (void) CopyMagickString(profile_info->filename,argv[i+1],
2513 MaxTextExtent);
2514 profile=FileToStringInfo(profile_info->filename,~0UL,exception);
cristy3ed852e2009-09-05 21:47:34 +00002515 if (profile != (StringInfo *) NULL)
2516 {
cristy071dd7b2010-04-09 13:04:54 +00002517 (void) ProfileImage(*image,profile_info->magick,
cristybb503372010-05-27 20:51:26 +00002518 GetStringInfoDatum(profile),(size_t)
cristy071dd7b2010-04-09 13:04:54 +00002519 GetStringInfoLength(profile),MagickFalse);
cristy3ed852e2009-09-05 21:47:34 +00002520 profile=DestroyStringInfo(profile);
2521 }
cristy071dd7b2010-04-09 13:04:54 +00002522 profile_info=DestroyImageInfo(profile_info);
cristy3ed852e2009-09-05 21:47:34 +00002523 break;
2524 }
2525 ResetImageProfileIterator(profile_image);
2526 name=GetNextImageProfile(profile_image);
2527 while (name != (const char *) NULL)
2528 {
2529 profile=GetImageProfile(profile_image,name);
2530 if (profile != (StringInfo *) NULL)
2531 (void) ProfileImage(*image,name,GetStringInfoDatum(profile),
cristybb503372010-05-27 20:51:26 +00002532 (size_t) GetStringInfoLength(profile),MagickFalse);
cristy3ed852e2009-09-05 21:47:34 +00002533 name=GetNextImageProfile(profile_image);
2534 }
2535 profile_image=DestroyImage(profile_image);
2536 break;
2537 }
2538 break;
2539 }
2540 case 'q':
2541 {
2542 if (LocaleCompare("quantize",option+1) == 0)
2543 {
2544 if (*option == '+')
2545 {
2546 quantize_info->colorspace=UndefinedColorspace;
2547 break;
2548 }
2549 quantize_info->colorspace=(ColorspaceType) ParseMagickOption(
2550 MagickColorspaceOptions,MagickFalse,argv[i+1]);
2551 break;
2552 }
2553 break;
2554 }
2555 case 'r':
2556 {
2557 if (LocaleCompare("radial-blur",option+1) == 0)
2558 {
2559 Image
2560 *blur_image;
2561
2562 /*
2563 Radial blur image.
2564 */
cristy6b3da3a2010-06-20 02:21:46 +00002565 (void) SyncImageSettings(mogrify_info,*image);
cristya5447be2010-01-11 00:20:51 +00002566 blur_image=RadialBlurImageChannel(*image,channel,
2567 StringToDouble(argv[i+1]),exception);
cristy3ed852e2009-09-05 21:47:34 +00002568 if (blur_image == (Image *) NULL)
2569 break;
2570 *image=DestroyImage(*image);
2571 *image=blur_image;
2572 break;
2573 }
2574 if (LocaleCompare("raise",option+1) == 0)
2575 {
2576 /*
2577 Surround image with a raise of solid color.
2578 */
2579 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2580 if ((flags & SigmaValue) == 0)
2581 geometry.height=geometry.width;
2582 (void) RaiseImage(*image,&geometry,*option == '-' ? MagickTrue :
2583 MagickFalse);
2584 InheritException(exception,&(*image)->exception);
2585 break;
2586 }
2587 if (LocaleCompare("random-threshold",option+1) == 0)
2588 {
2589 /*
2590 Threshold image.
2591 */
cristy6b3da3a2010-06-20 02:21:46 +00002592 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002593 (void) RandomThresholdImageChannel(*image,channel,argv[i+1],
2594 exception);
2595 break;
2596 }
2597 if (LocaleCompare("recolor",option+1) == 0)
2598 {
cristy3ed852e2009-09-05 21:47:34 +00002599 Image
cristyf055ae42010-04-02 23:01:38 +00002600 *color_image;
cristy3ed852e2009-09-05 21:47:34 +00002601
cristyf055ae42010-04-02 23:01:38 +00002602 KernelInfo
2603 *kernel;
cristy3ed852e2009-09-05 21:47:34 +00002604
cristy6b3da3a2010-06-20 02:21:46 +00002605 (void) SyncImageSettings(mogrify_info,*image);
cristyf055ae42010-04-02 23:01:38 +00002606 kernel=AcquireKernelInfo(argv[i+1]);
2607 if (kernel == (KernelInfo *) NULL)
2608 break;
2609 color_image=ColorMatrixImage(*image,kernel,exception);
2610 kernel=DestroyKernelInfo(kernel);
2611 if (color_image == (Image *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002612 break;
2613 *image=DestroyImage(*image);
cristyf055ae42010-04-02 23:01:38 +00002614 *image=color_image;
cristy3ed852e2009-09-05 21:47:34 +00002615 break;
2616 }
2617 if (LocaleCompare("region",option+1) == 0)
2618 {
2619 Image
2620 *crop_image;
2621
cristy6b3da3a2010-06-20 02:21:46 +00002622 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002623 if (region_image != (Image *) NULL)
2624 {
2625 /*
2626 Composite region.
2627 */
2628 (void) CompositeImage(region_image,(*image)->matte !=
2629 MagickFalse ? OverCompositeOp : CopyCompositeOp,*image,
2630 region_geometry.x,region_geometry.y);
2631 InheritException(exception,&region_image->exception);
2632 *image=DestroyImage(*image);
2633 *image=region_image;
2634 }
2635 if (*option == '+')
2636 {
2637 if (region_image != (Image *) NULL)
cristyb0a6e432010-10-09 13:26:15 +00002638 region_image=(Image *) NULL;
cristy3ed852e2009-09-05 21:47:34 +00002639 break;
2640 }
2641 /*
2642 Apply transformations to a selected region of the image.
2643 */
2644 (void) ParseGravityGeometry(*image,argv[i+1],&region_geometry,
2645 exception);
2646 crop_image=CropImage(*image,&region_geometry,exception);
2647 if (crop_image == (Image *) NULL)
2648 break;
2649 region_image=(*image);
2650 *image=crop_image;
2651 break;
2652 }
2653 if (LocaleCompare("render",option+1) == 0)
2654 {
cristy6b3da3a2010-06-20 02:21:46 +00002655 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002656 draw_info->render=(*option == '+') ? MagickTrue : MagickFalse;
2657 break;
2658 }
2659 if (LocaleCompare("remap",option+1) == 0)
2660 {
2661 Image
2662 *remap_image;
2663
2664 /*
2665 Transform image colors to match this set of colors.
2666 */
cristy6b3da3a2010-06-20 02:21:46 +00002667 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002668 if (*option == '+')
2669 break;
cristy6b3da3a2010-06-20 02:21:46 +00002670 remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
cristy3ed852e2009-09-05 21:47:34 +00002671 if (remap_image == (Image *) NULL)
2672 break;
2673 (void) RemapImage(quantize_info,*image,remap_image);
2674 InheritException(exception,&(*image)->exception);
2675 remap_image=DestroyImage(remap_image);
2676 break;
2677 }
2678 if (LocaleCompare("repage",option+1) == 0)
2679 {
2680 if (*option == '+')
2681 {
2682 (void) ParseAbsoluteGeometry("0x0+0+0",&(*image)->page);
2683 break;
2684 }
2685 (void) ResetImagePage(*image,argv[i+1]);
2686 InheritException(exception,&(*image)->exception);
2687 break;
2688 }
2689 if (LocaleCompare("resample",option+1) == 0)
2690 {
2691 Image
2692 *resample_image;
2693
2694 /*
2695 Resample image.
2696 */
cristy6b3da3a2010-06-20 02:21:46 +00002697 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002698 flags=ParseGeometry(argv[i+1],&geometry_info);
2699 if ((flags & SigmaValue) == 0)
2700 geometry_info.sigma=geometry_info.rho;
2701 resample_image=ResampleImage(*image,geometry_info.rho,
2702 geometry_info.sigma,(*image)->filter,(*image)->blur,exception);
2703 if (resample_image == (Image *) NULL)
2704 break;
2705 *image=DestroyImage(*image);
2706 *image=resample_image;
2707 break;
2708 }
2709 if (LocaleCompare("resize",option+1) == 0)
2710 {
2711 Image
2712 *resize_image;
2713
2714 /*
2715 Resize image.
2716 */
cristy6b3da3a2010-06-20 02:21:46 +00002717 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002718 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2719 resize_image=ResizeImage(*image,geometry.width,geometry.height,
2720 (*image)->filter,(*image)->blur,exception);
2721 if (resize_image == (Image *) NULL)
2722 break;
2723 *image=DestroyImage(*image);
2724 *image=resize_image;
2725 break;
2726 }
2727 if (LocaleNCompare("respect-parentheses",option+1,17) == 0)
2728 {
2729 respect_parenthesis=(*option == '-') ? MagickTrue : MagickFalse;
2730 break;
2731 }
2732 if (LocaleCompare("roll",option+1) == 0)
2733 {
2734 Image
2735 *roll_image;
2736
2737 /*
2738 Roll image.
2739 */
cristy6b3da3a2010-06-20 02:21:46 +00002740 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002741 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2742 roll_image=RollImage(*image,geometry.x,geometry.y,exception);
2743 if (roll_image == (Image *) NULL)
2744 break;
2745 *image=DestroyImage(*image);
2746 *image=roll_image;
2747 break;
2748 }
2749 if (LocaleCompare("rotate",option+1) == 0)
2750 {
2751 char
2752 *geometry;
2753
2754 Image
2755 *rotate_image;
2756
2757 /*
2758 Check for conditional image rotation.
2759 */
cristy6b3da3a2010-06-20 02:21:46 +00002760 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002761 if (strchr(argv[i+1],'>') != (char *) NULL)
2762 if ((*image)->columns <= (*image)->rows)
2763 break;
2764 if (strchr(argv[i+1],'<') != (char *) NULL)
2765 if ((*image)->columns >= (*image)->rows)
2766 break;
2767 /*
2768 Rotate image.
2769 */
2770 geometry=ConstantString(argv[i+1]);
2771 (void) SubstituteString(&geometry,">","");
2772 (void) SubstituteString(&geometry,"<","");
2773 (void) ParseGeometry(geometry,&geometry_info);
2774 geometry=DestroyString(geometry);
2775 rotate_image=RotateImage(*image,geometry_info.rho,exception);
2776 if (rotate_image == (Image *) NULL)
2777 break;
2778 *image=DestroyImage(*image);
2779 *image=rotate_image;
2780 break;
2781 }
2782 break;
2783 }
2784 case 's':
2785 {
2786 if (LocaleCompare("sample",option+1) == 0)
2787 {
2788 Image
2789 *sample_image;
2790
2791 /*
2792 Sample image with pixel replication.
2793 */
cristy6b3da3a2010-06-20 02:21:46 +00002794 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002795 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2796 sample_image=SampleImage(*image,geometry.width,geometry.height,
2797 exception);
2798 if (sample_image == (Image *) NULL)
2799 break;
2800 *image=DestroyImage(*image);
2801 *image=sample_image;
2802 break;
2803 }
2804 if (LocaleCompare("scale",option+1) == 0)
2805 {
2806 Image
2807 *scale_image;
2808
2809 /*
2810 Resize image.
2811 */
cristy6b3da3a2010-06-20 02:21:46 +00002812 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002813 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2814 scale_image=ScaleImage(*image,geometry.width,geometry.height,
2815 exception);
2816 if (scale_image == (Image *) NULL)
2817 break;
2818 *image=DestroyImage(*image);
2819 *image=scale_image;
2820 break;
2821 }
2822 if (LocaleCompare("selective-blur",option+1) == 0)
2823 {
2824 Image
2825 *blur_image;
2826
2827 /*
2828 Selectively blur pixels within a contrast threshold.
2829 */
cristy6b3da3a2010-06-20 02:21:46 +00002830 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002831 flags=ParseGeometry(argv[i+1],&geometry_info);
2832 if ((flags & PercentValue) != 0)
2833 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
2834 blur_image=SelectiveBlurImageChannel(*image,channel,
2835 geometry_info.rho,geometry_info.sigma,geometry_info.xi,exception);
2836 if (blur_image == (Image *) NULL)
2837 break;
2838 *image=DestroyImage(*image);
2839 *image=blur_image;
2840 break;
2841 }
2842 if (LocaleCompare("separate",option+1) == 0)
2843 {
2844 Image
2845 *separate_images;
2846
2847 /*
2848 Break channels into separate images.
2849 */
cristy6b3da3a2010-06-20 02:21:46 +00002850 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002851 separate_images=SeparateImages(*image,channel,exception);
2852 if (separate_images == (Image *) NULL)
2853 break;
2854 *image=DestroyImage(*image);
2855 *image=separate_images;
2856 break;
2857 }
2858 if (LocaleCompare("sepia-tone",option+1) == 0)
2859 {
2860 double
2861 threshold;
2862
2863 Image
2864 *sepia_image;
2865
2866 /*
2867 Sepia-tone image.
2868 */
cristy6b3da3a2010-06-20 02:21:46 +00002869 (void) SyncImageSettings(mogrify_info,*image);
cristyf2f27272009-12-17 14:48:46 +00002870 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
cristy3ed852e2009-09-05 21:47:34 +00002871 sepia_image=SepiaToneImage(*image,threshold,exception);
2872 if (sepia_image == (Image *) NULL)
2873 break;
2874 *image=DestroyImage(*image);
2875 *image=sepia_image;
2876 break;
2877 }
2878 if (LocaleCompare("segment",option+1) == 0)
2879 {
2880 /*
2881 Segment image.
2882 */
cristy6b3da3a2010-06-20 02:21:46 +00002883 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002884 flags=ParseGeometry(argv[i+1],&geometry_info);
2885 if ((flags & SigmaValue) == 0)
2886 geometry_info.sigma=1.0;
cristy7e6164a2010-07-22 20:43:57 +00002887 (void) SegmentImage(*image,(*image)->colorspace,
2888 mogrify_info->verbose,geometry_info.rho,geometry_info.sigma);
cristy3ed852e2009-09-05 21:47:34 +00002889 InheritException(exception,&(*image)->exception);
2890 break;
2891 }
2892 if (LocaleCompare("set",option+1) == 0)
2893 {
cristy6d9a1292010-05-31 14:17:06 +00002894 char
2895 *value;
2896
cristy3ed852e2009-09-05 21:47:34 +00002897 /*
2898 Set image option.
2899 */
cristy6d9a1292010-05-31 14:17:06 +00002900 if (*option == '+')
2901 {
2902 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2903 (void) DeleteImageRegistry(argv[i+1]+9);
2904 else
2905 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
cristy7e109582010-06-01 12:56:44 +00002906 {
cristy6b3da3a2010-06-20 02:21:46 +00002907 (void) DeleteImageOption(mogrify_info,argv[i+1]+7);
cristy7e109582010-06-01 12:56:44 +00002908 (void) DeleteImageArtifact(*image,argv[i+1]+7);
2909 }
cristy6d9a1292010-05-31 14:17:06 +00002910 else
2911 (void) DeleteImageProperty(*image,argv[i+1]);
2912 break;
2913 }
cristy6b3da3a2010-06-20 02:21:46 +00002914 value=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
cristy6d9a1292010-05-31 14:17:06 +00002915 if (value == (char *) NULL)
2916 break;
cristy3ed852e2009-09-05 21:47:34 +00002917 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
cristy6d9a1292010-05-31 14:17:06 +00002918 (void) SetImageRegistry(StringRegistryType,argv[i+1]+9,value,
2919 exception);
cristy3ed852e2009-09-05 21:47:34 +00002920 else
2921 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
cristy6d9a1292010-05-31 14:17:06 +00002922 {
cristy7f02ba12010-09-21 12:39:28 +00002923 (void) SetImageOption(image_info,argv[i+1]+7,value);
cristy6b3da3a2010-06-20 02:21:46 +00002924 (void) SetImageOption(mogrify_info,argv[i+1]+7,value);
cristy6d9a1292010-05-31 14:17:06 +00002925 (void) SetImageArtifact(*image,argv[i+1]+7,value);
2926 }
cristy3ed852e2009-09-05 21:47:34 +00002927 else
cristy6d9a1292010-05-31 14:17:06 +00002928 (void) SetImageProperty(*image,argv[i+1],value);
2929 value=DestroyString(value);
cristy3ed852e2009-09-05 21:47:34 +00002930 break;
2931 }
2932 if (LocaleCompare("shade",option+1) == 0)
2933 {
2934 Image
2935 *shade_image;
2936
2937 /*
2938 Shade image.
2939 */
cristy6b3da3a2010-06-20 02:21:46 +00002940 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002941 flags=ParseGeometry(argv[i+1],&geometry_info);
2942 if ((flags & SigmaValue) == 0)
2943 geometry_info.sigma=1.0;
2944 shade_image=ShadeImage(*image,(*option == '-') ? MagickTrue :
2945 MagickFalse,geometry_info.rho,geometry_info.sigma,exception);
2946 if (shade_image == (Image *) NULL)
2947 break;
2948 *image=DestroyImage(*image);
2949 *image=shade_image;
2950 break;
2951 }
2952 if (LocaleCompare("shadow",option+1) == 0)
2953 {
2954 Image
2955 *shadow_image;
2956
2957 /*
2958 Shadow image.
2959 */
cristy6b3da3a2010-06-20 02:21:46 +00002960 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002961 flags=ParseGeometry(argv[i+1],&geometry_info);
2962 if ((flags & SigmaValue) == 0)
2963 geometry_info.sigma=1.0;
2964 if ((flags & XiValue) == 0)
2965 geometry_info.xi=4.0;
2966 if ((flags & PsiValue) == 0)
2967 geometry_info.psi=4.0;
2968 shadow_image=ShadowImage(*image,geometry_info.rho,
cristybb503372010-05-27 20:51:26 +00002969 geometry_info.sigma,(ssize_t) ceil(geometry_info.xi-0.5),(ssize_t)
cristy0534a6b2010-03-18 01:19:38 +00002970 ceil(geometry_info.psi-0.5),exception);
cristy3ed852e2009-09-05 21:47:34 +00002971 if (shadow_image == (Image *) NULL)
2972 break;
2973 *image=DestroyImage(*image);
2974 *image=shadow_image;
2975 break;
2976 }
2977 if (LocaleCompare("sharpen",option+1) == 0)
2978 {
2979 Image
2980 *sharp_image;
2981
2982 /*
2983 Sharpen image.
2984 */
cristy6b3da3a2010-06-20 02:21:46 +00002985 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002986 flags=ParseGeometry(argv[i+1],&geometry_info);
2987 if ((flags & SigmaValue) == 0)
2988 geometry_info.sigma=1.0;
2989 sharp_image=SharpenImageChannel(*image,channel,geometry_info.rho,
2990 geometry_info.sigma,exception);
2991 if (sharp_image == (Image *) NULL)
2992 break;
2993 *image=DestroyImage(*image);
2994 *image=sharp_image;
2995 break;
2996 }
2997 if (LocaleCompare("shave",option+1) == 0)
2998 {
2999 Image
3000 *shave_image;
3001
3002 /*
3003 Shave the image edges.
3004 */
cristy6b3da3a2010-06-20 02:21:46 +00003005 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003006 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
3007 shave_image=ShaveImage(*image,&geometry,exception);
3008 if (shave_image == (Image *) NULL)
3009 break;
3010 *image=DestroyImage(*image);
3011 *image=shave_image;
3012 break;
3013 }
3014 if (LocaleCompare("shear",option+1) == 0)
3015 {
3016 Image
3017 *shear_image;
3018
3019 /*
3020 Shear image.
3021 */
cristy6b3da3a2010-06-20 02:21:46 +00003022 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003023 flags=ParseGeometry(argv[i+1],&geometry_info);
3024 if ((flags & SigmaValue) == 0)
3025 geometry_info.sigma=geometry_info.rho;
3026 shear_image=ShearImage(*image,geometry_info.rho,geometry_info.sigma,
3027 exception);
3028 if (shear_image == (Image *) NULL)
3029 break;
3030 *image=DestroyImage(*image);
3031 *image=shear_image;
3032 break;
3033 }
3034 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
3035 {
3036 /*
3037 Sigmoidal non-linearity contrast control.
3038 */
cristy6b3da3a2010-06-20 02:21:46 +00003039 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003040 flags=ParseGeometry(argv[i+1],&geometry_info);
3041 if ((flags & SigmaValue) == 0)
3042 geometry_info.sigma=(double) QuantumRange/2.0;
3043 if ((flags & PercentValue) != 0)
3044 geometry_info.sigma=(double) QuantumRange*geometry_info.sigma/
3045 100.0;
3046 (void) SigmoidalContrastImageChannel(*image,channel,
3047 (*option == '-') ? MagickTrue : MagickFalse,geometry_info.rho,
3048 geometry_info.sigma);
3049 InheritException(exception,&(*image)->exception);
3050 break;
3051 }
3052 if (LocaleCompare("sketch",option+1) == 0)
3053 {
3054 Image
3055 *sketch_image;
3056
3057 /*
3058 Sketch image.
3059 */
cristy6b3da3a2010-06-20 02:21:46 +00003060 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003061 flags=ParseGeometry(argv[i+1],&geometry_info);
3062 if ((flags & SigmaValue) == 0)
3063 geometry_info.sigma=1.0;
3064 sketch_image=SketchImage(*image,geometry_info.rho,
3065 geometry_info.sigma,geometry_info.xi,exception);
3066 if (sketch_image == (Image *) NULL)
3067 break;
3068 *image=DestroyImage(*image);
3069 *image=sketch_image;
3070 break;
3071 }
3072 if (LocaleCompare("solarize",option+1) == 0)
3073 {
3074 double
3075 threshold;
3076
cristy6b3da3a2010-06-20 02:21:46 +00003077 (void) SyncImageSettings(mogrify_info,*image);
cristyf2f27272009-12-17 14:48:46 +00003078 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
cristy3ed852e2009-09-05 21:47:34 +00003079 (void) SolarizeImage(*image,threshold);
3080 InheritException(exception,&(*image)->exception);
3081 break;
3082 }
3083 if (LocaleCompare("sparse-color",option+1) == 0)
3084 {
3085 Image
3086 *sparse_image;
3087
3088 SparseColorMethod
3089 method;
3090
3091 char
3092 *arguments;
3093
3094 /*
3095 Sparse Color Interpolated Gradient
3096 */
cristy6b3da3a2010-06-20 02:21:46 +00003097 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003098 method=(SparseColorMethod) ParseMagickOption(
3099 MagickSparseColorOptions,MagickFalse,argv[i+1]);
cristy6b3da3a2010-06-20 02:21:46 +00003100 arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
cristy3ed852e2009-09-05 21:47:34 +00003101 InheritException(exception,&(*image)->exception);
3102 if (arguments == (char *) NULL)
3103 break;
3104 sparse_image=SparseColorOption(*image,channel,method,arguments,
3105 option[0] == '+' ? MagickTrue : MagickFalse,exception);
3106 arguments=DestroyString(arguments);
3107 if (sparse_image == (Image *) NULL)
3108 break;
3109 *image=DestroyImage(*image);
3110 *image=sparse_image;
3111 break;
3112 }
3113 if (LocaleCompare("splice",option+1) == 0)
3114 {
3115 Image
3116 *splice_image;
3117
3118 /*
3119 Splice a solid color into the image.
3120 */
cristy6b3da3a2010-06-20 02:21:46 +00003121 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003122 (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
3123 splice_image=SpliceImage(*image,&geometry,exception);
3124 if (splice_image == (Image *) NULL)
3125 break;
3126 *image=DestroyImage(*image);
3127 *image=splice_image;
3128 break;
3129 }
3130 if (LocaleCompare("spread",option+1) == 0)
3131 {
3132 Image
3133 *spread_image;
3134
3135 /*
3136 Spread an image.
3137 */
cristy6b3da3a2010-06-20 02:21:46 +00003138 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003139 (void) ParseGeometry(argv[i+1],&geometry_info);
3140 spread_image=SpreadImage(*image,geometry_info.rho,exception);
3141 if (spread_image == (Image *) NULL)
3142 break;
3143 *image=DestroyImage(*image);
3144 *image=spread_image;
3145 break;
3146 }
3147 if (LocaleCompare("stretch",option+1) == 0)
3148 {
3149 if (*option == '+')
3150 {
3151 draw_info->stretch=UndefinedStretch;
3152 break;
3153 }
3154 draw_info->stretch=(StretchType) ParseMagickOption(
3155 MagickStretchOptions,MagickFalse,argv[i+1]);
3156 break;
3157 }
3158 if (LocaleCompare("strip",option+1) == 0)
3159 {
3160 /*
3161 Strip image of profiles and comments.
3162 */
cristy6b3da3a2010-06-20 02:21:46 +00003163 (void) SyncImageSettings(mogrify_info,*image);
glennrp3dae5ae2010-12-23 22:42:52 +00003164 (void) StripImage(*image);
cristy3ed852e2009-09-05 21:47:34 +00003165 InheritException(exception,&(*image)->exception);
3166 break;
3167 }
3168 if (LocaleCompare("stroke",option+1) == 0)
3169 {
3170 ExceptionInfo
3171 *sans;
3172
3173 if (*option == '+')
3174 {
3175 (void) QueryColorDatabase("none",&draw_info->stroke,exception);
3176 if (draw_info->stroke_pattern != (Image *) NULL)
3177 draw_info->stroke_pattern=DestroyImage(
3178 draw_info->stroke_pattern);
3179 break;
3180 }
3181 sans=AcquireExceptionInfo();
3182 status=QueryColorDatabase(argv[i+1],&draw_info->stroke,sans);
3183 sans=DestroyExceptionInfo(sans);
3184 if (status == MagickFalse)
cristy6b3da3a2010-06-20 02:21:46 +00003185 draw_info->stroke_pattern=GetImageCache(mogrify_info,argv[i+1],
cristy3ed852e2009-09-05 21:47:34 +00003186 exception);
3187 break;
3188 }
3189 if (LocaleCompare("strokewidth",option+1) == 0)
3190 {
cristyf2f27272009-12-17 14:48:46 +00003191 draw_info->stroke_width=StringToDouble(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00003192 break;
3193 }
3194 if (LocaleCompare("style",option+1) == 0)
3195 {
3196 if (*option == '+')
3197 {
3198 draw_info->style=UndefinedStyle;
3199 break;
3200 }
3201 draw_info->style=(StyleType) ParseMagickOption(MagickStyleOptions,
3202 MagickFalse,argv[i+1]);
3203 break;
3204 }
3205 if (LocaleCompare("swirl",option+1) == 0)
3206 {
3207 Image
3208 *swirl_image;
3209
3210 /*
3211 Swirl image.
3212 */
cristy6b3da3a2010-06-20 02:21:46 +00003213 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003214 (void) ParseGeometry(argv[i+1],&geometry_info);
3215 swirl_image=SwirlImage(*image,geometry_info.rho,exception);
3216 if (swirl_image == (Image *) NULL)
3217 break;
3218 *image=DestroyImage(*image);
3219 *image=swirl_image;
3220 break;
3221 }
3222 break;
3223 }
3224 case 't':
3225 {
3226 if (LocaleCompare("threshold",option+1) == 0)
3227 {
3228 double
3229 threshold;
3230
3231 /*
3232 Threshold image.
3233 */
cristy6b3da3a2010-06-20 02:21:46 +00003234 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003235 if (*option == '+')
3236 threshold=(double) QuantumRange/2.5;
3237 else
cristyf2f27272009-12-17 14:48:46 +00003238 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
cristy3ed852e2009-09-05 21:47:34 +00003239 (void) BilevelImageChannel(*image,channel,threshold);
3240 InheritException(exception,&(*image)->exception);
3241 break;
3242 }
3243 if (LocaleCompare("thumbnail",option+1) == 0)
3244 {
3245 Image
3246 *thumbnail_image;
3247
3248 /*
3249 Thumbnail image.
3250 */
cristy6b3da3a2010-06-20 02:21:46 +00003251 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003252 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
3253 thumbnail_image=ThumbnailImage(*image,geometry.width,
3254 geometry.height,exception);
3255 if (thumbnail_image == (Image *) NULL)
3256 break;
3257 *image=DestroyImage(*image);
3258 *image=thumbnail_image;
3259 break;
3260 }
3261 if (LocaleCompare("tile",option+1) == 0)
3262 {
3263 if (*option == '+')
3264 {
3265 if (draw_info->fill_pattern != (Image *) NULL)
3266 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
3267 break;
3268 }
cristy6b3da3a2010-06-20 02:21:46 +00003269 draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1],
cristy3ed852e2009-09-05 21:47:34 +00003270 exception);
3271 break;
3272 }
3273 if (LocaleCompare("tint",option+1) == 0)
3274 {
3275 Image
3276 *tint_image;
3277
3278 /*
3279 Tint the image.
3280 */
cristy6b3da3a2010-06-20 02:21:46 +00003281 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003282 tint_image=TintImage(*image,argv[i+1],draw_info->fill,exception);
3283 if (tint_image == (Image *) NULL)
3284 break;
3285 *image=DestroyImage(*image);
3286 *image=tint_image;
3287 break;
3288 }
3289 if (LocaleCompare("transform",option+1) == 0)
3290 {
3291 Image
3292 *transform_image;
3293
3294 /*
3295 Affine transform image.
3296 */
cristy6b3da3a2010-06-20 02:21:46 +00003297 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003298 transform_image=AffineTransformImage(*image,&draw_info->affine,
3299 exception);
3300 if (transform_image == (Image *) NULL)
3301 break;
3302 *image=DestroyImage(*image);
3303 *image=transform_image;
3304 break;
3305 }
3306 if (LocaleCompare("transparent",option+1) == 0)
3307 {
3308 MagickPixelPacket
3309 target;
3310
cristy6b3da3a2010-06-20 02:21:46 +00003311 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003312 (void) QueryMagickColor(argv[i+1],&target,exception);
3313 (void) TransparentPaintImage(*image,&target,(Quantum)
3314 TransparentOpacity,*option == '-' ? MagickFalse : MagickTrue);
3315 InheritException(exception,&(*image)->exception);
3316 break;
3317 }
3318 if (LocaleCompare("transpose",option+1) == 0)
3319 {
3320 Image
3321 *transpose_image;
3322
3323 /*
3324 Transpose image scanlines.
3325 */
cristy6b3da3a2010-06-20 02:21:46 +00003326 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003327 transpose_image=TransposeImage(*image,exception);
3328 if (transpose_image == (Image *) NULL)
3329 break;
3330 *image=DestroyImage(*image);
3331 *image=transpose_image;
3332 break;
3333 }
3334 if (LocaleCompare("transverse",option+1) == 0)
3335 {
3336 Image
3337 *transverse_image;
3338
3339 /*
3340 Transverse image scanlines.
3341 */
cristy6b3da3a2010-06-20 02:21:46 +00003342 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003343 transverse_image=TransverseImage(*image,exception);
3344 if (transverse_image == (Image *) NULL)
3345 break;
3346 *image=DestroyImage(*image);
3347 *image=transverse_image;
3348 break;
3349 }
3350 if (LocaleCompare("treedepth",option+1) == 0)
3351 {
cristye27293e2009-12-18 02:53:20 +00003352 quantize_info->tree_depth=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00003353 break;
3354 }
3355 if (LocaleCompare("trim",option+1) == 0)
3356 {
3357 Image
3358 *trim_image;
3359
3360 /*
3361 Trim image.
3362 */
cristy6b3da3a2010-06-20 02:21:46 +00003363 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003364 trim_image=TrimImage(*image,exception);
3365 if (trim_image == (Image *) NULL)
3366 break;
3367 *image=DestroyImage(*image);
3368 *image=trim_image;
3369 break;
3370 }
3371 if (LocaleCompare("type",option+1) == 0)
3372 {
3373 ImageType
3374 type;
3375
cristy6b3da3a2010-06-20 02:21:46 +00003376 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003377 if (*option == '+')
cristy5f1c1ff2010-12-23 21:38:06 +00003378 type=UndefinedType;
cristy3ed852e2009-09-05 21:47:34 +00003379 else
3380 type=(ImageType) ParseMagickOption(MagickTypeOptions,MagickFalse,
3381 argv[i+1]);
cristy5f1c1ff2010-12-23 21:38:06 +00003382 (*image)->type=UndefinedType;
cristy3ed852e2009-09-05 21:47:34 +00003383 (void) SetImageType(*image,type);
3384 InheritException(exception,&(*image)->exception);
3385 break;
3386 }
3387 break;
3388 }
3389 case 'u':
3390 {
3391 if (LocaleCompare("undercolor",option+1) == 0)
3392 {
3393 (void) QueryColorDatabase(argv[i+1],&draw_info->undercolor,
3394 exception);
3395 break;
3396 }
cristy045bd902010-01-30 18:56:24 +00003397 if (LocaleCompare("unique",option+1) == 0)
3398 {
3399 if (*option == '+')
3400 {
cristy83fae872010-04-22 15:04:16 +00003401 (void) DeleteImageArtifact(*image,"identify:unique-colors");
cristy045bd902010-01-30 18:56:24 +00003402 break;
3403 }
cristy83fae872010-04-22 15:04:16 +00003404 (void) SetImageArtifact(*image,"identify:unique-colors","true");
cristya01cbea2010-11-03 16:33:33 +00003405 (void) SetImageArtifact(*image,"verbose","true");
cristy045bd902010-01-30 18:56:24 +00003406 break;
3407 }
cristy3ed852e2009-09-05 21:47:34 +00003408 if (LocaleCompare("unique-colors",option+1) == 0)
3409 {
3410 Image
3411 *unique_image;
3412
3413 /*
3414 Unique image colors.
3415 */
cristy6b3da3a2010-06-20 02:21:46 +00003416 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003417 unique_image=UniqueImageColors(*image,exception);
3418 if (unique_image == (Image *) NULL)
3419 break;
3420 *image=DestroyImage(*image);
3421 *image=unique_image;
3422 break;
3423 }
3424 if (LocaleCompare("unsharp",option+1) == 0)
3425 {
3426 Image
3427 *unsharp_image;
3428
3429 /*
3430 Unsharp mask image.
3431 */
cristy6b3da3a2010-06-20 02:21:46 +00003432 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003433 flags=ParseGeometry(argv[i+1],&geometry_info);
3434 if ((flags & SigmaValue) == 0)
3435 geometry_info.sigma=1.0;
3436 if ((flags & XiValue) == 0)
3437 geometry_info.xi=1.0;
3438 if ((flags & PsiValue) == 0)
3439 geometry_info.psi=0.05;
3440 unsharp_image=UnsharpMaskImageChannel(*image,channel,
3441 geometry_info.rho,geometry_info.sigma,geometry_info.xi,
3442 geometry_info.psi,exception);
3443 if (unsharp_image == (Image *) NULL)
3444 break;
3445 *image=DestroyImage(*image);
3446 *image=unsharp_image;
3447 break;
3448 }
3449 break;
3450 }
3451 case 'v':
3452 {
3453 if (LocaleCompare("verbose",option+1) == 0)
3454 {
3455 (void) SetImageArtifact(*image,option+1,
3456 *option == '+' ? "false" : "true");
3457 break;
3458 }
3459 if (LocaleCompare("vignette",option+1) == 0)
3460 {
3461 Image
3462 *vignette_image;
3463
3464 /*
3465 Vignette image.
3466 */
cristy6b3da3a2010-06-20 02:21:46 +00003467 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003468 flags=ParseGeometry(argv[i+1],&geometry_info);
3469 if ((flags & SigmaValue) == 0)
3470 geometry_info.sigma=1.0;
3471 if ((flags & XiValue) == 0)
3472 geometry_info.xi=0.1*(*image)->columns;
3473 if ((flags & PsiValue) == 0)
3474 geometry_info.psi=0.1*(*image)->rows;
3475 vignette_image=VignetteImage(*image,geometry_info.rho,
cristybb503372010-05-27 20:51:26 +00003476 geometry_info.sigma,(ssize_t) ceil(geometry_info.xi-0.5),(ssize_t)
cristy0534a6b2010-03-18 01:19:38 +00003477 ceil(geometry_info.psi-0.5),exception);
cristy3ed852e2009-09-05 21:47:34 +00003478 if (vignette_image == (Image *) NULL)
3479 break;
3480 *image=DestroyImage(*image);
3481 *image=vignette_image;
3482 break;
3483 }
3484 if (LocaleCompare("virtual-pixel",option+1) == 0)
3485 {
3486 if (*option == '+')
3487 {
3488 (void) SetImageVirtualPixelMethod(*image,
3489 UndefinedVirtualPixelMethod);
3490 break;
3491 }
3492 (void) SetImageVirtualPixelMethod(*image,(VirtualPixelMethod)
3493 ParseMagickOption(MagickVirtualPixelOptions,MagickFalse,
3494 argv[i+1]));
3495 break;
3496 }
3497 break;
3498 }
3499 case 'w':
3500 {
3501 if (LocaleCompare("wave",option+1) == 0)
3502 {
3503 Image
3504 *wave_image;
3505
3506 /*
3507 Wave image.
3508 */
cristy6b3da3a2010-06-20 02:21:46 +00003509 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003510 flags=ParseGeometry(argv[i+1],&geometry_info);
3511 if ((flags & SigmaValue) == 0)
3512 geometry_info.sigma=1.0;
3513 wave_image=WaveImage(*image,geometry_info.rho,geometry_info.sigma,
3514 exception);
3515 if (wave_image == (Image *) NULL)
3516 break;
3517 *image=DestroyImage(*image);
3518 *image=wave_image;
3519 break;
3520 }
3521 if (LocaleCompare("weight",option+1) == 0)
3522 {
cristye27293e2009-12-18 02:53:20 +00003523 draw_info->weight=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00003524 if (LocaleCompare(argv[i+1],"all") == 0)
3525 draw_info->weight=0;
3526 if (LocaleCompare(argv[i+1],"bold") == 0)
3527 draw_info->weight=700;
3528 if (LocaleCompare(argv[i+1],"bolder") == 0)
3529 if (draw_info->weight <= 800)
3530 draw_info->weight+=100;
3531 if (LocaleCompare(argv[i+1],"lighter") == 0)
3532 if (draw_info->weight >= 100)
3533 draw_info->weight-=100;
3534 if (LocaleCompare(argv[i+1],"normal") == 0)
3535 draw_info->weight=400;
3536 break;
3537 }
3538 if (LocaleCompare("white-threshold",option+1) == 0)
3539 {
3540 /*
3541 White threshold image.
3542 */
cristy6b3da3a2010-06-20 02:21:46 +00003543 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003544 (void) WhiteThresholdImageChannel(*image,channel,argv[i+1],
3545 exception);
3546 InheritException(exception,&(*image)->exception);
3547 break;
3548 }
3549 break;
3550 }
3551 default:
3552 break;
3553 }
3554 i+=count;
3555 }
3556 if (region_image != (Image *) NULL)
3557 {
3558 /*
3559 Composite transformed region onto image.
3560 */
cristy6b3da3a2010-06-20 02:21:46 +00003561 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003562 (void) CompositeImage(region_image,(*image)->matte != MagickFalse ?
3563 OverCompositeOp : CopyCompositeOp,*image,region_geometry.x,
3564 region_geometry.y);
3565 InheritException(exception,&region_image->exception);
3566 *image=DestroyImage(*image);
3567 *image=region_image;
3568 }
3569 /*
3570 Free resources.
3571 */
3572 quantize_info=DestroyQuantizeInfo(quantize_info);
3573 draw_info=DestroyDrawInfo(draw_info);
cristy6b3da3a2010-06-20 02:21:46 +00003574 mogrify_info=DestroyImageInfo(mogrify_info);
3575 status=(*image)->exception.severity == UndefinedException ? MagickTrue :
3576 MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00003577 return(status);
3578}
3579
3580/*
3581%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3582% %
3583% %
3584% %
cristy5063d812010-10-19 16:28:10 +00003585+ M o g r i f y I m a g e C o m m a n d %
cristy3ed852e2009-09-05 21:47:34 +00003586% %
3587% %
3588% %
3589%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3590%
3591% MogrifyImageCommand() transforms an image or a sequence of images. These
3592% transforms include image scaling, image rotation, color reduction, and
3593% others. The transmogrified image overwrites the original image.
3594%
3595% The format of the MogrifyImageCommand method is:
3596%
3597% MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,int argc,
3598% const char **argv,char **metadata,ExceptionInfo *exception)
3599%
3600% A description of each parameter follows:
3601%
3602% o image_info: the image info.
3603%
3604% o argc: the number of elements in the argument vector.
3605%
3606% o argv: A text array containing the command line arguments.
3607%
3608% o metadata: any metadata is returned here.
3609%
3610% o exception: return any errors or warnings in this structure.
3611%
3612*/
3613
3614static MagickBooleanType MogrifyUsage(void)
3615{
3616 static const char
3617 *miscellaneous[]=
3618 {
3619 "-debug events display copious debugging information",
3620 "-help print program options",
3621 "-list type print a list of supported option arguments",
3622 "-log format format of debugging information",
3623 "-version print version information",
3624 (char *) NULL
3625 },
3626 *operators[]=
3627 {
3628 "-adaptive-blur geometry",
3629 " adaptively blur pixels; decrease effect near edges",
3630 "-adaptive-resize geometry",
3631 " adaptively resize image using 'mesh' interpolation",
3632 "-adaptive-sharpen geometry",
3633 " adaptively sharpen pixels; increase effect near edges",
3634 "-alpha option on, activate, off, deactivate, set, opaque, copy",
3635 " transparent, extract, background, or shape",
3636 "-annotate geometry text",
3637 " annotate the image with text",
3638 "-auto-gamma automagically adjust gamma level of image",
3639 "-auto-level automagically adjust color levels of image",
3640 "-auto-orient automagically orient (rotate) image",
3641 "-bench iterations measure performance",
3642 "-black-threshold value",
3643 " force all pixels below the threshold into black",
3644 "-blue-shift simulate a scene at nighttime in the moonlight",
3645 "-blur geometry reduce image noise and reduce detail levels",
3646 "-border geometry surround image with a border of color",
3647 "-bordercolor color border color",
cristya28d6b82010-01-11 20:03:47 +00003648 "-brightness-contrast geometry",
3649 " improve brightness / contrast of the image",
cristy3ed852e2009-09-05 21:47:34 +00003650 "-cdl filename color correct with a color decision list",
3651 "-charcoal radius simulate a charcoal drawing",
3652 "-chop geometry remove pixels from the image interior",
cristyecb0c6d2009-09-25 16:50:09 +00003653 "-clamp restrict pixel range from 0 to the quantum depth",
cristycee97112010-05-28 00:44:52 +00003654 "-clip clip along the first path from the 8BIM profile",
cristy3ed852e2009-09-05 21:47:34 +00003655 "-clip-mask filename associate a clip mask with the image",
cristycee97112010-05-28 00:44:52 +00003656 "-clip-path id clip along a named path from the 8BIM profile",
cristy3ed852e2009-09-05 21:47:34 +00003657 "-colorize value colorize the image with the fill color",
cristye6365592010-04-02 17:31:23 +00003658 "-color-matrix matrix apply color correction to the image",
cristy3ed852e2009-09-05 21:47:34 +00003659 "-contrast enhance or reduce the image contrast",
3660 "-contrast-stretch geometry",
3661 " improve contrast by `stretching' the intensity range",
3662 "-convolve coefficients",
3663 " apply a convolution kernel to the image",
3664 "-cycle amount cycle the image colormap",
3665 "-decipher filename convert cipher pixels to plain pixels",
3666 "-deskew threshold straighten an image",
3667 "-despeckle reduce the speckles within an image",
3668 "-distort method args",
3669 " distort images according to given method ad args",
3670 "-draw string annotate the image with a graphic primitive",
3671 "-edge radius apply a filter to detect edges in the image",
3672 "-encipher filename convert plain pixels to cipher pixels",
3673 "-emboss radius emboss an image",
3674 "-enhance apply a digital filter to enhance a noisy image",
3675 "-equalize perform histogram equalization to an image",
3676 "-evaluate operator value",
cristyd18ae7c2010-03-07 17:39:52 +00003677 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003678 "-extent geometry set the image size",
3679 "-extract geometry extract area from image",
3680 "-fft implements the discrete Fourier transform (DFT)",
3681 "-flip flip image vertically",
3682 "-floodfill geometry color",
3683 " floodfill the image with color",
3684 "-flop flop image horizontally",
3685 "-frame geometry surround image with an ornamental border",
cristyc2b730e2009-11-24 14:32:09 +00003686 "-function name parameters",
cristy3ed852e2009-09-05 21:47:34 +00003687 " apply function over image values",
3688 "-gamma value level of gamma correction",
3689 "-gaussian-blur geometry",
3690 " reduce image noise and reduce detail levels",
cristy901f09d2009-10-16 22:56:10 +00003691 "-geometry geometry preferred size or location of the image",
cristy3ed852e2009-09-05 21:47:34 +00003692 "-identify identify the format and characteristics of the image",
3693 "-ift implements the inverse discrete Fourier transform (DFT)",
3694 "-implode amount implode image pixels about the center",
3695 "-lat geometry local adaptive thresholding",
3696 "-layers method optimize, merge, or compare image layers",
3697 "-level value adjust the level of image contrast",
3698 "-level-colors color,color",
cristyee0f8d72009-09-19 00:58:29 +00003699 " level image with the given colors",
cristy3ed852e2009-09-05 21:47:34 +00003700 "-linear-stretch geometry",
3701 " improve contrast by `stretching with saturation'",
3702 "-liquid-rescale geometry",
3703 " rescale image with seam-carving",
3704 "-median radius apply a median filter to the image",
3705 "-modulate value vary the brightness, saturation, and hue",
3706 "-monochrome transform image to black and white",
cristy7c1b9fd2010-02-02 14:36:00 +00003707 "-morphology method kernel",
anthony29188a82010-01-22 10:12:34 +00003708 " apply a morphology method to the image",
cristy3ed852e2009-09-05 21:47:34 +00003709 "-motion-blur geometry",
3710 " simulate motion blur",
3711 "-negate replace every pixel with its complementary color ",
3712 "-noise radius add or reduce noise in an image",
3713 "-normalize transform image to span the full range of colors",
3714 "-opaque color change this color to the fill color",
3715 "-ordered-dither NxN",
3716 " add a noise pattern to the image with specific",
3717 " amplitudes",
3718 "-paint radius simulate an oil painting",
3719 "-polaroid angle simulate a Polaroid picture",
3720 "-posterize levels reduce the image to a limited number of color levels",
cristy3ed852e2009-09-05 21:47:34 +00003721 "-profile filename add, delete, or apply an image profile",
3722 "-quantize colorspace reduce colors in this colorspace",
3723 "-radial-blur angle radial blur the image",
3724 "-raise value lighten/darken image edges to create a 3-D effect",
3725 "-random-threshold low,high",
3726 " random threshold the image",
cristy3ed852e2009-09-05 21:47:34 +00003727 "-region geometry apply options to a portion of the image",
3728 "-render render vector graphics",
3729 "-repage geometry size and location of an image canvas",
3730 "-resample geometry change the resolution of an image",
3731 "-resize geometry resize the image",
3732 "-roll geometry roll an image vertically or horizontally",
3733 "-rotate degrees apply Paeth rotation to the image",
3734 "-sample geometry scale image with pixel sampling",
3735 "-scale geometry scale the image",
3736 "-segment values segment an image",
3737 "-selective-blur geometry",
3738 " selectively blur pixels within a contrast threshold",
3739 "-sepia-tone threshold",
3740 " simulate a sepia-toned photo",
3741 "-set property value set an image property",
3742 "-shade degrees shade the image using a distant light source",
3743 "-shadow geometry simulate an image shadow",
3744 "-sharpen geometry sharpen the image",
3745 "-shave geometry shave pixels from the image edges",
cristycee97112010-05-28 00:44:52 +00003746 "-shear geometry slide one edge of the image along the X or Y axis",
cristy3ed852e2009-09-05 21:47:34 +00003747 "-sigmoidal-contrast geometry",
3748 " increase the contrast without saturating highlights or shadows",
3749 "-sketch geometry simulate a pencil sketch",
3750 "-solarize threshold negate all pixels above the threshold level",
3751 "-sparse-color method args",
3752 " fill in a image based on a few color points",
3753 "-splice geometry splice the background color into the image",
3754 "-spread radius displace image pixels by a random amount",
3755 "-strip strip image of all profiles and comments",
3756 "-swirl degrees swirl image pixels about the center",
3757 "-threshold value threshold the image",
3758 "-thumbnail geometry create a thumbnail of the image",
3759 "-tile filename tile image when filling a graphic primitive",
3760 "-tint value tint the image with the fill color",
3761 "-transform affine transform image",
3762 "-transparent color make this color transparent within the image",
3763 "-transpose flip image vertically and rotate 90 degrees",
3764 "-transverse flop image horizontally and rotate 270 degrees",
3765 "-trim trim image edges",
3766 "-type type image type",
3767 "-unique-colors discard all but one of any pixel color",
3768 "-unsharp geometry sharpen the image",
3769 "-vignette geometry soften the edges of the image in vignette style",
cristycee97112010-05-28 00:44:52 +00003770 "-wave geometry alter an image along a sine wave",
cristy3ed852e2009-09-05 21:47:34 +00003771 "-white-threshold value",
3772 " force all pixels above the threshold into white",
3773 (char *) NULL
3774 },
3775 *sequence_operators[]=
3776 {
cristy4285d782011-02-09 20:12:28 +00003777 "-append append an image sequence",
cristy3ed852e2009-09-05 21:47:34 +00003778 "-clut apply a color lookup table to the image",
3779 "-coalesce merge a sequence of images",
3780 "-combine combine a sequence of images",
3781 "-composite composite image",
3782 "-crop geometry cut out a rectangular region of the image",
3783 "-deconstruct break down an image sequence into constituent parts",
cristyd18ae7c2010-03-07 17:39:52 +00003784 "-evaluate-sequence operator",
3785 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003786 "-flatten flatten a sequence of images",
3787 "-fx expression apply mathematical expression to an image channel(s)",
3788 "-hald-clut apply a Hald color lookup table to the image",
3789 "-morph value morph an image sequence",
3790 "-mosaic create a mosaic from an image sequence",
cristy36b94822010-05-20 12:48:16 +00003791 "-print string interpret string and print to console",
cristy3ed852e2009-09-05 21:47:34 +00003792 "-process arguments process the image with a custom image filter",
3793 "-reverse reverse image sequence",
3794 "-separate separate an image channel into a grayscale image",
cristy4285d782011-02-09 20:12:28 +00003795 "-smush geometry smush an image sequence together",
cristy3ed852e2009-09-05 21:47:34 +00003796 "-write filename write images to this file",
3797 (char *) NULL
3798 },
3799 *settings[]=
3800 {
3801 "-adjoin join images into a single multi-image file",
3802 "-affine matrix affine transform matrix",
3803 "-alpha option activate, deactivate, reset, or set the alpha channel",
3804 "-antialias remove pixel-aliasing",
3805 "-authenticate password",
3806 " decipher image with this password",
3807 "-attenuate value lessen (or intensify) when adding noise to an image",
3808 "-background color background color",
3809 "-bias value add bias when convolving an image",
3810 "-black-point-compensation",
3811 " use black point compensation",
3812 "-blue-primary point chromaticity blue primary point",
3813 "-bordercolor color border color",
3814 "-caption string assign a caption to an image",
3815 "-channel type apply option to select image channels",
3816 "-colors value preferred number of colors in the image",
3817 "-colorspace type alternate image colorspace",
3818 "-comment string annotate image with comment",
3819 "-compose operator set image composite operator",
3820 "-compress type type of pixel compression when writing the image",
3821 "-define format:option",
3822 " define one or more image format options",
3823 "-delay value display the next image after pausing",
3824 "-density geometry horizontal and vertical density of the image",
3825 "-depth value image depth",
cristyc9b12952010-03-28 01:12:28 +00003826 "-direction type render text right-to-left or left-to-right",
cristy3ed852e2009-09-05 21:47:34 +00003827 "-display server get image or font from this X server",
3828 "-dispose method layer disposal method",
3829 "-dither method apply error diffusion to image",
3830 "-encoding type text encoding type",
3831 "-endian type endianness (MSB or LSB) of the image",
3832 "-family name render text with this font family",
3833 "-fill color color to use when filling a graphic primitive",
3834 "-filter type use this filter when resizing an image",
3835 "-font name render text with this font",
3836 "-format \"string\" output formatted image characteristics",
3837 "-fuzz distance colors within this distance are considered equal",
3838 "-gravity type horizontal and vertical text placement",
3839 "-green-primary point chromaticity green primary point",
3840 "-intent type type of rendering intent when managing the image color",
3841 "-interlace type type of image interlacing scheme",
cristyb32b90a2009-09-07 21:45:48 +00003842 "-interline-spacing value",
3843 " set the space between two text lines",
cristy3ed852e2009-09-05 21:47:34 +00003844 "-interpolate method pixel color interpolation method",
3845 "-interword-spacing value",
3846 " set the space between two words",
3847 "-kerning value set the space between two letters",
3848 "-label string assign a label to an image",
3849 "-limit type value pixel cache resource limit",
3850 "-loop iterations add Netscape loop extension to your GIF animation",
3851 "-mask filename associate a mask with the image",
3852 "-mattecolor color frame color",
3853 "-monitor monitor progress",
3854 "-orient type image orientation",
3855 "-page geometry size and location of an image canvas (setting)",
3856 "-ping efficiently determine image attributes",
3857 "-pointsize value font point size",
cristy7c1b9fd2010-02-02 14:36:00 +00003858 "-precision value maximum number of significant digits to print",
cristy3ed852e2009-09-05 21:47:34 +00003859 "-preview type image preview type",
3860 "-quality value JPEG/MIFF/PNG compression level",
3861 "-quiet suppress all warning messages",
3862 "-red-primary point chromaticity red primary point",
3863 "-regard-warnings pay attention to warning messages",
3864 "-remap filename transform image colors to match this set of colors",
3865 "-respect-parentheses settings remain in effect until parenthesis boundary",
3866 "-sampling-factor geometry",
3867 " horizontal and vertical sampling factor",
3868 "-scene value image scene number",
3869 "-seed value seed a new sequence of pseudo-random numbers",
3870 "-size geometry width and height of image",
3871 "-stretch type render text with this font stretch",
3872 "-stroke color graphic primitive stroke color",
3873 "-strokewidth value graphic primitive stroke width",
3874 "-style type render text with this font style",
cristyd9a29192010-10-16 16:49:53 +00003875 "-synchronize synchronize image to storage device",
3876 "-taint declare the image as modified",
cristy3ed852e2009-09-05 21:47:34 +00003877 "-texture filename name of texture to tile onto the image background",
3878 "-tile-offset geometry",
3879 " tile offset",
3880 "-treedepth value color tree depth",
3881 "-transparent-color color",
3882 " transparent color",
3883 "-undercolor color annotation bounding box color",
3884 "-units type the units of image resolution",
3885 "-verbose print detailed information about the image",
3886 "-view FlashPix viewing transforms",
3887 "-virtual-pixel method",
3888 " virtual pixel access method",
3889 "-weight type render text with this font weight",
3890 "-white-point point chromaticity white point",
3891 (char *) NULL
3892 },
3893 *stack_operators[]=
3894 {
3895 "-clone index clone an image",
3896 "-delete index delete the image from the image sequence",
3897 "-insert index insert last image into the image sequence",
3898 "-swap indexes swap two images in the image sequence",
3899 (char *) NULL
3900 };
3901
3902 const char
3903 **p;
3904
cristybb503372010-05-27 20:51:26 +00003905 (void) printf("Version: %s\n",GetMagickVersion((size_t *) NULL));
cristy610b2e22009-10-22 14:59:43 +00003906 (void) printf("Copyright: %s\n",GetMagickCopyright());
3907 (void) printf("Features: %s\n\n",GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00003908 (void) printf("Usage: %s [options ...] file [ [options ...] file ...]\n",
3909 GetClientName());
3910 (void) printf("\nImage Settings:\n");
3911 for (p=settings; *p != (char *) NULL; p++)
3912 (void) printf(" %s\n",*p);
3913 (void) printf("\nImage Operators:\n");
3914 for (p=operators; *p != (char *) NULL; p++)
3915 (void) printf(" %s\n",*p);
3916 (void) printf("\nImage Sequence Operators:\n");
3917 for (p=sequence_operators; *p != (char *) NULL; p++)
3918 (void) printf(" %s\n",*p);
3919 (void) printf("\nImage Stack Operators:\n");
3920 for (p=stack_operators; *p != (char *) NULL; p++)
3921 (void) printf(" %s\n",*p);
3922 (void) printf("\nMiscellaneous Options:\n");
3923 for (p=miscellaneous; *p != (char *) NULL; p++)
3924 (void) printf(" %s\n",*p);
3925 (void) printf(
3926 "\nBy default, the image format of `file' is determined by its magic\n");
3927 (void) printf(
3928 "number. To specify a particular image format, precede the filename\n");
3929 (void) printf(
3930 "with an image format name and a colon (i.e. ps:image) or specify the\n");
3931 (void) printf(
3932 "image type as the filename suffix (i.e. image.ps). Specify 'file' as\n");
3933 (void) printf("'-' for standard input or output.\n");
3934 return(MagickFalse);
3935}
3936
3937WandExport MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,
3938 int argc,char **argv,char **wand_unused(metadata),ExceptionInfo *exception)
3939{
3940#define DestroyMogrify() \
3941{ \
3942 if (format != (char *) NULL) \
3943 format=DestroyString(format); \
3944 if (path != (char *) NULL) \
3945 path=DestroyString(path); \
3946 DestroyImageStack(); \
cristybb503372010-05-27 20:51:26 +00003947 for (i=0; i < (ssize_t) argc; i++) \
cristy3ed852e2009-09-05 21:47:34 +00003948 argv[i]=DestroyString(argv[i]); \
3949 argv=(char **) RelinquishMagickMemory(argv); \
3950}
3951#define ThrowMogrifyException(asperity,tag,option) \
3952{ \
3953 (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag,"`%s'", \
3954 option); \
3955 DestroyMogrify(); \
3956 return(MagickFalse); \
3957}
3958#define ThrowMogrifyInvalidArgumentException(option,argument) \
3959{ \
3960 (void) ThrowMagickException(exception,GetMagickModule(),OptionError, \
3961 "InvalidArgument","`%s': %s",argument,option); \
3962 DestroyMogrify(); \
3963 return(MagickFalse); \
3964}
3965
3966 char
3967 *format,
3968 *option,
3969 *path;
3970
3971 Image
3972 *image;
3973
3974 ImageStack
3975 image_stack[MaxImageStackDepth+1];
3976
cristybb503372010-05-27 20:51:26 +00003977 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003978 j,
3979 k;
3980
cristybb503372010-05-27 20:51:26 +00003981 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003982 i;
3983
3984 MagickBooleanType
3985 global_colormap;
3986
3987 MagickBooleanType
3988 fire,
3989 pend;
3990
3991 MagickStatusType
3992 status;
3993
3994 /*
3995 Set defaults.
3996 */
3997 assert(image_info != (ImageInfo *) NULL);
3998 assert(image_info->signature == MagickSignature);
3999 if (image_info->debug != MagickFalse)
4000 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
4001 assert(exception != (ExceptionInfo *) NULL);
4002 if (argc == 2)
4003 {
4004 option=argv[1];
4005 if ((LocaleCompare("version",option+1) == 0) ||
4006 (LocaleCompare("-version",option+1) == 0))
4007 {
4008 (void) fprintf(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +00004009 GetMagickVersion((size_t *) NULL));
cristy610b2e22009-10-22 14:59:43 +00004010 (void) fprintf(stdout,"Copyright: %s\n",GetMagickCopyright());
4011 (void) fprintf(stdout,"Features: %s\n\n",GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00004012 return(MagickFalse);
4013 }
4014 }
4015 if (argc < 2)
cristy13e61a12010-02-04 20:19:00 +00004016 return(MogrifyUsage());
cristy3ed852e2009-09-05 21:47:34 +00004017 format=(char *) NULL;
4018 path=(char *) NULL;
4019 global_colormap=MagickFalse;
4020 k=0;
4021 j=1;
4022 NewImageStack();
4023 option=(char *) NULL;
4024 pend=MagickFalse;
4025 status=MagickTrue;
4026 /*
4027 Parse command line.
4028 */
4029 ReadCommandlLine(argc,&argv);
4030 status=ExpandFilenames(&argc,&argv);
4031 if (status == MagickFalse)
4032 ThrowMogrifyException(ResourceLimitError,"MemoryAllocationFailed",
4033 GetExceptionMessage(errno));
cristybb503372010-05-27 20:51:26 +00004034 for (i=1; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00004035 {
4036 option=argv[i];
4037 if (LocaleCompare(option,"(") == 0)
4038 {
4039 FireImageStack(MagickFalse,MagickTrue,pend);
4040 if (k == MaxImageStackDepth)
4041 ThrowMogrifyException(OptionError,"ParenthesisNestedTooDeeply",
4042 option);
4043 PushImageStack();
4044 continue;
4045 }
4046 if (LocaleCompare(option,")") == 0)
4047 {
4048 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
4049 if (k == 0)
4050 ThrowMogrifyException(OptionError,"UnableToParseExpression",option);
4051 PopImageStack();
4052 continue;
4053 }
4054 if (IsMagickOption(option) == MagickFalse)
4055 {
4056 char
4057 backup_filename[MaxTextExtent],
4058 *filename;
4059
4060 Image
4061 *images;
4062
4063 /*
4064 Option is a file name: begin by reading image from specified file.
4065 */
4066 FireImageStack(MagickFalse,MagickFalse,pend);
4067 filename=argv[i];
cristycee97112010-05-28 00:44:52 +00004068 if ((LocaleCompare(filename,"--") == 0) && (i < (ssize_t) (argc-1)))
cristy3ed852e2009-09-05 21:47:34 +00004069 filename=argv[++i];
4070 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
4071 images=ReadImages(image_info,exception);
4072 status&=(images != (Image *) NULL) &&
4073 (exception->severity < ErrorException);
4074 if (images == (Image *) NULL)
4075 continue;
cristydaa76602010-06-30 13:05:11 +00004076 if (format != (char *) NULL)
4077 (void) CopyMagickString(images->filename,images->magick_filename,
4078 MaxTextExtent);
cristy3ed852e2009-09-05 21:47:34 +00004079 if (path != (char *) NULL)
4080 {
4081 GetPathComponent(option,TailPath,filename);
4082 (void) FormatMagickString(images->filename,MaxTextExtent,"%s%c%s",
4083 path,*DirectorySeparator,filename);
4084 }
4085 if (format != (char *) NULL)
cristydaa76602010-06-30 13:05:11 +00004086 AppendImageFormat(format,images->filename);
cristy3ed852e2009-09-05 21:47:34 +00004087 AppendImageStack(images);
4088 FinalizeImageSettings(image_info,image,MagickFalse);
4089 if (global_colormap != MagickFalse)
4090 {
4091 QuantizeInfo
4092 *quantize_info;
4093
4094 quantize_info=AcquireQuantizeInfo(image_info);
4095 (void) RemapImages(quantize_info,images,(Image *) NULL);
4096 quantize_info=DestroyQuantizeInfo(quantize_info);
4097 }
4098 *backup_filename='\0';
4099 if ((LocaleCompare(image->filename,"-") != 0) &&
4100 (IsPathWritable(image->filename) != MagickFalse))
4101 {
cristybb503372010-05-27 20:51:26 +00004102 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004103 i;
4104
4105 /*
4106 Rename image file as backup.
4107 */
4108 (void) CopyMagickString(backup_filename,image->filename,
4109 MaxTextExtent);
4110 for (i=0; i < 6; i++)
4111 {
4112 (void) ConcatenateMagickString(backup_filename,"~",MaxTextExtent);
4113 if (IsPathAccessible(backup_filename) == MagickFalse)
4114 break;
4115 }
4116 if ((IsPathAccessible(backup_filename) != MagickFalse) ||
4117 (rename(image->filename,backup_filename) != 0))
4118 *backup_filename='\0';
4119 }
4120 /*
4121 Write transmogrified image to disk.
4122 */
4123 image_info->synchronize=MagickTrue;
4124 status&=WriteImages(image_info,image,image->filename,exception);
4125 if ((status == MagickFalse) && (*backup_filename != '\0'))
4126 (void) remove(backup_filename);
4127 RemoveAllImageStack();
4128 continue;
4129 }
4130 pend=image != (Image *) NULL ? MagickTrue : MagickFalse;
4131 switch (*(option+1))
4132 {
4133 case 'a':
4134 {
4135 if (LocaleCompare("adaptive-blur",option+1) == 0)
4136 {
4137 i++;
cristybb503372010-05-27 20:51:26 +00004138 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004139 ThrowMogrifyException(OptionError,"MissingArgument",option);
4140 if (IsGeometry(argv[i]) == MagickFalse)
4141 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4142 break;
4143 }
4144 if (LocaleCompare("adaptive-resize",option+1) == 0)
4145 {
4146 i++;
cristybb503372010-05-27 20:51:26 +00004147 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004148 ThrowMogrifyException(OptionError,"MissingArgument",option);
4149 if (IsGeometry(argv[i]) == MagickFalse)
4150 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4151 break;
4152 }
4153 if (LocaleCompare("adaptive-sharpen",option+1) == 0)
4154 {
4155 i++;
cristybb503372010-05-27 20:51:26 +00004156 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004157 ThrowMogrifyException(OptionError,"MissingArgument",option);
4158 if (IsGeometry(argv[i]) == MagickFalse)
4159 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4160 break;
4161 }
4162 if (LocaleCompare("affine",option+1) == 0)
4163 {
4164 if (*option == '+')
4165 break;
4166 i++;
cristybb503372010-05-27 20:51:26 +00004167 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004168 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy3ed852e2009-09-05 21:47:34 +00004169 break;
4170 }
4171 if (LocaleCompare("alpha",option+1) == 0)
4172 {
cristybb503372010-05-27 20:51:26 +00004173 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004174 type;
4175
4176 if (*option == '+')
4177 break;
4178 i++;
cristybb503372010-05-27 20:51:26 +00004179 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004180 ThrowMogrifyException(OptionError,"MissingArgument",option);
4181 type=ParseMagickOption(MagickAlphaOptions,MagickFalse,argv[i]);
4182 if (type < 0)
4183 ThrowMogrifyException(OptionError,"UnrecognizedAlphaChannelType",
4184 argv[i]);
4185 break;
4186 }
4187 if (LocaleCompare("annotate",option+1) == 0)
4188 {
4189 if (*option == '+')
4190 break;
4191 i++;
cristybb503372010-05-27 20:51:26 +00004192 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004193 ThrowMogrifyException(OptionError,"MissingArgument",option);
4194 if (IsGeometry(argv[i]) == MagickFalse)
4195 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristybb503372010-05-27 20:51:26 +00004196 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004197 ThrowMogrifyException(OptionError,"MissingArgument",option);
4198 i++;
4199 break;
4200 }
4201 if (LocaleCompare("antialias",option+1) == 0)
4202 break;
4203 if (LocaleCompare("append",option+1) == 0)
4204 break;
4205 if (LocaleCompare("attenuate",option+1) == 0)
4206 {
4207 if (*option == '+')
4208 break;
4209 i++;
cristybb503372010-05-27 20:51:26 +00004210 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004211 ThrowMogrifyException(OptionError,"MissingArgument",option);
4212 if (IsGeometry(argv[i]) == MagickFalse)
4213 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4214 break;
4215 }
4216 if (LocaleCompare("authenticate",option+1) == 0)
4217 {
4218 if (*option == '+')
4219 break;
4220 i++;
cristybb503372010-05-27 20:51:26 +00004221 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004222 ThrowMogrifyException(OptionError,"MissingArgument",option);
4223 break;
4224 }
4225 if (LocaleCompare("auto-gamma",option+1) == 0)
4226 break;
4227 if (LocaleCompare("auto-level",option+1) == 0)
4228 break;
4229 if (LocaleCompare("auto-orient",option+1) == 0)
4230 break;
4231 if (LocaleCompare("average",option+1) == 0)
4232 break;
4233 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4234 }
4235 case 'b':
4236 {
4237 if (LocaleCompare("background",option+1) == 0)
4238 {
4239 if (*option == '+')
4240 break;
4241 i++;
cristybb503372010-05-27 20:51:26 +00004242 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004243 ThrowMogrifyException(OptionError,"MissingArgument",option);
4244 break;
4245 }
4246 if (LocaleCompare("bias",option+1) == 0)
4247 {
4248 if (*option == '+')
4249 break;
4250 i++;
cristybb503372010-05-27 20:51:26 +00004251 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004252 ThrowMogrifyException(OptionError,"MissingArgument",option);
4253 if (IsGeometry(argv[i]) == MagickFalse)
4254 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4255 break;
4256 }
4257 if (LocaleCompare("black-point-compensation",option+1) == 0)
4258 break;
4259 if (LocaleCompare("black-threshold",option+1) == 0)
4260 {
4261 if (*option == '+')
4262 break;
4263 i++;
cristybb503372010-05-27 20:51:26 +00004264 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004265 ThrowMogrifyException(OptionError,"MissingArgument",option);
4266 if (IsGeometry(argv[i]) == MagickFalse)
4267 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4268 break;
4269 }
4270 if (LocaleCompare("blue-primary",option+1) == 0)
4271 {
4272 if (*option == '+')
4273 break;
4274 i++;
cristybb503372010-05-27 20:51:26 +00004275 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004276 ThrowMogrifyException(OptionError,"MissingArgument",option);
4277 if (IsGeometry(argv[i]) == MagickFalse)
4278 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4279 break;
4280 }
4281 if (LocaleCompare("blue-shift",option+1) == 0)
4282 {
4283 i++;
cristybb503372010-05-27 20:51:26 +00004284 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004285 ThrowMogrifyException(OptionError,"MissingArgument",option);
4286 if (IsGeometry(argv[i]) == MagickFalse)
4287 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4288 break;
4289 }
4290 if (LocaleCompare("blur",option+1) == 0)
4291 {
4292 i++;
cristybb503372010-05-27 20:51:26 +00004293 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004294 ThrowMogrifyException(OptionError,"MissingArgument",option);
4295 if (IsGeometry(argv[i]) == MagickFalse)
4296 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4297 break;
4298 }
4299 if (LocaleCompare("border",option+1) == 0)
4300 {
4301 if (*option == '+')
4302 break;
4303 i++;
cristybb503372010-05-27 20:51:26 +00004304 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004305 ThrowMogrifyException(OptionError,"MissingArgument",option);
4306 if (IsGeometry(argv[i]) == MagickFalse)
4307 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4308 break;
4309 }
4310 if (LocaleCompare("bordercolor",option+1) == 0)
4311 {
4312 if (*option == '+')
4313 break;
4314 i++;
cristybb503372010-05-27 20:51:26 +00004315 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004316 ThrowMogrifyException(OptionError,"MissingArgument",option);
4317 break;
4318 }
4319 if (LocaleCompare("box",option+1) == 0)
4320 {
4321 if (*option == '+')
4322 break;
4323 i++;
cristybb503372010-05-27 20:51:26 +00004324 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004325 ThrowMogrifyException(OptionError,"MissingArgument",option);
4326 break;
4327 }
cristya28d6b82010-01-11 20:03:47 +00004328 if (LocaleCompare("brightness-contrast",option+1) == 0)
4329 {
4330 i++;
cristybb503372010-05-27 20:51:26 +00004331 if (i == (ssize_t) argc)
cristya28d6b82010-01-11 20:03:47 +00004332 ThrowMogrifyException(OptionError,"MissingArgument",option);
4333 if (IsGeometry(argv[i]) == MagickFalse)
4334 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4335 break;
4336 }
cristy3ed852e2009-09-05 21:47:34 +00004337 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4338 }
4339 case 'c':
4340 {
4341 if (LocaleCompare("cache",option+1) == 0)
4342 {
4343 if (*option == '+')
4344 break;
4345 i++;
cristybb503372010-05-27 20:51:26 +00004346 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004347 ThrowMogrifyException(OptionError,"MissingArgument",option);
4348 if (IsGeometry(argv[i]) == MagickFalse)
4349 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4350 break;
4351 }
4352 if (LocaleCompare("caption",option+1) == 0)
4353 {
4354 if (*option == '+')
4355 break;
4356 i++;
cristybb503372010-05-27 20:51:26 +00004357 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004358 ThrowMogrifyException(OptionError,"MissingArgument",option);
4359 break;
4360 }
4361 if (LocaleCompare("channel",option+1) == 0)
4362 {
cristybb503372010-05-27 20:51:26 +00004363 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004364 channel;
4365
4366 if (*option == '+')
4367 break;
4368 i++;
cristybb503372010-05-27 20:51:26 +00004369 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004370 ThrowMogrifyException(OptionError,"MissingArgument",option);
4371 channel=ParseChannelOption(argv[i]);
4372 if (channel < 0)
4373 ThrowMogrifyException(OptionError,"UnrecognizedChannelType",
4374 argv[i]);
4375 break;
4376 }
4377 if (LocaleCompare("cdl",option+1) == 0)
4378 {
4379 if (*option == '+')
4380 break;
4381 i++;
cristybb503372010-05-27 20:51:26 +00004382 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004383 ThrowMogrifyException(OptionError,"MissingArgument",option);
4384 break;
4385 }
4386 if (LocaleCompare("charcoal",option+1) == 0)
4387 {
4388 if (*option == '+')
4389 break;
4390 i++;
cristybb503372010-05-27 20:51:26 +00004391 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004392 ThrowMogrifyException(OptionError,"MissingArgument",option);
4393 if (IsGeometry(argv[i]) == MagickFalse)
4394 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4395 break;
4396 }
4397 if (LocaleCompare("chop",option+1) == 0)
4398 {
4399 if (*option == '+')
4400 break;
4401 i++;
cristybb503372010-05-27 20:51:26 +00004402 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004403 ThrowMogrifyException(OptionError,"MissingArgument",option);
4404 if (IsGeometry(argv[i]) == MagickFalse)
4405 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4406 break;
4407 }
cristy1eb45dd2009-09-25 16:38:06 +00004408 if (LocaleCompare("clamp",option+1) == 0)
4409 break;
4410 if (LocaleCompare("clip",option+1) == 0)
4411 break;
cristy3ed852e2009-09-05 21:47:34 +00004412 if (LocaleCompare("clip-mask",option+1) == 0)
4413 {
4414 if (*option == '+')
4415 break;
4416 i++;
cristybb503372010-05-27 20:51:26 +00004417 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004418 ThrowMogrifyException(OptionError,"MissingArgument",option);
4419 break;
4420 }
4421 if (LocaleCompare("clut",option+1) == 0)
4422 break;
4423 if (LocaleCompare("coalesce",option+1) == 0)
4424 break;
4425 if (LocaleCompare("colorize",option+1) == 0)
4426 {
4427 if (*option == '+')
4428 break;
4429 i++;
cristybb503372010-05-27 20:51:26 +00004430 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004431 ThrowMogrifyException(OptionError,"MissingArgument",option);
4432 if (IsGeometry(argv[i]) == MagickFalse)
4433 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4434 break;
4435 }
cristye6365592010-04-02 17:31:23 +00004436 if (LocaleCompare("color-matrix",option+1) == 0)
4437 {
cristyb6bd4ad2010-08-08 01:12:27 +00004438 KernelInfo
4439 *kernel_info;
4440
cristye6365592010-04-02 17:31:23 +00004441 if (*option == '+')
4442 break;
4443 i++;
cristybb503372010-05-27 20:51:26 +00004444 if (i == (ssize_t) (argc-1))
cristye6365592010-04-02 17:31:23 +00004445 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00004446 kernel_info=AcquireKernelInfo(argv[i]);
4447 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00004448 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00004449 kernel_info=DestroyKernelInfo(kernel_info);
cristye6365592010-04-02 17:31:23 +00004450 break;
4451 }
cristy3ed852e2009-09-05 21:47:34 +00004452 if (LocaleCompare("colors",option+1) == 0)
4453 {
4454 if (*option == '+')
4455 break;
4456 i++;
cristybb503372010-05-27 20:51:26 +00004457 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004458 ThrowMogrifyException(OptionError,"MissingArgument",option);
4459 if (IsGeometry(argv[i]) == MagickFalse)
4460 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4461 break;
4462 }
4463 if (LocaleCompare("colorspace",option+1) == 0)
4464 {
cristybb503372010-05-27 20:51:26 +00004465 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004466 colorspace;
4467
4468 if (*option == '+')
4469 break;
4470 i++;
cristybb503372010-05-27 20:51:26 +00004471 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004472 ThrowMogrifyException(OptionError,"MissingArgument",option);
4473 colorspace=ParseMagickOption(MagickColorspaceOptions,MagickFalse,
4474 argv[i]);
4475 if (colorspace < 0)
4476 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
4477 argv[i]);
4478 break;
4479 }
4480 if (LocaleCompare("combine",option+1) == 0)
4481 break;
4482 if (LocaleCompare("comment",option+1) == 0)
4483 {
4484 if (*option == '+')
4485 break;
4486 i++;
cristybb503372010-05-27 20:51:26 +00004487 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004488 ThrowMogrifyException(OptionError,"MissingArgument",option);
4489 break;
4490 }
4491 if (LocaleCompare("composite",option+1) == 0)
4492 break;
4493 if (LocaleCompare("compress",option+1) == 0)
4494 {
cristybb503372010-05-27 20:51:26 +00004495 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004496 compress;
4497
4498 if (*option == '+')
4499 break;
4500 i++;
cristybb503372010-05-27 20:51:26 +00004501 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004502 ThrowMogrifyException(OptionError,"MissingArgument",option);
4503 compress=ParseMagickOption(MagickCompressOptions,MagickFalse,
4504 argv[i]);
4505 if (compress < 0)
4506 ThrowMogrifyException(OptionError,"UnrecognizedImageCompression",
4507 argv[i]);
4508 break;
4509 }
cristy22879752009-10-25 23:55:40 +00004510 if (LocaleCompare("concurrent",option+1) == 0)
4511 break;
cristy3ed852e2009-09-05 21:47:34 +00004512 if (LocaleCompare("contrast",option+1) == 0)
4513 break;
4514 if (LocaleCompare("contrast-stretch",option+1) == 0)
4515 {
4516 i++;
cristybb503372010-05-27 20:51:26 +00004517 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004518 ThrowMogrifyException(OptionError,"MissingArgument",option);
4519 if (IsGeometry(argv[i]) == MagickFalse)
4520 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4521 break;
4522 }
4523 if (LocaleCompare("convolve",option+1) == 0)
4524 {
cristyb6bd4ad2010-08-08 01:12:27 +00004525 KernelInfo
4526 *kernel_info;
4527
cristy3ed852e2009-09-05 21:47:34 +00004528 if (*option == '+')
4529 break;
4530 i++;
cristybb503372010-05-27 20:51:26 +00004531 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004532 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00004533 kernel_info=AcquireKernelInfo(argv[i]);
4534 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00004535 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00004536 kernel_info=DestroyKernelInfo(kernel_info);
cristy3ed852e2009-09-05 21:47:34 +00004537 break;
4538 }
4539 if (LocaleCompare("crop",option+1) == 0)
4540 {
4541 if (*option == '+')
4542 break;
4543 i++;
cristybb503372010-05-27 20:51:26 +00004544 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004545 ThrowMogrifyException(OptionError,"MissingArgument",option);
4546 if (IsGeometry(argv[i]) == MagickFalse)
4547 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4548 break;
4549 }
4550 if (LocaleCompare("cycle",option+1) == 0)
4551 {
4552 if (*option == '+')
4553 break;
4554 i++;
cristybb503372010-05-27 20:51:26 +00004555 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004556 ThrowMogrifyException(OptionError,"MissingArgument",option);
4557 if (IsGeometry(argv[i]) == MagickFalse)
4558 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4559 break;
4560 }
4561 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4562 }
4563 case 'd':
4564 {
4565 if (LocaleCompare("decipher",option+1) == 0)
4566 {
4567 if (*option == '+')
4568 break;
4569 i++;
cristybb503372010-05-27 20:51:26 +00004570 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004571 ThrowMogrifyException(OptionError,"MissingArgument",option);
4572 break;
4573 }
4574 if (LocaleCompare("deconstruct",option+1) == 0)
4575 break;
4576 if (LocaleCompare("debug",option+1) == 0)
4577 {
cristybb503372010-05-27 20:51:26 +00004578 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004579 event;
4580
4581 if (*option == '+')
4582 break;
4583 i++;
cristybb503372010-05-27 20:51:26 +00004584 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004585 ThrowMogrifyException(OptionError,"MissingArgument",option);
4586 event=ParseMagickOption(MagickLogEventOptions,MagickFalse,argv[i]);
4587 if (event < 0)
4588 ThrowMogrifyException(OptionError,"UnrecognizedEventType",
4589 argv[i]);
4590 (void) SetLogEventMask(argv[i]);
4591 break;
4592 }
4593 if (LocaleCompare("define",option+1) == 0)
4594 {
4595 i++;
cristybb503372010-05-27 20:51:26 +00004596 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004597 ThrowMogrifyException(OptionError,"MissingArgument",option);
4598 if (*option == '+')
4599 {
4600 const char
4601 *define;
4602
4603 define=GetImageOption(image_info,argv[i]);
4604 if (define == (const char *) NULL)
4605 ThrowMogrifyException(OptionError,"NoSuchOption",argv[i]);
4606 break;
4607 }
4608 break;
4609 }
4610 if (LocaleCompare("delay",option+1) == 0)
4611 {
4612 if (*option == '+')
4613 break;
4614 i++;
cristybb503372010-05-27 20:51:26 +00004615 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004616 ThrowMogrifyException(OptionError,"MissingArgument",option);
4617 if (IsGeometry(argv[i]) == MagickFalse)
4618 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4619 break;
4620 }
4621 if (LocaleCompare("density",option+1) == 0)
4622 {
4623 if (*option == '+')
4624 break;
4625 i++;
cristybb503372010-05-27 20:51:26 +00004626 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004627 ThrowMogrifyException(OptionError,"MissingArgument",option);
4628 if (IsGeometry(argv[i]) == MagickFalse)
4629 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4630 break;
4631 }
4632 if (LocaleCompare("depth",option+1) == 0)
4633 {
4634 if (*option == '+')
4635 break;
4636 i++;
cristybb503372010-05-27 20:51:26 +00004637 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004638 ThrowMogrifyException(OptionError,"MissingArgument",option);
4639 if (IsGeometry(argv[i]) == MagickFalse)
4640 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4641 break;
4642 }
4643 if (LocaleCompare("deskew",option+1) == 0)
4644 {
4645 if (*option == '+')
4646 break;
4647 i++;
cristybb503372010-05-27 20:51:26 +00004648 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004649 ThrowMogrifyException(OptionError,"MissingArgument",option);
4650 if (IsGeometry(argv[i]) == MagickFalse)
4651 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4652 break;
4653 }
4654 if (LocaleCompare("despeckle",option+1) == 0)
4655 break;
4656 if (LocaleCompare("dft",option+1) == 0)
4657 break;
cristyc9b12952010-03-28 01:12:28 +00004658 if (LocaleCompare("direction",option+1) == 0)
4659 {
cristybb503372010-05-27 20:51:26 +00004660 ssize_t
cristyc9b12952010-03-28 01:12:28 +00004661 direction;
4662
4663 if (*option == '+')
4664 break;
4665 i++;
cristybb503372010-05-27 20:51:26 +00004666 if (i == (ssize_t) argc)
cristyc9b12952010-03-28 01:12:28 +00004667 ThrowMogrifyException(OptionError,"MissingArgument",option);
4668 direction=ParseMagickOption(MagickDirectionOptions,MagickFalse,
4669 argv[i]);
4670 if (direction < 0)
4671 ThrowMogrifyException(OptionError,"UnrecognizedDirectionType",
4672 argv[i]);
4673 break;
4674 }
cristy3ed852e2009-09-05 21:47:34 +00004675 if (LocaleCompare("display",option+1) == 0)
4676 {
4677 if (*option == '+')
4678 break;
4679 i++;
cristybb503372010-05-27 20:51:26 +00004680 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004681 ThrowMogrifyException(OptionError,"MissingArgument",option);
4682 break;
4683 }
4684 if (LocaleCompare("dispose",option+1) == 0)
4685 {
cristybb503372010-05-27 20:51:26 +00004686 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004687 dispose;
4688
4689 if (*option == '+')
4690 break;
4691 i++;
cristybb503372010-05-27 20:51:26 +00004692 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004693 ThrowMogrifyException(OptionError,"MissingArgument",option);
4694 dispose=ParseMagickOption(MagickDisposeOptions,MagickFalse,argv[i]);
4695 if (dispose < 0)
4696 ThrowMogrifyException(OptionError,"UnrecognizedDisposeMethod",
4697 argv[i]);
4698 break;
4699 }
4700 if (LocaleCompare("distort",option+1) == 0)
4701 {
cristybb503372010-05-27 20:51:26 +00004702 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004703 op;
4704
4705 i++;
cristybb503372010-05-27 20:51:26 +00004706 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004707 ThrowMogrifyException(OptionError,"MissingArgument",option);
4708 op=ParseMagickOption(MagickDistortOptions,MagickFalse,argv[i]);
4709 if (op < 0)
4710 ThrowMogrifyException(OptionError,"UnrecognizedDistortMethod",
4711 argv[i]);
4712 i++;
cristybb503372010-05-27 20:51:26 +00004713 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004714 ThrowMogrifyException(OptionError,"MissingArgument",option);
4715 break;
4716 }
4717 if (LocaleCompare("dither",option+1) == 0)
4718 {
cristybb503372010-05-27 20:51:26 +00004719 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004720 method;
4721
4722 if (*option == '+')
4723 break;
4724 i++;
cristybb503372010-05-27 20:51:26 +00004725 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004726 ThrowMogrifyException(OptionError,"MissingArgument",option);
4727 method=ParseMagickOption(MagickDitherOptions,MagickFalse,argv[i]);
4728 if (method < 0)
4729 ThrowMogrifyException(OptionError,"UnrecognizedDitherMethod",
4730 argv[i]);
4731 break;
4732 }
4733 if (LocaleCompare("draw",option+1) == 0)
4734 {
4735 if (*option == '+')
4736 break;
4737 i++;
cristybb503372010-05-27 20:51:26 +00004738 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004739 ThrowMogrifyException(OptionError,"MissingArgument",option);
4740 break;
4741 }
cristy22879752009-10-25 23:55:40 +00004742 if (LocaleCompare("duration",option+1) == 0)
4743 {
4744 if (*option == '+')
4745 break;
4746 i++;
cristybb503372010-05-27 20:51:26 +00004747 if (i == (ssize_t) (argc-1))
cristy22879752009-10-25 23:55:40 +00004748 ThrowMogrifyException(OptionError,"MissingArgument",option);
4749 if (IsGeometry(argv[i]) == MagickFalse)
4750 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4751 break;
4752 }
cristy3ed852e2009-09-05 21:47:34 +00004753 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4754 }
4755 case 'e':
4756 {
4757 if (LocaleCompare("edge",option+1) == 0)
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 if (IsGeometry(argv[i]) == MagickFalse)
4765 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4766 break;
4767 }
4768 if (LocaleCompare("emboss",option+1) == 0)
4769 {
4770 if (*option == '+')
4771 break;
4772 i++;
cristybb503372010-05-27 20:51:26 +00004773 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004774 ThrowMogrifyException(OptionError,"MissingArgument",option);
4775 if (IsGeometry(argv[i]) == MagickFalse)
4776 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4777 break;
4778 }
4779 if (LocaleCompare("encipher",option+1) == 0)
4780 {
4781 if (*option == '+')
4782 break;
4783 i++;
cristybb503372010-05-27 20:51:26 +00004784 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004785 ThrowMogrifyException(OptionError,"MissingArgument",option);
4786 break;
4787 }
4788 if (LocaleCompare("encoding",option+1) == 0)
4789 {
4790 if (*option == '+')
4791 break;
4792 i++;
cristybb503372010-05-27 20:51:26 +00004793 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004794 ThrowMogrifyException(OptionError,"MissingArgument",option);
4795 break;
4796 }
4797 if (LocaleCompare("endian",option+1) == 0)
4798 {
cristybb503372010-05-27 20:51:26 +00004799 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004800 endian;
4801
4802 if (*option == '+')
4803 break;
4804 i++;
cristybb503372010-05-27 20:51:26 +00004805 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004806 ThrowMogrifyException(OptionError,"MissingArgument",option);
4807 endian=ParseMagickOption(MagickEndianOptions,MagickFalse,argv[i]);
4808 if (endian < 0)
4809 ThrowMogrifyException(OptionError,"UnrecognizedEndianType",
4810 argv[i]);
4811 break;
4812 }
4813 if (LocaleCompare("enhance",option+1) == 0)
4814 break;
4815 if (LocaleCompare("equalize",option+1) == 0)
4816 break;
4817 if (LocaleCompare("evaluate",option+1) == 0)
4818 {
cristybb503372010-05-27 20:51:26 +00004819 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004820 op;
4821
4822 if (*option == '+')
4823 break;
4824 i++;
cristybb503372010-05-27 20:51:26 +00004825 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004826 ThrowMogrifyException(OptionError,"MissingArgument",option);
4827 op=ParseMagickOption(MagickEvaluateOptions,MagickFalse,argv[i]);
4828 if (op < 0)
4829 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4830 argv[i]);
4831 i++;
cristybb503372010-05-27 20:51:26 +00004832 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004833 ThrowMogrifyException(OptionError,"MissingArgument",option);
4834 if (IsGeometry(argv[i]) == MagickFalse)
4835 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4836 break;
4837 }
cristyd18ae7c2010-03-07 17:39:52 +00004838 if (LocaleCompare("evaluate-sequence",option+1) == 0)
4839 {
cristybb503372010-05-27 20:51:26 +00004840 ssize_t
cristyd18ae7c2010-03-07 17:39:52 +00004841 op;
4842
4843 if (*option == '+')
4844 break;
4845 i++;
cristybb503372010-05-27 20:51:26 +00004846 if (i == (ssize_t) argc)
cristyd18ae7c2010-03-07 17:39:52 +00004847 ThrowMogrifyException(OptionError,"MissingArgument",option);
4848 op=ParseMagickOption(MagickEvaluateOptions,MagickFalse,argv[i]);
4849 if (op < 0)
4850 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4851 argv[i]);
4852 break;
4853 }
cristy3ed852e2009-09-05 21:47:34 +00004854 if (LocaleCompare("extent",option+1) == 0)
4855 {
4856 if (*option == '+')
4857 break;
4858 i++;
cristybb503372010-05-27 20:51:26 +00004859 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004860 ThrowMogrifyException(OptionError,"MissingArgument",option);
4861 if (IsGeometry(argv[i]) == MagickFalse)
4862 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4863 break;
4864 }
4865 if (LocaleCompare("extract",option+1) == 0)
4866 {
4867 if (*option == '+')
4868 break;
4869 i++;
cristybb503372010-05-27 20:51:26 +00004870 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004871 ThrowMogrifyException(OptionError,"MissingArgument",option);
4872 if (IsGeometry(argv[i]) == MagickFalse)
4873 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4874 break;
4875 }
4876 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4877 }
4878 case 'f':
4879 {
4880 if (LocaleCompare("family",option+1) == 0)
4881 {
4882 if (*option == '+')
4883 break;
4884 i++;
cristybb503372010-05-27 20:51:26 +00004885 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004886 ThrowMogrifyException(OptionError,"MissingArgument",option);
4887 break;
4888 }
4889 if (LocaleCompare("fill",option+1) == 0)
4890 {
4891 if (*option == '+')
4892 break;
4893 i++;
cristybb503372010-05-27 20:51:26 +00004894 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004895 ThrowMogrifyException(OptionError,"MissingArgument",option);
4896 break;
4897 }
4898 if (LocaleCompare("filter",option+1) == 0)
4899 {
cristybb503372010-05-27 20:51:26 +00004900 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004901 filter;
4902
4903 if (*option == '+')
4904 break;
4905 i++;
cristybb503372010-05-27 20:51:26 +00004906 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004907 ThrowMogrifyException(OptionError,"MissingArgument",option);
4908 filter=ParseMagickOption(MagickFilterOptions,MagickFalse,argv[i]);
4909 if (filter < 0)
4910 ThrowMogrifyException(OptionError,"UnrecognizedImageFilter",
4911 argv[i]);
4912 break;
4913 }
4914 if (LocaleCompare("flatten",option+1) == 0)
4915 break;
4916 if (LocaleCompare("flip",option+1) == 0)
4917 break;
4918 if (LocaleCompare("flop",option+1) == 0)
4919 break;
4920 if (LocaleCompare("floodfill",option+1) == 0)
4921 {
4922 if (*option == '+')
4923 break;
4924 i++;
cristybb503372010-05-27 20:51:26 +00004925 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004926 ThrowMogrifyException(OptionError,"MissingArgument",option);
4927 if (IsGeometry(argv[i]) == MagickFalse)
4928 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4929 i++;
cristybb503372010-05-27 20:51:26 +00004930 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004931 ThrowMogrifyException(OptionError,"MissingArgument",option);
4932 break;
4933 }
4934 if (LocaleCompare("font",option+1) == 0)
4935 {
4936 if (*option == '+')
4937 break;
4938 i++;
cristybb503372010-05-27 20:51:26 +00004939 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004940 ThrowMogrifyException(OptionError,"MissingArgument",option);
4941 break;
4942 }
4943 if (LocaleCompare("format",option+1) == 0)
4944 {
4945 (void) CopyMagickString(argv[i]+1,"sans",MaxTextExtent);
4946 (void) CloneString(&format,(char *) NULL);
4947 if (*option == '+')
4948 break;
4949 i++;
cristybb503372010-05-27 20:51:26 +00004950 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004951 ThrowMogrifyException(OptionError,"MissingArgument",option);
4952 (void) CloneString(&format,argv[i]);
4953 (void) CopyMagickString(image_info->filename,format,MaxTextExtent);
4954 (void) ConcatenateMagickString(image_info->filename,":",
4955 MaxTextExtent);
cristyd965a422010-03-03 17:47:35 +00004956 (void) SetImageInfo(image_info,0,exception);
cristy3ed852e2009-09-05 21:47:34 +00004957 if (*image_info->magick == '\0')
4958 ThrowMogrifyException(OptionError,"UnrecognizedImageFormat",
4959 format);
4960 break;
4961 }
4962 if (LocaleCompare("frame",option+1) == 0)
4963 {
4964 if (*option == '+')
4965 break;
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 if (IsGeometry(argv[i]) == MagickFalse)
4970 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4971 break;
4972 }
4973 if (LocaleCompare("function",option+1) == 0)
4974 {
cristybb503372010-05-27 20:51:26 +00004975 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004976 op;
4977
4978 if (*option == '+')
4979 break;
4980 i++;
cristybb503372010-05-27 20:51:26 +00004981 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004982 ThrowMogrifyException(OptionError,"MissingArgument",option);
4983 op=ParseMagickOption(MagickFunctionOptions,MagickFalse,argv[i]);
4984 if (op < 0)
4985 ThrowMogrifyException(OptionError,"UnrecognizedFunction",argv[i]);
4986 i++;
cristybb503372010-05-27 20:51:26 +00004987 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004988 ThrowMogrifyException(OptionError,"MissingArgument",option);
4989 break;
4990 }
4991 if (LocaleCompare("fuzz",option+1) == 0)
4992 {
4993 if (*option == '+')
4994 break;
4995 i++;
cristybb503372010-05-27 20:51:26 +00004996 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004997 ThrowMogrifyException(OptionError,"MissingArgument",option);
4998 if (IsGeometry(argv[i]) == MagickFalse)
4999 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5000 break;
5001 }
5002 if (LocaleCompare("fx",option+1) == 0)
5003 {
5004 if (*option == '+')
5005 break;
5006 i++;
cristybb503372010-05-27 20:51:26 +00005007 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005008 ThrowMogrifyException(OptionError,"MissingArgument",option);
5009 break;
5010 }
5011 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5012 }
5013 case 'g':
5014 {
5015 if (LocaleCompare("gamma",option+1) == 0)
5016 {
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 if (IsGeometry(argv[i]) == MagickFalse)
5021 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5022 break;
5023 }
5024 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
5025 (LocaleCompare("gaussian",option+1) == 0))
5026 {
5027 i++;
cristybb503372010-05-27 20:51:26 +00005028 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005029 ThrowMogrifyException(OptionError,"MissingArgument",option);
5030 if (IsGeometry(argv[i]) == MagickFalse)
5031 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5032 break;
5033 }
5034 if (LocaleCompare("geometry",option+1) == 0)
5035 {
5036 if (*option == '+')
5037 break;
5038 i++;
cristybb503372010-05-27 20:51:26 +00005039 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005040 ThrowMogrifyException(OptionError,"MissingArgument",option);
5041 if (IsGeometry(argv[i]) == MagickFalse)
5042 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5043 break;
5044 }
5045 if (LocaleCompare("gravity",option+1) == 0)
5046 {
cristybb503372010-05-27 20:51:26 +00005047 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005048 gravity;
5049
5050 if (*option == '+')
5051 break;
5052 i++;
cristybb503372010-05-27 20:51:26 +00005053 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005054 ThrowMogrifyException(OptionError,"MissingArgument",option);
5055 gravity=ParseMagickOption(MagickGravityOptions,MagickFalse,argv[i]);
5056 if (gravity < 0)
5057 ThrowMogrifyException(OptionError,"UnrecognizedGravityType",
5058 argv[i]);
5059 break;
5060 }
5061 if (LocaleCompare("green-primary",option+1) == 0)
5062 {
5063 if (*option == '+')
5064 break;
5065 i++;
cristybb503372010-05-27 20:51:26 +00005066 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005067 ThrowMogrifyException(OptionError,"MissingArgument",option);
5068 if (IsGeometry(argv[i]) == MagickFalse)
5069 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5070 break;
5071 }
5072 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5073 }
5074 case 'h':
5075 {
5076 if (LocaleCompare("hald-clut",option+1) == 0)
5077 break;
5078 if ((LocaleCompare("help",option+1) == 0) ||
5079 (LocaleCompare("-help",option+1) == 0))
5080 return(MogrifyUsage());
5081 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5082 }
5083 case 'i':
5084 {
5085 if (LocaleCompare("identify",option+1) == 0)
5086 break;
5087 if (LocaleCompare("idft",option+1) == 0)
5088 break;
5089 if (LocaleCompare("implode",option+1) == 0)
5090 {
5091 if (*option == '+')
5092 break;
5093 i++;
cristybb503372010-05-27 20:51:26 +00005094 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005095 ThrowMogrifyException(OptionError,"MissingArgument",option);
5096 if (IsGeometry(argv[i]) == MagickFalse)
5097 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5098 break;
5099 }
5100 if (LocaleCompare("intent",option+1) == 0)
5101 {
cristybb503372010-05-27 20:51:26 +00005102 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005103 intent;
5104
5105 if (*option == '+')
5106 break;
5107 i++;
cristybb503372010-05-27 20:51:26 +00005108 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005109 ThrowMogrifyException(OptionError,"MissingArgument",option);
5110 intent=ParseMagickOption(MagickIntentOptions,MagickFalse,argv[i]);
5111 if (intent < 0)
5112 ThrowMogrifyException(OptionError,"UnrecognizedIntentType",
5113 argv[i]);
5114 break;
5115 }
5116 if (LocaleCompare("interlace",option+1) == 0)
5117 {
cristybb503372010-05-27 20:51:26 +00005118 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005119 interlace;
5120
5121 if (*option == '+')
5122 break;
5123 i++;
cristybb503372010-05-27 20:51:26 +00005124 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005125 ThrowMogrifyException(OptionError,"MissingArgument",option);
5126 interlace=ParseMagickOption(MagickInterlaceOptions,MagickFalse,
5127 argv[i]);
5128 if (interlace < 0)
5129 ThrowMogrifyException(OptionError,"UnrecognizedInterlaceType",
5130 argv[i]);
5131 break;
5132 }
cristyb32b90a2009-09-07 21:45:48 +00005133 if (LocaleCompare("interline-spacing",option+1) == 0)
5134 {
5135 if (*option == '+')
5136 break;
5137 i++;
cristybb503372010-05-27 20:51:26 +00005138 if (i == (ssize_t) (argc-1))
cristyb32b90a2009-09-07 21:45:48 +00005139 ThrowMogrifyException(OptionError,"MissingArgument",option);
5140 if (IsGeometry(argv[i]) == MagickFalse)
5141 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5142 break;
5143 }
cristy3ed852e2009-09-05 21:47:34 +00005144 if (LocaleCompare("interpolate",option+1) == 0)
5145 {
cristybb503372010-05-27 20:51:26 +00005146 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005147 interpolate;
5148
5149 if (*option == '+')
5150 break;
5151 i++;
cristybb503372010-05-27 20:51:26 +00005152 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005153 ThrowMogrifyException(OptionError,"MissingArgument",option);
5154 interpolate=ParseMagickOption(MagickInterpolateOptions,MagickFalse,
5155 argv[i]);
5156 if (interpolate < 0)
5157 ThrowMogrifyException(OptionError,"UnrecognizedInterpolateMethod",
5158 argv[i]);
5159 break;
5160 }
5161 if (LocaleCompare("interword-spacing",option+1) == 0)
5162 {
5163 if (*option == '+')
5164 break;
5165 i++;
cristybb503372010-05-27 20:51:26 +00005166 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005167 ThrowMogrifyException(OptionError,"MissingArgument",option);
5168 if (IsGeometry(argv[i]) == MagickFalse)
5169 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5170 break;
5171 }
5172 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5173 }
5174 case 'k':
5175 {
5176 if (LocaleCompare("kerning",option+1) == 0)
5177 {
5178 if (*option == '+')
5179 break;
5180 i++;
cristybb503372010-05-27 20:51:26 +00005181 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005182 ThrowMogrifyException(OptionError,"MissingArgument",option);
5183 if (IsGeometry(argv[i]) == MagickFalse)
5184 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5185 break;
5186 }
5187 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5188 }
5189 case 'l':
5190 {
5191 if (LocaleCompare("label",option+1) == 0)
5192 {
5193 if (*option == '+')
5194 break;
5195 i++;
cristybb503372010-05-27 20:51:26 +00005196 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005197 ThrowMogrifyException(OptionError,"MissingArgument",option);
5198 break;
5199 }
5200 if (LocaleCompare("lat",option+1) == 0)
5201 {
5202 if (*option == '+')
5203 break;
5204 i++;
cristybb503372010-05-27 20:51:26 +00005205 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005206 ThrowMogrifyException(OptionError,"MissingArgument",option);
5207 if (IsGeometry(argv[i]) == MagickFalse)
5208 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5209 }
5210 if (LocaleCompare("layers",option+1) == 0)
5211 {
cristybb503372010-05-27 20:51:26 +00005212 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005213 type;
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 type=ParseMagickOption(MagickLayerOptions,MagickFalse,argv[i]);
5221 if (type < 0)
5222 ThrowMogrifyException(OptionError,"UnrecognizedLayerMethod",
5223 argv[i]);
5224 break;
5225 }
5226 if (LocaleCompare("level",option+1) == 0)
5227 {
5228 i++;
cristybb503372010-05-27 20:51:26 +00005229 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005230 ThrowMogrifyException(OptionError,"MissingArgument",option);
5231 if (IsGeometry(argv[i]) == MagickFalse)
5232 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5233 break;
5234 }
5235 if (LocaleCompare("level-colors",option+1) == 0)
5236 {
5237 i++;
cristybb503372010-05-27 20:51:26 +00005238 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005239 ThrowMogrifyException(OptionError,"MissingArgument",option);
5240 break;
5241 }
5242 if (LocaleCompare("linewidth",option+1) == 0)
5243 {
5244 if (*option == '+')
5245 break;
5246 i++;
cristybb503372010-05-27 20:51:26 +00005247 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005248 ThrowMogrifyException(OptionError,"MissingArgument",option);
5249 if (IsGeometry(argv[i]) == MagickFalse)
5250 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5251 break;
5252 }
5253 if (LocaleCompare("limit",option+1) == 0)
5254 {
5255 char
5256 *p;
5257
5258 double
5259 value;
5260
cristybb503372010-05-27 20:51:26 +00005261 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005262 resource;
5263
5264 if (*option == '+')
5265 break;
5266 i++;
cristybb503372010-05-27 20:51:26 +00005267 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005268 ThrowMogrifyException(OptionError,"MissingArgument",option);
5269 resource=ParseMagickOption(MagickResourceOptions,MagickFalse,
5270 argv[i]);
5271 if (resource < 0)
5272 ThrowMogrifyException(OptionError,"UnrecognizedResourceType",
5273 argv[i]);
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 value=strtod(argv[i],&p);
5278 if ((p == argv[i]) && (LocaleCompare("unlimited",argv[i]) != 0))
5279 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5280 break;
5281 }
5282 if (LocaleCompare("liquid-rescale",option+1) == 0)
5283 {
5284 i++;
cristybb503372010-05-27 20:51:26 +00005285 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005286 ThrowMogrifyException(OptionError,"MissingArgument",option);
5287 if (IsGeometry(argv[i]) == MagickFalse)
5288 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5289 break;
5290 }
5291 if (LocaleCompare("list",option+1) == 0)
5292 {
cristybb503372010-05-27 20:51:26 +00005293 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005294 list;
5295
5296 if (*option == '+')
5297 break;
5298 i++;
cristybb503372010-05-27 20:51:26 +00005299 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005300 ThrowMogrifyException(OptionError,"MissingArgument",option);
5301 list=ParseMagickOption(MagickListOptions,MagickFalse,argv[i]);
5302 if (list < 0)
5303 ThrowMogrifyException(OptionError,"UnrecognizedListType",argv[i]);
cristyaeb2cbc2010-05-07 13:28:58 +00005304 status=MogrifyImageInfo(image_info,(int) (i-j+1),(const char **)
cristy3ed852e2009-09-05 21:47:34 +00005305 argv+j,exception);
cristyaeb2cbc2010-05-07 13:28:58 +00005306 return(status != 0 ? MagickFalse : MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00005307 }
5308 if (LocaleCompare("log",option+1) == 0)
5309 {
5310 if (*option == '+')
5311 break;
5312 i++;
cristybb503372010-05-27 20:51:26 +00005313 if ((i == (ssize_t) argc) ||
cristy3ed852e2009-09-05 21:47:34 +00005314 (strchr(argv[i],'%') == (char *) NULL))
5315 ThrowMogrifyException(OptionError,"MissingArgument",option);
5316 break;
5317 }
5318 if (LocaleCompare("loop",option+1) == 0)
5319 {
5320 if (*option == '+')
5321 break;
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 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5330 }
5331 case 'm':
5332 {
5333 if (LocaleCompare("map",option+1) == 0)
5334 {
5335 global_colormap=(*option == '+') ? MagickTrue : MagickFalse;
5336 if (*option == '+')
5337 break;
5338 i++;
cristybb503372010-05-27 20:51:26 +00005339 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005340 ThrowMogrifyException(OptionError,"MissingArgument",option);
5341 break;
5342 }
5343 if (LocaleCompare("mask",option+1) == 0)
5344 {
5345 if (*option == '+')
5346 break;
5347 i++;
cristybb503372010-05-27 20:51:26 +00005348 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005349 ThrowMogrifyException(OptionError,"MissingArgument",option);
5350 break;
5351 }
5352 if (LocaleCompare("matte",option+1) == 0)
5353 break;
5354 if (LocaleCompare("mattecolor",option+1) == 0)
5355 {
5356 if (*option == '+')
5357 break;
5358 i++;
cristybb503372010-05-27 20:51:26 +00005359 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005360 ThrowMogrifyException(OptionError,"MissingArgument",option);
5361 break;
5362 }
cristyf40785b2010-03-06 02:27:27 +00005363 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00005364 break;
cristyf40785b2010-03-06 02:27:27 +00005365 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00005366 break;
cristy3ed852e2009-09-05 21:47:34 +00005367 if (LocaleCompare("modulate",option+1) == 0)
5368 {
5369 if (*option == '+')
5370 break;
5371 i++;
cristybb503372010-05-27 20:51:26 +00005372 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005373 ThrowMogrifyException(OptionError,"MissingArgument",option);
5374 if (IsGeometry(argv[i]) == MagickFalse)
5375 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5376 break;
5377 }
5378 if (LocaleCompare("median",option+1) == 0)
5379 {
5380 if (*option == '+')
5381 break;
5382 i++;
cristybb503372010-05-27 20:51:26 +00005383 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005384 ThrowMogrifyException(OptionError,"MissingArgument",option);
5385 if (IsGeometry(argv[i]) == MagickFalse)
5386 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5387 break;
5388 }
5389 if (LocaleCompare("monitor",option+1) == 0)
5390 break;
5391 if (LocaleCompare("monochrome",option+1) == 0)
5392 break;
5393 if (LocaleCompare("morph",option+1) == 0)
5394 {
5395 if (*option == '+')
5396 break;
5397 i++;
cristybb503372010-05-27 20:51:26 +00005398 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005399 ThrowMogrifyException(OptionError,"MissingArgument",option);
5400 if (IsGeometry(argv[i]) == MagickFalse)
5401 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5402 break;
5403 }
anthony29188a82010-01-22 10:12:34 +00005404 if (LocaleCompare("morphology",option+1) == 0)
5405 {
anthony29188a82010-01-22 10:12:34 +00005406 char
5407 token[MaxTextExtent];
5408
cristyb6bd4ad2010-08-08 01:12:27 +00005409 KernelInfo
5410 *kernel_info;
5411
5412 ssize_t
5413 op;
5414
anthony29188a82010-01-22 10:12:34 +00005415 i++;
cristybb503372010-05-27 20:51:26 +00005416 if (i == (ssize_t) argc)
anthony29188a82010-01-22 10:12:34 +00005417 ThrowMogrifyException(OptionError,"MissingArgument",option);
5418 GetMagickToken(argv[i],NULL,token);
5419 op=ParseMagickOption(MagickMorphologyOptions,MagickFalse,token);
5420 if (op < 0)
5421 ThrowMogrifyException(OptionError,"UnrecognizedMorphologyMethod",
cristyf0c78232010-03-15 12:53:40 +00005422 token);
anthony29188a82010-01-22 10:12:34 +00005423 i++;
cristybb503372010-05-27 20:51:26 +00005424 if (i == (ssize_t) (argc-1))
anthony29188a82010-01-22 10:12:34 +00005425 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00005426 kernel_info=AcquireKernelInfo(argv[i]);
5427 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00005428 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00005429 kernel_info=DestroyKernelInfo(kernel_info);
anthony29188a82010-01-22 10:12:34 +00005430 break;
5431 }
cristy3ed852e2009-09-05 21:47:34 +00005432 if (LocaleCompare("mosaic",option+1) == 0)
5433 break;
5434 if (LocaleCompare("motion-blur",option+1) == 0)
5435 {
5436 if (*option == '+')
5437 break;
5438 i++;
cristybb503372010-05-27 20:51:26 +00005439 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005440 ThrowMogrifyException(OptionError,"MissingArgument",option);
5441 if (IsGeometry(argv[i]) == MagickFalse)
5442 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5443 break;
5444 }
5445 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5446 }
5447 case 'n':
5448 {
5449 if (LocaleCompare("negate",option+1) == 0)
5450 break;
5451 if (LocaleCompare("noise",option+1) == 0)
5452 {
5453 i++;
cristybb503372010-05-27 20:51:26 +00005454 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005455 ThrowMogrifyException(OptionError,"MissingArgument",option);
5456 if (*option == '+')
5457 {
cristybb503372010-05-27 20:51:26 +00005458 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005459 noise;
5460
5461 noise=ParseMagickOption(MagickNoiseOptions,MagickFalse,argv[i]);
5462 if (noise < 0)
5463 ThrowMogrifyException(OptionError,"UnrecognizedNoiseType",
5464 argv[i]);
5465 break;
5466 }
5467 if (IsGeometry(argv[i]) == MagickFalse)
5468 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5469 break;
5470 }
5471 if (LocaleCompare("noop",option+1) == 0)
5472 break;
5473 if (LocaleCompare("normalize",option+1) == 0)
5474 break;
5475 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5476 }
5477 case 'o':
5478 {
5479 if (LocaleCompare("opaque",option+1) == 0)
5480 {
cristy3ed852e2009-09-05 21:47:34 +00005481 i++;
cristybb503372010-05-27 20:51:26 +00005482 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005483 ThrowMogrifyException(OptionError,"MissingArgument",option);
5484 break;
5485 }
5486 if (LocaleCompare("ordered-dither",option+1) == 0)
5487 {
5488 if (*option == '+')
5489 break;
5490 i++;
cristybb503372010-05-27 20:51:26 +00005491 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005492 ThrowMogrifyException(OptionError,"MissingArgument",option);
5493 break;
5494 }
5495 if (LocaleCompare("orient",option+1) == 0)
5496 {
cristybb503372010-05-27 20:51:26 +00005497 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005498 orientation;
5499
5500 orientation=UndefinedOrientation;
5501 if (*option == '+')
5502 break;
5503 i++;
cristybb503372010-05-27 20:51:26 +00005504 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005505 ThrowMogrifyException(OptionError,"MissingArgument",option);
5506 orientation=ParseMagickOption(MagickOrientationOptions,MagickFalse,
5507 argv[i]);
5508 if (orientation < 0)
5509 ThrowMogrifyException(OptionError,"UnrecognizedImageOrientation",
5510 argv[i]);
5511 break;
5512 }
5513 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5514 }
5515 case 'p':
5516 {
5517 if (LocaleCompare("page",option+1) == 0)
5518 {
5519 if (*option == '+')
5520 break;
5521 i++;
cristybb503372010-05-27 20:51:26 +00005522 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005523 ThrowMogrifyException(OptionError,"MissingArgument",option);
5524 break;
5525 }
5526 if (LocaleCompare("paint",option+1) == 0)
5527 {
5528 if (*option == '+')
5529 break;
5530 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 if (IsGeometry(argv[i]) == MagickFalse)
5534 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5535 break;
5536 }
5537 if (LocaleCompare("path",option+1) == 0)
5538 {
5539 (void) CloneString(&path,(char *) NULL);
5540 if (*option == '+')
5541 break;
5542 i++;
cristybb503372010-05-27 20:51:26 +00005543 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005544 ThrowMogrifyException(OptionError,"MissingArgument",option);
5545 (void) CloneString(&path,argv[i]);
5546 break;
5547 }
5548 if (LocaleCompare("pointsize",option+1) == 0)
5549 {
5550 if (*option == '+')
5551 break;
5552 i++;
cristybb503372010-05-27 20:51:26 +00005553 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005554 ThrowMogrifyException(OptionError,"MissingArgument",option);
5555 if (IsGeometry(argv[i]) == MagickFalse)
5556 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5557 break;
5558 }
5559 if (LocaleCompare("polaroid",option+1) == 0)
5560 {
5561 if (*option == '+')
5562 break;
5563 i++;
cristybb503372010-05-27 20:51:26 +00005564 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005565 ThrowMogrifyException(OptionError,"MissingArgument",option);
5566 if (IsGeometry(argv[i]) == MagickFalse)
5567 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5568 break;
5569 }
5570 if (LocaleCompare("posterize",option+1) == 0)
5571 {
5572 if (*option == '+')
5573 break;
5574 i++;
cristybb503372010-05-27 20:51:26 +00005575 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005576 ThrowMogrifyException(OptionError,"MissingArgument",option);
5577 if (IsGeometry(argv[i]) == MagickFalse)
5578 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5579 break;
5580 }
cristye7f51092010-01-17 00:39:37 +00005581 if (LocaleCompare("precision",option+1) == 0)
5582 {
5583 if (*option == '+')
5584 break;
5585 i++;
cristybb503372010-05-27 20:51:26 +00005586 if (i == (ssize_t) argc)
cristye7f51092010-01-17 00:39:37 +00005587 ThrowMogrifyException(OptionError,"MissingArgument",option);
5588 if (IsGeometry(argv[i]) == MagickFalse)
5589 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5590 break;
5591 }
cristy3ed852e2009-09-05 21:47:34 +00005592 if (LocaleCompare("print",option+1) == 0)
5593 {
5594 if (*option == '+')
5595 break;
5596 i++;
cristybb503372010-05-27 20:51:26 +00005597 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005598 ThrowMogrifyException(OptionError,"MissingArgument",option);
5599 break;
5600 }
5601 if (LocaleCompare("process",option+1) == 0)
5602 {
5603 if (*option == '+')
5604 break;
5605 i++;
cristybb503372010-05-27 20:51:26 +00005606 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005607 ThrowMogrifyException(OptionError,"MissingArgument",option);
5608 break;
5609 }
5610 if (LocaleCompare("profile",option+1) == 0)
5611 {
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 break;
5616 }
5617 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5618 }
5619 case 'q':
5620 {
5621 if (LocaleCompare("quality",option+1) == 0)
5622 {
5623 if (*option == '+')
5624 break;
5625 i++;
cristybb503372010-05-27 20:51:26 +00005626 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005627 ThrowMogrifyException(OptionError,"MissingArgument",option);
5628 if (IsGeometry(argv[i]) == MagickFalse)
5629 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5630 break;
5631 }
5632 if (LocaleCompare("quantize",option+1) == 0)
5633 {
cristybb503372010-05-27 20:51:26 +00005634 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005635 colorspace;
5636
5637 if (*option == '+')
5638 break;
5639 i++;
cristybb503372010-05-27 20:51:26 +00005640 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005641 ThrowMogrifyException(OptionError,"MissingArgument",option);
5642 colorspace=ParseMagickOption(MagickColorspaceOptions,MagickFalse,
5643 argv[i]);
5644 if (colorspace < 0)
5645 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
5646 argv[i]);
5647 break;
5648 }
5649 if (LocaleCompare("quiet",option+1) == 0)
5650 break;
5651 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5652 }
5653 case 'r':
5654 {
5655 if (LocaleCompare("radial-blur",option+1) == 0)
5656 {
5657 i++;
cristybb503372010-05-27 20:51:26 +00005658 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005659 ThrowMogrifyException(OptionError,"MissingArgument",option);
5660 if (IsGeometry(argv[i]) == MagickFalse)
5661 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5662 break;
5663 }
5664 if (LocaleCompare("raise",option+1) == 0)
5665 {
5666 i++;
cristybb503372010-05-27 20:51:26 +00005667 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005668 ThrowMogrifyException(OptionError,"MissingArgument",option);
5669 if (IsGeometry(argv[i]) == MagickFalse)
5670 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5671 break;
5672 }
5673 if (LocaleCompare("random-threshold",option+1) == 0)
5674 {
5675 if (*option == '+')
5676 break;
5677 i++;
cristybb503372010-05-27 20:51:26 +00005678 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005679 ThrowMogrifyException(OptionError,"MissingArgument",option);
5680 if (IsGeometry(argv[i]) == MagickFalse)
5681 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5682 break;
5683 }
cristye6365592010-04-02 17:31:23 +00005684 if (LocaleCompare("recolor",option+1) == 0)
5685 {
5686 if (*option == '+')
5687 break;
5688 i++;
cristybb503372010-05-27 20:51:26 +00005689 if (i == (ssize_t) (argc-1))
cristye6365592010-04-02 17:31:23 +00005690 ThrowMogrifyException(OptionError,"MissingArgument",option);
5691 if (IsGeometry(argv[i]) == MagickFalse)
5692 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5693 break;
5694 }
cristy3ed852e2009-09-05 21:47:34 +00005695 if (LocaleCompare("red-primary",option+1) == 0)
5696 {
5697 if (*option == '+')
5698 break;
5699 i++;
cristybb503372010-05-27 20:51:26 +00005700 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005701 ThrowMogrifyException(OptionError,"MissingArgument",option);
5702 if (IsGeometry(argv[i]) == MagickFalse)
5703 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5704 }
cristy9f2083a2010-04-22 19:48:05 +00005705 if (LocaleCompare("regard-warnings",option+1) == 0)
5706 break;
cristy3ed852e2009-09-05 21:47:34 +00005707 if (LocaleCompare("region",option+1) == 0)
5708 {
5709 if (*option == '+')
5710 break;
5711 i++;
cristybb503372010-05-27 20:51:26 +00005712 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005713 ThrowMogrifyException(OptionError,"MissingArgument",option);
5714 if (IsGeometry(argv[i]) == MagickFalse)
5715 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5716 break;
5717 }
cristyf0c78232010-03-15 12:53:40 +00005718 if (LocaleCompare("remap",option+1) == 0)
5719 {
5720 if (*option == '+')
5721 break;
5722 i++;
cristybb503372010-05-27 20:51:26 +00005723 if (i == (ssize_t) (argc-1))
cristyf0c78232010-03-15 12:53:40 +00005724 ThrowMogrifyException(OptionError,"MissingArgument",option);
5725 break;
5726 }
cristy3ed852e2009-09-05 21:47:34 +00005727 if (LocaleCompare("render",option+1) == 0)
5728 break;
5729 if (LocaleCompare("repage",option+1) == 0)
5730 {
5731 if (*option == '+')
5732 break;
5733 i++;
cristybb503372010-05-27 20:51:26 +00005734 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005735 ThrowMogrifyException(OptionError,"MissingArgument",option);
5736 if (IsGeometry(argv[i]) == MagickFalse)
5737 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5738 break;
5739 }
5740 if (LocaleCompare("resample",option+1) == 0)
5741 {
5742 if (*option == '+')
5743 break;
5744 i++;
cristybb503372010-05-27 20:51:26 +00005745 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005746 ThrowMogrifyException(OptionError,"MissingArgument",option);
5747 if (IsGeometry(argv[i]) == MagickFalse)
5748 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5749 break;
5750 }
5751 if (LocaleCompare("resize",option+1) == 0)
5752 {
5753 if (*option == '+')
5754 break;
5755 i++;
cristybb503372010-05-27 20:51:26 +00005756 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005757 ThrowMogrifyException(OptionError,"MissingArgument",option);
5758 if (IsGeometry(argv[i]) == MagickFalse)
5759 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5760 break;
5761 }
5762 if (LocaleCompare("reverse",option+1) == 0)
5763 break;
5764 if (LocaleCompare("roll",option+1) == 0)
5765 {
5766 if (*option == '+')
5767 break;
5768 i++;
cristybb503372010-05-27 20:51:26 +00005769 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005770 ThrowMogrifyException(OptionError,"MissingArgument",option);
5771 if (IsGeometry(argv[i]) == MagickFalse)
5772 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5773 break;
5774 }
5775 if (LocaleCompare("rotate",option+1) == 0)
5776 {
5777 i++;
cristybb503372010-05-27 20:51:26 +00005778 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005779 ThrowMogrifyException(OptionError,"MissingArgument",option);
5780 if (IsGeometry(argv[i]) == MagickFalse)
5781 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5782 break;
5783 }
5784 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5785 }
5786 case 's':
5787 {
5788 if (LocaleCompare("sample",option+1) == 0)
5789 {
5790 if (*option == '+')
5791 break;
5792 i++;
cristybb503372010-05-27 20:51:26 +00005793 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005794 ThrowMogrifyException(OptionError,"MissingArgument",option);
5795 if (IsGeometry(argv[i]) == MagickFalse)
5796 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5797 break;
5798 }
5799 if (LocaleCompare("sampling-factor",option+1) == 0)
5800 {
5801 if (*option == '+')
5802 break;
5803 i++;
cristybb503372010-05-27 20:51:26 +00005804 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005805 ThrowMogrifyException(OptionError,"MissingArgument",option);
5806 if (IsGeometry(argv[i]) == MagickFalse)
5807 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5808 break;
5809 }
5810 if (LocaleCompare("scale",option+1) == 0)
5811 {
5812 if (*option == '+')
5813 break;
5814 i++;
cristybb503372010-05-27 20:51:26 +00005815 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005816 ThrowMogrifyException(OptionError,"MissingArgument",option);
5817 if (IsGeometry(argv[i]) == MagickFalse)
5818 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5819 break;
5820 }
5821 if (LocaleCompare("scene",option+1) == 0)
5822 {
5823 if (*option == '+')
5824 break;
5825 i++;
cristybb503372010-05-27 20:51:26 +00005826 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005827 ThrowMogrifyException(OptionError,"MissingArgument",option);
5828 if (IsGeometry(argv[i]) == MagickFalse)
5829 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5830 break;
5831 }
5832 if (LocaleCompare("seed",option+1) == 0)
5833 {
5834 if (*option == '+')
5835 break;
5836 i++;
cristybb503372010-05-27 20:51:26 +00005837 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005838 ThrowMogrifyException(OptionError,"MissingArgument",option);
5839 if (IsGeometry(argv[i]) == MagickFalse)
5840 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5841 break;
5842 }
5843 if (LocaleCompare("segment",option+1) == 0)
5844 {
5845 if (*option == '+')
5846 break;
5847 i++;
cristybb503372010-05-27 20:51:26 +00005848 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005849 ThrowMogrifyException(OptionError,"MissingArgument",option);
5850 if (IsGeometry(argv[i]) == MagickFalse)
5851 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5852 break;
5853 }
5854 if (LocaleCompare("selective-blur",option+1) == 0)
5855 {
5856 i++;
cristybb503372010-05-27 20:51:26 +00005857 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005858 ThrowMogrifyException(OptionError,"MissingArgument",option);
5859 if (IsGeometry(argv[i]) == MagickFalse)
5860 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5861 break;
5862 }
5863 if (LocaleCompare("separate",option+1) == 0)
5864 break;
5865 if (LocaleCompare("sepia-tone",option+1) == 0)
5866 {
5867 if (*option == '+')
5868 break;
5869 i++;
cristybb503372010-05-27 20:51:26 +00005870 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005871 ThrowMogrifyException(OptionError,"MissingArgument",option);
5872 if (IsGeometry(argv[i]) == MagickFalse)
5873 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5874 break;
5875 }
5876 if (LocaleCompare("set",option+1) == 0)
5877 {
5878 i++;
cristybb503372010-05-27 20:51:26 +00005879 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005880 ThrowMogrifyException(OptionError,"MissingArgument",option);
5881 if (*option == '+')
5882 break;
5883 i++;
cristybb503372010-05-27 20:51:26 +00005884 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005885 ThrowMogrifyException(OptionError,"MissingArgument",option);
5886 break;
5887 }
5888 if (LocaleCompare("shade",option+1) == 0)
5889 {
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("shadow",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("sharpen",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("shave",option+1) == 0)
5918 {
5919 if (*option == '+')
5920 break;
5921 i++;
cristybb503372010-05-27 20:51:26 +00005922 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005923 ThrowMogrifyException(OptionError,"MissingArgument",option);
5924 if (IsGeometry(argv[i]) == MagickFalse)
5925 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5926 break;
5927 }
5928 if (LocaleCompare("shear",option+1) == 0)
5929 {
5930 i++;
cristybb503372010-05-27 20:51:26 +00005931 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005932 ThrowMogrifyException(OptionError,"MissingArgument",option);
5933 if (IsGeometry(argv[i]) == MagickFalse)
5934 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5935 break;
5936 }
5937 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
5938 {
5939 i++;
cristybb503372010-05-27 20:51:26 +00005940 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005941 ThrowMogrifyException(OptionError,"MissingArgument",option);
5942 if (IsGeometry(argv[i]) == MagickFalse)
5943 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5944 break;
5945 }
5946 if (LocaleCompare("size",option+1) == 0)
5947 {
5948 if (*option == '+')
5949 break;
5950 i++;
cristybb503372010-05-27 20:51:26 +00005951 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005952 ThrowMogrifyException(OptionError,"MissingArgument",option);
5953 if (IsGeometry(argv[i]) == MagickFalse)
5954 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5955 break;
5956 }
5957 if (LocaleCompare("sketch",option+1) == 0)
5958 {
5959 if (*option == '+')
5960 break;
5961 i++;
cristybb503372010-05-27 20:51:26 +00005962 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005963 ThrowMogrifyException(OptionError,"MissingArgument",option);
5964 if (IsGeometry(argv[i]) == MagickFalse)
5965 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5966 break;
5967 }
cristy4285d782011-02-09 20:12:28 +00005968 if (LocaleCompare("smush",option+1) == 0)
5969 {
5970 if (*option == '+')
5971 break;
5972 i++;
5973 if (i == (ssize_t) argc)
5974 ThrowMogrifyException(OptionError,"MissingArgument",option);
5975 if (IsGeometry(argv[i]) == MagickFalse)
5976 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5977 if (i == (ssize_t) argc)
5978 ThrowMogrifyException(OptionError,"MissingArgument",option);
5979 i++;
5980 break;
5981 }
cristy3ed852e2009-09-05 21:47:34 +00005982 if (LocaleCompare("solarize",option+1) == 0)
5983 {
5984 if (*option == '+')
5985 break;
5986 i++;
cristybb503372010-05-27 20:51:26 +00005987 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005988 ThrowMogrifyException(OptionError,"MissingArgument",option);
5989 if (IsGeometry(argv[i]) == MagickFalse)
5990 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5991 break;
5992 }
5993 if (LocaleCompare("sparse-color",option+1) == 0)
5994 {
cristybb503372010-05-27 20:51:26 +00005995 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005996 op;
5997
5998 i++;
cristybb503372010-05-27 20:51:26 +00005999 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006000 ThrowMogrifyException(OptionError,"MissingArgument",option);
6001 op=ParseMagickOption(MagickSparseColorOptions,MagickFalse,argv[i]);
6002 if (op < 0)
6003 ThrowMogrifyException(OptionError,"UnrecognizedSparseColorMethod",
6004 argv[i]);
6005 i++;
cristybb503372010-05-27 20:51:26 +00006006 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006007 ThrowMogrifyException(OptionError,"MissingArgument",option);
6008 break;
6009 }
6010 if (LocaleCompare("spread",option+1) == 0)
6011 {
6012 if (*option == '+')
6013 break;
6014 i++;
cristybb503372010-05-27 20:51:26 +00006015 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006016 ThrowMogrifyException(OptionError,"MissingArgument",option);
6017 if (IsGeometry(argv[i]) == MagickFalse)
6018 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6019 break;
6020 }
6021 if (LocaleCompare("stretch",option+1) == 0)
6022 {
cristybb503372010-05-27 20:51:26 +00006023 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006024 stretch;
6025
6026 if (*option == '+')
6027 break;
6028 i++;
cristybb503372010-05-27 20:51:26 +00006029 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006030 ThrowMogrifyException(OptionError,"MissingArgument",option);
6031 stretch=ParseMagickOption(MagickStretchOptions,MagickFalse,argv[i]);
6032 if (stretch < 0)
6033 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
6034 argv[i]);
6035 break;
6036 }
6037 if (LocaleCompare("strip",option+1) == 0)
6038 break;
6039 if (LocaleCompare("stroke",option+1) == 0)
6040 {
6041 if (*option == '+')
6042 break;
6043 i++;
cristybb503372010-05-27 20:51:26 +00006044 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006045 ThrowMogrifyException(OptionError,"MissingArgument",option);
6046 break;
6047 }
6048 if (LocaleCompare("strokewidth",option+1) == 0)
6049 {
6050 if (*option == '+')
6051 break;
6052 i++;
cristybb503372010-05-27 20:51:26 +00006053 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006054 ThrowMogrifyException(OptionError,"MissingArgument",option);
6055 if (IsGeometry(argv[i]) == MagickFalse)
6056 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6057 break;
6058 }
6059 if (LocaleCompare("style",option+1) == 0)
6060 {
cristybb503372010-05-27 20:51:26 +00006061 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006062 style;
6063
6064 if (*option == '+')
6065 break;
6066 i++;
cristybb503372010-05-27 20:51:26 +00006067 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006068 ThrowMogrifyException(OptionError,"MissingArgument",option);
6069 style=ParseMagickOption(MagickStyleOptions,MagickFalse,argv[i]);
6070 if (style < 0)
6071 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
6072 argv[i]);
6073 break;
6074 }
6075 if (LocaleCompare("swirl",option+1) == 0)
6076 {
6077 if (*option == '+')
6078 break;
6079 i++;
cristybb503372010-05-27 20:51:26 +00006080 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006081 ThrowMogrifyException(OptionError,"MissingArgument",option);
6082 if (IsGeometry(argv[i]) == MagickFalse)
6083 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6084 break;
6085 }
cristyd9a29192010-10-16 16:49:53 +00006086 if (LocaleCompare("synchronize",option+1) == 0)
6087 break;
cristy3ed852e2009-09-05 21:47:34 +00006088 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6089 }
6090 case 't':
6091 {
6092 if (LocaleCompare("taint",option+1) == 0)
6093 break;
6094 if (LocaleCompare("texture",option+1) == 0)
6095 {
6096 if (*option == '+')
6097 break;
6098 i++;
cristybb503372010-05-27 20:51:26 +00006099 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006100 ThrowMogrifyException(OptionError,"MissingArgument",option);
6101 break;
6102 }
6103 if (LocaleCompare("tile",option+1) == 0)
6104 {
6105 if (*option == '+')
6106 break;
6107 i++;
cristybb503372010-05-27 20:51:26 +00006108 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006109 ThrowMogrifyException(OptionError,"MissingArgument",option);
6110 break;
6111 }
6112 if (LocaleCompare("tile-offset",option+1) == 0)
6113 {
6114 if (*option == '+')
6115 break;
6116 i++;
cristybb503372010-05-27 20:51:26 +00006117 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006118 ThrowMogrifyException(OptionError,"MissingArgument",option);
6119 if (IsGeometry(argv[i]) == MagickFalse)
6120 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6121 break;
6122 }
6123 if (LocaleCompare("tint",option+1) == 0)
6124 {
6125 if (*option == '+')
6126 break;
6127 i++;
cristybb503372010-05-27 20:51:26 +00006128 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006129 ThrowMogrifyException(OptionError,"MissingArgument",option);
6130 if (IsGeometry(argv[i]) == MagickFalse)
6131 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6132 break;
6133 }
6134 if (LocaleCompare("transform",option+1) == 0)
6135 break;
6136 if (LocaleCompare("transpose",option+1) == 0)
6137 break;
6138 if (LocaleCompare("transverse",option+1) == 0)
6139 break;
6140 if (LocaleCompare("threshold",option+1) == 0)
6141 {
6142 if (*option == '+')
6143 break;
6144 i++;
cristybb503372010-05-27 20:51:26 +00006145 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006146 ThrowMogrifyException(OptionError,"MissingArgument",option);
6147 if (IsGeometry(argv[i]) == MagickFalse)
6148 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6149 break;
6150 }
6151 if (LocaleCompare("thumbnail",option+1) == 0)
6152 {
6153 if (*option == '+')
6154 break;
6155 i++;
cristybb503372010-05-27 20:51:26 +00006156 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006157 ThrowMogrifyException(OptionError,"MissingArgument",option);
6158 if (IsGeometry(argv[i]) == MagickFalse)
6159 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6160 break;
6161 }
6162 if (LocaleCompare("transparent",option+1) == 0)
6163 {
6164 i++;
cristybb503372010-05-27 20:51:26 +00006165 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006166 ThrowMogrifyException(OptionError,"MissingArgument",option);
6167 break;
6168 }
6169 if (LocaleCompare("transparent-color",option+1) == 0)
6170 {
6171 if (*option == '+')
6172 break;
6173 i++;
cristybb503372010-05-27 20:51:26 +00006174 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006175 ThrowMogrifyException(OptionError,"MissingArgument",option);
6176 break;
6177 }
6178 if (LocaleCompare("treedepth",option+1) == 0)
6179 {
6180 if (*option == '+')
6181 break;
6182 i++;
cristybb503372010-05-27 20:51:26 +00006183 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006184 ThrowMogrifyException(OptionError,"MissingArgument",option);
6185 if (IsGeometry(argv[i]) == MagickFalse)
6186 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6187 break;
6188 }
6189 if (LocaleCompare("trim",option+1) == 0)
6190 break;
6191 if (LocaleCompare("type",option+1) == 0)
6192 {
cristybb503372010-05-27 20:51:26 +00006193 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006194 type;
6195
6196 if (*option == '+')
6197 break;
6198 i++;
cristybb503372010-05-27 20:51:26 +00006199 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006200 ThrowMogrifyException(OptionError,"MissingArgument",option);
6201 type=ParseMagickOption(MagickTypeOptions,MagickFalse,argv[i]);
6202 if (type < 0)
6203 ThrowMogrifyException(OptionError,"UnrecognizedImageType",
6204 argv[i]);
6205 break;
6206 }
6207 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6208 }
6209 case 'u':
6210 {
6211 if (LocaleCompare("undercolor",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 break;
6219 }
6220 if (LocaleCompare("unique-colors",option+1) == 0)
6221 break;
6222 if (LocaleCompare("units",option+1) == 0)
6223 {
cristybb503372010-05-27 20:51:26 +00006224 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006225 units;
6226
6227 if (*option == '+')
6228 break;
6229 i++;
cristybb503372010-05-27 20:51:26 +00006230 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006231 ThrowMogrifyException(OptionError,"MissingArgument",option);
6232 units=ParseMagickOption(MagickResolutionOptions,MagickFalse,
6233 argv[i]);
6234 if (units < 0)
6235 ThrowMogrifyException(OptionError,"UnrecognizedUnitsType",
6236 argv[i]);
6237 break;
6238 }
6239 if (LocaleCompare("unsharp",option+1) == 0)
6240 {
6241 i++;
cristybb503372010-05-27 20:51:26 +00006242 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006243 ThrowMogrifyException(OptionError,"MissingArgument",option);
6244 if (IsGeometry(argv[i]) == MagickFalse)
6245 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6246 break;
6247 }
6248 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6249 }
6250 case 'v':
6251 {
6252 if (LocaleCompare("verbose",option+1) == 0)
6253 {
6254 image_info->verbose=(*option == '-') ? MagickTrue : MagickFalse;
6255 break;
6256 }
6257 if ((LocaleCompare("version",option+1) == 0) ||
6258 (LocaleCompare("-version",option+1) == 0))
6259 {
6260 (void) fprintf(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +00006261 GetMagickVersion((size_t *) NULL));
cristy610b2e22009-10-22 14:59:43 +00006262 (void) fprintf(stdout,"Copyright: %s\n",GetMagickCopyright());
6263 (void) fprintf(stdout,"Features: %s\n\n",GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00006264 break;
6265 }
6266 if (LocaleCompare("view",option+1) == 0)
6267 {
6268 if (*option == '+')
6269 break;
6270 i++;
cristybb503372010-05-27 20:51:26 +00006271 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006272 ThrowMogrifyException(OptionError,"MissingArgument",option);
6273 break;
6274 }
6275 if (LocaleCompare("vignette",option+1) == 0)
6276 {
6277 if (*option == '+')
6278 break;
6279 i++;
cristybb503372010-05-27 20:51:26 +00006280 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006281 ThrowMogrifyException(OptionError,"MissingArgument",option);
6282 if (IsGeometry(argv[i]) == MagickFalse)
6283 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6284 break;
6285 }
6286 if (LocaleCompare("virtual-pixel",option+1) == 0)
6287 {
cristybb503372010-05-27 20:51:26 +00006288 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006289 method;
6290
6291 if (*option == '+')
6292 break;
6293 i++;
cristybb503372010-05-27 20:51:26 +00006294 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006295 ThrowMogrifyException(OptionError,"MissingArgument",option);
6296 method=ParseMagickOption(MagickVirtualPixelOptions,MagickFalse,
6297 argv[i]);
6298 if (method < 0)
6299 ThrowMogrifyException(OptionError,
6300 "UnrecognizedVirtualPixelMethod",argv[i]);
6301 break;
6302 }
6303 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6304 }
6305 case 'w':
6306 {
6307 if (LocaleCompare("wave",option+1) == 0)
6308 {
6309 i++;
cristybb503372010-05-27 20:51:26 +00006310 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006311 ThrowMogrifyException(OptionError,"MissingArgument",option);
6312 if (IsGeometry(argv[i]) == MagickFalse)
6313 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6314 break;
6315 }
6316 if (LocaleCompare("weight",option+1) == 0)
6317 {
6318 if (*option == '+')
6319 break;
6320 i++;
cristybb503372010-05-27 20:51:26 +00006321 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006322 ThrowMogrifyException(OptionError,"MissingArgument",option);
6323 break;
6324 }
6325 if (LocaleCompare("white-point",option+1) == 0)
6326 {
6327 if (*option == '+')
6328 break;
6329 i++;
cristybb503372010-05-27 20:51:26 +00006330 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006331 ThrowMogrifyException(OptionError,"MissingArgument",option);
6332 if (IsGeometry(argv[i]) == MagickFalse)
6333 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6334 break;
6335 }
6336 if (LocaleCompare("white-threshold",option+1) == 0)
6337 {
6338 if (*option == '+')
6339 break;
6340 i++;
cristybb503372010-05-27 20:51:26 +00006341 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006342 ThrowMogrifyException(OptionError,"MissingArgument",option);
6343 if (IsGeometry(argv[i]) == MagickFalse)
6344 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6345 break;
6346 }
6347 if (LocaleCompare("write",option+1) == 0)
6348 {
6349 i++;
cristybb503372010-05-27 20:51:26 +00006350 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006351 ThrowMogrifyException(OptionError,"MissingArgument",option);
6352 break;
6353 }
6354 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6355 }
6356 case '?':
6357 break;
6358 default:
6359 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6360 }
6361 fire=ParseMagickOption(MagickImageListOptions,MagickFalse,option+1) < 0 ?
6362 MagickFalse : MagickTrue;
6363 if (fire != MagickFalse)
6364 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
6365 }
6366 if (k != 0)
6367 ThrowMogrifyException(OptionError,"UnbalancedParenthesis",argv[i]);
cristycee97112010-05-28 00:44:52 +00006368 if (i != (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006369 ThrowMogrifyException(OptionError,"MissingAnImageFilename",argv[i]);
6370 DestroyMogrify();
6371 return(status != 0 ? MagickTrue : MagickFalse);
6372}
6373
6374/*
6375%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6376% %
6377% %
6378% %
6379+ M o g r i f y I m a g e I n f o %
6380% %
6381% %
6382% %
6383%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6384%
6385% MogrifyImageInfo() applies image processing settings to the image as
6386% prescribed by command line options.
6387%
6388% The format of the MogrifyImageInfo method is:
6389%
6390% MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,const int argc,
6391% const char **argv,ExceptionInfo *exception)
6392%
6393% A description of each parameter follows:
6394%
6395% o image_info: the image info..
6396%
6397% o argc: Specifies a pointer to an integer describing the number of
6398% elements in the argument vector.
6399%
6400% o argv: Specifies a pointer to a text array containing the command line
6401% arguments.
6402%
6403% o exception: return any errors or warnings in this structure.
6404%
6405*/
6406WandExport MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,
6407 const int argc,const char **argv,ExceptionInfo *exception)
6408{
6409 const char
6410 *option;
6411
6412 GeometryInfo
6413 geometry_info;
6414
cristybb503372010-05-27 20:51:26 +00006415 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006416 count;
6417
cristybb503372010-05-27 20:51:26 +00006418 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006419 i;
6420
6421 /*
6422 Initialize method variables.
6423 */
6424 assert(image_info != (ImageInfo *) NULL);
6425 assert(image_info->signature == MagickSignature);
6426 if (image_info->debug != MagickFalse)
6427 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
6428 image_info->filename);
6429 if (argc < 0)
6430 return(MagickTrue);
6431 /*
6432 Set the image settings.
6433 */
cristybb503372010-05-27 20:51:26 +00006434 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00006435 {
6436 option=argv[i];
6437 if (IsMagickOption(option) == MagickFalse)
6438 continue;
6439 count=MagickMax(ParseMagickOption(MagickCommandOptions,MagickFalse,option),
6440 0L);
cristycee97112010-05-28 00:44:52 +00006441 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006442 break;
6443 switch (*(option+1))
6444 {
6445 case 'a':
6446 {
6447 if (LocaleCompare("adjoin",option+1) == 0)
6448 {
6449 image_info->adjoin=(*option == '-') ? MagickTrue : MagickFalse;
6450 break;
6451 }
6452 if (LocaleCompare("antialias",option+1) == 0)
6453 {
6454 image_info->antialias=(*option == '-') ? MagickTrue : MagickFalse;
6455 break;
6456 }
6457 if (LocaleCompare("attenuate",option+1) == 0)
6458 {
6459 if (*option == '+')
6460 {
6461 (void) DeleteImageOption(image_info,option+1);
6462 break;
6463 }
6464 (void) SetImageOption(image_info,option+1,argv[i+1]);
6465 break;
6466 }
6467 if (LocaleCompare("authenticate",option+1) == 0)
6468 {
6469 if (*option == '+')
6470 (void) CloneString(&image_info->authenticate,(char *) NULL);
6471 else
6472 (void) CloneString(&image_info->authenticate,argv[i+1]);
6473 break;
6474 }
6475 break;
6476 }
6477 case 'b':
6478 {
6479 if (LocaleCompare("background",option+1) == 0)
6480 {
6481 if (*option == '+')
6482 {
6483 (void) DeleteImageOption(image_info,option+1);
6484 (void) QueryColorDatabase(BackgroundColor,
6485 &image_info->background_color,exception);
6486 break;
6487 }
6488 (void) SetImageOption(image_info,option+1,argv[i+1]);
6489 (void) QueryColorDatabase(argv[i+1],&image_info->background_color,
6490 exception);
6491 break;
6492 }
6493 if (LocaleCompare("bias",option+1) == 0)
6494 {
6495 if (*option == '+')
6496 {
6497 (void) SetImageOption(image_info,option+1,"0.0");
6498 break;
6499 }
6500 (void) SetImageOption(image_info,option+1,argv[i+1]);
6501 break;
6502 }
6503 if (LocaleCompare("black-point-compensation",option+1) == 0)
6504 {
6505 if (*option == '+')
6506 {
6507 (void) SetImageOption(image_info,option+1,"false");
6508 break;
6509 }
6510 (void) SetImageOption(image_info,option+1,"true");
6511 break;
6512 }
6513 if (LocaleCompare("blue-primary",option+1) == 0)
6514 {
6515 if (*option == '+')
6516 {
6517 (void) SetImageOption(image_info,option+1,"0.0");
6518 break;
6519 }
6520 (void) SetImageOption(image_info,option+1,argv[i+1]);
6521 break;
6522 }
6523 if (LocaleCompare("bordercolor",option+1) == 0)
6524 {
6525 if (*option == '+')
6526 {
6527 (void) DeleteImageOption(image_info,option+1);
6528 (void) QueryColorDatabase(BorderColor,&image_info->border_color,
6529 exception);
6530 break;
6531 }
6532 (void) QueryColorDatabase(argv[i+1],&image_info->border_color,
6533 exception);
6534 (void) SetImageOption(image_info,option+1,argv[i+1]);
6535 break;
6536 }
6537 if (LocaleCompare("box",option+1) == 0)
6538 {
6539 if (*option == '+')
6540 {
6541 (void) SetImageOption(image_info,"undercolor","none");
6542 break;
6543 }
6544 (void) SetImageOption(image_info,"undercolor",argv[i+1]);
6545 break;
6546 }
6547 break;
6548 }
6549 case 'c':
6550 {
6551 if (LocaleCompare("cache",option+1) == 0)
6552 {
6553 MagickSizeType
6554 limit;
6555
6556 limit=MagickResourceInfinity;
6557 if (LocaleCompare("unlimited",argv[i+1]) != 0)
cristyf2f27272009-12-17 14:48:46 +00006558 limit=(MagickSizeType) SiPrefixToDouble(argv[i+1],100.0);
cristy3ed852e2009-09-05 21:47:34 +00006559 (void) SetMagickResourceLimit(MemoryResource,limit);
6560 (void) SetMagickResourceLimit(MapResource,2*limit);
6561 break;
6562 }
6563 if (LocaleCompare("caption",option+1) == 0)
6564 {
6565 if (*option == '+')
6566 {
6567 (void) DeleteImageOption(image_info,option+1);
6568 break;
6569 }
6570 (void) SetImageOption(image_info,option+1,argv[i+1]);
6571 break;
6572 }
6573 if (LocaleCompare("channel",option+1) == 0)
6574 {
6575 if (*option == '+')
6576 {
6577 image_info->channel=DefaultChannels;
6578 break;
6579 }
6580 image_info->channel=(ChannelType) ParseChannelOption(argv[i+1]);
6581 break;
6582 }
6583 if (LocaleCompare("colors",option+1) == 0)
6584 {
cristye27293e2009-12-18 02:53:20 +00006585 image_info->colors=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006586 break;
6587 }
6588 if (LocaleCompare("colorspace",option+1) == 0)
6589 {
6590 if (*option == '+')
6591 {
6592 image_info->colorspace=UndefinedColorspace;
6593 (void) SetImageOption(image_info,option+1,"undefined");
6594 break;
6595 }
6596 image_info->colorspace=(ColorspaceType) ParseMagickOption(
6597 MagickColorspaceOptions,MagickFalse,argv[i+1]);
6598 (void) SetImageOption(image_info,option+1,argv[i+1]);
6599 break;
6600 }
6601 if (LocaleCompare("compress",option+1) == 0)
6602 {
6603 if (*option == '+')
6604 {
6605 image_info->compression=UndefinedCompression;
6606 (void) SetImageOption(image_info,option+1,"undefined");
6607 break;
6608 }
6609 image_info->compression=(CompressionType) ParseMagickOption(
6610 MagickCompressOptions,MagickFalse,argv[i+1]);
6611 (void) SetImageOption(image_info,option+1,argv[i+1]);
6612 break;
6613 }
6614 if (LocaleCompare("comment",option+1) == 0)
6615 {
6616 if (*option == '+')
6617 {
6618 (void) DeleteImageOption(image_info,option+1);
6619 break;
6620 }
6621 (void) SetImageOption(image_info,option+1,argv[i+1]);
6622 break;
6623 }
6624 if (LocaleCompare("compose",option+1) == 0)
6625 {
6626 if (*option == '+')
6627 {
6628 (void) SetImageOption(image_info,option+1,"undefined");
6629 break;
6630 }
6631 (void) SetImageOption(image_info,option+1,argv[i+1]);
6632 break;
6633 }
6634 if (LocaleCompare("compress",option+1) == 0)
6635 {
6636 if (*option == '+')
6637 {
6638 image_info->compression=UndefinedCompression;
6639 (void) SetImageOption(image_info,option+1,"undefined");
6640 break;
6641 }
6642 image_info->compression=(CompressionType) ParseMagickOption(
6643 MagickCompressOptions,MagickFalse,argv[i+1]);
6644 (void) SetImageOption(image_info,option+1,argv[i+1]);
6645 break;
6646 }
6647 break;
6648 }
6649 case 'd':
6650 {
6651 if (LocaleCompare("debug",option+1) == 0)
6652 {
6653 if (*option == '+')
6654 (void) SetLogEventMask("none");
6655 else
6656 (void) SetLogEventMask(argv[i+1]);
6657 image_info->debug=IsEventLogging();
6658 break;
6659 }
6660 if (LocaleCompare("define",option+1) == 0)
6661 {
6662 if (*option == '+')
6663 {
6664 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6665 (void) DeleteImageRegistry(argv[i+1]+9);
6666 else
6667 (void) DeleteImageOption(image_info,argv[i+1]);
6668 break;
6669 }
6670 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6671 {
6672 (void) DefineImageRegistry(StringRegistryType,argv[i+1]+9,
6673 exception);
6674 break;
6675 }
6676 (void) DefineImageOption(image_info,argv[i+1]);
6677 break;
6678 }
6679 if (LocaleCompare("delay",option+1) == 0)
6680 {
6681 if (*option == '+')
6682 {
6683 (void) SetImageOption(image_info,option+1,"0");
6684 break;
6685 }
6686 (void) SetImageOption(image_info,option+1,argv[i+1]);
6687 break;
6688 }
6689 if (LocaleCompare("density",option+1) == 0)
6690 {
6691 /*
6692 Set image density.
6693 */
6694 if (*option == '+')
6695 {
6696 if (image_info->density != (char *) NULL)
6697 image_info->density=DestroyString(image_info->density);
6698 (void) SetImageOption(image_info,option+1,"72");
6699 break;
6700 }
6701 (void) CloneString(&image_info->density,argv[i+1]);
6702 (void) SetImageOption(image_info,option+1,argv[i+1]);
6703 break;
6704 }
6705 if (LocaleCompare("depth",option+1) == 0)
6706 {
6707 if (*option == '+')
6708 {
6709 image_info->depth=MAGICKCORE_QUANTUM_DEPTH;
6710 break;
6711 }
cristye27293e2009-12-18 02:53:20 +00006712 image_info->depth=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006713 break;
6714 }
cristyc9b12952010-03-28 01:12:28 +00006715 if (LocaleCompare("direction",option+1) == 0)
6716 {
6717 if (*option == '+')
6718 {
6719 (void) SetImageOption(image_info,option+1,"undefined");
6720 break;
6721 }
6722 (void) SetImageOption(image_info,option+1,argv[i+1]);
6723 break;
6724 }
cristy3ed852e2009-09-05 21:47:34 +00006725 if (LocaleCompare("display",option+1) == 0)
6726 {
6727 if (*option == '+')
6728 {
6729 if (image_info->server_name != (char *) NULL)
6730 image_info->server_name=DestroyString(
6731 image_info->server_name);
6732 break;
6733 }
6734 (void) CloneString(&image_info->server_name,argv[i+1]);
6735 break;
6736 }
6737 if (LocaleCompare("dispose",option+1) == 0)
6738 {
6739 if (*option == '+')
6740 {
6741 (void) SetImageOption(image_info,option+1,"undefined");
6742 break;
6743 }
6744 (void) SetImageOption(image_info,option+1,argv[i+1]);
6745 break;
6746 }
6747 if (LocaleCompare("dither",option+1) == 0)
6748 {
6749 if (*option == '+')
6750 {
6751 image_info->dither=MagickFalse;
cristyd5acfd12010-06-15 00:11:38 +00006752 (void) SetImageOption(image_info,option+1,"none");
cristy3ed852e2009-09-05 21:47:34 +00006753 break;
6754 }
6755 (void) SetImageOption(image_info,option+1,argv[i+1]);
6756 image_info->dither=MagickTrue;
6757 break;
6758 }
6759 break;
6760 }
6761 case 'e':
6762 {
6763 if (LocaleCompare("encoding",option+1) == 0)
6764 {
6765 if (*option == '+')
6766 {
6767 (void) SetImageOption(image_info,option+1,"undefined");
6768 break;
6769 }
6770 (void) SetImageOption(image_info,option+1,argv[i+1]);
6771 break;
6772 }
6773 if (LocaleCompare("endian",option+1) == 0)
6774 {
6775 if (*option == '+')
6776 {
6777 image_info->endian=UndefinedEndian;
6778 (void) SetImageOption(image_info,option+1,"undefined");
6779 break;
6780 }
6781 image_info->endian=(EndianType) ParseMagickOption(
6782 MagickEndianOptions,MagickFalse,argv[i+1]);
6783 (void) SetImageOption(image_info,option+1,argv[i+1]);
6784 break;
6785 }
6786 if (LocaleCompare("extract",option+1) == 0)
6787 {
6788 /*
6789 Set image extract geometry.
6790 */
6791 if (*option == '+')
6792 {
6793 if (image_info->extract != (char *) NULL)
6794 image_info->extract=DestroyString(image_info->extract);
6795 break;
6796 }
6797 (void) CloneString(&image_info->extract,argv[i+1]);
6798 break;
6799 }
6800 break;
6801 }
6802 case 'f':
6803 {
6804 if (LocaleCompare("fill",option+1) == 0)
6805 {
6806 if (*option == '+')
6807 {
6808 (void) SetImageOption(image_info,option+1,"none");
6809 break;
6810 }
6811 (void) SetImageOption(image_info,option+1,argv[i+1]);
6812 break;
6813 }
6814 if (LocaleCompare("filter",option+1) == 0)
6815 {
6816 if (*option == '+')
6817 {
6818 (void) SetImageOption(image_info,option+1,"undefined");
6819 break;
6820 }
6821 (void) SetImageOption(image_info,option+1,argv[i+1]);
6822 break;
6823 }
6824 if (LocaleCompare("font",option+1) == 0)
6825 {
6826 if (*option == '+')
6827 {
6828 if (image_info->font != (char *) NULL)
6829 image_info->font=DestroyString(image_info->font);
6830 break;
6831 }
6832 (void) CloneString(&image_info->font,argv[i+1]);
6833 break;
6834 }
6835 if (LocaleCompare("format",option+1) == 0)
6836 {
6837 register const char
6838 *q;
6839
6840 for (q=strchr(argv[i+1],'%'); q != (char *) NULL; q=strchr(q+1,'%'))
6841 if (strchr("gkrz@[#",*(q+1)) != (char *) NULL)
6842 image_info->ping=MagickFalse;
6843 (void) SetImageOption(image_info,option+1,argv[i+1]);
6844 break;
6845 }
6846 if (LocaleCompare("fuzz",option+1) == 0)
6847 {
6848 if (*option == '+')
6849 {
6850 image_info->fuzz=0.0;
6851 (void) SetImageOption(image_info,option+1,"0");
6852 break;
6853 }
cristyf2f27272009-12-17 14:48:46 +00006854 image_info->fuzz=SiPrefixToDouble(argv[i+1],(double) QuantumRange+
cristy3ed852e2009-09-05 21:47:34 +00006855 1.0);
6856 (void) SetImageOption(image_info,option+1,argv[i+1]);
6857 break;
6858 }
6859 break;
6860 }
6861 case 'g':
6862 {
6863 if (LocaleCompare("gravity",option+1) == 0)
6864 {
6865 if (*option == '+')
6866 {
6867 (void) SetImageOption(image_info,option+1,"undefined");
6868 break;
6869 }
6870 (void) SetImageOption(image_info,option+1,argv[i+1]);
6871 break;
6872 }
6873 if (LocaleCompare("green-primary",option+1) == 0)
6874 {
6875 if (*option == '+')
6876 {
6877 (void) SetImageOption(image_info,option+1,"0.0");
6878 break;
6879 }
6880 (void) SetImageOption(image_info,option+1,argv[i+1]);
6881 break;
6882 }
6883 break;
6884 }
6885 case 'i':
6886 {
6887 if (LocaleCompare("intent",option+1) == 0)
6888 {
6889 if (*option == '+')
6890 {
6891 (void) SetImageOption(image_info,option+1,"undefined");
6892 break;
6893 }
6894 (void) SetImageOption(image_info,option+1,argv[i+1]);
6895 break;
6896 }
6897 if (LocaleCompare("interlace",option+1) == 0)
6898 {
6899 if (*option == '+')
6900 {
6901 image_info->interlace=UndefinedInterlace;
6902 (void) SetImageOption(image_info,option+1,"undefined");
6903 break;
6904 }
6905 image_info->interlace=(InterlaceType) ParseMagickOption(
6906 MagickInterlaceOptions,MagickFalse,argv[i+1]);
6907 (void) SetImageOption(image_info,option+1,argv[i+1]);
6908 break;
6909 }
cristyb32b90a2009-09-07 21:45:48 +00006910 if (LocaleCompare("interline-spacing",option+1) == 0)
6911 {
6912 if (*option == '+')
6913 {
6914 (void) SetImageOption(image_info,option+1,"undefined");
6915 break;
6916 }
6917 (void) SetImageOption(image_info,option+1,argv[i+1]);
6918 break;
6919 }
cristy3ed852e2009-09-05 21:47:34 +00006920 if (LocaleCompare("interpolate",option+1) == 0)
6921 {
6922 if (*option == '+')
6923 {
6924 (void) SetImageOption(image_info,option+1,"undefined");
6925 break;
6926 }
6927 (void) SetImageOption(image_info,option+1,argv[i+1]);
6928 break;
6929 }
6930 if (LocaleCompare("interword-spacing",option+1) == 0)
6931 {
6932 if (*option == '+')
6933 {
6934 (void) SetImageOption(image_info,option+1,"undefined");
6935 break;
6936 }
6937 (void) SetImageOption(image_info,option+1,argv[i+1]);
6938 break;
6939 }
6940 break;
6941 }
6942 case 'k':
6943 {
6944 if (LocaleCompare("kerning",option+1) == 0)
6945 {
6946 if (*option == '+')
6947 {
6948 (void) SetImageOption(image_info,option+1,"undefined");
6949 break;
6950 }
6951 (void) SetImageOption(image_info,option+1,argv[i+1]);
6952 break;
6953 }
6954 break;
6955 }
6956 case 'l':
6957 {
6958 if (LocaleCompare("label",option+1) == 0)
6959 {
6960 if (*option == '+')
6961 {
6962 (void) DeleteImageOption(image_info,option+1);
6963 break;
6964 }
6965 (void) SetImageOption(image_info,option+1,argv[i+1]);
6966 break;
6967 }
6968 if (LocaleCompare("limit",option+1) == 0)
6969 {
6970 MagickSizeType
6971 limit;
6972
6973 ResourceType
6974 type;
6975
6976 if (*option == '+')
6977 break;
6978 type=(ResourceType) ParseMagickOption(MagickResourceOptions,
6979 MagickFalse,argv[i+1]);
6980 limit=MagickResourceInfinity;
6981 if (LocaleCompare("unlimited",argv[i+2]) != 0)
cristyf2f27272009-12-17 14:48:46 +00006982 limit=(MagickSizeType) SiPrefixToDouble(argv[i+2],100.0);
cristy3ed852e2009-09-05 21:47:34 +00006983 (void) SetMagickResourceLimit(type,limit);
6984 break;
6985 }
6986 if (LocaleCompare("list",option+1) == 0)
6987 {
cristybb503372010-05-27 20:51:26 +00006988 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006989 list;
6990
6991 /*
6992 Display configuration list.
6993 */
6994 list=ParseMagickOption(MagickListOptions,MagickFalse,argv[i+1]);
6995 switch (list)
6996 {
6997 case MagickCoderOptions:
6998 {
6999 (void) ListCoderInfo((FILE *) NULL,exception);
7000 break;
7001 }
7002 case MagickColorOptions:
7003 {
7004 (void) ListColorInfo((FILE *) NULL,exception);
7005 break;
7006 }
7007 case MagickConfigureOptions:
7008 {
7009 (void) ListConfigureInfo((FILE *) NULL,exception);
7010 break;
7011 }
7012 case MagickDelegateOptions:
7013 {
7014 (void) ListDelegateInfo((FILE *) NULL,exception);
7015 break;
7016 }
7017 case MagickFontOptions:
7018 {
7019 (void) ListTypeInfo((FILE *) NULL,exception);
7020 break;
7021 }
7022 case MagickFormatOptions:
7023 {
7024 (void) ListMagickInfo((FILE *) NULL,exception);
7025 break;
7026 }
7027 case MagickLocaleOptions:
7028 {
7029 (void) ListLocaleInfo((FILE *) NULL,exception);
7030 break;
7031 }
7032 case MagickLogOptions:
7033 {
7034 (void) ListLogInfo((FILE *) NULL,exception);
7035 break;
7036 }
7037 case MagickMagicOptions:
7038 {
7039 (void) ListMagicInfo((FILE *) NULL,exception);
7040 break;
7041 }
7042 case MagickMimeOptions:
7043 {
7044 (void) ListMimeInfo((FILE *) NULL,exception);
7045 break;
7046 }
7047 case MagickModuleOptions:
7048 {
7049 (void) ListModuleInfo((FILE *) NULL,exception);
7050 break;
7051 }
7052 case MagickPolicyOptions:
7053 {
7054 (void) ListPolicyInfo((FILE *) NULL,exception);
7055 break;
7056 }
7057 case MagickResourceOptions:
7058 {
7059 (void) ListMagickResourceInfo((FILE *) NULL,exception);
7060 break;
7061 }
7062 case MagickThresholdOptions:
7063 {
7064 (void) ListThresholdMaps((FILE *) NULL,exception);
7065 break;
7066 }
7067 default:
7068 {
7069 (void) ListMagickOptions((FILE *) NULL,(MagickOption) list,
7070 exception);
7071 break;
7072 }
7073 }
cristyaeb2cbc2010-05-07 13:28:58 +00007074 break;
cristy3ed852e2009-09-05 21:47:34 +00007075 }
7076 if (LocaleCompare("log",option+1) == 0)
7077 {
7078 if (*option == '+')
7079 break;
7080 (void) SetLogFormat(argv[i+1]);
7081 break;
7082 }
7083 if (LocaleCompare("loop",option+1) == 0)
7084 {
7085 if (*option == '+')
7086 {
7087 (void) SetImageOption(image_info,option+1,"0");
7088 break;
7089 }
7090 (void) SetImageOption(image_info,option+1,argv[i+1]);
7091 break;
7092 }
7093 break;
7094 }
7095 case 'm':
7096 {
7097 if (LocaleCompare("matte",option+1) == 0)
7098 {
7099 if (*option == '+')
7100 {
7101 (void) SetImageOption(image_info,option+1,"false");
7102 break;
7103 }
7104 (void) SetImageOption(image_info,option+1,"true");
7105 break;
7106 }
7107 if (LocaleCompare("mattecolor",option+1) == 0)
7108 {
7109 if (*option == '+')
7110 {
7111 (void) SetImageOption(image_info,option+1,argv[i+1]);
7112 (void) QueryColorDatabase(MatteColor,&image_info->matte_color,
7113 exception);
7114 break;
7115 }
7116 (void) SetImageOption(image_info,option+1,argv[i+1]);
7117 (void) QueryColorDatabase(argv[i+1],&image_info->matte_color,
7118 exception);
7119 break;
7120 }
7121 if (LocaleCompare("monitor",option+1) == 0)
7122 {
7123 (void) SetImageInfoProgressMonitor(image_info,MonitorProgress,
7124 (void *) NULL);
7125 break;
7126 }
7127 if (LocaleCompare("monochrome",option+1) == 0)
7128 {
7129 image_info->monochrome=(*option == '-') ? MagickTrue : MagickFalse;
7130 break;
7131 }
7132 break;
7133 }
7134 case 'o':
7135 {
7136 if (LocaleCompare("orient",option+1) == 0)
7137 {
7138 if (*option == '+')
7139 {
7140 image_info->orientation=UndefinedOrientation;
7141 (void) SetImageOption(image_info,option+1,"undefined");
7142 break;
7143 }
7144 image_info->orientation=(OrientationType) ParseMagickOption(
7145 MagickOrientationOptions,MagickFalse,argv[i+1]);
cristyc6e214d2010-08-08 00:31:08 +00007146 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007147 break;
7148 }
7149 }
7150 case 'p':
7151 {
7152 if (LocaleCompare("page",option+1) == 0)
7153 {
7154 char
7155 *canonical_page,
7156 page[MaxTextExtent];
7157
7158 const char
7159 *image_option;
7160
7161 MagickStatusType
7162 flags;
7163
7164 RectangleInfo
7165 geometry;
7166
7167 if (*option == '+')
7168 {
7169 (void) DeleteImageOption(image_info,option+1);
7170 (void) CloneString(&image_info->page,(char *) NULL);
7171 break;
7172 }
7173 (void) ResetMagickMemory(&geometry,0,sizeof(geometry));
7174 image_option=GetImageOption(image_info,"page");
7175 if (image_option != (const char *) NULL)
7176 flags=ParseAbsoluteGeometry(image_option,&geometry);
7177 canonical_page=GetPageGeometry(argv[i+1]);
7178 flags=ParseAbsoluteGeometry(canonical_page,&geometry);
7179 canonical_page=DestroyString(canonical_page);
7180 (void) FormatMagickString(page,MaxTextExtent,"%lux%lu",
cristyf2faecf2010-05-28 19:19:36 +00007181 (unsigned long) geometry.width,(unsigned long) geometry.height);
cristy3ed852e2009-09-05 21:47:34 +00007182 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
7183 (void) FormatMagickString(page,MaxTextExtent,"%lux%lu%+ld%+ld",
cristyf2faecf2010-05-28 19:19:36 +00007184 (unsigned long) geometry.width,(unsigned long) geometry.height,
7185 (long) geometry.x,(long) geometry.y);
cristy3ed852e2009-09-05 21:47:34 +00007186 (void) SetImageOption(image_info,option+1,page);
7187 (void) CloneString(&image_info->page,page);
7188 break;
7189 }
7190 if (LocaleCompare("pen",option+1) == 0)
7191 {
7192 if (*option == '+')
7193 {
7194 (void) SetImageOption(image_info,option+1,"none");
7195 break;
7196 }
7197 (void) SetImageOption(image_info,option+1,argv[i+1]);
7198 break;
7199 }
7200 if (LocaleCompare("ping",option+1) == 0)
7201 {
7202 image_info->ping=(*option == '-') ? MagickTrue : MagickFalse;
7203 break;
7204 }
7205 if (LocaleCompare("pointsize",option+1) == 0)
7206 {
7207 if (*option == '+')
7208 geometry_info.rho=0.0;
7209 else
7210 (void) ParseGeometry(argv[i+1],&geometry_info);
7211 image_info->pointsize=geometry_info.rho;
7212 break;
7213 }
cristye7f51092010-01-17 00:39:37 +00007214 if (LocaleCompare("precision",option+1) == 0)
7215 {
cristybf2766a2010-01-17 03:33:23 +00007216 (void) SetMagickPrecision(StringToInteger(argv[i+1]));
cristye7f51092010-01-17 00:39:37 +00007217 break;
7218 }
cristy3ed852e2009-09-05 21:47:34 +00007219 if (LocaleCompare("preview",option+1) == 0)
7220 {
7221 /*
7222 Preview image.
7223 */
7224 if (*option == '+')
7225 {
7226 image_info->preview_type=UndefinedPreview;
7227 break;
7228 }
7229 image_info->preview_type=(PreviewType) ParseMagickOption(
7230 MagickPreviewOptions,MagickFalse,argv[i+1]);
7231 break;
7232 }
7233 break;
7234 }
7235 case 'q':
7236 {
7237 if (LocaleCompare("quality",option+1) == 0)
7238 {
7239 /*
7240 Set image compression quality.
7241 */
7242 if (*option == '+')
7243 {
7244 image_info->quality=UndefinedCompressionQuality;
7245 (void) SetImageOption(image_info,option+1,"0");
7246 break;
7247 }
cristye27293e2009-12-18 02:53:20 +00007248 image_info->quality=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007249 (void) SetImageOption(image_info,option+1,argv[i+1]);
7250 break;
7251 }
7252 if (LocaleCompare("quiet",option+1) == 0)
7253 {
7254 static WarningHandler
7255 warning_handler = (WarningHandler) NULL;
7256
7257 if (*option == '+')
7258 {
7259 /*
7260 Restore error or warning messages.
7261 */
7262 warning_handler=SetWarningHandler(warning_handler);
7263 break;
7264 }
7265 /*
7266 Suppress error or warning messages.
7267 */
7268 warning_handler=SetWarningHandler((WarningHandler) NULL);
7269 break;
7270 }
7271 break;
7272 }
7273 case 'r':
7274 {
7275 if (LocaleCompare("red-primary",option+1) == 0)
7276 {
7277 if (*option == '+')
7278 {
7279 (void) SetImageOption(image_info,option+1,"0.0");
7280 break;
7281 }
7282 (void) SetImageOption(image_info,option+1,argv[i+1]);
7283 break;
7284 }
7285 break;
7286 }
7287 case 's':
7288 {
7289 if (LocaleCompare("sampling-factor",option+1) == 0)
7290 {
7291 /*
7292 Set image sampling factor.
7293 */
7294 if (*option == '+')
7295 {
7296 if (image_info->sampling_factor != (char *) NULL)
7297 image_info->sampling_factor=DestroyString(
7298 image_info->sampling_factor);
7299 break;
7300 }
7301 (void) CloneString(&image_info->sampling_factor,argv[i+1]);
7302 break;
7303 }
7304 if (LocaleCompare("scene",option+1) == 0)
7305 {
7306 /*
7307 Set image scene.
7308 */
7309 if (*option == '+')
7310 {
7311 image_info->scene=0;
7312 (void) SetImageOption(image_info,option+1,"0");
7313 break;
7314 }
cristye27293e2009-12-18 02:53:20 +00007315 image_info->scene=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007316 (void) SetImageOption(image_info,option+1,argv[i+1]);
7317 break;
7318 }
7319 if (LocaleCompare("seed",option+1) == 0)
7320 {
cristybb503372010-05-27 20:51:26 +00007321 size_t
cristy3ed852e2009-09-05 21:47:34 +00007322 seed;
7323
7324 if (*option == '+')
7325 {
cristybb503372010-05-27 20:51:26 +00007326 seed=(size_t) time((time_t *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00007327 SeedPseudoRandomGenerator(seed);
7328 break;
7329 }
cristye27293e2009-12-18 02:53:20 +00007330 seed=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007331 SeedPseudoRandomGenerator(seed);
7332 break;
7333 }
7334 if (LocaleCompare("size",option+1) == 0)
7335 {
7336 if (*option == '+')
7337 {
7338 if (image_info->size != (char *) NULL)
7339 image_info->size=DestroyString(image_info->size);
7340 break;
7341 }
7342 (void) CloneString(&image_info->size,argv[i+1]);
7343 break;
7344 }
7345 if (LocaleCompare("stroke",option+1) == 0)
7346 {
7347 if (*option == '+')
7348 {
7349 (void) SetImageOption(image_info,option+1,"none");
7350 break;
7351 }
7352 (void) SetImageOption(image_info,option+1,argv[i+1]);
7353 break;
7354 }
7355 if (LocaleCompare("strokewidth",option+1) == 0)
7356 {
7357 if (*option == '+')
7358 {
7359 (void) SetImageOption(image_info,option+1,"0");
7360 break;
7361 }
7362 (void) SetImageOption(image_info,option+1,argv[i+1]);
7363 break;
7364 }
cristyd9a29192010-10-16 16:49:53 +00007365 if (LocaleCompare("synchronize",option+1) == 0)
7366 {
7367 if (*option == '+')
7368 {
7369 image_info->synchronize=MagickFalse;
7370 break;
7371 }
7372 image_info->synchronize=MagickTrue;
7373 break;
7374 }
cristy3ed852e2009-09-05 21:47:34 +00007375 break;
7376 }
7377 case 't':
7378 {
7379 if (LocaleCompare("taint",option+1) == 0)
7380 {
7381 if (*option == '+')
7382 {
7383 (void) SetImageOption(image_info,option+1,"false");
7384 break;
7385 }
7386 (void) SetImageOption(image_info,option+1,"true");
7387 break;
7388 }
7389 if (LocaleCompare("texture",option+1) == 0)
7390 {
7391 if (*option == '+')
7392 {
7393 if (image_info->texture != (char *) NULL)
7394 image_info->texture=DestroyString(image_info->texture);
7395 break;
7396 }
7397 (void) CloneString(&image_info->texture,argv[i+1]);
7398 break;
7399 }
7400 if (LocaleCompare("tile-offset",option+1) == 0)
7401 {
7402 if (*option == '+')
7403 {
7404 (void) SetImageOption(image_info,option+1,"0");
7405 break;
7406 }
7407 (void) SetImageOption(image_info,option+1,argv[i+1]);
7408 break;
7409 }
7410 if (LocaleCompare("transparent-color",option+1) == 0)
7411 {
7412 if (*option == '+')
7413 {
7414 (void) QueryColorDatabase("none",&image_info->transparent_color, exception);
7415 (void) SetImageOption(image_info,option+1,"none");
7416 break;
7417 }
7418 (void) QueryColorDatabase(argv[i+1],&image_info->transparent_color,
7419 exception);
7420 (void) SetImageOption(image_info,option+1,argv[i+1]);
7421 break;
7422 }
7423 if (LocaleCompare("type",option+1) == 0)
7424 {
7425 if (*option == '+')
7426 {
cristy5f1c1ff2010-12-23 21:38:06 +00007427 image_info->type=UndefinedType;
cristy3ed852e2009-09-05 21:47:34 +00007428 (void) SetImageOption(image_info,option+1,"undefined");
7429 break;
7430 }
7431 image_info->type=(ImageType) ParseMagickOption(MagickTypeOptions,
7432 MagickFalse,argv[i+1]);
7433 (void) SetImageOption(image_info,option+1,argv[i+1]);
7434 break;
7435 }
7436 break;
7437 }
7438 case 'u':
7439 {
7440 if (LocaleCompare("undercolor",option+1) == 0)
7441 {
7442 if (*option == '+')
7443 {
7444 (void) DeleteImageOption(image_info,option+1);
7445 break;
7446 }
7447 (void) SetImageOption(image_info,option+1,argv[i+1]);
7448 break;
7449 }
7450 if (LocaleCompare("units",option+1) == 0)
7451 {
7452 if (*option == '+')
7453 {
7454 image_info->units=UndefinedResolution;
7455 (void) SetImageOption(image_info,option+1,"undefined");
7456 break;
7457 }
7458 image_info->units=(ResolutionType) ParseMagickOption(
7459 MagickResolutionOptions,MagickFalse,argv[i+1]);
7460 (void) SetImageOption(image_info,option+1,argv[i+1]);
7461 break;
7462 }
7463 break;
7464 }
7465 case 'v':
7466 {
7467 if (LocaleCompare("verbose",option+1) == 0)
7468 {
7469 if (*option == '+')
7470 {
7471 image_info->verbose=MagickFalse;
7472 break;
7473 }
7474 image_info->verbose=MagickTrue;
7475 image_info->ping=MagickFalse;
7476 break;
7477 }
7478 if (LocaleCompare("view",option+1) == 0)
7479 {
7480 if (*option == '+')
7481 {
7482 if (image_info->view != (char *) NULL)
7483 image_info->view=DestroyString(image_info->view);
7484 break;
7485 }
7486 (void) CloneString(&image_info->view,argv[i+1]);
7487 break;
7488 }
7489 if (LocaleCompare("virtual-pixel",option+1) == 0)
7490 {
7491 if (*option == '+')
7492 {
7493 image_info->virtual_pixel_method=UndefinedVirtualPixelMethod;
7494 (void) SetImageOption(image_info,option+1,"undefined");
7495 break;
7496 }
7497 image_info->virtual_pixel_method=(VirtualPixelMethod)
7498 ParseMagickOption(MagickVirtualPixelOptions,MagickFalse,
7499 argv[i+1]);
7500 (void) SetImageOption(image_info,option+1,argv[i+1]);
7501 break;
7502 }
7503 break;
7504 }
7505 case 'w':
7506 {
7507 if (LocaleCompare("white-point",option+1) == 0)
7508 {
7509 if (*option == '+')
7510 {
7511 (void) SetImageOption(image_info,option+1,"0.0");
7512 break;
7513 }
7514 (void) SetImageOption(image_info,option+1,argv[i+1]);
7515 break;
7516 }
7517 break;
7518 }
7519 default:
7520 break;
7521 }
7522 i+=count;
7523 }
7524 return(MagickTrue);
7525}
7526
7527/*
7528%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7529% %
7530% %
7531% %
7532+ M o g r i f y I m a g e L i s t %
7533% %
7534% %
7535% %
7536%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7537%
7538% MogrifyImageList() applies any command line options that might affect the
7539% entire image list (e.g. -append, -coalesce, etc.).
7540%
7541% The format of the MogrifyImage method is:
7542%
7543% MagickBooleanType MogrifyImageList(ImageInfo *image_info,const int argc,
7544% const char **argv,Image **images,ExceptionInfo *exception)
7545%
7546% A description of each parameter follows:
7547%
7548% o image_info: the image info..
7549%
7550% o argc: Specifies a pointer to an integer describing the number of
7551% elements in the argument vector.
7552%
7553% o argv: Specifies a pointer to a text array containing the command line
7554% arguments.
7555%
7556% o images: the images.
7557%
7558% o exception: return any errors or warnings in this structure.
7559%
7560*/
7561WandExport MagickBooleanType MogrifyImageList(ImageInfo *image_info,
7562 const int argc,const char **argv,Image **images,ExceptionInfo *exception)
7563{
7564 ChannelType
7565 channel;
7566
7567 const char
7568 *option;
7569
cristy6b3da3a2010-06-20 02:21:46 +00007570 ImageInfo
7571 *mogrify_info;
cristy3ed852e2009-09-05 21:47:34 +00007572
7573 MagickStatusType
7574 status;
7575
7576 QuantizeInfo
7577 *quantize_info;
7578
cristybb503372010-05-27 20:51:26 +00007579 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00007580 i;
7581
cristy6b3da3a2010-06-20 02:21:46 +00007582 ssize_t
7583 count,
7584 index;
7585
cristy3ed852e2009-09-05 21:47:34 +00007586 /*
7587 Apply options to the image list.
7588 */
7589 assert(image_info != (ImageInfo *) NULL);
7590 assert(image_info->signature == MagickSignature);
7591 assert(images != (Image **) NULL);
7592 assert((*images)->signature == MagickSignature);
7593 if ((*images)->debug != MagickFalse)
7594 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
7595 (*images)->filename);
7596 if ((argc <= 0) || (*argv == (char *) NULL))
7597 return(MagickTrue);
cristy6b3da3a2010-06-20 02:21:46 +00007598 mogrify_info=CloneImageInfo(image_info);
7599 quantize_info=AcquireQuantizeInfo(mogrify_info);
7600 channel=mogrify_info->channel;
cristy3ed852e2009-09-05 21:47:34 +00007601 status=MagickTrue;
cristybb503372010-05-27 20:51:26 +00007602 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00007603 {
cristy74fe8f12009-10-03 19:09:01 +00007604 if (*images == (Image *) NULL)
7605 break;
cristy3ed852e2009-09-05 21:47:34 +00007606 option=argv[i];
7607 if (IsMagickOption(option) == MagickFalse)
7608 continue;
7609 count=MagickMax(ParseMagickOption(MagickCommandOptions,MagickFalse,option),
7610 0L);
cristycee97112010-05-28 00:44:52 +00007611 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00007612 break;
cristy6b3da3a2010-06-20 02:21:46 +00007613 status=MogrifyImageInfo(mogrify_info,(int) count+1,argv+i,exception);
cristy3ed852e2009-09-05 21:47:34 +00007614 switch (*(option+1))
7615 {
7616 case 'a':
7617 {
7618 if (LocaleCompare("affinity",option+1) == 0)
7619 {
cristy6b3da3a2010-06-20 02:21:46 +00007620 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007621 if (*option == '+')
7622 {
7623 (void) RemapImages(quantize_info,*images,(Image *) NULL);
7624 InheritException(exception,&(*images)->exception);
7625 break;
7626 }
7627 i++;
7628 break;
7629 }
7630 if (LocaleCompare("append",option+1) == 0)
7631 {
7632 Image
7633 *append_image;
7634
cristy6b3da3a2010-06-20 02:21:46 +00007635 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007636 append_image=AppendImages(*images,*option == '-' ? MagickTrue :
7637 MagickFalse,exception);
7638 if (append_image == (Image *) NULL)
7639 {
7640 status=MagickFalse;
7641 break;
7642 }
7643 *images=DestroyImageList(*images);
7644 *images=append_image;
7645 break;
7646 }
7647 if (LocaleCompare("average",option+1) == 0)
7648 {
7649 Image
7650 *average_image;
7651
cristyd18ae7c2010-03-07 17:39:52 +00007652 /*
7653 Average an image sequence (deprecated).
7654 */
cristy6b3da3a2010-06-20 02:21:46 +00007655 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007656 average_image=EvaluateImages(*images,MeanEvaluateOperator,
7657 exception);
cristy3ed852e2009-09-05 21:47:34 +00007658 if (average_image == (Image *) NULL)
7659 {
7660 status=MagickFalse;
7661 break;
7662 }
7663 *images=DestroyImageList(*images);
7664 *images=average_image;
7665 break;
7666 }
7667 break;
7668 }
7669 case 'c':
7670 {
7671 if (LocaleCompare("channel",option+1) == 0)
7672 {
7673 if (*option == '+')
7674 {
7675 channel=DefaultChannels;
7676 break;
7677 }
7678 channel=(ChannelType) ParseChannelOption(argv[i+1]);
7679 break;
7680 }
7681 if (LocaleCompare("clut",option+1) == 0)
7682 {
7683 Image
7684 *clut_image,
7685 *image;
7686
cristy6b3da3a2010-06-20 02:21:46 +00007687 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007688 image=RemoveFirstImageFromList(images);
7689 clut_image=RemoveFirstImageFromList(images);
7690 if (clut_image == (Image *) NULL)
7691 {
7692 status=MagickFalse;
7693 break;
7694 }
7695 (void) ClutImageChannel(image,channel,clut_image);
7696 clut_image=DestroyImage(clut_image);
7697 InheritException(exception,&image->exception);
7698 *images=DestroyImageList(*images);
7699 *images=image;
7700 break;
7701 }
7702 if (LocaleCompare("coalesce",option+1) == 0)
7703 {
7704 Image
7705 *coalesce_image;
7706
cristy6b3da3a2010-06-20 02:21:46 +00007707 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007708 coalesce_image=CoalesceImages(*images,exception);
7709 if (coalesce_image == (Image *) NULL)
7710 {
7711 status=MagickFalse;
7712 break;
7713 }
7714 *images=DestroyImageList(*images);
7715 *images=coalesce_image;
7716 break;
7717 }
7718 if (LocaleCompare("combine",option+1) == 0)
7719 {
7720 Image
7721 *combine_image;
7722
cristy6b3da3a2010-06-20 02:21:46 +00007723 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007724 combine_image=CombineImages(*images,channel,exception);
7725 if (combine_image == (Image *) NULL)
7726 {
7727 status=MagickFalse;
7728 break;
7729 }
7730 *images=DestroyImageList(*images);
7731 *images=combine_image;
7732 break;
7733 }
7734 if (LocaleCompare("composite",option+1) == 0)
7735 {
7736 Image
7737 *mask_image,
7738 *composite_image,
7739 *image;
7740
7741 RectangleInfo
7742 geometry;
7743
cristy6b3da3a2010-06-20 02:21:46 +00007744 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007745 image=RemoveFirstImageFromList(images);
7746 composite_image=RemoveFirstImageFromList(images);
7747 if (composite_image == (Image *) NULL)
7748 {
7749 status=MagickFalse;
7750 break;
7751 }
7752 (void) TransformImage(&composite_image,(char *) NULL,
7753 composite_image->geometry);
7754 SetGeometry(composite_image,&geometry);
7755 (void) ParseAbsoluteGeometry(composite_image->geometry,&geometry);
7756 GravityAdjustGeometry(image->columns,image->rows,image->gravity,
7757 &geometry);
7758 mask_image=RemoveFirstImageFromList(images);
7759 if (mask_image != (Image *) NULL)
7760 {
7761 if ((image->compose == DisplaceCompositeOp) ||
7762 (image->compose == DistortCompositeOp))
7763 {
7764 /*
7765 Merge Y displacement into X displacement image.
7766 */
7767 (void) CompositeImage(composite_image,CopyGreenCompositeOp,
7768 mask_image,0,0);
7769 mask_image=DestroyImage(mask_image);
7770 }
7771 else
7772 {
7773 /*
7774 Set a blending mask for the composition.
7775 */
7776 image->mask=mask_image;
7777 (void) NegateImage(image->mask,MagickFalse);
7778 }
7779 }
7780 (void) CompositeImageChannel(image,channel,image->compose,
7781 composite_image,geometry.x,geometry.y);
7782 if (image->mask != (Image *) NULL)
7783 image->mask=DestroyImage(image->mask);
7784 composite_image=DestroyImage(composite_image);
7785 InheritException(exception,&image->exception);
7786 *images=DestroyImageList(*images);
7787 *images=image;
7788 break;
7789 }
7790 if (LocaleCompare("crop",option+1) == 0)
7791 {
7792 MagickStatusType
7793 flags;
7794
7795 RectangleInfo
7796 geometry;
7797
cristy6b3da3a2010-06-20 02:21:46 +00007798 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007799 flags=ParseGravityGeometry(*images,argv[i+1],&geometry,exception);
7800 if (((geometry.width == 0) && (geometry.height == 0)) ||
7801 ((flags & XValue) != 0) || ((flags & YValue) != 0))
7802 break;
7803 (void) TransformImages(images,argv[i+1],(char *) NULL);
7804 InheritException(exception,&(*images)->exception);
7805 break;
7806 }
7807 break;
7808 }
7809 case 'd':
7810 {
7811 if (LocaleCompare("deconstruct",option+1) == 0)
7812 {
7813 Image
7814 *deconstruct_image;
7815
cristy6b3da3a2010-06-20 02:21:46 +00007816 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007817 deconstruct_image=DeconstructImages(*images,exception);
7818 if (deconstruct_image == (Image *) NULL)
7819 {
7820 status=MagickFalse;
7821 break;
7822 }
7823 *images=DestroyImageList(*images);
7824 *images=deconstruct_image;
7825 break;
7826 }
7827 if (LocaleCompare("delete",option+1) == 0)
7828 {
7829 if (*option == '+')
7830 DeleteImages(images,"-1",exception);
7831 else
7832 DeleteImages(images,argv[i+1],exception);
7833 break;
7834 }
7835 if (LocaleCompare("dither",option+1) == 0)
7836 {
7837 if (*option == '+')
7838 {
7839 quantize_info->dither=MagickFalse;
7840 break;
7841 }
7842 quantize_info->dither=MagickTrue;
7843 quantize_info->dither_method=(DitherMethod) ParseMagickOption(
7844 MagickDitherOptions,MagickFalse,argv[i+1]);
7845 break;
7846 }
7847 break;
7848 }
cristyd18ae7c2010-03-07 17:39:52 +00007849 case 'e':
7850 {
7851 if (LocaleCompare("evaluate-sequence",option+1) == 0)
7852 {
7853 Image
7854 *evaluate_image;
7855
7856 MagickEvaluateOperator
7857 op;
7858
cristy6b3da3a2010-06-20 02:21:46 +00007859 (void) SyncImageSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007860 op=(MagickEvaluateOperator) ParseMagickOption(MagickEvaluateOptions,
7861 MagickFalse,argv[i+1]);
7862 evaluate_image=EvaluateImages(*images,op,exception);
7863 if (evaluate_image == (Image *) NULL)
7864 {
7865 status=MagickFalse;
7866 break;
7867 }
7868 *images=DestroyImageList(*images);
7869 *images=evaluate_image;
7870 break;
7871 }
7872 break;
7873 }
cristy3ed852e2009-09-05 21:47:34 +00007874 case 'f':
7875 {
cristyf0a247f2009-10-04 00:20:03 +00007876 if (LocaleCompare("fft",option+1) == 0)
7877 {
7878 Image
7879 *fourier_image;
7880
7881 /*
7882 Implements the discrete Fourier transform (DFT).
7883 */
cristy6b3da3a2010-06-20 02:21:46 +00007884 (void) SyncImageSettings(mogrify_info,*images);
cristyf0a247f2009-10-04 00:20:03 +00007885 fourier_image=ForwardFourierTransformImage(*images,*option == '-' ?
7886 MagickTrue : MagickFalse,exception);
7887 if (fourier_image == (Image *) NULL)
7888 break;
7889 *images=DestroyImage(*images);
7890 *images=fourier_image;
7891 break;
7892 }
cristy3ed852e2009-09-05 21:47:34 +00007893 if (LocaleCompare("flatten",option+1) == 0)
7894 {
7895 Image
7896 *flatten_image;
7897
cristy6b3da3a2010-06-20 02:21:46 +00007898 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007899 flatten_image=MergeImageLayers(*images,FlattenLayer,exception);
7900 if (flatten_image == (Image *) NULL)
7901 break;
7902 *images=DestroyImageList(*images);
7903 *images=flatten_image;
7904 break;
7905 }
7906 if (LocaleCompare("fx",option+1) == 0)
7907 {
7908 Image
7909 *fx_image;
7910
cristy6b3da3a2010-06-20 02:21:46 +00007911 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007912 fx_image=FxImageChannel(*images,channel,argv[i+1],exception);
7913 if (fx_image == (Image *) NULL)
7914 {
7915 status=MagickFalse;
7916 break;
7917 }
7918 *images=DestroyImageList(*images);
7919 *images=fx_image;
7920 break;
7921 }
7922 break;
7923 }
7924 case 'h':
7925 {
7926 if (LocaleCompare("hald-clut",option+1) == 0)
7927 {
7928 Image
7929 *hald_image,
7930 *image;
7931
cristy6b3da3a2010-06-20 02:21:46 +00007932 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007933 image=RemoveFirstImageFromList(images);
7934 hald_image=RemoveFirstImageFromList(images);
7935 if (hald_image == (Image *) NULL)
7936 {
7937 status=MagickFalse;
7938 break;
7939 }
7940 (void) HaldClutImageChannel(image,channel,hald_image);
7941 hald_image=DestroyImage(hald_image);
7942 InheritException(exception,&image->exception);
cristy0aff6ea2009-11-14 01:40:53 +00007943 if (*images != (Image *) NULL)
7944 *images=DestroyImageList(*images);
cristy3ed852e2009-09-05 21:47:34 +00007945 *images=image;
7946 break;
7947 }
7948 break;
7949 }
7950 case 'i':
7951 {
7952 if (LocaleCompare("ift",option+1) == 0)
7953 {
7954 Image
cristy8587f882009-11-13 20:28:49 +00007955 *fourier_image,
7956 *magnitude_image,
7957 *phase_image;
cristy3ed852e2009-09-05 21:47:34 +00007958
7959 /*
7960 Implements the inverse fourier discrete Fourier transform (DFT).
7961 */
cristy6b3da3a2010-06-20 02:21:46 +00007962 (void) SyncImagesSettings(mogrify_info,*images);
cristy8587f882009-11-13 20:28:49 +00007963 magnitude_image=RemoveFirstImageFromList(images);
7964 phase_image=RemoveFirstImageFromList(images);
7965 if (phase_image == (Image *) NULL)
7966 {
7967 status=MagickFalse;
7968 break;
7969 }
7970 fourier_image=InverseFourierTransformImage(magnitude_image,
7971 phase_image,*option == '-' ? MagickTrue : MagickFalse,exception);
cristy3ed852e2009-09-05 21:47:34 +00007972 if (fourier_image == (Image *) NULL)
7973 break;
cristy0aff6ea2009-11-14 01:40:53 +00007974 if (*images != (Image *) NULL)
7975 *images=DestroyImage(*images);
cristy3ed852e2009-09-05 21:47:34 +00007976 *images=fourier_image;
7977 break;
7978 }
7979 if (LocaleCompare("insert",option+1) == 0)
7980 {
7981 Image
7982 *p,
7983 *q;
7984
7985 index=0;
7986 if (*option != '+')
cristy32c2aea2010-12-01 01:00:50 +00007987 index=(ssize_t) StringToLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007988 p=RemoveLastImageFromList(images);
7989 if (p == (Image *) NULL)
7990 {
7991 (void) ThrowMagickException(exception,GetMagickModule(),
7992 OptionError,"NoSuchImage","`%s'",argv[i+1]);
7993 status=MagickFalse;
7994 break;
7995 }
7996 q=p;
7997 if (index == 0)
7998 PrependImageToList(images,q);
7999 else
cristybb503372010-05-27 20:51:26 +00008000 if (index == (ssize_t) GetImageListLength(*images))
cristy3ed852e2009-09-05 21:47:34 +00008001 AppendImageToList(images,q);
8002 else
8003 {
8004 q=GetImageFromList(*images,index-1);
8005 if (q == (Image *) NULL)
8006 {
8007 (void) ThrowMagickException(exception,GetMagickModule(),
8008 OptionError,"NoSuchImage","`%s'",argv[i+1]);
8009 status=MagickFalse;
8010 break;
8011 }
8012 InsertImageInList(&q,p);
8013 }
8014 *images=GetFirstImageInList(q);
8015 break;
8016 }
8017 break;
8018 }
8019 case 'l':
8020 {
8021 if (LocaleCompare("layers",option+1) == 0)
8022 {
8023 Image
8024 *layers;
8025
8026 ImageLayerMethod
8027 method;
8028
cristy6b3da3a2010-06-20 02:21:46 +00008029 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00008030 layers=(Image *) NULL;
8031 method=(ImageLayerMethod) ParseMagickOption(MagickLayerOptions,
8032 MagickFalse,argv[i+1]);
8033 switch (method)
8034 {
8035 case CoalesceLayer:
8036 {
8037 layers=CoalesceImages(*images,exception);
8038 break;
8039 }
8040 case CompareAnyLayer:
8041 case CompareClearLayer:
8042 case CompareOverlayLayer:
8043 default:
8044 {
8045 layers=CompareImageLayers(*images,method,exception);
8046 break;
8047 }
8048 case MergeLayer:
8049 case FlattenLayer:
8050 case MosaicLayer:
8051 case TrimBoundsLayer:
8052 {
8053 layers=MergeImageLayers(*images,method,exception);
8054 break;
8055 }
8056 case DisposeLayer:
8057 {
8058 layers=DisposeImages(*images,exception);
8059 break;
8060 }
8061 case OptimizeImageLayer:
8062 {
8063 layers=OptimizeImageLayers(*images,exception);
8064 break;
8065 }
8066 case OptimizePlusLayer:
8067 {
8068 layers=OptimizePlusImageLayers(*images,exception);
8069 break;
8070 }
8071 case OptimizeTransLayer:
8072 {
8073 OptimizeImageTransparency(*images,exception);
8074 break;
8075 }
8076 case RemoveDupsLayer:
8077 {
8078 RemoveDuplicateLayers(images,exception);
8079 break;
8080 }
8081 case RemoveZeroLayer:
8082 {
8083 RemoveZeroDelayLayers(images,exception);
8084 break;
8085 }
8086 case OptimizeLayer:
8087 {
8088 /*
8089 General Purpose, GIF Animation Optimizer.
8090 */
8091 layers=CoalesceImages(*images,exception);
8092 if (layers == (Image *) NULL)
8093 {
8094 status=MagickFalse;
8095 break;
8096 }
8097 InheritException(exception,&layers->exception);
8098 *images=DestroyImageList(*images);
8099 *images=layers;
8100 layers=OptimizeImageLayers(*images,exception);
8101 if (layers == (Image *) NULL)
8102 {
8103 status=MagickFalse;
8104 break;
8105 }
8106 InheritException(exception,&layers->exception);
8107 *images=DestroyImageList(*images);
8108 *images=layers;
8109 layers=(Image *) NULL;
8110 OptimizeImageTransparency(*images,exception);
8111 InheritException(exception,&(*images)->exception);
8112 (void) RemapImages(quantize_info,*images,(Image *) NULL);
8113 break;
8114 }
8115 case CompositeLayer:
8116 {
8117 CompositeOperator
8118 compose;
8119
8120 Image
8121 *source;
8122
8123 RectangleInfo
8124 geometry;
8125
8126 /*
8127 Split image sequence at the first 'NULL:' image.
8128 */
8129 source=(*images);
8130 while (source != (Image *) NULL)
8131 {
8132 source=GetNextImageInList(source);
8133 if ((source != (Image *) NULL) &&
8134 (LocaleCompare(source->magick,"NULL") == 0))
8135 break;
8136 }
8137 if (source != (Image *) NULL)
8138 {
8139 if ((GetPreviousImageInList(source) == (Image *) NULL) ||
8140 (GetNextImageInList(source) == (Image *) NULL))
8141 source=(Image *) NULL;
8142 else
8143 {
8144 /*
8145 Separate the two lists, junk the null: image.
8146 */
8147 source=SplitImageList(source->previous);
8148 DeleteImageFromList(&source);
8149 }
8150 }
8151 if (source == (Image *) NULL)
8152 {
8153 (void) ThrowMagickException(exception,GetMagickModule(),
8154 OptionError,"MissingNullSeparator","layers Composite");
8155 status=MagickFalse;
8156 break;
8157 }
8158 /*
8159 Adjust offset with gravity and virtual canvas.
8160 */
8161 SetGeometry(*images,&geometry);
8162 (void) ParseAbsoluteGeometry((*images)->geometry,&geometry);
8163 geometry.width=source->page.width != 0 ?
8164 source->page.width : source->columns;
8165 geometry.height=source->page.height != 0 ?
8166 source->page.height : source->rows;
8167 GravityAdjustGeometry((*images)->page.width != 0 ?
8168 (*images)->page.width : (*images)->columns,
8169 (*images)->page.height != 0 ? (*images)->page.height :
8170 (*images)->rows,(*images)->gravity,&geometry);
8171 compose=OverCompositeOp;
cristy6b3da3a2010-06-20 02:21:46 +00008172 option=GetImageOption(mogrify_info,"compose");
cristy3ed852e2009-09-05 21:47:34 +00008173 if (option != (const char *) NULL)
8174 compose=(CompositeOperator) ParseMagickOption(
8175 MagickComposeOptions,MagickFalse,option);
8176 CompositeLayers(*images,compose,source,geometry.x,geometry.y,
8177 exception);
8178 source=DestroyImageList(source);
8179 break;
8180 }
8181 }
8182 if (layers == (Image *) NULL)
8183 break;
8184 InheritException(exception,&layers->exception);
8185 *images=DestroyImageList(*images);
8186 *images=layers;
8187 break;
8188 }
8189 break;
8190 }
8191 case 'm':
8192 {
8193 if (LocaleCompare("map",option+1) == 0)
8194 {
cristy6b3da3a2010-06-20 02:21:46 +00008195 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00008196 if (*option == '+')
8197 {
8198 (void) RemapImages(quantize_info,*images,(Image *) NULL);
8199 InheritException(exception,&(*images)->exception);
8200 break;
8201 }
8202 i++;
8203 break;
8204 }
cristyf40785b2010-03-06 02:27:27 +00008205 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00008206 {
8207 Image
cristyf40785b2010-03-06 02:27:27 +00008208 *maximum_image;
cristy1c274c92010-03-06 02:06:45 +00008209
cristyd18ae7c2010-03-07 17:39:52 +00008210 /*
8211 Maximum image sequence (deprecated).
8212 */
cristy6b3da3a2010-06-20 02:21:46 +00008213 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00008214 maximum_image=EvaluateImages(*images,MaxEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00008215 if (maximum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00008216 {
8217 status=MagickFalse;
8218 break;
8219 }
8220 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00008221 *images=maximum_image;
cristy1c274c92010-03-06 02:06:45 +00008222 break;
8223 }
cristyf40785b2010-03-06 02:27:27 +00008224 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00008225 {
8226 Image
cristyf40785b2010-03-06 02:27:27 +00008227 *minimum_image;
cristy1c274c92010-03-06 02:06:45 +00008228
cristyd18ae7c2010-03-07 17:39:52 +00008229 /*
8230 Minimum image sequence (deprecated).
8231 */
cristy6b3da3a2010-06-20 02:21:46 +00008232 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00008233 minimum_image=EvaluateImages(*images,MinEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00008234 if (minimum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00008235 {
8236 status=MagickFalse;
8237 break;
8238 }
8239 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00008240 *images=minimum_image;
cristy1c274c92010-03-06 02:06:45 +00008241 break;
8242 }
cristy3ed852e2009-09-05 21:47:34 +00008243 if (LocaleCompare("morph",option+1) == 0)
8244 {
8245 Image
8246 *morph_image;
8247
cristy6b3da3a2010-06-20 02:21:46 +00008248 (void) SyncImagesSettings(mogrify_info,*images);
cristye27293e2009-12-18 02:53:20 +00008249 morph_image=MorphImages(*images,StringToUnsignedLong(argv[i+1]),
cristy3ed852e2009-09-05 21:47:34 +00008250 exception);
8251 if (morph_image == (Image *) NULL)
8252 {
8253 status=MagickFalse;
8254 break;
8255 }
8256 *images=DestroyImageList(*images);
8257 *images=morph_image;
8258 break;
8259 }
8260 if (LocaleCompare("mosaic",option+1) == 0)
8261 {
8262 Image
8263 *mosaic_image;
8264
cristy6b3da3a2010-06-20 02:21:46 +00008265 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00008266 mosaic_image=MergeImageLayers(*images,MosaicLayer,exception);
8267 if (mosaic_image == (Image *) NULL)
8268 {
8269 status=MagickFalse;
8270 break;
8271 }
8272 *images=DestroyImageList(*images);
8273 *images=mosaic_image;
8274 break;
8275 }
8276 break;
8277 }
8278 case 'p':
8279 {
8280 if (LocaleCompare("print",option+1) == 0)
8281 {
8282 char
8283 *string;
8284
cristy6b3da3a2010-06-20 02:21:46 +00008285 (void) SyncImagesSettings(mogrify_info,*images);
8286 string=InterpretImageProperties(mogrify_info,*images,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00008287 if (string == (char *) NULL)
8288 break;
8289 InheritException(exception,&(*images)->exception);
8290 (void) fprintf(stdout,"%s",string);
8291 string=DestroyString(string);
8292 }
8293 if (LocaleCompare("process",option+1) == 0)
8294 {
8295 char
8296 **arguments;
8297
8298 int
8299 j,
8300 number_arguments;
8301
cristy6b3da3a2010-06-20 02:21:46 +00008302 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00008303 arguments=StringToArgv(argv[i+1],&number_arguments);
8304 if (arguments == (char **) NULL)
8305 break;
8306 if ((argc > 1) && (strchr(arguments[1],'=') != (char *) NULL))
8307 {
8308 char
8309 breaker,
8310 quote,
8311 *token;
8312
8313 const char
8314 *arguments;
8315
8316 int
8317 next,
8318 status;
8319
8320 size_t
8321 length;
8322
8323 TokenInfo
8324 *token_info;
8325
8326 /*
8327 Support old style syntax, filter="-option arg".
8328 */
8329 length=strlen(argv[i+1]);
8330 token=(char *) NULL;
8331 if (~length >= MaxTextExtent)
8332 token=(char *) AcquireQuantumMemory(length+MaxTextExtent,
8333 sizeof(*token));
8334 if (token == (char *) NULL)
8335 break;
8336 next=0;
8337 arguments=argv[i+1];
8338 token_info=AcquireTokenInfo();
8339 status=Tokenizer(token_info,0,token,length,arguments,"","=",
8340 "\"",'\0',&breaker,&next,&quote);
8341 token_info=DestroyTokenInfo(token_info);
8342 if (status == 0)
8343 {
8344 const char
8345 *argv;
8346
8347 argv=(&(arguments[next]));
8348 (void) InvokeDynamicImageFilter(token,&(*images),1,&argv,
8349 exception);
8350 }
8351 token=DestroyString(token);
8352 break;
8353 }
cristy91c0da22010-05-02 01:44:07 +00008354 (void) SubstituteString(&arguments[1],"-","");
cristy3ed852e2009-09-05 21:47:34 +00008355 (void) InvokeDynamicImageFilter(arguments[1],&(*images),
8356 number_arguments-2,(const char **) arguments+2,exception);
8357 for (j=0; j < number_arguments; j++)
8358 arguments[j]=DestroyString(arguments[j]);
8359 arguments=(char **) RelinquishMagickMemory(arguments);
8360 break;
8361 }
8362 break;
8363 }
8364 case 'r':
8365 {
8366 if (LocaleCompare("reverse",option+1) == 0)
8367 {
8368 ReverseImageList(images);
8369 InheritException(exception,&(*images)->exception);
8370 break;
8371 }
8372 break;
8373 }
8374 case 's':
8375 {
cristy4285d782011-02-09 20:12:28 +00008376 if (LocaleCompare("smush",option+1) == 0)
8377 {
8378 Image
8379 *smush_image;
8380
8381 ssize_t
8382 offset;
8383
8384 (void) SyncImagesSettings(mogrify_info,*images);
8385 offset=(ssize_t) StringToLong(argv[i+1]);
8386 smush_image=SmushImages(*images,*option == '-' ? MagickTrue :
8387 MagickFalse,offset,exception);
8388 if (smush_image == (Image *) NULL)
8389 {
8390 status=MagickFalse;
8391 break;
8392 }
8393 *images=DestroyImageList(*images);
8394 *images=smush_image;
8395 break;
8396 }
cristy3ed852e2009-09-05 21:47:34 +00008397 if (LocaleCompare("swap",option+1) == 0)
8398 {
8399 Image
8400 *p,
8401 *q,
8402 *swap;
8403
cristybb503372010-05-27 20:51:26 +00008404 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00008405 swap_index;
8406
8407 index=(-1);
8408 swap_index=(-2);
8409 if (*option != '+')
8410 {
8411 GeometryInfo
8412 geometry_info;
8413
8414 MagickStatusType
8415 flags;
8416
8417 swap_index=(-1);
8418 flags=ParseGeometry(argv[i+1],&geometry_info);
cristybb503372010-05-27 20:51:26 +00008419 index=(ssize_t) geometry_info.rho;
cristy3ed852e2009-09-05 21:47:34 +00008420 if ((flags & SigmaValue) != 0)
cristybb503372010-05-27 20:51:26 +00008421 swap_index=(ssize_t) geometry_info.sigma;
cristy3ed852e2009-09-05 21:47:34 +00008422 }
8423 p=GetImageFromList(*images,index);
8424 q=GetImageFromList(*images,swap_index);
8425 if ((p == (Image *) NULL) || (q == (Image *) NULL))
8426 {
8427 (void) ThrowMagickException(exception,GetMagickModule(),
8428 OptionError,"NoSuchImage","`%s'",(*images)->filename);
8429 status=MagickFalse;
8430 break;
8431 }
8432 if (p == q)
8433 break;
8434 swap=CloneImage(p,0,0,MagickTrue,exception);
8435 ReplaceImageInList(&p,CloneImage(q,0,0,MagickTrue,exception));
8436 ReplaceImageInList(&q,swap);
8437 *images=GetFirstImageInList(q);
8438 break;
8439 }
8440 break;
8441 }
8442 case 'w':
8443 {
8444 if (LocaleCompare("write",option+1) == 0)
8445 {
cristy071dd7b2010-04-09 13:04:54 +00008446 char
cristy06609ee2010-03-17 20:21:27 +00008447 key[MaxTextExtent];
8448
cristy3ed852e2009-09-05 21:47:34 +00008449 Image
8450 *write_images;
8451
8452 ImageInfo
8453 *write_info;
8454
cristy6b3da3a2010-06-20 02:21:46 +00008455 (void) SyncImagesSettings(mogrify_info,*images);
cristy06609ee2010-03-17 20:21:27 +00008456 (void) FormatMagickString(key,MaxTextExtent,"cache:%s",argv[i+1]);
8457 (void) DeleteImageRegistry(key);
cristy3ed852e2009-09-05 21:47:34 +00008458 write_images=(*images);
8459 if (*option == '+')
8460 write_images=CloneImageList(*images,exception);
cristy6b3da3a2010-06-20 02:21:46 +00008461 write_info=CloneImageInfo(mogrify_info);
cristy3ed852e2009-09-05 21:47:34 +00008462 status&=WriteImages(write_info,write_images,argv[i+1],exception);
8463 write_info=DestroyImageInfo(write_info);
8464 if (*option == '+')
8465 write_images=DestroyImageList(write_images);
8466 break;
8467 }
8468 break;
8469 }
8470 default:
8471 break;
8472 }
8473 i+=count;
8474 }
8475 quantize_info=DestroyQuantizeInfo(quantize_info);
cristy6b3da3a2010-06-20 02:21:46 +00008476 mogrify_info=DestroyImageInfo(mogrify_info);
8477 status&=MogrifyImageInfo(image_info,argc,argv,exception);
cristy3ed852e2009-09-05 21:47:34 +00008478 return(status != 0 ? MagickTrue : MagickFalse);
8479}
8480
8481/*
8482%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8483% %
8484% %
8485% %
8486+ M o g r i f y I m a g e s %
8487% %
8488% %
8489% %
8490%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8491%
8492% MogrifyImages() applies image processing options to a sequence of images as
8493% prescribed by command line options.
8494%
8495% The format of the MogrifyImage method is:
8496%
8497% MagickBooleanType MogrifyImages(ImageInfo *image_info,
8498% const MagickBooleanType post,const int argc,const char **argv,
8499% Image **images,Exceptioninfo *exception)
8500%
8501% A description of each parameter follows:
8502%
8503% o image_info: the image info..
8504%
8505% o post: If true, post process image list operators otherwise pre-process.
8506%
8507% o argc: Specifies a pointer to an integer describing the number of
8508% elements in the argument vector.
8509%
8510% o argv: Specifies a pointer to a text array containing the command line
8511% arguments.
8512%
8513% o images: the images.
8514%
8515% o exception: return any errors or warnings in this structure.
8516%
8517*/
8518WandExport MagickBooleanType MogrifyImages(ImageInfo *image_info,
8519 const MagickBooleanType post,const int argc,const char **argv,
8520 Image **images,ExceptionInfo *exception)
8521{
8522#define MogrifyImageTag "Mogrify/Image"
8523
8524 Image
8525 *image,
8526 *mogrify_images;
8527
cristy0e9f9c12010-02-11 03:00:47 +00008528 MagickBooleanType
8529 proceed;
8530
8531 MagickSizeType
8532 number_images;
8533
cristy3ed852e2009-09-05 21:47:34 +00008534 MagickStatusType
8535 status;
8536
cristybb503372010-05-27 20:51:26 +00008537 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00008538 i;
8539
cristy3ed852e2009-09-05 21:47:34 +00008540 /*
8541 Apply options to individual images in the list.
8542 */
8543 assert(image_info != (ImageInfo *) NULL);
8544 assert(image_info->signature == MagickSignature);
8545 if (images == (Image **) NULL)
8546 return(MogrifyImage(image_info,argc,argv,images,exception));
8547 assert((*images)->signature == MagickSignature);
8548 if ((*images)->debug != MagickFalse)
8549 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
8550 (*images)->filename);
8551 if ((argc <= 0) || (*argv == (char *) NULL))
8552 return(MagickTrue);
8553 (void) SetImageInfoProgressMonitor(image_info,(MagickProgressMonitor) NULL,
8554 (void *) NULL);
8555 mogrify_images=NewImageList();
8556 number_images=GetImageListLength(*images);
8557 status=0;
8558 if (post == MagickFalse)
8559 status&=MogrifyImageList(image_info,argc,argv,images,exception);
cristybb503372010-05-27 20:51:26 +00008560 for (i=0; i < (ssize_t) number_images; i++)
cristy3ed852e2009-09-05 21:47:34 +00008561 {
8562 image=RemoveFirstImageFromList(images);
8563 if (image == (Image *) NULL)
8564 continue;
8565 status&=MogrifyImage(image_info,argc,argv,&image,exception);
8566 AppendImageToList(&mogrify_images,image);
cristy0e9f9c12010-02-11 03:00:47 +00008567 proceed=SetImageProgress(image,MogrifyImageTag,(MagickOffsetType) i,
8568 number_images);
8569 if (proceed == MagickFalse)
8570 break;
cristy3ed852e2009-09-05 21:47:34 +00008571 }
8572 if (post != MagickFalse)
8573 status&=MogrifyImageList(image_info,argc,argv,&mogrify_images,exception);
8574 *images=mogrify_images;
8575 return(status != 0 ? MagickTrue : MagickFalse);
8576}