blob: ba70b746fc0c727f13ef7a5a32f7b35156dcb6b6 [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);
cristyda16f162011-02-19 23:52:17 +00005278 (void) value;
cristy3ed852e2009-09-05 21:47:34 +00005279 if ((p == argv[i]) && (LocaleCompare("unlimited",argv[i]) != 0))
5280 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5281 break;
5282 }
5283 if (LocaleCompare("liquid-rescale",option+1) == 0)
5284 {
5285 i++;
cristybb503372010-05-27 20:51:26 +00005286 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005287 ThrowMogrifyException(OptionError,"MissingArgument",option);
5288 if (IsGeometry(argv[i]) == MagickFalse)
5289 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5290 break;
5291 }
5292 if (LocaleCompare("list",option+1) == 0)
5293 {
cristybb503372010-05-27 20:51:26 +00005294 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005295 list;
5296
5297 if (*option == '+')
5298 break;
5299 i++;
cristybb503372010-05-27 20:51:26 +00005300 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005301 ThrowMogrifyException(OptionError,"MissingArgument",option);
5302 list=ParseMagickOption(MagickListOptions,MagickFalse,argv[i]);
5303 if (list < 0)
5304 ThrowMogrifyException(OptionError,"UnrecognizedListType",argv[i]);
cristyaeb2cbc2010-05-07 13:28:58 +00005305 status=MogrifyImageInfo(image_info,(int) (i-j+1),(const char **)
cristy3ed852e2009-09-05 21:47:34 +00005306 argv+j,exception);
cristyaeb2cbc2010-05-07 13:28:58 +00005307 return(status != 0 ? MagickFalse : MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00005308 }
5309 if (LocaleCompare("log",option+1) == 0)
5310 {
5311 if (*option == '+')
5312 break;
5313 i++;
cristybb503372010-05-27 20:51:26 +00005314 if ((i == (ssize_t) argc) ||
cristy3ed852e2009-09-05 21:47:34 +00005315 (strchr(argv[i],'%') == (char *) NULL))
5316 ThrowMogrifyException(OptionError,"MissingArgument",option);
5317 break;
5318 }
5319 if (LocaleCompare("loop",option+1) == 0)
5320 {
5321 if (*option == '+')
5322 break;
5323 i++;
cristybb503372010-05-27 20:51:26 +00005324 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005325 ThrowMogrifyException(OptionError,"MissingArgument",option);
5326 if (IsGeometry(argv[i]) == MagickFalse)
5327 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5328 break;
5329 }
5330 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5331 }
5332 case 'm':
5333 {
5334 if (LocaleCompare("map",option+1) == 0)
5335 {
5336 global_colormap=(*option == '+') ? MagickTrue : MagickFalse;
5337 if (*option == '+')
5338 break;
5339 i++;
cristybb503372010-05-27 20:51:26 +00005340 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005341 ThrowMogrifyException(OptionError,"MissingArgument",option);
5342 break;
5343 }
5344 if (LocaleCompare("mask",option+1) == 0)
5345 {
5346 if (*option == '+')
5347 break;
5348 i++;
cristybb503372010-05-27 20:51:26 +00005349 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005350 ThrowMogrifyException(OptionError,"MissingArgument",option);
5351 break;
5352 }
5353 if (LocaleCompare("matte",option+1) == 0)
5354 break;
5355 if (LocaleCompare("mattecolor",option+1) == 0)
5356 {
5357 if (*option == '+')
5358 break;
5359 i++;
cristybb503372010-05-27 20:51:26 +00005360 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005361 ThrowMogrifyException(OptionError,"MissingArgument",option);
5362 break;
5363 }
cristyf40785b2010-03-06 02:27:27 +00005364 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00005365 break;
cristyf40785b2010-03-06 02:27:27 +00005366 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00005367 break;
cristy3ed852e2009-09-05 21:47:34 +00005368 if (LocaleCompare("modulate",option+1) == 0)
5369 {
5370 if (*option == '+')
5371 break;
5372 i++;
cristybb503372010-05-27 20:51:26 +00005373 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005374 ThrowMogrifyException(OptionError,"MissingArgument",option);
5375 if (IsGeometry(argv[i]) == MagickFalse)
5376 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5377 break;
5378 }
5379 if (LocaleCompare("median",option+1) == 0)
5380 {
5381 if (*option == '+')
5382 break;
5383 i++;
cristybb503372010-05-27 20:51:26 +00005384 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005385 ThrowMogrifyException(OptionError,"MissingArgument",option);
5386 if (IsGeometry(argv[i]) == MagickFalse)
5387 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5388 break;
5389 }
5390 if (LocaleCompare("monitor",option+1) == 0)
5391 break;
5392 if (LocaleCompare("monochrome",option+1) == 0)
5393 break;
5394 if (LocaleCompare("morph",option+1) == 0)
5395 {
5396 if (*option == '+')
5397 break;
5398 i++;
cristybb503372010-05-27 20:51:26 +00005399 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005400 ThrowMogrifyException(OptionError,"MissingArgument",option);
5401 if (IsGeometry(argv[i]) == MagickFalse)
5402 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5403 break;
5404 }
anthony29188a82010-01-22 10:12:34 +00005405 if (LocaleCompare("morphology",option+1) == 0)
5406 {
anthony29188a82010-01-22 10:12:34 +00005407 char
5408 token[MaxTextExtent];
5409
cristyb6bd4ad2010-08-08 01:12:27 +00005410 KernelInfo
5411 *kernel_info;
5412
5413 ssize_t
5414 op;
5415
anthony29188a82010-01-22 10:12:34 +00005416 i++;
cristybb503372010-05-27 20:51:26 +00005417 if (i == (ssize_t) argc)
anthony29188a82010-01-22 10:12:34 +00005418 ThrowMogrifyException(OptionError,"MissingArgument",option);
5419 GetMagickToken(argv[i],NULL,token);
5420 op=ParseMagickOption(MagickMorphologyOptions,MagickFalse,token);
5421 if (op < 0)
5422 ThrowMogrifyException(OptionError,"UnrecognizedMorphologyMethod",
cristyf0c78232010-03-15 12:53:40 +00005423 token);
anthony29188a82010-01-22 10:12:34 +00005424 i++;
cristybb503372010-05-27 20:51:26 +00005425 if (i == (ssize_t) (argc-1))
anthony29188a82010-01-22 10:12:34 +00005426 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00005427 kernel_info=AcquireKernelInfo(argv[i]);
5428 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00005429 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00005430 kernel_info=DestroyKernelInfo(kernel_info);
anthony29188a82010-01-22 10:12:34 +00005431 break;
5432 }
cristy3ed852e2009-09-05 21:47:34 +00005433 if (LocaleCompare("mosaic",option+1) == 0)
5434 break;
5435 if (LocaleCompare("motion-blur",option+1) == 0)
5436 {
5437 if (*option == '+')
5438 break;
5439 i++;
cristybb503372010-05-27 20:51:26 +00005440 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005441 ThrowMogrifyException(OptionError,"MissingArgument",option);
5442 if (IsGeometry(argv[i]) == MagickFalse)
5443 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5444 break;
5445 }
5446 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5447 }
5448 case 'n':
5449 {
5450 if (LocaleCompare("negate",option+1) == 0)
5451 break;
5452 if (LocaleCompare("noise",option+1) == 0)
5453 {
5454 i++;
cristybb503372010-05-27 20:51:26 +00005455 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005456 ThrowMogrifyException(OptionError,"MissingArgument",option);
5457 if (*option == '+')
5458 {
cristybb503372010-05-27 20:51:26 +00005459 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005460 noise;
5461
5462 noise=ParseMagickOption(MagickNoiseOptions,MagickFalse,argv[i]);
5463 if (noise < 0)
5464 ThrowMogrifyException(OptionError,"UnrecognizedNoiseType",
5465 argv[i]);
5466 break;
5467 }
5468 if (IsGeometry(argv[i]) == MagickFalse)
5469 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5470 break;
5471 }
5472 if (LocaleCompare("noop",option+1) == 0)
5473 break;
5474 if (LocaleCompare("normalize",option+1) == 0)
5475 break;
5476 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5477 }
5478 case 'o':
5479 {
5480 if (LocaleCompare("opaque",option+1) == 0)
5481 {
cristy3ed852e2009-09-05 21:47:34 +00005482 i++;
cristybb503372010-05-27 20:51:26 +00005483 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005484 ThrowMogrifyException(OptionError,"MissingArgument",option);
5485 break;
5486 }
5487 if (LocaleCompare("ordered-dither",option+1) == 0)
5488 {
5489 if (*option == '+')
5490 break;
5491 i++;
cristybb503372010-05-27 20:51:26 +00005492 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005493 ThrowMogrifyException(OptionError,"MissingArgument",option);
5494 break;
5495 }
5496 if (LocaleCompare("orient",option+1) == 0)
5497 {
cristybb503372010-05-27 20:51:26 +00005498 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005499 orientation;
5500
5501 orientation=UndefinedOrientation;
5502 if (*option == '+')
5503 break;
5504 i++;
cristybb503372010-05-27 20:51:26 +00005505 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005506 ThrowMogrifyException(OptionError,"MissingArgument",option);
5507 orientation=ParseMagickOption(MagickOrientationOptions,MagickFalse,
5508 argv[i]);
5509 if (orientation < 0)
5510 ThrowMogrifyException(OptionError,"UnrecognizedImageOrientation",
5511 argv[i]);
5512 break;
5513 }
5514 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5515 }
5516 case 'p':
5517 {
5518 if (LocaleCompare("page",option+1) == 0)
5519 {
5520 if (*option == '+')
5521 break;
5522 i++;
cristybb503372010-05-27 20:51:26 +00005523 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005524 ThrowMogrifyException(OptionError,"MissingArgument",option);
5525 break;
5526 }
5527 if (LocaleCompare("paint",option+1) == 0)
5528 {
5529 if (*option == '+')
5530 break;
5531 i++;
cristybb503372010-05-27 20:51:26 +00005532 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005533 ThrowMogrifyException(OptionError,"MissingArgument",option);
5534 if (IsGeometry(argv[i]) == MagickFalse)
5535 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5536 break;
5537 }
5538 if (LocaleCompare("path",option+1) == 0)
5539 {
5540 (void) CloneString(&path,(char *) NULL);
5541 if (*option == '+')
5542 break;
5543 i++;
cristybb503372010-05-27 20:51:26 +00005544 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005545 ThrowMogrifyException(OptionError,"MissingArgument",option);
5546 (void) CloneString(&path,argv[i]);
5547 break;
5548 }
5549 if (LocaleCompare("pointsize",option+1) == 0)
5550 {
5551 if (*option == '+')
5552 break;
5553 i++;
cristybb503372010-05-27 20:51:26 +00005554 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005555 ThrowMogrifyException(OptionError,"MissingArgument",option);
5556 if (IsGeometry(argv[i]) == MagickFalse)
5557 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5558 break;
5559 }
5560 if (LocaleCompare("polaroid",option+1) == 0)
5561 {
5562 if (*option == '+')
5563 break;
5564 i++;
cristybb503372010-05-27 20:51:26 +00005565 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005566 ThrowMogrifyException(OptionError,"MissingArgument",option);
5567 if (IsGeometry(argv[i]) == MagickFalse)
5568 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5569 break;
5570 }
5571 if (LocaleCompare("posterize",option+1) == 0)
5572 {
5573 if (*option == '+')
5574 break;
5575 i++;
cristybb503372010-05-27 20:51:26 +00005576 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005577 ThrowMogrifyException(OptionError,"MissingArgument",option);
5578 if (IsGeometry(argv[i]) == MagickFalse)
5579 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5580 break;
5581 }
cristye7f51092010-01-17 00:39:37 +00005582 if (LocaleCompare("precision",option+1) == 0)
5583 {
5584 if (*option == '+')
5585 break;
5586 i++;
cristybb503372010-05-27 20:51:26 +00005587 if (i == (ssize_t) argc)
cristye7f51092010-01-17 00:39:37 +00005588 ThrowMogrifyException(OptionError,"MissingArgument",option);
5589 if (IsGeometry(argv[i]) == MagickFalse)
5590 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5591 break;
5592 }
cristy3ed852e2009-09-05 21:47:34 +00005593 if (LocaleCompare("print",option+1) == 0)
5594 {
5595 if (*option == '+')
5596 break;
5597 i++;
cristybb503372010-05-27 20:51:26 +00005598 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005599 ThrowMogrifyException(OptionError,"MissingArgument",option);
5600 break;
5601 }
5602 if (LocaleCompare("process",option+1) == 0)
5603 {
5604 if (*option == '+')
5605 break;
5606 i++;
cristybb503372010-05-27 20:51:26 +00005607 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005608 ThrowMogrifyException(OptionError,"MissingArgument",option);
5609 break;
5610 }
5611 if (LocaleCompare("profile",option+1) == 0)
5612 {
5613 i++;
cristybb503372010-05-27 20:51:26 +00005614 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005615 ThrowMogrifyException(OptionError,"MissingArgument",option);
5616 break;
5617 }
5618 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5619 }
5620 case 'q':
5621 {
5622 if (LocaleCompare("quality",option+1) == 0)
5623 {
5624 if (*option == '+')
5625 break;
5626 i++;
cristybb503372010-05-27 20:51:26 +00005627 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005628 ThrowMogrifyException(OptionError,"MissingArgument",option);
5629 if (IsGeometry(argv[i]) == MagickFalse)
5630 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5631 break;
5632 }
5633 if (LocaleCompare("quantize",option+1) == 0)
5634 {
cristybb503372010-05-27 20:51:26 +00005635 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005636 colorspace;
5637
5638 if (*option == '+')
5639 break;
5640 i++;
cristybb503372010-05-27 20:51:26 +00005641 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005642 ThrowMogrifyException(OptionError,"MissingArgument",option);
5643 colorspace=ParseMagickOption(MagickColorspaceOptions,MagickFalse,
5644 argv[i]);
5645 if (colorspace < 0)
5646 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
5647 argv[i]);
5648 break;
5649 }
5650 if (LocaleCompare("quiet",option+1) == 0)
5651 break;
5652 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5653 }
5654 case 'r':
5655 {
5656 if (LocaleCompare("radial-blur",option+1) == 0)
5657 {
5658 i++;
cristybb503372010-05-27 20:51:26 +00005659 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005660 ThrowMogrifyException(OptionError,"MissingArgument",option);
5661 if (IsGeometry(argv[i]) == MagickFalse)
5662 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5663 break;
5664 }
5665 if (LocaleCompare("raise",option+1) == 0)
5666 {
5667 i++;
cristybb503372010-05-27 20:51:26 +00005668 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005669 ThrowMogrifyException(OptionError,"MissingArgument",option);
5670 if (IsGeometry(argv[i]) == MagickFalse)
5671 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5672 break;
5673 }
5674 if (LocaleCompare("random-threshold",option+1) == 0)
5675 {
5676 if (*option == '+')
5677 break;
5678 i++;
cristybb503372010-05-27 20:51:26 +00005679 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005680 ThrowMogrifyException(OptionError,"MissingArgument",option);
5681 if (IsGeometry(argv[i]) == MagickFalse)
5682 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5683 break;
5684 }
cristye6365592010-04-02 17:31:23 +00005685 if (LocaleCompare("recolor",option+1) == 0)
5686 {
5687 if (*option == '+')
5688 break;
5689 i++;
cristybb503372010-05-27 20:51:26 +00005690 if (i == (ssize_t) (argc-1))
cristye6365592010-04-02 17:31:23 +00005691 ThrowMogrifyException(OptionError,"MissingArgument",option);
5692 if (IsGeometry(argv[i]) == MagickFalse)
5693 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5694 break;
5695 }
cristy3ed852e2009-09-05 21:47:34 +00005696 if (LocaleCompare("red-primary",option+1) == 0)
5697 {
5698 if (*option == '+')
5699 break;
5700 i++;
cristybb503372010-05-27 20:51:26 +00005701 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005702 ThrowMogrifyException(OptionError,"MissingArgument",option);
5703 if (IsGeometry(argv[i]) == MagickFalse)
5704 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5705 }
cristy9f2083a2010-04-22 19:48:05 +00005706 if (LocaleCompare("regard-warnings",option+1) == 0)
5707 break;
cristy3ed852e2009-09-05 21:47:34 +00005708 if (LocaleCompare("region",option+1) == 0)
5709 {
5710 if (*option == '+')
5711 break;
5712 i++;
cristybb503372010-05-27 20:51:26 +00005713 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005714 ThrowMogrifyException(OptionError,"MissingArgument",option);
5715 if (IsGeometry(argv[i]) == MagickFalse)
5716 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5717 break;
5718 }
cristyf0c78232010-03-15 12:53:40 +00005719 if (LocaleCompare("remap",option+1) == 0)
5720 {
5721 if (*option == '+')
5722 break;
5723 i++;
cristybb503372010-05-27 20:51:26 +00005724 if (i == (ssize_t) (argc-1))
cristyf0c78232010-03-15 12:53:40 +00005725 ThrowMogrifyException(OptionError,"MissingArgument",option);
5726 break;
5727 }
cristy3ed852e2009-09-05 21:47:34 +00005728 if (LocaleCompare("render",option+1) == 0)
5729 break;
5730 if (LocaleCompare("repage",option+1) == 0)
5731 {
5732 if (*option == '+')
5733 break;
5734 i++;
cristybb503372010-05-27 20:51:26 +00005735 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005736 ThrowMogrifyException(OptionError,"MissingArgument",option);
5737 if (IsGeometry(argv[i]) == MagickFalse)
5738 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5739 break;
5740 }
5741 if (LocaleCompare("resample",option+1) == 0)
5742 {
5743 if (*option == '+')
5744 break;
5745 i++;
cristybb503372010-05-27 20:51:26 +00005746 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005747 ThrowMogrifyException(OptionError,"MissingArgument",option);
5748 if (IsGeometry(argv[i]) == MagickFalse)
5749 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5750 break;
5751 }
5752 if (LocaleCompare("resize",option+1) == 0)
5753 {
5754 if (*option == '+')
5755 break;
5756 i++;
cristybb503372010-05-27 20:51:26 +00005757 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005758 ThrowMogrifyException(OptionError,"MissingArgument",option);
5759 if (IsGeometry(argv[i]) == MagickFalse)
5760 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5761 break;
5762 }
5763 if (LocaleCompare("reverse",option+1) == 0)
5764 break;
5765 if (LocaleCompare("roll",option+1) == 0)
5766 {
5767 if (*option == '+')
5768 break;
5769 i++;
cristybb503372010-05-27 20:51:26 +00005770 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005771 ThrowMogrifyException(OptionError,"MissingArgument",option);
5772 if (IsGeometry(argv[i]) == MagickFalse)
5773 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5774 break;
5775 }
5776 if (LocaleCompare("rotate",option+1) == 0)
5777 {
5778 i++;
cristybb503372010-05-27 20:51:26 +00005779 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005780 ThrowMogrifyException(OptionError,"MissingArgument",option);
5781 if (IsGeometry(argv[i]) == MagickFalse)
5782 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5783 break;
5784 }
5785 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5786 }
5787 case 's':
5788 {
5789 if (LocaleCompare("sample",option+1) == 0)
5790 {
5791 if (*option == '+')
5792 break;
5793 i++;
cristybb503372010-05-27 20:51:26 +00005794 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005795 ThrowMogrifyException(OptionError,"MissingArgument",option);
5796 if (IsGeometry(argv[i]) == MagickFalse)
5797 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5798 break;
5799 }
5800 if (LocaleCompare("sampling-factor",option+1) == 0)
5801 {
5802 if (*option == '+')
5803 break;
5804 i++;
cristybb503372010-05-27 20:51:26 +00005805 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005806 ThrowMogrifyException(OptionError,"MissingArgument",option);
5807 if (IsGeometry(argv[i]) == MagickFalse)
5808 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5809 break;
5810 }
5811 if (LocaleCompare("scale",option+1) == 0)
5812 {
5813 if (*option == '+')
5814 break;
5815 i++;
cristybb503372010-05-27 20:51:26 +00005816 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005817 ThrowMogrifyException(OptionError,"MissingArgument",option);
5818 if (IsGeometry(argv[i]) == MagickFalse)
5819 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5820 break;
5821 }
5822 if (LocaleCompare("scene",option+1) == 0)
5823 {
5824 if (*option == '+')
5825 break;
5826 i++;
cristybb503372010-05-27 20:51:26 +00005827 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005828 ThrowMogrifyException(OptionError,"MissingArgument",option);
5829 if (IsGeometry(argv[i]) == MagickFalse)
5830 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5831 break;
5832 }
5833 if (LocaleCompare("seed",option+1) == 0)
5834 {
5835 if (*option == '+')
5836 break;
5837 i++;
cristybb503372010-05-27 20:51:26 +00005838 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005839 ThrowMogrifyException(OptionError,"MissingArgument",option);
5840 if (IsGeometry(argv[i]) == MagickFalse)
5841 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5842 break;
5843 }
5844 if (LocaleCompare("segment",option+1) == 0)
5845 {
5846 if (*option == '+')
5847 break;
5848 i++;
cristybb503372010-05-27 20:51:26 +00005849 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005850 ThrowMogrifyException(OptionError,"MissingArgument",option);
5851 if (IsGeometry(argv[i]) == MagickFalse)
5852 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5853 break;
5854 }
5855 if (LocaleCompare("selective-blur",option+1) == 0)
5856 {
5857 i++;
cristybb503372010-05-27 20:51:26 +00005858 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005859 ThrowMogrifyException(OptionError,"MissingArgument",option);
5860 if (IsGeometry(argv[i]) == MagickFalse)
5861 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5862 break;
5863 }
5864 if (LocaleCompare("separate",option+1) == 0)
5865 break;
5866 if (LocaleCompare("sepia-tone",option+1) == 0)
5867 {
5868 if (*option == '+')
5869 break;
5870 i++;
cristybb503372010-05-27 20:51:26 +00005871 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005872 ThrowMogrifyException(OptionError,"MissingArgument",option);
5873 if (IsGeometry(argv[i]) == MagickFalse)
5874 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5875 break;
5876 }
5877 if (LocaleCompare("set",option+1) == 0)
5878 {
5879 i++;
cristybb503372010-05-27 20:51:26 +00005880 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005881 ThrowMogrifyException(OptionError,"MissingArgument",option);
5882 if (*option == '+')
5883 break;
5884 i++;
cristybb503372010-05-27 20:51:26 +00005885 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005886 ThrowMogrifyException(OptionError,"MissingArgument",option);
5887 break;
5888 }
5889 if (LocaleCompare("shade",option+1) == 0)
5890 {
5891 i++;
cristybb503372010-05-27 20:51:26 +00005892 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005893 ThrowMogrifyException(OptionError,"MissingArgument",option);
5894 if (IsGeometry(argv[i]) == MagickFalse)
5895 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5896 break;
5897 }
5898 if (LocaleCompare("shadow",option+1) == 0)
5899 {
5900 if (*option == '+')
5901 break;
5902 i++;
cristybb503372010-05-27 20:51:26 +00005903 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005904 ThrowMogrifyException(OptionError,"MissingArgument",option);
5905 if (IsGeometry(argv[i]) == MagickFalse)
5906 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5907 break;
5908 }
5909 if (LocaleCompare("sharpen",option+1) == 0)
5910 {
5911 i++;
cristybb503372010-05-27 20:51:26 +00005912 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005913 ThrowMogrifyException(OptionError,"MissingArgument",option);
5914 if (IsGeometry(argv[i]) == MagickFalse)
5915 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5916 break;
5917 }
5918 if (LocaleCompare("shave",option+1) == 0)
5919 {
5920 if (*option == '+')
5921 break;
5922 i++;
cristybb503372010-05-27 20:51:26 +00005923 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005924 ThrowMogrifyException(OptionError,"MissingArgument",option);
5925 if (IsGeometry(argv[i]) == MagickFalse)
5926 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5927 break;
5928 }
5929 if (LocaleCompare("shear",option+1) == 0)
5930 {
5931 i++;
cristybb503372010-05-27 20:51:26 +00005932 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005933 ThrowMogrifyException(OptionError,"MissingArgument",option);
5934 if (IsGeometry(argv[i]) == MagickFalse)
5935 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5936 break;
5937 }
5938 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
5939 {
5940 i++;
cristybb503372010-05-27 20:51:26 +00005941 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005942 ThrowMogrifyException(OptionError,"MissingArgument",option);
5943 if (IsGeometry(argv[i]) == MagickFalse)
5944 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5945 break;
5946 }
5947 if (LocaleCompare("size",option+1) == 0)
5948 {
5949 if (*option == '+')
5950 break;
5951 i++;
cristybb503372010-05-27 20:51:26 +00005952 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005953 ThrowMogrifyException(OptionError,"MissingArgument",option);
5954 if (IsGeometry(argv[i]) == MagickFalse)
5955 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5956 break;
5957 }
5958 if (LocaleCompare("sketch",option+1) == 0)
5959 {
5960 if (*option == '+')
5961 break;
5962 i++;
cristybb503372010-05-27 20:51:26 +00005963 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005964 ThrowMogrifyException(OptionError,"MissingArgument",option);
5965 if (IsGeometry(argv[i]) == MagickFalse)
5966 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5967 break;
5968 }
cristy4285d782011-02-09 20:12:28 +00005969 if (LocaleCompare("smush",option+1) == 0)
5970 {
cristy4285d782011-02-09 20:12:28 +00005971 i++;
5972 if (i == (ssize_t) argc)
5973 ThrowMogrifyException(OptionError,"MissingArgument",option);
5974 if (IsGeometry(argv[i]) == MagickFalse)
5975 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristy4285d782011-02-09 20:12:28 +00005976 i++;
5977 break;
5978 }
cristy3ed852e2009-09-05 21:47:34 +00005979 if (LocaleCompare("solarize",option+1) == 0)
5980 {
5981 if (*option == '+')
5982 break;
5983 i++;
cristybb503372010-05-27 20:51:26 +00005984 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005985 ThrowMogrifyException(OptionError,"MissingArgument",option);
5986 if (IsGeometry(argv[i]) == MagickFalse)
5987 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5988 break;
5989 }
5990 if (LocaleCompare("sparse-color",option+1) == 0)
5991 {
cristybb503372010-05-27 20:51:26 +00005992 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005993 op;
5994
5995 i++;
cristybb503372010-05-27 20:51:26 +00005996 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005997 ThrowMogrifyException(OptionError,"MissingArgument",option);
5998 op=ParseMagickOption(MagickSparseColorOptions,MagickFalse,argv[i]);
5999 if (op < 0)
6000 ThrowMogrifyException(OptionError,"UnrecognizedSparseColorMethod",
6001 argv[i]);
6002 i++;
cristybb503372010-05-27 20:51:26 +00006003 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006004 ThrowMogrifyException(OptionError,"MissingArgument",option);
6005 break;
6006 }
6007 if (LocaleCompare("spread",option+1) == 0)
6008 {
6009 if (*option == '+')
6010 break;
6011 i++;
cristybb503372010-05-27 20:51:26 +00006012 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006013 ThrowMogrifyException(OptionError,"MissingArgument",option);
6014 if (IsGeometry(argv[i]) == MagickFalse)
6015 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6016 break;
6017 }
6018 if (LocaleCompare("stretch",option+1) == 0)
6019 {
cristybb503372010-05-27 20:51:26 +00006020 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006021 stretch;
6022
6023 if (*option == '+')
6024 break;
6025 i++;
cristybb503372010-05-27 20:51:26 +00006026 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006027 ThrowMogrifyException(OptionError,"MissingArgument",option);
6028 stretch=ParseMagickOption(MagickStretchOptions,MagickFalse,argv[i]);
6029 if (stretch < 0)
6030 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
6031 argv[i]);
6032 break;
6033 }
6034 if (LocaleCompare("strip",option+1) == 0)
6035 break;
6036 if (LocaleCompare("stroke",option+1) == 0)
6037 {
6038 if (*option == '+')
6039 break;
6040 i++;
cristybb503372010-05-27 20:51:26 +00006041 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006042 ThrowMogrifyException(OptionError,"MissingArgument",option);
6043 break;
6044 }
6045 if (LocaleCompare("strokewidth",option+1) == 0)
6046 {
6047 if (*option == '+')
6048 break;
6049 i++;
cristybb503372010-05-27 20:51:26 +00006050 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006051 ThrowMogrifyException(OptionError,"MissingArgument",option);
6052 if (IsGeometry(argv[i]) == MagickFalse)
6053 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6054 break;
6055 }
6056 if (LocaleCompare("style",option+1) == 0)
6057 {
cristybb503372010-05-27 20:51:26 +00006058 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006059 style;
6060
6061 if (*option == '+')
6062 break;
6063 i++;
cristybb503372010-05-27 20:51:26 +00006064 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006065 ThrowMogrifyException(OptionError,"MissingArgument",option);
6066 style=ParseMagickOption(MagickStyleOptions,MagickFalse,argv[i]);
6067 if (style < 0)
6068 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
6069 argv[i]);
6070 break;
6071 }
6072 if (LocaleCompare("swirl",option+1) == 0)
6073 {
6074 if (*option == '+')
6075 break;
6076 i++;
cristybb503372010-05-27 20:51:26 +00006077 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006078 ThrowMogrifyException(OptionError,"MissingArgument",option);
6079 if (IsGeometry(argv[i]) == MagickFalse)
6080 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6081 break;
6082 }
cristyd9a29192010-10-16 16:49:53 +00006083 if (LocaleCompare("synchronize",option+1) == 0)
6084 break;
cristy3ed852e2009-09-05 21:47:34 +00006085 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6086 }
6087 case 't':
6088 {
6089 if (LocaleCompare("taint",option+1) == 0)
6090 break;
6091 if (LocaleCompare("texture",option+1) == 0)
6092 {
6093 if (*option == '+')
6094 break;
6095 i++;
cristybb503372010-05-27 20:51:26 +00006096 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006097 ThrowMogrifyException(OptionError,"MissingArgument",option);
6098 break;
6099 }
6100 if (LocaleCompare("tile",option+1) == 0)
6101 {
6102 if (*option == '+')
6103 break;
6104 i++;
cristybb503372010-05-27 20:51:26 +00006105 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006106 ThrowMogrifyException(OptionError,"MissingArgument",option);
6107 break;
6108 }
6109 if (LocaleCompare("tile-offset",option+1) == 0)
6110 {
6111 if (*option == '+')
6112 break;
6113 i++;
cristybb503372010-05-27 20:51:26 +00006114 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006115 ThrowMogrifyException(OptionError,"MissingArgument",option);
6116 if (IsGeometry(argv[i]) == MagickFalse)
6117 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6118 break;
6119 }
6120 if (LocaleCompare("tint",option+1) == 0)
6121 {
6122 if (*option == '+')
6123 break;
6124 i++;
cristybb503372010-05-27 20:51:26 +00006125 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006126 ThrowMogrifyException(OptionError,"MissingArgument",option);
6127 if (IsGeometry(argv[i]) == MagickFalse)
6128 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6129 break;
6130 }
6131 if (LocaleCompare("transform",option+1) == 0)
6132 break;
6133 if (LocaleCompare("transpose",option+1) == 0)
6134 break;
6135 if (LocaleCompare("transverse",option+1) == 0)
6136 break;
6137 if (LocaleCompare("threshold",option+1) == 0)
6138 {
6139 if (*option == '+')
6140 break;
6141 i++;
cristybb503372010-05-27 20:51:26 +00006142 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006143 ThrowMogrifyException(OptionError,"MissingArgument",option);
6144 if (IsGeometry(argv[i]) == MagickFalse)
6145 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6146 break;
6147 }
6148 if (LocaleCompare("thumbnail",option+1) == 0)
6149 {
6150 if (*option == '+')
6151 break;
6152 i++;
cristybb503372010-05-27 20:51:26 +00006153 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006154 ThrowMogrifyException(OptionError,"MissingArgument",option);
6155 if (IsGeometry(argv[i]) == MagickFalse)
6156 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6157 break;
6158 }
6159 if (LocaleCompare("transparent",option+1) == 0)
6160 {
6161 i++;
cristybb503372010-05-27 20:51:26 +00006162 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006163 ThrowMogrifyException(OptionError,"MissingArgument",option);
6164 break;
6165 }
6166 if (LocaleCompare("transparent-color",option+1) == 0)
6167 {
6168 if (*option == '+')
6169 break;
6170 i++;
cristybb503372010-05-27 20:51:26 +00006171 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006172 ThrowMogrifyException(OptionError,"MissingArgument",option);
6173 break;
6174 }
6175 if (LocaleCompare("treedepth",option+1) == 0)
6176 {
6177 if (*option == '+')
6178 break;
6179 i++;
cristybb503372010-05-27 20:51:26 +00006180 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006181 ThrowMogrifyException(OptionError,"MissingArgument",option);
6182 if (IsGeometry(argv[i]) == MagickFalse)
6183 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6184 break;
6185 }
6186 if (LocaleCompare("trim",option+1) == 0)
6187 break;
6188 if (LocaleCompare("type",option+1) == 0)
6189 {
cristybb503372010-05-27 20:51:26 +00006190 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006191 type;
6192
6193 if (*option == '+')
6194 break;
6195 i++;
cristybb503372010-05-27 20:51:26 +00006196 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006197 ThrowMogrifyException(OptionError,"MissingArgument",option);
6198 type=ParseMagickOption(MagickTypeOptions,MagickFalse,argv[i]);
6199 if (type < 0)
6200 ThrowMogrifyException(OptionError,"UnrecognizedImageType",
6201 argv[i]);
6202 break;
6203 }
6204 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6205 }
6206 case 'u':
6207 {
6208 if (LocaleCompare("undercolor",option+1) == 0)
6209 {
6210 if (*option == '+')
6211 break;
6212 i++;
cristybb503372010-05-27 20:51:26 +00006213 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006214 ThrowMogrifyException(OptionError,"MissingArgument",option);
6215 break;
6216 }
6217 if (LocaleCompare("unique-colors",option+1) == 0)
6218 break;
6219 if (LocaleCompare("units",option+1) == 0)
6220 {
cristybb503372010-05-27 20:51:26 +00006221 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006222 units;
6223
6224 if (*option == '+')
6225 break;
6226 i++;
cristybb503372010-05-27 20:51:26 +00006227 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006228 ThrowMogrifyException(OptionError,"MissingArgument",option);
6229 units=ParseMagickOption(MagickResolutionOptions,MagickFalse,
6230 argv[i]);
6231 if (units < 0)
6232 ThrowMogrifyException(OptionError,"UnrecognizedUnitsType",
6233 argv[i]);
6234 break;
6235 }
6236 if (LocaleCompare("unsharp",option+1) == 0)
6237 {
6238 i++;
cristybb503372010-05-27 20:51:26 +00006239 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006240 ThrowMogrifyException(OptionError,"MissingArgument",option);
6241 if (IsGeometry(argv[i]) == MagickFalse)
6242 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6243 break;
6244 }
6245 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6246 }
6247 case 'v':
6248 {
6249 if (LocaleCompare("verbose",option+1) == 0)
6250 {
6251 image_info->verbose=(*option == '-') ? MagickTrue : MagickFalse;
6252 break;
6253 }
6254 if ((LocaleCompare("version",option+1) == 0) ||
6255 (LocaleCompare("-version",option+1) == 0))
6256 {
6257 (void) fprintf(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +00006258 GetMagickVersion((size_t *) NULL));
cristy610b2e22009-10-22 14:59:43 +00006259 (void) fprintf(stdout,"Copyright: %s\n",GetMagickCopyright());
6260 (void) fprintf(stdout,"Features: %s\n\n",GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00006261 break;
6262 }
6263 if (LocaleCompare("view",option+1) == 0)
6264 {
6265 if (*option == '+')
6266 break;
6267 i++;
cristybb503372010-05-27 20:51:26 +00006268 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006269 ThrowMogrifyException(OptionError,"MissingArgument",option);
6270 break;
6271 }
6272 if (LocaleCompare("vignette",option+1) == 0)
6273 {
6274 if (*option == '+')
6275 break;
6276 i++;
cristybb503372010-05-27 20:51:26 +00006277 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006278 ThrowMogrifyException(OptionError,"MissingArgument",option);
6279 if (IsGeometry(argv[i]) == MagickFalse)
6280 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6281 break;
6282 }
6283 if (LocaleCompare("virtual-pixel",option+1) == 0)
6284 {
cristybb503372010-05-27 20:51:26 +00006285 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006286 method;
6287
6288 if (*option == '+')
6289 break;
6290 i++;
cristybb503372010-05-27 20:51:26 +00006291 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006292 ThrowMogrifyException(OptionError,"MissingArgument",option);
6293 method=ParseMagickOption(MagickVirtualPixelOptions,MagickFalse,
6294 argv[i]);
6295 if (method < 0)
6296 ThrowMogrifyException(OptionError,
6297 "UnrecognizedVirtualPixelMethod",argv[i]);
6298 break;
6299 }
6300 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6301 }
6302 case 'w':
6303 {
6304 if (LocaleCompare("wave",option+1) == 0)
6305 {
6306 i++;
cristybb503372010-05-27 20:51:26 +00006307 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006308 ThrowMogrifyException(OptionError,"MissingArgument",option);
6309 if (IsGeometry(argv[i]) == MagickFalse)
6310 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6311 break;
6312 }
6313 if (LocaleCompare("weight",option+1) == 0)
6314 {
6315 if (*option == '+')
6316 break;
6317 i++;
cristybb503372010-05-27 20:51:26 +00006318 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006319 ThrowMogrifyException(OptionError,"MissingArgument",option);
6320 break;
6321 }
6322 if (LocaleCompare("white-point",option+1) == 0)
6323 {
6324 if (*option == '+')
6325 break;
6326 i++;
cristybb503372010-05-27 20:51:26 +00006327 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006328 ThrowMogrifyException(OptionError,"MissingArgument",option);
6329 if (IsGeometry(argv[i]) == MagickFalse)
6330 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6331 break;
6332 }
6333 if (LocaleCompare("white-threshold",option+1) == 0)
6334 {
6335 if (*option == '+')
6336 break;
6337 i++;
cristybb503372010-05-27 20:51:26 +00006338 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006339 ThrowMogrifyException(OptionError,"MissingArgument",option);
6340 if (IsGeometry(argv[i]) == MagickFalse)
6341 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6342 break;
6343 }
6344 if (LocaleCompare("write",option+1) == 0)
6345 {
6346 i++;
cristybb503372010-05-27 20:51:26 +00006347 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006348 ThrowMogrifyException(OptionError,"MissingArgument",option);
6349 break;
6350 }
6351 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6352 }
6353 case '?':
6354 break;
6355 default:
6356 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6357 }
6358 fire=ParseMagickOption(MagickImageListOptions,MagickFalse,option+1) < 0 ?
6359 MagickFalse : MagickTrue;
6360 if (fire != MagickFalse)
6361 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
6362 }
6363 if (k != 0)
6364 ThrowMogrifyException(OptionError,"UnbalancedParenthesis",argv[i]);
cristycee97112010-05-28 00:44:52 +00006365 if (i != (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006366 ThrowMogrifyException(OptionError,"MissingAnImageFilename",argv[i]);
6367 DestroyMogrify();
6368 return(status != 0 ? MagickTrue : MagickFalse);
6369}
6370
6371/*
6372%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6373% %
6374% %
6375% %
6376+ M o g r i f y I m a g e I n f o %
6377% %
6378% %
6379% %
6380%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6381%
6382% MogrifyImageInfo() applies image processing settings to the image as
6383% prescribed by command line options.
6384%
6385% The format of the MogrifyImageInfo method is:
6386%
6387% MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,const int argc,
6388% const char **argv,ExceptionInfo *exception)
6389%
6390% A description of each parameter follows:
6391%
6392% o image_info: the image info..
6393%
6394% o argc: Specifies a pointer to an integer describing the number of
6395% elements in the argument vector.
6396%
6397% o argv: Specifies a pointer to a text array containing the command line
6398% arguments.
6399%
6400% o exception: return any errors or warnings in this structure.
6401%
6402*/
6403WandExport MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,
6404 const int argc,const char **argv,ExceptionInfo *exception)
6405{
6406 const char
6407 *option;
6408
6409 GeometryInfo
6410 geometry_info;
6411
cristybb503372010-05-27 20:51:26 +00006412 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006413 count;
6414
cristybb503372010-05-27 20:51:26 +00006415 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006416 i;
6417
6418 /*
6419 Initialize method variables.
6420 */
6421 assert(image_info != (ImageInfo *) NULL);
6422 assert(image_info->signature == MagickSignature);
6423 if (image_info->debug != MagickFalse)
6424 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
6425 image_info->filename);
6426 if (argc < 0)
6427 return(MagickTrue);
6428 /*
6429 Set the image settings.
6430 */
cristybb503372010-05-27 20:51:26 +00006431 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00006432 {
6433 option=argv[i];
6434 if (IsMagickOption(option) == MagickFalse)
6435 continue;
6436 count=MagickMax(ParseMagickOption(MagickCommandOptions,MagickFalse,option),
6437 0L);
cristycee97112010-05-28 00:44:52 +00006438 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006439 break;
6440 switch (*(option+1))
6441 {
6442 case 'a':
6443 {
6444 if (LocaleCompare("adjoin",option+1) == 0)
6445 {
6446 image_info->adjoin=(*option == '-') ? MagickTrue : MagickFalse;
6447 break;
6448 }
6449 if (LocaleCompare("antialias",option+1) == 0)
6450 {
6451 image_info->antialias=(*option == '-') ? MagickTrue : MagickFalse;
6452 break;
6453 }
6454 if (LocaleCompare("attenuate",option+1) == 0)
6455 {
6456 if (*option == '+')
6457 {
6458 (void) DeleteImageOption(image_info,option+1);
6459 break;
6460 }
6461 (void) SetImageOption(image_info,option+1,argv[i+1]);
6462 break;
6463 }
6464 if (LocaleCompare("authenticate",option+1) == 0)
6465 {
6466 if (*option == '+')
6467 (void) CloneString(&image_info->authenticate,(char *) NULL);
6468 else
6469 (void) CloneString(&image_info->authenticate,argv[i+1]);
6470 break;
6471 }
6472 break;
6473 }
6474 case 'b':
6475 {
6476 if (LocaleCompare("background",option+1) == 0)
6477 {
6478 if (*option == '+')
6479 {
6480 (void) DeleteImageOption(image_info,option+1);
6481 (void) QueryColorDatabase(BackgroundColor,
6482 &image_info->background_color,exception);
6483 break;
6484 }
6485 (void) SetImageOption(image_info,option+1,argv[i+1]);
6486 (void) QueryColorDatabase(argv[i+1],&image_info->background_color,
6487 exception);
6488 break;
6489 }
6490 if (LocaleCompare("bias",option+1) == 0)
6491 {
6492 if (*option == '+')
6493 {
6494 (void) SetImageOption(image_info,option+1,"0.0");
6495 break;
6496 }
6497 (void) SetImageOption(image_info,option+1,argv[i+1]);
6498 break;
6499 }
6500 if (LocaleCompare("black-point-compensation",option+1) == 0)
6501 {
6502 if (*option == '+')
6503 {
6504 (void) SetImageOption(image_info,option+1,"false");
6505 break;
6506 }
6507 (void) SetImageOption(image_info,option+1,"true");
6508 break;
6509 }
6510 if (LocaleCompare("blue-primary",option+1) == 0)
6511 {
6512 if (*option == '+')
6513 {
6514 (void) SetImageOption(image_info,option+1,"0.0");
6515 break;
6516 }
6517 (void) SetImageOption(image_info,option+1,argv[i+1]);
6518 break;
6519 }
6520 if (LocaleCompare("bordercolor",option+1) == 0)
6521 {
6522 if (*option == '+')
6523 {
6524 (void) DeleteImageOption(image_info,option+1);
6525 (void) QueryColorDatabase(BorderColor,&image_info->border_color,
6526 exception);
6527 break;
6528 }
6529 (void) QueryColorDatabase(argv[i+1],&image_info->border_color,
6530 exception);
6531 (void) SetImageOption(image_info,option+1,argv[i+1]);
6532 break;
6533 }
6534 if (LocaleCompare("box",option+1) == 0)
6535 {
6536 if (*option == '+')
6537 {
6538 (void) SetImageOption(image_info,"undercolor","none");
6539 break;
6540 }
6541 (void) SetImageOption(image_info,"undercolor",argv[i+1]);
6542 break;
6543 }
6544 break;
6545 }
6546 case 'c':
6547 {
6548 if (LocaleCompare("cache",option+1) == 0)
6549 {
6550 MagickSizeType
6551 limit;
6552
6553 limit=MagickResourceInfinity;
6554 if (LocaleCompare("unlimited",argv[i+1]) != 0)
cristyf2f27272009-12-17 14:48:46 +00006555 limit=(MagickSizeType) SiPrefixToDouble(argv[i+1],100.0);
cristy3ed852e2009-09-05 21:47:34 +00006556 (void) SetMagickResourceLimit(MemoryResource,limit);
6557 (void) SetMagickResourceLimit(MapResource,2*limit);
6558 break;
6559 }
6560 if (LocaleCompare("caption",option+1) == 0)
6561 {
6562 if (*option == '+')
6563 {
6564 (void) DeleteImageOption(image_info,option+1);
6565 break;
6566 }
6567 (void) SetImageOption(image_info,option+1,argv[i+1]);
6568 break;
6569 }
6570 if (LocaleCompare("channel",option+1) == 0)
6571 {
6572 if (*option == '+')
6573 {
6574 image_info->channel=DefaultChannels;
6575 break;
6576 }
6577 image_info->channel=(ChannelType) ParseChannelOption(argv[i+1]);
6578 break;
6579 }
6580 if (LocaleCompare("colors",option+1) == 0)
6581 {
cristye27293e2009-12-18 02:53:20 +00006582 image_info->colors=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006583 break;
6584 }
6585 if (LocaleCompare("colorspace",option+1) == 0)
6586 {
6587 if (*option == '+')
6588 {
6589 image_info->colorspace=UndefinedColorspace;
6590 (void) SetImageOption(image_info,option+1,"undefined");
6591 break;
6592 }
6593 image_info->colorspace=(ColorspaceType) ParseMagickOption(
6594 MagickColorspaceOptions,MagickFalse,argv[i+1]);
6595 (void) SetImageOption(image_info,option+1,argv[i+1]);
6596 break;
6597 }
6598 if (LocaleCompare("compress",option+1) == 0)
6599 {
6600 if (*option == '+')
6601 {
6602 image_info->compression=UndefinedCompression;
6603 (void) SetImageOption(image_info,option+1,"undefined");
6604 break;
6605 }
6606 image_info->compression=(CompressionType) ParseMagickOption(
6607 MagickCompressOptions,MagickFalse,argv[i+1]);
6608 (void) SetImageOption(image_info,option+1,argv[i+1]);
6609 break;
6610 }
6611 if (LocaleCompare("comment",option+1) == 0)
6612 {
6613 if (*option == '+')
6614 {
6615 (void) DeleteImageOption(image_info,option+1);
6616 break;
6617 }
6618 (void) SetImageOption(image_info,option+1,argv[i+1]);
6619 break;
6620 }
6621 if (LocaleCompare("compose",option+1) == 0)
6622 {
6623 if (*option == '+')
6624 {
6625 (void) SetImageOption(image_info,option+1,"undefined");
6626 break;
6627 }
6628 (void) SetImageOption(image_info,option+1,argv[i+1]);
6629 break;
6630 }
6631 if (LocaleCompare("compress",option+1) == 0)
6632 {
6633 if (*option == '+')
6634 {
6635 image_info->compression=UndefinedCompression;
6636 (void) SetImageOption(image_info,option+1,"undefined");
6637 break;
6638 }
6639 image_info->compression=(CompressionType) ParseMagickOption(
6640 MagickCompressOptions,MagickFalse,argv[i+1]);
6641 (void) SetImageOption(image_info,option+1,argv[i+1]);
6642 break;
6643 }
6644 break;
6645 }
6646 case 'd':
6647 {
6648 if (LocaleCompare("debug",option+1) == 0)
6649 {
6650 if (*option == '+')
6651 (void) SetLogEventMask("none");
6652 else
6653 (void) SetLogEventMask(argv[i+1]);
6654 image_info->debug=IsEventLogging();
6655 break;
6656 }
6657 if (LocaleCompare("define",option+1) == 0)
6658 {
6659 if (*option == '+')
6660 {
6661 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6662 (void) DeleteImageRegistry(argv[i+1]+9);
6663 else
6664 (void) DeleteImageOption(image_info,argv[i+1]);
6665 break;
6666 }
6667 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6668 {
6669 (void) DefineImageRegistry(StringRegistryType,argv[i+1]+9,
6670 exception);
6671 break;
6672 }
6673 (void) DefineImageOption(image_info,argv[i+1]);
6674 break;
6675 }
6676 if (LocaleCompare("delay",option+1) == 0)
6677 {
6678 if (*option == '+')
6679 {
6680 (void) SetImageOption(image_info,option+1,"0");
6681 break;
6682 }
6683 (void) SetImageOption(image_info,option+1,argv[i+1]);
6684 break;
6685 }
6686 if (LocaleCompare("density",option+1) == 0)
6687 {
6688 /*
6689 Set image density.
6690 */
6691 if (*option == '+')
6692 {
6693 if (image_info->density != (char *) NULL)
6694 image_info->density=DestroyString(image_info->density);
6695 (void) SetImageOption(image_info,option+1,"72");
6696 break;
6697 }
6698 (void) CloneString(&image_info->density,argv[i+1]);
6699 (void) SetImageOption(image_info,option+1,argv[i+1]);
6700 break;
6701 }
6702 if (LocaleCompare("depth",option+1) == 0)
6703 {
6704 if (*option == '+')
6705 {
6706 image_info->depth=MAGICKCORE_QUANTUM_DEPTH;
6707 break;
6708 }
cristye27293e2009-12-18 02:53:20 +00006709 image_info->depth=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006710 break;
6711 }
cristyc9b12952010-03-28 01:12:28 +00006712 if (LocaleCompare("direction",option+1) == 0)
6713 {
6714 if (*option == '+')
6715 {
6716 (void) SetImageOption(image_info,option+1,"undefined");
6717 break;
6718 }
6719 (void) SetImageOption(image_info,option+1,argv[i+1]);
6720 break;
6721 }
cristy3ed852e2009-09-05 21:47:34 +00006722 if (LocaleCompare("display",option+1) == 0)
6723 {
6724 if (*option == '+')
6725 {
6726 if (image_info->server_name != (char *) NULL)
6727 image_info->server_name=DestroyString(
6728 image_info->server_name);
6729 break;
6730 }
6731 (void) CloneString(&image_info->server_name,argv[i+1]);
6732 break;
6733 }
6734 if (LocaleCompare("dispose",option+1) == 0)
6735 {
6736 if (*option == '+')
6737 {
6738 (void) SetImageOption(image_info,option+1,"undefined");
6739 break;
6740 }
6741 (void) SetImageOption(image_info,option+1,argv[i+1]);
6742 break;
6743 }
6744 if (LocaleCompare("dither",option+1) == 0)
6745 {
6746 if (*option == '+')
6747 {
6748 image_info->dither=MagickFalse;
cristyd5acfd12010-06-15 00:11:38 +00006749 (void) SetImageOption(image_info,option+1,"none");
cristy3ed852e2009-09-05 21:47:34 +00006750 break;
6751 }
6752 (void) SetImageOption(image_info,option+1,argv[i+1]);
6753 image_info->dither=MagickTrue;
6754 break;
6755 }
6756 break;
6757 }
6758 case 'e':
6759 {
6760 if (LocaleCompare("encoding",option+1) == 0)
6761 {
6762 if (*option == '+')
6763 {
6764 (void) SetImageOption(image_info,option+1,"undefined");
6765 break;
6766 }
6767 (void) SetImageOption(image_info,option+1,argv[i+1]);
6768 break;
6769 }
6770 if (LocaleCompare("endian",option+1) == 0)
6771 {
6772 if (*option == '+')
6773 {
6774 image_info->endian=UndefinedEndian;
6775 (void) SetImageOption(image_info,option+1,"undefined");
6776 break;
6777 }
6778 image_info->endian=(EndianType) ParseMagickOption(
6779 MagickEndianOptions,MagickFalse,argv[i+1]);
6780 (void) SetImageOption(image_info,option+1,argv[i+1]);
6781 break;
6782 }
6783 if (LocaleCompare("extract",option+1) == 0)
6784 {
6785 /*
6786 Set image extract geometry.
6787 */
6788 if (*option == '+')
6789 {
6790 if (image_info->extract != (char *) NULL)
6791 image_info->extract=DestroyString(image_info->extract);
6792 break;
6793 }
6794 (void) CloneString(&image_info->extract,argv[i+1]);
6795 break;
6796 }
6797 break;
6798 }
6799 case 'f':
6800 {
6801 if (LocaleCompare("fill",option+1) == 0)
6802 {
6803 if (*option == '+')
6804 {
6805 (void) SetImageOption(image_info,option+1,"none");
6806 break;
6807 }
6808 (void) SetImageOption(image_info,option+1,argv[i+1]);
6809 break;
6810 }
6811 if (LocaleCompare("filter",option+1) == 0)
6812 {
6813 if (*option == '+')
6814 {
6815 (void) SetImageOption(image_info,option+1,"undefined");
6816 break;
6817 }
6818 (void) SetImageOption(image_info,option+1,argv[i+1]);
6819 break;
6820 }
6821 if (LocaleCompare("font",option+1) == 0)
6822 {
6823 if (*option == '+')
6824 {
6825 if (image_info->font != (char *) NULL)
6826 image_info->font=DestroyString(image_info->font);
6827 break;
6828 }
6829 (void) CloneString(&image_info->font,argv[i+1]);
6830 break;
6831 }
6832 if (LocaleCompare("format",option+1) == 0)
6833 {
6834 register const char
6835 *q;
6836
6837 for (q=strchr(argv[i+1],'%'); q != (char *) NULL; q=strchr(q+1,'%'))
6838 if (strchr("gkrz@[#",*(q+1)) != (char *) NULL)
6839 image_info->ping=MagickFalse;
6840 (void) SetImageOption(image_info,option+1,argv[i+1]);
6841 break;
6842 }
6843 if (LocaleCompare("fuzz",option+1) == 0)
6844 {
6845 if (*option == '+')
6846 {
6847 image_info->fuzz=0.0;
6848 (void) SetImageOption(image_info,option+1,"0");
6849 break;
6850 }
cristyf2f27272009-12-17 14:48:46 +00006851 image_info->fuzz=SiPrefixToDouble(argv[i+1],(double) QuantumRange+
cristy3ed852e2009-09-05 21:47:34 +00006852 1.0);
6853 (void) SetImageOption(image_info,option+1,argv[i+1]);
6854 break;
6855 }
6856 break;
6857 }
6858 case 'g':
6859 {
6860 if (LocaleCompare("gravity",option+1) == 0)
6861 {
6862 if (*option == '+')
6863 {
6864 (void) SetImageOption(image_info,option+1,"undefined");
6865 break;
6866 }
6867 (void) SetImageOption(image_info,option+1,argv[i+1]);
6868 break;
6869 }
6870 if (LocaleCompare("green-primary",option+1) == 0)
6871 {
6872 if (*option == '+')
6873 {
6874 (void) SetImageOption(image_info,option+1,"0.0");
6875 break;
6876 }
6877 (void) SetImageOption(image_info,option+1,argv[i+1]);
6878 break;
6879 }
6880 break;
6881 }
6882 case 'i':
6883 {
6884 if (LocaleCompare("intent",option+1) == 0)
6885 {
6886 if (*option == '+')
6887 {
6888 (void) SetImageOption(image_info,option+1,"undefined");
6889 break;
6890 }
6891 (void) SetImageOption(image_info,option+1,argv[i+1]);
6892 break;
6893 }
6894 if (LocaleCompare("interlace",option+1) == 0)
6895 {
6896 if (*option == '+')
6897 {
6898 image_info->interlace=UndefinedInterlace;
6899 (void) SetImageOption(image_info,option+1,"undefined");
6900 break;
6901 }
6902 image_info->interlace=(InterlaceType) ParseMagickOption(
6903 MagickInterlaceOptions,MagickFalse,argv[i+1]);
6904 (void) SetImageOption(image_info,option+1,argv[i+1]);
6905 break;
6906 }
cristyb32b90a2009-09-07 21:45:48 +00006907 if (LocaleCompare("interline-spacing",option+1) == 0)
6908 {
6909 if (*option == '+')
6910 {
6911 (void) SetImageOption(image_info,option+1,"undefined");
6912 break;
6913 }
6914 (void) SetImageOption(image_info,option+1,argv[i+1]);
6915 break;
6916 }
cristy3ed852e2009-09-05 21:47:34 +00006917 if (LocaleCompare("interpolate",option+1) == 0)
6918 {
6919 if (*option == '+')
6920 {
6921 (void) SetImageOption(image_info,option+1,"undefined");
6922 break;
6923 }
6924 (void) SetImageOption(image_info,option+1,argv[i+1]);
6925 break;
6926 }
6927 if (LocaleCompare("interword-spacing",option+1) == 0)
6928 {
6929 if (*option == '+')
6930 {
6931 (void) SetImageOption(image_info,option+1,"undefined");
6932 break;
6933 }
6934 (void) SetImageOption(image_info,option+1,argv[i+1]);
6935 break;
6936 }
6937 break;
6938 }
6939 case 'k':
6940 {
6941 if (LocaleCompare("kerning",option+1) == 0)
6942 {
6943 if (*option == '+')
6944 {
6945 (void) SetImageOption(image_info,option+1,"undefined");
6946 break;
6947 }
6948 (void) SetImageOption(image_info,option+1,argv[i+1]);
6949 break;
6950 }
6951 break;
6952 }
6953 case 'l':
6954 {
6955 if (LocaleCompare("label",option+1) == 0)
6956 {
6957 if (*option == '+')
6958 {
6959 (void) DeleteImageOption(image_info,option+1);
6960 break;
6961 }
6962 (void) SetImageOption(image_info,option+1,argv[i+1]);
6963 break;
6964 }
6965 if (LocaleCompare("limit",option+1) == 0)
6966 {
6967 MagickSizeType
6968 limit;
6969
6970 ResourceType
6971 type;
6972
6973 if (*option == '+')
6974 break;
6975 type=(ResourceType) ParseMagickOption(MagickResourceOptions,
6976 MagickFalse,argv[i+1]);
6977 limit=MagickResourceInfinity;
6978 if (LocaleCompare("unlimited",argv[i+2]) != 0)
cristyf2f27272009-12-17 14:48:46 +00006979 limit=(MagickSizeType) SiPrefixToDouble(argv[i+2],100.0);
cristy3ed852e2009-09-05 21:47:34 +00006980 (void) SetMagickResourceLimit(type,limit);
6981 break;
6982 }
6983 if (LocaleCompare("list",option+1) == 0)
6984 {
cristybb503372010-05-27 20:51:26 +00006985 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006986 list;
6987
6988 /*
6989 Display configuration list.
6990 */
6991 list=ParseMagickOption(MagickListOptions,MagickFalse,argv[i+1]);
6992 switch (list)
6993 {
6994 case MagickCoderOptions:
6995 {
6996 (void) ListCoderInfo((FILE *) NULL,exception);
6997 break;
6998 }
6999 case MagickColorOptions:
7000 {
7001 (void) ListColorInfo((FILE *) NULL,exception);
7002 break;
7003 }
7004 case MagickConfigureOptions:
7005 {
7006 (void) ListConfigureInfo((FILE *) NULL,exception);
7007 break;
7008 }
7009 case MagickDelegateOptions:
7010 {
7011 (void) ListDelegateInfo((FILE *) NULL,exception);
7012 break;
7013 }
7014 case MagickFontOptions:
7015 {
7016 (void) ListTypeInfo((FILE *) NULL,exception);
7017 break;
7018 }
7019 case MagickFormatOptions:
7020 {
7021 (void) ListMagickInfo((FILE *) NULL,exception);
7022 break;
7023 }
7024 case MagickLocaleOptions:
7025 {
7026 (void) ListLocaleInfo((FILE *) NULL,exception);
7027 break;
7028 }
7029 case MagickLogOptions:
7030 {
7031 (void) ListLogInfo((FILE *) NULL,exception);
7032 break;
7033 }
7034 case MagickMagicOptions:
7035 {
7036 (void) ListMagicInfo((FILE *) NULL,exception);
7037 break;
7038 }
7039 case MagickMimeOptions:
7040 {
7041 (void) ListMimeInfo((FILE *) NULL,exception);
7042 break;
7043 }
7044 case MagickModuleOptions:
7045 {
7046 (void) ListModuleInfo((FILE *) NULL,exception);
7047 break;
7048 }
7049 case MagickPolicyOptions:
7050 {
7051 (void) ListPolicyInfo((FILE *) NULL,exception);
7052 break;
7053 }
7054 case MagickResourceOptions:
7055 {
7056 (void) ListMagickResourceInfo((FILE *) NULL,exception);
7057 break;
7058 }
7059 case MagickThresholdOptions:
7060 {
7061 (void) ListThresholdMaps((FILE *) NULL,exception);
7062 break;
7063 }
7064 default:
7065 {
7066 (void) ListMagickOptions((FILE *) NULL,(MagickOption) list,
7067 exception);
7068 break;
7069 }
7070 }
cristyaeb2cbc2010-05-07 13:28:58 +00007071 break;
cristy3ed852e2009-09-05 21:47:34 +00007072 }
7073 if (LocaleCompare("log",option+1) == 0)
7074 {
7075 if (*option == '+')
7076 break;
7077 (void) SetLogFormat(argv[i+1]);
7078 break;
7079 }
7080 if (LocaleCompare("loop",option+1) == 0)
7081 {
7082 if (*option == '+')
7083 {
7084 (void) SetImageOption(image_info,option+1,"0");
7085 break;
7086 }
7087 (void) SetImageOption(image_info,option+1,argv[i+1]);
7088 break;
7089 }
7090 break;
7091 }
7092 case 'm':
7093 {
7094 if (LocaleCompare("matte",option+1) == 0)
7095 {
7096 if (*option == '+')
7097 {
7098 (void) SetImageOption(image_info,option+1,"false");
7099 break;
7100 }
7101 (void) SetImageOption(image_info,option+1,"true");
7102 break;
7103 }
7104 if (LocaleCompare("mattecolor",option+1) == 0)
7105 {
7106 if (*option == '+')
7107 {
7108 (void) SetImageOption(image_info,option+1,argv[i+1]);
7109 (void) QueryColorDatabase(MatteColor,&image_info->matte_color,
7110 exception);
7111 break;
7112 }
7113 (void) SetImageOption(image_info,option+1,argv[i+1]);
7114 (void) QueryColorDatabase(argv[i+1],&image_info->matte_color,
7115 exception);
7116 break;
7117 }
7118 if (LocaleCompare("monitor",option+1) == 0)
7119 {
7120 (void) SetImageInfoProgressMonitor(image_info,MonitorProgress,
7121 (void *) NULL);
7122 break;
7123 }
7124 if (LocaleCompare("monochrome",option+1) == 0)
7125 {
7126 image_info->monochrome=(*option == '-') ? MagickTrue : MagickFalse;
7127 break;
7128 }
7129 break;
7130 }
7131 case 'o':
7132 {
7133 if (LocaleCompare("orient",option+1) == 0)
7134 {
7135 if (*option == '+')
7136 {
7137 image_info->orientation=UndefinedOrientation;
7138 (void) SetImageOption(image_info,option+1,"undefined");
7139 break;
7140 }
7141 image_info->orientation=(OrientationType) ParseMagickOption(
7142 MagickOrientationOptions,MagickFalse,argv[i+1]);
cristyc6e214d2010-08-08 00:31:08 +00007143 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007144 break;
7145 }
7146 }
7147 case 'p':
7148 {
7149 if (LocaleCompare("page",option+1) == 0)
7150 {
7151 char
7152 *canonical_page,
7153 page[MaxTextExtent];
7154
7155 const char
7156 *image_option;
7157
7158 MagickStatusType
7159 flags;
7160
7161 RectangleInfo
7162 geometry;
7163
7164 if (*option == '+')
7165 {
7166 (void) DeleteImageOption(image_info,option+1);
7167 (void) CloneString(&image_info->page,(char *) NULL);
7168 break;
7169 }
7170 (void) ResetMagickMemory(&geometry,0,sizeof(geometry));
7171 image_option=GetImageOption(image_info,"page");
7172 if (image_option != (const char *) NULL)
7173 flags=ParseAbsoluteGeometry(image_option,&geometry);
7174 canonical_page=GetPageGeometry(argv[i+1]);
7175 flags=ParseAbsoluteGeometry(canonical_page,&geometry);
7176 canonical_page=DestroyString(canonical_page);
7177 (void) FormatMagickString(page,MaxTextExtent,"%lux%lu",
cristyf2faecf2010-05-28 19:19:36 +00007178 (unsigned long) geometry.width,(unsigned long) geometry.height);
cristy3ed852e2009-09-05 21:47:34 +00007179 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
7180 (void) FormatMagickString(page,MaxTextExtent,"%lux%lu%+ld%+ld",
cristyf2faecf2010-05-28 19:19:36 +00007181 (unsigned long) geometry.width,(unsigned long) geometry.height,
7182 (long) geometry.x,(long) geometry.y);
cristy3ed852e2009-09-05 21:47:34 +00007183 (void) SetImageOption(image_info,option+1,page);
7184 (void) CloneString(&image_info->page,page);
7185 break;
7186 }
7187 if (LocaleCompare("pen",option+1) == 0)
7188 {
7189 if (*option == '+')
7190 {
7191 (void) SetImageOption(image_info,option+1,"none");
7192 break;
7193 }
7194 (void) SetImageOption(image_info,option+1,argv[i+1]);
7195 break;
7196 }
7197 if (LocaleCompare("ping",option+1) == 0)
7198 {
7199 image_info->ping=(*option == '-') ? MagickTrue : MagickFalse;
7200 break;
7201 }
7202 if (LocaleCompare("pointsize",option+1) == 0)
7203 {
7204 if (*option == '+')
7205 geometry_info.rho=0.0;
7206 else
7207 (void) ParseGeometry(argv[i+1],&geometry_info);
7208 image_info->pointsize=geometry_info.rho;
7209 break;
7210 }
cristye7f51092010-01-17 00:39:37 +00007211 if (LocaleCompare("precision",option+1) == 0)
7212 {
cristybf2766a2010-01-17 03:33:23 +00007213 (void) SetMagickPrecision(StringToInteger(argv[i+1]));
cristye7f51092010-01-17 00:39:37 +00007214 break;
7215 }
cristy3ed852e2009-09-05 21:47:34 +00007216 if (LocaleCompare("preview",option+1) == 0)
7217 {
7218 /*
7219 Preview image.
7220 */
7221 if (*option == '+')
7222 {
7223 image_info->preview_type=UndefinedPreview;
7224 break;
7225 }
7226 image_info->preview_type=(PreviewType) ParseMagickOption(
7227 MagickPreviewOptions,MagickFalse,argv[i+1]);
7228 break;
7229 }
7230 break;
7231 }
7232 case 'q':
7233 {
7234 if (LocaleCompare("quality",option+1) == 0)
7235 {
7236 /*
7237 Set image compression quality.
7238 */
7239 if (*option == '+')
7240 {
7241 image_info->quality=UndefinedCompressionQuality;
7242 (void) SetImageOption(image_info,option+1,"0");
7243 break;
7244 }
cristye27293e2009-12-18 02:53:20 +00007245 image_info->quality=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007246 (void) SetImageOption(image_info,option+1,argv[i+1]);
7247 break;
7248 }
7249 if (LocaleCompare("quiet",option+1) == 0)
7250 {
7251 static WarningHandler
7252 warning_handler = (WarningHandler) NULL;
7253
7254 if (*option == '+')
7255 {
7256 /*
7257 Restore error or warning messages.
7258 */
7259 warning_handler=SetWarningHandler(warning_handler);
7260 break;
7261 }
7262 /*
7263 Suppress error or warning messages.
7264 */
7265 warning_handler=SetWarningHandler((WarningHandler) NULL);
7266 break;
7267 }
7268 break;
7269 }
7270 case 'r':
7271 {
7272 if (LocaleCompare("red-primary",option+1) == 0)
7273 {
7274 if (*option == '+')
7275 {
7276 (void) SetImageOption(image_info,option+1,"0.0");
7277 break;
7278 }
7279 (void) SetImageOption(image_info,option+1,argv[i+1]);
7280 break;
7281 }
7282 break;
7283 }
7284 case 's':
7285 {
7286 if (LocaleCompare("sampling-factor",option+1) == 0)
7287 {
7288 /*
7289 Set image sampling factor.
7290 */
7291 if (*option == '+')
7292 {
7293 if (image_info->sampling_factor != (char *) NULL)
7294 image_info->sampling_factor=DestroyString(
7295 image_info->sampling_factor);
7296 break;
7297 }
7298 (void) CloneString(&image_info->sampling_factor,argv[i+1]);
7299 break;
7300 }
7301 if (LocaleCompare("scene",option+1) == 0)
7302 {
7303 /*
7304 Set image scene.
7305 */
7306 if (*option == '+')
7307 {
7308 image_info->scene=0;
7309 (void) SetImageOption(image_info,option+1,"0");
7310 break;
7311 }
cristye27293e2009-12-18 02:53:20 +00007312 image_info->scene=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007313 (void) SetImageOption(image_info,option+1,argv[i+1]);
7314 break;
7315 }
7316 if (LocaleCompare("seed",option+1) == 0)
7317 {
cristybb503372010-05-27 20:51:26 +00007318 size_t
cristy3ed852e2009-09-05 21:47:34 +00007319 seed;
7320
7321 if (*option == '+')
7322 {
cristybb503372010-05-27 20:51:26 +00007323 seed=(size_t) time((time_t *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00007324 SeedPseudoRandomGenerator(seed);
7325 break;
7326 }
cristye27293e2009-12-18 02:53:20 +00007327 seed=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007328 SeedPseudoRandomGenerator(seed);
7329 break;
7330 }
7331 if (LocaleCompare("size",option+1) == 0)
7332 {
7333 if (*option == '+')
7334 {
7335 if (image_info->size != (char *) NULL)
7336 image_info->size=DestroyString(image_info->size);
7337 break;
7338 }
7339 (void) CloneString(&image_info->size,argv[i+1]);
7340 break;
7341 }
7342 if (LocaleCompare("stroke",option+1) == 0)
7343 {
7344 if (*option == '+')
7345 {
7346 (void) SetImageOption(image_info,option+1,"none");
7347 break;
7348 }
7349 (void) SetImageOption(image_info,option+1,argv[i+1]);
7350 break;
7351 }
7352 if (LocaleCompare("strokewidth",option+1) == 0)
7353 {
7354 if (*option == '+')
7355 {
7356 (void) SetImageOption(image_info,option+1,"0");
7357 break;
7358 }
7359 (void) SetImageOption(image_info,option+1,argv[i+1]);
7360 break;
7361 }
cristyd9a29192010-10-16 16:49:53 +00007362 if (LocaleCompare("synchronize",option+1) == 0)
7363 {
7364 if (*option == '+')
7365 {
7366 image_info->synchronize=MagickFalse;
7367 break;
7368 }
7369 image_info->synchronize=MagickTrue;
7370 break;
7371 }
cristy3ed852e2009-09-05 21:47:34 +00007372 break;
7373 }
7374 case 't':
7375 {
7376 if (LocaleCompare("taint",option+1) == 0)
7377 {
7378 if (*option == '+')
7379 {
7380 (void) SetImageOption(image_info,option+1,"false");
7381 break;
7382 }
7383 (void) SetImageOption(image_info,option+1,"true");
7384 break;
7385 }
7386 if (LocaleCompare("texture",option+1) == 0)
7387 {
7388 if (*option == '+')
7389 {
7390 if (image_info->texture != (char *) NULL)
7391 image_info->texture=DestroyString(image_info->texture);
7392 break;
7393 }
7394 (void) CloneString(&image_info->texture,argv[i+1]);
7395 break;
7396 }
7397 if (LocaleCompare("tile-offset",option+1) == 0)
7398 {
7399 if (*option == '+')
7400 {
7401 (void) SetImageOption(image_info,option+1,"0");
7402 break;
7403 }
7404 (void) SetImageOption(image_info,option+1,argv[i+1]);
7405 break;
7406 }
7407 if (LocaleCompare("transparent-color",option+1) == 0)
7408 {
7409 if (*option == '+')
7410 {
7411 (void) QueryColorDatabase("none",&image_info->transparent_color, exception);
7412 (void) SetImageOption(image_info,option+1,"none");
7413 break;
7414 }
7415 (void) QueryColorDatabase(argv[i+1],&image_info->transparent_color,
7416 exception);
7417 (void) SetImageOption(image_info,option+1,argv[i+1]);
7418 break;
7419 }
7420 if (LocaleCompare("type",option+1) == 0)
7421 {
7422 if (*option == '+')
7423 {
cristy5f1c1ff2010-12-23 21:38:06 +00007424 image_info->type=UndefinedType;
cristy3ed852e2009-09-05 21:47:34 +00007425 (void) SetImageOption(image_info,option+1,"undefined");
7426 break;
7427 }
7428 image_info->type=(ImageType) ParseMagickOption(MagickTypeOptions,
7429 MagickFalse,argv[i+1]);
7430 (void) SetImageOption(image_info,option+1,argv[i+1]);
7431 break;
7432 }
7433 break;
7434 }
7435 case 'u':
7436 {
7437 if (LocaleCompare("undercolor",option+1) == 0)
7438 {
7439 if (*option == '+')
7440 {
7441 (void) DeleteImageOption(image_info,option+1);
7442 break;
7443 }
7444 (void) SetImageOption(image_info,option+1,argv[i+1]);
7445 break;
7446 }
7447 if (LocaleCompare("units",option+1) == 0)
7448 {
7449 if (*option == '+')
7450 {
7451 image_info->units=UndefinedResolution;
7452 (void) SetImageOption(image_info,option+1,"undefined");
7453 break;
7454 }
7455 image_info->units=(ResolutionType) ParseMagickOption(
7456 MagickResolutionOptions,MagickFalse,argv[i+1]);
7457 (void) SetImageOption(image_info,option+1,argv[i+1]);
7458 break;
7459 }
7460 break;
7461 }
7462 case 'v':
7463 {
7464 if (LocaleCompare("verbose",option+1) == 0)
7465 {
7466 if (*option == '+')
7467 {
7468 image_info->verbose=MagickFalse;
7469 break;
7470 }
7471 image_info->verbose=MagickTrue;
7472 image_info->ping=MagickFalse;
7473 break;
7474 }
7475 if (LocaleCompare("view",option+1) == 0)
7476 {
7477 if (*option == '+')
7478 {
7479 if (image_info->view != (char *) NULL)
7480 image_info->view=DestroyString(image_info->view);
7481 break;
7482 }
7483 (void) CloneString(&image_info->view,argv[i+1]);
7484 break;
7485 }
7486 if (LocaleCompare("virtual-pixel",option+1) == 0)
7487 {
7488 if (*option == '+')
7489 {
7490 image_info->virtual_pixel_method=UndefinedVirtualPixelMethod;
7491 (void) SetImageOption(image_info,option+1,"undefined");
7492 break;
7493 }
7494 image_info->virtual_pixel_method=(VirtualPixelMethod)
7495 ParseMagickOption(MagickVirtualPixelOptions,MagickFalse,
7496 argv[i+1]);
7497 (void) SetImageOption(image_info,option+1,argv[i+1]);
7498 break;
7499 }
7500 break;
7501 }
7502 case 'w':
7503 {
7504 if (LocaleCompare("white-point",option+1) == 0)
7505 {
7506 if (*option == '+')
7507 {
7508 (void) SetImageOption(image_info,option+1,"0.0");
7509 break;
7510 }
7511 (void) SetImageOption(image_info,option+1,argv[i+1]);
7512 break;
7513 }
7514 break;
7515 }
7516 default:
7517 break;
7518 }
7519 i+=count;
7520 }
7521 return(MagickTrue);
7522}
7523
7524/*
7525%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7526% %
7527% %
7528% %
7529+ M o g r i f y I m a g e L i s t %
7530% %
7531% %
7532% %
7533%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7534%
7535% MogrifyImageList() applies any command line options that might affect the
7536% entire image list (e.g. -append, -coalesce, etc.).
7537%
7538% The format of the MogrifyImage method is:
7539%
7540% MagickBooleanType MogrifyImageList(ImageInfo *image_info,const int argc,
7541% const char **argv,Image **images,ExceptionInfo *exception)
7542%
7543% A description of each parameter follows:
7544%
7545% o image_info: the image info..
7546%
7547% o argc: Specifies a pointer to an integer describing the number of
7548% elements in the argument vector.
7549%
7550% o argv: Specifies a pointer to a text array containing the command line
7551% arguments.
7552%
7553% o images: the images.
7554%
7555% o exception: return any errors or warnings in this structure.
7556%
7557*/
7558WandExport MagickBooleanType MogrifyImageList(ImageInfo *image_info,
7559 const int argc,const char **argv,Image **images,ExceptionInfo *exception)
7560{
7561 ChannelType
7562 channel;
7563
7564 const char
7565 *option;
7566
cristy6b3da3a2010-06-20 02:21:46 +00007567 ImageInfo
7568 *mogrify_info;
cristy3ed852e2009-09-05 21:47:34 +00007569
7570 MagickStatusType
7571 status;
7572
7573 QuantizeInfo
7574 *quantize_info;
7575
cristybb503372010-05-27 20:51:26 +00007576 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00007577 i;
7578
cristy6b3da3a2010-06-20 02:21:46 +00007579 ssize_t
7580 count,
7581 index;
7582
cristy3ed852e2009-09-05 21:47:34 +00007583 /*
7584 Apply options to the image list.
7585 */
7586 assert(image_info != (ImageInfo *) NULL);
7587 assert(image_info->signature == MagickSignature);
7588 assert(images != (Image **) NULL);
7589 assert((*images)->signature == MagickSignature);
7590 if ((*images)->debug != MagickFalse)
7591 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
7592 (*images)->filename);
7593 if ((argc <= 0) || (*argv == (char *) NULL))
7594 return(MagickTrue);
cristy6b3da3a2010-06-20 02:21:46 +00007595 mogrify_info=CloneImageInfo(image_info);
7596 quantize_info=AcquireQuantizeInfo(mogrify_info);
7597 channel=mogrify_info->channel;
cristy3ed852e2009-09-05 21:47:34 +00007598 status=MagickTrue;
cristybb503372010-05-27 20:51:26 +00007599 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00007600 {
cristy74fe8f12009-10-03 19:09:01 +00007601 if (*images == (Image *) NULL)
7602 break;
cristy3ed852e2009-09-05 21:47:34 +00007603 option=argv[i];
7604 if (IsMagickOption(option) == MagickFalse)
7605 continue;
7606 count=MagickMax(ParseMagickOption(MagickCommandOptions,MagickFalse,option),
7607 0L);
cristycee97112010-05-28 00:44:52 +00007608 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00007609 break;
cristy6b3da3a2010-06-20 02:21:46 +00007610 status=MogrifyImageInfo(mogrify_info,(int) count+1,argv+i,exception);
cristy3ed852e2009-09-05 21:47:34 +00007611 switch (*(option+1))
7612 {
7613 case 'a':
7614 {
7615 if (LocaleCompare("affinity",option+1) == 0)
7616 {
cristy6b3da3a2010-06-20 02:21:46 +00007617 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007618 if (*option == '+')
7619 {
7620 (void) RemapImages(quantize_info,*images,(Image *) NULL);
7621 InheritException(exception,&(*images)->exception);
7622 break;
7623 }
7624 i++;
7625 break;
7626 }
7627 if (LocaleCompare("append",option+1) == 0)
7628 {
7629 Image
7630 *append_image;
7631
cristy6b3da3a2010-06-20 02:21:46 +00007632 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007633 append_image=AppendImages(*images,*option == '-' ? MagickTrue :
7634 MagickFalse,exception);
7635 if (append_image == (Image *) NULL)
7636 {
7637 status=MagickFalse;
7638 break;
7639 }
7640 *images=DestroyImageList(*images);
7641 *images=append_image;
7642 break;
7643 }
7644 if (LocaleCompare("average",option+1) == 0)
7645 {
7646 Image
7647 *average_image;
7648
cristyd18ae7c2010-03-07 17:39:52 +00007649 /*
7650 Average an image sequence (deprecated).
7651 */
cristy6b3da3a2010-06-20 02:21:46 +00007652 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007653 average_image=EvaluateImages(*images,MeanEvaluateOperator,
7654 exception);
cristy3ed852e2009-09-05 21:47:34 +00007655 if (average_image == (Image *) NULL)
7656 {
7657 status=MagickFalse;
7658 break;
7659 }
7660 *images=DestroyImageList(*images);
7661 *images=average_image;
7662 break;
7663 }
7664 break;
7665 }
7666 case 'c':
7667 {
7668 if (LocaleCompare("channel",option+1) == 0)
7669 {
7670 if (*option == '+')
7671 {
7672 channel=DefaultChannels;
7673 break;
7674 }
7675 channel=(ChannelType) ParseChannelOption(argv[i+1]);
7676 break;
7677 }
7678 if (LocaleCompare("clut",option+1) == 0)
7679 {
7680 Image
7681 *clut_image,
7682 *image;
7683
cristy6b3da3a2010-06-20 02:21:46 +00007684 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007685 image=RemoveFirstImageFromList(images);
7686 clut_image=RemoveFirstImageFromList(images);
7687 if (clut_image == (Image *) NULL)
7688 {
7689 status=MagickFalse;
7690 break;
7691 }
7692 (void) ClutImageChannel(image,channel,clut_image);
7693 clut_image=DestroyImage(clut_image);
7694 InheritException(exception,&image->exception);
7695 *images=DestroyImageList(*images);
7696 *images=image;
7697 break;
7698 }
7699 if (LocaleCompare("coalesce",option+1) == 0)
7700 {
7701 Image
7702 *coalesce_image;
7703
cristy6b3da3a2010-06-20 02:21:46 +00007704 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007705 coalesce_image=CoalesceImages(*images,exception);
7706 if (coalesce_image == (Image *) NULL)
7707 {
7708 status=MagickFalse;
7709 break;
7710 }
7711 *images=DestroyImageList(*images);
7712 *images=coalesce_image;
7713 break;
7714 }
7715 if (LocaleCompare("combine",option+1) == 0)
7716 {
7717 Image
7718 *combine_image;
7719
cristy6b3da3a2010-06-20 02:21:46 +00007720 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007721 combine_image=CombineImages(*images,channel,exception);
7722 if (combine_image == (Image *) NULL)
7723 {
7724 status=MagickFalse;
7725 break;
7726 }
7727 *images=DestroyImageList(*images);
7728 *images=combine_image;
7729 break;
7730 }
7731 if (LocaleCompare("composite",option+1) == 0)
7732 {
7733 Image
7734 *mask_image,
7735 *composite_image,
7736 *image;
7737
7738 RectangleInfo
7739 geometry;
7740
cristy6b3da3a2010-06-20 02:21:46 +00007741 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007742 image=RemoveFirstImageFromList(images);
7743 composite_image=RemoveFirstImageFromList(images);
7744 if (composite_image == (Image *) NULL)
7745 {
7746 status=MagickFalse;
7747 break;
7748 }
7749 (void) TransformImage(&composite_image,(char *) NULL,
7750 composite_image->geometry);
7751 SetGeometry(composite_image,&geometry);
7752 (void) ParseAbsoluteGeometry(composite_image->geometry,&geometry);
7753 GravityAdjustGeometry(image->columns,image->rows,image->gravity,
7754 &geometry);
7755 mask_image=RemoveFirstImageFromList(images);
7756 if (mask_image != (Image *) NULL)
7757 {
7758 if ((image->compose == DisplaceCompositeOp) ||
7759 (image->compose == DistortCompositeOp))
7760 {
7761 /*
7762 Merge Y displacement into X displacement image.
7763 */
7764 (void) CompositeImage(composite_image,CopyGreenCompositeOp,
7765 mask_image,0,0);
7766 mask_image=DestroyImage(mask_image);
7767 }
7768 else
7769 {
7770 /*
7771 Set a blending mask for the composition.
7772 */
7773 image->mask=mask_image;
7774 (void) NegateImage(image->mask,MagickFalse);
7775 }
7776 }
7777 (void) CompositeImageChannel(image,channel,image->compose,
7778 composite_image,geometry.x,geometry.y);
7779 if (image->mask != (Image *) NULL)
7780 image->mask=DestroyImage(image->mask);
7781 composite_image=DestroyImage(composite_image);
7782 InheritException(exception,&image->exception);
7783 *images=DestroyImageList(*images);
7784 *images=image;
7785 break;
7786 }
7787 if (LocaleCompare("crop",option+1) == 0)
7788 {
7789 MagickStatusType
7790 flags;
7791
7792 RectangleInfo
7793 geometry;
7794
cristy6b3da3a2010-06-20 02:21:46 +00007795 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007796 flags=ParseGravityGeometry(*images,argv[i+1],&geometry,exception);
7797 if (((geometry.width == 0) && (geometry.height == 0)) ||
7798 ((flags & XValue) != 0) || ((flags & YValue) != 0))
7799 break;
7800 (void) TransformImages(images,argv[i+1],(char *) NULL);
7801 InheritException(exception,&(*images)->exception);
7802 break;
7803 }
7804 break;
7805 }
7806 case 'd':
7807 {
7808 if (LocaleCompare("deconstruct",option+1) == 0)
7809 {
7810 Image
7811 *deconstruct_image;
7812
cristy6b3da3a2010-06-20 02:21:46 +00007813 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007814 deconstruct_image=DeconstructImages(*images,exception);
7815 if (deconstruct_image == (Image *) NULL)
7816 {
7817 status=MagickFalse;
7818 break;
7819 }
7820 *images=DestroyImageList(*images);
7821 *images=deconstruct_image;
7822 break;
7823 }
7824 if (LocaleCompare("delete",option+1) == 0)
7825 {
7826 if (*option == '+')
7827 DeleteImages(images,"-1",exception);
7828 else
7829 DeleteImages(images,argv[i+1],exception);
7830 break;
7831 }
7832 if (LocaleCompare("dither",option+1) == 0)
7833 {
7834 if (*option == '+')
7835 {
7836 quantize_info->dither=MagickFalse;
7837 break;
7838 }
7839 quantize_info->dither=MagickTrue;
7840 quantize_info->dither_method=(DitherMethod) ParseMagickOption(
7841 MagickDitherOptions,MagickFalse,argv[i+1]);
7842 break;
7843 }
7844 break;
7845 }
cristyd18ae7c2010-03-07 17:39:52 +00007846 case 'e':
7847 {
7848 if (LocaleCompare("evaluate-sequence",option+1) == 0)
7849 {
7850 Image
7851 *evaluate_image;
7852
7853 MagickEvaluateOperator
7854 op;
7855
cristy6b3da3a2010-06-20 02:21:46 +00007856 (void) SyncImageSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007857 op=(MagickEvaluateOperator) ParseMagickOption(MagickEvaluateOptions,
7858 MagickFalse,argv[i+1]);
7859 evaluate_image=EvaluateImages(*images,op,exception);
7860 if (evaluate_image == (Image *) NULL)
7861 {
7862 status=MagickFalse;
7863 break;
7864 }
7865 *images=DestroyImageList(*images);
7866 *images=evaluate_image;
7867 break;
7868 }
7869 break;
7870 }
cristy3ed852e2009-09-05 21:47:34 +00007871 case 'f':
7872 {
cristyf0a247f2009-10-04 00:20:03 +00007873 if (LocaleCompare("fft",option+1) == 0)
7874 {
7875 Image
7876 *fourier_image;
7877
7878 /*
7879 Implements the discrete Fourier transform (DFT).
7880 */
cristy6b3da3a2010-06-20 02:21:46 +00007881 (void) SyncImageSettings(mogrify_info,*images);
cristyf0a247f2009-10-04 00:20:03 +00007882 fourier_image=ForwardFourierTransformImage(*images,*option == '-' ?
7883 MagickTrue : MagickFalse,exception);
7884 if (fourier_image == (Image *) NULL)
7885 break;
7886 *images=DestroyImage(*images);
7887 *images=fourier_image;
7888 break;
7889 }
cristy3ed852e2009-09-05 21:47:34 +00007890 if (LocaleCompare("flatten",option+1) == 0)
7891 {
7892 Image
7893 *flatten_image;
7894
cristy6b3da3a2010-06-20 02:21:46 +00007895 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007896 flatten_image=MergeImageLayers(*images,FlattenLayer,exception);
7897 if (flatten_image == (Image *) NULL)
7898 break;
7899 *images=DestroyImageList(*images);
7900 *images=flatten_image;
7901 break;
7902 }
7903 if (LocaleCompare("fx",option+1) == 0)
7904 {
7905 Image
7906 *fx_image;
7907
cristy6b3da3a2010-06-20 02:21:46 +00007908 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007909 fx_image=FxImageChannel(*images,channel,argv[i+1],exception);
7910 if (fx_image == (Image *) NULL)
7911 {
7912 status=MagickFalse;
7913 break;
7914 }
7915 *images=DestroyImageList(*images);
7916 *images=fx_image;
7917 break;
7918 }
7919 break;
7920 }
7921 case 'h':
7922 {
7923 if (LocaleCompare("hald-clut",option+1) == 0)
7924 {
7925 Image
7926 *hald_image,
7927 *image;
7928
cristy6b3da3a2010-06-20 02:21:46 +00007929 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007930 image=RemoveFirstImageFromList(images);
7931 hald_image=RemoveFirstImageFromList(images);
7932 if (hald_image == (Image *) NULL)
7933 {
7934 status=MagickFalse;
7935 break;
7936 }
7937 (void) HaldClutImageChannel(image,channel,hald_image);
7938 hald_image=DestroyImage(hald_image);
7939 InheritException(exception,&image->exception);
cristy0aff6ea2009-11-14 01:40:53 +00007940 if (*images != (Image *) NULL)
7941 *images=DestroyImageList(*images);
cristy3ed852e2009-09-05 21:47:34 +00007942 *images=image;
7943 break;
7944 }
7945 break;
7946 }
7947 case 'i':
7948 {
7949 if (LocaleCompare("ift",option+1) == 0)
7950 {
7951 Image
cristy8587f882009-11-13 20:28:49 +00007952 *fourier_image,
7953 *magnitude_image,
7954 *phase_image;
cristy3ed852e2009-09-05 21:47:34 +00007955
7956 /*
7957 Implements the inverse fourier discrete Fourier transform (DFT).
7958 */
cristy6b3da3a2010-06-20 02:21:46 +00007959 (void) SyncImagesSettings(mogrify_info,*images);
cristy8587f882009-11-13 20:28:49 +00007960 magnitude_image=RemoveFirstImageFromList(images);
7961 phase_image=RemoveFirstImageFromList(images);
7962 if (phase_image == (Image *) NULL)
7963 {
7964 status=MagickFalse;
7965 break;
7966 }
7967 fourier_image=InverseFourierTransformImage(magnitude_image,
7968 phase_image,*option == '-' ? MagickTrue : MagickFalse,exception);
cristy3ed852e2009-09-05 21:47:34 +00007969 if (fourier_image == (Image *) NULL)
7970 break;
cristy0aff6ea2009-11-14 01:40:53 +00007971 if (*images != (Image *) NULL)
7972 *images=DestroyImage(*images);
cristy3ed852e2009-09-05 21:47:34 +00007973 *images=fourier_image;
7974 break;
7975 }
7976 if (LocaleCompare("insert",option+1) == 0)
7977 {
7978 Image
7979 *p,
7980 *q;
7981
7982 index=0;
7983 if (*option != '+')
cristy32c2aea2010-12-01 01:00:50 +00007984 index=(ssize_t) StringToLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007985 p=RemoveLastImageFromList(images);
7986 if (p == (Image *) NULL)
7987 {
7988 (void) ThrowMagickException(exception,GetMagickModule(),
7989 OptionError,"NoSuchImage","`%s'",argv[i+1]);
7990 status=MagickFalse;
7991 break;
7992 }
7993 q=p;
7994 if (index == 0)
7995 PrependImageToList(images,q);
7996 else
cristybb503372010-05-27 20:51:26 +00007997 if (index == (ssize_t) GetImageListLength(*images))
cristy3ed852e2009-09-05 21:47:34 +00007998 AppendImageToList(images,q);
7999 else
8000 {
8001 q=GetImageFromList(*images,index-1);
8002 if (q == (Image *) NULL)
8003 {
8004 (void) ThrowMagickException(exception,GetMagickModule(),
8005 OptionError,"NoSuchImage","`%s'",argv[i+1]);
8006 status=MagickFalse;
8007 break;
8008 }
8009 InsertImageInList(&q,p);
8010 }
8011 *images=GetFirstImageInList(q);
8012 break;
8013 }
8014 break;
8015 }
8016 case 'l':
8017 {
8018 if (LocaleCompare("layers",option+1) == 0)
8019 {
8020 Image
8021 *layers;
8022
8023 ImageLayerMethod
8024 method;
8025
cristy6b3da3a2010-06-20 02:21:46 +00008026 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00008027 layers=(Image *) NULL;
8028 method=(ImageLayerMethod) ParseMagickOption(MagickLayerOptions,
8029 MagickFalse,argv[i+1]);
8030 switch (method)
8031 {
8032 case CoalesceLayer:
8033 {
8034 layers=CoalesceImages(*images,exception);
8035 break;
8036 }
8037 case CompareAnyLayer:
8038 case CompareClearLayer:
8039 case CompareOverlayLayer:
8040 default:
8041 {
8042 layers=CompareImageLayers(*images,method,exception);
8043 break;
8044 }
8045 case MergeLayer:
8046 case FlattenLayer:
8047 case MosaicLayer:
8048 case TrimBoundsLayer:
8049 {
8050 layers=MergeImageLayers(*images,method,exception);
8051 break;
8052 }
8053 case DisposeLayer:
8054 {
8055 layers=DisposeImages(*images,exception);
8056 break;
8057 }
8058 case OptimizeImageLayer:
8059 {
8060 layers=OptimizeImageLayers(*images,exception);
8061 break;
8062 }
8063 case OptimizePlusLayer:
8064 {
8065 layers=OptimizePlusImageLayers(*images,exception);
8066 break;
8067 }
8068 case OptimizeTransLayer:
8069 {
8070 OptimizeImageTransparency(*images,exception);
8071 break;
8072 }
8073 case RemoveDupsLayer:
8074 {
8075 RemoveDuplicateLayers(images,exception);
8076 break;
8077 }
8078 case RemoveZeroLayer:
8079 {
8080 RemoveZeroDelayLayers(images,exception);
8081 break;
8082 }
8083 case OptimizeLayer:
8084 {
8085 /*
8086 General Purpose, GIF Animation Optimizer.
8087 */
8088 layers=CoalesceImages(*images,exception);
8089 if (layers == (Image *) NULL)
8090 {
8091 status=MagickFalse;
8092 break;
8093 }
8094 InheritException(exception,&layers->exception);
8095 *images=DestroyImageList(*images);
8096 *images=layers;
8097 layers=OptimizeImageLayers(*images,exception);
8098 if (layers == (Image *) NULL)
8099 {
8100 status=MagickFalse;
8101 break;
8102 }
8103 InheritException(exception,&layers->exception);
8104 *images=DestroyImageList(*images);
8105 *images=layers;
8106 layers=(Image *) NULL;
8107 OptimizeImageTransparency(*images,exception);
8108 InheritException(exception,&(*images)->exception);
8109 (void) RemapImages(quantize_info,*images,(Image *) NULL);
8110 break;
8111 }
8112 case CompositeLayer:
8113 {
8114 CompositeOperator
8115 compose;
8116
8117 Image
8118 *source;
8119
8120 RectangleInfo
8121 geometry;
8122
8123 /*
8124 Split image sequence at the first 'NULL:' image.
8125 */
8126 source=(*images);
8127 while (source != (Image *) NULL)
8128 {
8129 source=GetNextImageInList(source);
8130 if ((source != (Image *) NULL) &&
8131 (LocaleCompare(source->magick,"NULL") == 0))
8132 break;
8133 }
8134 if (source != (Image *) NULL)
8135 {
8136 if ((GetPreviousImageInList(source) == (Image *) NULL) ||
8137 (GetNextImageInList(source) == (Image *) NULL))
8138 source=(Image *) NULL;
8139 else
8140 {
8141 /*
8142 Separate the two lists, junk the null: image.
8143 */
8144 source=SplitImageList(source->previous);
8145 DeleteImageFromList(&source);
8146 }
8147 }
8148 if (source == (Image *) NULL)
8149 {
8150 (void) ThrowMagickException(exception,GetMagickModule(),
8151 OptionError,"MissingNullSeparator","layers Composite");
8152 status=MagickFalse;
8153 break;
8154 }
8155 /*
8156 Adjust offset with gravity and virtual canvas.
8157 */
8158 SetGeometry(*images,&geometry);
8159 (void) ParseAbsoluteGeometry((*images)->geometry,&geometry);
8160 geometry.width=source->page.width != 0 ?
8161 source->page.width : source->columns;
8162 geometry.height=source->page.height != 0 ?
8163 source->page.height : source->rows;
8164 GravityAdjustGeometry((*images)->page.width != 0 ?
8165 (*images)->page.width : (*images)->columns,
8166 (*images)->page.height != 0 ? (*images)->page.height :
8167 (*images)->rows,(*images)->gravity,&geometry);
8168 compose=OverCompositeOp;
cristy6b3da3a2010-06-20 02:21:46 +00008169 option=GetImageOption(mogrify_info,"compose");
cristy3ed852e2009-09-05 21:47:34 +00008170 if (option != (const char *) NULL)
8171 compose=(CompositeOperator) ParseMagickOption(
8172 MagickComposeOptions,MagickFalse,option);
8173 CompositeLayers(*images,compose,source,geometry.x,geometry.y,
8174 exception);
8175 source=DestroyImageList(source);
8176 break;
8177 }
8178 }
8179 if (layers == (Image *) NULL)
8180 break;
8181 InheritException(exception,&layers->exception);
8182 *images=DestroyImageList(*images);
8183 *images=layers;
8184 break;
8185 }
8186 break;
8187 }
8188 case 'm':
8189 {
8190 if (LocaleCompare("map",option+1) == 0)
8191 {
cristy6b3da3a2010-06-20 02:21:46 +00008192 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00008193 if (*option == '+')
8194 {
8195 (void) RemapImages(quantize_info,*images,(Image *) NULL);
8196 InheritException(exception,&(*images)->exception);
8197 break;
8198 }
8199 i++;
8200 break;
8201 }
cristyf40785b2010-03-06 02:27:27 +00008202 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00008203 {
8204 Image
cristyf40785b2010-03-06 02:27:27 +00008205 *maximum_image;
cristy1c274c92010-03-06 02:06:45 +00008206
cristyd18ae7c2010-03-07 17:39:52 +00008207 /*
8208 Maximum image sequence (deprecated).
8209 */
cristy6b3da3a2010-06-20 02:21:46 +00008210 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00008211 maximum_image=EvaluateImages(*images,MaxEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00008212 if (maximum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00008213 {
8214 status=MagickFalse;
8215 break;
8216 }
8217 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00008218 *images=maximum_image;
cristy1c274c92010-03-06 02:06:45 +00008219 break;
8220 }
cristyf40785b2010-03-06 02:27:27 +00008221 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00008222 {
8223 Image
cristyf40785b2010-03-06 02:27:27 +00008224 *minimum_image;
cristy1c274c92010-03-06 02:06:45 +00008225
cristyd18ae7c2010-03-07 17:39:52 +00008226 /*
8227 Minimum image sequence (deprecated).
8228 */
cristy6b3da3a2010-06-20 02:21:46 +00008229 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00008230 minimum_image=EvaluateImages(*images,MinEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00008231 if (minimum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00008232 {
8233 status=MagickFalse;
8234 break;
8235 }
8236 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00008237 *images=minimum_image;
cristy1c274c92010-03-06 02:06:45 +00008238 break;
8239 }
cristy3ed852e2009-09-05 21:47:34 +00008240 if (LocaleCompare("morph",option+1) == 0)
8241 {
8242 Image
8243 *morph_image;
8244
cristy6b3da3a2010-06-20 02:21:46 +00008245 (void) SyncImagesSettings(mogrify_info,*images);
cristye27293e2009-12-18 02:53:20 +00008246 morph_image=MorphImages(*images,StringToUnsignedLong(argv[i+1]),
cristy3ed852e2009-09-05 21:47:34 +00008247 exception);
8248 if (morph_image == (Image *) NULL)
8249 {
8250 status=MagickFalse;
8251 break;
8252 }
8253 *images=DestroyImageList(*images);
8254 *images=morph_image;
8255 break;
8256 }
8257 if (LocaleCompare("mosaic",option+1) == 0)
8258 {
8259 Image
8260 *mosaic_image;
8261
cristy6b3da3a2010-06-20 02:21:46 +00008262 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00008263 mosaic_image=MergeImageLayers(*images,MosaicLayer,exception);
8264 if (mosaic_image == (Image *) NULL)
8265 {
8266 status=MagickFalse;
8267 break;
8268 }
8269 *images=DestroyImageList(*images);
8270 *images=mosaic_image;
8271 break;
8272 }
8273 break;
8274 }
8275 case 'p':
8276 {
8277 if (LocaleCompare("print",option+1) == 0)
8278 {
8279 char
8280 *string;
8281
cristy6b3da3a2010-06-20 02:21:46 +00008282 (void) SyncImagesSettings(mogrify_info,*images);
8283 string=InterpretImageProperties(mogrify_info,*images,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00008284 if (string == (char *) NULL)
8285 break;
8286 InheritException(exception,&(*images)->exception);
8287 (void) fprintf(stdout,"%s",string);
8288 string=DestroyString(string);
8289 }
8290 if (LocaleCompare("process",option+1) == 0)
8291 {
8292 char
8293 **arguments;
8294
8295 int
8296 j,
8297 number_arguments;
8298
cristy6b3da3a2010-06-20 02:21:46 +00008299 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00008300 arguments=StringToArgv(argv[i+1],&number_arguments);
8301 if (arguments == (char **) NULL)
8302 break;
8303 if ((argc > 1) && (strchr(arguments[1],'=') != (char *) NULL))
8304 {
8305 char
8306 breaker,
8307 quote,
8308 *token;
8309
8310 const char
8311 *arguments;
8312
8313 int
8314 next,
8315 status;
8316
8317 size_t
8318 length;
8319
8320 TokenInfo
8321 *token_info;
8322
8323 /*
8324 Support old style syntax, filter="-option arg".
8325 */
8326 length=strlen(argv[i+1]);
8327 token=(char *) NULL;
8328 if (~length >= MaxTextExtent)
8329 token=(char *) AcquireQuantumMemory(length+MaxTextExtent,
8330 sizeof(*token));
8331 if (token == (char *) NULL)
8332 break;
8333 next=0;
8334 arguments=argv[i+1];
8335 token_info=AcquireTokenInfo();
8336 status=Tokenizer(token_info,0,token,length,arguments,"","=",
8337 "\"",'\0',&breaker,&next,&quote);
8338 token_info=DestroyTokenInfo(token_info);
8339 if (status == 0)
8340 {
8341 const char
8342 *argv;
8343
8344 argv=(&(arguments[next]));
8345 (void) InvokeDynamicImageFilter(token,&(*images),1,&argv,
8346 exception);
8347 }
8348 token=DestroyString(token);
8349 break;
8350 }
cristy91c0da22010-05-02 01:44:07 +00008351 (void) SubstituteString(&arguments[1],"-","");
cristy3ed852e2009-09-05 21:47:34 +00008352 (void) InvokeDynamicImageFilter(arguments[1],&(*images),
8353 number_arguments-2,(const char **) arguments+2,exception);
8354 for (j=0; j < number_arguments; j++)
8355 arguments[j]=DestroyString(arguments[j]);
8356 arguments=(char **) RelinquishMagickMemory(arguments);
8357 break;
8358 }
8359 break;
8360 }
8361 case 'r':
8362 {
8363 if (LocaleCompare("reverse",option+1) == 0)
8364 {
8365 ReverseImageList(images);
8366 InheritException(exception,&(*images)->exception);
8367 break;
8368 }
8369 break;
8370 }
8371 case 's':
8372 {
cristy4285d782011-02-09 20:12:28 +00008373 if (LocaleCompare("smush",option+1) == 0)
8374 {
8375 Image
8376 *smush_image;
8377
8378 ssize_t
8379 offset;
8380
8381 (void) SyncImagesSettings(mogrify_info,*images);
8382 offset=(ssize_t) StringToLong(argv[i+1]);
8383 smush_image=SmushImages(*images,*option == '-' ? MagickTrue :
8384 MagickFalse,offset,exception);
8385 if (smush_image == (Image *) NULL)
8386 {
8387 status=MagickFalse;
8388 break;
8389 }
8390 *images=DestroyImageList(*images);
8391 *images=smush_image;
8392 break;
8393 }
cristy3ed852e2009-09-05 21:47:34 +00008394 if (LocaleCompare("swap",option+1) == 0)
8395 {
8396 Image
8397 *p,
8398 *q,
8399 *swap;
8400
cristybb503372010-05-27 20:51:26 +00008401 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00008402 swap_index;
8403
8404 index=(-1);
8405 swap_index=(-2);
8406 if (*option != '+')
8407 {
8408 GeometryInfo
8409 geometry_info;
8410
8411 MagickStatusType
8412 flags;
8413
8414 swap_index=(-1);
8415 flags=ParseGeometry(argv[i+1],&geometry_info);
cristybb503372010-05-27 20:51:26 +00008416 index=(ssize_t) geometry_info.rho;
cristy3ed852e2009-09-05 21:47:34 +00008417 if ((flags & SigmaValue) != 0)
cristybb503372010-05-27 20:51:26 +00008418 swap_index=(ssize_t) geometry_info.sigma;
cristy3ed852e2009-09-05 21:47:34 +00008419 }
8420 p=GetImageFromList(*images,index);
8421 q=GetImageFromList(*images,swap_index);
8422 if ((p == (Image *) NULL) || (q == (Image *) NULL))
8423 {
8424 (void) ThrowMagickException(exception,GetMagickModule(),
8425 OptionError,"NoSuchImage","`%s'",(*images)->filename);
8426 status=MagickFalse;
8427 break;
8428 }
8429 if (p == q)
8430 break;
8431 swap=CloneImage(p,0,0,MagickTrue,exception);
8432 ReplaceImageInList(&p,CloneImage(q,0,0,MagickTrue,exception));
8433 ReplaceImageInList(&q,swap);
8434 *images=GetFirstImageInList(q);
8435 break;
8436 }
8437 break;
8438 }
8439 case 'w':
8440 {
8441 if (LocaleCompare("write",option+1) == 0)
8442 {
cristy071dd7b2010-04-09 13:04:54 +00008443 char
cristy06609ee2010-03-17 20:21:27 +00008444 key[MaxTextExtent];
8445
cristy3ed852e2009-09-05 21:47:34 +00008446 Image
8447 *write_images;
8448
8449 ImageInfo
8450 *write_info;
8451
cristy6b3da3a2010-06-20 02:21:46 +00008452 (void) SyncImagesSettings(mogrify_info,*images);
cristy06609ee2010-03-17 20:21:27 +00008453 (void) FormatMagickString(key,MaxTextExtent,"cache:%s",argv[i+1]);
8454 (void) DeleteImageRegistry(key);
cristy3ed852e2009-09-05 21:47:34 +00008455 write_images=(*images);
8456 if (*option == '+')
8457 write_images=CloneImageList(*images,exception);
cristy6b3da3a2010-06-20 02:21:46 +00008458 write_info=CloneImageInfo(mogrify_info);
cristy3ed852e2009-09-05 21:47:34 +00008459 status&=WriteImages(write_info,write_images,argv[i+1],exception);
8460 write_info=DestroyImageInfo(write_info);
8461 if (*option == '+')
8462 write_images=DestroyImageList(write_images);
8463 break;
8464 }
8465 break;
8466 }
8467 default:
8468 break;
8469 }
8470 i+=count;
8471 }
8472 quantize_info=DestroyQuantizeInfo(quantize_info);
cristy6b3da3a2010-06-20 02:21:46 +00008473 mogrify_info=DestroyImageInfo(mogrify_info);
8474 status&=MogrifyImageInfo(image_info,argc,argv,exception);
cristy3ed852e2009-09-05 21:47:34 +00008475 return(status != 0 ? MagickTrue : MagickFalse);
8476}
8477
8478/*
8479%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8480% %
8481% %
8482% %
8483+ M o g r i f y I m a g e s %
8484% %
8485% %
8486% %
8487%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8488%
8489% MogrifyImages() applies image processing options to a sequence of images as
8490% prescribed by command line options.
8491%
8492% The format of the MogrifyImage method is:
8493%
8494% MagickBooleanType MogrifyImages(ImageInfo *image_info,
8495% const MagickBooleanType post,const int argc,const char **argv,
8496% Image **images,Exceptioninfo *exception)
8497%
8498% A description of each parameter follows:
8499%
8500% o image_info: the image info..
8501%
8502% o post: If true, post process image list operators otherwise pre-process.
8503%
8504% o argc: Specifies a pointer to an integer describing the number of
8505% elements in the argument vector.
8506%
8507% o argv: Specifies a pointer to a text array containing the command line
8508% arguments.
8509%
8510% o images: the images.
8511%
8512% o exception: return any errors or warnings in this structure.
8513%
8514*/
8515WandExport MagickBooleanType MogrifyImages(ImageInfo *image_info,
8516 const MagickBooleanType post,const int argc,const char **argv,
8517 Image **images,ExceptionInfo *exception)
8518{
8519#define MogrifyImageTag "Mogrify/Image"
8520
8521 Image
8522 *image,
8523 *mogrify_images;
8524
cristy0e9f9c12010-02-11 03:00:47 +00008525 MagickBooleanType
8526 proceed;
8527
8528 MagickSizeType
8529 number_images;
8530
cristy3ed852e2009-09-05 21:47:34 +00008531 MagickStatusType
8532 status;
8533
cristybb503372010-05-27 20:51:26 +00008534 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00008535 i;
8536
cristy3ed852e2009-09-05 21:47:34 +00008537 /*
8538 Apply options to individual images in the list.
8539 */
8540 assert(image_info != (ImageInfo *) NULL);
8541 assert(image_info->signature == MagickSignature);
8542 if (images == (Image **) NULL)
8543 return(MogrifyImage(image_info,argc,argv,images,exception));
8544 assert((*images)->signature == MagickSignature);
8545 if ((*images)->debug != MagickFalse)
8546 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
8547 (*images)->filename);
8548 if ((argc <= 0) || (*argv == (char *) NULL))
8549 return(MagickTrue);
8550 (void) SetImageInfoProgressMonitor(image_info,(MagickProgressMonitor) NULL,
8551 (void *) NULL);
8552 mogrify_images=NewImageList();
8553 number_images=GetImageListLength(*images);
8554 status=0;
8555 if (post == MagickFalse)
8556 status&=MogrifyImageList(image_info,argc,argv,images,exception);
cristybb503372010-05-27 20:51:26 +00008557 for (i=0; i < (ssize_t) number_images; i++)
cristy3ed852e2009-09-05 21:47:34 +00008558 {
8559 image=RemoveFirstImageFromList(images);
8560 if (image == (Image *) NULL)
8561 continue;
8562 status&=MogrifyImage(image_info,argc,argv,&image,exception);
8563 AppendImageToList(&mogrify_images,image);
cristy0e9f9c12010-02-11 03:00:47 +00008564 proceed=SetImageProgress(image,MogrifyImageTag,(MagickOffsetType) i,
8565 number_images);
8566 if (proceed == MagickFalse)
8567 break;
cristy3ed852e2009-09-05 21:47:34 +00008568 }
8569 if (post != MagickFalse)
8570 status&=MogrifyImageList(image_info,argc,argv,&mogrify_images,exception);
8571 *images=mogrify_images;
8572 return(status != 0 ? MagickTrue : MagickFalse);
8573}