blob: 45f93b84c7c02ae05f53a37b01cc435952397363 [file] [log] [blame]
cristy3ed852e2009-09-05 21:47:34 +00001/*
2%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3% %
4% %
5% %
6% M M OOO GGGGG RRRR IIIII FFFFF Y Y %
7% MM MM O O G R R I F Y Y %
8% M M M O O G GGG RRRR I FFF Y %
9% M M O O G G R R I F Y %
10% M M OOO GGGG R R IIIII F Y %
11% %
12% %
13% MagickWand Module Methods %
14% %
15% Software Design %
16% John Cristy %
17% March 2000 %
18% %
19% %
cristy16af1cb2009-12-11 21:38:29 +000020% Copyright 1999-2010 ImageMagick Studio LLC, a non-profit organization %
cristy3ed852e2009-09-05 21:47:34 +000021% dedicated to making software imaging solutions freely available. %
22% %
23% You may not use this file except in compliance with the License. You may %
24% obtain a copy of the License at %
25% %
26% http://www.imagemagick.org/script/license.php %
27% %
28% Unless required by applicable law or agreed to in writing, software %
29% distributed under the License is distributed on an "AS IS" BASIS, %
30% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
31% See the License for the specific language governing permissions and %
32% limitations under the License. %
33% %
34%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35%
36% Use the mogrify program to resize an image, blur, crop, despeckle, dither,
37% draw on, flip, join, re-sample, and much more. This tool is similiar to
38% convert except that the original image file is overwritten (unless you
39% change the file suffix with the -format option) with any changes you
cristy6a917d92009-10-06 19:23:54 +000040% request.
cristy3ed852e2009-09-05 21:47:34 +000041%
42*/
43
44/*
45 Include declarations.
46*/
47#include "wand/studio.h"
48#include "wand/MagickWand.h"
49#include "wand/mogrify-private.h"
cristy0e9f9c12010-02-11 03:00:47 +000050#include "magick/monitor-private.h"
cristy3980b0d2009-10-25 14:37:13 +000051#include "magick/thread-private.h"
cristyf2f27272009-12-17 14:48:46 +000052#include "magick/string-private.h"
cristy3ed852e2009-09-05 21:47:34 +000053
54/*
55 Define declarations.
56*/
57#define UndefinedCompressionQuality 0UL
58
59/*
60 Constant declaration.
61*/
62static const char
cristy7138c592009-09-08 13:58:52 +000063 BackgroundColor[] = "#fff", /* white */
64 BorderColor[] = "#dfdfdf", /* gray */
65 MatteColor[] = "#bdbdbd"; /* gray */
cristy3ed852e2009-09-05 21:47:34 +000066
67/*
68%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
69% %
70% %
71% %
cristy3980b0d2009-10-25 14:37:13 +000072+ M a g i c k C o m m a n d G e n e s i s %
73% %
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,
84% MagickCommand command,const int argc,const char **argv,Image **image)
85%
86% A description of each parameter follows:
87%
88% o image_info: the image info.
89%
90% o command: the magick command.
91%
92% o argc: Specifies a pointer to an integer describing the number of
93% elements in the argument vector.
94%
95% o argv: Specifies a pointer to a text array containing the command line
96% arguments.
97%
98% o image: the image.
99%
100% o exception: return any errors or warnings in this structure.
101%
102*/
103WandExport MagickBooleanType MagickCommandGenesis(ImageInfo *image_info,
104 MagickCommand command,int argc,char **argv,char **metadata,
105 ExceptionInfo *exception)
106{
107 char
108 *option;
109
110 double
111 duration,
112 elapsed_time,
113 user_time;
114
cristy3980b0d2009-10-25 14:37:13 +0000115 MagickBooleanType
116 concurrent,
117 regard_warnings,
118 status;
119
cristybb503372010-05-27 20:51:26 +0000120 register ssize_t
cristy3980b0d2009-10-25 14:37:13 +0000121 i;
122
123 TimerInfo
124 *timer;
125
cristybb503372010-05-27 20:51:26 +0000126 size_t
cristy3980b0d2009-10-25 14:37:13 +0000127 iterations;
128
cristyd0a94fa2010-03-12 14:18:11 +0000129 (void) setlocale(LC_ALL,"");
130 (void) setlocale(LC_NUMERIC,"C");
cristy3980b0d2009-10-25 14:37:13 +0000131 concurrent=MagickFalse;
132 duration=(-1.0);
133 iterations=1;
cristy33557d72009-11-06 00:54:33 +0000134 status=MagickFalse;
cristy3980b0d2009-10-25 14:37:13 +0000135 regard_warnings=MagickFalse;
cristybb503372010-05-27 20:51:26 +0000136 for (i=1; i < (ssize_t) (argc-1); i++)
cristy3980b0d2009-10-25 14:37:13 +0000137 {
138 option=argv[i];
139 if ((strlen(option) == 1) || ((*option != '-') && (*option != '+')))
140 continue;
141 if (LocaleCompare("bench",option+1) == 0)
cristye27293e2009-12-18 02:53:20 +0000142 iterations=StringToUnsignedLong(argv[++i]);
cristy3980b0d2009-10-25 14:37:13 +0000143 if (LocaleCompare("concurrent",option+1) == 0)
144 concurrent=MagickTrue;
145 if (LocaleCompare("debug",option+1) == 0)
146 (void) SetLogEventMask(argv[++i]);
147 if (LocaleCompare("duration",option+1) == 0)
cristyf2f27272009-12-17 14:48:46 +0000148 duration=StringToDouble(argv[++i]);
cristy3980b0d2009-10-25 14:37:13 +0000149 if (LocaleCompare("regard-warnings",option+1) == 0)
150 regard_warnings=MagickTrue;
151 }
152 timer=AcquireTimerInfo();
cristyceae09d2009-10-28 17:18:47 +0000153 if (concurrent == MagickFalse)
cristy3980b0d2009-10-25 14:37:13 +0000154 {
cristybb503372010-05-27 20:51:26 +0000155 for (i=0; i < (ssize_t) iterations; i++)
cristy3980b0d2009-10-25 14:37:13 +0000156 {
cristy33557d72009-11-06 00:54:33 +0000157 if (status != MagickFalse)
cristyceae09d2009-10-28 17:18:47 +0000158 continue;
159 if (duration > 0)
160 {
161 if (GetElapsedTime(timer) > duration)
162 continue;
163 (void) ContinueTimer(timer);
164 }
165 status=command(image_info,argc,argv,metadata,exception);
cristy3980b0d2009-10-25 14:37:13 +0000166 if (exception->severity != UndefinedException)
167 {
168 if ((exception->severity > ErrorException) ||
169 (regard_warnings != MagickFalse))
170 status=MagickTrue;
171 CatchException(exception);
172 }
cristy3d1a5512009-10-25 21:23:27 +0000173 if ((metadata != (char **) NULL) && (*metadata != (char *) NULL))
cristy3980b0d2009-10-25 14:37:13 +0000174 {
175 (void) fputs(*metadata,stdout);
176 (void) fputc('\n',stdout);
177 *metadata=DestroyString(*metadata);
178 }
179 }
180 }
cristyceae09d2009-10-28 17:18:47 +0000181 else
182 {
183 SetOpenMPNested(1);
cristyb5d5f722009-11-04 03:03:49 +0000184#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristyceae09d2009-10-28 17:18:47 +0000185 # pragma omp parallel for shared(status)
186#endif
cristybb503372010-05-27 20:51:26 +0000187 for (i=0; i < (ssize_t) iterations; i++)
cristyceae09d2009-10-28 17:18:47 +0000188 {
cristy33557d72009-11-06 00:54:33 +0000189 if (status != MagickFalse)
cristyceae09d2009-10-28 17:18:47 +0000190 continue;
191 if (duration > 0)
192 {
193 if (GetElapsedTime(timer) > duration)
194 continue;
195 (void) ContinueTimer(timer);
196 }
197 status=command(image_info,argc,argv,metadata,exception);
cristyb5d5f722009-11-04 03:03:49 +0000198#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy524549f2010-06-20 21:10:20 +0000199 # pragma omp critical (MagickCore_CommandGenesis)
cristyceae09d2009-10-28 17:18:47 +0000200#endif
201 {
202 if (exception->severity != UndefinedException)
203 {
204 if ((exception->severity > ErrorException) ||
205 (regard_warnings != MagickFalse))
206 status=MagickTrue;
207 CatchException(exception);
208 }
209 if ((metadata != (char **) NULL) && (*metadata != (char *) NULL))
210 {
211 (void) fputs(*metadata,stdout);
212 (void) fputc('\n',stdout);
213 *metadata=DestroyString(*metadata);
214 }
215 }
216 }
217 }
cristy3980b0d2009-10-25 14:37:13 +0000218 if (iterations > 1)
219 {
220 elapsed_time=GetElapsedTime(timer);
221 user_time=GetUserTime(timer);
cristy8cd5b312010-01-07 01:10:24 +0000222 (void) fprintf(stderr,
cristye8c25f92010-06-03 00:53:06 +0000223 "Performance: %.20gi %gips %0.3fu %.20g:%02g.%03g\n",(double)
224 iterations,1.0*iterations/elapsed_time,user_time,(double)
225 (elapsed_time/60.0),floor(fmod(elapsed_time,60.0)),(double)
226 (1000.0*(elapsed_time-floor(elapsed_time))));
cristy524549f2010-06-20 21:10:20 +0000227 (void) fflush(stderr);
cristy3980b0d2009-10-25 14:37:13 +0000228 }
229 timer=DestroyTimerInfo(timer);
cristy1f9e1ed2009-11-18 04:09:38 +0000230 return(status);
cristy3980b0d2009-10-25 14:37:13 +0000231}
232
233/*
234%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
235% %
236% %
237% %
cristy3ed852e2009-09-05 21:47:34 +0000238+ M o g r i f y I m a g e %
239% %
240% %
241% %
242%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
243%
244% MogrifyImage() applies image processing options to an image as prescribed
245% by command line options.
246%
247% The format of the MogrifyImage method is:
248%
249% MagickBooleanType MogrifyImage(ImageInfo *image_info,const int argc,
250% const char **argv,Image **image)
251%
252% A description of each parameter follows:
253%
254% o image_info: the image info..
255%
256% o argc: Specifies a pointer to an integer describing the number of
257% elements in the argument vector.
258%
259% o argv: Specifies a pointer to a text array containing the command line
260% arguments.
261%
262% o image: the image.
263%
264% o exception: return any errors or warnings in this structure.
265%
266*/
267
268static inline Image *GetImageCache(const ImageInfo *image_info,const char *path,
269 ExceptionInfo *exception)
270{
271 char
272 key[MaxTextExtent];
273
274 ExceptionInfo
275 *sans_exception;
276
277 Image
278 *image;
279
280 ImageInfo
281 *read_info;
282
283 (void) FormatMagickString(key,MaxTextExtent,"cache:%s",path);
284 sans_exception=AcquireExceptionInfo();
285 image=(Image *) GetImageRegistry(ImageRegistryType,key,sans_exception);
286 sans_exception=DestroyExceptionInfo(sans_exception);
287 if (image != (Image *) NULL)
288 return(image);
289 read_info=CloneImageInfo(image_info);
290 (void) CopyMagickString(read_info->filename,path,MaxTextExtent);
291 image=ReadImage(read_info,exception);
292 read_info=DestroyImageInfo(read_info);
293 if (image != (Image *) NULL)
294 (void) SetImageRegistry(ImageRegistryType,key,image,exception);
295 return(image);
296}
297
cristy3ed852e2009-09-05 21:47:34 +0000298static MagickBooleanType IsPathWritable(const char *path)
299{
300 if (IsPathAccessible(path) == MagickFalse)
301 return(MagickFalse);
302 if (access(path,W_OK) != 0)
303 return(MagickFalse);
304 return(MagickTrue);
305}
306
cristybb503372010-05-27 20:51:26 +0000307static inline ssize_t MagickMax(const ssize_t x,const ssize_t y)
cristy3ed852e2009-09-05 21:47:34 +0000308{
309 if (x > y)
310 return(x);
311 return(y);
312}
313
314static MagickBooleanType MonitorProgress(const char *text,
cristyb32b90a2009-09-07 21:45:48 +0000315 const MagickOffsetType offset,const MagickSizeType extent,
cristy3ed852e2009-09-05 21:47:34 +0000316 void *wand_unused(client_data))
317{
318 char
319 message[MaxTextExtent],
320 tag[MaxTextExtent];
321
322 const char
323 *locale_message;
324
325 register char
326 *p;
327
cristyb32b90a2009-09-07 21:45:48 +0000328 if (extent < 2)
cristy3ed852e2009-09-05 21:47:34 +0000329 return(MagickTrue);
330 (void) CopyMagickMemory(tag,text,MaxTextExtent);
331 p=strrchr(tag,'/');
332 if (p != (char *) NULL)
333 *p='\0';
334 (void) FormatMagickString(message,MaxTextExtent,"Monitor/%s",tag);
335 locale_message=GetLocaleMessage(message);
336 if (locale_message == message)
337 locale_message=tag;
338 if (p == (char *) NULL)
cristyb32b90a2009-09-07 21:45:48 +0000339 (void) fprintf(stderr,"%s: %ld of %lu, %02ld%% complete\r",locale_message,
cristyf2faecf2010-05-28 19:19:36 +0000340 (long) offset,(unsigned long) extent,(long) (100L*offset/(extent-1)));
cristy3ed852e2009-09-05 21:47:34 +0000341 else
cristyb32b90a2009-09-07 21:45:48 +0000342 (void) fprintf(stderr,"%s[%s]: %ld of %lu, %02ld%% complete\r",
cristyf2faecf2010-05-28 19:19:36 +0000343 locale_message,p+1,(long) offset,(unsigned long) extent,(long)
cristyb32b90a2009-09-07 21:45:48 +0000344 (100L*offset/(extent-1)));
345 if (offset == (MagickOffsetType) (extent-1))
cristy3ed852e2009-09-05 21:47:34 +0000346 (void) fprintf(stderr,"\n");
347 (void) fflush(stderr);
348 return(MagickTrue);
349}
350
351static Image *SparseColorOption(const Image *image,const ChannelType channel,
352 const SparseColorMethod method,const char *arguments,
353 const MagickBooleanType color_from_image,ExceptionInfo *exception)
354{
355 ChannelType
356 channels;
357
358 char
359 token[MaxTextExtent];
360
361 const char
362 *p;
363
364 double
365 *sparse_arguments;
366
cristybb503372010-05-27 20:51:26 +0000367 register size_t
cristy3ed852e2009-09-05 21:47:34 +0000368 x;
369
cristybb503372010-05-27 20:51:26 +0000370 size_t
cristy3ed852e2009-09-05 21:47:34 +0000371 number_arguments;
372
cristybb503372010-05-27 20:51:26 +0000373 size_t
cristy3ed852e2009-09-05 21:47:34 +0000374 number_colors;
375
376 Image
377 *sparse_image;
378
379 MagickPixelPacket
380 color;
381
382 MagickBooleanType
383 error;
384
385 assert(image != (Image *) NULL);
386 assert(image->signature == MagickSignature);
387 if (image->debug != MagickFalse)
388 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
389 assert(exception != (ExceptionInfo *) NULL);
390 assert(exception->signature == MagickSignature);
391 /*
392 Limit channels according to image - and add up number of color channel.
393 */
394 channels=channel;
395 if (image->colorspace != CMYKColorspace)
396 channels=(ChannelType) (channels & ~IndexChannel); /* no index channel */
397 if (image->matte == MagickFalse)
398 channels=(ChannelType) (channels & ~OpacityChannel); /* no alpha channel */
399 number_colors=0;
400 if ((channels & RedChannel) != 0)
401 number_colors++;
402 if ((channels & GreenChannel) != 0)
403 number_colors++;
404 if ((channels & BlueChannel) != 0)
405 number_colors++;
406 if ((channels & IndexChannel) != 0)
407 number_colors++;
408 if ((channels & OpacityChannel) != 0)
409 number_colors++;
410 /*
411 Read string, to determine number of arguments needed,
412 */
413 p=arguments;
414 x=0;
415 while( *p != '\0' )
416 {
417 GetMagickToken(p,&p,token);
418 if ( token[0] == ',' ) continue;
419 if ( isalpha((int) token[0]) || token[0] == '#' ) {
420 if ( color_from_image ) {
421 (void) ThrowMagickException(exception,GetMagickModule(),
422 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
423 "Color arg given, when colors are coming from image");
424 return( (Image *)NULL);
425 }
426 x += number_colors; /* color argument */
427 }
428 else {
429 x++; /* floating point argument */
430 }
431 }
432 error=MagickTrue;
433 if ( color_from_image ) {
434 /* just the control points are being given */
435 error = ( x % 2 != 0 ) ? MagickTrue : MagickFalse;
436 number_arguments=(x/2)*(2+number_colors);
437 }
438 else {
439 /* control points and color values */
440 error = ( x % (2+number_colors) != 0 ) ? MagickTrue : MagickFalse;
441 number_arguments=x;
442 }
443 if ( error ) {
444 (void) ThrowMagickException(exception,GetMagickModule(),
445 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
446 "Invalid number of Arguments");
447 return( (Image *)NULL);
448 }
449
450 /* Allocate and fill in the floating point arguments */
451 sparse_arguments=(double *) AcquireQuantumMemory(number_arguments,
452 sizeof(*sparse_arguments));
453 if (sparse_arguments == (double *) NULL) {
454 (void) ThrowMagickException(exception,GetMagickModule(),ResourceLimitError,
455 "MemoryAllocationFailed","%s","SparseColorOption");
456 return( (Image *)NULL);
457 }
458 (void) ResetMagickMemory(sparse_arguments,0,number_arguments*
459 sizeof(*sparse_arguments));
460 p=arguments;
461 x=0;
462 while( *p != '\0' && x < number_arguments ) {
463 /* X coordinate */
464 token[0]=','; while ( token[0] == ',' ) GetMagickToken(p,&p,token);
465 if ( token[0] == '\0' ) break;
466 if ( isalpha((int) token[0]) || token[0] == '#' ) {
467 (void) ThrowMagickException(exception,GetMagickModule(),
468 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
469 "Color found, instead of X-coord");
470 error = MagickTrue;
471 break;
472 }
cristyf2f27272009-12-17 14:48:46 +0000473 sparse_arguments[x++]=StringToDouble(token);
cristy3ed852e2009-09-05 21:47:34 +0000474 /* Y coordinate */
475 token[0]=','; while ( token[0] == ',' ) GetMagickToken(p,&p,token);
476 if ( token[0] == '\0' ) break;
477 if ( isalpha((int) token[0]) || token[0] == '#' ) {
478 (void) ThrowMagickException(exception,GetMagickModule(),
479 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
480 "Color found, instead of Y-coord");
481 error = MagickTrue;
482 break;
483 }
cristyf2f27272009-12-17 14:48:46 +0000484 sparse_arguments[x++]=StringToDouble(token);
cristy3ed852e2009-09-05 21:47:34 +0000485 /* color values for this control point */
486#if 0
487 if ( (color_from_image ) {
488 /* get color from image */
489 /* HOW??? */
490 }
491 else
492#endif
493 {
494 /* color name or function given in string argument */
495 token[0]=','; while ( token[0] == ',' ) GetMagickToken(p,&p,token);
496 if ( token[0] == '\0' ) break;
497 if ( isalpha((int) token[0]) || token[0] == '#' ) {
498 /* Color string given */
499 (void) QueryMagickColor(token,&color,exception);
500 if ( channels & RedChannel )
501 sparse_arguments[x++] = QuantumScale*color.red;
502 if ( channels & GreenChannel )
503 sparse_arguments[x++] = QuantumScale*color.green;
504 if ( channels & BlueChannel )
505 sparse_arguments[x++] = QuantumScale*color.blue;
506 if ( channels & IndexChannel )
507 sparse_arguments[x++] = QuantumScale*color.index;
508 if ( channels & OpacityChannel )
509 sparse_arguments[x++] = QuantumScale*color.opacity;
510 }
511 else {
512#if 0
513 /* the color name/function/value was not found - error */
514 break;
515#else
516 /* Colors given as a set of floating point values - experimental */
517 /* NB: token contains the first floating point value to use! */
518 if ( channels & RedChannel ) {
519 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
520 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
521 break;
cristy0f19e682009-12-17 14:55:51 +0000522 sparse_arguments[x++]=StringToDouble(token);
cristy3ed852e2009-09-05 21:47:34 +0000523 token[0] = ','; /* used this token - get another */
524 }
525 if ( channels & GreenChannel ) {
526 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
527 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
528 break;
cristy0f19e682009-12-17 14:55:51 +0000529 sparse_arguments[x++]=StringToDouble(token);
cristy3ed852e2009-09-05 21:47:34 +0000530 token[0] = ','; /* used this token - get another */
531 }
532 if ( channels & BlueChannel ) {
533 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
534 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
535 break;
cristy0f19e682009-12-17 14:55:51 +0000536 sparse_arguments[x++]=StringToDouble(token);
cristy3ed852e2009-09-05 21:47:34 +0000537 token[0] = ','; /* used this token - get another */
538 }
539 if ( channels & IndexChannel ) {
540 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
541 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
542 break;
cristy0f19e682009-12-17 14:55:51 +0000543 sparse_arguments[x++]=StringToDouble(token);
cristy3ed852e2009-09-05 21:47:34 +0000544 token[0] = ','; /* used this token - get another */
545 }
546 if ( channels & OpacityChannel ) {
547 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
548 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
549 break;
cristy0f19e682009-12-17 14:55:51 +0000550 sparse_arguments[x++]=StringToDouble(token);
cristy3ed852e2009-09-05 21:47:34 +0000551 token[0] = ','; /* used this token - get another */
552 }
553#endif
554 }
555 }
556 }
557 if ( number_arguments != x && !error ) {
558 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
559 "InvalidArgument","`%s': %s","sparse-color","Argument Parsing Error");
560 sparse_arguments=(double *) RelinquishMagickMemory(sparse_arguments);
561 return( (Image *)NULL);
562 }
563 if ( error )
564 return( (Image *)NULL);
565
566 /* Call the Interpolation function with the parsed arguments */
567 sparse_image=SparseColorImage(image,channels,method,number_arguments,
568 sparse_arguments,exception);
569 sparse_arguments=(double *) RelinquishMagickMemory(sparse_arguments);
570 return( sparse_image );
571}
572
573WandExport MagickBooleanType MogrifyImage(ImageInfo *image_info,const int argc,
574 const char **argv,Image **image,ExceptionInfo *exception)
575{
576 ChannelType
577 channel;
578
579 const char
580 *format,
581 *option;
582
583 DrawInfo
584 *draw_info;
585
586 GeometryInfo
587 geometry_info;
588
589 Image
590 *region_image;
591
cristy6b3da3a2010-06-20 02:21:46 +0000592 ImageInfo
593 *mogrify_info;
594
cristybb503372010-05-27 20:51:26 +0000595 ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000596 count;
597
598 MagickBooleanType
599 status;
600
601 MagickPixelPacket
602 fill;
603
604 MagickStatusType
605 flags;
606
607 QuantizeInfo
608 *quantize_info;
609
610 RectangleInfo
611 geometry,
612 region_geometry;
613
cristybb503372010-05-27 20:51:26 +0000614 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000615 i;
616
617 /*
618 Initialize method variables.
619 */
620 assert(image_info != (const ImageInfo *) NULL);
621 assert(image_info->signature == MagickSignature);
622 assert(image != (Image **) NULL);
623 assert((*image)->signature == MagickSignature);
624 if ((*image)->debug != MagickFalse)
625 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",(*image)->filename);
626 if (argc < 0)
627 return(MagickTrue);
cristy6b3da3a2010-06-20 02:21:46 +0000628 mogrify_info=CloneImageInfo(image_info);
629 draw_info=CloneDrawInfo(mogrify_info,(DrawInfo *) NULL);
630 quantize_info=AcquireQuantizeInfo(mogrify_info);
cristy3ed852e2009-09-05 21:47:34 +0000631 SetGeometryInfo(&geometry_info);
632 GetMagickPixelPacket(*image,&fill);
633 SetMagickPixelPacket(*image,&(*image)->background_color,(IndexPacket *) NULL,
634 &fill);
cristy6b3da3a2010-06-20 02:21:46 +0000635 channel=mogrify_info->channel;
636 format=GetImageOption(mogrify_info,"format");
cristy3ed852e2009-09-05 21:47:34 +0000637 SetGeometry(*image,&region_geometry);
638 region_image=NewImageList();
639 /*
640 Transmogrify the image.
641 */
cristybb503372010-05-27 20:51:26 +0000642 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +0000643 {
644 option=argv[i];
645 if (IsMagickOption(option) == MagickFalse)
646 continue;
647 count=MagickMax(ParseMagickOption(MagickCommandOptions,MagickFalse,option),
648 0L);
cristycee97112010-05-28 00:44:52 +0000649 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +0000650 break;
cristy6b3da3a2010-06-20 02:21:46 +0000651 status=MogrifyImageInfo(mogrify_info,(int) count+1,argv+i,exception);
cristy3ed852e2009-09-05 21:47:34 +0000652 switch (*(option+1))
653 {
654 case 'a':
655 {
656 if (LocaleCompare("adaptive-blur",option+1) == 0)
657 {
658 Image
659 *blur_image;
660
661 /*
662 Adaptive blur image.
663 */
cristy6b3da3a2010-06-20 02:21:46 +0000664 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000665 flags=ParseGeometry(argv[i+1],&geometry_info);
666 if ((flags & SigmaValue) == 0)
667 geometry_info.sigma=1.0;
668 blur_image=AdaptiveBlurImageChannel(*image,channel,
669 geometry_info.rho,geometry_info.sigma,exception);
670 if (blur_image == (Image *) NULL)
671 break;
672 *image=DestroyImage(*image);
673 *image=blur_image;
674 break;
675 }
676 if (LocaleCompare("adaptive-resize",option+1) == 0)
677 {
678 Image
679 *resize_image;
680
681 /*
682 Adaptive resize image.
683 */
cristy6b3da3a2010-06-20 02:21:46 +0000684 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000685 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
686 resize_image=AdaptiveResizeImage(*image,geometry.width,
687 geometry.height,exception);
688 if (resize_image == (Image *) NULL)
689 break;
690 *image=DestroyImage(*image);
691 *image=resize_image;
692 break;
693 }
694 if (LocaleCompare("adaptive-sharpen",option+1) == 0)
695 {
696 Image
697 *sharp_image;
698
699 /*
700 Adaptive sharpen image.
701 */
cristy6b3da3a2010-06-20 02:21:46 +0000702 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000703 flags=ParseGeometry(argv[i+1],&geometry_info);
704 if ((flags & SigmaValue) == 0)
705 geometry_info.sigma=1.0;
706 sharp_image=AdaptiveSharpenImageChannel(*image,channel,
707 geometry_info.rho,geometry_info.sigma,exception);
708 if (sharp_image == (Image *) NULL)
709 break;
710 *image=DestroyImage(*image);
711 *image=sharp_image;
712 break;
713 }
714 if (LocaleCompare("affine",option+1) == 0)
715 {
716 /*
717 Affine matrix.
718 */
719 if (*option == '+')
720 {
721 GetAffineMatrix(&draw_info->affine);
722 break;
723 }
724 (void) ParseAffineGeometry(argv[i+1],&draw_info->affine,exception);
725 break;
726 }
727 if (LocaleCompare("alpha",option+1) == 0)
728 {
729 AlphaChannelType
730 alpha_type;
731
cristy6b3da3a2010-06-20 02:21:46 +0000732 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000733 alpha_type=(AlphaChannelType) ParseMagickOption(MagickAlphaOptions,
734 MagickFalse,argv[i+1]);
735 (void) SetImageAlphaChannel(*image,alpha_type);
736 InheritException(exception,&(*image)->exception);
737 break;
738 }
739 if (LocaleCompare("annotate",option+1) == 0)
740 {
741 char
742 *text,
743 geometry[MaxTextExtent];
744
745 /*
746 Annotate image.
747 */
cristy6b3da3a2010-06-20 02:21:46 +0000748 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000749 SetGeometryInfo(&geometry_info);
750 flags=ParseGeometry(argv[i+1],&geometry_info);
751 if ((flags & SigmaValue) == 0)
752 geometry_info.sigma=geometry_info.rho;
cristy6b3da3a2010-06-20 02:21:46 +0000753 text=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
cristy3ed852e2009-09-05 21:47:34 +0000754 InheritException(exception,&(*image)->exception);
755 if (text == (char *) NULL)
756 break;
757 (void) CloneString(&draw_info->text,text);
758 text=DestroyString(text);
759 (void) FormatMagickString(geometry,MaxTextExtent,"%+f%+f",
760 geometry_info.xi,geometry_info.psi);
761 (void) CloneString(&draw_info->geometry,geometry);
762 draw_info->affine.sx=cos(DegreesToRadians(
763 fmod(geometry_info.rho,360.0)));
764 draw_info->affine.rx=sin(DegreesToRadians(
765 fmod(geometry_info.rho,360.0)));
766 draw_info->affine.ry=(-sin(DegreesToRadians(
767 fmod(geometry_info.sigma,360.0))));
768 draw_info->affine.sy=cos(DegreesToRadians(
769 fmod(geometry_info.sigma,360.0)));
770 (void) AnnotateImage(*image,draw_info);
771 InheritException(exception,&(*image)->exception);
772 break;
773 }
774 if (LocaleCompare("antialias",option+1) == 0)
775 {
776 draw_info->stroke_antialias=(*option == '-') ? MagickTrue :
777 MagickFalse;
778 draw_info->text_antialias=(*option == '-') ? MagickTrue :
779 MagickFalse;
780 break;
781 }
782 if (LocaleCompare("auto-gamma",option+1) == 0)
783 {
784 /*
785 Auto Adjust Gamma of image based on its mean
786 */
cristy6b3da3a2010-06-20 02:21:46 +0000787 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000788 (void) AutoGammaImageChannel(*image,channel);
789 break;
790 }
791 if (LocaleCompare("auto-level",option+1) == 0)
792 {
793 /*
794 Perfectly Normalize (max/min stretch) the image
795 */
cristy6b3da3a2010-06-20 02:21:46 +0000796 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000797 (void) AutoLevelImageChannel(*image,channel);
798 break;
799 }
800 if (LocaleCompare("auto-orient",option+1) == 0)
801 {
802 Image
803 *orient_image;
804
cristy6b3da3a2010-06-20 02:21:46 +0000805 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000806 orient_image=NewImageList();
807 switch ((*image)->orientation)
808 {
809 case TopRightOrientation:
810 {
811 orient_image=FlopImage(*image,exception);
812 break;
813 }
814 case BottomRightOrientation:
815 {
816 orient_image=RotateImage(*image,180.0,exception);
817 break;
818 }
819 case BottomLeftOrientation:
820 {
821 orient_image=FlipImage(*image,exception);
822 break;
823 }
824 case LeftTopOrientation:
825 {
826 orient_image=TransposeImage(*image,exception);
827 break;
828 }
829 case RightTopOrientation:
830 {
831 orient_image=RotateImage(*image,90.0,exception);
832 break;
833 }
834 case RightBottomOrientation:
835 {
836 orient_image=TransverseImage(*image,exception);
837 break;
838 }
839 case LeftBottomOrientation:
840 {
841 orient_image=RotateImage(*image,270.0,exception);
842 break;
843 }
844 default:
845 break;
846 }
847 if (orient_image == (Image *) NULL)
848 break;
849 orient_image->orientation=TopLeftOrientation;
850 *image=DestroyImage(*image);
851 *image=orient_image;
852 break;
853 }
854 break;
855 }
856 case 'b':
857 {
858 if (LocaleCompare("black-threshold",option+1) == 0)
859 {
860 /*
861 Black threshold image.
862 */
cristy6b3da3a2010-06-20 02:21:46 +0000863 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000864 (void) BlackThresholdImageChannel(*image,channel,argv[i+1],
865 exception);
866 InheritException(exception,&(*image)->exception);
867 break;
868 }
869 if (LocaleCompare("blue-shift",option+1) == 0)
870 {
871 Image
872 *shift_image;
873
874 /*
875 Blue shift image.
876 */
cristy6b3da3a2010-06-20 02:21:46 +0000877 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000878 geometry_info.rho=1.5;
879 if (*option == '-')
880 flags=ParseGeometry(argv[i+1],&geometry_info);
881 shift_image=BlueShiftImage(*image,geometry_info.rho,exception);
882 if (shift_image == (Image *) NULL)
883 break;
884 *image=DestroyImage(*image);
885 *image=shift_image;
886 break;
887 }
888 if (LocaleCompare("blur",option+1) == 0)
889 {
890 Image
891 *blur_image;
892
893 /*
894 Gaussian blur image.
895 */
cristy6b3da3a2010-06-20 02:21:46 +0000896 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000897 flags=ParseGeometry(argv[i+1],&geometry_info);
898 if ((flags & SigmaValue) == 0)
899 geometry_info.sigma=1.0;
900 blur_image=BlurImageChannel(*image,channel,geometry_info.rho,
901 geometry_info.sigma,exception);
902 if (blur_image == (Image *) NULL)
903 break;
904 *image=DestroyImage(*image);
905 *image=blur_image;
906 break;
907 }
908 if (LocaleCompare("border",option+1) == 0)
909 {
910 Image
911 *border_image;
912
913 /*
914 Surround image with a border of solid color.
915 */
cristy6b3da3a2010-06-20 02:21:46 +0000916 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000917 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
918 if ((flags & SigmaValue) == 0)
919 geometry.height=geometry.width;
920 border_image=BorderImage(*image,&geometry,exception);
921 if (border_image == (Image *) NULL)
922 break;
923 *image=DestroyImage(*image);
924 *image=border_image;
925 break;
926 }
927 if (LocaleCompare("bordercolor",option+1) == 0)
928 {
929 if (*option == '+')
930 {
931 (void) QueryColorDatabase(BorderColor,&draw_info->border_color,
932 exception);
933 break;
934 }
935 (void) QueryColorDatabase(argv[i+1],&draw_info->border_color,
936 exception);
937 break;
938 }
939 if (LocaleCompare("box",option+1) == 0)
940 {
941 (void) QueryColorDatabase(argv[i+1],&draw_info->undercolor,
942 exception);
943 break;
944 }
cristya28d6b82010-01-11 20:03:47 +0000945 if (LocaleCompare("brightness-contrast",option+1) == 0)
946 {
947 double
948 brightness,
949 contrast;
950
951 GeometryInfo
952 geometry_info;
953
954 MagickStatusType
955 flags;
956
957 /*
958 Brightness / contrast image.
959 */
cristy6b3da3a2010-06-20 02:21:46 +0000960 (void) SyncImageSettings(mogrify_info,*image);
cristya28d6b82010-01-11 20:03:47 +0000961 flags=ParseGeometry(argv[i+1],&geometry_info);
962 brightness=geometry_info.rho;
cristy81fbc8b2010-01-11 20:04:07 +0000963 contrast=0.0;
cristya28d6b82010-01-11 20:03:47 +0000964 if ((flags & SigmaValue) != 0)
965 contrast=geometry_info.sigma;
cristy02cc0f22010-01-12 00:02:32 +0000966 (void) BrightnessContrastImageChannel(*image,channel,brightness,
967 contrast);
cristya28d6b82010-01-11 20:03:47 +0000968 InheritException(exception,&(*image)->exception);
969 break;
970 }
cristy3ed852e2009-09-05 21:47:34 +0000971 break;
972 }
973 case 'c':
974 {
975 if (LocaleCompare("cdl",option+1) == 0)
976 {
977 char
978 *color_correction_collection;
979
980 /*
981 Color correct with a color decision list.
982 */
cristy6b3da3a2010-06-20 02:21:46 +0000983 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000984 color_correction_collection=FileToString(argv[i+1],~0,exception);
985 if (color_correction_collection == (char *) NULL)
986 break;
987 (void) ColorDecisionListImage(*image,color_correction_collection);
988 InheritException(exception,&(*image)->exception);
989 break;
990 }
991 if (LocaleCompare("channel",option+1) == 0)
992 {
993 if (*option == '+')
994 {
995 channel=DefaultChannels;
996 break;
997 }
998 channel=(ChannelType) ParseChannelOption(argv[i+1]);
999 break;
1000 }
1001 if (LocaleCompare("charcoal",option+1) == 0)
1002 {
1003 Image
1004 *charcoal_image;
1005
1006 /*
1007 Charcoal image.
1008 */
cristy6b3da3a2010-06-20 02:21:46 +00001009 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001010 flags=ParseGeometry(argv[i+1],&geometry_info);
1011 if ((flags & SigmaValue) == 0)
1012 geometry_info.sigma=1.0;
1013 charcoal_image=CharcoalImage(*image,geometry_info.rho,
1014 geometry_info.sigma,exception);
1015 if (charcoal_image == (Image *) NULL)
1016 break;
1017 *image=DestroyImage(*image);
1018 *image=charcoal_image;
1019 break;
1020 }
1021 if (LocaleCompare("chop",option+1) == 0)
1022 {
1023 Image
1024 *chop_image;
1025
1026 /*
1027 Chop the image.
1028 */
cristy6b3da3a2010-06-20 02:21:46 +00001029 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001030 (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1031 chop_image=ChopImage(*image,&geometry,exception);
1032 if (chop_image == (Image *) NULL)
1033 break;
1034 *image=DestroyImage(*image);
1035 *image=chop_image;
1036 break;
1037 }
cristy1eb45dd2009-09-25 16:38:06 +00001038 if (LocaleCompare("clamp",option+1) == 0)
1039 {
1040 /*
1041 Clamp image.
1042 */
cristy6b3da3a2010-06-20 02:21:46 +00001043 (void) SyncImageSettings(mogrify_info,*image);
cristy1eb45dd2009-09-25 16:38:06 +00001044 (void) ClampImageChannel(*image,channel);
1045 InheritException(exception,&(*image)->exception);
1046 break;
1047 }
cristy3ed852e2009-09-05 21:47:34 +00001048 if (LocaleCompare("clip",option+1) == 0)
1049 {
cristy6b3da3a2010-06-20 02:21:46 +00001050 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001051 if (*option == '+')
1052 {
1053 (void) SetImageClipMask(*image,(Image *) NULL);
1054 InheritException(exception,&(*image)->exception);
1055 break;
1056 }
1057 (void) ClipImage(*image);
1058 InheritException(exception,&(*image)->exception);
1059 break;
1060 }
1061 if (LocaleCompare("clip-mask",option+1) == 0)
1062 {
1063 Image
1064 *mask;
1065
cristybb503372010-05-27 20:51:26 +00001066 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001067 y;
1068
cristybb503372010-05-27 20:51:26 +00001069 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001070 x;
1071
1072 register PixelPacket
cristyc47d1f82009-11-26 01:44:43 +00001073 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00001074
cristy6b3da3a2010-06-20 02:21:46 +00001075 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001076 if (*option == '+')
1077 {
1078 /*
1079 Remove a mask.
1080 */
1081 (void) SetImageMask(*image,(Image *) NULL);
1082 InheritException(exception,&(*image)->exception);
1083 break;
1084 }
1085 /*
1086 Set the image mask.
1087 */
cristy6b3da3a2010-06-20 02:21:46 +00001088 mask=GetImageCache(mogrify_info,argv[i+1],exception);
cristy3ed852e2009-09-05 21:47:34 +00001089 if (mask == (Image *) NULL)
1090 break;
cristybb503372010-05-27 20:51:26 +00001091 for (y=0; y < (ssize_t) mask->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00001092 {
1093 q=GetAuthenticPixels(mask,0,y,mask->columns,1,exception);
1094 if (q == (PixelPacket *) NULL)
1095 break;
cristybb503372010-05-27 20:51:26 +00001096 for (x=0; x < (ssize_t) mask->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00001097 {
1098 if (mask->matte == MagickFalse)
1099 q->opacity=PixelIntensityToQuantum(q);
1100 q->red=q->opacity;
1101 q->green=q->opacity;
1102 q->blue=q->opacity;
1103 q++;
1104 }
1105 if (SyncAuthenticPixels(mask,exception) == MagickFalse)
1106 break;
1107 }
1108 if (SetImageStorageClass(mask,DirectClass) == MagickFalse)
1109 return(MagickFalse);
1110 mask->matte=MagickTrue;
1111 (void) SetImageClipMask(*image,mask);
1112 mask=DestroyImage(mask);
1113 InheritException(exception,&(*image)->exception);
1114 break;
1115 }
1116 if (LocaleCompare("clip-path",option+1) == 0)
1117 {
cristy6b3da3a2010-06-20 02:21:46 +00001118 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001119 (void) ClipImagePath(*image,argv[i+1],*option == '-' ? MagickTrue :
1120 MagickFalse);
1121 InheritException(exception,&(*image)->exception);
1122 break;
1123 }
1124 if (LocaleCompare("colorize",option+1) == 0)
1125 {
1126 Image
1127 *colorize_image;
1128
1129 /*
1130 Colorize the image.
1131 */
cristy6b3da3a2010-06-20 02:21:46 +00001132 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001133 colorize_image=ColorizeImage(*image,argv[i+1],draw_info->fill,
1134 exception);
1135 if (colorize_image == (Image *) NULL)
1136 break;
1137 *image=DestroyImage(*image);
1138 *image=colorize_image;
1139 break;
1140 }
cristye6365592010-04-02 17:31:23 +00001141 if (LocaleCompare("color-matrix",option+1) == 0)
1142 {
1143 Image
1144 *color_image;
1145
1146 KernelInfo
1147 *kernel;
1148
cristy6b3da3a2010-06-20 02:21:46 +00001149 (void) SyncImageSettings(mogrify_info,*image);
cristye6365592010-04-02 17:31:23 +00001150 kernel=AcquireKernelInfo(argv[i+1]);
1151 if (kernel == (KernelInfo *) NULL)
1152 break;
1153 color_image=ColorMatrixImage(*image,kernel,exception);
1154 kernel=DestroyKernelInfo(kernel);
1155 if (color_image == (Image *) NULL)
1156 break;
1157 *image=DestroyImage(*image);
1158 *image=color_image;
1159 break;
1160 }
cristy3ed852e2009-09-05 21:47:34 +00001161 if (LocaleCompare("colors",option+1) == 0)
1162 {
1163 /*
1164 Reduce the number of colors in the image.
1165 */
cristy6b3da3a2010-06-20 02:21:46 +00001166 (void) SyncImageSettings(mogrify_info,*image);
cristye27293e2009-12-18 02:53:20 +00001167 quantize_info->number_colors=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00001168 if (quantize_info->number_colors == 0)
1169 break;
1170 if (((*image)->storage_class == DirectClass) ||
1171 (*image)->colors > quantize_info->number_colors)
1172 (void) QuantizeImage(quantize_info,*image);
1173 else
1174 (void) CompressImageColormap(*image);
1175 InheritException(exception,&(*image)->exception);
1176 break;
1177 }
1178 if (LocaleCompare("colorspace",option+1) == 0)
1179 {
1180 ColorspaceType
1181 colorspace;
1182
cristy6b3da3a2010-06-20 02:21:46 +00001183 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001184 if (*option == '+')
1185 {
1186 (void) TransformImageColorspace(*image,RGBColorspace);
1187 InheritException(exception,&(*image)->exception);
1188 break;
1189 }
1190 colorspace=(ColorspaceType) ParseMagickOption(
1191 MagickColorspaceOptions,MagickFalse,argv[i+1]);
1192 (void) TransformImageColorspace(*image,colorspace);
1193 InheritException(exception,&(*image)->exception);
1194 break;
1195 }
1196 if (LocaleCompare("contrast",option+1) == 0)
1197 {
cristy6b3da3a2010-06-20 02:21:46 +00001198 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001199 (void) ContrastImage(*image,(*option == '-') ? MagickTrue :
1200 MagickFalse);
1201 InheritException(exception,&(*image)->exception);
1202 break;
1203 }
1204 if (LocaleCompare("contrast-stretch",option+1) == 0)
1205 {
1206 double
1207 black_point,
1208 white_point;
1209
cristy3ed852e2009-09-05 21:47:34 +00001210 MagickStatusType
1211 flags;
1212
1213 /*
1214 Contrast stretch image.
1215 */
cristy6b3da3a2010-06-20 02:21:46 +00001216 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001217 flags=ParseGeometry(argv[i+1],&geometry_info);
1218 black_point=geometry_info.rho;
1219 white_point=(flags & SigmaValue) != 0 ? geometry_info.sigma :
1220 black_point;
1221 if ((flags & PercentValue) != 0)
1222 {
1223 black_point*=(double) (*image)->columns*(*image)->rows/100.0;
1224 white_point*=(double) (*image)->columns*(*image)->rows/100.0;
1225 }
1226 white_point=(MagickRealType) (*image)->columns*(*image)->rows-
1227 white_point;
1228 (void) ContrastStretchImageChannel(*image,channel,black_point,
1229 white_point);
1230 InheritException(exception,&(*image)->exception);
1231 break;
1232 }
1233 if (LocaleCompare("convolve",option+1) == 0)
1234 {
cristy36826ab2010-03-06 01:29:30 +00001235 double
1236 gamma;
1237
cristy3ed852e2009-09-05 21:47:34 +00001238 Image
1239 *convolve_image;
1240
cristy2be15382010-01-21 02:38:03 +00001241 KernelInfo
cristy56a9e512010-01-06 18:18:55 +00001242 *kernel;
cristy3ed852e2009-09-05 21:47:34 +00001243
cristybb503372010-05-27 20:51:26 +00001244 register ssize_t
cristy36826ab2010-03-06 01:29:30 +00001245 j;
1246
cristy6b3da3a2010-06-20 02:21:46 +00001247 (void) SyncImageSettings(mogrify_info,*image);
cristy2be15382010-01-21 02:38:03 +00001248 kernel=AcquireKernelInfo(argv[i+1]);
1249 if (kernel == (KernelInfo *) NULL)
cristy56a9e512010-01-06 18:18:55 +00001250 break;
cristy36826ab2010-03-06 01:29:30 +00001251 gamma=0.0;
cristybb503372010-05-27 20:51:26 +00001252 for (j=0; j < (ssize_t) (kernel->width*kernel->height); j++)
cristy36826ab2010-03-06 01:29:30 +00001253 gamma+=kernel->values[j];
1254 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
cristybb503372010-05-27 20:51:26 +00001255 for (j=0; j < (ssize_t) (kernel->width*kernel->height); j++)
cristy36826ab2010-03-06 01:29:30 +00001256 kernel->values[j]*=gamma;
cristy6771f1e2010-03-05 19:43:39 +00001257 convolve_image=FilterImageChannel(*image,channel,kernel,exception);
anthony83ba99b2010-01-24 08:48:15 +00001258 kernel=DestroyKernelInfo(kernel);
cristy3ed852e2009-09-05 21:47:34 +00001259 if (convolve_image == (Image *) NULL)
1260 break;
1261 *image=DestroyImage(*image);
1262 *image=convolve_image;
1263 break;
1264 }
1265 if (LocaleCompare("crop",option+1) == 0)
1266 {
cristy6b3da3a2010-06-20 02:21:46 +00001267 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001268 flags=ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1269 if (((geometry.width != 0) || (geometry.height != 0)) &&
1270 ((flags & XValue) == 0) && ((flags & YValue) == 0))
1271 break;
1272 (void) TransformImage(image,argv[i+1],(char *) NULL);
1273 InheritException(exception,&(*image)->exception);
1274 break;
1275 }
1276 if (LocaleCompare("cycle",option+1) == 0)
1277 {
1278 /*
1279 Cycle an image colormap.
1280 */
cristy6b3da3a2010-06-20 02:21:46 +00001281 (void) SyncImageSettings(mogrify_info,*image);
cristyf2f27272009-12-17 14:48:46 +00001282 (void) CycleColormapImage(*image,StringToLong(argv[i+1]));
cristy3ed852e2009-09-05 21:47:34 +00001283 InheritException(exception,&(*image)->exception);
1284 break;
1285 }
1286 break;
1287 }
1288 case 'd':
1289 {
1290 if (LocaleCompare("decipher",option+1) == 0)
1291 {
1292 StringInfo
1293 *passkey;
1294
1295 /*
1296 Decipher pixels.
1297 */
cristy6b3da3a2010-06-20 02:21:46 +00001298 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001299 passkey=FileToStringInfo(argv[i+1],~0,exception);
1300 if (passkey != (StringInfo *) NULL)
1301 {
1302 (void) PasskeyDecipherImage(*image,passkey,exception);
1303 passkey=DestroyStringInfo(passkey);
1304 }
1305 break;
1306 }
1307 if (LocaleCompare("density",option+1) == 0)
1308 {
1309 /*
1310 Set image density.
1311 */
1312 (void) CloneString(&draw_info->density,argv[i+1]);
1313 break;
1314 }
1315 if (LocaleCompare("depth",option+1) == 0)
1316 {
cristy6b3da3a2010-06-20 02:21:46 +00001317 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001318 if (*option == '+')
1319 {
1320 (void) SetImageDepth(*image,MAGICKCORE_QUANTUM_DEPTH);
1321 break;
1322 }
cristye27293e2009-12-18 02:53:20 +00001323 (void) SetImageDepth(*image,StringToUnsignedLong(argv[i+1]));
cristy3ed852e2009-09-05 21:47:34 +00001324 break;
1325 }
1326 if (LocaleCompare("deskew",option+1) == 0)
1327 {
1328 double
1329 threshold;
1330
1331 Image
1332 *deskew_image;
1333
1334 /*
1335 Straighten the image.
1336 */
cristy6b3da3a2010-06-20 02:21:46 +00001337 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001338 if (*option == '+')
1339 threshold=40.0*QuantumRange/100.0;
1340 else
cristyf2f27272009-12-17 14:48:46 +00001341 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
cristy3ed852e2009-09-05 21:47:34 +00001342 deskew_image=DeskewImage(*image,threshold,exception);
1343 if (deskew_image == (Image *) NULL)
1344 break;
1345 *image=DestroyImage(*image);
1346 *image=deskew_image;
1347 break;
1348 }
1349 if (LocaleCompare("despeckle",option+1) == 0)
1350 {
1351 Image
1352 *despeckle_image;
1353
1354 /*
1355 Reduce the speckles within an image.
1356 */
cristy6b3da3a2010-06-20 02:21:46 +00001357 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001358 despeckle_image=DespeckleImage(*image,exception);
1359 if (despeckle_image == (Image *) NULL)
1360 break;
1361 *image=DestroyImage(*image);
1362 *image=despeckle_image;
1363 break;
1364 }
1365 if (LocaleCompare("display",option+1) == 0)
1366 {
1367 (void) CloneString(&draw_info->server_name,argv[i+1]);
1368 break;
1369 }
cristy3ed852e2009-09-05 21:47:34 +00001370 if (LocaleCompare("distort",option+1) == 0)
1371 {
1372 char
1373 *args,
1374 token[MaxTextExtent];
1375
1376 const char
1377 *p;
1378
1379 DistortImageMethod
1380 method;
1381
1382 double
1383 *arguments;
1384
1385 Image
1386 *distort_image;
1387
cristybb503372010-05-27 20:51:26 +00001388 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001389 x;
1390
cristybb503372010-05-27 20:51:26 +00001391 size_t
cristy3ed852e2009-09-05 21:47:34 +00001392 number_arguments;
1393
1394 /*
1395 Distort image.
1396 */
cristy6b3da3a2010-06-20 02:21:46 +00001397 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001398 method=(DistortImageMethod) ParseMagickOption(MagickDistortOptions,
1399 MagickFalse,argv[i+1]);
cristy6b3da3a2010-06-20 02:21:46 +00001400 args=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
cristy3ed852e2009-09-05 21:47:34 +00001401 InheritException(exception,&(*image)->exception);
1402 if (args == (char *) NULL)
1403 break;
1404 p=(char *) args;
1405 for (x=0; *p != '\0'; x++)
1406 {
1407 GetMagickToken(p,&p,token);
1408 if (*token == ',')
1409 GetMagickToken(p,&p,token);
1410 }
cristybb503372010-05-27 20:51:26 +00001411 number_arguments=(size_t) x;
cristy3ed852e2009-09-05 21:47:34 +00001412 arguments=(double *) AcquireQuantumMemory(number_arguments,
1413 sizeof(*arguments));
1414 if (arguments == (double *) NULL)
1415 ThrowWandFatalException(ResourceLimitFatalError,
1416 "MemoryAllocationFailed",(*image)->filename);
1417 (void) ResetMagickMemory(arguments,0,number_arguments*
1418 sizeof(*arguments));
1419 p=(char *) args;
cristybb503372010-05-27 20:51:26 +00001420 for (x=0; (x < (ssize_t) number_arguments) && (*p != '\0'); x++)
cristy3ed852e2009-09-05 21:47:34 +00001421 {
1422 GetMagickToken(p,&p,token);
1423 if (*token == ',')
1424 GetMagickToken(p,&p,token);
cristyf2f27272009-12-17 14:48:46 +00001425 arguments[x]=StringToDouble(token);
cristy3ed852e2009-09-05 21:47:34 +00001426 }
1427 args=DestroyString(args);
1428 distort_image=DistortImage(*image,method,number_arguments,arguments,
1429 (*option == '+') ? MagickTrue : MagickFalse,exception);
1430 arguments=(double *) RelinquishMagickMemory(arguments);
1431 if (distort_image == (Image *) NULL)
1432 break;
1433 *image=DestroyImage(*image);
1434 *image=distort_image;
1435 break;
1436 }
1437 if (LocaleCompare("dither",option+1) == 0)
1438 {
1439 if (*option == '+')
1440 {
1441 quantize_info->dither=MagickFalse;
1442 break;
1443 }
1444 quantize_info->dither=MagickTrue;
1445 quantize_info->dither_method=(DitherMethod) ParseMagickOption(
1446 MagickDitherOptions,MagickFalse,argv[i+1]);
1447 if (quantize_info->dither_method == NoDitherMethod)
1448 quantize_info->dither=MagickFalse;
1449 break;
1450 }
1451 if (LocaleCompare("draw",option+1) == 0)
1452 {
1453 /*
1454 Draw image.
1455 */
cristy6b3da3a2010-06-20 02:21:46 +00001456 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001457 (void) CloneString(&draw_info->primitive,argv[i+1]);
1458 (void) DrawImage(*image,draw_info);
1459 InheritException(exception,&(*image)->exception);
1460 break;
1461 }
1462 break;
1463 }
1464 case 'e':
1465 {
1466 if (LocaleCompare("edge",option+1) == 0)
1467 {
1468 Image
1469 *edge_image;
1470
1471 /*
1472 Enhance edges in the image.
1473 */
cristy6b3da3a2010-06-20 02:21:46 +00001474 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001475 flags=ParseGeometry(argv[i+1],&geometry_info);
1476 if ((flags & SigmaValue) == 0)
1477 geometry_info.sigma=1.0;
1478 edge_image=EdgeImage(*image,geometry_info.rho,exception);
1479 if (edge_image == (Image *) NULL)
1480 break;
1481 *image=DestroyImage(*image);
1482 *image=edge_image;
1483 break;
1484 }
1485 if (LocaleCompare("emboss",option+1) == 0)
1486 {
1487 Image
1488 *emboss_image;
1489
1490 /*
1491 Gaussian embossen image.
1492 */
cristy6b3da3a2010-06-20 02:21:46 +00001493 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001494 flags=ParseGeometry(argv[i+1],&geometry_info);
1495 if ((flags & SigmaValue) == 0)
1496 geometry_info.sigma=1.0;
1497 emboss_image=EmbossImage(*image,geometry_info.rho,
1498 geometry_info.sigma,exception);
1499 if (emboss_image == (Image *) NULL)
1500 break;
1501 *image=DestroyImage(*image);
1502 *image=emboss_image;
1503 break;
1504 }
1505 if (LocaleCompare("encipher",option+1) == 0)
1506 {
1507 StringInfo
1508 *passkey;
1509
1510 /*
1511 Encipher pixels.
1512 */
cristy6b3da3a2010-06-20 02:21:46 +00001513 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001514 passkey=FileToStringInfo(argv[i+1],~0,exception);
1515 if (passkey != (StringInfo *) NULL)
1516 {
1517 (void) PasskeyEncipherImage(*image,passkey,exception);
1518 passkey=DestroyStringInfo(passkey);
1519 }
1520 break;
1521 }
1522 if (LocaleCompare("encoding",option+1) == 0)
1523 {
1524 (void) CloneString(&draw_info->encoding,argv[i+1]);
1525 break;
1526 }
1527 if (LocaleCompare("enhance",option+1) == 0)
1528 {
1529 Image
1530 *enhance_image;
1531
1532 /*
1533 Enhance image.
1534 */
cristy6b3da3a2010-06-20 02:21:46 +00001535 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001536 enhance_image=EnhanceImage(*image,exception);
1537 if (enhance_image == (Image *) NULL)
1538 break;
1539 *image=DestroyImage(*image);
1540 *image=enhance_image;
1541 break;
1542 }
1543 if (LocaleCompare("equalize",option+1) == 0)
1544 {
1545 /*
1546 Equalize image.
1547 */
cristy6b3da3a2010-06-20 02:21:46 +00001548 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001549 (void) EqualizeImageChannel(*image,channel);
1550 InheritException(exception,&(*image)->exception);
1551 break;
1552 }
1553 if (LocaleCompare("evaluate",option+1) == 0)
1554 {
1555 double
1556 constant;
1557
1558 MagickEvaluateOperator
1559 op;
1560
cristy6b3da3a2010-06-20 02:21:46 +00001561 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001562 op=(MagickEvaluateOperator) ParseMagickOption(MagickEvaluateOptions,
1563 MagickFalse,argv[i+1]);
cristyf2f27272009-12-17 14:48:46 +00001564 constant=SiPrefixToDouble(argv[i+2],QuantumRange);
cristy3ed852e2009-09-05 21:47:34 +00001565 (void) EvaluateImageChannel(*image,channel,op,constant,exception);
1566 break;
1567 }
1568 if (LocaleCompare("extent",option+1) == 0)
1569 {
1570 Image
1571 *extent_image;
1572
1573 /*
1574 Set the image extent.
1575 */
cristy6b3da3a2010-06-20 02:21:46 +00001576 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001577 flags=ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
cristyf0bbfd92009-11-25 14:12:31 +00001578 if (geometry.width == 0)
cristy2ea9a4e2009-11-25 14:30:22 +00001579 geometry.width=(*image)->columns;
cristyf0bbfd92009-11-25 14:12:31 +00001580 if (geometry.height == 0)
cristy2ea9a4e2009-11-25 14:30:22 +00001581 geometry.height=(*image)->rows;
cristy3ed852e2009-09-05 21:47:34 +00001582 geometry.x=(-geometry.x);
1583 geometry.y=(-geometry.y);
1584 extent_image=ExtentImage(*image,&geometry,exception);
1585 if (extent_image == (Image *) NULL)
1586 break;
1587 *image=DestroyImage(*image);
1588 *image=extent_image;
1589 break;
1590 }
1591 break;
1592 }
1593 case 'f':
1594 {
1595 if (LocaleCompare("family",option+1) == 0)
1596 {
1597 if (*option == '+')
1598 {
1599 if (draw_info->family != (char *) NULL)
1600 draw_info->family=DestroyString(draw_info->family);
1601 break;
1602 }
1603 (void) CloneString(&draw_info->family,argv[i+1]);
1604 break;
1605 }
cristy0fe961c2010-01-30 03:09:54 +00001606 if (LocaleCompare("features",option+1) == 0)
1607 {
1608 if (*option == '+')
1609 {
1610 (void) DeleteImageArtifact(*image,"identify:features");
1611 break;
1612 }
1613 (void) SetImageArtifact(*image,"identify:features",argv[i+1]);
1614 break;
1615 }
cristy3ed852e2009-09-05 21:47:34 +00001616 if (LocaleCompare("fill",option+1) == 0)
1617 {
1618 ExceptionInfo
1619 *sans;
1620
1621 GetMagickPixelPacket(*image,&fill);
1622 if (*option == '+')
1623 {
1624 (void) QueryMagickColor("none",&fill,exception);
1625 (void) QueryColorDatabase("none",&draw_info->fill,exception);
1626 if (draw_info->fill_pattern != (Image *) NULL)
1627 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
1628 break;
1629 }
1630 sans=AcquireExceptionInfo();
1631 (void) QueryMagickColor(argv[i+1],&fill,sans);
1632 status=QueryColorDatabase(argv[i+1],&draw_info->fill,sans);
1633 sans=DestroyExceptionInfo(sans);
1634 if (status == MagickFalse)
cristy6b3da3a2010-06-20 02:21:46 +00001635 draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1],
cristy3ed852e2009-09-05 21:47:34 +00001636 exception);
1637 break;
1638 }
1639 if (LocaleCompare("flip",option+1) == 0)
1640 {
1641 Image
1642 *flip_image;
1643
1644 /*
1645 Flip image scanlines.
1646 */
cristy6b3da3a2010-06-20 02:21:46 +00001647 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001648 flip_image=FlipImage(*image,exception);
1649 if (flip_image == (Image *) NULL)
1650 break;
1651 *image=DestroyImage(*image);
1652 *image=flip_image;
1653 break;
1654 }
1655 if (LocaleCompare("flop",option+1) == 0)
1656 {
1657 Image
1658 *flop_image;
1659
1660 /*
1661 Flop image scanlines.
1662 */
cristy6b3da3a2010-06-20 02:21:46 +00001663 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001664 flop_image=FlopImage(*image,exception);
1665 if (flop_image == (Image *) NULL)
1666 break;
1667 *image=DestroyImage(*image);
1668 *image=flop_image;
1669 break;
1670 }
1671 if (LocaleCompare("floodfill",option+1) == 0)
1672 {
1673 MagickPixelPacket
1674 target;
1675
1676 /*
1677 Floodfill image.
1678 */
cristy6b3da3a2010-06-20 02:21:46 +00001679 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001680 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
1681 (void) QueryMagickColor(argv[i+2],&target,exception);
1682 (void) FloodfillPaintImage(*image,channel,draw_info,&target,
1683 geometry.x,geometry.y,*option == '-' ? MagickFalse : MagickTrue);
1684 InheritException(exception,&(*image)->exception);
1685 break;
1686 }
1687 if (LocaleCompare("font",option+1) == 0)
1688 {
1689 if (*option == '+')
1690 {
1691 if (draw_info->font != (char *) NULL)
1692 draw_info->font=DestroyString(draw_info->font);
1693 break;
1694 }
1695 (void) CloneString(&draw_info->font,argv[i+1]);
1696 break;
1697 }
1698 if (LocaleCompare("format",option+1) == 0)
1699 {
1700 format=argv[i+1];
1701 break;
1702 }
1703 if (LocaleCompare("frame",option+1) == 0)
1704 {
1705 FrameInfo
1706 frame_info;
1707
1708 Image
1709 *frame_image;
1710
1711 /*
1712 Surround image with an ornamental border.
1713 */
cristy6b3da3a2010-06-20 02:21:46 +00001714 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001715 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
1716 frame_info.width=geometry.width;
1717 frame_info.height=geometry.height;
1718 if ((flags & HeightValue) == 0)
1719 frame_info.height=geometry.width;
1720 frame_info.outer_bevel=geometry.x;
1721 frame_info.inner_bevel=geometry.y;
cristybb503372010-05-27 20:51:26 +00001722 frame_info.x=(ssize_t) frame_info.width;
1723 frame_info.y=(ssize_t) frame_info.height;
cristy3ed852e2009-09-05 21:47:34 +00001724 frame_info.width=(*image)->columns+2*frame_info.width;
1725 frame_info.height=(*image)->rows+2*frame_info.height;
1726 frame_image=FrameImage(*image,&frame_info,exception);
1727 if (frame_image == (Image *) NULL)
1728 break;
1729 *image=DestroyImage(*image);
1730 *image=frame_image;
1731 break;
1732 }
1733 if (LocaleCompare("function",option+1) == 0)
1734 {
1735 char
1736 *arguments,
1737 token[MaxTextExtent];
1738
1739 const char
1740 *p;
1741
1742 double
1743 *parameters;
1744
1745 MagickFunction
1746 function;
1747
cristybb503372010-05-27 20:51:26 +00001748 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001749 x;
1750
cristybb503372010-05-27 20:51:26 +00001751 size_t
cristy3ed852e2009-09-05 21:47:34 +00001752 number_parameters;
1753
1754 /*
1755 Function Modify Image Values
1756 */
cristy6b3da3a2010-06-20 02:21:46 +00001757 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001758 function=(MagickFunction) ParseMagickOption(MagickFunctionOptions,
1759 MagickFalse,argv[i+1]);
cristy6b3da3a2010-06-20 02:21:46 +00001760 arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
cristy3ed852e2009-09-05 21:47:34 +00001761 InheritException(exception,&(*image)->exception);
1762 if (arguments == (char *) NULL)
1763 break;
1764 p=(char *) arguments;
1765 for (x=0; *p != '\0'; x++)
1766 {
1767 GetMagickToken(p,&p,token);
1768 if (*token == ',')
1769 GetMagickToken(p,&p,token);
1770 }
cristybb503372010-05-27 20:51:26 +00001771 number_parameters=(size_t) x;
cristy3ed852e2009-09-05 21:47:34 +00001772 parameters=(double *) AcquireQuantumMemory(number_parameters,
1773 sizeof(*parameters));
1774 if (parameters == (double *) NULL)
1775 ThrowWandFatalException(ResourceLimitFatalError,
1776 "MemoryAllocationFailed",(*image)->filename);
1777 (void) ResetMagickMemory(parameters,0,number_parameters*
1778 sizeof(*parameters));
1779 p=(char *) arguments;
cristybb503372010-05-27 20:51:26 +00001780 for (x=0; (x < (ssize_t) number_parameters) && (*p != '\0'); x++)
cristy3ed852e2009-09-05 21:47:34 +00001781 {
1782 GetMagickToken(p,&p,token);
1783 if (*token == ',')
1784 GetMagickToken(p,&p,token);
cristyf2f27272009-12-17 14:48:46 +00001785 parameters[x]=StringToDouble(token);
cristy3ed852e2009-09-05 21:47:34 +00001786 }
1787 arguments=DestroyString(arguments);
1788 (void) FunctionImageChannel(*image,channel,function,
1789 number_parameters,parameters,exception);
1790 parameters=(double *) RelinquishMagickMemory(parameters);
1791 break;
1792 }
1793 break;
1794 }
1795 case 'g':
1796 {
1797 if (LocaleCompare("gamma",option+1) == 0)
1798 {
1799 /*
1800 Gamma image.
1801 */
cristy6b3da3a2010-06-20 02:21:46 +00001802 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001803 if (*option == '+')
cristyf2f27272009-12-17 14:48:46 +00001804 (*image)->gamma=StringToDouble(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00001805 else
1806 {
1807 if (strchr(argv[i+1],',') != (char *) NULL)
1808 (void) GammaImage(*image,argv[i+1]);
1809 else
cristya5447be2010-01-11 00:20:51 +00001810 (void) GammaImageChannel(*image,channel,
1811 StringToDouble(argv[i+1]));
cristy3ed852e2009-09-05 21:47:34 +00001812 InheritException(exception,&(*image)->exception);
1813 }
1814 break;
1815 }
1816 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
1817 (LocaleCompare("gaussian",option+1) == 0))
1818 {
1819 Image
1820 *gaussian_image;
1821
1822 /*
1823 Gaussian blur image.
1824 */
cristy6b3da3a2010-06-20 02:21:46 +00001825 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001826 flags=ParseGeometry(argv[i+1],&geometry_info);
1827 if ((flags & SigmaValue) == 0)
1828 geometry_info.sigma=1.0;
1829 gaussian_image=GaussianBlurImageChannel(*image,channel,
1830 geometry_info.rho,geometry_info.sigma,exception);
1831 if (gaussian_image == (Image *) NULL)
1832 break;
1833 *image=DestroyImage(*image);
1834 *image=gaussian_image;
1835 break;
1836 }
1837 if (LocaleCompare("geometry",option+1) == 0)
1838 {
cristy6b3da3a2010-06-20 02:21:46 +00001839 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001840 if (*option == '+')
1841 {
1842 if ((*image)->geometry != (char *) NULL)
1843 (*image)->geometry=DestroyString((*image)->geometry);
1844 break;
1845 }
1846 flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
1847 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
1848 (void) CloneString(&(*image)->geometry,argv[i+1]);
1849 else
1850 {
1851 Image
1852 *zoom_image;
1853
1854 /*
1855 Resize image.
1856 */
1857 zoom_image=ZoomImage(*image,geometry.width,geometry.height,
1858 exception);
1859 if (zoom_image == (Image *) NULL)
1860 break;
1861 *image=DestroyImage(*image);
1862 *image=zoom_image;
1863 }
1864 break;
1865 }
1866 if (LocaleCompare("gravity",option+1) == 0)
1867 {
1868 if (*option == '+')
1869 {
1870 draw_info->gravity=UndefinedGravity;
1871 break;
1872 }
1873 draw_info->gravity=(GravityType) ParseMagickOption(
1874 MagickGravityOptions,MagickFalse,argv[i+1]);
1875 break;
1876 }
1877 break;
1878 }
1879 case 'h':
1880 {
1881 if (LocaleCompare("highlight-color",option+1) == 0)
1882 {
1883 (void) SetImageArtifact(*image,option+1,argv[i+1]);
1884 break;
1885 }
1886 break;
1887 }
1888 case 'i':
1889 {
1890 if (LocaleCompare("identify",option+1) == 0)
1891 {
1892 char
1893 *text;
1894
cristy6b3da3a2010-06-20 02:21:46 +00001895 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001896 if (format == (char *) NULL)
1897 {
cristy6b3da3a2010-06-20 02:21:46 +00001898 (void) IdentifyImage(*image,stdout,mogrify_info->verbose);
cristy3ed852e2009-09-05 21:47:34 +00001899 InheritException(exception,&(*image)->exception);
1900 break;
1901 }
cristy6b3da3a2010-06-20 02:21:46 +00001902 text=InterpretImageProperties(mogrify_info,*image,format);
cristy3ed852e2009-09-05 21:47:34 +00001903 InheritException(exception,&(*image)->exception);
1904 if (text == (char *) NULL)
1905 break;
1906 (void) fputs(text,stdout);
1907 (void) fputc('\n',stdout);
1908 text=DestroyString(text);
1909 break;
1910 }
1911 if (LocaleCompare("implode",option+1) == 0)
1912 {
1913 Image
1914 *implode_image;
1915
1916 /*
1917 Implode image.
1918 */
cristy6b3da3a2010-06-20 02:21:46 +00001919 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001920 (void) ParseGeometry(argv[i+1],&geometry_info);
1921 implode_image=ImplodeImage(*image,geometry_info.rho,exception);
1922 if (implode_image == (Image *) NULL)
1923 break;
1924 *image=DestroyImage(*image);
1925 *image=implode_image;
1926 break;
1927 }
cristyb32b90a2009-09-07 21:45:48 +00001928 if (LocaleCompare("interline-spacing",option+1) == 0)
1929 {
1930 if (*option == '+')
1931 (void) ParseGeometry("0",&geometry_info);
1932 else
1933 (void) ParseGeometry(argv[i+1],&geometry_info);
1934 draw_info->interline_spacing=geometry_info.rho;
1935 break;
1936 }
cristy3ed852e2009-09-05 21:47:34 +00001937 if (LocaleCompare("interword-spacing",option+1) == 0)
1938 {
1939 if (*option == '+')
1940 (void) ParseGeometry("0",&geometry_info);
1941 else
1942 (void) ParseGeometry(argv[i+1],&geometry_info);
1943 draw_info->interword_spacing=geometry_info.rho;
1944 break;
1945 }
1946 break;
1947 }
1948 case 'k':
1949 {
1950 if (LocaleCompare("kerning",option+1) == 0)
1951 {
1952 if (*option == '+')
1953 (void) ParseGeometry("0",&geometry_info);
1954 else
1955 (void) ParseGeometry(argv[i+1],&geometry_info);
1956 draw_info->kerning=geometry_info.rho;
1957 break;
1958 }
1959 break;
1960 }
1961 case 'l':
1962 {
1963 if (LocaleCompare("lat",option+1) == 0)
1964 {
1965 Image
1966 *threshold_image;
1967
1968 /*
1969 Local adaptive threshold image.
1970 */
cristy6b3da3a2010-06-20 02:21:46 +00001971 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001972 flags=ParseGeometry(argv[i+1],&geometry_info);
1973 if ((flags & PercentValue) != 0)
1974 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
cristybb503372010-05-27 20:51:26 +00001975 threshold_image=AdaptiveThresholdImage(*image,(size_t)
1976 geometry_info.rho,(size_t) geometry_info.sigma,
1977 (ssize_t) geometry_info.xi,exception);
cristy3ed852e2009-09-05 21:47:34 +00001978 if (threshold_image == (Image *) NULL)
1979 break;
1980 *image=DestroyImage(*image);
1981 *image=threshold_image;
1982 break;
1983 }
1984 if (LocaleCompare("level",option+1) == 0)
1985 {
cristy3ed852e2009-09-05 21:47:34 +00001986 MagickRealType
1987 black_point,
1988 gamma,
1989 white_point;
1990
1991 MagickStatusType
1992 flags;
1993
1994 /*
1995 Parse levels.
1996 */
cristy6b3da3a2010-06-20 02:21:46 +00001997 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001998 flags=ParseGeometry(argv[i+1],&geometry_info);
1999 black_point=geometry_info.rho;
2000 white_point=(MagickRealType) QuantumRange;
2001 if ((flags & SigmaValue) != 0)
2002 white_point=geometry_info.sigma;
2003 gamma=1.0;
2004 if ((flags & XiValue) != 0)
2005 gamma=geometry_info.xi;
2006 if ((flags & PercentValue) != 0)
2007 {
2008 black_point*=(MagickRealType) (QuantumRange/100.0);
2009 white_point*=(MagickRealType) (QuantumRange/100.0);
2010 }
2011 if ((flags & SigmaValue) == 0)
2012 white_point=(MagickRealType) QuantumRange-black_point;
2013 if ((*option == '+') || ((flags & AspectValue) != 0))
2014 (void) LevelizeImageChannel(*image,channel,black_point,
2015 white_point,gamma);
2016 else
2017 (void) LevelImageChannel(*image,channel,black_point,white_point,
2018 gamma);
2019 InheritException(exception,&(*image)->exception);
2020 break;
2021 }
2022 if (LocaleCompare("level-colors",option+1) == 0)
2023 {
2024 char
2025 token[MaxTextExtent];
2026
2027 const char
2028 *p;
2029
2030 MagickPixelPacket
2031 black_point,
2032 white_point;
2033
2034 p=(const char *) argv[i+1];
2035 GetMagickToken(p,&p,token); /* get black point color */
cristyee0f8d72009-09-19 00:58:29 +00002036 if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
cristy3ed852e2009-09-05 21:47:34 +00002037 (void) QueryMagickColor(token,&black_point,exception);
2038 else
cristyee0f8d72009-09-19 00:58:29 +00002039 (void) QueryMagickColor("#000000",&black_point,exception);
cristy3ed852e2009-09-05 21:47:34 +00002040 if (isalpha((int) token[0]) || (token[0] == '#'))
2041 GetMagickToken(p,&p,token);
cristyee0f8d72009-09-19 00:58:29 +00002042 if (*token == '\0')
cristy3ed852e2009-09-05 21:47:34 +00002043 white_point=black_point; /* set everything to that color */
2044 else
2045 {
2046 /*
2047 Get white point color.
2048 */
cristyee0f8d72009-09-19 00:58:29 +00002049 if ((isalpha((int) *token) == 0) && ((*token == '#') == 0))
cristy3ed852e2009-09-05 21:47:34 +00002050 GetMagickToken(p,&p,token);
cristyee0f8d72009-09-19 00:58:29 +00002051 if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
cristy3ed852e2009-09-05 21:47:34 +00002052 (void) QueryMagickColor(token,&white_point,exception);
2053 else
cristyee0f8d72009-09-19 00:58:29 +00002054 (void) QueryMagickColor("#ffffff",&white_point,exception);
cristy3ed852e2009-09-05 21:47:34 +00002055 }
cristy74fe8f12009-10-03 19:09:01 +00002056 (void) LevelColorsImageChannel(*image,channel,&black_point,
2057 &white_point,*option == '+' ? MagickTrue : MagickFalse);
cristy3ed852e2009-09-05 21:47:34 +00002058 break;
2059 }
2060 if (LocaleCompare("linear-stretch",option+1) == 0)
2061 {
2062 double
2063 black_point,
2064 white_point;
2065
cristy3ed852e2009-09-05 21:47:34 +00002066 MagickStatusType
2067 flags;
2068
cristy6b3da3a2010-06-20 02:21:46 +00002069 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002070 flags=ParseGeometry(argv[i+1],&geometry_info);
2071 black_point=geometry_info.rho;
2072 white_point=(MagickRealType) (*image)->columns*(*image)->rows;
2073 if ((flags & SigmaValue) != 0)
2074 white_point=geometry_info.sigma;
2075 if ((flags & PercentValue) != 0)
2076 {
2077 black_point*=(double) (*image)->columns*(*image)->rows/100.0;
2078 white_point*=(double) (*image)->columns*(*image)->rows/100.0;
2079 }
2080 if ((flags & SigmaValue) == 0)
2081 white_point=(MagickRealType) (*image)->columns*(*image)->rows-
2082 black_point;
2083 (void) LinearStretchImage(*image,black_point,white_point);
2084 InheritException(exception,&(*image)->exception);
2085 break;
2086 }
2087 if (LocaleCompare("linewidth",option+1) == 0)
2088 {
cristyf2f27272009-12-17 14:48:46 +00002089 draw_info->stroke_width=StringToDouble(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00002090 break;
2091 }
2092 if (LocaleCompare("liquid-rescale",option+1) == 0)
2093 {
2094 Image
2095 *resize_image;
2096
2097 /*
2098 Liquid rescale image.
2099 */
cristy6b3da3a2010-06-20 02:21:46 +00002100 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002101 flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2102 if ((flags & XValue) == 0)
2103 geometry.x=1;
2104 if ((flags & YValue) == 0)
2105 geometry.y=0;
2106 resize_image=LiquidRescaleImage(*image,geometry.width,
2107 geometry.height,1.0*geometry.x,1.0*geometry.y,exception);
2108 if (resize_image == (Image *) NULL)
2109 break;
2110 *image=DestroyImage(*image);
2111 *image=resize_image;
2112 break;
2113 }
2114 if (LocaleCompare("lowlight-color",option+1) == 0)
2115 {
2116 (void) SetImageArtifact(*image,option+1,argv[i+1]);
2117 break;
2118 }
2119 break;
2120 }
2121 case 'm':
2122 {
2123 if (LocaleCompare("map",option+1) == 0)
2124 {
2125 Image
2126 *remap_image;
2127
2128 /*
2129 Transform image colors to match this set of colors.
2130 */
cristy6b3da3a2010-06-20 02:21:46 +00002131 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002132 if (*option == '+')
2133 break;
cristy6b3da3a2010-06-20 02:21:46 +00002134 remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
cristy3ed852e2009-09-05 21:47:34 +00002135 if (remap_image == (Image *) NULL)
2136 break;
2137 (void) RemapImage(quantize_info,*image,remap_image);
2138 InheritException(exception,&(*image)->exception);
2139 remap_image=DestroyImage(remap_image);
2140 break;
2141 }
2142 if (LocaleCompare("mask",option+1) == 0)
2143 {
2144 Image
2145 *mask;
2146
cristy6b3da3a2010-06-20 02:21:46 +00002147 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002148 if (*option == '+')
2149 {
2150 /*
2151 Remove a mask.
2152 */
2153 (void) SetImageMask(*image,(Image *) NULL);
2154 InheritException(exception,&(*image)->exception);
2155 break;
2156 }
2157 /*
2158 Set the image mask.
2159 */
cristy6b3da3a2010-06-20 02:21:46 +00002160 mask=GetImageCache(mogrify_info,argv[i+1],exception);
cristy3ed852e2009-09-05 21:47:34 +00002161 if (mask == (Image *) NULL)
2162 break;
2163 (void) SetImageMask(*image,mask);
2164 mask=DestroyImage(mask);
2165 InheritException(exception,&(*image)->exception);
2166 break;
2167 }
2168 if (LocaleCompare("matte",option+1) == 0)
2169 {
2170 (void) SetImageAlphaChannel(*image,(*option == '-') ?
2171 SetAlphaChannel : DeactivateAlphaChannel );
2172 InheritException(exception,&(*image)->exception);
2173 break;
2174 }
2175 if (LocaleCompare("median",option+1) == 0)
2176 {
2177 Image
2178 *median_image;
2179
2180 /*
2181 Median filter image.
2182 */
cristy6b3da3a2010-06-20 02:21:46 +00002183 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002184 (void) ParseGeometry(argv[i+1],&geometry_info);
2185 median_image=MedianFilterImage(*image,geometry_info.rho,exception);
2186 if (median_image == (Image *) NULL)
2187 break;
2188 *image=DestroyImage(*image);
2189 *image=median_image;
2190 break;
2191 }
2192 if (LocaleCompare("modulate",option+1) == 0)
2193 {
cristy6b3da3a2010-06-20 02:21:46 +00002194 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002195 (void) ModulateImage(*image,argv[i+1]);
2196 InheritException(exception,&(*image)->exception);
2197 break;
2198 }
2199 if (LocaleCompare("monitor",option+1) == 0)
2200 {
cristy7d34ef22010-03-25 01:11:22 +00002201 if (*option == '+')
2202 {
2203 (void) SetImageProgressMonitor(*image,
2204 (MagickProgressMonitor) NULL,(void *) NULL);
2205 break;
2206 }
cristy3ed852e2009-09-05 21:47:34 +00002207 (void) SetImageProgressMonitor(*image,MonitorProgress,
2208 (void *) NULL);
2209 break;
2210 }
2211 if (LocaleCompare("monochrome",option+1) == 0)
2212 {
cristy6b3da3a2010-06-20 02:21:46 +00002213 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002214 (void) SetImageType(*image,BilevelType);
2215 InheritException(exception,&(*image)->exception);
2216 break;
2217 }
anthony29188a82010-01-22 10:12:34 +00002218 if (LocaleCompare("morphology",option+1) == 0)
2219 {
anthony29188a82010-01-22 10:12:34 +00002220 char
2221 token[MaxTextExtent];
2222
2223 const char
2224 *p;
2225
cristye96405a2010-05-19 02:24:31 +00002226 Image
2227 *morphology_image;
2228
2229 KernelInfo
2230 *kernel;
2231
cristybb503372010-05-27 20:51:26 +00002232 ssize_t
anthony29188a82010-01-22 10:12:34 +00002233 iterations;
2234
cristye96405a2010-05-19 02:24:31 +00002235 MorphologyMethod
2236 method;
2237
anthony29188a82010-01-22 10:12:34 +00002238 /*
2239 Morphological Image Operation
2240 */
cristy6b3da3a2010-06-20 02:21:46 +00002241 (void) SyncImageSettings(mogrify_info,*image);
anthony29188a82010-01-22 10:12:34 +00002242 p=argv[i+1];
2243 GetMagickToken(p,&p,token);
2244 method=(MorphologyMethod) ParseMagickOption(MagickMorphologyOptions,
cristyd2c1e1e2010-05-08 01:05:44 +00002245 MagickFalse,token);
cristyef656912010-03-05 19:54:59 +00002246 iterations=1L;
anthony29188a82010-01-22 10:12:34 +00002247 GetMagickToken(p,&p,token);
cristyef656912010-03-05 19:54:59 +00002248 if ((*p == ':') || (*p == ','))
anthony29188a82010-01-22 10:12:34 +00002249 GetMagickToken(p,&p,token);
cristyef656912010-03-05 19:54:59 +00002250 if ((*p != '\0'))
2251 iterations=StringToLong(p);
anthony29188a82010-01-22 10:12:34 +00002252 kernel=AcquireKernelInfo(argv[i+2]);
2253 if (kernel == (KernelInfo *) NULL)
cristye96405a2010-05-19 02:24:31 +00002254 {
2255 (void) ThrowMagickException(exception,GetMagickModule(),
2256 OptionError,"UnabletoParseKernel","morphology");
2257 status=MagickFalse;
2258 break;
2259 }
anthony29188a82010-01-22 10:12:34 +00002260 morphology_image=MorphologyImageChannel(*image,channel,method,
cristy02d5b4f2010-02-01 01:08:27 +00002261 iterations,kernel,exception);
anthony83ba99b2010-01-24 08:48:15 +00002262 kernel=DestroyKernelInfo(kernel);
anthony29188a82010-01-22 10:12:34 +00002263 if (morphology_image == (Image *) NULL)
2264 break;
2265 *image=DestroyImage(*image);
2266 *image=morphology_image;
2267 break;
2268 }
cristy3ed852e2009-09-05 21:47:34 +00002269 if (LocaleCompare("motion-blur",option+1) == 0)
2270 {
2271 Image
2272 *blur_image;
2273
2274 /*
2275 Motion blur image.
2276 */
cristy6b3da3a2010-06-20 02:21:46 +00002277 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002278 flags=ParseGeometry(argv[i+1],&geometry_info);
2279 if ((flags & SigmaValue) == 0)
2280 geometry_info.sigma=1.0;
2281 blur_image=MotionBlurImageChannel(*image,channel,geometry_info.rho,
2282 geometry_info.sigma,geometry_info.xi,exception);
2283 if (blur_image == (Image *) NULL)
2284 break;
2285 *image=DestroyImage(*image);
2286 *image=blur_image;
2287 break;
2288 }
2289 break;
2290 }
2291 case 'n':
2292 {
2293 if (LocaleCompare("negate",option+1) == 0)
2294 {
cristy6b3da3a2010-06-20 02:21:46 +00002295 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002296 (void) NegateImageChannel(*image,channel,*option == '+' ?
2297 MagickTrue : MagickFalse);
2298 InheritException(exception,&(*image)->exception);
2299 break;
2300 }
2301 if (LocaleCompare("noise",option+1) == 0)
2302 {
2303 Image
2304 *noisy_image;
2305
cristy6b3da3a2010-06-20 02:21:46 +00002306 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002307 if (*option == '-')
2308 {
2309 (void) ParseGeometry(argv[i+1],&geometry_info);
2310 noisy_image=ReduceNoiseImage(*image,geometry_info.rho,
2311 exception);
2312 }
2313 else
2314 {
2315 NoiseType
2316 noise;
2317
2318 noise=(NoiseType) ParseMagickOption(MagickNoiseOptions,
2319 MagickFalse,argv[i+1]);
2320 noisy_image=AddNoiseImageChannel(*image,channel,noise,
2321 exception);
2322 }
2323 if (noisy_image == (Image *) NULL)
2324 break;
2325 *image=DestroyImage(*image);
2326 *image=noisy_image;
2327 break;
2328 }
2329 if (LocaleCompare("normalize",option+1) == 0)
2330 {
cristy6b3da3a2010-06-20 02:21:46 +00002331 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002332 (void) NormalizeImageChannel(*image,channel);
2333 InheritException(exception,&(*image)->exception);
2334 break;
2335 }
2336 break;
2337 }
2338 case 'o':
2339 {
2340 if (LocaleCompare("opaque",option+1) == 0)
2341 {
2342 MagickPixelPacket
2343 target;
2344
cristy6b3da3a2010-06-20 02:21:46 +00002345 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002346 (void) QueryMagickColor(argv[i+1],&target,exception);
2347 (void) OpaquePaintImageChannel(*image,channel,&target,&fill,
2348 *option == '-' ? MagickFalse : MagickTrue);
2349 break;
2350 }
2351 if (LocaleCompare("ordered-dither",option+1) == 0)
2352 {
cristy6b3da3a2010-06-20 02:21:46 +00002353 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002354 (void) OrderedPosterizeImageChannel(*image,channel,argv[i+1],
2355 exception);
2356 break;
2357 }
2358 break;
2359 }
2360 case 'p':
2361 {
2362 if (LocaleCompare("paint",option+1) == 0)
2363 {
2364 Image
2365 *paint_image;
2366
2367 /*
2368 Oil paint image.
2369 */
cristy6b3da3a2010-06-20 02:21:46 +00002370 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002371 (void) ParseGeometry(argv[i+1],&geometry_info);
2372 paint_image=OilPaintImage(*image,geometry_info.rho,exception);
2373 if (paint_image == (Image *) NULL)
2374 break;
2375 *image=DestroyImage(*image);
2376 *image=paint_image;
2377 break;
2378 }
2379 if (LocaleCompare("pen",option+1) == 0)
2380 {
2381 if (*option == '+')
2382 {
2383 (void) QueryColorDatabase("none",&draw_info->fill,exception);
2384 break;
2385 }
2386 (void) QueryColorDatabase(argv[i+1],&draw_info->fill,exception);
2387 break;
2388 }
2389 if (LocaleCompare("pointsize",option+1) == 0)
2390 {
2391 if (*option == '+')
2392 (void) ParseGeometry("12",&geometry_info);
2393 else
2394 (void) ParseGeometry(argv[i+1],&geometry_info);
2395 draw_info->pointsize=geometry_info.rho;
2396 break;
2397 }
2398 if (LocaleCompare("polaroid",option+1) == 0)
2399 {
2400 double
2401 angle;
2402
2403 Image
2404 *polaroid_image;
2405
2406 RandomInfo
2407 *random_info;
2408
2409 /*
2410 Simulate a Polaroid picture.
2411 */
cristy6b3da3a2010-06-20 02:21:46 +00002412 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002413 random_info=AcquireRandomInfo();
2414 angle=22.5*(GetPseudoRandomValue(random_info)-0.5);
2415 random_info=DestroyRandomInfo(random_info);
2416 if (*option == '-')
2417 {
2418 SetGeometryInfo(&geometry_info);
2419 flags=ParseGeometry(argv[i+1],&geometry_info);
2420 angle=geometry_info.rho;
2421 }
2422 polaroid_image=PolaroidImage(*image,draw_info,angle,exception);
2423 if (polaroid_image == (Image *) NULL)
2424 break;
2425 *image=DestroyImage(*image);
2426 *image=polaroid_image;
2427 break;
2428 }
2429 if (LocaleCompare("posterize",option+1) == 0)
2430 {
2431 /*
2432 Posterize image.
2433 */
cristy6b3da3a2010-06-20 02:21:46 +00002434 (void) SyncImageSettings(mogrify_info,*image);
cristye27293e2009-12-18 02:53:20 +00002435 (void) PosterizeImage(*image,StringToUnsignedLong(argv[i+1]),
cristy3ed852e2009-09-05 21:47:34 +00002436 quantize_info->dither);
2437 InheritException(exception,&(*image)->exception);
2438 break;
2439 }
2440 if (LocaleCompare("preview",option+1) == 0)
2441 {
2442 Image
2443 *preview_image;
2444
2445 PreviewType
2446 preview_type;
2447
2448 /*
2449 Preview image.
2450 */
cristy6b3da3a2010-06-20 02:21:46 +00002451 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002452 if (*option == '+')
2453 preview_type=UndefinedPreview;
2454 else
2455 preview_type=(PreviewType) ParseMagickOption(MagickPreviewOptions,
2456 MagickFalse,argv[i+1]);
2457 preview_image=PreviewImage(*image,preview_type,exception);
2458 if (preview_image == (Image *) NULL)
2459 break;
2460 *image=DestroyImage(*image);
2461 *image=preview_image;
2462 break;
2463 }
2464 if (LocaleCompare("profile",option+1) == 0)
2465 {
2466 const char
2467 *name;
2468
2469 const StringInfo
2470 *profile;
2471
2472 Image
2473 *profile_image;
2474
2475 ImageInfo
2476 *profile_info;
2477
cristy6b3da3a2010-06-20 02:21:46 +00002478 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002479 if (*option == '+')
2480 {
2481 /*
2482 Remove a profile from the image.
2483 */
2484 (void) ProfileImage(*image,argv[i+1],(const unsigned char *)
2485 NULL,0,MagickTrue);
2486 InheritException(exception,&(*image)->exception);
2487 break;
2488 }
2489 /*
2490 Associate a profile with the image.
2491 */
cristy6b3da3a2010-06-20 02:21:46 +00002492 profile_info=CloneImageInfo(mogrify_info);
cristy3ed852e2009-09-05 21:47:34 +00002493 profile=GetImageProfile(*image,"iptc");
2494 if (profile != (StringInfo *) NULL)
2495 profile_info->profile=(void *) CloneStringInfo(profile);
2496 profile_image=GetImageCache(profile_info,argv[i+1],exception);
2497 profile_info=DestroyImageInfo(profile_info);
2498 if (profile_image == (Image *) NULL)
2499 {
cristy3ed852e2009-09-05 21:47:34 +00002500 StringInfo
2501 *profile;
2502
cristy6b3da3a2010-06-20 02:21:46 +00002503 profile_info=CloneImageInfo(mogrify_info);
cristy071dd7b2010-04-09 13:04:54 +00002504 (void) CopyMagickString(profile_info->filename,argv[i+1],
2505 MaxTextExtent);
2506 profile=FileToStringInfo(profile_info->filename,~0UL,exception);
cristy3ed852e2009-09-05 21:47:34 +00002507 if (profile != (StringInfo *) NULL)
2508 {
cristy071dd7b2010-04-09 13:04:54 +00002509 (void) ProfileImage(*image,profile_info->magick,
cristybb503372010-05-27 20:51:26 +00002510 GetStringInfoDatum(profile),(size_t)
cristy071dd7b2010-04-09 13:04:54 +00002511 GetStringInfoLength(profile),MagickFalse);
cristy3ed852e2009-09-05 21:47:34 +00002512 profile=DestroyStringInfo(profile);
2513 }
cristy071dd7b2010-04-09 13:04:54 +00002514 profile_info=DestroyImageInfo(profile_info);
cristy3ed852e2009-09-05 21:47:34 +00002515 break;
2516 }
2517 ResetImageProfileIterator(profile_image);
2518 name=GetNextImageProfile(profile_image);
2519 while (name != (const char *) NULL)
2520 {
2521 profile=GetImageProfile(profile_image,name);
2522 if (profile != (StringInfo *) NULL)
2523 (void) ProfileImage(*image,name,GetStringInfoDatum(profile),
cristybb503372010-05-27 20:51:26 +00002524 (size_t) GetStringInfoLength(profile),MagickFalse);
cristy3ed852e2009-09-05 21:47:34 +00002525 name=GetNextImageProfile(profile_image);
2526 }
2527 profile_image=DestroyImage(profile_image);
2528 break;
2529 }
2530 break;
2531 }
2532 case 'q':
2533 {
2534 if (LocaleCompare("quantize",option+1) == 0)
2535 {
2536 if (*option == '+')
2537 {
2538 quantize_info->colorspace=UndefinedColorspace;
2539 break;
2540 }
2541 quantize_info->colorspace=(ColorspaceType) ParseMagickOption(
2542 MagickColorspaceOptions,MagickFalse,argv[i+1]);
2543 break;
2544 }
2545 break;
2546 }
2547 case 'r':
2548 {
2549 if (LocaleCompare("radial-blur",option+1) == 0)
2550 {
2551 Image
2552 *blur_image;
2553
2554 /*
2555 Radial blur image.
2556 */
cristy6b3da3a2010-06-20 02:21:46 +00002557 (void) SyncImageSettings(mogrify_info,*image);
cristya5447be2010-01-11 00:20:51 +00002558 blur_image=RadialBlurImageChannel(*image,channel,
2559 StringToDouble(argv[i+1]),exception);
cristy3ed852e2009-09-05 21:47:34 +00002560 if (blur_image == (Image *) NULL)
2561 break;
2562 *image=DestroyImage(*image);
2563 *image=blur_image;
2564 break;
2565 }
2566 if (LocaleCompare("raise",option+1) == 0)
2567 {
2568 /*
2569 Surround image with a raise of solid color.
2570 */
2571 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2572 if ((flags & SigmaValue) == 0)
2573 geometry.height=geometry.width;
2574 (void) RaiseImage(*image,&geometry,*option == '-' ? MagickTrue :
2575 MagickFalse);
2576 InheritException(exception,&(*image)->exception);
2577 break;
2578 }
2579 if (LocaleCompare("random-threshold",option+1) == 0)
2580 {
2581 /*
2582 Threshold image.
2583 */
cristy6b3da3a2010-06-20 02:21:46 +00002584 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002585 (void) RandomThresholdImageChannel(*image,channel,argv[i+1],
2586 exception);
2587 break;
2588 }
2589 if (LocaleCompare("recolor",option+1) == 0)
2590 {
cristy3ed852e2009-09-05 21:47:34 +00002591 Image
cristyf055ae42010-04-02 23:01:38 +00002592 *color_image;
cristy3ed852e2009-09-05 21:47:34 +00002593
cristyf055ae42010-04-02 23:01:38 +00002594 KernelInfo
2595 *kernel;
cristy3ed852e2009-09-05 21:47:34 +00002596
cristy6b3da3a2010-06-20 02:21:46 +00002597 (void) SyncImageSettings(mogrify_info,*image);
cristyf055ae42010-04-02 23:01:38 +00002598 kernel=AcquireKernelInfo(argv[i+1]);
2599 if (kernel == (KernelInfo *) NULL)
2600 break;
2601 color_image=ColorMatrixImage(*image,kernel,exception);
2602 kernel=DestroyKernelInfo(kernel);
2603 if (color_image == (Image *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002604 break;
2605 *image=DestroyImage(*image);
cristyf055ae42010-04-02 23:01:38 +00002606 *image=color_image;
cristy3ed852e2009-09-05 21:47:34 +00002607 break;
2608 }
2609 if (LocaleCompare("region",option+1) == 0)
2610 {
2611 Image
2612 *crop_image;
2613
cristy6b3da3a2010-06-20 02:21:46 +00002614 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002615 if (region_image != (Image *) NULL)
2616 {
2617 /*
2618 Composite region.
2619 */
2620 (void) CompositeImage(region_image,(*image)->matte !=
2621 MagickFalse ? OverCompositeOp : CopyCompositeOp,*image,
2622 region_geometry.x,region_geometry.y);
2623 InheritException(exception,&region_image->exception);
2624 *image=DestroyImage(*image);
2625 *image=region_image;
2626 }
2627 if (*option == '+')
2628 {
2629 if (region_image != (Image *) NULL)
2630 region_image=DestroyImage(region_image);
2631 break;
2632 }
2633 /*
2634 Apply transformations to a selected region of the image.
2635 */
2636 (void) ParseGravityGeometry(*image,argv[i+1],&region_geometry,
2637 exception);
2638 crop_image=CropImage(*image,&region_geometry,exception);
2639 if (crop_image == (Image *) NULL)
2640 break;
2641 region_image=(*image);
2642 *image=crop_image;
2643 break;
2644 }
2645 if (LocaleCompare("render",option+1) == 0)
2646 {
cristy6b3da3a2010-06-20 02:21:46 +00002647 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002648 draw_info->render=(*option == '+') ? MagickTrue : MagickFalse;
2649 break;
2650 }
2651 if (LocaleCompare("remap",option+1) == 0)
2652 {
2653 Image
2654 *remap_image;
2655
2656 /*
2657 Transform image colors to match this set of colors.
2658 */
cristy6b3da3a2010-06-20 02:21:46 +00002659 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002660 if (*option == '+')
2661 break;
cristy6b3da3a2010-06-20 02:21:46 +00002662 remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
cristy3ed852e2009-09-05 21:47:34 +00002663 if (remap_image == (Image *) NULL)
2664 break;
2665 (void) RemapImage(quantize_info,*image,remap_image);
2666 InheritException(exception,&(*image)->exception);
2667 remap_image=DestroyImage(remap_image);
2668 break;
2669 }
2670 if (LocaleCompare("repage",option+1) == 0)
2671 {
2672 if (*option == '+')
2673 {
2674 (void) ParseAbsoluteGeometry("0x0+0+0",&(*image)->page);
2675 break;
2676 }
2677 (void) ResetImagePage(*image,argv[i+1]);
2678 InheritException(exception,&(*image)->exception);
2679 break;
2680 }
2681 if (LocaleCompare("resample",option+1) == 0)
2682 {
2683 Image
2684 *resample_image;
2685
2686 /*
2687 Resample image.
2688 */
cristy6b3da3a2010-06-20 02:21:46 +00002689 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002690 flags=ParseGeometry(argv[i+1],&geometry_info);
2691 if ((flags & SigmaValue) == 0)
2692 geometry_info.sigma=geometry_info.rho;
2693 resample_image=ResampleImage(*image,geometry_info.rho,
2694 geometry_info.sigma,(*image)->filter,(*image)->blur,exception);
2695 if (resample_image == (Image *) NULL)
2696 break;
2697 *image=DestroyImage(*image);
2698 *image=resample_image;
2699 break;
2700 }
2701 if (LocaleCompare("resize",option+1) == 0)
2702 {
2703 Image
2704 *resize_image;
2705
2706 /*
2707 Resize image.
2708 */
cristy6b3da3a2010-06-20 02:21:46 +00002709 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002710 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2711 resize_image=ResizeImage(*image,geometry.width,geometry.height,
2712 (*image)->filter,(*image)->blur,exception);
2713 if (resize_image == (Image *) NULL)
2714 break;
2715 *image=DestroyImage(*image);
2716 *image=resize_image;
2717 break;
2718 }
2719 if (LocaleNCompare("respect-parentheses",option+1,17) == 0)
2720 {
2721 respect_parenthesis=(*option == '-') ? MagickTrue : MagickFalse;
2722 break;
2723 }
2724 if (LocaleCompare("roll",option+1) == 0)
2725 {
2726 Image
2727 *roll_image;
2728
2729 /*
2730 Roll image.
2731 */
cristy6b3da3a2010-06-20 02:21:46 +00002732 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002733 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2734 roll_image=RollImage(*image,geometry.x,geometry.y,exception);
2735 if (roll_image == (Image *) NULL)
2736 break;
2737 *image=DestroyImage(*image);
2738 *image=roll_image;
2739 break;
2740 }
2741 if (LocaleCompare("rotate",option+1) == 0)
2742 {
2743 char
2744 *geometry;
2745
2746 Image
2747 *rotate_image;
2748
2749 /*
2750 Check for conditional image rotation.
2751 */
cristy6b3da3a2010-06-20 02:21:46 +00002752 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002753 if (strchr(argv[i+1],'>') != (char *) NULL)
2754 if ((*image)->columns <= (*image)->rows)
2755 break;
2756 if (strchr(argv[i+1],'<') != (char *) NULL)
2757 if ((*image)->columns >= (*image)->rows)
2758 break;
2759 /*
2760 Rotate image.
2761 */
2762 geometry=ConstantString(argv[i+1]);
2763 (void) SubstituteString(&geometry,">","");
2764 (void) SubstituteString(&geometry,"<","");
2765 (void) ParseGeometry(geometry,&geometry_info);
2766 geometry=DestroyString(geometry);
2767 rotate_image=RotateImage(*image,geometry_info.rho,exception);
2768 if (rotate_image == (Image *) NULL)
2769 break;
2770 *image=DestroyImage(*image);
2771 *image=rotate_image;
2772 break;
2773 }
2774 break;
2775 }
2776 case 's':
2777 {
2778 if (LocaleCompare("sample",option+1) == 0)
2779 {
2780 Image
2781 *sample_image;
2782
2783 /*
2784 Sample image with pixel replication.
2785 */
cristy6b3da3a2010-06-20 02:21:46 +00002786 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002787 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2788 sample_image=SampleImage(*image,geometry.width,geometry.height,
2789 exception);
2790 if (sample_image == (Image *) NULL)
2791 break;
2792 *image=DestroyImage(*image);
2793 *image=sample_image;
2794 break;
2795 }
2796 if (LocaleCompare("scale",option+1) == 0)
2797 {
2798 Image
2799 *scale_image;
2800
2801 /*
2802 Resize image.
2803 */
cristy6b3da3a2010-06-20 02:21:46 +00002804 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002805 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2806 scale_image=ScaleImage(*image,geometry.width,geometry.height,
2807 exception);
2808 if (scale_image == (Image *) NULL)
2809 break;
2810 *image=DestroyImage(*image);
2811 *image=scale_image;
2812 break;
2813 }
2814 if (LocaleCompare("selective-blur",option+1) == 0)
2815 {
2816 Image
2817 *blur_image;
2818
2819 /*
2820 Selectively blur pixels within a contrast threshold.
2821 */
cristy6b3da3a2010-06-20 02:21:46 +00002822 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002823 flags=ParseGeometry(argv[i+1],&geometry_info);
2824 if ((flags & PercentValue) != 0)
2825 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
2826 blur_image=SelectiveBlurImageChannel(*image,channel,
2827 geometry_info.rho,geometry_info.sigma,geometry_info.xi,exception);
2828 if (blur_image == (Image *) NULL)
2829 break;
2830 *image=DestroyImage(*image);
2831 *image=blur_image;
2832 break;
2833 }
2834 if (LocaleCompare("separate",option+1) == 0)
2835 {
2836 Image
2837 *separate_images;
2838
2839 /*
2840 Break channels into separate images.
2841 */
cristy6b3da3a2010-06-20 02:21:46 +00002842 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002843 separate_images=SeparateImages(*image,channel,exception);
2844 if (separate_images == (Image *) NULL)
2845 break;
2846 *image=DestroyImage(*image);
2847 *image=separate_images;
2848 break;
2849 }
2850 if (LocaleCompare("sepia-tone",option+1) == 0)
2851 {
2852 double
2853 threshold;
2854
2855 Image
2856 *sepia_image;
2857
2858 /*
2859 Sepia-tone image.
2860 */
cristy6b3da3a2010-06-20 02:21:46 +00002861 (void) SyncImageSettings(mogrify_info,*image);
cristyf2f27272009-12-17 14:48:46 +00002862 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
cristy3ed852e2009-09-05 21:47:34 +00002863 sepia_image=SepiaToneImage(*image,threshold,exception);
2864 if (sepia_image == (Image *) NULL)
2865 break;
2866 *image=DestroyImage(*image);
2867 *image=sepia_image;
2868 break;
2869 }
2870 if (LocaleCompare("segment",option+1) == 0)
2871 {
2872 /*
2873 Segment image.
2874 */
cristy6b3da3a2010-06-20 02:21:46 +00002875 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002876 flags=ParseGeometry(argv[i+1],&geometry_info);
2877 if ((flags & SigmaValue) == 0)
2878 geometry_info.sigma=1.0;
cristy6b3da3a2010-06-20 02:21:46 +00002879 (void) SegmentImage(*image,(*image)->colorspace,mogrify_info->verbose,
cristy3ed852e2009-09-05 21:47:34 +00002880 geometry_info.rho,geometry_info.sigma);
2881 InheritException(exception,&(*image)->exception);
2882 break;
2883 }
2884 if (LocaleCompare("set",option+1) == 0)
2885 {
cristy6d9a1292010-05-31 14:17:06 +00002886 char
2887 *value;
2888
cristy3ed852e2009-09-05 21:47:34 +00002889 /*
2890 Set image option.
2891 */
cristy6d9a1292010-05-31 14:17:06 +00002892 if (*option == '+')
2893 {
2894 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2895 (void) DeleteImageRegistry(argv[i+1]+9);
2896 else
2897 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
cristy7e109582010-06-01 12:56:44 +00002898 {
cristy6b3da3a2010-06-20 02:21:46 +00002899 (void) DeleteImageOption(mogrify_info,argv[i+1]+7);
cristy7e109582010-06-01 12:56:44 +00002900 (void) DeleteImageArtifact(*image,argv[i+1]+7);
2901 }
cristy6d9a1292010-05-31 14:17:06 +00002902 else
2903 (void) DeleteImageProperty(*image,argv[i+1]);
2904 break;
2905 }
cristy6b3da3a2010-06-20 02:21:46 +00002906 value=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
cristy6d9a1292010-05-31 14:17:06 +00002907 if (value == (char *) NULL)
2908 break;
cristy3ed852e2009-09-05 21:47:34 +00002909 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
cristy6d9a1292010-05-31 14:17:06 +00002910 (void) SetImageRegistry(StringRegistryType,argv[i+1]+9,value,
2911 exception);
cristy3ed852e2009-09-05 21:47:34 +00002912 else
2913 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
cristy6d9a1292010-05-31 14:17:06 +00002914 {
cristy6b3da3a2010-06-20 02:21:46 +00002915 (void) SetImageOption(mogrify_info,argv[i+1]+7,value);
cristy6d9a1292010-05-31 14:17:06 +00002916 (void) SetImageArtifact(*image,argv[i+1]+7,value);
2917 }
cristy3ed852e2009-09-05 21:47:34 +00002918 else
cristy6d9a1292010-05-31 14:17:06 +00002919 (void) SetImageProperty(*image,argv[i+1],value);
2920 value=DestroyString(value);
cristy3ed852e2009-09-05 21:47:34 +00002921 break;
2922 }
2923 if (LocaleCompare("shade",option+1) == 0)
2924 {
2925 Image
2926 *shade_image;
2927
2928 /*
2929 Shade image.
2930 */
cristy6b3da3a2010-06-20 02:21:46 +00002931 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002932 flags=ParseGeometry(argv[i+1],&geometry_info);
2933 if ((flags & SigmaValue) == 0)
2934 geometry_info.sigma=1.0;
2935 shade_image=ShadeImage(*image,(*option == '-') ? MagickTrue :
2936 MagickFalse,geometry_info.rho,geometry_info.sigma,exception);
2937 if (shade_image == (Image *) NULL)
2938 break;
2939 *image=DestroyImage(*image);
2940 *image=shade_image;
2941 break;
2942 }
2943 if (LocaleCompare("shadow",option+1) == 0)
2944 {
2945 Image
2946 *shadow_image;
2947
2948 /*
2949 Shadow image.
2950 */
cristy6b3da3a2010-06-20 02:21:46 +00002951 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002952 flags=ParseGeometry(argv[i+1],&geometry_info);
2953 if ((flags & SigmaValue) == 0)
2954 geometry_info.sigma=1.0;
2955 if ((flags & XiValue) == 0)
2956 geometry_info.xi=4.0;
2957 if ((flags & PsiValue) == 0)
2958 geometry_info.psi=4.0;
2959 shadow_image=ShadowImage(*image,geometry_info.rho,
cristybb503372010-05-27 20:51:26 +00002960 geometry_info.sigma,(ssize_t) ceil(geometry_info.xi-0.5),(ssize_t)
cristy0534a6b2010-03-18 01:19:38 +00002961 ceil(geometry_info.psi-0.5),exception);
cristy3ed852e2009-09-05 21:47:34 +00002962 if (shadow_image == (Image *) NULL)
2963 break;
2964 *image=DestroyImage(*image);
2965 *image=shadow_image;
2966 break;
2967 }
2968 if (LocaleCompare("sharpen",option+1) == 0)
2969 {
2970 Image
2971 *sharp_image;
2972
2973 /*
2974 Sharpen image.
2975 */
cristy6b3da3a2010-06-20 02:21:46 +00002976 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002977 flags=ParseGeometry(argv[i+1],&geometry_info);
2978 if ((flags & SigmaValue) == 0)
2979 geometry_info.sigma=1.0;
2980 sharp_image=SharpenImageChannel(*image,channel,geometry_info.rho,
2981 geometry_info.sigma,exception);
2982 if (sharp_image == (Image *) NULL)
2983 break;
2984 *image=DestroyImage(*image);
2985 *image=sharp_image;
2986 break;
2987 }
2988 if (LocaleCompare("shave",option+1) == 0)
2989 {
2990 Image
2991 *shave_image;
2992
2993 /*
2994 Shave the image edges.
2995 */
cristy6b3da3a2010-06-20 02:21:46 +00002996 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002997 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2998 shave_image=ShaveImage(*image,&geometry,exception);
2999 if (shave_image == (Image *) NULL)
3000 break;
3001 *image=DestroyImage(*image);
3002 *image=shave_image;
3003 break;
3004 }
3005 if (LocaleCompare("shear",option+1) == 0)
3006 {
3007 Image
3008 *shear_image;
3009
3010 /*
3011 Shear image.
3012 */
cristy6b3da3a2010-06-20 02:21:46 +00003013 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003014 flags=ParseGeometry(argv[i+1],&geometry_info);
3015 if ((flags & SigmaValue) == 0)
3016 geometry_info.sigma=geometry_info.rho;
3017 shear_image=ShearImage(*image,geometry_info.rho,geometry_info.sigma,
3018 exception);
3019 if (shear_image == (Image *) NULL)
3020 break;
3021 *image=DestroyImage(*image);
3022 *image=shear_image;
3023 break;
3024 }
3025 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
3026 {
3027 /*
3028 Sigmoidal non-linearity contrast control.
3029 */
cristy6b3da3a2010-06-20 02:21:46 +00003030 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003031 flags=ParseGeometry(argv[i+1],&geometry_info);
3032 if ((flags & SigmaValue) == 0)
3033 geometry_info.sigma=(double) QuantumRange/2.0;
3034 if ((flags & PercentValue) != 0)
3035 geometry_info.sigma=(double) QuantumRange*geometry_info.sigma/
3036 100.0;
3037 (void) SigmoidalContrastImageChannel(*image,channel,
3038 (*option == '-') ? MagickTrue : MagickFalse,geometry_info.rho,
3039 geometry_info.sigma);
3040 InheritException(exception,&(*image)->exception);
3041 break;
3042 }
3043 if (LocaleCompare("sketch",option+1) == 0)
3044 {
3045 Image
3046 *sketch_image;
3047
3048 /*
3049 Sketch image.
3050 */
cristy6b3da3a2010-06-20 02:21:46 +00003051 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003052 flags=ParseGeometry(argv[i+1],&geometry_info);
3053 if ((flags & SigmaValue) == 0)
3054 geometry_info.sigma=1.0;
3055 sketch_image=SketchImage(*image,geometry_info.rho,
3056 geometry_info.sigma,geometry_info.xi,exception);
3057 if (sketch_image == (Image *) NULL)
3058 break;
3059 *image=DestroyImage(*image);
3060 *image=sketch_image;
3061 break;
3062 }
3063 if (LocaleCompare("solarize",option+1) == 0)
3064 {
3065 double
3066 threshold;
3067
cristy6b3da3a2010-06-20 02:21:46 +00003068 (void) SyncImageSettings(mogrify_info,*image);
cristyf2f27272009-12-17 14:48:46 +00003069 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
cristy3ed852e2009-09-05 21:47:34 +00003070 (void) SolarizeImage(*image,threshold);
3071 InheritException(exception,&(*image)->exception);
3072 break;
3073 }
3074 if (LocaleCompare("sparse-color",option+1) == 0)
3075 {
3076 Image
3077 *sparse_image;
3078
3079 SparseColorMethod
3080 method;
3081
3082 char
3083 *arguments;
3084
3085 /*
3086 Sparse Color Interpolated Gradient
3087 */
cristy6b3da3a2010-06-20 02:21:46 +00003088 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003089 method=(SparseColorMethod) ParseMagickOption(
3090 MagickSparseColorOptions,MagickFalse,argv[i+1]);
cristy6b3da3a2010-06-20 02:21:46 +00003091 arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
cristy3ed852e2009-09-05 21:47:34 +00003092 InheritException(exception,&(*image)->exception);
3093 if (arguments == (char *) NULL)
3094 break;
3095 sparse_image=SparseColorOption(*image,channel,method,arguments,
3096 option[0] == '+' ? MagickTrue : MagickFalse,exception);
3097 arguments=DestroyString(arguments);
3098 if (sparse_image == (Image *) NULL)
3099 break;
3100 *image=DestroyImage(*image);
3101 *image=sparse_image;
3102 break;
3103 }
3104 if (LocaleCompare("splice",option+1) == 0)
3105 {
3106 Image
3107 *splice_image;
3108
3109 /*
3110 Splice a solid color into the image.
3111 */
cristy6b3da3a2010-06-20 02:21:46 +00003112 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003113 (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
3114 splice_image=SpliceImage(*image,&geometry,exception);
3115 if (splice_image == (Image *) NULL)
3116 break;
3117 *image=DestroyImage(*image);
3118 *image=splice_image;
3119 break;
3120 }
3121 if (LocaleCompare("spread",option+1) == 0)
3122 {
3123 Image
3124 *spread_image;
3125
3126 /*
3127 Spread an image.
3128 */
cristy6b3da3a2010-06-20 02:21:46 +00003129 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003130 (void) ParseGeometry(argv[i+1],&geometry_info);
3131 spread_image=SpreadImage(*image,geometry_info.rho,exception);
3132 if (spread_image == (Image *) NULL)
3133 break;
3134 *image=DestroyImage(*image);
3135 *image=spread_image;
3136 break;
3137 }
3138 if (LocaleCompare("stretch",option+1) == 0)
3139 {
3140 if (*option == '+')
3141 {
3142 draw_info->stretch=UndefinedStretch;
3143 break;
3144 }
3145 draw_info->stretch=(StretchType) ParseMagickOption(
3146 MagickStretchOptions,MagickFalse,argv[i+1]);
3147 break;
3148 }
3149 if (LocaleCompare("strip",option+1) == 0)
3150 {
3151 /*
3152 Strip image of profiles and comments.
3153 */
cristy6b3da3a2010-06-20 02:21:46 +00003154 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003155 (void) StripImage(*image);
3156 InheritException(exception,&(*image)->exception);
3157 break;
3158 }
3159 if (LocaleCompare("stroke",option+1) == 0)
3160 {
3161 ExceptionInfo
3162 *sans;
3163
3164 if (*option == '+')
3165 {
3166 (void) QueryColorDatabase("none",&draw_info->stroke,exception);
3167 if (draw_info->stroke_pattern != (Image *) NULL)
3168 draw_info->stroke_pattern=DestroyImage(
3169 draw_info->stroke_pattern);
3170 break;
3171 }
3172 sans=AcquireExceptionInfo();
3173 status=QueryColorDatabase(argv[i+1],&draw_info->stroke,sans);
3174 sans=DestroyExceptionInfo(sans);
3175 if (status == MagickFalse)
cristy6b3da3a2010-06-20 02:21:46 +00003176 draw_info->stroke_pattern=GetImageCache(mogrify_info,argv[i+1],
cristy3ed852e2009-09-05 21:47:34 +00003177 exception);
3178 break;
3179 }
3180 if (LocaleCompare("strokewidth",option+1) == 0)
3181 {
cristyf2f27272009-12-17 14:48:46 +00003182 draw_info->stroke_width=StringToDouble(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00003183 break;
3184 }
3185 if (LocaleCompare("style",option+1) == 0)
3186 {
3187 if (*option == '+')
3188 {
3189 draw_info->style=UndefinedStyle;
3190 break;
3191 }
3192 draw_info->style=(StyleType) ParseMagickOption(MagickStyleOptions,
3193 MagickFalse,argv[i+1]);
3194 break;
3195 }
3196 if (LocaleCompare("swirl",option+1) == 0)
3197 {
3198 Image
3199 *swirl_image;
3200
3201 /*
3202 Swirl image.
3203 */
cristy6b3da3a2010-06-20 02:21:46 +00003204 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003205 (void) ParseGeometry(argv[i+1],&geometry_info);
3206 swirl_image=SwirlImage(*image,geometry_info.rho,exception);
3207 if (swirl_image == (Image *) NULL)
3208 break;
3209 *image=DestroyImage(*image);
3210 *image=swirl_image;
3211 break;
3212 }
3213 break;
3214 }
3215 case 't':
3216 {
3217 if (LocaleCompare("threshold",option+1) == 0)
3218 {
3219 double
3220 threshold;
3221
3222 /*
3223 Threshold image.
3224 */
cristy6b3da3a2010-06-20 02:21:46 +00003225 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003226 if (*option == '+')
3227 threshold=(double) QuantumRange/2.5;
3228 else
cristyf2f27272009-12-17 14:48:46 +00003229 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
cristy3ed852e2009-09-05 21:47:34 +00003230 (void) BilevelImageChannel(*image,channel,threshold);
3231 InheritException(exception,&(*image)->exception);
3232 break;
3233 }
3234 if (LocaleCompare("thumbnail",option+1) == 0)
3235 {
3236 Image
3237 *thumbnail_image;
3238
3239 /*
3240 Thumbnail image.
3241 */
cristy6b3da3a2010-06-20 02:21:46 +00003242 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003243 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
3244 thumbnail_image=ThumbnailImage(*image,geometry.width,
3245 geometry.height,exception);
3246 if (thumbnail_image == (Image *) NULL)
3247 break;
3248 *image=DestroyImage(*image);
3249 *image=thumbnail_image;
3250 break;
3251 }
3252 if (LocaleCompare("tile",option+1) == 0)
3253 {
3254 if (*option == '+')
3255 {
3256 if (draw_info->fill_pattern != (Image *) NULL)
3257 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
3258 break;
3259 }
cristy6b3da3a2010-06-20 02:21:46 +00003260 draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1],
cristy3ed852e2009-09-05 21:47:34 +00003261 exception);
3262 break;
3263 }
3264 if (LocaleCompare("tint",option+1) == 0)
3265 {
3266 Image
3267 *tint_image;
3268
3269 /*
3270 Tint the image.
3271 */
cristy6b3da3a2010-06-20 02:21:46 +00003272 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003273 tint_image=TintImage(*image,argv[i+1],draw_info->fill,exception);
3274 if (tint_image == (Image *) NULL)
3275 break;
3276 *image=DestroyImage(*image);
3277 *image=tint_image;
3278 break;
3279 }
3280 if (LocaleCompare("transform",option+1) == 0)
3281 {
3282 Image
3283 *transform_image;
3284
3285 /*
3286 Affine transform image.
3287 */
cristy6b3da3a2010-06-20 02:21:46 +00003288 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003289 transform_image=AffineTransformImage(*image,&draw_info->affine,
3290 exception);
3291 if (transform_image == (Image *) NULL)
3292 break;
3293 *image=DestroyImage(*image);
3294 *image=transform_image;
3295 break;
3296 }
3297 if (LocaleCompare("transparent",option+1) == 0)
3298 {
3299 MagickPixelPacket
3300 target;
3301
cristy6b3da3a2010-06-20 02:21:46 +00003302 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003303 (void) QueryMagickColor(argv[i+1],&target,exception);
3304 (void) TransparentPaintImage(*image,&target,(Quantum)
3305 TransparentOpacity,*option == '-' ? MagickFalse : MagickTrue);
3306 InheritException(exception,&(*image)->exception);
3307 break;
3308 }
3309 if (LocaleCompare("transpose",option+1) == 0)
3310 {
3311 Image
3312 *transpose_image;
3313
3314 /*
3315 Transpose image scanlines.
3316 */
cristy6b3da3a2010-06-20 02:21:46 +00003317 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003318 transpose_image=TransposeImage(*image,exception);
3319 if (transpose_image == (Image *) NULL)
3320 break;
3321 *image=DestroyImage(*image);
3322 *image=transpose_image;
3323 break;
3324 }
3325 if (LocaleCompare("transverse",option+1) == 0)
3326 {
3327 Image
3328 *transverse_image;
3329
3330 /*
3331 Transverse image scanlines.
3332 */
cristy6b3da3a2010-06-20 02:21:46 +00003333 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003334 transverse_image=TransverseImage(*image,exception);
3335 if (transverse_image == (Image *) NULL)
3336 break;
3337 *image=DestroyImage(*image);
3338 *image=transverse_image;
3339 break;
3340 }
3341 if (LocaleCompare("treedepth",option+1) == 0)
3342 {
cristye27293e2009-12-18 02:53:20 +00003343 quantize_info->tree_depth=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00003344 break;
3345 }
3346 if (LocaleCompare("trim",option+1) == 0)
3347 {
3348 Image
3349 *trim_image;
3350
3351 /*
3352 Trim image.
3353 */
cristy6b3da3a2010-06-20 02:21:46 +00003354 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003355 trim_image=TrimImage(*image,exception);
3356 if (trim_image == (Image *) NULL)
3357 break;
3358 *image=DestroyImage(*image);
3359 *image=trim_image;
3360 break;
3361 }
3362 if (LocaleCompare("type",option+1) == 0)
3363 {
3364 ImageType
3365 type;
3366
cristy6b3da3a2010-06-20 02:21:46 +00003367 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003368 if (*option == '+')
3369 type=UndefinedType;
3370 else
3371 type=(ImageType) ParseMagickOption(MagickTypeOptions,MagickFalse,
3372 argv[i+1]);
3373 (*image)->type=UndefinedType;
3374 (void) SetImageType(*image,type);
3375 InheritException(exception,&(*image)->exception);
3376 break;
3377 }
3378 break;
3379 }
3380 case 'u':
3381 {
3382 if (LocaleCompare("undercolor",option+1) == 0)
3383 {
3384 (void) QueryColorDatabase(argv[i+1],&draw_info->undercolor,
3385 exception);
3386 break;
3387 }
cristy045bd902010-01-30 18:56:24 +00003388 if (LocaleCompare("unique",option+1) == 0)
3389 {
3390 if (*option == '+')
3391 {
cristy83fae872010-04-22 15:04:16 +00003392 (void) DeleteImageArtifact(*image,"identify:unique-colors");
cristy045bd902010-01-30 18:56:24 +00003393 break;
3394 }
cristy83fae872010-04-22 15:04:16 +00003395 (void) SetImageArtifact(*image,"identify:unique-colors","true");
cristy045bd902010-01-30 18:56:24 +00003396 break;
3397 }
cristy3ed852e2009-09-05 21:47:34 +00003398 if (LocaleCompare("unique-colors",option+1) == 0)
3399 {
3400 Image
3401 *unique_image;
3402
3403 /*
3404 Unique image colors.
3405 */
cristy6b3da3a2010-06-20 02:21:46 +00003406 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003407 unique_image=UniqueImageColors(*image,exception);
3408 if (unique_image == (Image *) NULL)
3409 break;
3410 *image=DestroyImage(*image);
3411 *image=unique_image;
3412 break;
3413 }
3414 if (LocaleCompare("unsharp",option+1) == 0)
3415 {
3416 Image
3417 *unsharp_image;
3418
3419 /*
3420 Unsharp mask image.
3421 */
cristy6b3da3a2010-06-20 02:21:46 +00003422 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003423 flags=ParseGeometry(argv[i+1],&geometry_info);
3424 if ((flags & SigmaValue) == 0)
3425 geometry_info.sigma=1.0;
3426 if ((flags & XiValue) == 0)
3427 geometry_info.xi=1.0;
3428 if ((flags & PsiValue) == 0)
3429 geometry_info.psi=0.05;
3430 unsharp_image=UnsharpMaskImageChannel(*image,channel,
3431 geometry_info.rho,geometry_info.sigma,geometry_info.xi,
3432 geometry_info.psi,exception);
3433 if (unsharp_image == (Image *) NULL)
3434 break;
3435 *image=DestroyImage(*image);
3436 *image=unsharp_image;
3437 break;
3438 }
3439 break;
3440 }
3441 case 'v':
3442 {
3443 if (LocaleCompare("verbose",option+1) == 0)
3444 {
3445 (void) SetImageArtifact(*image,option+1,
3446 *option == '+' ? "false" : "true");
3447 break;
3448 }
3449 if (LocaleCompare("vignette",option+1) == 0)
3450 {
3451 Image
3452 *vignette_image;
3453
3454 /*
3455 Vignette image.
3456 */
cristy6b3da3a2010-06-20 02:21:46 +00003457 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003458 flags=ParseGeometry(argv[i+1],&geometry_info);
3459 if ((flags & SigmaValue) == 0)
3460 geometry_info.sigma=1.0;
3461 if ((flags & XiValue) == 0)
3462 geometry_info.xi=0.1*(*image)->columns;
3463 if ((flags & PsiValue) == 0)
3464 geometry_info.psi=0.1*(*image)->rows;
3465 vignette_image=VignetteImage(*image,geometry_info.rho,
cristybb503372010-05-27 20:51:26 +00003466 geometry_info.sigma,(ssize_t) ceil(geometry_info.xi-0.5),(ssize_t)
cristy0534a6b2010-03-18 01:19:38 +00003467 ceil(geometry_info.psi-0.5),exception);
cristy3ed852e2009-09-05 21:47:34 +00003468 if (vignette_image == (Image *) NULL)
3469 break;
3470 *image=DestroyImage(*image);
3471 *image=vignette_image;
3472 break;
3473 }
3474 if (LocaleCompare("virtual-pixel",option+1) == 0)
3475 {
3476 if (*option == '+')
3477 {
3478 (void) SetImageVirtualPixelMethod(*image,
3479 UndefinedVirtualPixelMethod);
3480 break;
3481 }
3482 (void) SetImageVirtualPixelMethod(*image,(VirtualPixelMethod)
3483 ParseMagickOption(MagickVirtualPixelOptions,MagickFalse,
3484 argv[i+1]));
3485 break;
3486 }
3487 break;
3488 }
3489 case 'w':
3490 {
3491 if (LocaleCompare("wave",option+1) == 0)
3492 {
3493 Image
3494 *wave_image;
3495
3496 /*
3497 Wave image.
3498 */
cristy6b3da3a2010-06-20 02:21:46 +00003499 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003500 flags=ParseGeometry(argv[i+1],&geometry_info);
3501 if ((flags & SigmaValue) == 0)
3502 geometry_info.sigma=1.0;
3503 wave_image=WaveImage(*image,geometry_info.rho,geometry_info.sigma,
3504 exception);
3505 if (wave_image == (Image *) NULL)
3506 break;
3507 *image=DestroyImage(*image);
3508 *image=wave_image;
3509 break;
3510 }
3511 if (LocaleCompare("weight",option+1) == 0)
3512 {
cristye27293e2009-12-18 02:53:20 +00003513 draw_info->weight=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00003514 if (LocaleCompare(argv[i+1],"all") == 0)
3515 draw_info->weight=0;
3516 if (LocaleCompare(argv[i+1],"bold") == 0)
3517 draw_info->weight=700;
3518 if (LocaleCompare(argv[i+1],"bolder") == 0)
3519 if (draw_info->weight <= 800)
3520 draw_info->weight+=100;
3521 if (LocaleCompare(argv[i+1],"lighter") == 0)
3522 if (draw_info->weight >= 100)
3523 draw_info->weight-=100;
3524 if (LocaleCompare(argv[i+1],"normal") == 0)
3525 draw_info->weight=400;
3526 break;
3527 }
3528 if (LocaleCompare("white-threshold",option+1) == 0)
3529 {
3530 /*
3531 White threshold image.
3532 */
cristy6b3da3a2010-06-20 02:21:46 +00003533 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003534 (void) WhiteThresholdImageChannel(*image,channel,argv[i+1],
3535 exception);
3536 InheritException(exception,&(*image)->exception);
3537 break;
3538 }
3539 break;
3540 }
3541 default:
3542 break;
3543 }
3544 i+=count;
3545 }
3546 if (region_image != (Image *) NULL)
3547 {
3548 /*
3549 Composite transformed region onto image.
3550 */
cristy6b3da3a2010-06-20 02:21:46 +00003551 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003552 (void) CompositeImage(region_image,(*image)->matte != MagickFalse ?
3553 OverCompositeOp : CopyCompositeOp,*image,region_geometry.x,
3554 region_geometry.y);
3555 InheritException(exception,&region_image->exception);
3556 *image=DestroyImage(*image);
3557 *image=region_image;
3558 }
3559 /*
3560 Free resources.
3561 */
3562 quantize_info=DestroyQuantizeInfo(quantize_info);
3563 draw_info=DestroyDrawInfo(draw_info);
cristy6b3da3a2010-06-20 02:21:46 +00003564 mogrify_info=DestroyImageInfo(mogrify_info);
3565 status=(*image)->exception.severity == UndefinedException ? MagickTrue :
3566 MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00003567 return(status);
3568}
3569
3570/*
3571%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3572% %
3573% %
3574% %
3575% M o g r i f y I m a g e C o m m a n d %
3576% %
3577% %
3578% %
3579%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3580%
3581% MogrifyImageCommand() transforms an image or a sequence of images. These
3582% transforms include image scaling, image rotation, color reduction, and
3583% others. The transmogrified image overwrites the original image.
3584%
3585% The format of the MogrifyImageCommand method is:
3586%
3587% MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,int argc,
3588% const char **argv,char **metadata,ExceptionInfo *exception)
3589%
3590% A description of each parameter follows:
3591%
3592% o image_info: the image info.
3593%
3594% o argc: the number of elements in the argument vector.
3595%
3596% o argv: A text array containing the command line arguments.
3597%
3598% o metadata: any metadata is returned here.
3599%
3600% o exception: return any errors or warnings in this structure.
3601%
3602*/
3603
3604static MagickBooleanType MogrifyUsage(void)
3605{
3606 static const char
3607 *miscellaneous[]=
3608 {
3609 "-debug events display copious debugging information",
3610 "-help print program options",
3611 "-list type print a list of supported option arguments",
3612 "-log format format of debugging information",
3613 "-version print version information",
3614 (char *) NULL
3615 },
3616 *operators[]=
3617 {
3618 "-adaptive-blur geometry",
3619 " adaptively blur pixels; decrease effect near edges",
3620 "-adaptive-resize geometry",
3621 " adaptively resize image using 'mesh' interpolation",
3622 "-adaptive-sharpen geometry",
3623 " adaptively sharpen pixels; increase effect near edges",
3624 "-alpha option on, activate, off, deactivate, set, opaque, copy",
3625 " transparent, extract, background, or shape",
3626 "-annotate geometry text",
3627 " annotate the image with text",
3628 "-auto-gamma automagically adjust gamma level of image",
3629 "-auto-level automagically adjust color levels of image",
3630 "-auto-orient automagically orient (rotate) image",
3631 "-bench iterations measure performance",
3632 "-black-threshold value",
3633 " force all pixels below the threshold into black",
3634 "-blue-shift simulate a scene at nighttime in the moonlight",
3635 "-blur geometry reduce image noise and reduce detail levels",
3636 "-border geometry surround image with a border of color",
3637 "-bordercolor color border color",
cristya28d6b82010-01-11 20:03:47 +00003638 "-brightness-contrast geometry",
3639 " improve brightness / contrast of the image",
cristy3ed852e2009-09-05 21:47:34 +00003640 "-cdl filename color correct with a color decision list",
3641 "-charcoal radius simulate a charcoal drawing",
3642 "-chop geometry remove pixels from the image interior",
cristyecb0c6d2009-09-25 16:50:09 +00003643 "-clamp restrict pixel range from 0 to the quantum depth",
cristycee97112010-05-28 00:44:52 +00003644 "-clip clip along the first path from the 8BIM profile",
cristy3ed852e2009-09-05 21:47:34 +00003645 "-clip-mask filename associate a clip mask with the image",
cristycee97112010-05-28 00:44:52 +00003646 "-clip-path id clip along a named path from the 8BIM profile",
cristy3ed852e2009-09-05 21:47:34 +00003647 "-colorize value colorize the image with the fill color",
cristye6365592010-04-02 17:31:23 +00003648 "-color-matrix matrix apply color correction to the image",
cristy3ed852e2009-09-05 21:47:34 +00003649 "-contrast enhance or reduce the image contrast",
3650 "-contrast-stretch geometry",
3651 " improve contrast by `stretching' the intensity range",
3652 "-convolve coefficients",
3653 " apply a convolution kernel to the image",
3654 "-cycle amount cycle the image colormap",
3655 "-decipher filename convert cipher pixels to plain pixels",
3656 "-deskew threshold straighten an image",
3657 "-despeckle reduce the speckles within an image",
3658 "-distort method args",
3659 " distort images according to given method ad args",
3660 "-draw string annotate the image with a graphic primitive",
3661 "-edge radius apply a filter to detect edges in the image",
3662 "-encipher filename convert plain pixels to cipher pixels",
3663 "-emboss radius emboss an image",
3664 "-enhance apply a digital filter to enhance a noisy image",
3665 "-equalize perform histogram equalization to an image",
3666 "-evaluate operator value",
cristyd18ae7c2010-03-07 17:39:52 +00003667 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003668 "-extent geometry set the image size",
3669 "-extract geometry extract area from image",
3670 "-fft implements the discrete Fourier transform (DFT)",
3671 "-flip flip image vertically",
3672 "-floodfill geometry color",
3673 " floodfill the image with color",
3674 "-flop flop image horizontally",
3675 "-frame geometry surround image with an ornamental border",
cristyc2b730e2009-11-24 14:32:09 +00003676 "-function name parameters",
cristy3ed852e2009-09-05 21:47:34 +00003677 " apply function over image values",
3678 "-gamma value level of gamma correction",
3679 "-gaussian-blur geometry",
3680 " reduce image noise and reduce detail levels",
cristy901f09d2009-10-16 22:56:10 +00003681 "-geometry geometry preferred size or location of the image",
cristy3ed852e2009-09-05 21:47:34 +00003682 "-identify identify the format and characteristics of the image",
3683 "-ift implements the inverse discrete Fourier transform (DFT)",
3684 "-implode amount implode image pixels about the center",
3685 "-lat geometry local adaptive thresholding",
3686 "-layers method optimize, merge, or compare image layers",
3687 "-level value adjust the level of image contrast",
3688 "-level-colors color,color",
cristyee0f8d72009-09-19 00:58:29 +00003689 " level image with the given colors",
cristy3ed852e2009-09-05 21:47:34 +00003690 "-linear-stretch geometry",
3691 " improve contrast by `stretching with saturation'",
3692 "-liquid-rescale geometry",
3693 " rescale image with seam-carving",
3694 "-median radius apply a median filter to the image",
3695 "-modulate value vary the brightness, saturation, and hue",
3696 "-monochrome transform image to black and white",
cristy7c1b9fd2010-02-02 14:36:00 +00003697 "-morphology method kernel",
anthony29188a82010-01-22 10:12:34 +00003698 " apply a morphology method to the image",
cristy3ed852e2009-09-05 21:47:34 +00003699 "-motion-blur geometry",
3700 " simulate motion blur",
3701 "-negate replace every pixel with its complementary color ",
3702 "-noise radius add or reduce noise in an image",
3703 "-normalize transform image to span the full range of colors",
3704 "-opaque color change this color to the fill color",
3705 "-ordered-dither NxN",
3706 " add a noise pattern to the image with specific",
3707 " amplitudes",
3708 "-paint radius simulate an oil painting",
3709 "-polaroid angle simulate a Polaroid picture",
3710 "-posterize levels reduce the image to a limited number of color levels",
cristy3ed852e2009-09-05 21:47:34 +00003711 "-profile filename add, delete, or apply an image profile",
3712 "-quantize colorspace reduce colors in this colorspace",
3713 "-radial-blur angle radial blur the image",
3714 "-raise value lighten/darken image edges to create a 3-D effect",
3715 "-random-threshold low,high",
3716 " random threshold the image",
cristy3ed852e2009-09-05 21:47:34 +00003717 "-region geometry apply options to a portion of the image",
3718 "-render render vector graphics",
3719 "-repage geometry size and location of an image canvas",
3720 "-resample geometry change the resolution of an image",
3721 "-resize geometry resize the image",
3722 "-roll geometry roll an image vertically or horizontally",
3723 "-rotate degrees apply Paeth rotation to the image",
3724 "-sample geometry scale image with pixel sampling",
3725 "-scale geometry scale the image",
3726 "-segment values segment an image",
3727 "-selective-blur geometry",
3728 " selectively blur pixels within a contrast threshold",
3729 "-sepia-tone threshold",
3730 " simulate a sepia-toned photo",
3731 "-set property value set an image property",
3732 "-shade degrees shade the image using a distant light source",
3733 "-shadow geometry simulate an image shadow",
3734 "-sharpen geometry sharpen the image",
3735 "-shave geometry shave pixels from the image edges",
cristycee97112010-05-28 00:44:52 +00003736 "-shear geometry slide one edge of the image along the X or Y axis",
cristy3ed852e2009-09-05 21:47:34 +00003737 "-sigmoidal-contrast geometry",
3738 " increase the contrast without saturating highlights or shadows",
3739 "-sketch geometry simulate a pencil sketch",
3740 "-solarize threshold negate all pixels above the threshold level",
3741 "-sparse-color method args",
3742 " fill in a image based on a few color points",
3743 "-splice geometry splice the background color into the image",
3744 "-spread radius displace image pixels by a random amount",
3745 "-strip strip image of all profiles and comments",
3746 "-swirl degrees swirl image pixels about the center",
3747 "-threshold value threshold the image",
3748 "-thumbnail geometry create a thumbnail of the image",
3749 "-tile filename tile image when filling a graphic primitive",
3750 "-tint value tint the image with the fill color",
3751 "-transform affine transform image",
3752 "-transparent color make this color transparent within the image",
3753 "-transpose flip image vertically and rotate 90 degrees",
3754 "-transverse flop image horizontally and rotate 270 degrees",
3755 "-trim trim image edges",
3756 "-type type image type",
3757 "-unique-colors discard all but one of any pixel color",
3758 "-unsharp geometry sharpen the image",
3759 "-vignette geometry soften the edges of the image in vignette style",
cristycee97112010-05-28 00:44:52 +00003760 "-wave geometry alter an image along a sine wave",
cristy3ed852e2009-09-05 21:47:34 +00003761 "-white-threshold value",
3762 " force all pixels above the threshold into white",
3763 (char *) NULL
3764 },
3765 *sequence_operators[]=
3766 {
3767 "-append append an image sequence",
cristy3ed852e2009-09-05 21:47:34 +00003768 "-clut apply a color lookup table to the image",
3769 "-coalesce merge a sequence of images",
3770 "-combine combine a sequence of images",
3771 "-composite composite image",
3772 "-crop geometry cut out a rectangular region of the image",
3773 "-deconstruct break down an image sequence into constituent parts",
cristyd18ae7c2010-03-07 17:39:52 +00003774 "-evaluate-sequence operator",
3775 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003776 "-flatten flatten a sequence of images",
3777 "-fx expression apply mathematical expression to an image channel(s)",
3778 "-hald-clut apply a Hald color lookup table to the image",
3779 "-morph value morph an image sequence",
3780 "-mosaic create a mosaic from an image sequence",
cristy36b94822010-05-20 12:48:16 +00003781 "-print string interpret string and print to console",
cristy3ed852e2009-09-05 21:47:34 +00003782 "-process arguments process the image with a custom image filter",
3783 "-reverse reverse image sequence",
3784 "-separate separate an image channel into a grayscale image",
3785 "-write filename write images to this file",
3786 (char *) NULL
3787 },
3788 *settings[]=
3789 {
3790 "-adjoin join images into a single multi-image file",
3791 "-affine matrix affine transform matrix",
3792 "-alpha option activate, deactivate, reset, or set the alpha channel",
3793 "-antialias remove pixel-aliasing",
3794 "-authenticate password",
3795 " decipher image with this password",
3796 "-attenuate value lessen (or intensify) when adding noise to an image",
3797 "-background color background color",
3798 "-bias value add bias when convolving an image",
3799 "-black-point-compensation",
3800 " use black point compensation",
3801 "-blue-primary point chromaticity blue primary point",
3802 "-bordercolor color border color",
3803 "-caption string assign a caption to an image",
3804 "-channel type apply option to select image channels",
3805 "-colors value preferred number of colors in the image",
3806 "-colorspace type alternate image colorspace",
3807 "-comment string annotate image with comment",
3808 "-compose operator set image composite operator",
3809 "-compress type type of pixel compression when writing the image",
3810 "-define format:option",
3811 " define one or more image format options",
3812 "-delay value display the next image after pausing",
3813 "-density geometry horizontal and vertical density of the image",
3814 "-depth value image depth",
cristyc9b12952010-03-28 01:12:28 +00003815 "-direction type render text right-to-left or left-to-right",
cristy3ed852e2009-09-05 21:47:34 +00003816 "-display server get image or font from this X server",
3817 "-dispose method layer disposal method",
3818 "-dither method apply error diffusion to image",
3819 "-encoding type text encoding type",
3820 "-endian type endianness (MSB or LSB) of the image",
3821 "-family name render text with this font family",
3822 "-fill color color to use when filling a graphic primitive",
3823 "-filter type use this filter when resizing an image",
3824 "-font name render text with this font",
3825 "-format \"string\" output formatted image characteristics",
3826 "-fuzz distance colors within this distance are considered equal",
3827 "-gravity type horizontal and vertical text placement",
3828 "-green-primary point chromaticity green primary point",
3829 "-intent type type of rendering intent when managing the image color",
3830 "-interlace type type of image interlacing scheme",
cristyb32b90a2009-09-07 21:45:48 +00003831 "-interline-spacing value",
3832 " set the space between two text lines",
cristy3ed852e2009-09-05 21:47:34 +00003833 "-interpolate method pixel color interpolation method",
3834 "-interword-spacing value",
3835 " set the space between two words",
3836 "-kerning value set the space between two letters",
3837 "-label string assign a label to an image",
3838 "-limit type value pixel cache resource limit",
3839 "-loop iterations add Netscape loop extension to your GIF animation",
3840 "-mask filename associate a mask with the image",
3841 "-mattecolor color frame color",
3842 "-monitor monitor progress",
3843 "-orient type image orientation",
3844 "-page geometry size and location of an image canvas (setting)",
3845 "-ping efficiently determine image attributes",
3846 "-pointsize value font point size",
cristy7c1b9fd2010-02-02 14:36:00 +00003847 "-precision value maximum number of significant digits to print",
cristy3ed852e2009-09-05 21:47:34 +00003848 "-preview type image preview type",
3849 "-quality value JPEG/MIFF/PNG compression level",
3850 "-quiet suppress all warning messages",
3851 "-red-primary point chromaticity red primary point",
3852 "-regard-warnings pay attention to warning messages",
3853 "-remap filename transform image colors to match this set of colors",
3854 "-respect-parentheses settings remain in effect until parenthesis boundary",
3855 "-sampling-factor geometry",
3856 " horizontal and vertical sampling factor",
3857 "-scene value image scene number",
3858 "-seed value seed a new sequence of pseudo-random numbers",
3859 "-size geometry width and height of image",
3860 "-stretch type render text with this font stretch",
3861 "-stroke color graphic primitive stroke color",
3862 "-strokewidth value graphic primitive stroke width",
3863 "-style type render text with this font style",
3864 "-taint image as ineligible for bi-modal delegate",
3865 "-texture filename name of texture to tile onto the image background",
3866 "-tile-offset geometry",
3867 " tile offset",
3868 "-treedepth value color tree depth",
3869 "-transparent-color color",
3870 " transparent color",
3871 "-undercolor color annotation bounding box color",
3872 "-units type the units of image resolution",
3873 "-verbose print detailed information about the image",
3874 "-view FlashPix viewing transforms",
3875 "-virtual-pixel method",
3876 " virtual pixel access method",
3877 "-weight type render text with this font weight",
3878 "-white-point point chromaticity white point",
3879 (char *) NULL
3880 },
3881 *stack_operators[]=
3882 {
3883 "-clone index clone an image",
3884 "-delete index delete the image from the image sequence",
3885 "-insert index insert last image into the image sequence",
3886 "-swap indexes swap two images in the image sequence",
3887 (char *) NULL
3888 };
3889
3890 const char
3891 **p;
3892
cristybb503372010-05-27 20:51:26 +00003893 (void) printf("Version: %s\n",GetMagickVersion((size_t *) NULL));
cristy610b2e22009-10-22 14:59:43 +00003894 (void) printf("Copyright: %s\n",GetMagickCopyright());
3895 (void) printf("Features: %s\n\n",GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00003896 (void) printf("Usage: %s [options ...] file [ [options ...] file ...]\n",
3897 GetClientName());
3898 (void) printf("\nImage Settings:\n");
3899 for (p=settings; *p != (char *) NULL; p++)
3900 (void) printf(" %s\n",*p);
3901 (void) printf("\nImage Operators:\n");
3902 for (p=operators; *p != (char *) NULL; p++)
3903 (void) printf(" %s\n",*p);
3904 (void) printf("\nImage Sequence Operators:\n");
3905 for (p=sequence_operators; *p != (char *) NULL; p++)
3906 (void) printf(" %s\n",*p);
3907 (void) printf("\nImage Stack Operators:\n");
3908 for (p=stack_operators; *p != (char *) NULL; p++)
3909 (void) printf(" %s\n",*p);
3910 (void) printf("\nMiscellaneous Options:\n");
3911 for (p=miscellaneous; *p != (char *) NULL; p++)
3912 (void) printf(" %s\n",*p);
3913 (void) printf(
3914 "\nBy default, the image format of `file' is determined by its magic\n");
3915 (void) printf(
3916 "number. To specify a particular image format, precede the filename\n");
3917 (void) printf(
3918 "with an image format name and a colon (i.e. ps:image) or specify the\n");
3919 (void) printf(
3920 "image type as the filename suffix (i.e. image.ps). Specify 'file' as\n");
3921 (void) printf("'-' for standard input or output.\n");
3922 return(MagickFalse);
3923}
3924
3925WandExport MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,
3926 int argc,char **argv,char **wand_unused(metadata),ExceptionInfo *exception)
3927{
3928#define DestroyMogrify() \
3929{ \
3930 if (format != (char *) NULL) \
3931 format=DestroyString(format); \
3932 if (path != (char *) NULL) \
3933 path=DestroyString(path); \
3934 DestroyImageStack(); \
cristybb503372010-05-27 20:51:26 +00003935 for (i=0; i < (ssize_t) argc; i++) \
cristy3ed852e2009-09-05 21:47:34 +00003936 argv[i]=DestroyString(argv[i]); \
3937 argv=(char **) RelinquishMagickMemory(argv); \
3938}
3939#define ThrowMogrifyException(asperity,tag,option) \
3940{ \
3941 (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag,"`%s'", \
3942 option); \
3943 DestroyMogrify(); \
3944 return(MagickFalse); \
3945}
3946#define ThrowMogrifyInvalidArgumentException(option,argument) \
3947{ \
3948 (void) ThrowMagickException(exception,GetMagickModule(),OptionError, \
3949 "InvalidArgument","`%s': %s",argument,option); \
3950 DestroyMogrify(); \
3951 return(MagickFalse); \
3952}
3953
3954 char
3955 *format,
3956 *option,
3957 *path;
3958
3959 Image
3960 *image;
3961
3962 ImageStack
3963 image_stack[MaxImageStackDepth+1];
3964
cristybb503372010-05-27 20:51:26 +00003965 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003966 j,
3967 k;
3968
cristybb503372010-05-27 20:51:26 +00003969 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003970 i;
3971
3972 MagickBooleanType
3973 global_colormap;
3974
3975 MagickBooleanType
3976 fire,
3977 pend;
3978
3979 MagickStatusType
3980 status;
3981
3982 /*
3983 Set defaults.
3984 */
3985 assert(image_info != (ImageInfo *) NULL);
3986 assert(image_info->signature == MagickSignature);
3987 if (image_info->debug != MagickFalse)
3988 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3989 assert(exception != (ExceptionInfo *) NULL);
3990 if (argc == 2)
3991 {
3992 option=argv[1];
3993 if ((LocaleCompare("version",option+1) == 0) ||
3994 (LocaleCompare("-version",option+1) == 0))
3995 {
3996 (void) fprintf(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +00003997 GetMagickVersion((size_t *) NULL));
cristy610b2e22009-10-22 14:59:43 +00003998 (void) fprintf(stdout,"Copyright: %s\n",GetMagickCopyright());
3999 (void) fprintf(stdout,"Features: %s\n\n",GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00004000 return(MagickFalse);
4001 }
4002 }
4003 if (argc < 2)
cristy13e61a12010-02-04 20:19:00 +00004004 return(MogrifyUsage());
cristy3ed852e2009-09-05 21:47:34 +00004005 format=(char *) NULL;
4006 path=(char *) NULL;
4007 global_colormap=MagickFalse;
4008 k=0;
4009 j=1;
4010 NewImageStack();
4011 option=(char *) NULL;
4012 pend=MagickFalse;
4013 status=MagickTrue;
4014 /*
4015 Parse command line.
4016 */
4017 ReadCommandlLine(argc,&argv);
4018 status=ExpandFilenames(&argc,&argv);
4019 if (status == MagickFalse)
4020 ThrowMogrifyException(ResourceLimitError,"MemoryAllocationFailed",
4021 GetExceptionMessage(errno));
cristybb503372010-05-27 20:51:26 +00004022 for (i=1; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00004023 {
4024 option=argv[i];
4025 if (LocaleCompare(option,"(") == 0)
4026 {
4027 FireImageStack(MagickFalse,MagickTrue,pend);
4028 if (k == MaxImageStackDepth)
4029 ThrowMogrifyException(OptionError,"ParenthesisNestedTooDeeply",
4030 option);
4031 PushImageStack();
4032 continue;
4033 }
4034 if (LocaleCompare(option,")") == 0)
4035 {
4036 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
4037 if (k == 0)
4038 ThrowMogrifyException(OptionError,"UnableToParseExpression",option);
4039 PopImageStack();
4040 continue;
4041 }
4042 if (IsMagickOption(option) == MagickFalse)
4043 {
4044 char
4045 backup_filename[MaxTextExtent],
4046 *filename;
4047
4048 Image
4049 *images;
4050
4051 /*
4052 Option is a file name: begin by reading image from specified file.
4053 */
4054 FireImageStack(MagickFalse,MagickFalse,pend);
4055 filename=argv[i];
cristycee97112010-05-28 00:44:52 +00004056 if ((LocaleCompare(filename,"--") == 0) && (i < (ssize_t) (argc-1)))
cristy3ed852e2009-09-05 21:47:34 +00004057 filename=argv[++i];
4058 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
4059 images=ReadImages(image_info,exception);
4060 status&=(images != (Image *) NULL) &&
4061 (exception->severity < ErrorException);
4062 if (images == (Image *) NULL)
4063 continue;
cristydaa76602010-06-30 13:05:11 +00004064 if (format != (char *) NULL)
4065 (void) CopyMagickString(images->filename,images->magick_filename,
4066 MaxTextExtent);
cristy3ed852e2009-09-05 21:47:34 +00004067 if (path != (char *) NULL)
4068 {
4069 GetPathComponent(option,TailPath,filename);
4070 (void) FormatMagickString(images->filename,MaxTextExtent,"%s%c%s",
4071 path,*DirectorySeparator,filename);
4072 }
4073 if (format != (char *) NULL)
cristydaa76602010-06-30 13:05:11 +00004074 AppendImageFormat(format,images->filename);
cristy3ed852e2009-09-05 21:47:34 +00004075 AppendImageStack(images);
4076 FinalizeImageSettings(image_info,image,MagickFalse);
4077 if (global_colormap != MagickFalse)
4078 {
4079 QuantizeInfo
4080 *quantize_info;
4081
4082 quantize_info=AcquireQuantizeInfo(image_info);
4083 (void) RemapImages(quantize_info,images,(Image *) NULL);
4084 quantize_info=DestroyQuantizeInfo(quantize_info);
4085 }
4086 *backup_filename='\0';
4087 if ((LocaleCompare(image->filename,"-") != 0) &&
4088 (IsPathWritable(image->filename) != MagickFalse))
4089 {
cristybb503372010-05-27 20:51:26 +00004090 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004091 i;
4092
4093 /*
4094 Rename image file as backup.
4095 */
4096 (void) CopyMagickString(backup_filename,image->filename,
4097 MaxTextExtent);
4098 for (i=0; i < 6; i++)
4099 {
4100 (void) ConcatenateMagickString(backup_filename,"~",MaxTextExtent);
4101 if (IsPathAccessible(backup_filename) == MagickFalse)
4102 break;
4103 }
4104 if ((IsPathAccessible(backup_filename) != MagickFalse) ||
4105 (rename(image->filename,backup_filename) != 0))
4106 *backup_filename='\0';
4107 }
4108 /*
4109 Write transmogrified image to disk.
4110 */
4111 image_info->synchronize=MagickTrue;
4112 status&=WriteImages(image_info,image,image->filename,exception);
4113 if ((status == MagickFalse) && (*backup_filename != '\0'))
4114 (void) remove(backup_filename);
4115 RemoveAllImageStack();
4116 continue;
4117 }
4118 pend=image != (Image *) NULL ? MagickTrue : MagickFalse;
4119 switch (*(option+1))
4120 {
4121 case 'a':
4122 {
4123 if (LocaleCompare("adaptive-blur",option+1) == 0)
4124 {
4125 i++;
cristybb503372010-05-27 20:51:26 +00004126 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004127 ThrowMogrifyException(OptionError,"MissingArgument",option);
4128 if (IsGeometry(argv[i]) == MagickFalse)
4129 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4130 break;
4131 }
4132 if (LocaleCompare("adaptive-resize",option+1) == 0)
4133 {
4134 i++;
cristybb503372010-05-27 20:51:26 +00004135 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004136 ThrowMogrifyException(OptionError,"MissingArgument",option);
4137 if (IsGeometry(argv[i]) == MagickFalse)
4138 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4139 break;
4140 }
4141 if (LocaleCompare("adaptive-sharpen",option+1) == 0)
4142 {
4143 i++;
cristybb503372010-05-27 20:51:26 +00004144 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004145 ThrowMogrifyException(OptionError,"MissingArgument",option);
4146 if (IsGeometry(argv[i]) == MagickFalse)
4147 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4148 break;
4149 }
4150 if (LocaleCompare("affine",option+1) == 0)
4151 {
4152 if (*option == '+')
4153 break;
4154 i++;
cristybb503372010-05-27 20:51:26 +00004155 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004156 ThrowMogrifyException(OptionError,"MissingArgument",option);
4157 if (IsGeometry(argv[i]) == MagickFalse)
4158 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4159 break;
4160 }
4161 if (LocaleCompare("alpha",option+1) == 0)
4162 {
cristybb503372010-05-27 20:51:26 +00004163 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004164 type;
4165
4166 if (*option == '+')
4167 break;
4168 i++;
cristybb503372010-05-27 20:51:26 +00004169 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004170 ThrowMogrifyException(OptionError,"MissingArgument",option);
4171 type=ParseMagickOption(MagickAlphaOptions,MagickFalse,argv[i]);
4172 if (type < 0)
4173 ThrowMogrifyException(OptionError,"UnrecognizedAlphaChannelType",
4174 argv[i]);
4175 break;
4176 }
4177 if (LocaleCompare("annotate",option+1) == 0)
4178 {
4179 if (*option == '+')
4180 break;
4181 i++;
cristybb503372010-05-27 20:51:26 +00004182 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004183 ThrowMogrifyException(OptionError,"MissingArgument",option);
4184 if (IsGeometry(argv[i]) == MagickFalse)
4185 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristybb503372010-05-27 20:51:26 +00004186 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004187 ThrowMogrifyException(OptionError,"MissingArgument",option);
4188 i++;
4189 break;
4190 }
4191 if (LocaleCompare("antialias",option+1) == 0)
4192 break;
4193 if (LocaleCompare("append",option+1) == 0)
4194 break;
4195 if (LocaleCompare("attenuate",option+1) == 0)
4196 {
4197 if (*option == '+')
4198 break;
4199 i++;
cristybb503372010-05-27 20:51:26 +00004200 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004201 ThrowMogrifyException(OptionError,"MissingArgument",option);
4202 if (IsGeometry(argv[i]) == MagickFalse)
4203 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4204 break;
4205 }
4206 if (LocaleCompare("authenticate",option+1) == 0)
4207 {
4208 if (*option == '+')
4209 break;
4210 i++;
cristybb503372010-05-27 20:51:26 +00004211 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004212 ThrowMogrifyException(OptionError,"MissingArgument",option);
4213 break;
4214 }
4215 if (LocaleCompare("auto-gamma",option+1) == 0)
4216 break;
4217 if (LocaleCompare("auto-level",option+1) == 0)
4218 break;
4219 if (LocaleCompare("auto-orient",option+1) == 0)
4220 break;
4221 if (LocaleCompare("average",option+1) == 0)
4222 break;
4223 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4224 }
4225 case 'b':
4226 {
4227 if (LocaleCompare("background",option+1) == 0)
4228 {
4229 if (*option == '+')
4230 break;
4231 i++;
cristybb503372010-05-27 20:51:26 +00004232 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004233 ThrowMogrifyException(OptionError,"MissingArgument",option);
4234 break;
4235 }
4236 if (LocaleCompare("bias",option+1) == 0)
4237 {
4238 if (*option == '+')
4239 break;
4240 i++;
cristybb503372010-05-27 20:51:26 +00004241 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004242 ThrowMogrifyException(OptionError,"MissingArgument",option);
4243 if (IsGeometry(argv[i]) == MagickFalse)
4244 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4245 break;
4246 }
4247 if (LocaleCompare("black-point-compensation",option+1) == 0)
4248 break;
4249 if (LocaleCompare("black-threshold",option+1) == 0)
4250 {
4251 if (*option == '+')
4252 break;
4253 i++;
cristybb503372010-05-27 20:51:26 +00004254 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004255 ThrowMogrifyException(OptionError,"MissingArgument",option);
4256 if (IsGeometry(argv[i]) == MagickFalse)
4257 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4258 break;
4259 }
4260 if (LocaleCompare("blue-primary",option+1) == 0)
4261 {
4262 if (*option == '+')
4263 break;
4264 i++;
cristybb503372010-05-27 20:51:26 +00004265 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004266 ThrowMogrifyException(OptionError,"MissingArgument",option);
4267 if (IsGeometry(argv[i]) == MagickFalse)
4268 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4269 break;
4270 }
4271 if (LocaleCompare("blue-shift",option+1) == 0)
4272 {
4273 i++;
cristybb503372010-05-27 20:51:26 +00004274 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004275 ThrowMogrifyException(OptionError,"MissingArgument",option);
4276 if (IsGeometry(argv[i]) == MagickFalse)
4277 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4278 break;
4279 }
4280 if (LocaleCompare("blur",option+1) == 0)
4281 {
4282 i++;
cristybb503372010-05-27 20:51:26 +00004283 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004284 ThrowMogrifyException(OptionError,"MissingArgument",option);
4285 if (IsGeometry(argv[i]) == MagickFalse)
4286 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4287 break;
4288 }
4289 if (LocaleCompare("border",option+1) == 0)
4290 {
4291 if (*option == '+')
4292 break;
4293 i++;
cristybb503372010-05-27 20:51:26 +00004294 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004295 ThrowMogrifyException(OptionError,"MissingArgument",option);
4296 if (IsGeometry(argv[i]) == MagickFalse)
4297 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4298 break;
4299 }
4300 if (LocaleCompare("bordercolor",option+1) == 0)
4301 {
4302 if (*option == '+')
4303 break;
4304 i++;
cristybb503372010-05-27 20:51:26 +00004305 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004306 ThrowMogrifyException(OptionError,"MissingArgument",option);
4307 break;
4308 }
4309 if (LocaleCompare("box",option+1) == 0)
4310 {
4311 if (*option == '+')
4312 break;
4313 i++;
cristybb503372010-05-27 20:51:26 +00004314 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004315 ThrowMogrifyException(OptionError,"MissingArgument",option);
4316 break;
4317 }
cristya28d6b82010-01-11 20:03:47 +00004318 if (LocaleCompare("brightness-contrast",option+1) == 0)
4319 {
4320 i++;
cristybb503372010-05-27 20:51:26 +00004321 if (i == (ssize_t) argc)
cristya28d6b82010-01-11 20:03:47 +00004322 ThrowMogrifyException(OptionError,"MissingArgument",option);
4323 if (IsGeometry(argv[i]) == MagickFalse)
4324 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4325 break;
4326 }
cristy3ed852e2009-09-05 21:47:34 +00004327 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4328 }
4329 case 'c':
4330 {
4331 if (LocaleCompare("cache",option+1) == 0)
4332 {
4333 if (*option == '+')
4334 break;
4335 i++;
cristybb503372010-05-27 20:51:26 +00004336 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004337 ThrowMogrifyException(OptionError,"MissingArgument",option);
4338 if (IsGeometry(argv[i]) == MagickFalse)
4339 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4340 break;
4341 }
4342 if (LocaleCompare("caption",option+1) == 0)
4343 {
4344 if (*option == '+')
4345 break;
4346 i++;
cristybb503372010-05-27 20:51:26 +00004347 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004348 ThrowMogrifyException(OptionError,"MissingArgument",option);
4349 break;
4350 }
4351 if (LocaleCompare("channel",option+1) == 0)
4352 {
cristybb503372010-05-27 20:51:26 +00004353 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004354 channel;
4355
4356 if (*option == '+')
4357 break;
4358 i++;
cristybb503372010-05-27 20:51:26 +00004359 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004360 ThrowMogrifyException(OptionError,"MissingArgument",option);
4361 channel=ParseChannelOption(argv[i]);
4362 if (channel < 0)
4363 ThrowMogrifyException(OptionError,"UnrecognizedChannelType",
4364 argv[i]);
4365 break;
4366 }
4367 if (LocaleCompare("cdl",option+1) == 0)
4368 {
4369 if (*option == '+')
4370 break;
4371 i++;
cristybb503372010-05-27 20:51:26 +00004372 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004373 ThrowMogrifyException(OptionError,"MissingArgument",option);
4374 break;
4375 }
4376 if (LocaleCompare("charcoal",option+1) == 0)
4377 {
4378 if (*option == '+')
4379 break;
4380 i++;
cristybb503372010-05-27 20:51:26 +00004381 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004382 ThrowMogrifyException(OptionError,"MissingArgument",option);
4383 if (IsGeometry(argv[i]) == MagickFalse)
4384 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4385 break;
4386 }
4387 if (LocaleCompare("chop",option+1) == 0)
4388 {
4389 if (*option == '+')
4390 break;
4391 i++;
cristybb503372010-05-27 20:51:26 +00004392 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004393 ThrowMogrifyException(OptionError,"MissingArgument",option);
4394 if (IsGeometry(argv[i]) == MagickFalse)
4395 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4396 break;
4397 }
cristy1eb45dd2009-09-25 16:38:06 +00004398 if (LocaleCompare("clamp",option+1) == 0)
4399 break;
4400 if (LocaleCompare("clip",option+1) == 0)
4401 break;
cristy3ed852e2009-09-05 21:47:34 +00004402 if (LocaleCompare("clip-mask",option+1) == 0)
4403 {
4404 if (*option == '+')
4405 break;
4406 i++;
cristybb503372010-05-27 20:51:26 +00004407 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004408 ThrowMogrifyException(OptionError,"MissingArgument",option);
4409 break;
4410 }
4411 if (LocaleCompare("clut",option+1) == 0)
4412 break;
4413 if (LocaleCompare("coalesce",option+1) == 0)
4414 break;
4415 if (LocaleCompare("colorize",option+1) == 0)
4416 {
4417 if (*option == '+')
4418 break;
4419 i++;
cristybb503372010-05-27 20:51:26 +00004420 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004421 ThrowMogrifyException(OptionError,"MissingArgument",option);
4422 if (IsGeometry(argv[i]) == MagickFalse)
4423 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4424 break;
4425 }
cristye6365592010-04-02 17:31:23 +00004426 if (LocaleCompare("color-matrix",option+1) == 0)
4427 {
4428 if (*option == '+')
4429 break;
4430 i++;
cristybb503372010-05-27 20:51:26 +00004431 if (i == (ssize_t) (argc-1))
cristye6365592010-04-02 17:31:23 +00004432 ThrowMogrifyException(OptionError,"MissingArgument",option);
4433 if (IsGeometry(argv[i]) == MagickFalse)
4434 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4435 break;
4436 }
cristy3ed852e2009-09-05 21:47:34 +00004437 if (LocaleCompare("colors",option+1) == 0)
4438 {
4439 if (*option == '+')
4440 break;
4441 i++;
cristybb503372010-05-27 20:51:26 +00004442 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004443 ThrowMogrifyException(OptionError,"MissingArgument",option);
4444 if (IsGeometry(argv[i]) == MagickFalse)
4445 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4446 break;
4447 }
4448 if (LocaleCompare("colorspace",option+1) == 0)
4449 {
cristybb503372010-05-27 20:51:26 +00004450 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004451 colorspace;
4452
4453 if (*option == '+')
4454 break;
4455 i++;
cristybb503372010-05-27 20:51:26 +00004456 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004457 ThrowMogrifyException(OptionError,"MissingArgument",option);
4458 colorspace=ParseMagickOption(MagickColorspaceOptions,MagickFalse,
4459 argv[i]);
4460 if (colorspace < 0)
4461 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
4462 argv[i]);
4463 break;
4464 }
4465 if (LocaleCompare("combine",option+1) == 0)
4466 break;
4467 if (LocaleCompare("comment",option+1) == 0)
4468 {
4469 if (*option == '+')
4470 break;
4471 i++;
cristybb503372010-05-27 20:51:26 +00004472 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004473 ThrowMogrifyException(OptionError,"MissingArgument",option);
4474 break;
4475 }
4476 if (LocaleCompare("composite",option+1) == 0)
4477 break;
4478 if (LocaleCompare("compress",option+1) == 0)
4479 {
cristybb503372010-05-27 20:51:26 +00004480 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004481 compress;
4482
4483 if (*option == '+')
4484 break;
4485 i++;
cristybb503372010-05-27 20:51:26 +00004486 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004487 ThrowMogrifyException(OptionError,"MissingArgument",option);
4488 compress=ParseMagickOption(MagickCompressOptions,MagickFalse,
4489 argv[i]);
4490 if (compress < 0)
4491 ThrowMogrifyException(OptionError,"UnrecognizedImageCompression",
4492 argv[i]);
4493 break;
4494 }
cristy22879752009-10-25 23:55:40 +00004495 if (LocaleCompare("concurrent",option+1) == 0)
4496 break;
cristy3ed852e2009-09-05 21:47:34 +00004497 if (LocaleCompare("contrast",option+1) == 0)
4498 break;
4499 if (LocaleCompare("contrast-stretch",option+1) == 0)
4500 {
4501 i++;
cristybb503372010-05-27 20:51:26 +00004502 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004503 ThrowMogrifyException(OptionError,"MissingArgument",option);
4504 if (IsGeometry(argv[i]) == MagickFalse)
4505 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4506 break;
4507 }
4508 if (LocaleCompare("convolve",option+1) == 0)
4509 {
anthony29188a82010-01-22 10:12:34 +00004510 char
4511 token[MaxTextExtent];
4512
cristy3ed852e2009-09-05 21:47:34 +00004513 if (*option == '+')
4514 break;
4515 i++;
cristybb503372010-05-27 20:51:26 +00004516 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004517 ThrowMogrifyException(OptionError,"MissingArgument",option);
anthony29188a82010-01-22 10:12:34 +00004518#if 1
cristydfbe6ca2010-03-12 14:08:17 +00004519 (void) token;
cristy3ed852e2009-09-05 21:47:34 +00004520 if (IsGeometry(argv[i]) == MagickFalse)
4521 ThrowMogrifyInvalidArgumentException(option,argv[i]);
anthony29188a82010-01-22 10:12:34 +00004522#else
4523 /* Allow the use of built-in kernels like 'gaussian'
4524 * These may not work for kernels with 'nan' values, like 'diamond'
4525 */
4526 GetMagickToken(argv[i],NULL,token);
4527 if ( isalpha((int)token[0]) )
4528 {
cristybb503372010-05-27 20:51:26 +00004529 ssize_t
anthony29188a82010-01-22 10:12:34 +00004530 op;
4531
4532 op=ParseMagickOption(MagickKernelOptions,MagickFalse,token);
4533 if (op < 0)
4534 ThrowMogrifyException(OptionError,"UnrecognizedKernelType",
4535 token);
4536 }
4537 /* geometry current returns invalid if 'nan' values are used */
4538 else if (IsGeometry(argv[i]) == MagickFalse)
4539 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4540#endif
cristy3ed852e2009-09-05 21:47:34 +00004541 break;
4542 }
4543 if (LocaleCompare("crop",option+1) == 0)
4544 {
4545 if (*option == '+')
4546 break;
4547 i++;
cristybb503372010-05-27 20:51:26 +00004548 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004549 ThrowMogrifyException(OptionError,"MissingArgument",option);
4550 if (IsGeometry(argv[i]) == MagickFalse)
4551 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4552 break;
4553 }
4554 if (LocaleCompare("cycle",option+1) == 0)
4555 {
4556 if (*option == '+')
4557 break;
4558 i++;
cristybb503372010-05-27 20:51:26 +00004559 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004560 ThrowMogrifyException(OptionError,"MissingArgument",option);
4561 if (IsGeometry(argv[i]) == MagickFalse)
4562 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4563 break;
4564 }
4565 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4566 }
4567 case 'd':
4568 {
4569 if (LocaleCompare("decipher",option+1) == 0)
4570 {
4571 if (*option == '+')
4572 break;
4573 i++;
cristybb503372010-05-27 20:51:26 +00004574 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004575 ThrowMogrifyException(OptionError,"MissingArgument",option);
4576 break;
4577 }
4578 if (LocaleCompare("deconstruct",option+1) == 0)
4579 break;
4580 if (LocaleCompare("debug",option+1) == 0)
4581 {
cristybb503372010-05-27 20:51:26 +00004582 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004583 event;
4584
4585 if (*option == '+')
4586 break;
4587 i++;
cristybb503372010-05-27 20:51:26 +00004588 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004589 ThrowMogrifyException(OptionError,"MissingArgument",option);
4590 event=ParseMagickOption(MagickLogEventOptions,MagickFalse,argv[i]);
4591 if (event < 0)
4592 ThrowMogrifyException(OptionError,"UnrecognizedEventType",
4593 argv[i]);
4594 (void) SetLogEventMask(argv[i]);
4595 break;
4596 }
4597 if (LocaleCompare("define",option+1) == 0)
4598 {
4599 i++;
cristybb503372010-05-27 20:51:26 +00004600 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004601 ThrowMogrifyException(OptionError,"MissingArgument",option);
4602 if (*option == '+')
4603 {
4604 const char
4605 *define;
4606
4607 define=GetImageOption(image_info,argv[i]);
4608 if (define == (const char *) NULL)
4609 ThrowMogrifyException(OptionError,"NoSuchOption",argv[i]);
4610 break;
4611 }
4612 break;
4613 }
4614 if (LocaleCompare("delay",option+1) == 0)
4615 {
4616 if (*option == '+')
4617 break;
4618 i++;
cristybb503372010-05-27 20:51:26 +00004619 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004620 ThrowMogrifyException(OptionError,"MissingArgument",option);
4621 if (IsGeometry(argv[i]) == MagickFalse)
4622 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4623 break;
4624 }
4625 if (LocaleCompare("density",option+1) == 0)
4626 {
4627 if (*option == '+')
4628 break;
4629 i++;
cristybb503372010-05-27 20:51:26 +00004630 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004631 ThrowMogrifyException(OptionError,"MissingArgument",option);
4632 if (IsGeometry(argv[i]) == MagickFalse)
4633 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4634 break;
4635 }
4636 if (LocaleCompare("depth",option+1) == 0)
4637 {
4638 if (*option == '+')
4639 break;
4640 i++;
cristybb503372010-05-27 20:51:26 +00004641 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004642 ThrowMogrifyException(OptionError,"MissingArgument",option);
4643 if (IsGeometry(argv[i]) == MagickFalse)
4644 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4645 break;
4646 }
4647 if (LocaleCompare("deskew",option+1) == 0)
4648 {
4649 if (*option == '+')
4650 break;
4651 i++;
cristybb503372010-05-27 20:51:26 +00004652 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004653 ThrowMogrifyException(OptionError,"MissingArgument",option);
4654 if (IsGeometry(argv[i]) == MagickFalse)
4655 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4656 break;
4657 }
4658 if (LocaleCompare("despeckle",option+1) == 0)
4659 break;
4660 if (LocaleCompare("dft",option+1) == 0)
4661 break;
cristyc9b12952010-03-28 01:12:28 +00004662 if (LocaleCompare("direction",option+1) == 0)
4663 {
cristybb503372010-05-27 20:51:26 +00004664 ssize_t
cristyc9b12952010-03-28 01:12:28 +00004665 direction;
4666
4667 if (*option == '+')
4668 break;
4669 i++;
cristybb503372010-05-27 20:51:26 +00004670 if (i == (ssize_t) argc)
cristyc9b12952010-03-28 01:12:28 +00004671 ThrowMogrifyException(OptionError,"MissingArgument",option);
4672 direction=ParseMagickOption(MagickDirectionOptions,MagickFalse,
4673 argv[i]);
4674 if (direction < 0)
4675 ThrowMogrifyException(OptionError,"UnrecognizedDirectionType",
4676 argv[i]);
4677 break;
4678 }
cristy3ed852e2009-09-05 21:47:34 +00004679 if (LocaleCompare("display",option+1) == 0)
4680 {
4681 if (*option == '+')
4682 break;
4683 i++;
cristybb503372010-05-27 20:51:26 +00004684 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004685 ThrowMogrifyException(OptionError,"MissingArgument",option);
4686 break;
4687 }
4688 if (LocaleCompare("dispose",option+1) == 0)
4689 {
cristybb503372010-05-27 20:51:26 +00004690 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004691 dispose;
4692
4693 if (*option == '+')
4694 break;
4695 i++;
cristybb503372010-05-27 20:51:26 +00004696 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004697 ThrowMogrifyException(OptionError,"MissingArgument",option);
4698 dispose=ParseMagickOption(MagickDisposeOptions,MagickFalse,argv[i]);
4699 if (dispose < 0)
4700 ThrowMogrifyException(OptionError,"UnrecognizedDisposeMethod",
4701 argv[i]);
4702 break;
4703 }
4704 if (LocaleCompare("distort",option+1) == 0)
4705 {
cristybb503372010-05-27 20:51:26 +00004706 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004707 op;
4708
4709 i++;
cristybb503372010-05-27 20:51:26 +00004710 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004711 ThrowMogrifyException(OptionError,"MissingArgument",option);
4712 op=ParseMagickOption(MagickDistortOptions,MagickFalse,argv[i]);
4713 if (op < 0)
4714 ThrowMogrifyException(OptionError,"UnrecognizedDistortMethod",
4715 argv[i]);
4716 i++;
cristybb503372010-05-27 20:51:26 +00004717 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004718 ThrowMogrifyException(OptionError,"MissingArgument",option);
4719 break;
4720 }
4721 if (LocaleCompare("dither",option+1) == 0)
4722 {
cristybb503372010-05-27 20:51:26 +00004723 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004724 method;
4725
4726 if (*option == '+')
4727 break;
4728 i++;
cristybb503372010-05-27 20:51:26 +00004729 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004730 ThrowMogrifyException(OptionError,"MissingArgument",option);
4731 method=ParseMagickOption(MagickDitherOptions,MagickFalse,argv[i]);
4732 if (method < 0)
4733 ThrowMogrifyException(OptionError,"UnrecognizedDitherMethod",
4734 argv[i]);
4735 break;
4736 }
4737 if (LocaleCompare("draw",option+1) == 0)
4738 {
4739 if (*option == '+')
4740 break;
4741 i++;
cristybb503372010-05-27 20:51:26 +00004742 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004743 ThrowMogrifyException(OptionError,"MissingArgument",option);
4744 break;
4745 }
cristy22879752009-10-25 23:55:40 +00004746 if (LocaleCompare("duration",option+1) == 0)
4747 {
4748 if (*option == '+')
4749 break;
4750 i++;
cristybb503372010-05-27 20:51:26 +00004751 if (i == (ssize_t) (argc-1))
cristy22879752009-10-25 23:55:40 +00004752 ThrowMogrifyException(OptionError,"MissingArgument",option);
4753 if (IsGeometry(argv[i]) == MagickFalse)
4754 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4755 break;
4756 }
cristy3ed852e2009-09-05 21:47:34 +00004757 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4758 }
4759 case 'e':
4760 {
4761 if (LocaleCompare("edge",option+1) == 0)
4762 {
4763 if (*option == '+')
4764 break;
4765 i++;
cristybb503372010-05-27 20:51:26 +00004766 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004767 ThrowMogrifyException(OptionError,"MissingArgument",option);
4768 if (IsGeometry(argv[i]) == MagickFalse)
4769 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4770 break;
4771 }
4772 if (LocaleCompare("emboss",option+1) == 0)
4773 {
4774 if (*option == '+')
4775 break;
4776 i++;
cristybb503372010-05-27 20:51:26 +00004777 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004778 ThrowMogrifyException(OptionError,"MissingArgument",option);
4779 if (IsGeometry(argv[i]) == MagickFalse)
4780 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4781 break;
4782 }
4783 if (LocaleCompare("encipher",option+1) == 0)
4784 {
4785 if (*option == '+')
4786 break;
4787 i++;
cristybb503372010-05-27 20:51:26 +00004788 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004789 ThrowMogrifyException(OptionError,"MissingArgument",option);
4790 break;
4791 }
4792 if (LocaleCompare("encoding",option+1) == 0)
4793 {
4794 if (*option == '+')
4795 break;
4796 i++;
cristybb503372010-05-27 20:51:26 +00004797 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004798 ThrowMogrifyException(OptionError,"MissingArgument",option);
4799 break;
4800 }
4801 if (LocaleCompare("endian",option+1) == 0)
4802 {
cristybb503372010-05-27 20:51:26 +00004803 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004804 endian;
4805
4806 if (*option == '+')
4807 break;
4808 i++;
cristybb503372010-05-27 20:51:26 +00004809 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004810 ThrowMogrifyException(OptionError,"MissingArgument",option);
4811 endian=ParseMagickOption(MagickEndianOptions,MagickFalse,argv[i]);
4812 if (endian < 0)
4813 ThrowMogrifyException(OptionError,"UnrecognizedEndianType",
4814 argv[i]);
4815 break;
4816 }
4817 if (LocaleCompare("enhance",option+1) == 0)
4818 break;
4819 if (LocaleCompare("equalize",option+1) == 0)
4820 break;
4821 if (LocaleCompare("evaluate",option+1) == 0)
4822 {
cristybb503372010-05-27 20:51:26 +00004823 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004824 op;
4825
4826 if (*option == '+')
4827 break;
4828 i++;
cristybb503372010-05-27 20:51:26 +00004829 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004830 ThrowMogrifyException(OptionError,"MissingArgument",option);
4831 op=ParseMagickOption(MagickEvaluateOptions,MagickFalse,argv[i]);
4832 if (op < 0)
4833 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4834 argv[i]);
4835 i++;
cristybb503372010-05-27 20:51:26 +00004836 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004837 ThrowMogrifyException(OptionError,"MissingArgument",option);
4838 if (IsGeometry(argv[i]) == MagickFalse)
4839 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4840 break;
4841 }
cristyd18ae7c2010-03-07 17:39:52 +00004842 if (LocaleCompare("evaluate-sequence",option+1) == 0)
4843 {
cristybb503372010-05-27 20:51:26 +00004844 ssize_t
cristyd18ae7c2010-03-07 17:39:52 +00004845 op;
4846
4847 if (*option == '+')
4848 break;
4849 i++;
cristybb503372010-05-27 20:51:26 +00004850 if (i == (ssize_t) argc)
cristyd18ae7c2010-03-07 17:39:52 +00004851 ThrowMogrifyException(OptionError,"MissingArgument",option);
4852 op=ParseMagickOption(MagickEvaluateOptions,MagickFalse,argv[i]);
4853 if (op < 0)
4854 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4855 argv[i]);
4856 break;
4857 }
cristy3ed852e2009-09-05 21:47:34 +00004858 if (LocaleCompare("extent",option+1) == 0)
4859 {
4860 if (*option == '+')
4861 break;
4862 i++;
cristybb503372010-05-27 20:51:26 +00004863 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004864 ThrowMogrifyException(OptionError,"MissingArgument",option);
4865 if (IsGeometry(argv[i]) == MagickFalse)
4866 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4867 break;
4868 }
4869 if (LocaleCompare("extract",option+1) == 0)
4870 {
4871 if (*option == '+')
4872 break;
4873 i++;
cristybb503372010-05-27 20:51:26 +00004874 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004875 ThrowMogrifyException(OptionError,"MissingArgument",option);
4876 if (IsGeometry(argv[i]) == MagickFalse)
4877 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4878 break;
4879 }
4880 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4881 }
4882 case 'f':
4883 {
4884 if (LocaleCompare("family",option+1) == 0)
4885 {
4886 if (*option == '+')
4887 break;
4888 i++;
cristybb503372010-05-27 20:51:26 +00004889 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004890 ThrowMogrifyException(OptionError,"MissingArgument",option);
4891 break;
4892 }
4893 if (LocaleCompare("fill",option+1) == 0)
4894 {
4895 if (*option == '+')
4896 break;
4897 i++;
cristybb503372010-05-27 20:51:26 +00004898 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004899 ThrowMogrifyException(OptionError,"MissingArgument",option);
4900 break;
4901 }
4902 if (LocaleCompare("filter",option+1) == 0)
4903 {
cristybb503372010-05-27 20:51:26 +00004904 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004905 filter;
4906
4907 if (*option == '+')
4908 break;
4909 i++;
cristybb503372010-05-27 20:51:26 +00004910 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004911 ThrowMogrifyException(OptionError,"MissingArgument",option);
4912 filter=ParseMagickOption(MagickFilterOptions,MagickFalse,argv[i]);
4913 if (filter < 0)
4914 ThrowMogrifyException(OptionError,"UnrecognizedImageFilter",
4915 argv[i]);
4916 break;
4917 }
4918 if (LocaleCompare("flatten",option+1) == 0)
4919 break;
4920 if (LocaleCompare("flip",option+1) == 0)
4921 break;
4922 if (LocaleCompare("flop",option+1) == 0)
4923 break;
4924 if (LocaleCompare("floodfill",option+1) == 0)
4925 {
4926 if (*option == '+')
4927 break;
4928 i++;
cristybb503372010-05-27 20:51:26 +00004929 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004930 ThrowMogrifyException(OptionError,"MissingArgument",option);
4931 if (IsGeometry(argv[i]) == MagickFalse)
4932 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4933 i++;
cristybb503372010-05-27 20:51:26 +00004934 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004935 ThrowMogrifyException(OptionError,"MissingArgument",option);
4936 break;
4937 }
4938 if (LocaleCompare("font",option+1) == 0)
4939 {
4940 if (*option == '+')
4941 break;
4942 i++;
cristybb503372010-05-27 20:51:26 +00004943 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004944 ThrowMogrifyException(OptionError,"MissingArgument",option);
4945 break;
4946 }
4947 if (LocaleCompare("format",option+1) == 0)
4948 {
4949 (void) CopyMagickString(argv[i]+1,"sans",MaxTextExtent);
4950 (void) CloneString(&format,(char *) NULL);
4951 if (*option == '+')
4952 break;
4953 i++;
cristybb503372010-05-27 20:51:26 +00004954 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004955 ThrowMogrifyException(OptionError,"MissingArgument",option);
4956 (void) CloneString(&format,argv[i]);
4957 (void) CopyMagickString(image_info->filename,format,MaxTextExtent);
4958 (void) ConcatenateMagickString(image_info->filename,":",
4959 MaxTextExtent);
cristyd965a422010-03-03 17:47:35 +00004960 (void) SetImageInfo(image_info,0,exception);
cristy3ed852e2009-09-05 21:47:34 +00004961 if (*image_info->magick == '\0')
4962 ThrowMogrifyException(OptionError,"UnrecognizedImageFormat",
4963 format);
4964 break;
4965 }
4966 if (LocaleCompare("frame",option+1) == 0)
4967 {
4968 if (*option == '+')
4969 break;
4970 i++;
cristybb503372010-05-27 20:51:26 +00004971 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004972 ThrowMogrifyException(OptionError,"MissingArgument",option);
4973 if (IsGeometry(argv[i]) == MagickFalse)
4974 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4975 break;
4976 }
4977 if (LocaleCompare("function",option+1) == 0)
4978 {
cristybb503372010-05-27 20:51:26 +00004979 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004980 op;
4981
4982 if (*option == '+')
4983 break;
4984 i++;
cristybb503372010-05-27 20:51:26 +00004985 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004986 ThrowMogrifyException(OptionError,"MissingArgument",option);
4987 op=ParseMagickOption(MagickFunctionOptions,MagickFalse,argv[i]);
4988 if (op < 0)
4989 ThrowMogrifyException(OptionError,"UnrecognizedFunction",argv[i]);
4990 i++;
cristybb503372010-05-27 20:51:26 +00004991 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004992 ThrowMogrifyException(OptionError,"MissingArgument",option);
4993 break;
4994 }
4995 if (LocaleCompare("fuzz",option+1) == 0)
4996 {
4997 if (*option == '+')
4998 break;
4999 i++;
cristybb503372010-05-27 20:51:26 +00005000 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005001 ThrowMogrifyException(OptionError,"MissingArgument",option);
5002 if (IsGeometry(argv[i]) == MagickFalse)
5003 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5004 break;
5005 }
5006 if (LocaleCompare("fx",option+1) == 0)
5007 {
5008 if (*option == '+')
5009 break;
5010 i++;
cristybb503372010-05-27 20:51:26 +00005011 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005012 ThrowMogrifyException(OptionError,"MissingArgument",option);
5013 break;
5014 }
5015 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5016 }
5017 case 'g':
5018 {
5019 if (LocaleCompare("gamma",option+1) == 0)
5020 {
5021 i++;
cristybb503372010-05-27 20:51:26 +00005022 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005023 ThrowMogrifyException(OptionError,"MissingArgument",option);
5024 if (IsGeometry(argv[i]) == MagickFalse)
5025 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5026 break;
5027 }
5028 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
5029 (LocaleCompare("gaussian",option+1) == 0))
5030 {
5031 i++;
cristybb503372010-05-27 20:51:26 +00005032 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005033 ThrowMogrifyException(OptionError,"MissingArgument",option);
5034 if (IsGeometry(argv[i]) == MagickFalse)
5035 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5036 break;
5037 }
5038 if (LocaleCompare("geometry",option+1) == 0)
5039 {
5040 if (*option == '+')
5041 break;
5042 i++;
cristybb503372010-05-27 20:51:26 +00005043 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005044 ThrowMogrifyException(OptionError,"MissingArgument",option);
5045 if (IsGeometry(argv[i]) == MagickFalse)
5046 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5047 break;
5048 }
5049 if (LocaleCompare("gravity",option+1) == 0)
5050 {
cristybb503372010-05-27 20:51:26 +00005051 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005052 gravity;
5053
5054 if (*option == '+')
5055 break;
5056 i++;
cristybb503372010-05-27 20:51:26 +00005057 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005058 ThrowMogrifyException(OptionError,"MissingArgument",option);
5059 gravity=ParseMagickOption(MagickGravityOptions,MagickFalse,argv[i]);
5060 if (gravity < 0)
5061 ThrowMogrifyException(OptionError,"UnrecognizedGravityType",
5062 argv[i]);
5063 break;
5064 }
5065 if (LocaleCompare("green-primary",option+1) == 0)
5066 {
5067 if (*option == '+')
5068 break;
5069 i++;
cristybb503372010-05-27 20:51:26 +00005070 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005071 ThrowMogrifyException(OptionError,"MissingArgument",option);
5072 if (IsGeometry(argv[i]) == MagickFalse)
5073 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5074 break;
5075 }
5076 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5077 }
5078 case 'h':
5079 {
5080 if (LocaleCompare("hald-clut",option+1) == 0)
5081 break;
5082 if ((LocaleCompare("help",option+1) == 0) ||
5083 (LocaleCompare("-help",option+1) == 0))
5084 return(MogrifyUsage());
5085 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5086 }
5087 case 'i':
5088 {
5089 if (LocaleCompare("identify",option+1) == 0)
5090 break;
5091 if (LocaleCompare("idft",option+1) == 0)
5092 break;
5093 if (LocaleCompare("implode",option+1) == 0)
5094 {
5095 if (*option == '+')
5096 break;
5097 i++;
cristybb503372010-05-27 20:51:26 +00005098 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005099 ThrowMogrifyException(OptionError,"MissingArgument",option);
5100 if (IsGeometry(argv[i]) == MagickFalse)
5101 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5102 break;
5103 }
5104 if (LocaleCompare("intent",option+1) == 0)
5105 {
cristybb503372010-05-27 20:51:26 +00005106 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005107 intent;
5108
5109 if (*option == '+')
5110 break;
5111 i++;
cristybb503372010-05-27 20:51:26 +00005112 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005113 ThrowMogrifyException(OptionError,"MissingArgument",option);
5114 intent=ParseMagickOption(MagickIntentOptions,MagickFalse,argv[i]);
5115 if (intent < 0)
5116 ThrowMogrifyException(OptionError,"UnrecognizedIntentType",
5117 argv[i]);
5118 break;
5119 }
5120 if (LocaleCompare("interlace",option+1) == 0)
5121 {
cristybb503372010-05-27 20:51:26 +00005122 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005123 interlace;
5124
5125 if (*option == '+')
5126 break;
5127 i++;
cristybb503372010-05-27 20:51:26 +00005128 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005129 ThrowMogrifyException(OptionError,"MissingArgument",option);
5130 interlace=ParseMagickOption(MagickInterlaceOptions,MagickFalse,
5131 argv[i]);
5132 if (interlace < 0)
5133 ThrowMogrifyException(OptionError,"UnrecognizedInterlaceType",
5134 argv[i]);
5135 break;
5136 }
cristyb32b90a2009-09-07 21:45:48 +00005137 if (LocaleCompare("interline-spacing",option+1) == 0)
5138 {
5139 if (*option == '+')
5140 break;
5141 i++;
cristybb503372010-05-27 20:51:26 +00005142 if (i == (ssize_t) (argc-1))
cristyb32b90a2009-09-07 21:45:48 +00005143 ThrowMogrifyException(OptionError,"MissingArgument",option);
5144 if (IsGeometry(argv[i]) == MagickFalse)
5145 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5146 break;
5147 }
cristy3ed852e2009-09-05 21:47:34 +00005148 if (LocaleCompare("interpolate",option+1) == 0)
5149 {
cristybb503372010-05-27 20:51:26 +00005150 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005151 interpolate;
5152
5153 if (*option == '+')
5154 break;
5155 i++;
cristybb503372010-05-27 20:51:26 +00005156 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005157 ThrowMogrifyException(OptionError,"MissingArgument",option);
5158 interpolate=ParseMagickOption(MagickInterpolateOptions,MagickFalse,
5159 argv[i]);
5160 if (interpolate < 0)
5161 ThrowMogrifyException(OptionError,"UnrecognizedInterpolateMethod",
5162 argv[i]);
5163 break;
5164 }
5165 if (LocaleCompare("interword-spacing",option+1) == 0)
5166 {
5167 if (*option == '+')
5168 break;
5169 i++;
cristybb503372010-05-27 20:51:26 +00005170 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005171 ThrowMogrifyException(OptionError,"MissingArgument",option);
5172 if (IsGeometry(argv[i]) == MagickFalse)
5173 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5174 break;
5175 }
5176 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5177 }
5178 case 'k':
5179 {
5180 if (LocaleCompare("kerning",option+1) == 0)
5181 {
5182 if (*option == '+')
5183 break;
5184 i++;
cristybb503372010-05-27 20:51:26 +00005185 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005186 ThrowMogrifyException(OptionError,"MissingArgument",option);
5187 if (IsGeometry(argv[i]) == MagickFalse)
5188 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5189 break;
5190 }
5191 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5192 }
5193 case 'l':
5194 {
5195 if (LocaleCompare("label",option+1) == 0)
5196 {
5197 if (*option == '+')
5198 break;
5199 i++;
cristybb503372010-05-27 20:51:26 +00005200 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005201 ThrowMogrifyException(OptionError,"MissingArgument",option);
5202 break;
5203 }
5204 if (LocaleCompare("lat",option+1) == 0)
5205 {
5206 if (*option == '+')
5207 break;
5208 i++;
cristybb503372010-05-27 20:51:26 +00005209 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005210 ThrowMogrifyException(OptionError,"MissingArgument",option);
5211 if (IsGeometry(argv[i]) == MagickFalse)
5212 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5213 }
5214 if (LocaleCompare("layers",option+1) == 0)
5215 {
cristybb503372010-05-27 20:51:26 +00005216 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005217 type;
5218
5219 if (*option == '+')
5220 break;
5221 i++;
cristybb503372010-05-27 20:51:26 +00005222 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005223 ThrowMogrifyException(OptionError,"MissingArgument",option);
5224 type=ParseMagickOption(MagickLayerOptions,MagickFalse,argv[i]);
5225 if (type < 0)
5226 ThrowMogrifyException(OptionError,"UnrecognizedLayerMethod",
5227 argv[i]);
5228 break;
5229 }
5230 if (LocaleCompare("level",option+1) == 0)
5231 {
5232 i++;
cristybb503372010-05-27 20:51:26 +00005233 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005234 ThrowMogrifyException(OptionError,"MissingArgument",option);
5235 if (IsGeometry(argv[i]) == MagickFalse)
5236 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5237 break;
5238 }
5239 if (LocaleCompare("level-colors",option+1) == 0)
5240 {
5241 i++;
cristybb503372010-05-27 20:51:26 +00005242 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005243 ThrowMogrifyException(OptionError,"MissingArgument",option);
5244 break;
5245 }
5246 if (LocaleCompare("linewidth",option+1) == 0)
5247 {
5248 if (*option == '+')
5249 break;
5250 i++;
cristybb503372010-05-27 20:51:26 +00005251 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005252 ThrowMogrifyException(OptionError,"MissingArgument",option);
5253 if (IsGeometry(argv[i]) == MagickFalse)
5254 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5255 break;
5256 }
5257 if (LocaleCompare("limit",option+1) == 0)
5258 {
5259 char
5260 *p;
5261
5262 double
5263 value;
5264
cristybb503372010-05-27 20:51:26 +00005265 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005266 resource;
5267
5268 if (*option == '+')
5269 break;
5270 i++;
cristybb503372010-05-27 20:51:26 +00005271 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005272 ThrowMogrifyException(OptionError,"MissingArgument",option);
5273 resource=ParseMagickOption(MagickResourceOptions,MagickFalse,
5274 argv[i]);
5275 if (resource < 0)
5276 ThrowMogrifyException(OptionError,"UnrecognizedResourceType",
5277 argv[i]);
5278 i++;
cristybb503372010-05-27 20:51:26 +00005279 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005280 ThrowMogrifyException(OptionError,"MissingArgument",option);
5281 value=strtod(argv[i],&p);
5282 if ((p == argv[i]) && (LocaleCompare("unlimited",argv[i]) != 0))
5283 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5284 break;
5285 }
5286 if (LocaleCompare("liquid-rescale",option+1) == 0)
5287 {
5288 i++;
cristybb503372010-05-27 20:51:26 +00005289 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005290 ThrowMogrifyException(OptionError,"MissingArgument",option);
5291 if (IsGeometry(argv[i]) == MagickFalse)
5292 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5293 break;
5294 }
5295 if (LocaleCompare("list",option+1) == 0)
5296 {
cristybb503372010-05-27 20:51:26 +00005297 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005298 list;
5299
5300 if (*option == '+')
5301 break;
5302 i++;
cristybb503372010-05-27 20:51:26 +00005303 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005304 ThrowMogrifyException(OptionError,"MissingArgument",option);
5305 list=ParseMagickOption(MagickListOptions,MagickFalse,argv[i]);
5306 if (list < 0)
5307 ThrowMogrifyException(OptionError,"UnrecognizedListType",argv[i]);
cristyaeb2cbc2010-05-07 13:28:58 +00005308 status=MogrifyImageInfo(image_info,(int) (i-j+1),(const char **)
cristy3ed852e2009-09-05 21:47:34 +00005309 argv+j,exception);
cristyaeb2cbc2010-05-07 13:28:58 +00005310 return(status != 0 ? MagickFalse : MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00005311 }
5312 if (LocaleCompare("log",option+1) == 0)
5313 {
5314 if (*option == '+')
5315 break;
5316 i++;
cristybb503372010-05-27 20:51:26 +00005317 if ((i == (ssize_t) argc) ||
cristy3ed852e2009-09-05 21:47:34 +00005318 (strchr(argv[i],'%') == (char *) NULL))
5319 ThrowMogrifyException(OptionError,"MissingArgument",option);
5320 break;
5321 }
5322 if (LocaleCompare("loop",option+1) == 0)
5323 {
5324 if (*option == '+')
5325 break;
5326 i++;
cristybb503372010-05-27 20:51:26 +00005327 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005328 ThrowMogrifyException(OptionError,"MissingArgument",option);
5329 if (IsGeometry(argv[i]) == MagickFalse)
5330 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5331 break;
5332 }
5333 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5334 }
5335 case 'm':
5336 {
5337 if (LocaleCompare("map",option+1) == 0)
5338 {
5339 global_colormap=(*option == '+') ? MagickTrue : MagickFalse;
5340 if (*option == '+')
5341 break;
5342 i++;
cristybb503372010-05-27 20:51:26 +00005343 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005344 ThrowMogrifyException(OptionError,"MissingArgument",option);
5345 break;
5346 }
5347 if (LocaleCompare("mask",option+1) == 0)
5348 {
5349 if (*option == '+')
5350 break;
5351 i++;
cristybb503372010-05-27 20:51:26 +00005352 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005353 ThrowMogrifyException(OptionError,"MissingArgument",option);
5354 break;
5355 }
5356 if (LocaleCompare("matte",option+1) == 0)
5357 break;
5358 if (LocaleCompare("mattecolor",option+1) == 0)
5359 {
5360 if (*option == '+')
5361 break;
5362 i++;
cristybb503372010-05-27 20:51:26 +00005363 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005364 ThrowMogrifyException(OptionError,"MissingArgument",option);
5365 break;
5366 }
cristyf40785b2010-03-06 02:27:27 +00005367 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00005368 break;
cristyf40785b2010-03-06 02:27:27 +00005369 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00005370 break;
cristy3ed852e2009-09-05 21:47:34 +00005371 if (LocaleCompare("modulate",option+1) == 0)
5372 {
5373 if (*option == '+')
5374 break;
5375 i++;
cristybb503372010-05-27 20:51:26 +00005376 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005377 ThrowMogrifyException(OptionError,"MissingArgument",option);
5378 if (IsGeometry(argv[i]) == MagickFalse)
5379 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5380 break;
5381 }
5382 if (LocaleCompare("median",option+1) == 0)
5383 {
5384 if (*option == '+')
5385 break;
5386 i++;
cristybb503372010-05-27 20:51:26 +00005387 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005388 ThrowMogrifyException(OptionError,"MissingArgument",option);
5389 if (IsGeometry(argv[i]) == MagickFalse)
5390 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5391 break;
5392 }
5393 if (LocaleCompare("monitor",option+1) == 0)
5394 break;
5395 if (LocaleCompare("monochrome",option+1) == 0)
5396 break;
5397 if (LocaleCompare("morph",option+1) == 0)
5398 {
5399 if (*option == '+')
5400 break;
5401 i++;
cristybb503372010-05-27 20:51:26 +00005402 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005403 ThrowMogrifyException(OptionError,"MissingArgument",option);
5404 if (IsGeometry(argv[i]) == MagickFalse)
5405 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5406 break;
5407 }
anthony29188a82010-01-22 10:12:34 +00005408 if (LocaleCompare("morphology",option+1) == 0)
5409 {
cristybb503372010-05-27 20:51:26 +00005410 ssize_t
anthony29188a82010-01-22 10:12:34 +00005411 op;
5412
5413 char
5414 token[MaxTextExtent];
5415
5416 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);
5427 GetMagickToken(argv[i],NULL,token);
cristyf0c78232010-03-15 12:53:40 +00005428 if (isalpha((int) ((unsigned char) *token)) != 0)
anthony29188a82010-01-22 10:12:34 +00005429 {
5430 op=ParseMagickOption(MagickKernelOptions,MagickFalse,token);
5431 if (op < 0)
5432 ThrowMogrifyException(OptionError,"UnrecognizedKernelType",
cristyf0c78232010-03-15 12:53:40 +00005433 token);
anthony29188a82010-01-22 10:12:34 +00005434 }
anthony29188a82010-01-22 10:12:34 +00005435 break;
5436 }
cristy3ed852e2009-09-05 21:47:34 +00005437 if (LocaleCompare("mosaic",option+1) == 0)
5438 break;
5439 if (LocaleCompare("motion-blur",option+1) == 0)
5440 {
5441 if (*option == '+')
5442 break;
5443 i++;
cristybb503372010-05-27 20:51:26 +00005444 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005445 ThrowMogrifyException(OptionError,"MissingArgument",option);
5446 if (IsGeometry(argv[i]) == MagickFalse)
5447 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5448 break;
5449 }
5450 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5451 }
5452 case 'n':
5453 {
5454 if (LocaleCompare("negate",option+1) == 0)
5455 break;
5456 if (LocaleCompare("noise",option+1) == 0)
5457 {
5458 i++;
cristybb503372010-05-27 20:51:26 +00005459 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005460 ThrowMogrifyException(OptionError,"MissingArgument",option);
5461 if (*option == '+')
5462 {
cristybb503372010-05-27 20:51:26 +00005463 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005464 noise;
5465
5466 noise=ParseMagickOption(MagickNoiseOptions,MagickFalse,argv[i]);
5467 if (noise < 0)
5468 ThrowMogrifyException(OptionError,"UnrecognizedNoiseType",
5469 argv[i]);
5470 break;
5471 }
5472 if (IsGeometry(argv[i]) == MagickFalse)
5473 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5474 break;
5475 }
5476 if (LocaleCompare("noop",option+1) == 0)
5477 break;
5478 if (LocaleCompare("normalize",option+1) == 0)
5479 break;
5480 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5481 }
5482 case 'o':
5483 {
5484 if (LocaleCompare("opaque",option+1) == 0)
5485 {
cristy3ed852e2009-09-05 21:47:34 +00005486 i++;
cristybb503372010-05-27 20:51:26 +00005487 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005488 ThrowMogrifyException(OptionError,"MissingArgument",option);
5489 break;
5490 }
5491 if (LocaleCompare("ordered-dither",option+1) == 0)
5492 {
5493 if (*option == '+')
5494 break;
5495 i++;
cristybb503372010-05-27 20:51:26 +00005496 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005497 ThrowMogrifyException(OptionError,"MissingArgument",option);
5498 break;
5499 }
5500 if (LocaleCompare("orient",option+1) == 0)
5501 {
cristybb503372010-05-27 20:51:26 +00005502 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005503 orientation;
5504
5505 orientation=UndefinedOrientation;
5506 if (*option == '+')
5507 break;
5508 i++;
cristybb503372010-05-27 20:51:26 +00005509 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005510 ThrowMogrifyException(OptionError,"MissingArgument",option);
5511 orientation=ParseMagickOption(MagickOrientationOptions,MagickFalse,
5512 argv[i]);
5513 if (orientation < 0)
5514 ThrowMogrifyException(OptionError,"UnrecognizedImageOrientation",
5515 argv[i]);
5516 break;
5517 }
5518 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5519 }
5520 case 'p':
5521 {
5522 if (LocaleCompare("page",option+1) == 0)
5523 {
5524 if (*option == '+')
5525 break;
5526 i++;
cristybb503372010-05-27 20:51:26 +00005527 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005528 ThrowMogrifyException(OptionError,"MissingArgument",option);
5529 break;
5530 }
5531 if (LocaleCompare("paint",option+1) == 0)
5532 {
5533 if (*option == '+')
5534 break;
5535 i++;
cristybb503372010-05-27 20:51:26 +00005536 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005537 ThrowMogrifyException(OptionError,"MissingArgument",option);
5538 if (IsGeometry(argv[i]) == MagickFalse)
5539 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5540 break;
5541 }
5542 if (LocaleCompare("path",option+1) == 0)
5543 {
5544 (void) CloneString(&path,(char *) NULL);
5545 if (*option == '+')
5546 break;
5547 i++;
cristybb503372010-05-27 20:51:26 +00005548 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005549 ThrowMogrifyException(OptionError,"MissingArgument",option);
5550 (void) CloneString(&path,argv[i]);
5551 break;
5552 }
5553 if (LocaleCompare("pointsize",option+1) == 0)
5554 {
5555 if (*option == '+')
5556 break;
5557 i++;
cristybb503372010-05-27 20:51:26 +00005558 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005559 ThrowMogrifyException(OptionError,"MissingArgument",option);
5560 if (IsGeometry(argv[i]) == MagickFalse)
5561 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5562 break;
5563 }
5564 if (LocaleCompare("polaroid",option+1) == 0)
5565 {
5566 if (*option == '+')
5567 break;
5568 i++;
cristybb503372010-05-27 20:51:26 +00005569 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005570 ThrowMogrifyException(OptionError,"MissingArgument",option);
5571 if (IsGeometry(argv[i]) == MagickFalse)
5572 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5573 break;
5574 }
5575 if (LocaleCompare("posterize",option+1) == 0)
5576 {
5577 if (*option == '+')
5578 break;
5579 i++;
cristybb503372010-05-27 20:51:26 +00005580 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005581 ThrowMogrifyException(OptionError,"MissingArgument",option);
5582 if (IsGeometry(argv[i]) == MagickFalse)
5583 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5584 break;
5585 }
cristye7f51092010-01-17 00:39:37 +00005586 if (LocaleCompare("precision",option+1) == 0)
5587 {
5588 if (*option == '+')
5589 break;
5590 i++;
cristybb503372010-05-27 20:51:26 +00005591 if (i == (ssize_t) argc)
cristye7f51092010-01-17 00:39:37 +00005592 ThrowMogrifyException(OptionError,"MissingArgument",option);
5593 if (IsGeometry(argv[i]) == MagickFalse)
5594 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5595 break;
5596 }
cristy3ed852e2009-09-05 21:47:34 +00005597 if (LocaleCompare("print",option+1) == 0)
5598 {
5599 if (*option == '+')
5600 break;
5601 i++;
cristybb503372010-05-27 20:51:26 +00005602 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005603 ThrowMogrifyException(OptionError,"MissingArgument",option);
5604 break;
5605 }
5606 if (LocaleCompare("process",option+1) == 0)
5607 {
5608 if (*option == '+')
5609 break;
5610 i++;
cristybb503372010-05-27 20:51:26 +00005611 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005612 ThrowMogrifyException(OptionError,"MissingArgument",option);
5613 break;
5614 }
5615 if (LocaleCompare("profile",option+1) == 0)
5616 {
5617 i++;
cristybb503372010-05-27 20:51:26 +00005618 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005619 ThrowMogrifyException(OptionError,"MissingArgument",option);
5620 break;
5621 }
5622 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5623 }
5624 case 'q':
5625 {
5626 if (LocaleCompare("quality",option+1) == 0)
5627 {
5628 if (*option == '+')
5629 break;
5630 i++;
cristybb503372010-05-27 20:51:26 +00005631 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005632 ThrowMogrifyException(OptionError,"MissingArgument",option);
5633 if (IsGeometry(argv[i]) == MagickFalse)
5634 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5635 break;
5636 }
5637 if (LocaleCompare("quantize",option+1) == 0)
5638 {
cristybb503372010-05-27 20:51:26 +00005639 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005640 colorspace;
5641
5642 if (*option == '+')
5643 break;
5644 i++;
cristybb503372010-05-27 20:51:26 +00005645 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005646 ThrowMogrifyException(OptionError,"MissingArgument",option);
5647 colorspace=ParseMagickOption(MagickColorspaceOptions,MagickFalse,
5648 argv[i]);
5649 if (colorspace < 0)
5650 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
5651 argv[i]);
5652 break;
5653 }
5654 if (LocaleCompare("quiet",option+1) == 0)
5655 break;
5656 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5657 }
5658 case 'r':
5659 {
5660 if (LocaleCompare("radial-blur",option+1) == 0)
5661 {
5662 i++;
cristybb503372010-05-27 20:51:26 +00005663 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005664 ThrowMogrifyException(OptionError,"MissingArgument",option);
5665 if (IsGeometry(argv[i]) == MagickFalse)
5666 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5667 break;
5668 }
5669 if (LocaleCompare("raise",option+1) == 0)
5670 {
5671 i++;
cristybb503372010-05-27 20:51:26 +00005672 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005673 ThrowMogrifyException(OptionError,"MissingArgument",option);
5674 if (IsGeometry(argv[i]) == MagickFalse)
5675 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5676 break;
5677 }
5678 if (LocaleCompare("random-threshold",option+1) == 0)
5679 {
5680 if (*option == '+')
5681 break;
5682 i++;
cristybb503372010-05-27 20:51:26 +00005683 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005684 ThrowMogrifyException(OptionError,"MissingArgument",option);
5685 if (IsGeometry(argv[i]) == MagickFalse)
5686 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5687 break;
5688 }
cristye6365592010-04-02 17:31:23 +00005689 if (LocaleCompare("recolor",option+1) == 0)
5690 {
5691 if (*option == '+')
5692 break;
5693 i++;
cristybb503372010-05-27 20:51:26 +00005694 if (i == (ssize_t) (argc-1))
cristye6365592010-04-02 17:31:23 +00005695 ThrowMogrifyException(OptionError,"MissingArgument",option);
5696 if (IsGeometry(argv[i]) == MagickFalse)
5697 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5698 break;
5699 }
cristy3ed852e2009-09-05 21:47:34 +00005700 if (LocaleCompare("red-primary",option+1) == 0)
5701 {
5702 if (*option == '+')
5703 break;
5704 i++;
cristybb503372010-05-27 20:51:26 +00005705 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005706 ThrowMogrifyException(OptionError,"MissingArgument",option);
5707 if (IsGeometry(argv[i]) == MagickFalse)
5708 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5709 }
cristy9f2083a2010-04-22 19:48:05 +00005710 if (LocaleCompare("regard-warnings",option+1) == 0)
5711 break;
cristy3ed852e2009-09-05 21:47:34 +00005712 if (LocaleCompare("region",option+1) == 0)
5713 {
5714 if (*option == '+')
5715 break;
5716 i++;
cristybb503372010-05-27 20:51:26 +00005717 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005718 ThrowMogrifyException(OptionError,"MissingArgument",option);
5719 if (IsGeometry(argv[i]) == MagickFalse)
5720 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5721 break;
5722 }
cristyf0c78232010-03-15 12:53:40 +00005723 if (LocaleCompare("remap",option+1) == 0)
5724 {
5725 if (*option == '+')
5726 break;
5727 i++;
cristybb503372010-05-27 20:51:26 +00005728 if (i == (ssize_t) (argc-1))
cristyf0c78232010-03-15 12:53:40 +00005729 ThrowMogrifyException(OptionError,"MissingArgument",option);
5730 break;
5731 }
cristy3ed852e2009-09-05 21:47:34 +00005732 if (LocaleCompare("render",option+1) == 0)
5733 break;
5734 if (LocaleCompare("repage",option+1) == 0)
5735 {
5736 if (*option == '+')
5737 break;
5738 i++;
cristybb503372010-05-27 20:51:26 +00005739 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005740 ThrowMogrifyException(OptionError,"MissingArgument",option);
5741 if (IsGeometry(argv[i]) == MagickFalse)
5742 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5743 break;
5744 }
5745 if (LocaleCompare("resample",option+1) == 0)
5746 {
5747 if (*option == '+')
5748 break;
5749 i++;
cristybb503372010-05-27 20:51:26 +00005750 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005751 ThrowMogrifyException(OptionError,"MissingArgument",option);
5752 if (IsGeometry(argv[i]) == MagickFalse)
5753 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5754 break;
5755 }
5756 if (LocaleCompare("resize",option+1) == 0)
5757 {
5758 if (*option == '+')
5759 break;
5760 i++;
cristybb503372010-05-27 20:51:26 +00005761 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005762 ThrowMogrifyException(OptionError,"MissingArgument",option);
5763 if (IsGeometry(argv[i]) == MagickFalse)
5764 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5765 break;
5766 }
5767 if (LocaleCompare("reverse",option+1) == 0)
5768 break;
5769 if (LocaleCompare("roll",option+1) == 0)
5770 {
5771 if (*option == '+')
5772 break;
5773 i++;
cristybb503372010-05-27 20:51:26 +00005774 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005775 ThrowMogrifyException(OptionError,"MissingArgument",option);
5776 if (IsGeometry(argv[i]) == MagickFalse)
5777 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5778 break;
5779 }
5780 if (LocaleCompare("rotate",option+1) == 0)
5781 {
5782 i++;
cristybb503372010-05-27 20:51:26 +00005783 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005784 ThrowMogrifyException(OptionError,"MissingArgument",option);
5785 if (IsGeometry(argv[i]) == MagickFalse)
5786 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5787 break;
5788 }
5789 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5790 }
5791 case 's':
5792 {
5793 if (LocaleCompare("sample",option+1) == 0)
5794 {
5795 if (*option == '+')
5796 break;
5797 i++;
cristybb503372010-05-27 20:51:26 +00005798 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005799 ThrowMogrifyException(OptionError,"MissingArgument",option);
5800 if (IsGeometry(argv[i]) == MagickFalse)
5801 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5802 break;
5803 }
5804 if (LocaleCompare("sampling-factor",option+1) == 0)
5805 {
5806 if (*option == '+')
5807 break;
5808 i++;
cristybb503372010-05-27 20:51:26 +00005809 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005810 ThrowMogrifyException(OptionError,"MissingArgument",option);
5811 if (IsGeometry(argv[i]) == MagickFalse)
5812 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5813 break;
5814 }
5815 if (LocaleCompare("scale",option+1) == 0)
5816 {
5817 if (*option == '+')
5818 break;
5819 i++;
cristybb503372010-05-27 20:51:26 +00005820 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005821 ThrowMogrifyException(OptionError,"MissingArgument",option);
5822 if (IsGeometry(argv[i]) == MagickFalse)
5823 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5824 break;
5825 }
5826 if (LocaleCompare("scene",option+1) == 0)
5827 {
5828 if (*option == '+')
5829 break;
5830 i++;
cristybb503372010-05-27 20:51:26 +00005831 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005832 ThrowMogrifyException(OptionError,"MissingArgument",option);
5833 if (IsGeometry(argv[i]) == MagickFalse)
5834 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5835 break;
5836 }
5837 if (LocaleCompare("seed",option+1) == 0)
5838 {
5839 if (*option == '+')
5840 break;
5841 i++;
cristybb503372010-05-27 20:51:26 +00005842 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005843 ThrowMogrifyException(OptionError,"MissingArgument",option);
5844 if (IsGeometry(argv[i]) == MagickFalse)
5845 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5846 break;
5847 }
5848 if (LocaleCompare("segment",option+1) == 0)
5849 {
5850 if (*option == '+')
5851 break;
5852 i++;
cristybb503372010-05-27 20:51:26 +00005853 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005854 ThrowMogrifyException(OptionError,"MissingArgument",option);
5855 if (IsGeometry(argv[i]) == MagickFalse)
5856 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5857 break;
5858 }
5859 if (LocaleCompare("selective-blur",option+1) == 0)
5860 {
5861 i++;
cristybb503372010-05-27 20:51:26 +00005862 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005863 ThrowMogrifyException(OptionError,"MissingArgument",option);
5864 if (IsGeometry(argv[i]) == MagickFalse)
5865 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5866 break;
5867 }
5868 if (LocaleCompare("separate",option+1) == 0)
5869 break;
5870 if (LocaleCompare("sepia-tone",option+1) == 0)
5871 {
5872 if (*option == '+')
5873 break;
5874 i++;
cristybb503372010-05-27 20:51:26 +00005875 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005876 ThrowMogrifyException(OptionError,"MissingArgument",option);
5877 if (IsGeometry(argv[i]) == MagickFalse)
5878 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5879 break;
5880 }
5881 if (LocaleCompare("set",option+1) == 0)
5882 {
5883 i++;
cristybb503372010-05-27 20:51:26 +00005884 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005885 ThrowMogrifyException(OptionError,"MissingArgument",option);
5886 if (*option == '+')
5887 break;
5888 i++;
cristybb503372010-05-27 20:51:26 +00005889 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005890 ThrowMogrifyException(OptionError,"MissingArgument",option);
5891 break;
5892 }
5893 if (LocaleCompare("shade",option+1) == 0)
5894 {
5895 i++;
cristybb503372010-05-27 20:51:26 +00005896 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005897 ThrowMogrifyException(OptionError,"MissingArgument",option);
5898 if (IsGeometry(argv[i]) == MagickFalse)
5899 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5900 break;
5901 }
5902 if (LocaleCompare("shadow",option+1) == 0)
5903 {
5904 if (*option == '+')
5905 break;
5906 i++;
cristybb503372010-05-27 20:51:26 +00005907 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005908 ThrowMogrifyException(OptionError,"MissingArgument",option);
5909 if (IsGeometry(argv[i]) == MagickFalse)
5910 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5911 break;
5912 }
5913 if (LocaleCompare("sharpen",option+1) == 0)
5914 {
5915 i++;
cristybb503372010-05-27 20:51:26 +00005916 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005917 ThrowMogrifyException(OptionError,"MissingArgument",option);
5918 if (IsGeometry(argv[i]) == MagickFalse)
5919 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5920 break;
5921 }
5922 if (LocaleCompare("shave",option+1) == 0)
5923 {
5924 if (*option == '+')
5925 break;
5926 i++;
cristybb503372010-05-27 20:51:26 +00005927 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005928 ThrowMogrifyException(OptionError,"MissingArgument",option);
5929 if (IsGeometry(argv[i]) == MagickFalse)
5930 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5931 break;
5932 }
5933 if (LocaleCompare("shear",option+1) == 0)
5934 {
5935 i++;
cristybb503372010-05-27 20:51:26 +00005936 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005937 ThrowMogrifyException(OptionError,"MissingArgument",option);
5938 if (IsGeometry(argv[i]) == MagickFalse)
5939 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5940 break;
5941 }
5942 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
5943 {
5944 i++;
cristybb503372010-05-27 20:51:26 +00005945 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005946 ThrowMogrifyException(OptionError,"MissingArgument",option);
5947 if (IsGeometry(argv[i]) == MagickFalse)
5948 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5949 break;
5950 }
5951 if (LocaleCompare("size",option+1) == 0)
5952 {
5953 if (*option == '+')
5954 break;
5955 i++;
cristybb503372010-05-27 20:51:26 +00005956 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005957 ThrowMogrifyException(OptionError,"MissingArgument",option);
5958 if (IsGeometry(argv[i]) == MagickFalse)
5959 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5960 break;
5961 }
5962 if (LocaleCompare("sketch",option+1) == 0)
5963 {
5964 if (*option == '+')
5965 break;
5966 i++;
cristybb503372010-05-27 20:51:26 +00005967 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005968 ThrowMogrifyException(OptionError,"MissingArgument",option);
5969 if (IsGeometry(argv[i]) == MagickFalse)
5970 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5971 break;
5972 }
5973 if (LocaleCompare("solarize",option+1) == 0)
5974 {
5975 if (*option == '+')
5976 break;
5977 i++;
cristybb503372010-05-27 20:51:26 +00005978 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005979 ThrowMogrifyException(OptionError,"MissingArgument",option);
5980 if (IsGeometry(argv[i]) == MagickFalse)
5981 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5982 break;
5983 }
5984 if (LocaleCompare("sparse-color",option+1) == 0)
5985 {
cristybb503372010-05-27 20:51:26 +00005986 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005987 op;
5988
5989 i++;
cristybb503372010-05-27 20:51:26 +00005990 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005991 ThrowMogrifyException(OptionError,"MissingArgument",option);
5992 op=ParseMagickOption(MagickSparseColorOptions,MagickFalse,argv[i]);
5993 if (op < 0)
5994 ThrowMogrifyException(OptionError,"UnrecognizedSparseColorMethod",
5995 argv[i]);
5996 i++;
cristybb503372010-05-27 20:51:26 +00005997 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005998 ThrowMogrifyException(OptionError,"MissingArgument",option);
5999 break;
6000 }
6001 if (LocaleCompare("spread",option+1) == 0)
6002 {
6003 if (*option == '+')
6004 break;
6005 i++;
cristybb503372010-05-27 20:51:26 +00006006 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006007 ThrowMogrifyException(OptionError,"MissingArgument",option);
6008 if (IsGeometry(argv[i]) == MagickFalse)
6009 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6010 break;
6011 }
6012 if (LocaleCompare("stretch",option+1) == 0)
6013 {
cristybb503372010-05-27 20:51:26 +00006014 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006015 stretch;
6016
6017 if (*option == '+')
6018 break;
6019 i++;
cristybb503372010-05-27 20:51:26 +00006020 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006021 ThrowMogrifyException(OptionError,"MissingArgument",option);
6022 stretch=ParseMagickOption(MagickStretchOptions,MagickFalse,argv[i]);
6023 if (stretch < 0)
6024 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
6025 argv[i]);
6026 break;
6027 }
6028 if (LocaleCompare("strip",option+1) == 0)
6029 break;
6030 if (LocaleCompare("stroke",option+1) == 0)
6031 {
6032 if (*option == '+')
6033 break;
6034 i++;
cristybb503372010-05-27 20:51:26 +00006035 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006036 ThrowMogrifyException(OptionError,"MissingArgument",option);
6037 break;
6038 }
6039 if (LocaleCompare("strokewidth",option+1) == 0)
6040 {
6041 if (*option == '+')
6042 break;
6043 i++;
cristybb503372010-05-27 20:51:26 +00006044 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006045 ThrowMogrifyException(OptionError,"MissingArgument",option);
6046 if (IsGeometry(argv[i]) == MagickFalse)
6047 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6048 break;
6049 }
6050 if (LocaleCompare("style",option+1) == 0)
6051 {
cristybb503372010-05-27 20:51:26 +00006052 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006053 style;
6054
6055 if (*option == '+')
6056 break;
6057 i++;
cristybb503372010-05-27 20:51:26 +00006058 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006059 ThrowMogrifyException(OptionError,"MissingArgument",option);
6060 style=ParseMagickOption(MagickStyleOptions,MagickFalse,argv[i]);
6061 if (style < 0)
6062 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
6063 argv[i]);
6064 break;
6065 }
6066 if (LocaleCompare("swirl",option+1) == 0)
6067 {
6068 if (*option == '+')
6069 break;
6070 i++;
cristybb503372010-05-27 20:51:26 +00006071 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006072 ThrowMogrifyException(OptionError,"MissingArgument",option);
6073 if (IsGeometry(argv[i]) == MagickFalse)
6074 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6075 break;
6076 }
6077 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6078 }
6079 case 't':
6080 {
6081 if (LocaleCompare("taint",option+1) == 0)
6082 break;
6083 if (LocaleCompare("texture",option+1) == 0)
6084 {
6085 if (*option == '+')
6086 break;
6087 i++;
cristybb503372010-05-27 20:51:26 +00006088 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006089 ThrowMogrifyException(OptionError,"MissingArgument",option);
6090 break;
6091 }
6092 if (LocaleCompare("tile",option+1) == 0)
6093 {
6094 if (*option == '+')
6095 break;
6096 i++;
cristybb503372010-05-27 20:51:26 +00006097 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006098 ThrowMogrifyException(OptionError,"MissingArgument",option);
6099 break;
6100 }
6101 if (LocaleCompare("tile-offset",option+1) == 0)
6102 {
6103 if (*option == '+')
6104 break;
6105 i++;
cristybb503372010-05-27 20:51:26 +00006106 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006107 ThrowMogrifyException(OptionError,"MissingArgument",option);
6108 if (IsGeometry(argv[i]) == MagickFalse)
6109 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6110 break;
6111 }
6112 if (LocaleCompare("tint",option+1) == 0)
6113 {
6114 if (*option == '+')
6115 break;
6116 i++;
cristybb503372010-05-27 20:51:26 +00006117 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006118 ThrowMogrifyException(OptionError,"MissingArgument",option);
6119 if (IsGeometry(argv[i]) == MagickFalse)
6120 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6121 break;
6122 }
6123 if (LocaleCompare("transform",option+1) == 0)
6124 break;
6125 if (LocaleCompare("transpose",option+1) == 0)
6126 break;
6127 if (LocaleCompare("transverse",option+1) == 0)
6128 break;
6129 if (LocaleCompare("threshold",option+1) == 0)
6130 {
6131 if (*option == '+')
6132 break;
6133 i++;
cristybb503372010-05-27 20:51:26 +00006134 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006135 ThrowMogrifyException(OptionError,"MissingArgument",option);
6136 if (IsGeometry(argv[i]) == MagickFalse)
6137 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6138 break;
6139 }
6140 if (LocaleCompare("thumbnail",option+1) == 0)
6141 {
6142 if (*option == '+')
6143 break;
6144 i++;
cristybb503372010-05-27 20:51:26 +00006145 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006146 ThrowMogrifyException(OptionError,"MissingArgument",option);
6147 if (IsGeometry(argv[i]) == MagickFalse)
6148 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6149 break;
6150 }
6151 if (LocaleCompare("transparent",option+1) == 0)
6152 {
6153 i++;
cristybb503372010-05-27 20:51:26 +00006154 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006155 ThrowMogrifyException(OptionError,"MissingArgument",option);
6156 break;
6157 }
6158 if (LocaleCompare("transparent-color",option+1) == 0)
6159 {
6160 if (*option == '+')
6161 break;
6162 i++;
cristybb503372010-05-27 20:51:26 +00006163 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006164 ThrowMogrifyException(OptionError,"MissingArgument",option);
6165 break;
6166 }
6167 if (LocaleCompare("treedepth",option+1) == 0)
6168 {
6169 if (*option == '+')
6170 break;
6171 i++;
cristybb503372010-05-27 20:51:26 +00006172 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006173 ThrowMogrifyException(OptionError,"MissingArgument",option);
6174 if (IsGeometry(argv[i]) == MagickFalse)
6175 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6176 break;
6177 }
6178 if (LocaleCompare("trim",option+1) == 0)
6179 break;
6180 if (LocaleCompare("type",option+1) == 0)
6181 {
cristybb503372010-05-27 20:51:26 +00006182 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006183 type;
6184
6185 if (*option == '+')
6186 break;
6187 i++;
cristybb503372010-05-27 20:51:26 +00006188 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006189 ThrowMogrifyException(OptionError,"MissingArgument",option);
6190 type=ParseMagickOption(MagickTypeOptions,MagickFalse,argv[i]);
6191 if (type < 0)
6192 ThrowMogrifyException(OptionError,"UnrecognizedImageType",
6193 argv[i]);
6194 break;
6195 }
6196 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6197 }
6198 case 'u':
6199 {
6200 if (LocaleCompare("undercolor",option+1) == 0)
6201 {
6202 if (*option == '+')
6203 break;
6204 i++;
cristybb503372010-05-27 20:51:26 +00006205 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006206 ThrowMogrifyException(OptionError,"MissingArgument",option);
6207 break;
6208 }
6209 if (LocaleCompare("unique-colors",option+1) == 0)
6210 break;
6211 if (LocaleCompare("units",option+1) == 0)
6212 {
cristybb503372010-05-27 20:51:26 +00006213 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006214 units;
6215
6216 if (*option == '+')
6217 break;
6218 i++;
cristybb503372010-05-27 20:51:26 +00006219 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006220 ThrowMogrifyException(OptionError,"MissingArgument",option);
6221 units=ParseMagickOption(MagickResolutionOptions,MagickFalse,
6222 argv[i]);
6223 if (units < 0)
6224 ThrowMogrifyException(OptionError,"UnrecognizedUnitsType",
6225 argv[i]);
6226 break;
6227 }
6228 if (LocaleCompare("unsharp",option+1) == 0)
6229 {
6230 i++;
cristybb503372010-05-27 20:51:26 +00006231 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006232 ThrowMogrifyException(OptionError,"MissingArgument",option);
6233 if (IsGeometry(argv[i]) == MagickFalse)
6234 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6235 break;
6236 }
6237 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6238 }
6239 case 'v':
6240 {
6241 if (LocaleCompare("verbose",option+1) == 0)
6242 {
6243 image_info->verbose=(*option == '-') ? MagickTrue : MagickFalse;
6244 break;
6245 }
6246 if ((LocaleCompare("version",option+1) == 0) ||
6247 (LocaleCompare("-version",option+1) == 0))
6248 {
6249 (void) fprintf(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +00006250 GetMagickVersion((size_t *) NULL));
cristy610b2e22009-10-22 14:59:43 +00006251 (void) fprintf(stdout,"Copyright: %s\n",GetMagickCopyright());
6252 (void) fprintf(stdout,"Features: %s\n\n",GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00006253 break;
6254 }
6255 if (LocaleCompare("view",option+1) == 0)
6256 {
6257 if (*option == '+')
6258 break;
6259 i++;
cristybb503372010-05-27 20:51:26 +00006260 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006261 ThrowMogrifyException(OptionError,"MissingArgument",option);
6262 break;
6263 }
6264 if (LocaleCompare("vignette",option+1) == 0)
6265 {
6266 if (*option == '+')
6267 break;
6268 i++;
cristybb503372010-05-27 20:51:26 +00006269 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006270 ThrowMogrifyException(OptionError,"MissingArgument",option);
6271 if (IsGeometry(argv[i]) == MagickFalse)
6272 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6273 break;
6274 }
6275 if (LocaleCompare("virtual-pixel",option+1) == 0)
6276 {
cristybb503372010-05-27 20:51:26 +00006277 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006278 method;
6279
6280 if (*option == '+')
6281 break;
6282 i++;
cristybb503372010-05-27 20:51:26 +00006283 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006284 ThrowMogrifyException(OptionError,"MissingArgument",option);
6285 method=ParseMagickOption(MagickVirtualPixelOptions,MagickFalse,
6286 argv[i]);
6287 if (method < 0)
6288 ThrowMogrifyException(OptionError,
6289 "UnrecognizedVirtualPixelMethod",argv[i]);
6290 break;
6291 }
6292 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6293 }
6294 case 'w':
6295 {
6296 if (LocaleCompare("wave",option+1) == 0)
6297 {
6298 i++;
cristybb503372010-05-27 20:51:26 +00006299 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006300 ThrowMogrifyException(OptionError,"MissingArgument",option);
6301 if (IsGeometry(argv[i]) == MagickFalse)
6302 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6303 break;
6304 }
6305 if (LocaleCompare("weight",option+1) == 0)
6306 {
6307 if (*option == '+')
6308 break;
6309 i++;
cristybb503372010-05-27 20:51:26 +00006310 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006311 ThrowMogrifyException(OptionError,"MissingArgument",option);
6312 break;
6313 }
6314 if (LocaleCompare("white-point",option+1) == 0)
6315 {
6316 if (*option == '+')
6317 break;
6318 i++;
cristybb503372010-05-27 20:51:26 +00006319 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006320 ThrowMogrifyException(OptionError,"MissingArgument",option);
6321 if (IsGeometry(argv[i]) == MagickFalse)
6322 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6323 break;
6324 }
6325 if (LocaleCompare("white-threshold",option+1) == 0)
6326 {
6327 if (*option == '+')
6328 break;
6329 i++;
cristybb503372010-05-27 20:51:26 +00006330 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006331 ThrowMogrifyException(OptionError,"MissingArgument",option);
6332 if (IsGeometry(argv[i]) == MagickFalse)
6333 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6334 break;
6335 }
6336 if (LocaleCompare("write",option+1) == 0)
6337 {
6338 i++;
cristybb503372010-05-27 20:51:26 +00006339 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006340 ThrowMogrifyException(OptionError,"MissingArgument",option);
6341 break;
6342 }
6343 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6344 }
6345 case '?':
6346 break;
6347 default:
6348 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6349 }
6350 fire=ParseMagickOption(MagickImageListOptions,MagickFalse,option+1) < 0 ?
6351 MagickFalse : MagickTrue;
6352 if (fire != MagickFalse)
6353 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
6354 }
6355 if (k != 0)
6356 ThrowMogrifyException(OptionError,"UnbalancedParenthesis",argv[i]);
cristycee97112010-05-28 00:44:52 +00006357 if (i != (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006358 ThrowMogrifyException(OptionError,"MissingAnImageFilename",argv[i]);
6359 DestroyMogrify();
6360 return(status != 0 ? MagickTrue : MagickFalse);
6361}
6362
6363/*
6364%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6365% %
6366% %
6367% %
6368+ M o g r i f y I m a g e I n f o %
6369% %
6370% %
6371% %
6372%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6373%
6374% MogrifyImageInfo() applies image processing settings to the image as
6375% prescribed by command line options.
6376%
6377% The format of the MogrifyImageInfo method is:
6378%
6379% MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,const int argc,
6380% const char **argv,ExceptionInfo *exception)
6381%
6382% A description of each parameter follows:
6383%
6384% o image_info: the image info..
6385%
6386% o argc: Specifies a pointer to an integer describing the number of
6387% elements in the argument vector.
6388%
6389% o argv: Specifies a pointer to a text array containing the command line
6390% arguments.
6391%
6392% o exception: return any errors or warnings in this structure.
6393%
6394*/
6395WandExport MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,
6396 const int argc,const char **argv,ExceptionInfo *exception)
6397{
6398 const char
6399 *option;
6400
6401 GeometryInfo
6402 geometry_info;
6403
cristybb503372010-05-27 20:51:26 +00006404 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006405 count;
6406
cristybb503372010-05-27 20:51:26 +00006407 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006408 i;
6409
6410 /*
6411 Initialize method variables.
6412 */
6413 assert(image_info != (ImageInfo *) NULL);
6414 assert(image_info->signature == MagickSignature);
6415 if (image_info->debug != MagickFalse)
6416 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
6417 image_info->filename);
6418 if (argc < 0)
6419 return(MagickTrue);
6420 /*
6421 Set the image settings.
6422 */
cristybb503372010-05-27 20:51:26 +00006423 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00006424 {
6425 option=argv[i];
6426 if (IsMagickOption(option) == MagickFalse)
6427 continue;
6428 count=MagickMax(ParseMagickOption(MagickCommandOptions,MagickFalse,option),
6429 0L);
cristycee97112010-05-28 00:44:52 +00006430 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006431 break;
6432 switch (*(option+1))
6433 {
6434 case 'a':
6435 {
6436 if (LocaleCompare("adjoin",option+1) == 0)
6437 {
6438 image_info->adjoin=(*option == '-') ? MagickTrue : MagickFalse;
6439 break;
6440 }
6441 if (LocaleCompare("antialias",option+1) == 0)
6442 {
6443 image_info->antialias=(*option == '-') ? MagickTrue : MagickFalse;
6444 break;
6445 }
6446 if (LocaleCompare("attenuate",option+1) == 0)
6447 {
6448 if (*option == '+')
6449 {
6450 (void) DeleteImageOption(image_info,option+1);
6451 break;
6452 }
6453 (void) SetImageOption(image_info,option+1,argv[i+1]);
6454 break;
6455 }
6456 if (LocaleCompare("authenticate",option+1) == 0)
6457 {
6458 if (*option == '+')
6459 (void) CloneString(&image_info->authenticate,(char *) NULL);
6460 else
6461 (void) CloneString(&image_info->authenticate,argv[i+1]);
6462 break;
6463 }
6464 break;
6465 }
6466 case 'b':
6467 {
6468 if (LocaleCompare("background",option+1) == 0)
6469 {
6470 if (*option == '+')
6471 {
6472 (void) DeleteImageOption(image_info,option+1);
6473 (void) QueryColorDatabase(BackgroundColor,
6474 &image_info->background_color,exception);
6475 break;
6476 }
6477 (void) SetImageOption(image_info,option+1,argv[i+1]);
6478 (void) QueryColorDatabase(argv[i+1],&image_info->background_color,
6479 exception);
6480 break;
6481 }
6482 if (LocaleCompare("bias",option+1) == 0)
6483 {
6484 if (*option == '+')
6485 {
6486 (void) SetImageOption(image_info,option+1,"0.0");
6487 break;
6488 }
6489 (void) SetImageOption(image_info,option+1,argv[i+1]);
6490 break;
6491 }
6492 if (LocaleCompare("black-point-compensation",option+1) == 0)
6493 {
6494 if (*option == '+')
6495 {
6496 (void) SetImageOption(image_info,option+1,"false");
6497 break;
6498 }
6499 (void) SetImageOption(image_info,option+1,"true");
6500 break;
6501 }
6502 if (LocaleCompare("blue-primary",option+1) == 0)
6503 {
6504 if (*option == '+')
6505 {
6506 (void) SetImageOption(image_info,option+1,"0.0");
6507 break;
6508 }
6509 (void) SetImageOption(image_info,option+1,argv[i+1]);
6510 break;
6511 }
6512 if (LocaleCompare("bordercolor",option+1) == 0)
6513 {
6514 if (*option == '+')
6515 {
6516 (void) DeleteImageOption(image_info,option+1);
6517 (void) QueryColorDatabase(BorderColor,&image_info->border_color,
6518 exception);
6519 break;
6520 }
6521 (void) QueryColorDatabase(argv[i+1],&image_info->border_color,
6522 exception);
6523 (void) SetImageOption(image_info,option+1,argv[i+1]);
6524 break;
6525 }
6526 if (LocaleCompare("box",option+1) == 0)
6527 {
6528 if (*option == '+')
6529 {
6530 (void) SetImageOption(image_info,"undercolor","none");
6531 break;
6532 }
6533 (void) SetImageOption(image_info,"undercolor",argv[i+1]);
6534 break;
6535 }
6536 break;
6537 }
6538 case 'c':
6539 {
6540 if (LocaleCompare("cache",option+1) == 0)
6541 {
6542 MagickSizeType
6543 limit;
6544
6545 limit=MagickResourceInfinity;
6546 if (LocaleCompare("unlimited",argv[i+1]) != 0)
cristyf2f27272009-12-17 14:48:46 +00006547 limit=(MagickSizeType) SiPrefixToDouble(argv[i+1],100.0);
cristy3ed852e2009-09-05 21:47:34 +00006548 (void) SetMagickResourceLimit(MemoryResource,limit);
6549 (void) SetMagickResourceLimit(MapResource,2*limit);
6550 break;
6551 }
6552 if (LocaleCompare("caption",option+1) == 0)
6553 {
6554 if (*option == '+')
6555 {
6556 (void) DeleteImageOption(image_info,option+1);
6557 break;
6558 }
6559 (void) SetImageOption(image_info,option+1,argv[i+1]);
6560 break;
6561 }
6562 if (LocaleCompare("channel",option+1) == 0)
6563 {
6564 if (*option == '+')
6565 {
6566 image_info->channel=DefaultChannels;
6567 break;
6568 }
6569 image_info->channel=(ChannelType) ParseChannelOption(argv[i+1]);
6570 break;
6571 }
6572 if (LocaleCompare("colors",option+1) == 0)
6573 {
cristye27293e2009-12-18 02:53:20 +00006574 image_info->colors=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006575 break;
6576 }
6577 if (LocaleCompare("colorspace",option+1) == 0)
6578 {
6579 if (*option == '+')
6580 {
6581 image_info->colorspace=UndefinedColorspace;
6582 (void) SetImageOption(image_info,option+1,"undefined");
6583 break;
6584 }
6585 image_info->colorspace=(ColorspaceType) ParseMagickOption(
6586 MagickColorspaceOptions,MagickFalse,argv[i+1]);
6587 (void) SetImageOption(image_info,option+1,argv[i+1]);
6588 break;
6589 }
6590 if (LocaleCompare("compress",option+1) == 0)
6591 {
6592 if (*option == '+')
6593 {
6594 image_info->compression=UndefinedCompression;
6595 (void) SetImageOption(image_info,option+1,"undefined");
6596 break;
6597 }
6598 image_info->compression=(CompressionType) ParseMagickOption(
6599 MagickCompressOptions,MagickFalse,argv[i+1]);
6600 (void) SetImageOption(image_info,option+1,argv[i+1]);
6601 break;
6602 }
6603 if (LocaleCompare("comment",option+1) == 0)
6604 {
6605 if (*option == '+')
6606 {
6607 (void) DeleteImageOption(image_info,option+1);
6608 break;
6609 }
6610 (void) SetImageOption(image_info,option+1,argv[i+1]);
6611 break;
6612 }
6613 if (LocaleCompare("compose",option+1) == 0)
6614 {
6615 if (*option == '+')
6616 {
6617 (void) SetImageOption(image_info,option+1,"undefined");
6618 break;
6619 }
6620 (void) SetImageOption(image_info,option+1,argv[i+1]);
6621 break;
6622 }
6623 if (LocaleCompare("compress",option+1) == 0)
6624 {
6625 if (*option == '+')
6626 {
6627 image_info->compression=UndefinedCompression;
6628 (void) SetImageOption(image_info,option+1,"undefined");
6629 break;
6630 }
6631 image_info->compression=(CompressionType) ParseMagickOption(
6632 MagickCompressOptions,MagickFalse,argv[i+1]);
6633 (void) SetImageOption(image_info,option+1,argv[i+1]);
6634 break;
6635 }
6636 break;
6637 }
6638 case 'd':
6639 {
6640 if (LocaleCompare("debug",option+1) == 0)
6641 {
6642 if (*option == '+')
6643 (void) SetLogEventMask("none");
6644 else
6645 (void) SetLogEventMask(argv[i+1]);
6646 image_info->debug=IsEventLogging();
6647 break;
6648 }
6649 if (LocaleCompare("define",option+1) == 0)
6650 {
6651 if (*option == '+')
6652 {
6653 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6654 (void) DeleteImageRegistry(argv[i+1]+9);
6655 else
6656 (void) DeleteImageOption(image_info,argv[i+1]);
6657 break;
6658 }
6659 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6660 {
6661 (void) DefineImageRegistry(StringRegistryType,argv[i+1]+9,
6662 exception);
6663 break;
6664 }
6665 (void) DefineImageOption(image_info,argv[i+1]);
6666 break;
6667 }
6668 if (LocaleCompare("delay",option+1) == 0)
6669 {
6670 if (*option == '+')
6671 {
6672 (void) SetImageOption(image_info,option+1,"0");
6673 break;
6674 }
6675 (void) SetImageOption(image_info,option+1,argv[i+1]);
6676 break;
6677 }
6678 if (LocaleCompare("density",option+1) == 0)
6679 {
6680 /*
6681 Set image density.
6682 */
6683 if (*option == '+')
6684 {
6685 if (image_info->density != (char *) NULL)
6686 image_info->density=DestroyString(image_info->density);
6687 (void) SetImageOption(image_info,option+1,"72");
6688 break;
6689 }
6690 (void) CloneString(&image_info->density,argv[i+1]);
6691 (void) SetImageOption(image_info,option+1,argv[i+1]);
6692 break;
6693 }
6694 if (LocaleCompare("depth",option+1) == 0)
6695 {
6696 if (*option == '+')
6697 {
6698 image_info->depth=MAGICKCORE_QUANTUM_DEPTH;
6699 break;
6700 }
cristye27293e2009-12-18 02:53:20 +00006701 image_info->depth=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006702 break;
6703 }
cristyc9b12952010-03-28 01:12:28 +00006704 if (LocaleCompare("direction",option+1) == 0)
6705 {
6706 if (*option == '+')
6707 {
6708 (void) SetImageOption(image_info,option+1,"undefined");
6709 break;
6710 }
6711 (void) SetImageOption(image_info,option+1,argv[i+1]);
6712 break;
6713 }
cristy3ed852e2009-09-05 21:47:34 +00006714 if (LocaleCompare("display",option+1) == 0)
6715 {
6716 if (*option == '+')
6717 {
6718 if (image_info->server_name != (char *) NULL)
6719 image_info->server_name=DestroyString(
6720 image_info->server_name);
6721 break;
6722 }
6723 (void) CloneString(&image_info->server_name,argv[i+1]);
6724 break;
6725 }
6726 if (LocaleCompare("dispose",option+1) == 0)
6727 {
6728 if (*option == '+')
6729 {
6730 (void) SetImageOption(image_info,option+1,"undefined");
6731 break;
6732 }
6733 (void) SetImageOption(image_info,option+1,argv[i+1]);
6734 break;
6735 }
6736 if (LocaleCompare("dither",option+1) == 0)
6737 {
6738 if (*option == '+')
6739 {
6740 image_info->dither=MagickFalse;
cristyd5acfd12010-06-15 00:11:38 +00006741 (void) SetImageOption(image_info,option+1,"none");
cristy3ed852e2009-09-05 21:47:34 +00006742 break;
6743 }
6744 (void) SetImageOption(image_info,option+1,argv[i+1]);
6745 image_info->dither=MagickTrue;
6746 break;
6747 }
6748 break;
6749 }
6750 case 'e':
6751 {
6752 if (LocaleCompare("encoding",option+1) == 0)
6753 {
6754 if (*option == '+')
6755 {
6756 (void) SetImageOption(image_info,option+1,"undefined");
6757 break;
6758 }
6759 (void) SetImageOption(image_info,option+1,argv[i+1]);
6760 break;
6761 }
6762 if (LocaleCompare("endian",option+1) == 0)
6763 {
6764 if (*option == '+')
6765 {
6766 image_info->endian=UndefinedEndian;
6767 (void) SetImageOption(image_info,option+1,"undefined");
6768 break;
6769 }
6770 image_info->endian=(EndianType) ParseMagickOption(
6771 MagickEndianOptions,MagickFalse,argv[i+1]);
6772 (void) SetImageOption(image_info,option+1,argv[i+1]);
6773 break;
6774 }
6775 if (LocaleCompare("extract",option+1) == 0)
6776 {
6777 /*
6778 Set image extract geometry.
6779 */
6780 if (*option == '+')
6781 {
6782 if (image_info->extract != (char *) NULL)
6783 image_info->extract=DestroyString(image_info->extract);
6784 break;
6785 }
6786 (void) CloneString(&image_info->extract,argv[i+1]);
6787 break;
6788 }
6789 break;
6790 }
6791 case 'f':
6792 {
6793 if (LocaleCompare("fill",option+1) == 0)
6794 {
6795 if (*option == '+')
6796 {
6797 (void) SetImageOption(image_info,option+1,"none");
6798 break;
6799 }
6800 (void) SetImageOption(image_info,option+1,argv[i+1]);
6801 break;
6802 }
6803 if (LocaleCompare("filter",option+1) == 0)
6804 {
6805 if (*option == '+')
6806 {
6807 (void) SetImageOption(image_info,option+1,"undefined");
6808 break;
6809 }
6810 (void) SetImageOption(image_info,option+1,argv[i+1]);
6811 break;
6812 }
6813 if (LocaleCompare("font",option+1) == 0)
6814 {
6815 if (*option == '+')
6816 {
6817 if (image_info->font != (char *) NULL)
6818 image_info->font=DestroyString(image_info->font);
6819 break;
6820 }
6821 (void) CloneString(&image_info->font,argv[i+1]);
6822 break;
6823 }
6824 if (LocaleCompare("format",option+1) == 0)
6825 {
6826 register const char
6827 *q;
6828
6829 for (q=strchr(argv[i+1],'%'); q != (char *) NULL; q=strchr(q+1,'%'))
6830 if (strchr("gkrz@[#",*(q+1)) != (char *) NULL)
6831 image_info->ping=MagickFalse;
6832 (void) SetImageOption(image_info,option+1,argv[i+1]);
6833 break;
6834 }
6835 if (LocaleCompare("fuzz",option+1) == 0)
6836 {
6837 if (*option == '+')
6838 {
6839 image_info->fuzz=0.0;
6840 (void) SetImageOption(image_info,option+1,"0");
6841 break;
6842 }
cristyf2f27272009-12-17 14:48:46 +00006843 image_info->fuzz=SiPrefixToDouble(argv[i+1],(double) QuantumRange+
cristy3ed852e2009-09-05 21:47:34 +00006844 1.0);
6845 (void) SetImageOption(image_info,option+1,argv[i+1]);
6846 break;
6847 }
6848 break;
6849 }
6850 case 'g':
6851 {
6852 if (LocaleCompare("gravity",option+1) == 0)
6853 {
6854 if (*option == '+')
6855 {
6856 (void) SetImageOption(image_info,option+1,"undefined");
6857 break;
6858 }
6859 (void) SetImageOption(image_info,option+1,argv[i+1]);
6860 break;
6861 }
6862 if (LocaleCompare("green-primary",option+1) == 0)
6863 {
6864 if (*option == '+')
6865 {
6866 (void) SetImageOption(image_info,option+1,"0.0");
6867 break;
6868 }
6869 (void) SetImageOption(image_info,option+1,argv[i+1]);
6870 break;
6871 }
6872 break;
6873 }
6874 case 'i':
6875 {
6876 if (LocaleCompare("intent",option+1) == 0)
6877 {
6878 if (*option == '+')
6879 {
6880 (void) SetImageOption(image_info,option+1,"undefined");
6881 break;
6882 }
6883 (void) SetImageOption(image_info,option+1,argv[i+1]);
6884 break;
6885 }
6886 if (LocaleCompare("interlace",option+1) == 0)
6887 {
6888 if (*option == '+')
6889 {
6890 image_info->interlace=UndefinedInterlace;
6891 (void) SetImageOption(image_info,option+1,"undefined");
6892 break;
6893 }
6894 image_info->interlace=(InterlaceType) ParseMagickOption(
6895 MagickInterlaceOptions,MagickFalse,argv[i+1]);
6896 (void) SetImageOption(image_info,option+1,argv[i+1]);
6897 break;
6898 }
cristyb32b90a2009-09-07 21:45:48 +00006899 if (LocaleCompare("interline-spacing",option+1) == 0)
6900 {
6901 if (*option == '+')
6902 {
6903 (void) SetImageOption(image_info,option+1,"undefined");
6904 break;
6905 }
6906 (void) SetImageOption(image_info,option+1,argv[i+1]);
6907 break;
6908 }
cristy3ed852e2009-09-05 21:47:34 +00006909 if (LocaleCompare("interpolate",option+1) == 0)
6910 {
6911 if (*option == '+')
6912 {
6913 (void) SetImageOption(image_info,option+1,"undefined");
6914 break;
6915 }
6916 (void) SetImageOption(image_info,option+1,argv[i+1]);
6917 break;
6918 }
6919 if (LocaleCompare("interword-spacing",option+1) == 0)
6920 {
6921 if (*option == '+')
6922 {
6923 (void) SetImageOption(image_info,option+1,"undefined");
6924 break;
6925 }
6926 (void) SetImageOption(image_info,option+1,argv[i+1]);
6927 break;
6928 }
6929 break;
6930 }
6931 case 'k':
6932 {
6933 if (LocaleCompare("kerning",option+1) == 0)
6934 {
6935 if (*option == '+')
6936 {
6937 (void) SetImageOption(image_info,option+1,"undefined");
6938 break;
6939 }
6940 (void) SetImageOption(image_info,option+1,argv[i+1]);
6941 break;
6942 }
6943 break;
6944 }
6945 case 'l':
6946 {
6947 if (LocaleCompare("label",option+1) == 0)
6948 {
6949 if (*option == '+')
6950 {
6951 (void) DeleteImageOption(image_info,option+1);
6952 break;
6953 }
6954 (void) SetImageOption(image_info,option+1,argv[i+1]);
6955 break;
6956 }
6957 if (LocaleCompare("limit",option+1) == 0)
6958 {
6959 MagickSizeType
6960 limit;
6961
6962 ResourceType
6963 type;
6964
6965 if (*option == '+')
6966 break;
6967 type=(ResourceType) ParseMagickOption(MagickResourceOptions,
6968 MagickFalse,argv[i+1]);
6969 limit=MagickResourceInfinity;
6970 if (LocaleCompare("unlimited",argv[i+2]) != 0)
cristyf2f27272009-12-17 14:48:46 +00006971 limit=(MagickSizeType) SiPrefixToDouble(argv[i+2],100.0);
cristy3ed852e2009-09-05 21:47:34 +00006972 (void) SetMagickResourceLimit(type,limit);
6973 break;
6974 }
6975 if (LocaleCompare("list",option+1) == 0)
6976 {
cristybb503372010-05-27 20:51:26 +00006977 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006978 list;
6979
6980 /*
6981 Display configuration list.
6982 */
6983 list=ParseMagickOption(MagickListOptions,MagickFalse,argv[i+1]);
6984 switch (list)
6985 {
6986 case MagickCoderOptions:
6987 {
6988 (void) ListCoderInfo((FILE *) NULL,exception);
6989 break;
6990 }
6991 case MagickColorOptions:
6992 {
6993 (void) ListColorInfo((FILE *) NULL,exception);
6994 break;
6995 }
6996 case MagickConfigureOptions:
6997 {
6998 (void) ListConfigureInfo((FILE *) NULL,exception);
6999 break;
7000 }
7001 case MagickDelegateOptions:
7002 {
7003 (void) ListDelegateInfo((FILE *) NULL,exception);
7004 break;
7005 }
7006 case MagickFontOptions:
7007 {
7008 (void) ListTypeInfo((FILE *) NULL,exception);
7009 break;
7010 }
7011 case MagickFormatOptions:
7012 {
7013 (void) ListMagickInfo((FILE *) NULL,exception);
7014 break;
7015 }
7016 case MagickLocaleOptions:
7017 {
7018 (void) ListLocaleInfo((FILE *) NULL,exception);
7019 break;
7020 }
7021 case MagickLogOptions:
7022 {
7023 (void) ListLogInfo((FILE *) NULL,exception);
7024 break;
7025 }
7026 case MagickMagicOptions:
7027 {
7028 (void) ListMagicInfo((FILE *) NULL,exception);
7029 break;
7030 }
7031 case MagickMimeOptions:
7032 {
7033 (void) ListMimeInfo((FILE *) NULL,exception);
7034 break;
7035 }
7036 case MagickModuleOptions:
7037 {
7038 (void) ListModuleInfo((FILE *) NULL,exception);
7039 break;
7040 }
7041 case MagickPolicyOptions:
7042 {
7043 (void) ListPolicyInfo((FILE *) NULL,exception);
7044 break;
7045 }
7046 case MagickResourceOptions:
7047 {
7048 (void) ListMagickResourceInfo((FILE *) NULL,exception);
7049 break;
7050 }
7051 case MagickThresholdOptions:
7052 {
7053 (void) ListThresholdMaps((FILE *) NULL,exception);
7054 break;
7055 }
7056 default:
7057 {
7058 (void) ListMagickOptions((FILE *) NULL,(MagickOption) list,
7059 exception);
7060 break;
7061 }
7062 }
cristyaeb2cbc2010-05-07 13:28:58 +00007063 break;
cristy3ed852e2009-09-05 21:47:34 +00007064 }
7065 if (LocaleCompare("log",option+1) == 0)
7066 {
7067 if (*option == '+')
7068 break;
7069 (void) SetLogFormat(argv[i+1]);
7070 break;
7071 }
7072 if (LocaleCompare("loop",option+1) == 0)
7073 {
7074 if (*option == '+')
7075 {
7076 (void) SetImageOption(image_info,option+1,"0");
7077 break;
7078 }
7079 (void) SetImageOption(image_info,option+1,argv[i+1]);
7080 break;
7081 }
7082 break;
7083 }
7084 case 'm':
7085 {
7086 if (LocaleCompare("matte",option+1) == 0)
7087 {
7088 if (*option == '+')
7089 {
7090 (void) SetImageOption(image_info,option+1,"false");
7091 break;
7092 }
7093 (void) SetImageOption(image_info,option+1,"true");
7094 break;
7095 }
7096 if (LocaleCompare("mattecolor",option+1) == 0)
7097 {
7098 if (*option == '+')
7099 {
7100 (void) SetImageOption(image_info,option+1,argv[i+1]);
7101 (void) QueryColorDatabase(MatteColor,&image_info->matte_color,
7102 exception);
7103 break;
7104 }
7105 (void) SetImageOption(image_info,option+1,argv[i+1]);
7106 (void) QueryColorDatabase(argv[i+1],&image_info->matte_color,
7107 exception);
7108 break;
7109 }
7110 if (LocaleCompare("monitor",option+1) == 0)
7111 {
7112 (void) SetImageInfoProgressMonitor(image_info,MonitorProgress,
7113 (void *) NULL);
7114 break;
7115 }
7116 if (LocaleCompare("monochrome",option+1) == 0)
7117 {
7118 image_info->monochrome=(*option == '-') ? MagickTrue : MagickFalse;
7119 break;
7120 }
7121 break;
7122 }
7123 case 'o':
7124 {
7125 if (LocaleCompare("orient",option+1) == 0)
7126 {
7127 if (*option == '+')
7128 {
7129 image_info->orientation=UndefinedOrientation;
7130 (void) SetImageOption(image_info,option+1,"undefined");
7131 break;
7132 }
7133 image_info->orientation=(OrientationType) ParseMagickOption(
7134 MagickOrientationOptions,MagickFalse,argv[i+1]);
7135 (void) SetImageOption(image_info,option+1,"undefined");
7136 break;
7137 }
7138 }
7139 case 'p':
7140 {
7141 if (LocaleCompare("page",option+1) == 0)
7142 {
7143 char
7144 *canonical_page,
7145 page[MaxTextExtent];
7146
7147 const char
7148 *image_option;
7149
7150 MagickStatusType
7151 flags;
7152
7153 RectangleInfo
7154 geometry;
7155
7156 if (*option == '+')
7157 {
7158 (void) DeleteImageOption(image_info,option+1);
7159 (void) CloneString(&image_info->page,(char *) NULL);
7160 break;
7161 }
7162 (void) ResetMagickMemory(&geometry,0,sizeof(geometry));
7163 image_option=GetImageOption(image_info,"page");
7164 if (image_option != (const char *) NULL)
7165 flags=ParseAbsoluteGeometry(image_option,&geometry);
7166 canonical_page=GetPageGeometry(argv[i+1]);
7167 flags=ParseAbsoluteGeometry(canonical_page,&geometry);
7168 canonical_page=DestroyString(canonical_page);
7169 (void) FormatMagickString(page,MaxTextExtent,"%lux%lu",
cristyf2faecf2010-05-28 19:19:36 +00007170 (unsigned long) geometry.width,(unsigned long) geometry.height);
cristy3ed852e2009-09-05 21:47:34 +00007171 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
7172 (void) FormatMagickString(page,MaxTextExtent,"%lux%lu%+ld%+ld",
cristyf2faecf2010-05-28 19:19:36 +00007173 (unsigned long) geometry.width,(unsigned long) geometry.height,
7174 (long) geometry.x,(long) geometry.y);
cristy3ed852e2009-09-05 21:47:34 +00007175 (void) SetImageOption(image_info,option+1,page);
7176 (void) CloneString(&image_info->page,page);
7177 break;
7178 }
7179 if (LocaleCompare("pen",option+1) == 0)
7180 {
7181 if (*option == '+')
7182 {
7183 (void) SetImageOption(image_info,option+1,"none");
7184 break;
7185 }
7186 (void) SetImageOption(image_info,option+1,argv[i+1]);
7187 break;
7188 }
7189 if (LocaleCompare("ping",option+1) == 0)
7190 {
7191 image_info->ping=(*option == '-') ? MagickTrue : MagickFalse;
7192 break;
7193 }
7194 if (LocaleCompare("pointsize",option+1) == 0)
7195 {
7196 if (*option == '+')
7197 geometry_info.rho=0.0;
7198 else
7199 (void) ParseGeometry(argv[i+1],&geometry_info);
7200 image_info->pointsize=geometry_info.rho;
7201 break;
7202 }
cristye7f51092010-01-17 00:39:37 +00007203 if (LocaleCompare("precision",option+1) == 0)
7204 {
cristybf2766a2010-01-17 03:33:23 +00007205 (void) SetMagickPrecision(StringToInteger(argv[i+1]));
cristye7f51092010-01-17 00:39:37 +00007206 break;
7207 }
cristy3ed852e2009-09-05 21:47:34 +00007208 if (LocaleCompare("preview",option+1) == 0)
7209 {
7210 /*
7211 Preview image.
7212 */
7213 if (*option == '+')
7214 {
7215 image_info->preview_type=UndefinedPreview;
7216 break;
7217 }
7218 image_info->preview_type=(PreviewType) ParseMagickOption(
7219 MagickPreviewOptions,MagickFalse,argv[i+1]);
7220 break;
7221 }
7222 break;
7223 }
7224 case 'q':
7225 {
7226 if (LocaleCompare("quality",option+1) == 0)
7227 {
7228 /*
7229 Set image compression quality.
7230 */
7231 if (*option == '+')
7232 {
7233 image_info->quality=UndefinedCompressionQuality;
7234 (void) SetImageOption(image_info,option+1,"0");
7235 break;
7236 }
cristye27293e2009-12-18 02:53:20 +00007237 image_info->quality=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007238 (void) SetImageOption(image_info,option+1,argv[i+1]);
7239 break;
7240 }
7241 if (LocaleCompare("quiet",option+1) == 0)
7242 {
7243 static WarningHandler
7244 warning_handler = (WarningHandler) NULL;
7245
7246 if (*option == '+')
7247 {
7248 /*
7249 Restore error or warning messages.
7250 */
7251 warning_handler=SetWarningHandler(warning_handler);
7252 break;
7253 }
7254 /*
7255 Suppress error or warning messages.
7256 */
7257 warning_handler=SetWarningHandler((WarningHandler) NULL);
7258 break;
7259 }
7260 break;
7261 }
7262 case 'r':
7263 {
7264 if (LocaleCompare("red-primary",option+1) == 0)
7265 {
7266 if (*option == '+')
7267 {
7268 (void) SetImageOption(image_info,option+1,"0.0");
7269 break;
7270 }
7271 (void) SetImageOption(image_info,option+1,argv[i+1]);
7272 break;
7273 }
7274 break;
7275 }
7276 case 's':
7277 {
7278 if (LocaleCompare("sampling-factor",option+1) == 0)
7279 {
7280 /*
7281 Set image sampling factor.
7282 */
7283 if (*option == '+')
7284 {
7285 if (image_info->sampling_factor != (char *) NULL)
7286 image_info->sampling_factor=DestroyString(
7287 image_info->sampling_factor);
7288 break;
7289 }
7290 (void) CloneString(&image_info->sampling_factor,argv[i+1]);
7291 break;
7292 }
7293 if (LocaleCompare("scene",option+1) == 0)
7294 {
7295 /*
7296 Set image scene.
7297 */
7298 if (*option == '+')
7299 {
7300 image_info->scene=0;
7301 (void) SetImageOption(image_info,option+1,"0");
7302 break;
7303 }
cristye27293e2009-12-18 02:53:20 +00007304 image_info->scene=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007305 (void) SetImageOption(image_info,option+1,argv[i+1]);
7306 break;
7307 }
7308 if (LocaleCompare("seed",option+1) == 0)
7309 {
cristybb503372010-05-27 20:51:26 +00007310 size_t
cristy3ed852e2009-09-05 21:47:34 +00007311 seed;
7312
7313 if (*option == '+')
7314 {
cristybb503372010-05-27 20:51:26 +00007315 seed=(size_t) time((time_t *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00007316 SeedPseudoRandomGenerator(seed);
7317 break;
7318 }
cristye27293e2009-12-18 02:53:20 +00007319 seed=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007320 SeedPseudoRandomGenerator(seed);
7321 break;
7322 }
7323 if (LocaleCompare("size",option+1) == 0)
7324 {
7325 if (*option == '+')
7326 {
7327 if (image_info->size != (char *) NULL)
7328 image_info->size=DestroyString(image_info->size);
7329 break;
7330 }
7331 (void) CloneString(&image_info->size,argv[i+1]);
7332 break;
7333 }
7334 if (LocaleCompare("stroke",option+1) == 0)
7335 {
7336 if (*option == '+')
7337 {
7338 (void) SetImageOption(image_info,option+1,"none");
7339 break;
7340 }
7341 (void) SetImageOption(image_info,option+1,argv[i+1]);
7342 break;
7343 }
7344 if (LocaleCompare("strokewidth",option+1) == 0)
7345 {
7346 if (*option == '+')
7347 {
7348 (void) SetImageOption(image_info,option+1,"0");
7349 break;
7350 }
7351 (void) SetImageOption(image_info,option+1,argv[i+1]);
7352 break;
7353 }
7354 break;
7355 }
7356 case 't':
7357 {
7358 if (LocaleCompare("taint",option+1) == 0)
7359 {
7360 if (*option == '+')
7361 {
7362 (void) SetImageOption(image_info,option+1,"false");
7363 break;
7364 }
7365 (void) SetImageOption(image_info,option+1,"true");
7366 break;
7367 }
7368 if (LocaleCompare("texture",option+1) == 0)
7369 {
7370 if (*option == '+')
7371 {
7372 if (image_info->texture != (char *) NULL)
7373 image_info->texture=DestroyString(image_info->texture);
7374 break;
7375 }
7376 (void) CloneString(&image_info->texture,argv[i+1]);
7377 break;
7378 }
7379 if (LocaleCompare("tile-offset",option+1) == 0)
7380 {
7381 if (*option == '+')
7382 {
7383 (void) SetImageOption(image_info,option+1,"0");
7384 break;
7385 }
7386 (void) SetImageOption(image_info,option+1,argv[i+1]);
7387 break;
7388 }
7389 if (LocaleCompare("transparent-color",option+1) == 0)
7390 {
7391 if (*option == '+')
7392 {
7393 (void) QueryColorDatabase("none",&image_info->transparent_color, exception);
7394 (void) SetImageOption(image_info,option+1,"none");
7395 break;
7396 }
7397 (void) QueryColorDatabase(argv[i+1],&image_info->transparent_color,
7398 exception);
7399 (void) SetImageOption(image_info,option+1,argv[i+1]);
7400 break;
7401 }
7402 if (LocaleCompare("type",option+1) == 0)
7403 {
7404 if (*option == '+')
7405 {
7406 image_info->type=UndefinedType;
7407 (void) SetImageOption(image_info,option+1,"undefined");
7408 break;
7409 }
7410 image_info->type=(ImageType) ParseMagickOption(MagickTypeOptions,
7411 MagickFalse,argv[i+1]);
7412 (void) SetImageOption(image_info,option+1,argv[i+1]);
7413 break;
7414 }
7415 break;
7416 }
7417 case 'u':
7418 {
7419 if (LocaleCompare("undercolor",option+1) == 0)
7420 {
7421 if (*option == '+')
7422 {
7423 (void) DeleteImageOption(image_info,option+1);
7424 break;
7425 }
7426 (void) SetImageOption(image_info,option+1,argv[i+1]);
7427 break;
7428 }
7429 if (LocaleCompare("units",option+1) == 0)
7430 {
7431 if (*option == '+')
7432 {
7433 image_info->units=UndefinedResolution;
7434 (void) SetImageOption(image_info,option+1,"undefined");
7435 break;
7436 }
7437 image_info->units=(ResolutionType) ParseMagickOption(
7438 MagickResolutionOptions,MagickFalse,argv[i+1]);
7439 (void) SetImageOption(image_info,option+1,argv[i+1]);
7440 break;
7441 }
7442 break;
7443 }
7444 case 'v':
7445 {
7446 if (LocaleCompare("verbose",option+1) == 0)
7447 {
7448 if (*option == '+')
7449 {
7450 image_info->verbose=MagickFalse;
7451 break;
7452 }
7453 image_info->verbose=MagickTrue;
7454 image_info->ping=MagickFalse;
7455 break;
7456 }
7457 if (LocaleCompare("view",option+1) == 0)
7458 {
7459 if (*option == '+')
7460 {
7461 if (image_info->view != (char *) NULL)
7462 image_info->view=DestroyString(image_info->view);
7463 break;
7464 }
7465 (void) CloneString(&image_info->view,argv[i+1]);
7466 break;
7467 }
7468 if (LocaleCompare("virtual-pixel",option+1) == 0)
7469 {
7470 if (*option == '+')
7471 {
7472 image_info->virtual_pixel_method=UndefinedVirtualPixelMethod;
7473 (void) SetImageOption(image_info,option+1,"undefined");
7474 break;
7475 }
7476 image_info->virtual_pixel_method=(VirtualPixelMethod)
7477 ParseMagickOption(MagickVirtualPixelOptions,MagickFalse,
7478 argv[i+1]);
7479 (void) SetImageOption(image_info,option+1,argv[i+1]);
7480 break;
7481 }
7482 break;
7483 }
7484 case 'w':
7485 {
7486 if (LocaleCompare("white-point",option+1) == 0)
7487 {
7488 if (*option == '+')
7489 {
7490 (void) SetImageOption(image_info,option+1,"0.0");
7491 break;
7492 }
7493 (void) SetImageOption(image_info,option+1,argv[i+1]);
7494 break;
7495 }
7496 break;
7497 }
7498 default:
7499 break;
7500 }
7501 i+=count;
7502 }
7503 return(MagickTrue);
7504}
7505
7506/*
7507%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7508% %
7509% %
7510% %
7511+ M o g r i f y I m a g e L i s t %
7512% %
7513% %
7514% %
7515%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7516%
7517% MogrifyImageList() applies any command line options that might affect the
7518% entire image list (e.g. -append, -coalesce, etc.).
7519%
7520% The format of the MogrifyImage method is:
7521%
7522% MagickBooleanType MogrifyImageList(ImageInfo *image_info,const int argc,
7523% const char **argv,Image **images,ExceptionInfo *exception)
7524%
7525% A description of each parameter follows:
7526%
7527% o image_info: the image info..
7528%
7529% o argc: Specifies a pointer to an integer describing the number of
7530% elements in the argument vector.
7531%
7532% o argv: Specifies a pointer to a text array containing the command line
7533% arguments.
7534%
7535% o images: the images.
7536%
7537% o exception: return any errors or warnings in this structure.
7538%
7539*/
7540WandExport MagickBooleanType MogrifyImageList(ImageInfo *image_info,
7541 const int argc,const char **argv,Image **images,ExceptionInfo *exception)
7542{
7543 ChannelType
7544 channel;
7545
7546 const char
7547 *option;
7548
cristy6b3da3a2010-06-20 02:21:46 +00007549 ImageInfo
7550 *mogrify_info;
cristy3ed852e2009-09-05 21:47:34 +00007551
7552 MagickStatusType
7553 status;
7554
7555 QuantizeInfo
7556 *quantize_info;
7557
cristybb503372010-05-27 20:51:26 +00007558 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00007559 i;
7560
cristy6b3da3a2010-06-20 02:21:46 +00007561 ssize_t
7562 count,
7563 index;
7564
cristy3ed852e2009-09-05 21:47:34 +00007565 /*
7566 Apply options to the image list.
7567 */
7568 assert(image_info != (ImageInfo *) NULL);
7569 assert(image_info->signature == MagickSignature);
7570 assert(images != (Image **) NULL);
7571 assert((*images)->signature == MagickSignature);
7572 if ((*images)->debug != MagickFalse)
7573 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
7574 (*images)->filename);
7575 if ((argc <= 0) || (*argv == (char *) NULL))
7576 return(MagickTrue);
cristy6b3da3a2010-06-20 02:21:46 +00007577 mogrify_info=CloneImageInfo(image_info);
7578 quantize_info=AcquireQuantizeInfo(mogrify_info);
7579 channel=mogrify_info->channel;
cristy3ed852e2009-09-05 21:47:34 +00007580 status=MagickTrue;
cristybb503372010-05-27 20:51:26 +00007581 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00007582 {
cristy74fe8f12009-10-03 19:09:01 +00007583 if (*images == (Image *) NULL)
7584 break;
cristy3ed852e2009-09-05 21:47:34 +00007585 option=argv[i];
7586 if (IsMagickOption(option) == MagickFalse)
7587 continue;
7588 count=MagickMax(ParseMagickOption(MagickCommandOptions,MagickFalse,option),
7589 0L);
cristycee97112010-05-28 00:44:52 +00007590 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00007591 break;
cristy6b3da3a2010-06-20 02:21:46 +00007592 status=MogrifyImageInfo(mogrify_info,(int) count+1,argv+i,exception);
cristy3ed852e2009-09-05 21:47:34 +00007593 switch (*(option+1))
7594 {
7595 case 'a':
7596 {
7597 if (LocaleCompare("affinity",option+1) == 0)
7598 {
cristy6b3da3a2010-06-20 02:21:46 +00007599 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007600 if (*option == '+')
7601 {
7602 (void) RemapImages(quantize_info,*images,(Image *) NULL);
7603 InheritException(exception,&(*images)->exception);
7604 break;
7605 }
7606 i++;
7607 break;
7608 }
7609 if (LocaleCompare("append",option+1) == 0)
7610 {
7611 Image
7612 *append_image;
7613
cristy6b3da3a2010-06-20 02:21:46 +00007614 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007615 append_image=AppendImages(*images,*option == '-' ? MagickTrue :
7616 MagickFalse,exception);
7617 if (append_image == (Image *) NULL)
7618 {
7619 status=MagickFalse;
7620 break;
7621 }
7622 *images=DestroyImageList(*images);
7623 *images=append_image;
7624 break;
7625 }
7626 if (LocaleCompare("average",option+1) == 0)
7627 {
7628 Image
7629 *average_image;
7630
cristyd18ae7c2010-03-07 17:39:52 +00007631 /*
7632 Average an image sequence (deprecated).
7633 */
cristy6b3da3a2010-06-20 02:21:46 +00007634 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007635 average_image=EvaluateImages(*images,MeanEvaluateOperator,
7636 exception);
cristy3ed852e2009-09-05 21:47:34 +00007637 if (average_image == (Image *) NULL)
7638 {
7639 status=MagickFalse;
7640 break;
7641 }
7642 *images=DestroyImageList(*images);
7643 *images=average_image;
7644 break;
7645 }
7646 break;
7647 }
7648 case 'c':
7649 {
7650 if (LocaleCompare("channel",option+1) == 0)
7651 {
7652 if (*option == '+')
7653 {
7654 channel=DefaultChannels;
7655 break;
7656 }
7657 channel=(ChannelType) ParseChannelOption(argv[i+1]);
7658 break;
7659 }
7660 if (LocaleCompare("clut",option+1) == 0)
7661 {
7662 Image
7663 *clut_image,
7664 *image;
7665
cristy6b3da3a2010-06-20 02:21:46 +00007666 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007667 image=RemoveFirstImageFromList(images);
7668 clut_image=RemoveFirstImageFromList(images);
7669 if (clut_image == (Image *) NULL)
7670 {
7671 status=MagickFalse;
7672 break;
7673 }
7674 (void) ClutImageChannel(image,channel,clut_image);
7675 clut_image=DestroyImage(clut_image);
7676 InheritException(exception,&image->exception);
7677 *images=DestroyImageList(*images);
7678 *images=image;
7679 break;
7680 }
7681 if (LocaleCompare("coalesce",option+1) == 0)
7682 {
7683 Image
7684 *coalesce_image;
7685
cristy6b3da3a2010-06-20 02:21:46 +00007686 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007687 coalesce_image=CoalesceImages(*images,exception);
7688 if (coalesce_image == (Image *) NULL)
7689 {
7690 status=MagickFalse;
7691 break;
7692 }
7693 *images=DestroyImageList(*images);
7694 *images=coalesce_image;
7695 break;
7696 }
7697 if (LocaleCompare("combine",option+1) == 0)
7698 {
7699 Image
7700 *combine_image;
7701
cristy6b3da3a2010-06-20 02:21:46 +00007702 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007703 combine_image=CombineImages(*images,channel,exception);
7704 if (combine_image == (Image *) NULL)
7705 {
7706 status=MagickFalse;
7707 break;
7708 }
7709 *images=DestroyImageList(*images);
7710 *images=combine_image;
7711 break;
7712 }
7713 if (LocaleCompare("composite",option+1) == 0)
7714 {
7715 Image
7716 *mask_image,
7717 *composite_image,
7718 *image;
7719
7720 RectangleInfo
7721 geometry;
7722
cristy6b3da3a2010-06-20 02:21:46 +00007723 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007724 image=RemoveFirstImageFromList(images);
7725 composite_image=RemoveFirstImageFromList(images);
7726 if (composite_image == (Image *) NULL)
7727 {
7728 status=MagickFalse;
7729 break;
7730 }
7731 (void) TransformImage(&composite_image,(char *) NULL,
7732 composite_image->geometry);
7733 SetGeometry(composite_image,&geometry);
7734 (void) ParseAbsoluteGeometry(composite_image->geometry,&geometry);
7735 GravityAdjustGeometry(image->columns,image->rows,image->gravity,
7736 &geometry);
7737 mask_image=RemoveFirstImageFromList(images);
7738 if (mask_image != (Image *) NULL)
7739 {
7740 if ((image->compose == DisplaceCompositeOp) ||
7741 (image->compose == DistortCompositeOp))
7742 {
7743 /*
7744 Merge Y displacement into X displacement image.
7745 */
7746 (void) CompositeImage(composite_image,CopyGreenCompositeOp,
7747 mask_image,0,0);
7748 mask_image=DestroyImage(mask_image);
7749 }
7750 else
7751 {
7752 /*
7753 Set a blending mask for the composition.
7754 */
7755 image->mask=mask_image;
7756 (void) NegateImage(image->mask,MagickFalse);
7757 }
7758 }
7759 (void) CompositeImageChannel(image,channel,image->compose,
7760 composite_image,geometry.x,geometry.y);
7761 if (image->mask != (Image *) NULL)
7762 image->mask=DestroyImage(image->mask);
7763 composite_image=DestroyImage(composite_image);
7764 InheritException(exception,&image->exception);
7765 *images=DestroyImageList(*images);
7766 *images=image;
7767 break;
7768 }
7769 if (LocaleCompare("crop",option+1) == 0)
7770 {
7771 MagickStatusType
7772 flags;
7773
7774 RectangleInfo
7775 geometry;
7776
cristy6b3da3a2010-06-20 02:21:46 +00007777 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007778 flags=ParseGravityGeometry(*images,argv[i+1],&geometry,exception);
7779 if (((geometry.width == 0) && (geometry.height == 0)) ||
7780 ((flags & XValue) != 0) || ((flags & YValue) != 0))
7781 break;
7782 (void) TransformImages(images,argv[i+1],(char *) NULL);
7783 InheritException(exception,&(*images)->exception);
7784 break;
7785 }
7786 break;
7787 }
7788 case 'd':
7789 {
7790 if (LocaleCompare("deconstruct",option+1) == 0)
7791 {
7792 Image
7793 *deconstruct_image;
7794
cristy6b3da3a2010-06-20 02:21:46 +00007795 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007796 deconstruct_image=DeconstructImages(*images,exception);
7797 if (deconstruct_image == (Image *) NULL)
7798 {
7799 status=MagickFalse;
7800 break;
7801 }
7802 *images=DestroyImageList(*images);
7803 *images=deconstruct_image;
7804 break;
7805 }
7806 if (LocaleCompare("delete",option+1) == 0)
7807 {
7808 if (*option == '+')
7809 DeleteImages(images,"-1",exception);
7810 else
7811 DeleteImages(images,argv[i+1],exception);
7812 break;
7813 }
7814 if (LocaleCompare("dither",option+1) == 0)
7815 {
7816 if (*option == '+')
7817 {
7818 quantize_info->dither=MagickFalse;
7819 break;
7820 }
7821 quantize_info->dither=MagickTrue;
7822 quantize_info->dither_method=(DitherMethod) ParseMagickOption(
7823 MagickDitherOptions,MagickFalse,argv[i+1]);
7824 break;
7825 }
7826 break;
7827 }
cristyd18ae7c2010-03-07 17:39:52 +00007828 case 'e':
7829 {
7830 if (LocaleCompare("evaluate-sequence",option+1) == 0)
7831 {
7832 Image
7833 *evaluate_image;
7834
7835 MagickEvaluateOperator
7836 op;
7837
cristy6b3da3a2010-06-20 02:21:46 +00007838 (void) SyncImageSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007839 op=(MagickEvaluateOperator) ParseMagickOption(MagickEvaluateOptions,
7840 MagickFalse,argv[i+1]);
7841 evaluate_image=EvaluateImages(*images,op,exception);
7842 if (evaluate_image == (Image *) NULL)
7843 {
7844 status=MagickFalse;
7845 break;
7846 }
7847 *images=DestroyImageList(*images);
7848 *images=evaluate_image;
7849 break;
7850 }
7851 break;
7852 }
cristy3ed852e2009-09-05 21:47:34 +00007853 case 'f':
7854 {
cristyf0a247f2009-10-04 00:20:03 +00007855 if (LocaleCompare("fft",option+1) == 0)
7856 {
7857 Image
7858 *fourier_image;
7859
7860 /*
7861 Implements the discrete Fourier transform (DFT).
7862 */
cristy6b3da3a2010-06-20 02:21:46 +00007863 (void) SyncImageSettings(mogrify_info,*images);
cristyf0a247f2009-10-04 00:20:03 +00007864 fourier_image=ForwardFourierTransformImage(*images,*option == '-' ?
7865 MagickTrue : MagickFalse,exception);
7866 if (fourier_image == (Image *) NULL)
7867 break;
7868 *images=DestroyImage(*images);
7869 *images=fourier_image;
7870 break;
7871 }
cristy3ed852e2009-09-05 21:47:34 +00007872 if (LocaleCompare("flatten",option+1) == 0)
7873 {
7874 Image
7875 *flatten_image;
7876
cristy6b3da3a2010-06-20 02:21:46 +00007877 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007878 flatten_image=MergeImageLayers(*images,FlattenLayer,exception);
7879 if (flatten_image == (Image *) NULL)
7880 break;
7881 *images=DestroyImageList(*images);
7882 *images=flatten_image;
7883 break;
7884 }
7885 if (LocaleCompare("fx",option+1) == 0)
7886 {
7887 Image
7888 *fx_image;
7889
cristy6b3da3a2010-06-20 02:21:46 +00007890 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007891 fx_image=FxImageChannel(*images,channel,argv[i+1],exception);
7892 if (fx_image == (Image *) NULL)
7893 {
7894 status=MagickFalse;
7895 break;
7896 }
7897 *images=DestroyImageList(*images);
7898 *images=fx_image;
7899 break;
7900 }
7901 break;
7902 }
7903 case 'h':
7904 {
7905 if (LocaleCompare("hald-clut",option+1) == 0)
7906 {
7907 Image
7908 *hald_image,
7909 *image;
7910
cristy6b3da3a2010-06-20 02:21:46 +00007911 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007912 image=RemoveFirstImageFromList(images);
7913 hald_image=RemoveFirstImageFromList(images);
7914 if (hald_image == (Image *) NULL)
7915 {
7916 status=MagickFalse;
7917 break;
7918 }
7919 (void) HaldClutImageChannel(image,channel,hald_image);
7920 hald_image=DestroyImage(hald_image);
7921 InheritException(exception,&image->exception);
cristy0aff6ea2009-11-14 01:40:53 +00007922 if (*images != (Image *) NULL)
7923 *images=DestroyImageList(*images);
cristy3ed852e2009-09-05 21:47:34 +00007924 *images=image;
7925 break;
7926 }
7927 break;
7928 }
7929 case 'i':
7930 {
7931 if (LocaleCompare("ift",option+1) == 0)
7932 {
7933 Image
cristy8587f882009-11-13 20:28:49 +00007934 *fourier_image,
7935 *magnitude_image,
7936 *phase_image;
cristy3ed852e2009-09-05 21:47:34 +00007937
7938 /*
7939 Implements the inverse fourier discrete Fourier transform (DFT).
7940 */
cristy6b3da3a2010-06-20 02:21:46 +00007941 (void) SyncImagesSettings(mogrify_info,*images);
cristy8587f882009-11-13 20:28:49 +00007942 magnitude_image=RemoveFirstImageFromList(images);
7943 phase_image=RemoveFirstImageFromList(images);
7944 if (phase_image == (Image *) NULL)
7945 {
7946 status=MagickFalse;
7947 break;
7948 }
7949 fourier_image=InverseFourierTransformImage(magnitude_image,
7950 phase_image,*option == '-' ? MagickTrue : MagickFalse,exception);
cristy3ed852e2009-09-05 21:47:34 +00007951 if (fourier_image == (Image *) NULL)
7952 break;
cristy0aff6ea2009-11-14 01:40:53 +00007953 if (*images != (Image *) NULL)
7954 *images=DestroyImage(*images);
cristy3ed852e2009-09-05 21:47:34 +00007955 *images=fourier_image;
7956 break;
7957 }
7958 if (LocaleCompare("insert",option+1) == 0)
7959 {
7960 Image
7961 *p,
7962 *q;
7963
7964 index=0;
7965 if (*option != '+')
cristyf2f27272009-12-17 14:48:46 +00007966 index=StringToLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007967 p=RemoveLastImageFromList(images);
7968 if (p == (Image *) NULL)
7969 {
7970 (void) ThrowMagickException(exception,GetMagickModule(),
7971 OptionError,"NoSuchImage","`%s'",argv[i+1]);
7972 status=MagickFalse;
7973 break;
7974 }
7975 q=p;
7976 if (index == 0)
7977 PrependImageToList(images,q);
7978 else
cristybb503372010-05-27 20:51:26 +00007979 if (index == (ssize_t) GetImageListLength(*images))
cristy3ed852e2009-09-05 21:47:34 +00007980 AppendImageToList(images,q);
7981 else
7982 {
7983 q=GetImageFromList(*images,index-1);
7984 if (q == (Image *) NULL)
7985 {
7986 (void) ThrowMagickException(exception,GetMagickModule(),
7987 OptionError,"NoSuchImage","`%s'",argv[i+1]);
7988 status=MagickFalse;
7989 break;
7990 }
7991 InsertImageInList(&q,p);
7992 }
7993 *images=GetFirstImageInList(q);
7994 break;
7995 }
7996 break;
7997 }
7998 case 'l':
7999 {
8000 if (LocaleCompare("layers",option+1) == 0)
8001 {
8002 Image
8003 *layers;
8004
8005 ImageLayerMethod
8006 method;
8007
cristy6b3da3a2010-06-20 02:21:46 +00008008 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00008009 layers=(Image *) NULL;
8010 method=(ImageLayerMethod) ParseMagickOption(MagickLayerOptions,
8011 MagickFalse,argv[i+1]);
8012 switch (method)
8013 {
8014 case CoalesceLayer:
8015 {
8016 layers=CoalesceImages(*images,exception);
8017 break;
8018 }
8019 case CompareAnyLayer:
8020 case CompareClearLayer:
8021 case CompareOverlayLayer:
8022 default:
8023 {
8024 layers=CompareImageLayers(*images,method,exception);
8025 break;
8026 }
8027 case MergeLayer:
8028 case FlattenLayer:
8029 case MosaicLayer:
8030 case TrimBoundsLayer:
8031 {
8032 layers=MergeImageLayers(*images,method,exception);
8033 break;
8034 }
8035 case DisposeLayer:
8036 {
8037 layers=DisposeImages(*images,exception);
8038 break;
8039 }
8040 case OptimizeImageLayer:
8041 {
8042 layers=OptimizeImageLayers(*images,exception);
8043 break;
8044 }
8045 case OptimizePlusLayer:
8046 {
8047 layers=OptimizePlusImageLayers(*images,exception);
8048 break;
8049 }
8050 case OptimizeTransLayer:
8051 {
8052 OptimizeImageTransparency(*images,exception);
8053 break;
8054 }
8055 case RemoveDupsLayer:
8056 {
8057 RemoveDuplicateLayers(images,exception);
8058 break;
8059 }
8060 case RemoveZeroLayer:
8061 {
8062 RemoveZeroDelayLayers(images,exception);
8063 break;
8064 }
8065 case OptimizeLayer:
8066 {
8067 /*
8068 General Purpose, GIF Animation Optimizer.
8069 */
8070 layers=CoalesceImages(*images,exception);
8071 if (layers == (Image *) NULL)
8072 {
8073 status=MagickFalse;
8074 break;
8075 }
8076 InheritException(exception,&layers->exception);
8077 *images=DestroyImageList(*images);
8078 *images=layers;
8079 layers=OptimizeImageLayers(*images,exception);
8080 if (layers == (Image *) NULL)
8081 {
8082 status=MagickFalse;
8083 break;
8084 }
8085 InheritException(exception,&layers->exception);
8086 *images=DestroyImageList(*images);
8087 *images=layers;
8088 layers=(Image *) NULL;
8089 OptimizeImageTransparency(*images,exception);
8090 InheritException(exception,&(*images)->exception);
8091 (void) RemapImages(quantize_info,*images,(Image *) NULL);
8092 break;
8093 }
8094 case CompositeLayer:
8095 {
8096 CompositeOperator
8097 compose;
8098
8099 Image
8100 *source;
8101
8102 RectangleInfo
8103 geometry;
8104
8105 /*
8106 Split image sequence at the first 'NULL:' image.
8107 */
8108 source=(*images);
8109 while (source != (Image *) NULL)
8110 {
8111 source=GetNextImageInList(source);
8112 if ((source != (Image *) NULL) &&
8113 (LocaleCompare(source->magick,"NULL") == 0))
8114 break;
8115 }
8116 if (source != (Image *) NULL)
8117 {
8118 if ((GetPreviousImageInList(source) == (Image *) NULL) ||
8119 (GetNextImageInList(source) == (Image *) NULL))
8120 source=(Image *) NULL;
8121 else
8122 {
8123 /*
8124 Separate the two lists, junk the null: image.
8125 */
8126 source=SplitImageList(source->previous);
8127 DeleteImageFromList(&source);
8128 }
8129 }
8130 if (source == (Image *) NULL)
8131 {
8132 (void) ThrowMagickException(exception,GetMagickModule(),
8133 OptionError,"MissingNullSeparator","layers Composite");
8134 status=MagickFalse;
8135 break;
8136 }
8137 /*
8138 Adjust offset with gravity and virtual canvas.
8139 */
8140 SetGeometry(*images,&geometry);
8141 (void) ParseAbsoluteGeometry((*images)->geometry,&geometry);
8142 geometry.width=source->page.width != 0 ?
8143 source->page.width : source->columns;
8144 geometry.height=source->page.height != 0 ?
8145 source->page.height : source->rows;
8146 GravityAdjustGeometry((*images)->page.width != 0 ?
8147 (*images)->page.width : (*images)->columns,
8148 (*images)->page.height != 0 ? (*images)->page.height :
8149 (*images)->rows,(*images)->gravity,&geometry);
8150 compose=OverCompositeOp;
cristy6b3da3a2010-06-20 02:21:46 +00008151 option=GetImageOption(mogrify_info,"compose");
cristy3ed852e2009-09-05 21:47:34 +00008152 if (option != (const char *) NULL)
8153 compose=(CompositeOperator) ParseMagickOption(
8154 MagickComposeOptions,MagickFalse,option);
8155 CompositeLayers(*images,compose,source,geometry.x,geometry.y,
8156 exception);
8157 source=DestroyImageList(source);
8158 break;
8159 }
8160 }
8161 if (layers == (Image *) NULL)
8162 break;
8163 InheritException(exception,&layers->exception);
8164 *images=DestroyImageList(*images);
8165 *images=layers;
8166 break;
8167 }
8168 break;
8169 }
8170 case 'm':
8171 {
8172 if (LocaleCompare("map",option+1) == 0)
8173 {
cristy6b3da3a2010-06-20 02:21:46 +00008174 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00008175 if (*option == '+')
8176 {
8177 (void) RemapImages(quantize_info,*images,(Image *) NULL);
8178 InheritException(exception,&(*images)->exception);
8179 break;
8180 }
8181 i++;
8182 break;
8183 }
cristyf40785b2010-03-06 02:27:27 +00008184 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00008185 {
8186 Image
cristyf40785b2010-03-06 02:27:27 +00008187 *maximum_image;
cristy1c274c92010-03-06 02:06:45 +00008188
cristyd18ae7c2010-03-07 17:39:52 +00008189 /*
8190 Maximum image sequence (deprecated).
8191 */
cristy6b3da3a2010-06-20 02:21:46 +00008192 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00008193 maximum_image=EvaluateImages(*images,MaxEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00008194 if (maximum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00008195 {
8196 status=MagickFalse;
8197 break;
8198 }
8199 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00008200 *images=maximum_image;
cristy1c274c92010-03-06 02:06:45 +00008201 break;
8202 }
cristyf40785b2010-03-06 02:27:27 +00008203 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00008204 {
8205 Image
cristyf40785b2010-03-06 02:27:27 +00008206 *minimum_image;
cristy1c274c92010-03-06 02:06:45 +00008207
cristyd18ae7c2010-03-07 17:39:52 +00008208 /*
8209 Minimum image sequence (deprecated).
8210 */
cristy6b3da3a2010-06-20 02:21:46 +00008211 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00008212 minimum_image=EvaluateImages(*images,MinEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00008213 if (minimum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00008214 {
8215 status=MagickFalse;
8216 break;
8217 }
8218 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00008219 *images=minimum_image;
cristy1c274c92010-03-06 02:06:45 +00008220 break;
8221 }
cristy3ed852e2009-09-05 21:47:34 +00008222 if (LocaleCompare("morph",option+1) == 0)
8223 {
8224 Image
8225 *morph_image;
8226
cristy6b3da3a2010-06-20 02:21:46 +00008227 (void) SyncImagesSettings(mogrify_info,*images);
cristye27293e2009-12-18 02:53:20 +00008228 morph_image=MorphImages(*images,StringToUnsignedLong(argv[i+1]),
cristy3ed852e2009-09-05 21:47:34 +00008229 exception);
8230 if (morph_image == (Image *) NULL)
8231 {
8232 status=MagickFalse;
8233 break;
8234 }
8235 *images=DestroyImageList(*images);
8236 *images=morph_image;
8237 break;
8238 }
8239 if (LocaleCompare("mosaic",option+1) == 0)
8240 {
8241 Image
8242 *mosaic_image;
8243
cristy6b3da3a2010-06-20 02:21:46 +00008244 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00008245 mosaic_image=MergeImageLayers(*images,MosaicLayer,exception);
8246 if (mosaic_image == (Image *) NULL)
8247 {
8248 status=MagickFalse;
8249 break;
8250 }
8251 *images=DestroyImageList(*images);
8252 *images=mosaic_image;
8253 break;
8254 }
8255 break;
8256 }
8257 case 'p':
8258 {
8259 if (LocaleCompare("print",option+1) == 0)
8260 {
8261 char
8262 *string;
8263
cristy6b3da3a2010-06-20 02:21:46 +00008264 (void) SyncImagesSettings(mogrify_info,*images);
8265 string=InterpretImageProperties(mogrify_info,*images,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00008266 if (string == (char *) NULL)
8267 break;
8268 InheritException(exception,&(*images)->exception);
8269 (void) fprintf(stdout,"%s",string);
8270 string=DestroyString(string);
8271 }
8272 if (LocaleCompare("process",option+1) == 0)
8273 {
8274 char
8275 **arguments;
8276
8277 int
8278 j,
8279 number_arguments;
8280
cristy6b3da3a2010-06-20 02:21:46 +00008281 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00008282 arguments=StringToArgv(argv[i+1],&number_arguments);
8283 if (arguments == (char **) NULL)
8284 break;
8285 if ((argc > 1) && (strchr(arguments[1],'=') != (char *) NULL))
8286 {
8287 char
8288 breaker,
8289 quote,
8290 *token;
8291
8292 const char
8293 *arguments;
8294
8295 int
8296 next,
8297 status;
8298
8299 size_t
8300 length;
8301
8302 TokenInfo
8303 *token_info;
8304
8305 /*
8306 Support old style syntax, filter="-option arg".
8307 */
8308 length=strlen(argv[i+1]);
8309 token=(char *) NULL;
8310 if (~length >= MaxTextExtent)
8311 token=(char *) AcquireQuantumMemory(length+MaxTextExtent,
8312 sizeof(*token));
8313 if (token == (char *) NULL)
8314 break;
8315 next=0;
8316 arguments=argv[i+1];
8317 token_info=AcquireTokenInfo();
8318 status=Tokenizer(token_info,0,token,length,arguments,"","=",
8319 "\"",'\0',&breaker,&next,&quote);
8320 token_info=DestroyTokenInfo(token_info);
8321 if (status == 0)
8322 {
8323 const char
8324 *argv;
8325
8326 argv=(&(arguments[next]));
8327 (void) InvokeDynamicImageFilter(token,&(*images),1,&argv,
8328 exception);
8329 }
8330 token=DestroyString(token);
8331 break;
8332 }
cristy91c0da22010-05-02 01:44:07 +00008333 (void) SubstituteString(&arguments[1],"-","");
cristy3ed852e2009-09-05 21:47:34 +00008334 (void) InvokeDynamicImageFilter(arguments[1],&(*images),
8335 number_arguments-2,(const char **) arguments+2,exception);
8336 for (j=0; j < number_arguments; j++)
8337 arguments[j]=DestroyString(arguments[j]);
8338 arguments=(char **) RelinquishMagickMemory(arguments);
8339 break;
8340 }
8341 break;
8342 }
8343 case 'r':
8344 {
8345 if (LocaleCompare("reverse",option+1) == 0)
8346 {
8347 ReverseImageList(images);
8348 InheritException(exception,&(*images)->exception);
8349 break;
8350 }
8351 break;
8352 }
8353 case 's':
8354 {
8355 if (LocaleCompare("swap",option+1) == 0)
8356 {
8357 Image
8358 *p,
8359 *q,
8360 *swap;
8361
cristybb503372010-05-27 20:51:26 +00008362 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00008363 swap_index;
8364
8365 index=(-1);
8366 swap_index=(-2);
8367 if (*option != '+')
8368 {
8369 GeometryInfo
8370 geometry_info;
8371
8372 MagickStatusType
8373 flags;
8374
8375 swap_index=(-1);
8376 flags=ParseGeometry(argv[i+1],&geometry_info);
cristybb503372010-05-27 20:51:26 +00008377 index=(ssize_t) geometry_info.rho;
cristy3ed852e2009-09-05 21:47:34 +00008378 if ((flags & SigmaValue) != 0)
cristybb503372010-05-27 20:51:26 +00008379 swap_index=(ssize_t) geometry_info.sigma;
cristy3ed852e2009-09-05 21:47:34 +00008380 }
8381 p=GetImageFromList(*images,index);
8382 q=GetImageFromList(*images,swap_index);
8383 if ((p == (Image *) NULL) || (q == (Image *) NULL))
8384 {
8385 (void) ThrowMagickException(exception,GetMagickModule(),
8386 OptionError,"NoSuchImage","`%s'",(*images)->filename);
8387 status=MagickFalse;
8388 break;
8389 }
8390 if (p == q)
8391 break;
8392 swap=CloneImage(p,0,0,MagickTrue,exception);
8393 ReplaceImageInList(&p,CloneImage(q,0,0,MagickTrue,exception));
8394 ReplaceImageInList(&q,swap);
8395 *images=GetFirstImageInList(q);
8396 break;
8397 }
8398 break;
8399 }
8400 case 'w':
8401 {
8402 if (LocaleCompare("write",option+1) == 0)
8403 {
cristy071dd7b2010-04-09 13:04:54 +00008404 char
cristy06609ee2010-03-17 20:21:27 +00008405 key[MaxTextExtent];
8406
cristy3ed852e2009-09-05 21:47:34 +00008407 Image
8408 *write_images;
8409
8410 ImageInfo
8411 *write_info;
8412
cristy6b3da3a2010-06-20 02:21:46 +00008413 (void) SyncImagesSettings(mogrify_info,*images);
cristy06609ee2010-03-17 20:21:27 +00008414 (void) FormatMagickString(key,MaxTextExtent,"cache:%s",argv[i+1]);
8415 (void) DeleteImageRegistry(key);
cristy3ed852e2009-09-05 21:47:34 +00008416 write_images=(*images);
8417 if (*option == '+')
8418 write_images=CloneImageList(*images,exception);
cristy6b3da3a2010-06-20 02:21:46 +00008419 write_info=CloneImageInfo(mogrify_info);
cristy3ed852e2009-09-05 21:47:34 +00008420 status&=WriteImages(write_info,write_images,argv[i+1],exception);
8421 write_info=DestroyImageInfo(write_info);
8422 if (*option == '+')
8423 write_images=DestroyImageList(write_images);
8424 break;
8425 }
8426 break;
8427 }
8428 default:
8429 break;
8430 }
8431 i+=count;
8432 }
8433 quantize_info=DestroyQuantizeInfo(quantize_info);
cristy6b3da3a2010-06-20 02:21:46 +00008434 mogrify_info=DestroyImageInfo(mogrify_info);
8435 status&=MogrifyImageInfo(image_info,argc,argv,exception);
cristy3ed852e2009-09-05 21:47:34 +00008436 return(status != 0 ? MagickTrue : MagickFalse);
8437}
8438
8439/*
8440%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8441% %
8442% %
8443% %
8444+ M o g r i f y I m a g e s %
8445% %
8446% %
8447% %
8448%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8449%
8450% MogrifyImages() applies image processing options to a sequence of images as
8451% prescribed by command line options.
8452%
8453% The format of the MogrifyImage method is:
8454%
8455% MagickBooleanType MogrifyImages(ImageInfo *image_info,
8456% const MagickBooleanType post,const int argc,const char **argv,
8457% Image **images,Exceptioninfo *exception)
8458%
8459% A description of each parameter follows:
8460%
8461% o image_info: the image info..
8462%
8463% o post: If true, post process image list operators otherwise pre-process.
8464%
8465% o argc: Specifies a pointer to an integer describing the number of
8466% elements in the argument vector.
8467%
8468% o argv: Specifies a pointer to a text array containing the command line
8469% arguments.
8470%
8471% o images: the images.
8472%
8473% o exception: return any errors or warnings in this structure.
8474%
8475*/
8476WandExport MagickBooleanType MogrifyImages(ImageInfo *image_info,
8477 const MagickBooleanType post,const int argc,const char **argv,
8478 Image **images,ExceptionInfo *exception)
8479{
8480#define MogrifyImageTag "Mogrify/Image"
8481
8482 Image
8483 *image,
8484 *mogrify_images;
8485
cristy0e9f9c12010-02-11 03:00:47 +00008486 MagickBooleanType
8487 proceed;
8488
8489 MagickSizeType
8490 number_images;
8491
cristy3ed852e2009-09-05 21:47:34 +00008492 MagickStatusType
8493 status;
8494
cristybb503372010-05-27 20:51:26 +00008495 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00008496 i;
8497
cristy3ed852e2009-09-05 21:47:34 +00008498 /*
8499 Apply options to individual images in the list.
8500 */
8501 assert(image_info != (ImageInfo *) NULL);
8502 assert(image_info->signature == MagickSignature);
8503 if (images == (Image **) NULL)
8504 return(MogrifyImage(image_info,argc,argv,images,exception));
8505 assert((*images)->signature == MagickSignature);
8506 if ((*images)->debug != MagickFalse)
8507 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
8508 (*images)->filename);
8509 if ((argc <= 0) || (*argv == (char *) NULL))
8510 return(MagickTrue);
8511 (void) SetImageInfoProgressMonitor(image_info,(MagickProgressMonitor) NULL,
8512 (void *) NULL);
8513 mogrify_images=NewImageList();
8514 number_images=GetImageListLength(*images);
8515 status=0;
8516 if (post == MagickFalse)
8517 status&=MogrifyImageList(image_info,argc,argv,images,exception);
cristybb503372010-05-27 20:51:26 +00008518 for (i=0; i < (ssize_t) number_images; i++)
cristy3ed852e2009-09-05 21:47:34 +00008519 {
8520 image=RemoveFirstImageFromList(images);
8521 if (image == (Image *) NULL)
8522 continue;
8523 status&=MogrifyImage(image_info,argc,argv,&image,exception);
8524 AppendImageToList(&mogrify_images,image);
cristy0e9f9c12010-02-11 03:00:47 +00008525 proceed=SetImageProgress(image,MogrifyImageTag,(MagickOffsetType) i,
8526 number_images);
8527 if (proceed == MagickFalse)
8528 break;
cristy3ed852e2009-09-05 21:47:34 +00008529 }
8530 if (post != MagickFalse)
8531 status&=MogrifyImageList(image_info,argc,argv,&mogrify_images,exception);
8532 *images=mogrify_images;
8533 return(status != 0 ? MagickTrue : MagickFalse);
8534}