blob: aab7c82d41d2051a1d18c4291095da1f028487bd [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)
cristyceae09d2009-10-28 17:18:47 +0000199 # pragma omp critical (MagickCore_Launch_Command)
200#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,
cristye7f51092010-01-17 00:39:37 +0000223 "Performance: %lui %gips %0.3fu %ld:%02ld.%03ld\n",
cristycee97112010-05-28 00:44:52 +0000224 iterations,1.0*iterations/elapsed_time,user_time,(long)
225 (elapsed_time/60.0),(long) floor(fmod(elapsed_time,60.0)),
226 (long) (1000.0*(elapsed_time-floor(elapsed_time))));
cristy3980b0d2009-10-25 14:37:13 +0000227 }
228 timer=DestroyTimerInfo(timer);
cristy1f9e1ed2009-11-18 04:09:38 +0000229 return(status);
cristy3980b0d2009-10-25 14:37:13 +0000230}
231
232/*
233%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
234% %
235% %
236% %
cristy3ed852e2009-09-05 21:47:34 +0000237+ M o g r i f y I m a g e %
238% %
239% %
240% %
241%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
242%
243% MogrifyImage() applies image processing options to an image as prescribed
244% by command line options.
245%
246% The format of the MogrifyImage method is:
247%
248% MagickBooleanType MogrifyImage(ImageInfo *image_info,const int argc,
249% const char **argv,Image **image)
250%
251% A description of each parameter follows:
252%
253% o image_info: the image info..
254%
255% o argc: Specifies a pointer to an integer describing the number of
256% elements in the argument vector.
257%
258% o argv: Specifies a pointer to a text array containing the command line
259% arguments.
260%
261% o image: the image.
262%
263% o exception: return any errors or warnings in this structure.
264%
265*/
266
267static inline Image *GetImageCache(const ImageInfo *image_info,const char *path,
268 ExceptionInfo *exception)
269{
270 char
271 key[MaxTextExtent];
272
273 ExceptionInfo
274 *sans_exception;
275
276 Image
277 *image;
278
279 ImageInfo
280 *read_info;
281
282 (void) FormatMagickString(key,MaxTextExtent,"cache:%s",path);
283 sans_exception=AcquireExceptionInfo();
284 image=(Image *) GetImageRegistry(ImageRegistryType,key,sans_exception);
285 sans_exception=DestroyExceptionInfo(sans_exception);
286 if (image != (Image *) NULL)
287 return(image);
288 read_info=CloneImageInfo(image_info);
289 (void) CopyMagickString(read_info->filename,path,MaxTextExtent);
290 image=ReadImage(read_info,exception);
291 read_info=DestroyImageInfo(read_info);
292 if (image != (Image *) NULL)
293 (void) SetImageRegistry(ImageRegistryType,key,image,exception);
294 return(image);
295}
296
cristy3ed852e2009-09-05 21:47:34 +0000297static MagickBooleanType IsPathWritable(const char *path)
298{
299 if (IsPathAccessible(path) == MagickFalse)
300 return(MagickFalse);
301 if (access(path,W_OK) != 0)
302 return(MagickFalse);
303 return(MagickTrue);
304}
305
cristybb503372010-05-27 20:51:26 +0000306static inline ssize_t MagickMax(const ssize_t x,const ssize_t y)
cristy3ed852e2009-09-05 21:47:34 +0000307{
308 if (x > y)
309 return(x);
310 return(y);
311}
312
313static MagickBooleanType MonitorProgress(const char *text,
cristyb32b90a2009-09-07 21:45:48 +0000314 const MagickOffsetType offset,const MagickSizeType extent,
cristy3ed852e2009-09-05 21:47:34 +0000315 void *wand_unused(client_data))
316{
317 char
318 message[MaxTextExtent],
319 tag[MaxTextExtent];
320
321 const char
322 *locale_message;
323
324 register char
325 *p;
326
cristyb32b90a2009-09-07 21:45:48 +0000327 if (extent < 2)
cristy3ed852e2009-09-05 21:47:34 +0000328 return(MagickTrue);
329 (void) CopyMagickMemory(tag,text,MaxTextExtent);
330 p=strrchr(tag,'/');
331 if (p != (char *) NULL)
332 *p='\0';
333 (void) FormatMagickString(message,MaxTextExtent,"Monitor/%s",tag);
334 locale_message=GetLocaleMessage(message);
335 if (locale_message == message)
336 locale_message=tag;
337 if (p == (char *) NULL)
cristyb32b90a2009-09-07 21:45:48 +0000338 (void) fprintf(stderr,"%s: %ld of %lu, %02ld%% complete\r",locale_message,
cristycee97112010-05-28 00:44:52 +0000339 (long) offset,(size_t) extent,(long) (100L*offset/(extent-1)));
cristy3ed852e2009-09-05 21:47:34 +0000340 else
cristyb32b90a2009-09-07 21:45:48 +0000341 (void) fprintf(stderr,"%s[%s]: %ld of %lu, %02ld%% complete\r",
cristycee97112010-05-28 00:44:52 +0000342 locale_message,p+1,(long) offset,(size_t) extent,(long)
cristyb32b90a2009-09-07 21:45:48 +0000343 (100L*offset/(extent-1)));
344 if (offset == (MagickOffsetType) (extent-1))
cristy3ed852e2009-09-05 21:47:34 +0000345 (void) fprintf(stderr,"\n");
346 (void) fflush(stderr);
347 return(MagickTrue);
348}
349
350static Image *SparseColorOption(const Image *image,const ChannelType channel,
351 const SparseColorMethod method,const char *arguments,
352 const MagickBooleanType color_from_image,ExceptionInfo *exception)
353{
354 ChannelType
355 channels;
356
357 char
358 token[MaxTextExtent];
359
360 const char
361 *p;
362
363 double
364 *sparse_arguments;
365
cristybb503372010-05-27 20:51:26 +0000366 register size_t
cristy3ed852e2009-09-05 21:47:34 +0000367 x;
368
cristybb503372010-05-27 20:51:26 +0000369 size_t
cristy3ed852e2009-09-05 21:47:34 +0000370 number_arguments;
371
cristybb503372010-05-27 20:51:26 +0000372 size_t
cristy3ed852e2009-09-05 21:47:34 +0000373 number_colors;
374
375 Image
376 *sparse_image;
377
378 MagickPixelPacket
379 color;
380
381 MagickBooleanType
382 error;
383
384 assert(image != (Image *) NULL);
385 assert(image->signature == MagickSignature);
386 if (image->debug != MagickFalse)
387 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
388 assert(exception != (ExceptionInfo *) NULL);
389 assert(exception->signature == MagickSignature);
390 /*
391 Limit channels according to image - and add up number of color channel.
392 */
393 channels=channel;
394 if (image->colorspace != CMYKColorspace)
395 channels=(ChannelType) (channels & ~IndexChannel); /* no index channel */
396 if (image->matte == MagickFalse)
397 channels=(ChannelType) (channels & ~OpacityChannel); /* no alpha channel */
398 number_colors=0;
399 if ((channels & RedChannel) != 0)
400 number_colors++;
401 if ((channels & GreenChannel) != 0)
402 number_colors++;
403 if ((channels & BlueChannel) != 0)
404 number_colors++;
405 if ((channels & IndexChannel) != 0)
406 number_colors++;
407 if ((channels & OpacityChannel) != 0)
408 number_colors++;
409 /*
410 Read string, to determine number of arguments needed,
411 */
412 p=arguments;
413 x=0;
414 while( *p != '\0' )
415 {
416 GetMagickToken(p,&p,token);
417 if ( token[0] == ',' ) continue;
418 if ( isalpha((int) token[0]) || token[0] == '#' ) {
419 if ( color_from_image ) {
420 (void) ThrowMagickException(exception,GetMagickModule(),
421 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
422 "Color arg given, when colors are coming from image");
423 return( (Image *)NULL);
424 }
425 x += number_colors; /* color argument */
426 }
427 else {
428 x++; /* floating point argument */
429 }
430 }
431 error=MagickTrue;
432 if ( color_from_image ) {
433 /* just the control points are being given */
434 error = ( x % 2 != 0 ) ? MagickTrue : MagickFalse;
435 number_arguments=(x/2)*(2+number_colors);
436 }
437 else {
438 /* control points and color values */
439 error = ( x % (2+number_colors) != 0 ) ? MagickTrue : MagickFalse;
440 number_arguments=x;
441 }
442 if ( error ) {
443 (void) ThrowMagickException(exception,GetMagickModule(),
444 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
445 "Invalid number of Arguments");
446 return( (Image *)NULL);
447 }
448
449 /* Allocate and fill in the floating point arguments */
450 sparse_arguments=(double *) AcquireQuantumMemory(number_arguments,
451 sizeof(*sparse_arguments));
452 if (sparse_arguments == (double *) NULL) {
453 (void) ThrowMagickException(exception,GetMagickModule(),ResourceLimitError,
454 "MemoryAllocationFailed","%s","SparseColorOption");
455 return( (Image *)NULL);
456 }
457 (void) ResetMagickMemory(sparse_arguments,0,number_arguments*
458 sizeof(*sparse_arguments));
459 p=arguments;
460 x=0;
461 while( *p != '\0' && x < number_arguments ) {
462 /* X coordinate */
463 token[0]=','; while ( token[0] == ',' ) GetMagickToken(p,&p,token);
464 if ( token[0] == '\0' ) break;
465 if ( isalpha((int) token[0]) || token[0] == '#' ) {
466 (void) ThrowMagickException(exception,GetMagickModule(),
467 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
468 "Color found, instead of X-coord");
469 error = MagickTrue;
470 break;
471 }
cristyf2f27272009-12-17 14:48:46 +0000472 sparse_arguments[x++]=StringToDouble(token);
cristy3ed852e2009-09-05 21:47:34 +0000473 /* Y coordinate */
474 token[0]=','; while ( token[0] == ',' ) GetMagickToken(p,&p,token);
475 if ( token[0] == '\0' ) break;
476 if ( isalpha((int) token[0]) || token[0] == '#' ) {
477 (void) ThrowMagickException(exception,GetMagickModule(),
478 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
479 "Color found, instead of Y-coord");
480 error = MagickTrue;
481 break;
482 }
cristyf2f27272009-12-17 14:48:46 +0000483 sparse_arguments[x++]=StringToDouble(token);
cristy3ed852e2009-09-05 21:47:34 +0000484 /* color values for this control point */
485#if 0
486 if ( (color_from_image ) {
487 /* get color from image */
488 /* HOW??? */
489 }
490 else
491#endif
492 {
493 /* color name or function given in string argument */
494 token[0]=','; while ( token[0] == ',' ) GetMagickToken(p,&p,token);
495 if ( token[0] == '\0' ) break;
496 if ( isalpha((int) token[0]) || token[0] == '#' ) {
497 /* Color string given */
498 (void) QueryMagickColor(token,&color,exception);
499 if ( channels & RedChannel )
500 sparse_arguments[x++] = QuantumScale*color.red;
501 if ( channels & GreenChannel )
502 sparse_arguments[x++] = QuantumScale*color.green;
503 if ( channels & BlueChannel )
504 sparse_arguments[x++] = QuantumScale*color.blue;
505 if ( channels & IndexChannel )
506 sparse_arguments[x++] = QuantumScale*color.index;
507 if ( channels & OpacityChannel )
508 sparse_arguments[x++] = QuantumScale*color.opacity;
509 }
510 else {
511#if 0
512 /* the color name/function/value was not found - error */
513 break;
514#else
515 /* Colors given as a set of floating point values - experimental */
516 /* NB: token contains the first floating point value to use! */
517 if ( channels & RedChannel ) {
518 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
519 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
520 break;
cristy0f19e682009-12-17 14:55:51 +0000521 sparse_arguments[x++]=StringToDouble(token);
cristy3ed852e2009-09-05 21:47:34 +0000522 token[0] = ','; /* used this token - get another */
523 }
524 if ( channels & GreenChannel ) {
525 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
526 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
527 break;
cristy0f19e682009-12-17 14:55:51 +0000528 sparse_arguments[x++]=StringToDouble(token);
cristy3ed852e2009-09-05 21:47:34 +0000529 token[0] = ','; /* used this token - get another */
530 }
531 if ( channels & BlueChannel ) {
532 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
533 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
534 break;
cristy0f19e682009-12-17 14:55:51 +0000535 sparse_arguments[x++]=StringToDouble(token);
cristy3ed852e2009-09-05 21:47:34 +0000536 token[0] = ','; /* used this token - get another */
537 }
538 if ( channels & IndexChannel ) {
539 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
540 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
541 break;
cristy0f19e682009-12-17 14:55:51 +0000542 sparse_arguments[x++]=StringToDouble(token);
cristy3ed852e2009-09-05 21:47:34 +0000543 token[0] = ','; /* used this token - get another */
544 }
545 if ( channels & OpacityChannel ) {
546 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
547 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
548 break;
cristy0f19e682009-12-17 14:55:51 +0000549 sparse_arguments[x++]=StringToDouble(token);
cristy3ed852e2009-09-05 21:47:34 +0000550 token[0] = ','; /* used this token - get another */
551 }
552#endif
553 }
554 }
555 }
556 if ( number_arguments != x && !error ) {
557 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
558 "InvalidArgument","`%s': %s","sparse-color","Argument Parsing Error");
559 sparse_arguments=(double *) RelinquishMagickMemory(sparse_arguments);
560 return( (Image *)NULL);
561 }
562 if ( error )
563 return( (Image *)NULL);
564
565 /* Call the Interpolation function with the parsed arguments */
566 sparse_image=SparseColorImage(image,channels,method,number_arguments,
567 sparse_arguments,exception);
568 sparse_arguments=(double *) RelinquishMagickMemory(sparse_arguments);
569 return( sparse_image );
570}
571
572WandExport MagickBooleanType MogrifyImage(ImageInfo *image_info,const int argc,
573 const char **argv,Image **image,ExceptionInfo *exception)
574{
575 ChannelType
576 channel;
577
578 const char
579 *format,
580 *option;
581
582 DrawInfo
583 *draw_info;
584
585 GeometryInfo
586 geometry_info;
587
588 Image
589 *region_image;
590
cristybb503372010-05-27 20:51:26 +0000591 ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000592 count;
593
594 MagickBooleanType
595 status;
596
597 MagickPixelPacket
598 fill;
599
600 MagickStatusType
601 flags;
602
603 QuantizeInfo
604 *quantize_info;
605
606 RectangleInfo
607 geometry,
608 region_geometry;
609
cristybb503372010-05-27 20:51:26 +0000610 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000611 i;
612
613 /*
614 Initialize method variables.
615 */
616 assert(image_info != (const ImageInfo *) NULL);
617 assert(image_info->signature == MagickSignature);
618 assert(image != (Image **) NULL);
619 assert((*image)->signature == MagickSignature);
620 if ((*image)->debug != MagickFalse)
621 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",(*image)->filename);
622 if (argc < 0)
623 return(MagickTrue);
624 draw_info=CloneDrawInfo(image_info,(DrawInfo *) NULL);
625 quantize_info=AcquireQuantizeInfo(image_info);
626 SetGeometryInfo(&geometry_info);
627 GetMagickPixelPacket(*image,&fill);
628 SetMagickPixelPacket(*image,&(*image)->background_color,(IndexPacket *) NULL,
629 &fill);
630 channel=image_info->channel;
631 format=GetImageOption(image_info,"format");
632 SetGeometry(*image,&region_geometry);
633 region_image=NewImageList();
634 /*
635 Transmogrify the image.
636 */
cristybb503372010-05-27 20:51:26 +0000637 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +0000638 {
639 option=argv[i];
640 if (IsMagickOption(option) == MagickFalse)
641 continue;
642 count=MagickMax(ParseMagickOption(MagickCommandOptions,MagickFalse,option),
643 0L);
cristycee97112010-05-28 00:44:52 +0000644 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +0000645 break;
cristycee97112010-05-28 00:44:52 +0000646 status=MogrifyImageInfo(image_info,(int) count+1,argv+i,exception);
cristy3ed852e2009-09-05 21:47:34 +0000647 switch (*(option+1))
648 {
649 case 'a':
650 {
651 if (LocaleCompare("adaptive-blur",option+1) == 0)
652 {
653 Image
654 *blur_image;
655
656 /*
657 Adaptive blur image.
658 */
659 (void) SyncImageSettings(image_info,*image);
660 flags=ParseGeometry(argv[i+1],&geometry_info);
661 if ((flags & SigmaValue) == 0)
662 geometry_info.sigma=1.0;
663 blur_image=AdaptiveBlurImageChannel(*image,channel,
664 geometry_info.rho,geometry_info.sigma,exception);
665 if (blur_image == (Image *) NULL)
666 break;
667 *image=DestroyImage(*image);
668 *image=blur_image;
669 break;
670 }
671 if (LocaleCompare("adaptive-resize",option+1) == 0)
672 {
673 Image
674 *resize_image;
675
676 /*
677 Adaptive resize image.
678 */
679 (void) SyncImageSettings(image_info,*image);
680 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
681 resize_image=AdaptiveResizeImage(*image,geometry.width,
682 geometry.height,exception);
683 if (resize_image == (Image *) NULL)
684 break;
685 *image=DestroyImage(*image);
686 *image=resize_image;
687 break;
688 }
689 if (LocaleCompare("adaptive-sharpen",option+1) == 0)
690 {
691 Image
692 *sharp_image;
693
694 /*
695 Adaptive sharpen image.
696 */
697 (void) SyncImageSettings(image_info,*image);
698 flags=ParseGeometry(argv[i+1],&geometry_info);
699 if ((flags & SigmaValue) == 0)
700 geometry_info.sigma=1.0;
701 sharp_image=AdaptiveSharpenImageChannel(*image,channel,
702 geometry_info.rho,geometry_info.sigma,exception);
703 if (sharp_image == (Image *) NULL)
704 break;
705 *image=DestroyImage(*image);
706 *image=sharp_image;
707 break;
708 }
709 if (LocaleCompare("affine",option+1) == 0)
710 {
711 /*
712 Affine matrix.
713 */
714 if (*option == '+')
715 {
716 GetAffineMatrix(&draw_info->affine);
717 break;
718 }
719 (void) ParseAffineGeometry(argv[i+1],&draw_info->affine,exception);
720 break;
721 }
722 if (LocaleCompare("alpha",option+1) == 0)
723 {
724 AlphaChannelType
725 alpha_type;
726
727 (void) SyncImageSettings(image_info,*image);
728 alpha_type=(AlphaChannelType) ParseMagickOption(MagickAlphaOptions,
729 MagickFalse,argv[i+1]);
730 (void) SetImageAlphaChannel(*image,alpha_type);
731 InheritException(exception,&(*image)->exception);
732 break;
733 }
734 if (LocaleCompare("annotate",option+1) == 0)
735 {
736 char
737 *text,
738 geometry[MaxTextExtent];
739
740 /*
741 Annotate image.
742 */
743 (void) SyncImageSettings(image_info,*image);
744 SetGeometryInfo(&geometry_info);
745 flags=ParseGeometry(argv[i+1],&geometry_info);
746 if ((flags & SigmaValue) == 0)
747 geometry_info.sigma=geometry_info.rho;
748 text=InterpretImageProperties(image_info,*image,argv[i+2]);
749 InheritException(exception,&(*image)->exception);
750 if (text == (char *) NULL)
751 break;
752 (void) CloneString(&draw_info->text,text);
753 text=DestroyString(text);
754 (void) FormatMagickString(geometry,MaxTextExtent,"%+f%+f",
755 geometry_info.xi,geometry_info.psi);
756 (void) CloneString(&draw_info->geometry,geometry);
757 draw_info->affine.sx=cos(DegreesToRadians(
758 fmod(geometry_info.rho,360.0)));
759 draw_info->affine.rx=sin(DegreesToRadians(
760 fmod(geometry_info.rho,360.0)));
761 draw_info->affine.ry=(-sin(DegreesToRadians(
762 fmod(geometry_info.sigma,360.0))));
763 draw_info->affine.sy=cos(DegreesToRadians(
764 fmod(geometry_info.sigma,360.0)));
765 (void) AnnotateImage(*image,draw_info);
766 InheritException(exception,&(*image)->exception);
767 break;
768 }
769 if (LocaleCompare("antialias",option+1) == 0)
770 {
771 draw_info->stroke_antialias=(*option == '-') ? MagickTrue :
772 MagickFalse;
773 draw_info->text_antialias=(*option == '-') ? MagickTrue :
774 MagickFalse;
775 break;
776 }
777 if (LocaleCompare("auto-gamma",option+1) == 0)
778 {
779 /*
780 Auto Adjust Gamma of image based on its mean
781 */
782 (void) SyncImageSettings(image_info,*image);
783 (void) AutoGammaImageChannel(*image,channel);
784 break;
785 }
786 if (LocaleCompare("auto-level",option+1) == 0)
787 {
788 /*
789 Perfectly Normalize (max/min stretch) the image
790 */
791 (void) SyncImageSettings(image_info,*image);
792 (void) AutoLevelImageChannel(*image,channel);
793 break;
794 }
795 if (LocaleCompare("auto-orient",option+1) == 0)
796 {
797 Image
798 *orient_image;
799
800 (void) SyncImageSettings(image_info,*image);
801 orient_image=NewImageList();
802 switch ((*image)->orientation)
803 {
804 case TopRightOrientation:
805 {
806 orient_image=FlopImage(*image,exception);
807 break;
808 }
809 case BottomRightOrientation:
810 {
811 orient_image=RotateImage(*image,180.0,exception);
812 break;
813 }
814 case BottomLeftOrientation:
815 {
816 orient_image=FlipImage(*image,exception);
817 break;
818 }
819 case LeftTopOrientation:
820 {
821 orient_image=TransposeImage(*image,exception);
822 break;
823 }
824 case RightTopOrientation:
825 {
826 orient_image=RotateImage(*image,90.0,exception);
827 break;
828 }
829 case RightBottomOrientation:
830 {
831 orient_image=TransverseImage(*image,exception);
832 break;
833 }
834 case LeftBottomOrientation:
835 {
836 orient_image=RotateImage(*image,270.0,exception);
837 break;
838 }
839 default:
840 break;
841 }
842 if (orient_image == (Image *) NULL)
843 break;
844 orient_image->orientation=TopLeftOrientation;
845 *image=DestroyImage(*image);
846 *image=orient_image;
847 break;
848 }
849 break;
850 }
851 case 'b':
852 {
853 if (LocaleCompare("black-threshold",option+1) == 0)
854 {
855 /*
856 Black threshold image.
857 */
858 (void) SyncImageSettings(image_info,*image);
859 (void) BlackThresholdImageChannel(*image,channel,argv[i+1],
860 exception);
861 InheritException(exception,&(*image)->exception);
862 break;
863 }
864 if (LocaleCompare("blue-shift",option+1) == 0)
865 {
866 Image
867 *shift_image;
868
869 /*
870 Blue shift image.
871 */
872 (void) SyncImageSettings(image_info,*image);
873 geometry_info.rho=1.5;
874 if (*option == '-')
875 flags=ParseGeometry(argv[i+1],&geometry_info);
876 shift_image=BlueShiftImage(*image,geometry_info.rho,exception);
877 if (shift_image == (Image *) NULL)
878 break;
879 *image=DestroyImage(*image);
880 *image=shift_image;
881 break;
882 }
883 if (LocaleCompare("blur",option+1) == 0)
884 {
885 Image
886 *blur_image;
887
888 /*
889 Gaussian blur image.
890 */
891 (void) SyncImageSettings(image_info,*image);
892 flags=ParseGeometry(argv[i+1],&geometry_info);
893 if ((flags & SigmaValue) == 0)
894 geometry_info.sigma=1.0;
895 blur_image=BlurImageChannel(*image,channel,geometry_info.rho,
896 geometry_info.sigma,exception);
897 if (blur_image == (Image *) NULL)
898 break;
899 *image=DestroyImage(*image);
900 *image=blur_image;
901 break;
902 }
903 if (LocaleCompare("border",option+1) == 0)
904 {
905 Image
906 *border_image;
907
908 /*
909 Surround image with a border of solid color.
910 */
911 (void) SyncImageSettings(image_info,*image);
912 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
913 if ((flags & SigmaValue) == 0)
914 geometry.height=geometry.width;
915 border_image=BorderImage(*image,&geometry,exception);
916 if (border_image == (Image *) NULL)
917 break;
918 *image=DestroyImage(*image);
919 *image=border_image;
920 break;
921 }
922 if (LocaleCompare("bordercolor",option+1) == 0)
923 {
924 if (*option == '+')
925 {
926 (void) QueryColorDatabase(BorderColor,&draw_info->border_color,
927 exception);
928 break;
929 }
930 (void) QueryColorDatabase(argv[i+1],&draw_info->border_color,
931 exception);
932 break;
933 }
934 if (LocaleCompare("box",option+1) == 0)
935 {
936 (void) QueryColorDatabase(argv[i+1],&draw_info->undercolor,
937 exception);
938 break;
939 }
cristya28d6b82010-01-11 20:03:47 +0000940 if (LocaleCompare("brightness-contrast",option+1) == 0)
941 {
942 double
943 brightness,
944 contrast;
945
946 GeometryInfo
947 geometry_info;
948
949 MagickStatusType
950 flags;
951
952 /*
953 Brightness / contrast image.
954 */
955 (void) SyncImageSettings(image_info,*image);
956 flags=ParseGeometry(argv[i+1],&geometry_info);
957 brightness=geometry_info.rho;
cristy81fbc8b2010-01-11 20:04:07 +0000958 contrast=0.0;
cristya28d6b82010-01-11 20:03:47 +0000959 if ((flags & SigmaValue) != 0)
960 contrast=geometry_info.sigma;
cristy02cc0f22010-01-12 00:02:32 +0000961 (void) BrightnessContrastImageChannel(*image,channel,brightness,
962 contrast);
cristya28d6b82010-01-11 20:03:47 +0000963 InheritException(exception,&(*image)->exception);
964 break;
965 }
cristy3ed852e2009-09-05 21:47:34 +0000966 break;
967 }
968 case 'c':
969 {
970 if (LocaleCompare("cdl",option+1) == 0)
971 {
972 char
973 *color_correction_collection;
974
975 /*
976 Color correct with a color decision list.
977 */
978 (void) SyncImageSettings(image_info,*image);
979 color_correction_collection=FileToString(argv[i+1],~0,exception);
980 if (color_correction_collection == (char *) NULL)
981 break;
982 (void) ColorDecisionListImage(*image,color_correction_collection);
983 InheritException(exception,&(*image)->exception);
984 break;
985 }
986 if (LocaleCompare("channel",option+1) == 0)
987 {
988 if (*option == '+')
989 {
990 channel=DefaultChannels;
991 break;
992 }
993 channel=(ChannelType) ParseChannelOption(argv[i+1]);
994 break;
995 }
996 if (LocaleCompare("charcoal",option+1) == 0)
997 {
998 Image
999 *charcoal_image;
1000
1001 /*
1002 Charcoal image.
1003 */
1004 (void) SyncImageSettings(image_info,*image);
1005 flags=ParseGeometry(argv[i+1],&geometry_info);
1006 if ((flags & SigmaValue) == 0)
1007 geometry_info.sigma=1.0;
1008 charcoal_image=CharcoalImage(*image,geometry_info.rho,
1009 geometry_info.sigma,exception);
1010 if (charcoal_image == (Image *) NULL)
1011 break;
1012 *image=DestroyImage(*image);
1013 *image=charcoal_image;
1014 break;
1015 }
1016 if (LocaleCompare("chop",option+1) == 0)
1017 {
1018 Image
1019 *chop_image;
1020
1021 /*
1022 Chop the image.
1023 */
1024 (void) SyncImageSettings(image_info,*image);
1025 (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1026 chop_image=ChopImage(*image,&geometry,exception);
1027 if (chop_image == (Image *) NULL)
1028 break;
1029 *image=DestroyImage(*image);
1030 *image=chop_image;
1031 break;
1032 }
cristy1eb45dd2009-09-25 16:38:06 +00001033 if (LocaleCompare("clamp",option+1) == 0)
1034 {
1035 /*
1036 Clamp image.
1037 */
1038 (void) SyncImageSettings(image_info,*image);
1039 (void) ClampImageChannel(*image,channel);
1040 InheritException(exception,&(*image)->exception);
1041 break;
1042 }
cristy3ed852e2009-09-05 21:47:34 +00001043 if (LocaleCompare("clip",option+1) == 0)
1044 {
1045 (void) SyncImageSettings(image_info,*image);
1046 if (*option == '+')
1047 {
1048 (void) SetImageClipMask(*image,(Image *) NULL);
1049 InheritException(exception,&(*image)->exception);
1050 break;
1051 }
1052 (void) ClipImage(*image);
1053 InheritException(exception,&(*image)->exception);
1054 break;
1055 }
1056 if (LocaleCompare("clip-mask",option+1) == 0)
1057 {
1058 Image
1059 *mask;
1060
cristybb503372010-05-27 20:51:26 +00001061 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001062 y;
1063
cristybb503372010-05-27 20:51:26 +00001064 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001065 x;
1066
1067 register PixelPacket
cristyc47d1f82009-11-26 01:44:43 +00001068 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00001069
1070 (void) SyncImageSettings(image_info,*image);
1071 if (*option == '+')
1072 {
1073 /*
1074 Remove a mask.
1075 */
1076 (void) SetImageMask(*image,(Image *) NULL);
1077 InheritException(exception,&(*image)->exception);
1078 break;
1079 }
1080 /*
1081 Set the image mask.
1082 */
1083 mask=GetImageCache(image_info,argv[i+1],exception);
1084 if (mask == (Image *) NULL)
1085 break;
cristybb503372010-05-27 20:51:26 +00001086 for (y=0; y < (ssize_t) mask->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00001087 {
1088 q=GetAuthenticPixels(mask,0,y,mask->columns,1,exception);
1089 if (q == (PixelPacket *) NULL)
1090 break;
cristybb503372010-05-27 20:51:26 +00001091 for (x=0; x < (ssize_t) mask->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00001092 {
1093 if (mask->matte == MagickFalse)
1094 q->opacity=PixelIntensityToQuantum(q);
1095 q->red=q->opacity;
1096 q->green=q->opacity;
1097 q->blue=q->opacity;
1098 q++;
1099 }
1100 if (SyncAuthenticPixels(mask,exception) == MagickFalse)
1101 break;
1102 }
1103 if (SetImageStorageClass(mask,DirectClass) == MagickFalse)
1104 return(MagickFalse);
1105 mask->matte=MagickTrue;
1106 (void) SetImageClipMask(*image,mask);
1107 mask=DestroyImage(mask);
1108 InheritException(exception,&(*image)->exception);
1109 break;
1110 }
1111 if (LocaleCompare("clip-path",option+1) == 0)
1112 {
1113 (void) SyncImageSettings(image_info,*image);
1114 (void) ClipImagePath(*image,argv[i+1],*option == '-' ? MagickTrue :
1115 MagickFalse);
1116 InheritException(exception,&(*image)->exception);
1117 break;
1118 }
1119 if (LocaleCompare("colorize",option+1) == 0)
1120 {
1121 Image
1122 *colorize_image;
1123
1124 /*
1125 Colorize the image.
1126 */
1127 (void) SyncImageSettings(image_info,*image);
1128 colorize_image=ColorizeImage(*image,argv[i+1],draw_info->fill,
1129 exception);
1130 if (colorize_image == (Image *) NULL)
1131 break;
1132 *image=DestroyImage(*image);
1133 *image=colorize_image;
1134 break;
1135 }
cristye6365592010-04-02 17:31:23 +00001136 if (LocaleCompare("color-matrix",option+1) == 0)
1137 {
1138 Image
1139 *color_image;
1140
1141 KernelInfo
1142 *kernel;
1143
1144 (void) SyncImageSettings(image_info,*image);
1145 kernel=AcquireKernelInfo(argv[i+1]);
1146 if (kernel == (KernelInfo *) NULL)
1147 break;
1148 color_image=ColorMatrixImage(*image,kernel,exception);
1149 kernel=DestroyKernelInfo(kernel);
1150 if (color_image == (Image *) NULL)
1151 break;
1152 *image=DestroyImage(*image);
1153 *image=color_image;
1154 break;
1155 }
cristy3ed852e2009-09-05 21:47:34 +00001156 if (LocaleCompare("colors",option+1) == 0)
1157 {
1158 /*
1159 Reduce the number of colors in the image.
1160 */
1161 (void) SyncImageSettings(image_info,*image);
cristye27293e2009-12-18 02:53:20 +00001162 quantize_info->number_colors=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00001163 if (quantize_info->number_colors == 0)
1164 break;
1165 if (((*image)->storage_class == DirectClass) ||
1166 (*image)->colors > quantize_info->number_colors)
1167 (void) QuantizeImage(quantize_info,*image);
1168 else
1169 (void) CompressImageColormap(*image);
1170 InheritException(exception,&(*image)->exception);
1171 break;
1172 }
1173 if (LocaleCompare("colorspace",option+1) == 0)
1174 {
1175 ColorspaceType
1176 colorspace;
1177
1178 (void) SyncImageSettings(image_info,*image);
1179 if (*option == '+')
1180 {
1181 (void) TransformImageColorspace(*image,RGBColorspace);
1182 InheritException(exception,&(*image)->exception);
1183 break;
1184 }
1185 colorspace=(ColorspaceType) ParseMagickOption(
1186 MagickColorspaceOptions,MagickFalse,argv[i+1]);
1187 (void) TransformImageColorspace(*image,colorspace);
1188 InheritException(exception,&(*image)->exception);
1189 break;
1190 }
1191 if (LocaleCompare("contrast",option+1) == 0)
1192 {
1193 (void) SyncImageSettings(image_info,*image);
1194 (void) ContrastImage(*image,(*option == '-') ? MagickTrue :
1195 MagickFalse);
1196 InheritException(exception,&(*image)->exception);
1197 break;
1198 }
1199 if (LocaleCompare("contrast-stretch",option+1) == 0)
1200 {
1201 double
1202 black_point,
1203 white_point;
1204
cristy3ed852e2009-09-05 21:47:34 +00001205 MagickStatusType
1206 flags;
1207
1208 /*
1209 Contrast stretch image.
1210 */
1211 (void) SyncImageSettings(image_info,*image);
1212 flags=ParseGeometry(argv[i+1],&geometry_info);
1213 black_point=geometry_info.rho;
1214 white_point=(flags & SigmaValue) != 0 ? geometry_info.sigma :
1215 black_point;
1216 if ((flags & PercentValue) != 0)
1217 {
1218 black_point*=(double) (*image)->columns*(*image)->rows/100.0;
1219 white_point*=(double) (*image)->columns*(*image)->rows/100.0;
1220 }
1221 white_point=(MagickRealType) (*image)->columns*(*image)->rows-
1222 white_point;
1223 (void) ContrastStretchImageChannel(*image,channel,black_point,
1224 white_point);
1225 InheritException(exception,&(*image)->exception);
1226 break;
1227 }
1228 if (LocaleCompare("convolve",option+1) == 0)
1229 {
cristy36826ab2010-03-06 01:29:30 +00001230 double
1231 gamma;
1232
cristy3ed852e2009-09-05 21:47:34 +00001233 Image
1234 *convolve_image;
1235
cristy2be15382010-01-21 02:38:03 +00001236 KernelInfo
cristy56a9e512010-01-06 18:18:55 +00001237 *kernel;
cristy3ed852e2009-09-05 21:47:34 +00001238
cristybb503372010-05-27 20:51:26 +00001239 register ssize_t
cristy36826ab2010-03-06 01:29:30 +00001240 j;
1241
cristya6510532010-03-06 13:09:30 +00001242 (void) SyncImageSettings(image_info,*image);
cristy2be15382010-01-21 02:38:03 +00001243 kernel=AcquireKernelInfo(argv[i+1]);
1244 if (kernel == (KernelInfo *) NULL)
cristy56a9e512010-01-06 18:18:55 +00001245 break;
cristy36826ab2010-03-06 01:29:30 +00001246 gamma=0.0;
cristybb503372010-05-27 20:51:26 +00001247 for (j=0; j < (ssize_t) (kernel->width*kernel->height); j++)
cristy36826ab2010-03-06 01:29:30 +00001248 gamma+=kernel->values[j];
1249 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
cristybb503372010-05-27 20:51:26 +00001250 for (j=0; j < (ssize_t) (kernel->width*kernel->height); j++)
cristy36826ab2010-03-06 01:29:30 +00001251 kernel->values[j]*=gamma;
cristy6771f1e2010-03-05 19:43:39 +00001252 convolve_image=FilterImageChannel(*image,channel,kernel,exception);
anthony83ba99b2010-01-24 08:48:15 +00001253 kernel=DestroyKernelInfo(kernel);
cristy3ed852e2009-09-05 21:47:34 +00001254 if (convolve_image == (Image *) NULL)
1255 break;
1256 *image=DestroyImage(*image);
1257 *image=convolve_image;
1258 break;
1259 }
1260 if (LocaleCompare("crop",option+1) == 0)
1261 {
1262 (void) SyncImageSettings(image_info,*image);
1263 flags=ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1264 if (((geometry.width != 0) || (geometry.height != 0)) &&
1265 ((flags & XValue) == 0) && ((flags & YValue) == 0))
1266 break;
1267 (void) TransformImage(image,argv[i+1],(char *) NULL);
1268 InheritException(exception,&(*image)->exception);
1269 break;
1270 }
1271 if (LocaleCompare("cycle",option+1) == 0)
1272 {
1273 /*
1274 Cycle an image colormap.
1275 */
1276 (void) SyncImageSettings(image_info,*image);
cristyf2f27272009-12-17 14:48:46 +00001277 (void) CycleColormapImage(*image,StringToLong(argv[i+1]));
cristy3ed852e2009-09-05 21:47:34 +00001278 InheritException(exception,&(*image)->exception);
1279 break;
1280 }
1281 break;
1282 }
1283 case 'd':
1284 {
1285 if (LocaleCompare("decipher",option+1) == 0)
1286 {
1287 StringInfo
1288 *passkey;
1289
1290 /*
1291 Decipher pixels.
1292 */
1293 (void) SyncImageSettings(image_info,*image);
1294 passkey=FileToStringInfo(argv[i+1],~0,exception);
1295 if (passkey != (StringInfo *) NULL)
1296 {
1297 (void) PasskeyDecipherImage(*image,passkey,exception);
1298 passkey=DestroyStringInfo(passkey);
1299 }
1300 break;
1301 }
1302 if (LocaleCompare("density",option+1) == 0)
1303 {
1304 /*
1305 Set image density.
1306 */
1307 (void) CloneString(&draw_info->density,argv[i+1]);
1308 break;
1309 }
1310 if (LocaleCompare("depth",option+1) == 0)
1311 {
1312 (void) SyncImageSettings(image_info,*image);
1313 if (*option == '+')
1314 {
1315 (void) SetImageDepth(*image,MAGICKCORE_QUANTUM_DEPTH);
1316 break;
1317 }
cristye27293e2009-12-18 02:53:20 +00001318 (void) SetImageDepth(*image,StringToUnsignedLong(argv[i+1]));
cristy3ed852e2009-09-05 21:47:34 +00001319 break;
1320 }
1321 if (LocaleCompare("deskew",option+1) == 0)
1322 {
1323 double
1324 threshold;
1325
1326 Image
1327 *deskew_image;
1328
1329 /*
1330 Straighten the image.
1331 */
1332 (void) SyncImageSettings(image_info,*image);
1333 if (*option == '+')
1334 threshold=40.0*QuantumRange/100.0;
1335 else
cristyf2f27272009-12-17 14:48:46 +00001336 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
cristy3ed852e2009-09-05 21:47:34 +00001337 deskew_image=DeskewImage(*image,threshold,exception);
1338 if (deskew_image == (Image *) NULL)
1339 break;
1340 *image=DestroyImage(*image);
1341 *image=deskew_image;
1342 break;
1343 }
1344 if (LocaleCompare("despeckle",option+1) == 0)
1345 {
1346 Image
1347 *despeckle_image;
1348
1349 /*
1350 Reduce the speckles within an image.
1351 */
1352 (void) SyncImageSettings(image_info,*image);
1353 despeckle_image=DespeckleImage(*image,exception);
1354 if (despeckle_image == (Image *) NULL)
1355 break;
1356 *image=DestroyImage(*image);
1357 *image=despeckle_image;
1358 break;
1359 }
1360 if (LocaleCompare("display",option+1) == 0)
1361 {
1362 (void) CloneString(&draw_info->server_name,argv[i+1]);
1363 break;
1364 }
cristy3ed852e2009-09-05 21:47:34 +00001365 if (LocaleCompare("distort",option+1) == 0)
1366 {
1367 char
1368 *args,
1369 token[MaxTextExtent];
1370
1371 const char
1372 *p;
1373
1374 DistortImageMethod
1375 method;
1376
1377 double
1378 *arguments;
1379
1380 Image
1381 *distort_image;
1382
cristybb503372010-05-27 20:51:26 +00001383 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001384 x;
1385
cristybb503372010-05-27 20:51:26 +00001386 size_t
cristy3ed852e2009-09-05 21:47:34 +00001387 number_arguments;
1388
1389 /*
1390 Distort image.
1391 */
1392 (void) SyncImageSettings(image_info,*image);
1393 method=(DistortImageMethod) ParseMagickOption(MagickDistortOptions,
1394 MagickFalse,argv[i+1]);
1395 args=InterpretImageProperties(image_info,*image,argv[i+2]);
1396 InheritException(exception,&(*image)->exception);
1397 if (args == (char *) NULL)
1398 break;
1399 p=(char *) args;
1400 for (x=0; *p != '\0'; x++)
1401 {
1402 GetMagickToken(p,&p,token);
1403 if (*token == ',')
1404 GetMagickToken(p,&p,token);
1405 }
cristybb503372010-05-27 20:51:26 +00001406 number_arguments=(size_t) x;
cristy3ed852e2009-09-05 21:47:34 +00001407 arguments=(double *) AcquireQuantumMemory(number_arguments,
1408 sizeof(*arguments));
1409 if (arguments == (double *) NULL)
1410 ThrowWandFatalException(ResourceLimitFatalError,
1411 "MemoryAllocationFailed",(*image)->filename);
1412 (void) ResetMagickMemory(arguments,0,number_arguments*
1413 sizeof(*arguments));
1414 p=(char *) args;
cristybb503372010-05-27 20:51:26 +00001415 for (x=0; (x < (ssize_t) number_arguments) && (*p != '\0'); x++)
cristy3ed852e2009-09-05 21:47:34 +00001416 {
1417 GetMagickToken(p,&p,token);
1418 if (*token == ',')
1419 GetMagickToken(p,&p,token);
cristyf2f27272009-12-17 14:48:46 +00001420 arguments[x]=StringToDouble(token);
cristy3ed852e2009-09-05 21:47:34 +00001421 }
1422 args=DestroyString(args);
1423 distort_image=DistortImage(*image,method,number_arguments,arguments,
1424 (*option == '+') ? MagickTrue : MagickFalse,exception);
1425 arguments=(double *) RelinquishMagickMemory(arguments);
1426 if (distort_image == (Image *) NULL)
1427 break;
1428 *image=DestroyImage(*image);
1429 *image=distort_image;
1430 break;
1431 }
1432 if (LocaleCompare("dither",option+1) == 0)
1433 {
1434 if (*option == '+')
1435 {
1436 quantize_info->dither=MagickFalse;
1437 break;
1438 }
1439 quantize_info->dither=MagickTrue;
1440 quantize_info->dither_method=(DitherMethod) ParseMagickOption(
1441 MagickDitherOptions,MagickFalse,argv[i+1]);
1442 if (quantize_info->dither_method == NoDitherMethod)
1443 quantize_info->dither=MagickFalse;
1444 break;
1445 }
1446 if (LocaleCompare("draw",option+1) == 0)
1447 {
1448 /*
1449 Draw image.
1450 */
1451 (void) SyncImageSettings(image_info,*image);
1452 (void) CloneString(&draw_info->primitive,argv[i+1]);
1453 (void) DrawImage(*image,draw_info);
1454 InheritException(exception,&(*image)->exception);
1455 break;
1456 }
1457 break;
1458 }
1459 case 'e':
1460 {
1461 if (LocaleCompare("edge",option+1) == 0)
1462 {
1463 Image
1464 *edge_image;
1465
1466 /*
1467 Enhance edges in the image.
1468 */
1469 (void) SyncImageSettings(image_info,*image);
1470 flags=ParseGeometry(argv[i+1],&geometry_info);
1471 if ((flags & SigmaValue) == 0)
1472 geometry_info.sigma=1.0;
1473 edge_image=EdgeImage(*image,geometry_info.rho,exception);
1474 if (edge_image == (Image *) NULL)
1475 break;
1476 *image=DestroyImage(*image);
1477 *image=edge_image;
1478 break;
1479 }
1480 if (LocaleCompare("emboss",option+1) == 0)
1481 {
1482 Image
1483 *emboss_image;
1484
1485 /*
1486 Gaussian embossen image.
1487 */
1488 (void) SyncImageSettings(image_info,*image);
1489 flags=ParseGeometry(argv[i+1],&geometry_info);
1490 if ((flags & SigmaValue) == 0)
1491 geometry_info.sigma=1.0;
1492 emboss_image=EmbossImage(*image,geometry_info.rho,
1493 geometry_info.sigma,exception);
1494 if (emboss_image == (Image *) NULL)
1495 break;
1496 *image=DestroyImage(*image);
1497 *image=emboss_image;
1498 break;
1499 }
1500 if (LocaleCompare("encipher",option+1) == 0)
1501 {
1502 StringInfo
1503 *passkey;
1504
1505 /*
1506 Encipher pixels.
1507 */
1508 (void) SyncImageSettings(image_info,*image);
1509 passkey=FileToStringInfo(argv[i+1],~0,exception);
1510 if (passkey != (StringInfo *) NULL)
1511 {
1512 (void) PasskeyEncipherImage(*image,passkey,exception);
1513 passkey=DestroyStringInfo(passkey);
1514 }
1515 break;
1516 }
1517 if (LocaleCompare("encoding",option+1) == 0)
1518 {
1519 (void) CloneString(&draw_info->encoding,argv[i+1]);
1520 break;
1521 }
1522 if (LocaleCompare("enhance",option+1) == 0)
1523 {
1524 Image
1525 *enhance_image;
1526
1527 /*
1528 Enhance image.
1529 */
1530 (void) SyncImageSettings(image_info,*image);
1531 enhance_image=EnhanceImage(*image,exception);
1532 if (enhance_image == (Image *) NULL)
1533 break;
1534 *image=DestroyImage(*image);
1535 *image=enhance_image;
1536 break;
1537 }
1538 if (LocaleCompare("equalize",option+1) == 0)
1539 {
1540 /*
1541 Equalize image.
1542 */
1543 (void) SyncImageSettings(image_info,*image);
1544 (void) EqualizeImageChannel(*image,channel);
1545 InheritException(exception,&(*image)->exception);
1546 break;
1547 }
1548 if (LocaleCompare("evaluate",option+1) == 0)
1549 {
1550 double
1551 constant;
1552
1553 MagickEvaluateOperator
1554 op;
1555
1556 (void) SyncImageSettings(image_info,*image);
1557 op=(MagickEvaluateOperator) ParseMagickOption(MagickEvaluateOptions,
1558 MagickFalse,argv[i+1]);
cristyf2f27272009-12-17 14:48:46 +00001559 constant=SiPrefixToDouble(argv[i+2],QuantumRange);
cristy3ed852e2009-09-05 21:47:34 +00001560 (void) EvaluateImageChannel(*image,channel,op,constant,exception);
1561 break;
1562 }
1563 if (LocaleCompare("extent",option+1) == 0)
1564 {
1565 Image
1566 *extent_image;
1567
1568 /*
1569 Set the image extent.
1570 */
1571 (void) SyncImageSettings(image_info,*image);
1572 flags=ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
cristyf0bbfd92009-11-25 14:12:31 +00001573 if (geometry.width == 0)
cristy2ea9a4e2009-11-25 14:30:22 +00001574 geometry.width=(*image)->columns;
cristyf0bbfd92009-11-25 14:12:31 +00001575 if (geometry.height == 0)
cristy2ea9a4e2009-11-25 14:30:22 +00001576 geometry.height=(*image)->rows;
cristy3ed852e2009-09-05 21:47:34 +00001577 geometry.x=(-geometry.x);
1578 geometry.y=(-geometry.y);
1579 extent_image=ExtentImage(*image,&geometry,exception);
1580 if (extent_image == (Image *) NULL)
1581 break;
1582 *image=DestroyImage(*image);
1583 *image=extent_image;
1584 break;
1585 }
1586 break;
1587 }
1588 case 'f':
1589 {
1590 if (LocaleCompare("family",option+1) == 0)
1591 {
1592 if (*option == '+')
1593 {
1594 if (draw_info->family != (char *) NULL)
1595 draw_info->family=DestroyString(draw_info->family);
1596 break;
1597 }
1598 (void) CloneString(&draw_info->family,argv[i+1]);
1599 break;
1600 }
cristy0fe961c2010-01-30 03:09:54 +00001601 if (LocaleCompare("features",option+1) == 0)
1602 {
1603 if (*option == '+')
1604 {
1605 (void) DeleteImageArtifact(*image,"identify:features");
1606 break;
1607 }
1608 (void) SetImageArtifact(*image,"identify:features",argv[i+1]);
1609 break;
1610 }
cristy3ed852e2009-09-05 21:47:34 +00001611 if (LocaleCompare("fill",option+1) == 0)
1612 {
1613 ExceptionInfo
1614 *sans;
1615
1616 GetMagickPixelPacket(*image,&fill);
1617 if (*option == '+')
1618 {
1619 (void) QueryMagickColor("none",&fill,exception);
1620 (void) QueryColorDatabase("none",&draw_info->fill,exception);
1621 if (draw_info->fill_pattern != (Image *) NULL)
1622 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
1623 break;
1624 }
1625 sans=AcquireExceptionInfo();
1626 (void) QueryMagickColor(argv[i+1],&fill,sans);
1627 status=QueryColorDatabase(argv[i+1],&draw_info->fill,sans);
1628 sans=DestroyExceptionInfo(sans);
1629 if (status == MagickFalse)
1630 draw_info->fill_pattern=GetImageCache(image_info,argv[i+1],
1631 exception);
1632 break;
1633 }
1634 if (LocaleCompare("flip",option+1) == 0)
1635 {
1636 Image
1637 *flip_image;
1638
1639 /*
1640 Flip image scanlines.
1641 */
1642 (void) SyncImageSettings(image_info,*image);
1643 flip_image=FlipImage(*image,exception);
1644 if (flip_image == (Image *) NULL)
1645 break;
1646 *image=DestroyImage(*image);
1647 *image=flip_image;
1648 break;
1649 }
1650 if (LocaleCompare("flop",option+1) == 0)
1651 {
1652 Image
1653 *flop_image;
1654
1655 /*
1656 Flop image scanlines.
1657 */
1658 (void) SyncImageSettings(image_info,*image);
1659 flop_image=FlopImage(*image,exception);
1660 if (flop_image == (Image *) NULL)
1661 break;
1662 *image=DestroyImage(*image);
1663 *image=flop_image;
1664 break;
1665 }
1666 if (LocaleCompare("floodfill",option+1) == 0)
1667 {
1668 MagickPixelPacket
1669 target;
1670
1671 /*
1672 Floodfill image.
1673 */
1674 (void) SyncImageSettings(image_info,*image);
1675 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
1676 (void) QueryMagickColor(argv[i+2],&target,exception);
1677 (void) FloodfillPaintImage(*image,channel,draw_info,&target,
1678 geometry.x,geometry.y,*option == '-' ? MagickFalse : MagickTrue);
1679 InheritException(exception,&(*image)->exception);
1680 break;
1681 }
1682 if (LocaleCompare("font",option+1) == 0)
1683 {
1684 if (*option == '+')
1685 {
1686 if (draw_info->font != (char *) NULL)
1687 draw_info->font=DestroyString(draw_info->font);
1688 break;
1689 }
1690 (void) CloneString(&draw_info->font,argv[i+1]);
1691 break;
1692 }
1693 if (LocaleCompare("format",option+1) == 0)
1694 {
1695 format=argv[i+1];
1696 break;
1697 }
1698 if (LocaleCompare("frame",option+1) == 0)
1699 {
1700 FrameInfo
1701 frame_info;
1702
1703 Image
1704 *frame_image;
1705
1706 /*
1707 Surround image with an ornamental border.
1708 */
1709 (void) SyncImageSettings(image_info,*image);
1710 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
1711 frame_info.width=geometry.width;
1712 frame_info.height=geometry.height;
1713 if ((flags & HeightValue) == 0)
1714 frame_info.height=geometry.width;
1715 frame_info.outer_bevel=geometry.x;
1716 frame_info.inner_bevel=geometry.y;
cristybb503372010-05-27 20:51:26 +00001717 frame_info.x=(ssize_t) frame_info.width;
1718 frame_info.y=(ssize_t) frame_info.height;
cristy3ed852e2009-09-05 21:47:34 +00001719 frame_info.width=(*image)->columns+2*frame_info.width;
1720 frame_info.height=(*image)->rows+2*frame_info.height;
1721 frame_image=FrameImage(*image,&frame_info,exception);
1722 if (frame_image == (Image *) NULL)
1723 break;
1724 *image=DestroyImage(*image);
1725 *image=frame_image;
1726 break;
1727 }
1728 if (LocaleCompare("function",option+1) == 0)
1729 {
1730 char
1731 *arguments,
1732 token[MaxTextExtent];
1733
1734 const char
1735 *p;
1736
1737 double
1738 *parameters;
1739
1740 MagickFunction
1741 function;
1742
cristybb503372010-05-27 20:51:26 +00001743 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001744 x;
1745
cristybb503372010-05-27 20:51:26 +00001746 size_t
cristy3ed852e2009-09-05 21:47:34 +00001747 number_parameters;
1748
1749 /*
1750 Function Modify Image Values
1751 */
1752 (void) SyncImageSettings(image_info,*image);
1753 function=(MagickFunction) ParseMagickOption(MagickFunctionOptions,
1754 MagickFalse,argv[i+1]);
1755 arguments=InterpretImageProperties(image_info,*image,argv[i+2]);
1756 InheritException(exception,&(*image)->exception);
1757 if (arguments == (char *) NULL)
1758 break;
1759 p=(char *) arguments;
1760 for (x=0; *p != '\0'; x++)
1761 {
1762 GetMagickToken(p,&p,token);
1763 if (*token == ',')
1764 GetMagickToken(p,&p,token);
1765 }
cristybb503372010-05-27 20:51:26 +00001766 number_parameters=(size_t) x;
cristy3ed852e2009-09-05 21:47:34 +00001767 parameters=(double *) AcquireQuantumMemory(number_parameters,
1768 sizeof(*parameters));
1769 if (parameters == (double *) NULL)
1770 ThrowWandFatalException(ResourceLimitFatalError,
1771 "MemoryAllocationFailed",(*image)->filename);
1772 (void) ResetMagickMemory(parameters,0,number_parameters*
1773 sizeof(*parameters));
1774 p=(char *) arguments;
cristybb503372010-05-27 20:51:26 +00001775 for (x=0; (x < (ssize_t) number_parameters) && (*p != '\0'); x++)
cristy3ed852e2009-09-05 21:47:34 +00001776 {
1777 GetMagickToken(p,&p,token);
1778 if (*token == ',')
1779 GetMagickToken(p,&p,token);
cristyf2f27272009-12-17 14:48:46 +00001780 parameters[x]=StringToDouble(token);
cristy3ed852e2009-09-05 21:47:34 +00001781 }
1782 arguments=DestroyString(arguments);
1783 (void) FunctionImageChannel(*image,channel,function,
1784 number_parameters,parameters,exception);
1785 parameters=(double *) RelinquishMagickMemory(parameters);
1786 break;
1787 }
1788 break;
1789 }
1790 case 'g':
1791 {
1792 if (LocaleCompare("gamma",option+1) == 0)
1793 {
1794 /*
1795 Gamma image.
1796 */
1797 (void) SyncImageSettings(image_info,*image);
1798 if (*option == '+')
cristyf2f27272009-12-17 14:48:46 +00001799 (*image)->gamma=StringToDouble(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00001800 else
1801 {
1802 if (strchr(argv[i+1],',') != (char *) NULL)
1803 (void) GammaImage(*image,argv[i+1]);
1804 else
cristya5447be2010-01-11 00:20:51 +00001805 (void) GammaImageChannel(*image,channel,
1806 StringToDouble(argv[i+1]));
cristy3ed852e2009-09-05 21:47:34 +00001807 InheritException(exception,&(*image)->exception);
1808 }
1809 break;
1810 }
1811 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
1812 (LocaleCompare("gaussian",option+1) == 0))
1813 {
1814 Image
1815 *gaussian_image;
1816
1817 /*
1818 Gaussian blur image.
1819 */
1820 (void) SyncImageSettings(image_info,*image);
1821 flags=ParseGeometry(argv[i+1],&geometry_info);
1822 if ((flags & SigmaValue) == 0)
1823 geometry_info.sigma=1.0;
1824 gaussian_image=GaussianBlurImageChannel(*image,channel,
1825 geometry_info.rho,geometry_info.sigma,exception);
1826 if (gaussian_image == (Image *) NULL)
1827 break;
1828 *image=DestroyImage(*image);
1829 *image=gaussian_image;
1830 break;
1831 }
1832 if (LocaleCompare("geometry",option+1) == 0)
1833 {
1834 (void) SyncImageSettings(image_info,*image);
1835 if (*option == '+')
1836 {
1837 if ((*image)->geometry != (char *) NULL)
1838 (*image)->geometry=DestroyString((*image)->geometry);
1839 break;
1840 }
1841 flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
1842 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
1843 (void) CloneString(&(*image)->geometry,argv[i+1]);
1844 else
1845 {
1846 Image
1847 *zoom_image;
1848
1849 /*
1850 Resize image.
1851 */
1852 zoom_image=ZoomImage(*image,geometry.width,geometry.height,
1853 exception);
1854 if (zoom_image == (Image *) NULL)
1855 break;
1856 *image=DestroyImage(*image);
1857 *image=zoom_image;
1858 }
1859 break;
1860 }
1861 if (LocaleCompare("gravity",option+1) == 0)
1862 {
1863 if (*option == '+')
1864 {
1865 draw_info->gravity=UndefinedGravity;
1866 break;
1867 }
1868 draw_info->gravity=(GravityType) ParseMagickOption(
1869 MagickGravityOptions,MagickFalse,argv[i+1]);
1870 break;
1871 }
1872 break;
1873 }
1874 case 'h':
1875 {
1876 if (LocaleCompare("highlight-color",option+1) == 0)
1877 {
1878 (void) SetImageArtifact(*image,option+1,argv[i+1]);
1879 break;
1880 }
1881 break;
1882 }
1883 case 'i':
1884 {
1885 if (LocaleCompare("identify",option+1) == 0)
1886 {
1887 char
1888 *text;
1889
1890 (void) SyncImageSettings(image_info,*image);
1891 if (format == (char *) NULL)
1892 {
1893 (void) IdentifyImage(*image,stdout,image_info->verbose);
1894 InheritException(exception,&(*image)->exception);
1895 break;
1896 }
1897 text=InterpretImageProperties(image_info,*image,format);
1898 InheritException(exception,&(*image)->exception);
1899 if (text == (char *) NULL)
1900 break;
1901 (void) fputs(text,stdout);
1902 (void) fputc('\n',stdout);
1903 text=DestroyString(text);
1904 break;
1905 }
1906 if (LocaleCompare("implode",option+1) == 0)
1907 {
1908 Image
1909 *implode_image;
1910
1911 /*
1912 Implode image.
1913 */
1914 (void) SyncImageSettings(image_info,*image);
1915 (void) ParseGeometry(argv[i+1],&geometry_info);
1916 implode_image=ImplodeImage(*image,geometry_info.rho,exception);
1917 if (implode_image == (Image *) NULL)
1918 break;
1919 *image=DestroyImage(*image);
1920 *image=implode_image;
1921 break;
1922 }
cristyb32b90a2009-09-07 21:45:48 +00001923 if (LocaleCompare("interline-spacing",option+1) == 0)
1924 {
1925 if (*option == '+')
1926 (void) ParseGeometry("0",&geometry_info);
1927 else
1928 (void) ParseGeometry(argv[i+1],&geometry_info);
1929 draw_info->interline_spacing=geometry_info.rho;
1930 break;
1931 }
cristy3ed852e2009-09-05 21:47:34 +00001932 if (LocaleCompare("interword-spacing",option+1) == 0)
1933 {
1934 if (*option == '+')
1935 (void) ParseGeometry("0",&geometry_info);
1936 else
1937 (void) ParseGeometry(argv[i+1],&geometry_info);
1938 draw_info->interword_spacing=geometry_info.rho;
1939 break;
1940 }
1941 break;
1942 }
1943 case 'k':
1944 {
1945 if (LocaleCompare("kerning",option+1) == 0)
1946 {
1947 if (*option == '+')
1948 (void) ParseGeometry("0",&geometry_info);
1949 else
1950 (void) ParseGeometry(argv[i+1],&geometry_info);
1951 draw_info->kerning=geometry_info.rho;
1952 break;
1953 }
1954 break;
1955 }
1956 case 'l':
1957 {
1958 if (LocaleCompare("lat",option+1) == 0)
1959 {
1960 Image
1961 *threshold_image;
1962
1963 /*
1964 Local adaptive threshold image.
1965 */
1966 (void) SyncImageSettings(image_info,*image);
1967 flags=ParseGeometry(argv[i+1],&geometry_info);
1968 if ((flags & PercentValue) != 0)
1969 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
cristybb503372010-05-27 20:51:26 +00001970 threshold_image=AdaptiveThresholdImage(*image,(size_t)
1971 geometry_info.rho,(size_t) geometry_info.sigma,
1972 (ssize_t) geometry_info.xi,exception);
cristy3ed852e2009-09-05 21:47:34 +00001973 if (threshold_image == (Image *) NULL)
1974 break;
1975 *image=DestroyImage(*image);
1976 *image=threshold_image;
1977 break;
1978 }
1979 if (LocaleCompare("level",option+1) == 0)
1980 {
cristy3ed852e2009-09-05 21:47:34 +00001981 MagickRealType
1982 black_point,
1983 gamma,
1984 white_point;
1985
1986 MagickStatusType
1987 flags;
1988
1989 /*
1990 Parse levels.
1991 */
1992 (void) SyncImageSettings(image_info,*image);
1993 flags=ParseGeometry(argv[i+1],&geometry_info);
1994 black_point=geometry_info.rho;
1995 white_point=(MagickRealType) QuantumRange;
1996 if ((flags & SigmaValue) != 0)
1997 white_point=geometry_info.sigma;
1998 gamma=1.0;
1999 if ((flags & XiValue) != 0)
2000 gamma=geometry_info.xi;
2001 if ((flags & PercentValue) != 0)
2002 {
2003 black_point*=(MagickRealType) (QuantumRange/100.0);
2004 white_point*=(MagickRealType) (QuantumRange/100.0);
2005 }
2006 if ((flags & SigmaValue) == 0)
2007 white_point=(MagickRealType) QuantumRange-black_point;
2008 if ((*option == '+') || ((flags & AspectValue) != 0))
2009 (void) LevelizeImageChannel(*image,channel,black_point,
2010 white_point,gamma);
2011 else
2012 (void) LevelImageChannel(*image,channel,black_point,white_point,
2013 gamma);
2014 InheritException(exception,&(*image)->exception);
2015 break;
2016 }
2017 if (LocaleCompare("level-colors",option+1) == 0)
2018 {
2019 char
2020 token[MaxTextExtent];
2021
2022 const char
2023 *p;
2024
2025 MagickPixelPacket
2026 black_point,
2027 white_point;
2028
2029 p=(const char *) argv[i+1];
2030 GetMagickToken(p,&p,token); /* get black point color */
cristyee0f8d72009-09-19 00:58:29 +00002031 if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
cristy3ed852e2009-09-05 21:47:34 +00002032 (void) QueryMagickColor(token,&black_point,exception);
2033 else
cristyee0f8d72009-09-19 00:58:29 +00002034 (void) QueryMagickColor("#000000",&black_point,exception);
cristy3ed852e2009-09-05 21:47:34 +00002035 if (isalpha((int) token[0]) || (token[0] == '#'))
2036 GetMagickToken(p,&p,token);
cristyee0f8d72009-09-19 00:58:29 +00002037 if (*token == '\0')
cristy3ed852e2009-09-05 21:47:34 +00002038 white_point=black_point; /* set everything to that color */
2039 else
2040 {
2041 /*
2042 Get white point color.
2043 */
cristyee0f8d72009-09-19 00:58:29 +00002044 if ((isalpha((int) *token) == 0) && ((*token == '#') == 0))
cristy3ed852e2009-09-05 21:47:34 +00002045 GetMagickToken(p,&p,token);
cristyee0f8d72009-09-19 00:58:29 +00002046 if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
cristy3ed852e2009-09-05 21:47:34 +00002047 (void) QueryMagickColor(token,&white_point,exception);
2048 else
cristyee0f8d72009-09-19 00:58:29 +00002049 (void) QueryMagickColor("#ffffff",&white_point,exception);
cristy3ed852e2009-09-05 21:47:34 +00002050 }
cristy74fe8f12009-10-03 19:09:01 +00002051 (void) LevelColorsImageChannel(*image,channel,&black_point,
2052 &white_point,*option == '+' ? MagickTrue : MagickFalse);
cristy3ed852e2009-09-05 21:47:34 +00002053 break;
2054 }
2055 if (LocaleCompare("linear-stretch",option+1) == 0)
2056 {
2057 double
2058 black_point,
2059 white_point;
2060
cristy3ed852e2009-09-05 21:47:34 +00002061 MagickStatusType
2062 flags;
2063
2064 (void) SyncImageSettings(image_info,*image);
2065 flags=ParseGeometry(argv[i+1],&geometry_info);
2066 black_point=geometry_info.rho;
2067 white_point=(MagickRealType) (*image)->columns*(*image)->rows;
2068 if ((flags & SigmaValue) != 0)
2069 white_point=geometry_info.sigma;
2070 if ((flags & PercentValue) != 0)
2071 {
2072 black_point*=(double) (*image)->columns*(*image)->rows/100.0;
2073 white_point*=(double) (*image)->columns*(*image)->rows/100.0;
2074 }
2075 if ((flags & SigmaValue) == 0)
2076 white_point=(MagickRealType) (*image)->columns*(*image)->rows-
2077 black_point;
2078 (void) LinearStretchImage(*image,black_point,white_point);
2079 InheritException(exception,&(*image)->exception);
2080 break;
2081 }
2082 if (LocaleCompare("linewidth",option+1) == 0)
2083 {
cristyf2f27272009-12-17 14:48:46 +00002084 draw_info->stroke_width=StringToDouble(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00002085 break;
2086 }
2087 if (LocaleCompare("liquid-rescale",option+1) == 0)
2088 {
2089 Image
2090 *resize_image;
2091
2092 /*
2093 Liquid rescale image.
2094 */
2095 (void) SyncImageSettings(image_info,*image);
2096 flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2097 if ((flags & XValue) == 0)
2098 geometry.x=1;
2099 if ((flags & YValue) == 0)
2100 geometry.y=0;
2101 resize_image=LiquidRescaleImage(*image,geometry.width,
2102 geometry.height,1.0*geometry.x,1.0*geometry.y,exception);
2103 if (resize_image == (Image *) NULL)
2104 break;
2105 *image=DestroyImage(*image);
2106 *image=resize_image;
2107 break;
2108 }
2109 if (LocaleCompare("lowlight-color",option+1) == 0)
2110 {
2111 (void) SetImageArtifact(*image,option+1,argv[i+1]);
2112 break;
2113 }
2114 break;
2115 }
2116 case 'm':
2117 {
2118 if (LocaleCompare("map",option+1) == 0)
2119 {
2120 Image
2121 *remap_image;
2122
2123 /*
2124 Transform image colors to match this set of colors.
2125 */
2126 (void) SyncImageSettings(image_info,*image);
2127 if (*option == '+')
2128 break;
2129 remap_image=GetImageCache(image_info,argv[i+1],exception);
2130 if (remap_image == (Image *) NULL)
2131 break;
2132 (void) RemapImage(quantize_info,*image,remap_image);
2133 InheritException(exception,&(*image)->exception);
2134 remap_image=DestroyImage(remap_image);
2135 break;
2136 }
2137 if (LocaleCompare("mask",option+1) == 0)
2138 {
2139 Image
2140 *mask;
2141
2142 (void) SyncImageSettings(image_info,*image);
2143 if (*option == '+')
2144 {
2145 /*
2146 Remove a mask.
2147 */
2148 (void) SetImageMask(*image,(Image *) NULL);
2149 InheritException(exception,&(*image)->exception);
2150 break;
2151 }
2152 /*
2153 Set the image mask.
2154 */
2155 mask=GetImageCache(image_info,argv[i+1],exception);
2156 if (mask == (Image *) NULL)
2157 break;
2158 (void) SetImageMask(*image,mask);
2159 mask=DestroyImage(mask);
2160 InheritException(exception,&(*image)->exception);
2161 break;
2162 }
2163 if (LocaleCompare("matte",option+1) == 0)
2164 {
2165 (void) SetImageAlphaChannel(*image,(*option == '-') ?
2166 SetAlphaChannel : DeactivateAlphaChannel );
2167 InheritException(exception,&(*image)->exception);
2168 break;
2169 }
2170 if (LocaleCompare("median",option+1) == 0)
2171 {
2172 Image
2173 *median_image;
2174
2175 /*
2176 Median filter image.
2177 */
2178 (void) SyncImageSettings(image_info,*image);
2179 (void) ParseGeometry(argv[i+1],&geometry_info);
2180 median_image=MedianFilterImage(*image,geometry_info.rho,exception);
2181 if (median_image == (Image *) NULL)
2182 break;
2183 *image=DestroyImage(*image);
2184 *image=median_image;
2185 break;
2186 }
2187 if (LocaleCompare("modulate",option+1) == 0)
2188 {
2189 (void) SyncImageSettings(image_info,*image);
2190 (void) ModulateImage(*image,argv[i+1]);
2191 InheritException(exception,&(*image)->exception);
2192 break;
2193 }
2194 if (LocaleCompare("monitor",option+1) == 0)
2195 {
cristy7d34ef22010-03-25 01:11:22 +00002196 if (*option == '+')
2197 {
2198 (void) SetImageProgressMonitor(*image,
2199 (MagickProgressMonitor) NULL,(void *) NULL);
2200 break;
2201 }
cristy3ed852e2009-09-05 21:47:34 +00002202 (void) SetImageProgressMonitor(*image,MonitorProgress,
2203 (void *) NULL);
2204 break;
2205 }
2206 if (LocaleCompare("monochrome",option+1) == 0)
2207 {
2208 (void) SyncImageSettings(image_info,*image);
2209 (void) SetImageType(*image,BilevelType);
2210 InheritException(exception,&(*image)->exception);
2211 break;
2212 }
anthony29188a82010-01-22 10:12:34 +00002213 if (LocaleCompare("morphology",option+1) == 0)
2214 {
anthony29188a82010-01-22 10:12:34 +00002215 char
2216 token[MaxTextExtent];
2217
2218 const char
2219 *p;
2220
cristye96405a2010-05-19 02:24:31 +00002221 Image
2222 *morphology_image;
2223
2224 KernelInfo
2225 *kernel;
2226
cristybb503372010-05-27 20:51:26 +00002227 ssize_t
anthony29188a82010-01-22 10:12:34 +00002228 iterations;
2229
cristye96405a2010-05-19 02:24:31 +00002230 MorphologyMethod
2231 method;
2232
anthony29188a82010-01-22 10:12:34 +00002233 /*
2234 Morphological Image Operation
2235 */
2236 (void) SyncImageSettings(image_info,*image);
2237 p=argv[i+1];
2238 GetMagickToken(p,&p,token);
2239 method=(MorphologyMethod) ParseMagickOption(MagickMorphologyOptions,
cristyd2c1e1e2010-05-08 01:05:44 +00002240 MagickFalse,token);
cristyef656912010-03-05 19:54:59 +00002241 iterations=1L;
anthony29188a82010-01-22 10:12:34 +00002242 GetMagickToken(p,&p,token);
cristyef656912010-03-05 19:54:59 +00002243 if ((*p == ':') || (*p == ','))
anthony29188a82010-01-22 10:12:34 +00002244 GetMagickToken(p,&p,token);
cristyef656912010-03-05 19:54:59 +00002245 if ((*p != '\0'))
2246 iterations=StringToLong(p);
anthony29188a82010-01-22 10:12:34 +00002247 kernel=AcquireKernelInfo(argv[i+2]);
2248 if (kernel == (KernelInfo *) NULL)
cristye96405a2010-05-19 02:24:31 +00002249 {
2250 (void) ThrowMagickException(exception,GetMagickModule(),
2251 OptionError,"UnabletoParseKernel","morphology");
2252 status=MagickFalse;
2253 break;
2254 }
anthony29188a82010-01-22 10:12:34 +00002255 morphology_image=MorphologyImageChannel(*image,channel,method,
cristy02d5b4f2010-02-01 01:08:27 +00002256 iterations,kernel,exception);
anthony83ba99b2010-01-24 08:48:15 +00002257 kernel=DestroyKernelInfo(kernel);
anthony29188a82010-01-22 10:12:34 +00002258 if (morphology_image == (Image *) NULL)
2259 break;
2260 *image=DestroyImage(*image);
2261 *image=morphology_image;
2262 break;
2263 }
cristy3ed852e2009-09-05 21:47:34 +00002264 if (LocaleCompare("motion-blur",option+1) == 0)
2265 {
2266 Image
2267 *blur_image;
2268
2269 /*
2270 Motion blur image.
2271 */
2272 (void) SyncImageSettings(image_info,*image);
2273 flags=ParseGeometry(argv[i+1],&geometry_info);
2274 if ((flags & SigmaValue) == 0)
2275 geometry_info.sigma=1.0;
2276 blur_image=MotionBlurImageChannel(*image,channel,geometry_info.rho,
2277 geometry_info.sigma,geometry_info.xi,exception);
2278 if (blur_image == (Image *) NULL)
2279 break;
2280 *image=DestroyImage(*image);
2281 *image=blur_image;
2282 break;
2283 }
2284 break;
2285 }
2286 case 'n':
2287 {
2288 if (LocaleCompare("negate",option+1) == 0)
2289 {
2290 (void) SyncImageSettings(image_info,*image);
2291 (void) NegateImageChannel(*image,channel,*option == '+' ?
2292 MagickTrue : MagickFalse);
2293 InheritException(exception,&(*image)->exception);
2294 break;
2295 }
2296 if (LocaleCompare("noise",option+1) == 0)
2297 {
2298 Image
2299 *noisy_image;
2300
2301 (void) SyncImageSettings(image_info,*image);
2302 if (*option == '-')
2303 {
2304 (void) ParseGeometry(argv[i+1],&geometry_info);
2305 noisy_image=ReduceNoiseImage(*image,geometry_info.rho,
2306 exception);
2307 }
2308 else
2309 {
2310 NoiseType
2311 noise;
2312
2313 noise=(NoiseType) ParseMagickOption(MagickNoiseOptions,
2314 MagickFalse,argv[i+1]);
2315 noisy_image=AddNoiseImageChannel(*image,channel,noise,
2316 exception);
2317 }
2318 if (noisy_image == (Image *) NULL)
2319 break;
2320 *image=DestroyImage(*image);
2321 *image=noisy_image;
2322 break;
2323 }
2324 if (LocaleCompare("normalize",option+1) == 0)
2325 {
2326 (void) SyncImageSettings(image_info,*image);
2327 (void) NormalizeImageChannel(*image,channel);
2328 InheritException(exception,&(*image)->exception);
2329 break;
2330 }
2331 break;
2332 }
2333 case 'o':
2334 {
2335 if (LocaleCompare("opaque",option+1) == 0)
2336 {
2337 MagickPixelPacket
2338 target;
2339
2340 (void) SyncImageSettings(image_info,*image);
2341 (void) QueryMagickColor(argv[i+1],&target,exception);
2342 (void) OpaquePaintImageChannel(*image,channel,&target,&fill,
2343 *option == '-' ? MagickFalse : MagickTrue);
2344 break;
2345 }
2346 if (LocaleCompare("ordered-dither",option+1) == 0)
2347 {
2348 (void) SyncImageSettings(image_info,*image);
2349 (void) OrderedPosterizeImageChannel(*image,channel,argv[i+1],
2350 exception);
2351 break;
2352 }
2353 break;
2354 }
2355 case 'p':
2356 {
2357 if (LocaleCompare("paint",option+1) == 0)
2358 {
2359 Image
2360 *paint_image;
2361
2362 /*
2363 Oil paint image.
2364 */
2365 (void) SyncImageSettings(image_info,*image);
2366 (void) ParseGeometry(argv[i+1],&geometry_info);
2367 paint_image=OilPaintImage(*image,geometry_info.rho,exception);
2368 if (paint_image == (Image *) NULL)
2369 break;
2370 *image=DestroyImage(*image);
2371 *image=paint_image;
2372 break;
2373 }
2374 if (LocaleCompare("pen",option+1) == 0)
2375 {
2376 if (*option == '+')
2377 {
2378 (void) QueryColorDatabase("none",&draw_info->fill,exception);
2379 break;
2380 }
2381 (void) QueryColorDatabase(argv[i+1],&draw_info->fill,exception);
2382 break;
2383 }
2384 if (LocaleCompare("pointsize",option+1) == 0)
2385 {
2386 if (*option == '+')
2387 (void) ParseGeometry("12",&geometry_info);
2388 else
2389 (void) ParseGeometry(argv[i+1],&geometry_info);
2390 draw_info->pointsize=geometry_info.rho;
2391 break;
2392 }
2393 if (LocaleCompare("polaroid",option+1) == 0)
2394 {
2395 double
2396 angle;
2397
2398 Image
2399 *polaroid_image;
2400
2401 RandomInfo
2402 *random_info;
2403
2404 /*
2405 Simulate a Polaroid picture.
2406 */
2407 (void) SyncImageSettings(image_info,*image);
2408 random_info=AcquireRandomInfo();
2409 angle=22.5*(GetPseudoRandomValue(random_info)-0.5);
2410 random_info=DestroyRandomInfo(random_info);
2411 if (*option == '-')
2412 {
2413 SetGeometryInfo(&geometry_info);
2414 flags=ParseGeometry(argv[i+1],&geometry_info);
2415 angle=geometry_info.rho;
2416 }
2417 polaroid_image=PolaroidImage(*image,draw_info,angle,exception);
2418 if (polaroid_image == (Image *) NULL)
2419 break;
2420 *image=DestroyImage(*image);
2421 *image=polaroid_image;
2422 break;
2423 }
2424 if (LocaleCompare("posterize",option+1) == 0)
2425 {
2426 /*
2427 Posterize image.
2428 */
2429 (void) SyncImageSettings(image_info,*image);
cristye27293e2009-12-18 02:53:20 +00002430 (void) PosterizeImage(*image,StringToUnsignedLong(argv[i+1]),
cristy3ed852e2009-09-05 21:47:34 +00002431 quantize_info->dither);
2432 InheritException(exception,&(*image)->exception);
2433 break;
2434 }
2435 if (LocaleCompare("preview",option+1) == 0)
2436 {
2437 Image
2438 *preview_image;
2439
2440 PreviewType
2441 preview_type;
2442
2443 /*
2444 Preview image.
2445 */
2446 (void) SyncImageSettings(image_info,*image);
2447 if (*option == '+')
2448 preview_type=UndefinedPreview;
2449 else
2450 preview_type=(PreviewType) ParseMagickOption(MagickPreviewOptions,
2451 MagickFalse,argv[i+1]);
2452 preview_image=PreviewImage(*image,preview_type,exception);
2453 if (preview_image == (Image *) NULL)
2454 break;
2455 *image=DestroyImage(*image);
2456 *image=preview_image;
2457 break;
2458 }
2459 if (LocaleCompare("profile",option+1) == 0)
2460 {
2461 const char
2462 *name;
2463
2464 const StringInfo
2465 *profile;
2466
2467 Image
2468 *profile_image;
2469
2470 ImageInfo
2471 *profile_info;
2472
2473 (void) SyncImageSettings(image_info,*image);
2474 if (*option == '+')
2475 {
2476 /*
2477 Remove a profile from the image.
2478 */
2479 (void) ProfileImage(*image,argv[i+1],(const unsigned char *)
2480 NULL,0,MagickTrue);
2481 InheritException(exception,&(*image)->exception);
2482 break;
2483 }
2484 /*
2485 Associate a profile with the image.
2486 */
2487 profile_info=CloneImageInfo(image_info);
2488 profile=GetImageProfile(*image,"iptc");
2489 if (profile != (StringInfo *) NULL)
2490 profile_info->profile=(void *) CloneStringInfo(profile);
2491 profile_image=GetImageCache(profile_info,argv[i+1],exception);
2492 profile_info=DestroyImageInfo(profile_info);
2493 if (profile_image == (Image *) NULL)
2494 {
cristy3ed852e2009-09-05 21:47:34 +00002495 StringInfo
2496 *profile;
2497
cristy071dd7b2010-04-09 13:04:54 +00002498 profile_info=CloneImageInfo(image_info);
2499 (void) CopyMagickString(profile_info->filename,argv[i+1],
2500 MaxTextExtent);
2501 profile=FileToStringInfo(profile_info->filename,~0UL,exception);
cristy3ed852e2009-09-05 21:47:34 +00002502 if (profile != (StringInfo *) NULL)
2503 {
cristy071dd7b2010-04-09 13:04:54 +00002504 (void) ProfileImage(*image,profile_info->magick,
cristybb503372010-05-27 20:51:26 +00002505 GetStringInfoDatum(profile),(size_t)
cristy071dd7b2010-04-09 13:04:54 +00002506 GetStringInfoLength(profile),MagickFalse);
cristy3ed852e2009-09-05 21:47:34 +00002507 profile=DestroyStringInfo(profile);
2508 }
cristy071dd7b2010-04-09 13:04:54 +00002509 profile_info=DestroyImageInfo(profile_info);
cristy3ed852e2009-09-05 21:47:34 +00002510 break;
2511 }
2512 ResetImageProfileIterator(profile_image);
2513 name=GetNextImageProfile(profile_image);
2514 while (name != (const char *) NULL)
2515 {
2516 profile=GetImageProfile(profile_image,name);
2517 if (profile != (StringInfo *) NULL)
2518 (void) ProfileImage(*image,name,GetStringInfoDatum(profile),
cristybb503372010-05-27 20:51:26 +00002519 (size_t) GetStringInfoLength(profile),MagickFalse);
cristy3ed852e2009-09-05 21:47:34 +00002520 name=GetNextImageProfile(profile_image);
2521 }
2522 profile_image=DestroyImage(profile_image);
2523 break;
2524 }
2525 break;
2526 }
2527 case 'q':
2528 {
2529 if (LocaleCompare("quantize",option+1) == 0)
2530 {
2531 if (*option == '+')
2532 {
2533 quantize_info->colorspace=UndefinedColorspace;
2534 break;
2535 }
2536 quantize_info->colorspace=(ColorspaceType) ParseMagickOption(
2537 MagickColorspaceOptions,MagickFalse,argv[i+1]);
2538 break;
2539 }
2540 break;
2541 }
2542 case 'r':
2543 {
2544 if (LocaleCompare("radial-blur",option+1) == 0)
2545 {
2546 Image
2547 *blur_image;
2548
2549 /*
2550 Radial blur image.
2551 */
2552 (void) SyncImageSettings(image_info,*image);
cristya5447be2010-01-11 00:20:51 +00002553 blur_image=RadialBlurImageChannel(*image,channel,
2554 StringToDouble(argv[i+1]),exception);
cristy3ed852e2009-09-05 21:47:34 +00002555 if (blur_image == (Image *) NULL)
2556 break;
2557 *image=DestroyImage(*image);
2558 *image=blur_image;
2559 break;
2560 }
2561 if (LocaleCompare("raise",option+1) == 0)
2562 {
2563 /*
2564 Surround image with a raise of solid color.
2565 */
2566 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2567 if ((flags & SigmaValue) == 0)
2568 geometry.height=geometry.width;
2569 (void) RaiseImage(*image,&geometry,*option == '-' ? MagickTrue :
2570 MagickFalse);
2571 InheritException(exception,&(*image)->exception);
2572 break;
2573 }
2574 if (LocaleCompare("random-threshold",option+1) == 0)
2575 {
2576 /*
2577 Threshold image.
2578 */
2579 (void) SyncImageSettings(image_info,*image);
2580 (void) RandomThresholdImageChannel(*image,channel,argv[i+1],
2581 exception);
2582 break;
2583 }
2584 if (LocaleCompare("recolor",option+1) == 0)
2585 {
cristy3ed852e2009-09-05 21:47:34 +00002586 Image
cristyf055ae42010-04-02 23:01:38 +00002587 *color_image;
cristy3ed852e2009-09-05 21:47:34 +00002588
cristyf055ae42010-04-02 23:01:38 +00002589 KernelInfo
2590 *kernel;
cristy3ed852e2009-09-05 21:47:34 +00002591
cristy3ed852e2009-09-05 21:47:34 +00002592 (void) SyncImageSettings(image_info,*image);
cristyf055ae42010-04-02 23:01:38 +00002593 kernel=AcquireKernelInfo(argv[i+1]);
2594 if (kernel == (KernelInfo *) NULL)
2595 break;
2596 color_image=ColorMatrixImage(*image,kernel,exception);
2597 kernel=DestroyKernelInfo(kernel);
2598 if (color_image == (Image *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002599 break;
2600 *image=DestroyImage(*image);
cristyf055ae42010-04-02 23:01:38 +00002601 *image=color_image;
cristy3ed852e2009-09-05 21:47:34 +00002602 break;
2603 }
2604 if (LocaleCompare("region",option+1) == 0)
2605 {
2606 Image
2607 *crop_image;
2608
2609 (void) SyncImageSettings(image_info,*image);
2610 if (region_image != (Image *) NULL)
2611 {
2612 /*
2613 Composite region.
2614 */
2615 (void) CompositeImage(region_image,(*image)->matte !=
2616 MagickFalse ? OverCompositeOp : CopyCompositeOp,*image,
2617 region_geometry.x,region_geometry.y);
2618 InheritException(exception,&region_image->exception);
2619 *image=DestroyImage(*image);
2620 *image=region_image;
2621 }
2622 if (*option == '+')
2623 {
2624 if (region_image != (Image *) NULL)
2625 region_image=DestroyImage(region_image);
2626 break;
2627 }
2628 /*
2629 Apply transformations to a selected region of the image.
2630 */
2631 (void) ParseGravityGeometry(*image,argv[i+1],&region_geometry,
2632 exception);
2633 crop_image=CropImage(*image,&region_geometry,exception);
2634 if (crop_image == (Image *) NULL)
2635 break;
2636 region_image=(*image);
2637 *image=crop_image;
2638 break;
2639 }
2640 if (LocaleCompare("render",option+1) == 0)
2641 {
2642 (void) SyncImageSettings(image_info,*image);
2643 draw_info->render=(*option == '+') ? MagickTrue : MagickFalse;
2644 break;
2645 }
2646 if (LocaleCompare("remap",option+1) == 0)
2647 {
2648 Image
2649 *remap_image;
2650
2651 /*
2652 Transform image colors to match this set of colors.
2653 */
2654 (void) SyncImageSettings(image_info,*image);
2655 if (*option == '+')
2656 break;
2657 remap_image=GetImageCache(image_info,argv[i+1],exception);
2658 if (remap_image == (Image *) NULL)
2659 break;
2660 (void) RemapImage(quantize_info,*image,remap_image);
2661 InheritException(exception,&(*image)->exception);
2662 remap_image=DestroyImage(remap_image);
2663 break;
2664 }
2665 if (LocaleCompare("repage",option+1) == 0)
2666 {
2667 if (*option == '+')
2668 {
2669 (void) ParseAbsoluteGeometry("0x0+0+0",&(*image)->page);
2670 break;
2671 }
2672 (void) ResetImagePage(*image,argv[i+1]);
2673 InheritException(exception,&(*image)->exception);
2674 break;
2675 }
2676 if (LocaleCompare("resample",option+1) == 0)
2677 {
2678 Image
2679 *resample_image;
2680
2681 /*
2682 Resample image.
2683 */
2684 (void) SyncImageSettings(image_info,*image);
2685 flags=ParseGeometry(argv[i+1],&geometry_info);
2686 if ((flags & SigmaValue) == 0)
2687 geometry_info.sigma=geometry_info.rho;
2688 resample_image=ResampleImage(*image,geometry_info.rho,
2689 geometry_info.sigma,(*image)->filter,(*image)->blur,exception);
2690 if (resample_image == (Image *) NULL)
2691 break;
2692 *image=DestroyImage(*image);
2693 *image=resample_image;
2694 break;
2695 }
2696 if (LocaleCompare("resize",option+1) == 0)
2697 {
2698 Image
2699 *resize_image;
2700
2701 /*
2702 Resize image.
2703 */
2704 (void) SyncImageSettings(image_info,*image);
2705 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2706 resize_image=ResizeImage(*image,geometry.width,geometry.height,
2707 (*image)->filter,(*image)->blur,exception);
2708 if (resize_image == (Image *) NULL)
2709 break;
2710 *image=DestroyImage(*image);
2711 *image=resize_image;
2712 break;
2713 }
2714 if (LocaleNCompare("respect-parentheses",option+1,17) == 0)
2715 {
2716 respect_parenthesis=(*option == '-') ? MagickTrue : MagickFalse;
2717 break;
2718 }
2719 if (LocaleCompare("roll",option+1) == 0)
2720 {
2721 Image
2722 *roll_image;
2723
2724 /*
2725 Roll image.
2726 */
2727 (void) SyncImageSettings(image_info,*image);
2728 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2729 roll_image=RollImage(*image,geometry.x,geometry.y,exception);
2730 if (roll_image == (Image *) NULL)
2731 break;
2732 *image=DestroyImage(*image);
2733 *image=roll_image;
2734 break;
2735 }
2736 if (LocaleCompare("rotate",option+1) == 0)
2737 {
2738 char
2739 *geometry;
2740
2741 Image
2742 *rotate_image;
2743
2744 /*
2745 Check for conditional image rotation.
2746 */
2747 (void) SyncImageSettings(image_info,*image);
2748 if (strchr(argv[i+1],'>') != (char *) NULL)
2749 if ((*image)->columns <= (*image)->rows)
2750 break;
2751 if (strchr(argv[i+1],'<') != (char *) NULL)
2752 if ((*image)->columns >= (*image)->rows)
2753 break;
2754 /*
2755 Rotate image.
2756 */
2757 geometry=ConstantString(argv[i+1]);
2758 (void) SubstituteString(&geometry,">","");
2759 (void) SubstituteString(&geometry,"<","");
2760 (void) ParseGeometry(geometry,&geometry_info);
2761 geometry=DestroyString(geometry);
2762 rotate_image=RotateImage(*image,geometry_info.rho,exception);
2763 if (rotate_image == (Image *) NULL)
2764 break;
2765 *image=DestroyImage(*image);
2766 *image=rotate_image;
2767 break;
2768 }
2769 break;
2770 }
2771 case 's':
2772 {
2773 if (LocaleCompare("sample",option+1) == 0)
2774 {
2775 Image
2776 *sample_image;
2777
2778 /*
2779 Sample image with pixel replication.
2780 */
2781 (void) SyncImageSettings(image_info,*image);
2782 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2783 sample_image=SampleImage(*image,geometry.width,geometry.height,
2784 exception);
2785 if (sample_image == (Image *) NULL)
2786 break;
2787 *image=DestroyImage(*image);
2788 *image=sample_image;
2789 break;
2790 }
2791 if (LocaleCompare("scale",option+1) == 0)
2792 {
2793 Image
2794 *scale_image;
2795
2796 /*
2797 Resize image.
2798 */
2799 (void) SyncImageSettings(image_info,*image);
2800 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2801 scale_image=ScaleImage(*image,geometry.width,geometry.height,
2802 exception);
2803 if (scale_image == (Image *) NULL)
2804 break;
2805 *image=DestroyImage(*image);
2806 *image=scale_image;
2807 break;
2808 }
2809 if (LocaleCompare("selective-blur",option+1) == 0)
2810 {
2811 Image
2812 *blur_image;
2813
2814 /*
2815 Selectively blur pixels within a contrast threshold.
2816 */
2817 (void) SyncImageSettings(image_info,*image);
2818 flags=ParseGeometry(argv[i+1],&geometry_info);
2819 if ((flags & PercentValue) != 0)
2820 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
2821 blur_image=SelectiveBlurImageChannel(*image,channel,
2822 geometry_info.rho,geometry_info.sigma,geometry_info.xi,exception);
2823 if (blur_image == (Image *) NULL)
2824 break;
2825 *image=DestroyImage(*image);
2826 *image=blur_image;
2827 break;
2828 }
2829 if (LocaleCompare("separate",option+1) == 0)
2830 {
2831 Image
2832 *separate_images;
2833
2834 /*
2835 Break channels into separate images.
2836 */
2837 (void) SyncImageSettings(image_info,*image);
2838 separate_images=SeparateImages(*image,channel,exception);
2839 if (separate_images == (Image *) NULL)
2840 break;
2841 *image=DestroyImage(*image);
2842 *image=separate_images;
2843 break;
2844 }
2845 if (LocaleCompare("sepia-tone",option+1) == 0)
2846 {
2847 double
2848 threshold;
2849
2850 Image
2851 *sepia_image;
2852
2853 /*
2854 Sepia-tone image.
2855 */
2856 (void) SyncImageSettings(image_info,*image);
cristyf2f27272009-12-17 14:48:46 +00002857 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
cristy3ed852e2009-09-05 21:47:34 +00002858 sepia_image=SepiaToneImage(*image,threshold,exception);
2859 if (sepia_image == (Image *) NULL)
2860 break;
2861 *image=DestroyImage(*image);
2862 *image=sepia_image;
2863 break;
2864 }
2865 if (LocaleCompare("segment",option+1) == 0)
2866 {
2867 /*
2868 Segment image.
2869 */
2870 (void) SyncImageSettings(image_info,*image);
2871 flags=ParseGeometry(argv[i+1],&geometry_info);
2872 if ((flags & SigmaValue) == 0)
2873 geometry_info.sigma=1.0;
2874 (void) SegmentImage(*image,(*image)->colorspace,image_info->verbose,
2875 geometry_info.rho,geometry_info.sigma);
2876 InheritException(exception,&(*image)->exception);
2877 break;
2878 }
2879 if (LocaleCompare("set",option+1) == 0)
2880 {
2881 /*
2882 Set image option.
2883 */
2884 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2885 (void) DeleteImageRegistry(argv[i+1]+9);
2886 else
2887 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
2888 (void) DeleteImageOption(image_info,argv[i+1]+7);
2889 else
2890 (void) DeleteImageProperty(*image,argv[i+1]);
2891 if (*option == '-')
2892 {
2893 char
2894 *value;
2895
2896 value=InterpretImageProperties(image_info,*image,argv[i+2]);
2897 if (value != (char *) NULL)
2898 {
2899 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2900 (void) SetImageRegistry(StringRegistryType,argv[i+1]+9,
2901 value,exception);
2902 else
2903 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
2904 {
2905 (void) SetImageOption(image_info,argv[i+1]+7,value);
2906 (void) SetImageArtifact(*image,argv[i+1]+7,value);
2907 }
2908 else
2909 (void) SetImageProperty(*image,argv[i+1],value);
2910 value=DestroyString(value);
2911 }
2912 }
2913 break;
2914 }
2915 if (LocaleCompare("shade",option+1) == 0)
2916 {
2917 Image
2918 *shade_image;
2919
2920 /*
2921 Shade image.
2922 */
2923 (void) SyncImageSettings(image_info,*image);
2924 flags=ParseGeometry(argv[i+1],&geometry_info);
2925 if ((flags & SigmaValue) == 0)
2926 geometry_info.sigma=1.0;
2927 shade_image=ShadeImage(*image,(*option == '-') ? MagickTrue :
2928 MagickFalse,geometry_info.rho,geometry_info.sigma,exception);
2929 if (shade_image == (Image *) NULL)
2930 break;
2931 *image=DestroyImage(*image);
2932 *image=shade_image;
2933 break;
2934 }
2935 if (LocaleCompare("shadow",option+1) == 0)
2936 {
2937 Image
2938 *shadow_image;
2939
2940 /*
2941 Shadow image.
2942 */
2943 (void) SyncImageSettings(image_info,*image);
2944 flags=ParseGeometry(argv[i+1],&geometry_info);
2945 if ((flags & SigmaValue) == 0)
2946 geometry_info.sigma=1.0;
2947 if ((flags & XiValue) == 0)
2948 geometry_info.xi=4.0;
2949 if ((flags & PsiValue) == 0)
2950 geometry_info.psi=4.0;
2951 shadow_image=ShadowImage(*image,geometry_info.rho,
cristybb503372010-05-27 20:51:26 +00002952 geometry_info.sigma,(ssize_t) ceil(geometry_info.xi-0.5),(ssize_t)
cristy0534a6b2010-03-18 01:19:38 +00002953 ceil(geometry_info.psi-0.5),exception);
cristy3ed852e2009-09-05 21:47:34 +00002954 if (shadow_image == (Image *) NULL)
2955 break;
2956 *image=DestroyImage(*image);
2957 *image=shadow_image;
2958 break;
2959 }
2960 if (LocaleCompare("sharpen",option+1) == 0)
2961 {
2962 Image
2963 *sharp_image;
2964
2965 /*
2966 Sharpen image.
2967 */
2968 (void) SyncImageSettings(image_info,*image);
2969 flags=ParseGeometry(argv[i+1],&geometry_info);
2970 if ((flags & SigmaValue) == 0)
2971 geometry_info.sigma=1.0;
2972 sharp_image=SharpenImageChannel(*image,channel,geometry_info.rho,
2973 geometry_info.sigma,exception);
2974 if (sharp_image == (Image *) NULL)
2975 break;
2976 *image=DestroyImage(*image);
2977 *image=sharp_image;
2978 break;
2979 }
2980 if (LocaleCompare("shave",option+1) == 0)
2981 {
2982 Image
2983 *shave_image;
2984
2985 /*
2986 Shave the image edges.
2987 */
2988 (void) SyncImageSettings(image_info,*image);
2989 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2990 shave_image=ShaveImage(*image,&geometry,exception);
2991 if (shave_image == (Image *) NULL)
2992 break;
2993 *image=DestroyImage(*image);
2994 *image=shave_image;
2995 break;
2996 }
2997 if (LocaleCompare("shear",option+1) == 0)
2998 {
2999 Image
3000 *shear_image;
3001
3002 /*
3003 Shear image.
3004 */
3005 (void) SyncImageSettings(image_info,*image);
3006 flags=ParseGeometry(argv[i+1],&geometry_info);
3007 if ((flags & SigmaValue) == 0)
3008 geometry_info.sigma=geometry_info.rho;
3009 shear_image=ShearImage(*image,geometry_info.rho,geometry_info.sigma,
3010 exception);
3011 if (shear_image == (Image *) NULL)
3012 break;
3013 *image=DestroyImage(*image);
3014 *image=shear_image;
3015 break;
3016 }
3017 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
3018 {
3019 /*
3020 Sigmoidal non-linearity contrast control.
3021 */
3022 (void) SyncImageSettings(image_info,*image);
3023 flags=ParseGeometry(argv[i+1],&geometry_info);
3024 if ((flags & SigmaValue) == 0)
3025 geometry_info.sigma=(double) QuantumRange/2.0;
3026 if ((flags & PercentValue) != 0)
3027 geometry_info.sigma=(double) QuantumRange*geometry_info.sigma/
3028 100.0;
3029 (void) SigmoidalContrastImageChannel(*image,channel,
3030 (*option == '-') ? MagickTrue : MagickFalse,geometry_info.rho,
3031 geometry_info.sigma);
3032 InheritException(exception,&(*image)->exception);
3033 break;
3034 }
3035 if (LocaleCompare("sketch",option+1) == 0)
3036 {
3037 Image
3038 *sketch_image;
3039
3040 /*
3041 Sketch image.
3042 */
3043 (void) SyncImageSettings(image_info,*image);
3044 flags=ParseGeometry(argv[i+1],&geometry_info);
3045 if ((flags & SigmaValue) == 0)
3046 geometry_info.sigma=1.0;
3047 sketch_image=SketchImage(*image,geometry_info.rho,
3048 geometry_info.sigma,geometry_info.xi,exception);
3049 if (sketch_image == (Image *) NULL)
3050 break;
3051 *image=DestroyImage(*image);
3052 *image=sketch_image;
3053 break;
3054 }
3055 if (LocaleCompare("solarize",option+1) == 0)
3056 {
3057 double
3058 threshold;
3059
3060 (void) SyncImageSettings(image_info,*image);
cristyf2f27272009-12-17 14:48:46 +00003061 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
cristy3ed852e2009-09-05 21:47:34 +00003062 (void) SolarizeImage(*image,threshold);
3063 InheritException(exception,&(*image)->exception);
3064 break;
3065 }
3066 if (LocaleCompare("sparse-color",option+1) == 0)
3067 {
3068 Image
3069 *sparse_image;
3070
3071 SparseColorMethod
3072 method;
3073
3074 char
3075 *arguments;
3076
3077 /*
3078 Sparse Color Interpolated Gradient
3079 */
3080 (void) SyncImageSettings(image_info,*image);
3081 method=(SparseColorMethod) ParseMagickOption(
3082 MagickSparseColorOptions,MagickFalse,argv[i+1]);
3083 arguments=InterpretImageProperties(image_info,*image,argv[i+2]);
3084 InheritException(exception,&(*image)->exception);
3085 if (arguments == (char *) NULL)
3086 break;
3087 sparse_image=SparseColorOption(*image,channel,method,arguments,
3088 option[0] == '+' ? MagickTrue : MagickFalse,exception);
3089 arguments=DestroyString(arguments);
3090 if (sparse_image == (Image *) NULL)
3091 break;
3092 *image=DestroyImage(*image);
3093 *image=sparse_image;
3094 break;
3095 }
3096 if (LocaleCompare("splice",option+1) == 0)
3097 {
3098 Image
3099 *splice_image;
3100
3101 /*
3102 Splice a solid color into the image.
3103 */
3104 (void) SyncImageSettings(image_info,*image);
3105 (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
3106 splice_image=SpliceImage(*image,&geometry,exception);
3107 if (splice_image == (Image *) NULL)
3108 break;
3109 *image=DestroyImage(*image);
3110 *image=splice_image;
3111 break;
3112 }
3113 if (LocaleCompare("spread",option+1) == 0)
3114 {
3115 Image
3116 *spread_image;
3117
3118 /*
3119 Spread an image.
3120 */
3121 (void) SyncImageSettings(image_info,*image);
3122 (void) ParseGeometry(argv[i+1],&geometry_info);
3123 spread_image=SpreadImage(*image,geometry_info.rho,exception);
3124 if (spread_image == (Image *) NULL)
3125 break;
3126 *image=DestroyImage(*image);
3127 *image=spread_image;
3128 break;
3129 }
3130 if (LocaleCompare("stretch",option+1) == 0)
3131 {
3132 if (*option == '+')
3133 {
3134 draw_info->stretch=UndefinedStretch;
3135 break;
3136 }
3137 draw_info->stretch=(StretchType) ParseMagickOption(
3138 MagickStretchOptions,MagickFalse,argv[i+1]);
3139 break;
3140 }
3141 if (LocaleCompare("strip",option+1) == 0)
3142 {
3143 /*
3144 Strip image of profiles and comments.
3145 */
3146 (void) SyncImageSettings(image_info,*image);
3147 (void) StripImage(*image);
3148 InheritException(exception,&(*image)->exception);
3149 break;
3150 }
3151 if (LocaleCompare("stroke",option+1) == 0)
3152 {
3153 ExceptionInfo
3154 *sans;
3155
3156 if (*option == '+')
3157 {
3158 (void) QueryColorDatabase("none",&draw_info->stroke,exception);
3159 if (draw_info->stroke_pattern != (Image *) NULL)
3160 draw_info->stroke_pattern=DestroyImage(
3161 draw_info->stroke_pattern);
3162 break;
3163 }
3164 sans=AcquireExceptionInfo();
3165 status=QueryColorDatabase(argv[i+1],&draw_info->stroke,sans);
3166 sans=DestroyExceptionInfo(sans);
3167 if (status == MagickFalse)
3168 draw_info->stroke_pattern=GetImageCache(image_info,argv[i+1],
3169 exception);
3170 break;
3171 }
3172 if (LocaleCompare("strokewidth",option+1) == 0)
3173 {
cristyf2f27272009-12-17 14:48:46 +00003174 draw_info->stroke_width=StringToDouble(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00003175 break;
3176 }
3177 if (LocaleCompare("style",option+1) == 0)
3178 {
3179 if (*option == '+')
3180 {
3181 draw_info->style=UndefinedStyle;
3182 break;
3183 }
3184 draw_info->style=(StyleType) ParseMagickOption(MagickStyleOptions,
3185 MagickFalse,argv[i+1]);
3186 break;
3187 }
3188 if (LocaleCompare("swirl",option+1) == 0)
3189 {
3190 Image
3191 *swirl_image;
3192
3193 /*
3194 Swirl image.
3195 */
3196 (void) SyncImageSettings(image_info,*image);
3197 (void) ParseGeometry(argv[i+1],&geometry_info);
3198 swirl_image=SwirlImage(*image,geometry_info.rho,exception);
3199 if (swirl_image == (Image *) NULL)
3200 break;
3201 *image=DestroyImage(*image);
3202 *image=swirl_image;
3203 break;
3204 }
3205 break;
3206 }
3207 case 't':
3208 {
3209 if (LocaleCompare("threshold",option+1) == 0)
3210 {
3211 double
3212 threshold;
3213
3214 /*
3215 Threshold image.
3216 */
3217 (void) SyncImageSettings(image_info,*image);
3218 if (*option == '+')
3219 threshold=(double) QuantumRange/2.5;
3220 else
cristyf2f27272009-12-17 14:48:46 +00003221 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
cristy3ed852e2009-09-05 21:47:34 +00003222 (void) BilevelImageChannel(*image,channel,threshold);
3223 InheritException(exception,&(*image)->exception);
3224 break;
3225 }
3226 if (LocaleCompare("thumbnail",option+1) == 0)
3227 {
3228 Image
3229 *thumbnail_image;
3230
3231 /*
3232 Thumbnail image.
3233 */
3234 (void) SyncImageSettings(image_info,*image);
3235 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
3236 thumbnail_image=ThumbnailImage(*image,geometry.width,
3237 geometry.height,exception);
3238 if (thumbnail_image == (Image *) NULL)
3239 break;
3240 *image=DestroyImage(*image);
3241 *image=thumbnail_image;
3242 break;
3243 }
3244 if (LocaleCompare("tile",option+1) == 0)
3245 {
3246 if (*option == '+')
3247 {
3248 if (draw_info->fill_pattern != (Image *) NULL)
3249 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
3250 break;
3251 }
3252 draw_info->fill_pattern=GetImageCache(image_info,argv[i+1],
3253 exception);
3254 break;
3255 }
3256 if (LocaleCompare("tint",option+1) == 0)
3257 {
3258 Image
3259 *tint_image;
3260
3261 /*
3262 Tint the image.
3263 */
3264 (void) SyncImageSettings(image_info,*image);
3265 tint_image=TintImage(*image,argv[i+1],draw_info->fill,exception);
3266 if (tint_image == (Image *) NULL)
3267 break;
3268 *image=DestroyImage(*image);
3269 *image=tint_image;
3270 break;
3271 }
3272 if (LocaleCompare("transform",option+1) == 0)
3273 {
3274 Image
3275 *transform_image;
3276
3277 /*
3278 Affine transform image.
3279 */
3280 (void) SyncImageSettings(image_info,*image);
3281 transform_image=AffineTransformImage(*image,&draw_info->affine,
3282 exception);
3283 if (transform_image == (Image *) NULL)
3284 break;
3285 *image=DestroyImage(*image);
3286 *image=transform_image;
3287 break;
3288 }
3289 if (LocaleCompare("transparent",option+1) == 0)
3290 {
3291 MagickPixelPacket
3292 target;
3293
3294 (void) SyncImageSettings(image_info,*image);
3295 (void) QueryMagickColor(argv[i+1],&target,exception);
3296 (void) TransparentPaintImage(*image,&target,(Quantum)
3297 TransparentOpacity,*option == '-' ? MagickFalse : MagickTrue);
3298 InheritException(exception,&(*image)->exception);
3299 break;
3300 }
3301 if (LocaleCompare("transpose",option+1) == 0)
3302 {
3303 Image
3304 *transpose_image;
3305
3306 /*
3307 Transpose image scanlines.
3308 */
3309 (void) SyncImageSettings(image_info,*image);
3310 transpose_image=TransposeImage(*image,exception);
3311 if (transpose_image == (Image *) NULL)
3312 break;
3313 *image=DestroyImage(*image);
3314 *image=transpose_image;
3315 break;
3316 }
3317 if (LocaleCompare("transverse",option+1) == 0)
3318 {
3319 Image
3320 *transverse_image;
3321
3322 /*
3323 Transverse image scanlines.
3324 */
3325 (void) SyncImageSettings(image_info,*image);
3326 transverse_image=TransverseImage(*image,exception);
3327 if (transverse_image == (Image *) NULL)
3328 break;
3329 *image=DestroyImage(*image);
3330 *image=transverse_image;
3331 break;
3332 }
3333 if (LocaleCompare("treedepth",option+1) == 0)
3334 {
cristye27293e2009-12-18 02:53:20 +00003335 quantize_info->tree_depth=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00003336 break;
3337 }
3338 if (LocaleCompare("trim",option+1) == 0)
3339 {
3340 Image
3341 *trim_image;
3342
3343 /*
3344 Trim image.
3345 */
3346 (void) SyncImageSettings(image_info,*image);
3347 trim_image=TrimImage(*image,exception);
3348 if (trim_image == (Image *) NULL)
3349 break;
3350 *image=DestroyImage(*image);
3351 *image=trim_image;
3352 break;
3353 }
3354 if (LocaleCompare("type",option+1) == 0)
3355 {
3356 ImageType
3357 type;
3358
3359 (void) SyncImageSettings(image_info,*image);
3360 if (*option == '+')
3361 type=UndefinedType;
3362 else
3363 type=(ImageType) ParseMagickOption(MagickTypeOptions,MagickFalse,
3364 argv[i+1]);
3365 (*image)->type=UndefinedType;
3366 (void) SetImageType(*image,type);
3367 InheritException(exception,&(*image)->exception);
3368 break;
3369 }
3370 break;
3371 }
3372 case 'u':
3373 {
3374 if (LocaleCompare("undercolor",option+1) == 0)
3375 {
3376 (void) QueryColorDatabase(argv[i+1],&draw_info->undercolor,
3377 exception);
3378 break;
3379 }
cristy045bd902010-01-30 18:56:24 +00003380 if (LocaleCompare("unique",option+1) == 0)
3381 {
3382 if (*option == '+')
3383 {
cristy83fae872010-04-22 15:04:16 +00003384 (void) DeleteImageArtifact(*image,"identify:unique-colors");
cristy045bd902010-01-30 18:56:24 +00003385 break;
3386 }
cristy83fae872010-04-22 15:04:16 +00003387 (void) SetImageArtifact(*image,"identify:unique-colors","true");
cristy045bd902010-01-30 18:56:24 +00003388 break;
3389 }
cristy3ed852e2009-09-05 21:47:34 +00003390 if (LocaleCompare("unique-colors",option+1) == 0)
3391 {
3392 Image
3393 *unique_image;
3394
3395 /*
3396 Unique image colors.
3397 */
3398 (void) SyncImageSettings(image_info,*image);
3399 unique_image=UniqueImageColors(*image,exception);
3400 if (unique_image == (Image *) NULL)
3401 break;
3402 *image=DestroyImage(*image);
3403 *image=unique_image;
3404 break;
3405 }
3406 if (LocaleCompare("unsharp",option+1) == 0)
3407 {
3408 Image
3409 *unsharp_image;
3410
3411 /*
3412 Unsharp mask image.
3413 */
3414 (void) SyncImageSettings(image_info,*image);
3415 flags=ParseGeometry(argv[i+1],&geometry_info);
3416 if ((flags & SigmaValue) == 0)
3417 geometry_info.sigma=1.0;
3418 if ((flags & XiValue) == 0)
3419 geometry_info.xi=1.0;
3420 if ((flags & PsiValue) == 0)
3421 geometry_info.psi=0.05;
3422 unsharp_image=UnsharpMaskImageChannel(*image,channel,
3423 geometry_info.rho,geometry_info.sigma,geometry_info.xi,
3424 geometry_info.psi,exception);
3425 if (unsharp_image == (Image *) NULL)
3426 break;
3427 *image=DestroyImage(*image);
3428 *image=unsharp_image;
3429 break;
3430 }
3431 break;
3432 }
3433 case 'v':
3434 {
3435 if (LocaleCompare("verbose",option+1) == 0)
3436 {
3437 (void) SetImageArtifact(*image,option+1,
3438 *option == '+' ? "false" : "true");
3439 break;
3440 }
3441 if (LocaleCompare("vignette",option+1) == 0)
3442 {
3443 Image
3444 *vignette_image;
3445
3446 /*
3447 Vignette image.
3448 */
3449 (void) SyncImageSettings(image_info,*image);
3450 flags=ParseGeometry(argv[i+1],&geometry_info);
3451 if ((flags & SigmaValue) == 0)
3452 geometry_info.sigma=1.0;
3453 if ((flags & XiValue) == 0)
3454 geometry_info.xi=0.1*(*image)->columns;
3455 if ((flags & PsiValue) == 0)
3456 geometry_info.psi=0.1*(*image)->rows;
3457 vignette_image=VignetteImage(*image,geometry_info.rho,
cristybb503372010-05-27 20:51:26 +00003458 geometry_info.sigma,(ssize_t) ceil(geometry_info.xi-0.5),(ssize_t)
cristy0534a6b2010-03-18 01:19:38 +00003459 ceil(geometry_info.psi-0.5),exception);
cristy3ed852e2009-09-05 21:47:34 +00003460 if (vignette_image == (Image *) NULL)
3461 break;
3462 *image=DestroyImage(*image);
3463 *image=vignette_image;
3464 break;
3465 }
3466 if (LocaleCompare("virtual-pixel",option+1) == 0)
3467 {
3468 if (*option == '+')
3469 {
3470 (void) SetImageVirtualPixelMethod(*image,
3471 UndefinedVirtualPixelMethod);
3472 break;
3473 }
3474 (void) SetImageVirtualPixelMethod(*image,(VirtualPixelMethod)
3475 ParseMagickOption(MagickVirtualPixelOptions,MagickFalse,
3476 argv[i+1]));
3477 break;
3478 }
3479 break;
3480 }
3481 case 'w':
3482 {
3483 if (LocaleCompare("wave",option+1) == 0)
3484 {
3485 Image
3486 *wave_image;
3487
3488 /*
3489 Wave image.
3490 */
3491 (void) SyncImageSettings(image_info,*image);
3492 flags=ParseGeometry(argv[i+1],&geometry_info);
3493 if ((flags & SigmaValue) == 0)
3494 geometry_info.sigma=1.0;
3495 wave_image=WaveImage(*image,geometry_info.rho,geometry_info.sigma,
3496 exception);
3497 if (wave_image == (Image *) NULL)
3498 break;
3499 *image=DestroyImage(*image);
3500 *image=wave_image;
3501 break;
3502 }
3503 if (LocaleCompare("weight",option+1) == 0)
3504 {
cristye27293e2009-12-18 02:53:20 +00003505 draw_info->weight=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00003506 if (LocaleCompare(argv[i+1],"all") == 0)
3507 draw_info->weight=0;
3508 if (LocaleCompare(argv[i+1],"bold") == 0)
3509 draw_info->weight=700;
3510 if (LocaleCompare(argv[i+1],"bolder") == 0)
3511 if (draw_info->weight <= 800)
3512 draw_info->weight+=100;
3513 if (LocaleCompare(argv[i+1],"lighter") == 0)
3514 if (draw_info->weight >= 100)
3515 draw_info->weight-=100;
3516 if (LocaleCompare(argv[i+1],"normal") == 0)
3517 draw_info->weight=400;
3518 break;
3519 }
3520 if (LocaleCompare("white-threshold",option+1) == 0)
3521 {
3522 /*
3523 White threshold image.
3524 */
3525 (void) SyncImageSettings(image_info,*image);
3526 (void) WhiteThresholdImageChannel(*image,channel,argv[i+1],
3527 exception);
3528 InheritException(exception,&(*image)->exception);
3529 break;
3530 }
3531 break;
3532 }
3533 default:
3534 break;
3535 }
3536 i+=count;
3537 }
3538 if (region_image != (Image *) NULL)
3539 {
3540 /*
3541 Composite transformed region onto image.
3542 */
3543 (void) SyncImageSettings(image_info,*image);
3544 (void) CompositeImage(region_image,(*image)->matte != MagickFalse ?
3545 OverCompositeOp : CopyCompositeOp,*image,region_geometry.x,
3546 region_geometry.y);
3547 InheritException(exception,&region_image->exception);
3548 *image=DestroyImage(*image);
3549 *image=region_image;
3550 }
3551 /*
3552 Free resources.
3553 */
3554 quantize_info=DestroyQuantizeInfo(quantize_info);
3555 draw_info=DestroyDrawInfo(draw_info);
3556 status=(*image)->exception.severity == UndefinedException ?
3557 MagickTrue : MagickFalse;
3558 return(status);
3559}
3560
3561/*
3562%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3563% %
3564% %
3565% %
3566% M o g r i f y I m a g e C o m m a n d %
3567% %
3568% %
3569% %
3570%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3571%
3572% MogrifyImageCommand() transforms an image or a sequence of images. These
3573% transforms include image scaling, image rotation, color reduction, and
3574% others. The transmogrified image overwrites the original image.
3575%
3576% The format of the MogrifyImageCommand method is:
3577%
3578% MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,int argc,
3579% const char **argv,char **metadata,ExceptionInfo *exception)
3580%
3581% A description of each parameter follows:
3582%
3583% o image_info: the image info.
3584%
3585% o argc: the number of elements in the argument vector.
3586%
3587% o argv: A text array containing the command line arguments.
3588%
3589% o metadata: any metadata is returned here.
3590%
3591% o exception: return any errors or warnings in this structure.
3592%
3593*/
3594
3595static MagickBooleanType MogrifyUsage(void)
3596{
3597 static const char
3598 *miscellaneous[]=
3599 {
3600 "-debug events display copious debugging information",
3601 "-help print program options",
3602 "-list type print a list of supported option arguments",
3603 "-log format format of debugging information",
3604 "-version print version information",
3605 (char *) NULL
3606 },
3607 *operators[]=
3608 {
3609 "-adaptive-blur geometry",
3610 " adaptively blur pixels; decrease effect near edges",
3611 "-adaptive-resize geometry",
3612 " adaptively resize image using 'mesh' interpolation",
3613 "-adaptive-sharpen geometry",
3614 " adaptively sharpen pixels; increase effect near edges",
3615 "-alpha option on, activate, off, deactivate, set, opaque, copy",
3616 " transparent, extract, background, or shape",
3617 "-annotate geometry text",
3618 " annotate the image with text",
3619 "-auto-gamma automagically adjust gamma level of image",
3620 "-auto-level automagically adjust color levels of image",
3621 "-auto-orient automagically orient (rotate) image",
3622 "-bench iterations measure performance",
3623 "-black-threshold value",
3624 " force all pixels below the threshold into black",
3625 "-blue-shift simulate a scene at nighttime in the moonlight",
3626 "-blur geometry reduce image noise and reduce detail levels",
3627 "-border geometry surround image with a border of color",
3628 "-bordercolor color border color",
cristya28d6b82010-01-11 20:03:47 +00003629 "-brightness-contrast geometry",
3630 " improve brightness / contrast of the image",
cristy3ed852e2009-09-05 21:47:34 +00003631 "-cdl filename color correct with a color decision list",
3632 "-charcoal radius simulate a charcoal drawing",
3633 "-chop geometry remove pixels from the image interior",
cristyecb0c6d2009-09-25 16:50:09 +00003634 "-clamp restrict pixel range from 0 to the quantum depth",
cristycee97112010-05-28 00:44:52 +00003635 "-clip clip along the first path from the 8BIM profile",
cristy3ed852e2009-09-05 21:47:34 +00003636 "-clip-mask filename associate a clip mask with the image",
cristycee97112010-05-28 00:44:52 +00003637 "-clip-path id clip along a named path from the 8BIM profile",
cristy3ed852e2009-09-05 21:47:34 +00003638 "-colorize value colorize the image with the fill color",
cristye6365592010-04-02 17:31:23 +00003639 "-color-matrix matrix apply color correction to the image",
cristy3ed852e2009-09-05 21:47:34 +00003640 "-contrast enhance or reduce the image contrast",
3641 "-contrast-stretch geometry",
3642 " improve contrast by `stretching' the intensity range",
3643 "-convolve coefficients",
3644 " apply a convolution kernel to the image",
3645 "-cycle amount cycle the image colormap",
3646 "-decipher filename convert cipher pixels to plain pixels",
3647 "-deskew threshold straighten an image",
3648 "-despeckle reduce the speckles within an image",
3649 "-distort method args",
3650 " distort images according to given method ad args",
3651 "-draw string annotate the image with a graphic primitive",
3652 "-edge radius apply a filter to detect edges in the image",
3653 "-encipher filename convert plain pixels to cipher pixels",
3654 "-emboss radius emboss an image",
3655 "-enhance apply a digital filter to enhance a noisy image",
3656 "-equalize perform histogram equalization to an image",
3657 "-evaluate operator value",
cristyd18ae7c2010-03-07 17:39:52 +00003658 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003659 "-extent geometry set the image size",
3660 "-extract geometry extract area from image",
3661 "-fft implements the discrete Fourier transform (DFT)",
3662 "-flip flip image vertically",
3663 "-floodfill geometry color",
3664 " floodfill the image with color",
3665 "-flop flop image horizontally",
3666 "-frame geometry surround image with an ornamental border",
cristyc2b730e2009-11-24 14:32:09 +00003667 "-function name parameters",
cristy3ed852e2009-09-05 21:47:34 +00003668 " apply function over image values",
3669 "-gamma value level of gamma correction",
3670 "-gaussian-blur geometry",
3671 " reduce image noise and reduce detail levels",
cristy901f09d2009-10-16 22:56:10 +00003672 "-geometry geometry preferred size or location of the image",
cristy3ed852e2009-09-05 21:47:34 +00003673 "-identify identify the format and characteristics of the image",
3674 "-ift implements the inverse discrete Fourier transform (DFT)",
3675 "-implode amount implode image pixels about the center",
3676 "-lat geometry local adaptive thresholding",
3677 "-layers method optimize, merge, or compare image layers",
3678 "-level value adjust the level of image contrast",
3679 "-level-colors color,color",
cristyee0f8d72009-09-19 00:58:29 +00003680 " level image with the given colors",
cristy3ed852e2009-09-05 21:47:34 +00003681 "-linear-stretch geometry",
3682 " improve contrast by `stretching with saturation'",
3683 "-liquid-rescale geometry",
3684 " rescale image with seam-carving",
3685 "-median radius apply a median filter to the image",
3686 "-modulate value vary the brightness, saturation, and hue",
3687 "-monochrome transform image to black and white",
cristy7c1b9fd2010-02-02 14:36:00 +00003688 "-morphology method kernel",
anthony29188a82010-01-22 10:12:34 +00003689 " apply a morphology method to the image",
cristy3ed852e2009-09-05 21:47:34 +00003690 "-motion-blur geometry",
3691 " simulate motion blur",
3692 "-negate replace every pixel with its complementary color ",
3693 "-noise radius add or reduce noise in an image",
3694 "-normalize transform image to span the full range of colors",
3695 "-opaque color change this color to the fill color",
3696 "-ordered-dither NxN",
3697 " add a noise pattern to the image with specific",
3698 " amplitudes",
3699 "-paint radius simulate an oil painting",
3700 "-polaroid angle simulate a Polaroid picture",
3701 "-posterize levels reduce the image to a limited number of color levels",
cristy3ed852e2009-09-05 21:47:34 +00003702 "-profile filename add, delete, or apply an image profile",
3703 "-quantize colorspace reduce colors in this colorspace",
3704 "-radial-blur angle radial blur the image",
3705 "-raise value lighten/darken image edges to create a 3-D effect",
3706 "-random-threshold low,high",
3707 " random threshold the image",
cristy3ed852e2009-09-05 21:47:34 +00003708 "-region geometry apply options to a portion of the image",
3709 "-render render vector graphics",
3710 "-repage geometry size and location of an image canvas",
3711 "-resample geometry change the resolution of an image",
3712 "-resize geometry resize the image",
3713 "-roll geometry roll an image vertically or horizontally",
3714 "-rotate degrees apply Paeth rotation to the image",
3715 "-sample geometry scale image with pixel sampling",
3716 "-scale geometry scale the image",
3717 "-segment values segment an image",
3718 "-selective-blur geometry",
3719 " selectively blur pixels within a contrast threshold",
3720 "-sepia-tone threshold",
3721 " simulate a sepia-toned photo",
3722 "-set property value set an image property",
3723 "-shade degrees shade the image using a distant light source",
3724 "-shadow geometry simulate an image shadow",
3725 "-sharpen geometry sharpen the image",
3726 "-shave geometry shave pixels from the image edges",
cristycee97112010-05-28 00:44:52 +00003727 "-shear geometry slide one edge of the image along the X or Y axis",
cristy3ed852e2009-09-05 21:47:34 +00003728 "-sigmoidal-contrast geometry",
3729 " increase the contrast without saturating highlights or shadows",
3730 "-sketch geometry simulate a pencil sketch",
3731 "-solarize threshold negate all pixels above the threshold level",
3732 "-sparse-color method args",
3733 " fill in a image based on a few color points",
3734 "-splice geometry splice the background color into the image",
3735 "-spread radius displace image pixels by a random amount",
3736 "-strip strip image of all profiles and comments",
3737 "-swirl degrees swirl image pixels about the center",
3738 "-threshold value threshold the image",
3739 "-thumbnail geometry create a thumbnail of the image",
3740 "-tile filename tile image when filling a graphic primitive",
3741 "-tint value tint the image with the fill color",
3742 "-transform affine transform image",
3743 "-transparent color make this color transparent within the image",
3744 "-transpose flip image vertically and rotate 90 degrees",
3745 "-transverse flop image horizontally and rotate 270 degrees",
3746 "-trim trim image edges",
3747 "-type type image type",
3748 "-unique-colors discard all but one of any pixel color",
3749 "-unsharp geometry sharpen the image",
3750 "-vignette geometry soften the edges of the image in vignette style",
cristycee97112010-05-28 00:44:52 +00003751 "-wave geometry alter an image along a sine wave",
cristy3ed852e2009-09-05 21:47:34 +00003752 "-white-threshold value",
3753 " force all pixels above the threshold into white",
3754 (char *) NULL
3755 },
3756 *sequence_operators[]=
3757 {
3758 "-append append an image sequence",
cristy3ed852e2009-09-05 21:47:34 +00003759 "-clut apply a color lookup table to the image",
3760 "-coalesce merge a sequence of images",
3761 "-combine combine a sequence of images",
3762 "-composite composite image",
3763 "-crop geometry cut out a rectangular region of the image",
3764 "-deconstruct break down an image sequence into constituent parts",
cristyd18ae7c2010-03-07 17:39:52 +00003765 "-evaluate-sequence operator",
3766 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003767 "-flatten flatten a sequence of images",
3768 "-fx expression apply mathematical expression to an image channel(s)",
3769 "-hald-clut apply a Hald color lookup table to the image",
3770 "-morph value morph an image sequence",
3771 "-mosaic create a mosaic from an image sequence",
cristy36b94822010-05-20 12:48:16 +00003772 "-print string interpret string and print to console",
cristy3ed852e2009-09-05 21:47:34 +00003773 "-process arguments process the image with a custom image filter",
3774 "-reverse reverse image sequence",
3775 "-separate separate an image channel into a grayscale image",
3776 "-write filename write images to this file",
3777 (char *) NULL
3778 },
3779 *settings[]=
3780 {
3781 "-adjoin join images into a single multi-image file",
3782 "-affine matrix affine transform matrix",
3783 "-alpha option activate, deactivate, reset, or set the alpha channel",
3784 "-antialias remove pixel-aliasing",
3785 "-authenticate password",
3786 " decipher image with this password",
3787 "-attenuate value lessen (or intensify) when adding noise to an image",
3788 "-background color background color",
3789 "-bias value add bias when convolving an image",
3790 "-black-point-compensation",
3791 " use black point compensation",
3792 "-blue-primary point chromaticity blue primary point",
3793 "-bordercolor color border color",
3794 "-caption string assign a caption to an image",
3795 "-channel type apply option to select image channels",
3796 "-colors value preferred number of colors in the image",
3797 "-colorspace type alternate image colorspace",
3798 "-comment string annotate image with comment",
3799 "-compose operator set image composite operator",
3800 "-compress type type of pixel compression when writing the image",
3801 "-define format:option",
3802 " define one or more image format options",
3803 "-delay value display the next image after pausing",
3804 "-density geometry horizontal and vertical density of the image",
3805 "-depth value image depth",
cristyc9b12952010-03-28 01:12:28 +00003806 "-direction type render text right-to-left or left-to-right",
cristy3ed852e2009-09-05 21:47:34 +00003807 "-display server get image or font from this X server",
3808 "-dispose method layer disposal method",
3809 "-dither method apply error diffusion to image",
3810 "-encoding type text encoding type",
3811 "-endian type endianness (MSB or LSB) of the image",
3812 "-family name render text with this font family",
3813 "-fill color color to use when filling a graphic primitive",
3814 "-filter type use this filter when resizing an image",
3815 "-font name render text with this font",
3816 "-format \"string\" output formatted image characteristics",
3817 "-fuzz distance colors within this distance are considered equal",
3818 "-gravity type horizontal and vertical text placement",
3819 "-green-primary point chromaticity green primary point",
3820 "-intent type type of rendering intent when managing the image color",
3821 "-interlace type type of image interlacing scheme",
cristyb32b90a2009-09-07 21:45:48 +00003822 "-interline-spacing value",
3823 " set the space between two text lines",
cristy3ed852e2009-09-05 21:47:34 +00003824 "-interpolate method pixel color interpolation method",
3825 "-interword-spacing value",
3826 " set the space between two words",
3827 "-kerning value set the space between two letters",
3828 "-label string assign a label to an image",
3829 "-limit type value pixel cache resource limit",
3830 "-loop iterations add Netscape loop extension to your GIF animation",
3831 "-mask filename associate a mask with the image",
3832 "-mattecolor color frame color",
3833 "-monitor monitor progress",
3834 "-orient type image orientation",
3835 "-page geometry size and location of an image canvas (setting)",
3836 "-ping efficiently determine image attributes",
3837 "-pointsize value font point size",
cristy7c1b9fd2010-02-02 14:36:00 +00003838 "-precision value maximum number of significant digits to print",
cristy3ed852e2009-09-05 21:47:34 +00003839 "-preview type image preview type",
3840 "-quality value JPEG/MIFF/PNG compression level",
3841 "-quiet suppress all warning messages",
3842 "-red-primary point chromaticity red primary point",
3843 "-regard-warnings pay attention to warning messages",
3844 "-remap filename transform image colors to match this set of colors",
3845 "-respect-parentheses settings remain in effect until parenthesis boundary",
3846 "-sampling-factor geometry",
3847 " horizontal and vertical sampling factor",
3848 "-scene value image scene number",
3849 "-seed value seed a new sequence of pseudo-random numbers",
3850 "-size geometry width and height of image",
3851 "-stretch type render text with this font stretch",
3852 "-stroke color graphic primitive stroke color",
3853 "-strokewidth value graphic primitive stroke width",
3854 "-style type render text with this font style",
3855 "-taint image as ineligible for bi-modal delegate",
3856 "-texture filename name of texture to tile onto the image background",
3857 "-tile-offset geometry",
3858 " tile offset",
3859 "-treedepth value color tree depth",
3860 "-transparent-color color",
3861 " transparent color",
3862 "-undercolor color annotation bounding box color",
3863 "-units type the units of image resolution",
3864 "-verbose print detailed information about the image",
3865 "-view FlashPix viewing transforms",
3866 "-virtual-pixel method",
3867 " virtual pixel access method",
3868 "-weight type render text with this font weight",
3869 "-white-point point chromaticity white point",
3870 (char *) NULL
3871 },
3872 *stack_operators[]=
3873 {
3874 "-clone index clone an image",
3875 "-delete index delete the image from the image sequence",
3876 "-insert index insert last image into the image sequence",
3877 "-swap indexes swap two images in the image sequence",
3878 (char *) NULL
3879 };
3880
3881 const char
3882 **p;
3883
cristybb503372010-05-27 20:51:26 +00003884 (void) printf("Version: %s\n",GetMagickVersion((size_t *) NULL));
cristy610b2e22009-10-22 14:59:43 +00003885 (void) printf("Copyright: %s\n",GetMagickCopyright());
3886 (void) printf("Features: %s\n\n",GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00003887 (void) printf("Usage: %s [options ...] file [ [options ...] file ...]\n",
3888 GetClientName());
3889 (void) printf("\nImage Settings:\n");
3890 for (p=settings; *p != (char *) NULL; p++)
3891 (void) printf(" %s\n",*p);
3892 (void) printf("\nImage Operators:\n");
3893 for (p=operators; *p != (char *) NULL; p++)
3894 (void) printf(" %s\n",*p);
3895 (void) printf("\nImage Sequence Operators:\n");
3896 for (p=sequence_operators; *p != (char *) NULL; p++)
3897 (void) printf(" %s\n",*p);
3898 (void) printf("\nImage Stack Operators:\n");
3899 for (p=stack_operators; *p != (char *) NULL; p++)
3900 (void) printf(" %s\n",*p);
3901 (void) printf("\nMiscellaneous Options:\n");
3902 for (p=miscellaneous; *p != (char *) NULL; p++)
3903 (void) printf(" %s\n",*p);
3904 (void) printf(
3905 "\nBy default, the image format of `file' is determined by its magic\n");
3906 (void) printf(
3907 "number. To specify a particular image format, precede the filename\n");
3908 (void) printf(
3909 "with an image format name and a colon (i.e. ps:image) or specify the\n");
3910 (void) printf(
3911 "image type as the filename suffix (i.e. image.ps). Specify 'file' as\n");
3912 (void) printf("'-' for standard input or output.\n");
3913 return(MagickFalse);
3914}
3915
3916WandExport MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,
3917 int argc,char **argv,char **wand_unused(metadata),ExceptionInfo *exception)
3918{
3919#define DestroyMogrify() \
3920{ \
3921 if (format != (char *) NULL) \
3922 format=DestroyString(format); \
3923 if (path != (char *) NULL) \
3924 path=DestroyString(path); \
3925 DestroyImageStack(); \
cristybb503372010-05-27 20:51:26 +00003926 for (i=0; i < (ssize_t) argc; i++) \
cristy3ed852e2009-09-05 21:47:34 +00003927 argv[i]=DestroyString(argv[i]); \
3928 argv=(char **) RelinquishMagickMemory(argv); \
3929}
3930#define ThrowMogrifyException(asperity,tag,option) \
3931{ \
3932 (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag,"`%s'", \
3933 option); \
3934 DestroyMogrify(); \
3935 return(MagickFalse); \
3936}
3937#define ThrowMogrifyInvalidArgumentException(option,argument) \
3938{ \
3939 (void) ThrowMagickException(exception,GetMagickModule(),OptionError, \
3940 "InvalidArgument","`%s': %s",argument,option); \
3941 DestroyMogrify(); \
3942 return(MagickFalse); \
3943}
3944
3945 char
3946 *format,
3947 *option,
3948 *path;
3949
3950 Image
3951 *image;
3952
3953 ImageStack
3954 image_stack[MaxImageStackDepth+1];
3955
cristybb503372010-05-27 20:51:26 +00003956 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003957 j,
3958 k;
3959
cristybb503372010-05-27 20:51:26 +00003960 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003961 i;
3962
3963 MagickBooleanType
3964 global_colormap;
3965
3966 MagickBooleanType
3967 fire,
3968 pend;
3969
3970 MagickStatusType
3971 status;
3972
3973 /*
3974 Set defaults.
3975 */
3976 assert(image_info != (ImageInfo *) NULL);
3977 assert(image_info->signature == MagickSignature);
3978 if (image_info->debug != MagickFalse)
3979 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3980 assert(exception != (ExceptionInfo *) NULL);
3981 if (argc == 2)
3982 {
3983 option=argv[1];
3984 if ((LocaleCompare("version",option+1) == 0) ||
3985 (LocaleCompare("-version",option+1) == 0))
3986 {
3987 (void) fprintf(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +00003988 GetMagickVersion((size_t *) NULL));
cristy610b2e22009-10-22 14:59:43 +00003989 (void) fprintf(stdout,"Copyright: %s\n",GetMagickCopyright());
3990 (void) fprintf(stdout,"Features: %s\n\n",GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00003991 return(MagickFalse);
3992 }
3993 }
3994 if (argc < 2)
cristy13e61a12010-02-04 20:19:00 +00003995 return(MogrifyUsage());
cristy3ed852e2009-09-05 21:47:34 +00003996 format=(char *) NULL;
3997 path=(char *) NULL;
3998 global_colormap=MagickFalse;
3999 k=0;
4000 j=1;
4001 NewImageStack();
4002 option=(char *) NULL;
4003 pend=MagickFalse;
4004 status=MagickTrue;
4005 /*
4006 Parse command line.
4007 */
4008 ReadCommandlLine(argc,&argv);
4009 status=ExpandFilenames(&argc,&argv);
4010 if (status == MagickFalse)
4011 ThrowMogrifyException(ResourceLimitError,"MemoryAllocationFailed",
4012 GetExceptionMessage(errno));
cristybb503372010-05-27 20:51:26 +00004013 for (i=1; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00004014 {
4015 option=argv[i];
4016 if (LocaleCompare(option,"(") == 0)
4017 {
4018 FireImageStack(MagickFalse,MagickTrue,pend);
4019 if (k == MaxImageStackDepth)
4020 ThrowMogrifyException(OptionError,"ParenthesisNestedTooDeeply",
4021 option);
4022 PushImageStack();
4023 continue;
4024 }
4025 if (LocaleCompare(option,")") == 0)
4026 {
4027 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
4028 if (k == 0)
4029 ThrowMogrifyException(OptionError,"UnableToParseExpression",option);
4030 PopImageStack();
4031 continue;
4032 }
4033 if (IsMagickOption(option) == MagickFalse)
4034 {
4035 char
4036 backup_filename[MaxTextExtent],
4037 *filename;
4038
4039 Image
4040 *images;
4041
4042 /*
4043 Option is a file name: begin by reading image from specified file.
4044 */
4045 FireImageStack(MagickFalse,MagickFalse,pend);
4046 filename=argv[i];
cristycee97112010-05-28 00:44:52 +00004047 if ((LocaleCompare(filename,"--") == 0) && (i < (ssize_t) (argc-1)))
cristy3ed852e2009-09-05 21:47:34 +00004048 filename=argv[++i];
4049 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
4050 images=ReadImages(image_info,exception);
4051 status&=(images != (Image *) NULL) &&
4052 (exception->severity < ErrorException);
4053 if (images == (Image *) NULL)
4054 continue;
4055 if (path != (char *) NULL)
4056 {
4057 GetPathComponent(option,TailPath,filename);
4058 (void) FormatMagickString(images->filename,MaxTextExtent,"%s%c%s",
4059 path,*DirectorySeparator,filename);
4060 }
4061 if (format != (char *) NULL)
4062 AppendImageFormat(format,images->filename);
4063 AppendImageStack(images);
4064 FinalizeImageSettings(image_info,image,MagickFalse);
4065 if (global_colormap != MagickFalse)
4066 {
4067 QuantizeInfo
4068 *quantize_info;
4069
4070 quantize_info=AcquireQuantizeInfo(image_info);
4071 (void) RemapImages(quantize_info,images,(Image *) NULL);
4072 quantize_info=DestroyQuantizeInfo(quantize_info);
4073 }
4074 *backup_filename='\0';
4075 if ((LocaleCompare(image->filename,"-") != 0) &&
4076 (IsPathWritable(image->filename) != MagickFalse))
4077 {
cristybb503372010-05-27 20:51:26 +00004078 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004079 i;
4080
4081 /*
4082 Rename image file as backup.
4083 */
4084 (void) CopyMagickString(backup_filename,image->filename,
4085 MaxTextExtent);
4086 for (i=0; i < 6; i++)
4087 {
4088 (void) ConcatenateMagickString(backup_filename,"~",MaxTextExtent);
4089 if (IsPathAccessible(backup_filename) == MagickFalse)
4090 break;
4091 }
4092 if ((IsPathAccessible(backup_filename) != MagickFalse) ||
4093 (rename(image->filename,backup_filename) != 0))
4094 *backup_filename='\0';
4095 }
4096 /*
4097 Write transmogrified image to disk.
4098 */
4099 image_info->synchronize=MagickTrue;
4100 status&=WriteImages(image_info,image,image->filename,exception);
4101 if ((status == MagickFalse) && (*backup_filename != '\0'))
4102 (void) remove(backup_filename);
4103 RemoveAllImageStack();
4104 continue;
4105 }
4106 pend=image != (Image *) NULL ? MagickTrue : MagickFalse;
4107 switch (*(option+1))
4108 {
4109 case 'a':
4110 {
4111 if (LocaleCompare("adaptive-blur",option+1) == 0)
4112 {
4113 i++;
cristybb503372010-05-27 20:51:26 +00004114 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004115 ThrowMogrifyException(OptionError,"MissingArgument",option);
4116 if (IsGeometry(argv[i]) == MagickFalse)
4117 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4118 break;
4119 }
4120 if (LocaleCompare("adaptive-resize",option+1) == 0)
4121 {
4122 i++;
cristybb503372010-05-27 20:51:26 +00004123 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004124 ThrowMogrifyException(OptionError,"MissingArgument",option);
4125 if (IsGeometry(argv[i]) == MagickFalse)
4126 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4127 break;
4128 }
4129 if (LocaleCompare("adaptive-sharpen",option+1) == 0)
4130 {
4131 i++;
cristybb503372010-05-27 20:51:26 +00004132 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004133 ThrowMogrifyException(OptionError,"MissingArgument",option);
4134 if (IsGeometry(argv[i]) == MagickFalse)
4135 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4136 break;
4137 }
4138 if (LocaleCompare("affine",option+1) == 0)
4139 {
4140 if (*option == '+')
4141 break;
4142 i++;
cristybb503372010-05-27 20:51:26 +00004143 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004144 ThrowMogrifyException(OptionError,"MissingArgument",option);
4145 if (IsGeometry(argv[i]) == MagickFalse)
4146 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4147 break;
4148 }
4149 if (LocaleCompare("alpha",option+1) == 0)
4150 {
cristybb503372010-05-27 20:51:26 +00004151 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004152 type;
4153
4154 if (*option == '+')
4155 break;
4156 i++;
cristybb503372010-05-27 20:51:26 +00004157 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004158 ThrowMogrifyException(OptionError,"MissingArgument",option);
4159 type=ParseMagickOption(MagickAlphaOptions,MagickFalse,argv[i]);
4160 if (type < 0)
4161 ThrowMogrifyException(OptionError,"UnrecognizedAlphaChannelType",
4162 argv[i]);
4163 break;
4164 }
4165 if (LocaleCompare("annotate",option+1) == 0)
4166 {
4167 if (*option == '+')
4168 break;
4169 i++;
cristybb503372010-05-27 20:51:26 +00004170 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004171 ThrowMogrifyException(OptionError,"MissingArgument",option);
4172 if (IsGeometry(argv[i]) == MagickFalse)
4173 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristybb503372010-05-27 20:51:26 +00004174 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004175 ThrowMogrifyException(OptionError,"MissingArgument",option);
4176 i++;
4177 break;
4178 }
4179 if (LocaleCompare("antialias",option+1) == 0)
4180 break;
4181 if (LocaleCompare("append",option+1) == 0)
4182 break;
4183 if (LocaleCompare("attenuate",option+1) == 0)
4184 {
4185 if (*option == '+')
4186 break;
4187 i++;
cristybb503372010-05-27 20:51:26 +00004188 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004189 ThrowMogrifyException(OptionError,"MissingArgument",option);
4190 if (IsGeometry(argv[i]) == MagickFalse)
4191 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4192 break;
4193 }
4194 if (LocaleCompare("authenticate",option+1) == 0)
4195 {
4196 if (*option == '+')
4197 break;
4198 i++;
cristybb503372010-05-27 20:51:26 +00004199 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004200 ThrowMogrifyException(OptionError,"MissingArgument",option);
4201 break;
4202 }
4203 if (LocaleCompare("auto-gamma",option+1) == 0)
4204 break;
4205 if (LocaleCompare("auto-level",option+1) == 0)
4206 break;
4207 if (LocaleCompare("auto-orient",option+1) == 0)
4208 break;
4209 if (LocaleCompare("average",option+1) == 0)
4210 break;
4211 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4212 }
4213 case 'b':
4214 {
4215 if (LocaleCompare("background",option+1) == 0)
4216 {
4217 if (*option == '+')
4218 break;
4219 i++;
cristybb503372010-05-27 20:51:26 +00004220 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004221 ThrowMogrifyException(OptionError,"MissingArgument",option);
4222 break;
4223 }
4224 if (LocaleCompare("bias",option+1) == 0)
4225 {
4226 if (*option == '+')
4227 break;
4228 i++;
cristybb503372010-05-27 20:51:26 +00004229 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004230 ThrowMogrifyException(OptionError,"MissingArgument",option);
4231 if (IsGeometry(argv[i]) == MagickFalse)
4232 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4233 break;
4234 }
4235 if (LocaleCompare("black-point-compensation",option+1) == 0)
4236 break;
4237 if (LocaleCompare("black-threshold",option+1) == 0)
4238 {
4239 if (*option == '+')
4240 break;
4241 i++;
cristybb503372010-05-27 20:51:26 +00004242 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004243 ThrowMogrifyException(OptionError,"MissingArgument",option);
4244 if (IsGeometry(argv[i]) == MagickFalse)
4245 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4246 break;
4247 }
4248 if (LocaleCompare("blue-primary",option+1) == 0)
4249 {
4250 if (*option == '+')
4251 break;
4252 i++;
cristybb503372010-05-27 20:51:26 +00004253 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004254 ThrowMogrifyException(OptionError,"MissingArgument",option);
4255 if (IsGeometry(argv[i]) == MagickFalse)
4256 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4257 break;
4258 }
4259 if (LocaleCompare("blue-shift",option+1) == 0)
4260 {
4261 i++;
cristybb503372010-05-27 20:51:26 +00004262 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004263 ThrowMogrifyException(OptionError,"MissingArgument",option);
4264 if (IsGeometry(argv[i]) == MagickFalse)
4265 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4266 break;
4267 }
4268 if (LocaleCompare("blur",option+1) == 0)
4269 {
4270 i++;
cristybb503372010-05-27 20:51:26 +00004271 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004272 ThrowMogrifyException(OptionError,"MissingArgument",option);
4273 if (IsGeometry(argv[i]) == MagickFalse)
4274 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4275 break;
4276 }
4277 if (LocaleCompare("border",option+1) == 0)
4278 {
4279 if (*option == '+')
4280 break;
4281 i++;
cristybb503372010-05-27 20:51:26 +00004282 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004283 ThrowMogrifyException(OptionError,"MissingArgument",option);
4284 if (IsGeometry(argv[i]) == MagickFalse)
4285 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4286 break;
4287 }
4288 if (LocaleCompare("bordercolor",option+1) == 0)
4289 {
4290 if (*option == '+')
4291 break;
4292 i++;
cristybb503372010-05-27 20:51:26 +00004293 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004294 ThrowMogrifyException(OptionError,"MissingArgument",option);
4295 break;
4296 }
4297 if (LocaleCompare("box",option+1) == 0)
4298 {
4299 if (*option == '+')
4300 break;
4301 i++;
cristybb503372010-05-27 20:51:26 +00004302 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004303 ThrowMogrifyException(OptionError,"MissingArgument",option);
4304 break;
4305 }
cristya28d6b82010-01-11 20:03:47 +00004306 if (LocaleCompare("brightness-contrast",option+1) == 0)
4307 {
4308 i++;
cristybb503372010-05-27 20:51:26 +00004309 if (i == (ssize_t) argc)
cristya28d6b82010-01-11 20:03:47 +00004310 ThrowMogrifyException(OptionError,"MissingArgument",option);
4311 if (IsGeometry(argv[i]) == MagickFalse)
4312 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4313 break;
4314 }
cristy3ed852e2009-09-05 21:47:34 +00004315 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4316 }
4317 case 'c':
4318 {
4319 if (LocaleCompare("cache",option+1) == 0)
4320 {
4321 if (*option == '+')
4322 break;
4323 i++;
cristybb503372010-05-27 20:51:26 +00004324 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004325 ThrowMogrifyException(OptionError,"MissingArgument",option);
4326 if (IsGeometry(argv[i]) == MagickFalse)
4327 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4328 break;
4329 }
4330 if (LocaleCompare("caption",option+1) == 0)
4331 {
4332 if (*option == '+')
4333 break;
4334 i++;
cristybb503372010-05-27 20:51:26 +00004335 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004336 ThrowMogrifyException(OptionError,"MissingArgument",option);
4337 break;
4338 }
4339 if (LocaleCompare("channel",option+1) == 0)
4340 {
cristybb503372010-05-27 20:51:26 +00004341 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004342 channel;
4343
4344 if (*option == '+')
4345 break;
4346 i++;
cristybb503372010-05-27 20:51:26 +00004347 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004348 ThrowMogrifyException(OptionError,"MissingArgument",option);
4349 channel=ParseChannelOption(argv[i]);
4350 if (channel < 0)
4351 ThrowMogrifyException(OptionError,"UnrecognizedChannelType",
4352 argv[i]);
4353 break;
4354 }
4355 if (LocaleCompare("cdl",option+1) == 0)
4356 {
4357 if (*option == '+')
4358 break;
4359 i++;
cristybb503372010-05-27 20:51:26 +00004360 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004361 ThrowMogrifyException(OptionError,"MissingArgument",option);
4362 break;
4363 }
4364 if (LocaleCompare("charcoal",option+1) == 0)
4365 {
4366 if (*option == '+')
4367 break;
4368 i++;
cristybb503372010-05-27 20:51:26 +00004369 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004370 ThrowMogrifyException(OptionError,"MissingArgument",option);
4371 if (IsGeometry(argv[i]) == MagickFalse)
4372 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4373 break;
4374 }
4375 if (LocaleCompare("chop",option+1) == 0)
4376 {
4377 if (*option == '+')
4378 break;
4379 i++;
cristybb503372010-05-27 20:51:26 +00004380 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004381 ThrowMogrifyException(OptionError,"MissingArgument",option);
4382 if (IsGeometry(argv[i]) == MagickFalse)
4383 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4384 break;
4385 }
cristy1eb45dd2009-09-25 16:38:06 +00004386 if (LocaleCompare("clamp",option+1) == 0)
4387 break;
4388 if (LocaleCompare("clip",option+1) == 0)
4389 break;
cristy3ed852e2009-09-05 21:47:34 +00004390 if (LocaleCompare("clip-mask",option+1) == 0)
4391 {
4392 if (*option == '+')
4393 break;
4394 i++;
cristybb503372010-05-27 20:51:26 +00004395 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004396 ThrowMogrifyException(OptionError,"MissingArgument",option);
4397 break;
4398 }
4399 if (LocaleCompare("clut",option+1) == 0)
4400 break;
4401 if (LocaleCompare("coalesce",option+1) == 0)
4402 break;
4403 if (LocaleCompare("colorize",option+1) == 0)
4404 {
4405 if (*option == '+')
4406 break;
4407 i++;
cristybb503372010-05-27 20:51:26 +00004408 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004409 ThrowMogrifyException(OptionError,"MissingArgument",option);
4410 if (IsGeometry(argv[i]) == MagickFalse)
4411 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4412 break;
4413 }
cristye6365592010-04-02 17:31:23 +00004414 if (LocaleCompare("color-matrix",option+1) == 0)
4415 {
4416 if (*option == '+')
4417 break;
4418 i++;
cristybb503372010-05-27 20:51:26 +00004419 if (i == (ssize_t) (argc-1))
cristye6365592010-04-02 17:31:23 +00004420 ThrowMogrifyException(OptionError,"MissingArgument",option);
4421 if (IsGeometry(argv[i]) == MagickFalse)
4422 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4423 break;
4424 }
cristy3ed852e2009-09-05 21:47:34 +00004425 if (LocaleCompare("colors",option+1) == 0)
4426 {
4427 if (*option == '+')
4428 break;
4429 i++;
cristybb503372010-05-27 20:51:26 +00004430 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004431 ThrowMogrifyException(OptionError,"MissingArgument",option);
4432 if (IsGeometry(argv[i]) == MagickFalse)
4433 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4434 break;
4435 }
4436 if (LocaleCompare("colorspace",option+1) == 0)
4437 {
cristybb503372010-05-27 20:51:26 +00004438 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004439 colorspace;
4440
4441 if (*option == '+')
4442 break;
4443 i++;
cristybb503372010-05-27 20:51:26 +00004444 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004445 ThrowMogrifyException(OptionError,"MissingArgument",option);
4446 colorspace=ParseMagickOption(MagickColorspaceOptions,MagickFalse,
4447 argv[i]);
4448 if (colorspace < 0)
4449 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
4450 argv[i]);
4451 break;
4452 }
4453 if (LocaleCompare("combine",option+1) == 0)
4454 break;
4455 if (LocaleCompare("comment",option+1) == 0)
4456 {
4457 if (*option == '+')
4458 break;
4459 i++;
cristybb503372010-05-27 20:51:26 +00004460 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004461 ThrowMogrifyException(OptionError,"MissingArgument",option);
4462 break;
4463 }
4464 if (LocaleCompare("composite",option+1) == 0)
4465 break;
4466 if (LocaleCompare("compress",option+1) == 0)
4467 {
cristybb503372010-05-27 20:51:26 +00004468 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004469 compress;
4470
4471 if (*option == '+')
4472 break;
4473 i++;
cristybb503372010-05-27 20:51:26 +00004474 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004475 ThrowMogrifyException(OptionError,"MissingArgument",option);
4476 compress=ParseMagickOption(MagickCompressOptions,MagickFalse,
4477 argv[i]);
4478 if (compress < 0)
4479 ThrowMogrifyException(OptionError,"UnrecognizedImageCompression",
4480 argv[i]);
4481 break;
4482 }
cristy22879752009-10-25 23:55:40 +00004483 if (LocaleCompare("concurrent",option+1) == 0)
4484 break;
cristy3ed852e2009-09-05 21:47:34 +00004485 if (LocaleCompare("contrast",option+1) == 0)
4486 break;
4487 if (LocaleCompare("contrast-stretch",option+1) == 0)
4488 {
4489 i++;
cristybb503372010-05-27 20:51:26 +00004490 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004491 ThrowMogrifyException(OptionError,"MissingArgument",option);
4492 if (IsGeometry(argv[i]) == MagickFalse)
4493 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4494 break;
4495 }
4496 if (LocaleCompare("convolve",option+1) == 0)
4497 {
anthony29188a82010-01-22 10:12:34 +00004498 char
4499 token[MaxTextExtent];
4500
cristy3ed852e2009-09-05 21:47:34 +00004501 if (*option == '+')
4502 break;
4503 i++;
cristybb503372010-05-27 20:51:26 +00004504 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004505 ThrowMogrifyException(OptionError,"MissingArgument",option);
anthony29188a82010-01-22 10:12:34 +00004506#if 1
cristydfbe6ca2010-03-12 14:08:17 +00004507 (void) token;
cristy3ed852e2009-09-05 21:47:34 +00004508 if (IsGeometry(argv[i]) == MagickFalse)
4509 ThrowMogrifyInvalidArgumentException(option,argv[i]);
anthony29188a82010-01-22 10:12:34 +00004510#else
4511 /* Allow the use of built-in kernels like 'gaussian'
4512 * These may not work for kernels with 'nan' values, like 'diamond'
4513 */
4514 GetMagickToken(argv[i],NULL,token);
4515 if ( isalpha((int)token[0]) )
4516 {
cristybb503372010-05-27 20:51:26 +00004517 ssize_t
anthony29188a82010-01-22 10:12:34 +00004518 op;
4519
4520 op=ParseMagickOption(MagickKernelOptions,MagickFalse,token);
4521 if (op < 0)
4522 ThrowMogrifyException(OptionError,"UnrecognizedKernelType",
4523 token);
4524 }
4525 /* geometry current returns invalid if 'nan' values are used */
4526 else if (IsGeometry(argv[i]) == MagickFalse)
4527 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4528#endif
cristy3ed852e2009-09-05 21:47:34 +00004529 break;
4530 }
4531 if (LocaleCompare("crop",option+1) == 0)
4532 {
4533 if (*option == '+')
4534 break;
4535 i++;
cristybb503372010-05-27 20:51:26 +00004536 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004537 ThrowMogrifyException(OptionError,"MissingArgument",option);
4538 if (IsGeometry(argv[i]) == MagickFalse)
4539 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4540 break;
4541 }
4542 if (LocaleCompare("cycle",option+1) == 0)
4543 {
4544 if (*option == '+')
4545 break;
4546 i++;
cristybb503372010-05-27 20:51:26 +00004547 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004548 ThrowMogrifyException(OptionError,"MissingArgument",option);
4549 if (IsGeometry(argv[i]) == MagickFalse)
4550 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4551 break;
4552 }
4553 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4554 }
4555 case 'd':
4556 {
4557 if (LocaleCompare("decipher",option+1) == 0)
4558 {
4559 if (*option == '+')
4560 break;
4561 i++;
cristybb503372010-05-27 20:51:26 +00004562 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004563 ThrowMogrifyException(OptionError,"MissingArgument",option);
4564 break;
4565 }
4566 if (LocaleCompare("deconstruct",option+1) == 0)
4567 break;
4568 if (LocaleCompare("debug",option+1) == 0)
4569 {
cristybb503372010-05-27 20:51:26 +00004570 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004571 event;
4572
4573 if (*option == '+')
4574 break;
4575 i++;
cristybb503372010-05-27 20:51:26 +00004576 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004577 ThrowMogrifyException(OptionError,"MissingArgument",option);
4578 event=ParseMagickOption(MagickLogEventOptions,MagickFalse,argv[i]);
4579 if (event < 0)
4580 ThrowMogrifyException(OptionError,"UnrecognizedEventType",
4581 argv[i]);
4582 (void) SetLogEventMask(argv[i]);
4583 break;
4584 }
4585 if (LocaleCompare("define",option+1) == 0)
4586 {
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 if (*option == '+')
4591 {
4592 const char
4593 *define;
4594
4595 define=GetImageOption(image_info,argv[i]);
4596 if (define == (const char *) NULL)
4597 ThrowMogrifyException(OptionError,"NoSuchOption",argv[i]);
4598 break;
4599 }
4600 break;
4601 }
4602 if (LocaleCompare("delay",option+1) == 0)
4603 {
4604 if (*option == '+')
4605 break;
4606 i++;
cristybb503372010-05-27 20:51:26 +00004607 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004608 ThrowMogrifyException(OptionError,"MissingArgument",option);
4609 if (IsGeometry(argv[i]) == MagickFalse)
4610 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4611 break;
4612 }
4613 if (LocaleCompare("density",option+1) == 0)
4614 {
4615 if (*option == '+')
4616 break;
4617 i++;
cristybb503372010-05-27 20:51:26 +00004618 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004619 ThrowMogrifyException(OptionError,"MissingArgument",option);
4620 if (IsGeometry(argv[i]) == MagickFalse)
4621 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4622 break;
4623 }
4624 if (LocaleCompare("depth",option+1) == 0)
4625 {
4626 if (*option == '+')
4627 break;
4628 i++;
cristybb503372010-05-27 20:51:26 +00004629 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004630 ThrowMogrifyException(OptionError,"MissingArgument",option);
4631 if (IsGeometry(argv[i]) == MagickFalse)
4632 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4633 break;
4634 }
4635 if (LocaleCompare("deskew",option+1) == 0)
4636 {
4637 if (*option == '+')
4638 break;
4639 i++;
cristybb503372010-05-27 20:51:26 +00004640 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004641 ThrowMogrifyException(OptionError,"MissingArgument",option);
4642 if (IsGeometry(argv[i]) == MagickFalse)
4643 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4644 break;
4645 }
4646 if (LocaleCompare("despeckle",option+1) == 0)
4647 break;
4648 if (LocaleCompare("dft",option+1) == 0)
4649 break;
cristyc9b12952010-03-28 01:12:28 +00004650 if (LocaleCompare("direction",option+1) == 0)
4651 {
cristybb503372010-05-27 20:51:26 +00004652 ssize_t
cristyc9b12952010-03-28 01:12:28 +00004653 direction;
4654
4655 if (*option == '+')
4656 break;
4657 i++;
cristybb503372010-05-27 20:51:26 +00004658 if (i == (ssize_t) argc)
cristyc9b12952010-03-28 01:12:28 +00004659 ThrowMogrifyException(OptionError,"MissingArgument",option);
4660 direction=ParseMagickOption(MagickDirectionOptions,MagickFalse,
4661 argv[i]);
4662 if (direction < 0)
4663 ThrowMogrifyException(OptionError,"UnrecognizedDirectionType",
4664 argv[i]);
4665 break;
4666 }
cristy3ed852e2009-09-05 21:47:34 +00004667 if (LocaleCompare("display",option+1) == 0)
4668 {
4669 if (*option == '+')
4670 break;
4671 i++;
cristybb503372010-05-27 20:51:26 +00004672 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004673 ThrowMogrifyException(OptionError,"MissingArgument",option);
4674 break;
4675 }
4676 if (LocaleCompare("dispose",option+1) == 0)
4677 {
cristybb503372010-05-27 20:51:26 +00004678 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004679 dispose;
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 dispose=ParseMagickOption(MagickDisposeOptions,MagickFalse,argv[i]);
4687 if (dispose < 0)
4688 ThrowMogrifyException(OptionError,"UnrecognizedDisposeMethod",
4689 argv[i]);
4690 break;
4691 }
4692 if (LocaleCompare("distort",option+1) == 0)
4693 {
cristybb503372010-05-27 20:51:26 +00004694 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004695 op;
4696
4697 i++;
cristybb503372010-05-27 20:51:26 +00004698 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004699 ThrowMogrifyException(OptionError,"MissingArgument",option);
4700 op=ParseMagickOption(MagickDistortOptions,MagickFalse,argv[i]);
4701 if (op < 0)
4702 ThrowMogrifyException(OptionError,"UnrecognizedDistortMethod",
4703 argv[i]);
4704 i++;
cristybb503372010-05-27 20:51:26 +00004705 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004706 ThrowMogrifyException(OptionError,"MissingArgument",option);
4707 break;
4708 }
4709 if (LocaleCompare("dither",option+1) == 0)
4710 {
cristybb503372010-05-27 20:51:26 +00004711 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004712 method;
4713
4714 if (*option == '+')
4715 break;
4716 i++;
cristybb503372010-05-27 20:51:26 +00004717 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004718 ThrowMogrifyException(OptionError,"MissingArgument",option);
4719 method=ParseMagickOption(MagickDitherOptions,MagickFalse,argv[i]);
4720 if (method < 0)
4721 ThrowMogrifyException(OptionError,"UnrecognizedDitherMethod",
4722 argv[i]);
4723 break;
4724 }
4725 if (LocaleCompare("draw",option+1) == 0)
4726 {
4727 if (*option == '+')
4728 break;
4729 i++;
cristybb503372010-05-27 20:51:26 +00004730 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004731 ThrowMogrifyException(OptionError,"MissingArgument",option);
4732 break;
4733 }
cristy22879752009-10-25 23:55:40 +00004734 if (LocaleCompare("duration",option+1) == 0)
4735 {
4736 if (*option == '+')
4737 break;
4738 i++;
cristybb503372010-05-27 20:51:26 +00004739 if (i == (ssize_t) (argc-1))
cristy22879752009-10-25 23:55:40 +00004740 ThrowMogrifyException(OptionError,"MissingArgument",option);
4741 if (IsGeometry(argv[i]) == MagickFalse)
4742 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4743 break;
4744 }
cristy3ed852e2009-09-05 21:47:34 +00004745 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4746 }
4747 case 'e':
4748 {
4749 if (LocaleCompare("edge",option+1) == 0)
4750 {
4751 if (*option == '+')
4752 break;
4753 i++;
cristybb503372010-05-27 20:51:26 +00004754 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004755 ThrowMogrifyException(OptionError,"MissingArgument",option);
4756 if (IsGeometry(argv[i]) == MagickFalse)
4757 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4758 break;
4759 }
4760 if (LocaleCompare("emboss",option+1) == 0)
4761 {
4762 if (*option == '+')
4763 break;
4764 i++;
cristybb503372010-05-27 20:51:26 +00004765 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004766 ThrowMogrifyException(OptionError,"MissingArgument",option);
4767 if (IsGeometry(argv[i]) == MagickFalse)
4768 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4769 break;
4770 }
4771 if (LocaleCompare("encipher",option+1) == 0)
4772 {
4773 if (*option == '+')
4774 break;
4775 i++;
cristybb503372010-05-27 20:51:26 +00004776 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004777 ThrowMogrifyException(OptionError,"MissingArgument",option);
4778 break;
4779 }
4780 if (LocaleCompare("encoding",option+1) == 0)
4781 {
4782 if (*option == '+')
4783 break;
4784 i++;
cristybb503372010-05-27 20:51:26 +00004785 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004786 ThrowMogrifyException(OptionError,"MissingArgument",option);
4787 break;
4788 }
4789 if (LocaleCompare("endian",option+1) == 0)
4790 {
cristybb503372010-05-27 20:51:26 +00004791 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004792 endian;
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 endian=ParseMagickOption(MagickEndianOptions,MagickFalse,argv[i]);
4800 if (endian < 0)
4801 ThrowMogrifyException(OptionError,"UnrecognizedEndianType",
4802 argv[i]);
4803 break;
4804 }
4805 if (LocaleCompare("enhance",option+1) == 0)
4806 break;
4807 if (LocaleCompare("equalize",option+1) == 0)
4808 break;
4809 if (LocaleCompare("evaluate",option+1) == 0)
4810 {
cristybb503372010-05-27 20:51:26 +00004811 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004812 op;
4813
4814 if (*option == '+')
4815 break;
4816 i++;
cristybb503372010-05-27 20:51:26 +00004817 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004818 ThrowMogrifyException(OptionError,"MissingArgument",option);
4819 op=ParseMagickOption(MagickEvaluateOptions,MagickFalse,argv[i]);
4820 if (op < 0)
4821 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4822 argv[i]);
4823 i++;
cristybb503372010-05-27 20:51:26 +00004824 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004825 ThrowMogrifyException(OptionError,"MissingArgument",option);
4826 if (IsGeometry(argv[i]) == MagickFalse)
4827 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4828 break;
4829 }
cristyd18ae7c2010-03-07 17:39:52 +00004830 if (LocaleCompare("evaluate-sequence",option+1) == 0)
4831 {
cristybb503372010-05-27 20:51:26 +00004832 ssize_t
cristyd18ae7c2010-03-07 17:39:52 +00004833 op;
4834
4835 if (*option == '+')
4836 break;
4837 i++;
cristybb503372010-05-27 20:51:26 +00004838 if (i == (ssize_t) argc)
cristyd18ae7c2010-03-07 17:39:52 +00004839 ThrowMogrifyException(OptionError,"MissingArgument",option);
4840 op=ParseMagickOption(MagickEvaluateOptions,MagickFalse,argv[i]);
4841 if (op < 0)
4842 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4843 argv[i]);
4844 break;
4845 }
cristy3ed852e2009-09-05 21:47:34 +00004846 if (LocaleCompare("extent",option+1) == 0)
4847 {
4848 if (*option == '+')
4849 break;
4850 i++;
cristybb503372010-05-27 20:51:26 +00004851 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004852 ThrowMogrifyException(OptionError,"MissingArgument",option);
4853 if (IsGeometry(argv[i]) == MagickFalse)
4854 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4855 break;
4856 }
4857 if (LocaleCompare("extract",option+1) == 0)
4858 {
4859 if (*option == '+')
4860 break;
4861 i++;
cristybb503372010-05-27 20:51:26 +00004862 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004863 ThrowMogrifyException(OptionError,"MissingArgument",option);
4864 if (IsGeometry(argv[i]) == MagickFalse)
4865 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4866 break;
4867 }
4868 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4869 }
4870 case 'f':
4871 {
4872 if (LocaleCompare("family",option+1) == 0)
4873 {
4874 if (*option == '+')
4875 break;
4876 i++;
cristybb503372010-05-27 20:51:26 +00004877 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004878 ThrowMogrifyException(OptionError,"MissingArgument",option);
4879 break;
4880 }
4881 if (LocaleCompare("fill",option+1) == 0)
4882 {
4883 if (*option == '+')
4884 break;
4885 i++;
cristybb503372010-05-27 20:51:26 +00004886 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004887 ThrowMogrifyException(OptionError,"MissingArgument",option);
4888 break;
4889 }
4890 if (LocaleCompare("filter",option+1) == 0)
4891 {
cristybb503372010-05-27 20:51:26 +00004892 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004893 filter;
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 filter=ParseMagickOption(MagickFilterOptions,MagickFalse,argv[i]);
4901 if (filter < 0)
4902 ThrowMogrifyException(OptionError,"UnrecognizedImageFilter",
4903 argv[i]);
4904 break;
4905 }
4906 if (LocaleCompare("flatten",option+1) == 0)
4907 break;
4908 if (LocaleCompare("flip",option+1) == 0)
4909 break;
4910 if (LocaleCompare("flop",option+1) == 0)
4911 break;
4912 if (LocaleCompare("floodfill",option+1) == 0)
4913 {
4914 if (*option == '+')
4915 break;
4916 i++;
cristybb503372010-05-27 20:51:26 +00004917 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004918 ThrowMogrifyException(OptionError,"MissingArgument",option);
4919 if (IsGeometry(argv[i]) == MagickFalse)
4920 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4921 i++;
cristybb503372010-05-27 20:51:26 +00004922 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004923 ThrowMogrifyException(OptionError,"MissingArgument",option);
4924 break;
4925 }
4926 if (LocaleCompare("font",option+1) == 0)
4927 {
4928 if (*option == '+')
4929 break;
4930 i++;
cristybb503372010-05-27 20:51:26 +00004931 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004932 ThrowMogrifyException(OptionError,"MissingArgument",option);
4933 break;
4934 }
4935 if (LocaleCompare("format",option+1) == 0)
4936 {
4937 (void) CopyMagickString(argv[i]+1,"sans",MaxTextExtent);
4938 (void) CloneString(&format,(char *) NULL);
4939 if (*option == '+')
4940 break;
4941 i++;
cristybb503372010-05-27 20:51:26 +00004942 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004943 ThrowMogrifyException(OptionError,"MissingArgument",option);
4944 (void) CloneString(&format,argv[i]);
4945 (void) CopyMagickString(image_info->filename,format,MaxTextExtent);
4946 (void) ConcatenateMagickString(image_info->filename,":",
4947 MaxTextExtent);
cristyd965a422010-03-03 17:47:35 +00004948 (void) SetImageInfo(image_info,0,exception);
cristy3ed852e2009-09-05 21:47:34 +00004949 if (*image_info->magick == '\0')
4950 ThrowMogrifyException(OptionError,"UnrecognizedImageFormat",
4951 format);
4952 break;
4953 }
4954 if (LocaleCompare("frame",option+1) == 0)
4955 {
4956 if (*option == '+')
4957 break;
4958 i++;
cristybb503372010-05-27 20:51:26 +00004959 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004960 ThrowMogrifyException(OptionError,"MissingArgument",option);
4961 if (IsGeometry(argv[i]) == MagickFalse)
4962 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4963 break;
4964 }
4965 if (LocaleCompare("function",option+1) == 0)
4966 {
cristybb503372010-05-27 20:51:26 +00004967 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004968 op;
4969
4970 if (*option == '+')
4971 break;
4972 i++;
cristybb503372010-05-27 20:51:26 +00004973 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004974 ThrowMogrifyException(OptionError,"MissingArgument",option);
4975 op=ParseMagickOption(MagickFunctionOptions,MagickFalse,argv[i]);
4976 if (op < 0)
4977 ThrowMogrifyException(OptionError,"UnrecognizedFunction",argv[i]);
4978 i++;
cristybb503372010-05-27 20:51:26 +00004979 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004980 ThrowMogrifyException(OptionError,"MissingArgument",option);
4981 break;
4982 }
4983 if (LocaleCompare("fuzz",option+1) == 0)
4984 {
4985 if (*option == '+')
4986 break;
4987 i++;
cristybb503372010-05-27 20:51:26 +00004988 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004989 ThrowMogrifyException(OptionError,"MissingArgument",option);
4990 if (IsGeometry(argv[i]) == MagickFalse)
4991 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4992 break;
4993 }
4994 if (LocaleCompare("fx",option+1) == 0)
4995 {
4996 if (*option == '+')
4997 break;
4998 i++;
cristybb503372010-05-27 20:51:26 +00004999 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005000 ThrowMogrifyException(OptionError,"MissingArgument",option);
5001 break;
5002 }
5003 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5004 }
5005 case 'g':
5006 {
5007 if (LocaleCompare("gamma",option+1) == 0)
5008 {
5009 i++;
cristybb503372010-05-27 20:51:26 +00005010 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005011 ThrowMogrifyException(OptionError,"MissingArgument",option);
5012 if (IsGeometry(argv[i]) == MagickFalse)
5013 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5014 break;
5015 }
5016 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
5017 (LocaleCompare("gaussian",option+1) == 0))
5018 {
5019 i++;
cristybb503372010-05-27 20:51:26 +00005020 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005021 ThrowMogrifyException(OptionError,"MissingArgument",option);
5022 if (IsGeometry(argv[i]) == MagickFalse)
5023 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5024 break;
5025 }
5026 if (LocaleCompare("geometry",option+1) == 0)
5027 {
5028 if (*option == '+')
5029 break;
5030 i++;
cristybb503372010-05-27 20:51:26 +00005031 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005032 ThrowMogrifyException(OptionError,"MissingArgument",option);
5033 if (IsGeometry(argv[i]) == MagickFalse)
5034 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5035 break;
5036 }
5037 if (LocaleCompare("gravity",option+1) == 0)
5038 {
cristybb503372010-05-27 20:51:26 +00005039 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005040 gravity;
5041
5042 if (*option == '+')
5043 break;
5044 i++;
cristybb503372010-05-27 20:51:26 +00005045 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005046 ThrowMogrifyException(OptionError,"MissingArgument",option);
5047 gravity=ParseMagickOption(MagickGravityOptions,MagickFalse,argv[i]);
5048 if (gravity < 0)
5049 ThrowMogrifyException(OptionError,"UnrecognizedGravityType",
5050 argv[i]);
5051 break;
5052 }
5053 if (LocaleCompare("green-primary",option+1) == 0)
5054 {
5055 if (*option == '+')
5056 break;
5057 i++;
cristybb503372010-05-27 20:51:26 +00005058 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005059 ThrowMogrifyException(OptionError,"MissingArgument",option);
5060 if (IsGeometry(argv[i]) == MagickFalse)
5061 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5062 break;
5063 }
5064 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5065 }
5066 case 'h':
5067 {
5068 if (LocaleCompare("hald-clut",option+1) == 0)
5069 break;
5070 if ((LocaleCompare("help",option+1) == 0) ||
5071 (LocaleCompare("-help",option+1) == 0))
5072 return(MogrifyUsage());
5073 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5074 }
5075 case 'i':
5076 {
5077 if (LocaleCompare("identify",option+1) == 0)
5078 break;
5079 if (LocaleCompare("idft",option+1) == 0)
5080 break;
5081 if (LocaleCompare("implode",option+1) == 0)
5082 {
5083 if (*option == '+')
5084 break;
5085 i++;
cristybb503372010-05-27 20:51:26 +00005086 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005087 ThrowMogrifyException(OptionError,"MissingArgument",option);
5088 if (IsGeometry(argv[i]) == MagickFalse)
5089 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5090 break;
5091 }
5092 if (LocaleCompare("intent",option+1) == 0)
5093 {
cristybb503372010-05-27 20:51:26 +00005094 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005095 intent;
5096
5097 if (*option == '+')
5098 break;
5099 i++;
cristybb503372010-05-27 20:51:26 +00005100 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005101 ThrowMogrifyException(OptionError,"MissingArgument",option);
5102 intent=ParseMagickOption(MagickIntentOptions,MagickFalse,argv[i]);
5103 if (intent < 0)
5104 ThrowMogrifyException(OptionError,"UnrecognizedIntentType",
5105 argv[i]);
5106 break;
5107 }
5108 if (LocaleCompare("interlace",option+1) == 0)
5109 {
cristybb503372010-05-27 20:51:26 +00005110 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005111 interlace;
5112
5113 if (*option == '+')
5114 break;
5115 i++;
cristybb503372010-05-27 20:51:26 +00005116 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005117 ThrowMogrifyException(OptionError,"MissingArgument",option);
5118 interlace=ParseMagickOption(MagickInterlaceOptions,MagickFalse,
5119 argv[i]);
5120 if (interlace < 0)
5121 ThrowMogrifyException(OptionError,"UnrecognizedInterlaceType",
5122 argv[i]);
5123 break;
5124 }
cristyb32b90a2009-09-07 21:45:48 +00005125 if (LocaleCompare("interline-spacing",option+1) == 0)
5126 {
5127 if (*option == '+')
5128 break;
5129 i++;
cristybb503372010-05-27 20:51:26 +00005130 if (i == (ssize_t) (argc-1))
cristyb32b90a2009-09-07 21:45:48 +00005131 ThrowMogrifyException(OptionError,"MissingArgument",option);
5132 if (IsGeometry(argv[i]) == MagickFalse)
5133 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5134 break;
5135 }
cristy3ed852e2009-09-05 21:47:34 +00005136 if (LocaleCompare("interpolate",option+1) == 0)
5137 {
cristybb503372010-05-27 20:51:26 +00005138 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005139 interpolate;
5140
5141 if (*option == '+')
5142 break;
5143 i++;
cristybb503372010-05-27 20:51:26 +00005144 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005145 ThrowMogrifyException(OptionError,"MissingArgument",option);
5146 interpolate=ParseMagickOption(MagickInterpolateOptions,MagickFalse,
5147 argv[i]);
5148 if (interpolate < 0)
5149 ThrowMogrifyException(OptionError,"UnrecognizedInterpolateMethod",
5150 argv[i]);
5151 break;
5152 }
5153 if (LocaleCompare("interword-spacing",option+1) == 0)
5154 {
5155 if (*option == '+')
5156 break;
5157 i++;
cristybb503372010-05-27 20:51:26 +00005158 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005159 ThrowMogrifyException(OptionError,"MissingArgument",option);
5160 if (IsGeometry(argv[i]) == MagickFalse)
5161 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5162 break;
5163 }
5164 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5165 }
5166 case 'k':
5167 {
5168 if (LocaleCompare("kerning",option+1) == 0)
5169 {
5170 if (*option == '+')
5171 break;
5172 i++;
cristybb503372010-05-27 20:51:26 +00005173 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005174 ThrowMogrifyException(OptionError,"MissingArgument",option);
5175 if (IsGeometry(argv[i]) == MagickFalse)
5176 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5177 break;
5178 }
5179 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5180 }
5181 case 'l':
5182 {
5183 if (LocaleCompare("label",option+1) == 0)
5184 {
5185 if (*option == '+')
5186 break;
5187 i++;
cristybb503372010-05-27 20:51:26 +00005188 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005189 ThrowMogrifyException(OptionError,"MissingArgument",option);
5190 break;
5191 }
5192 if (LocaleCompare("lat",option+1) == 0)
5193 {
5194 if (*option == '+')
5195 break;
5196 i++;
cristybb503372010-05-27 20:51:26 +00005197 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005198 ThrowMogrifyException(OptionError,"MissingArgument",option);
5199 if (IsGeometry(argv[i]) == MagickFalse)
5200 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5201 }
5202 if (LocaleCompare("layers",option+1) == 0)
5203 {
cristybb503372010-05-27 20:51:26 +00005204 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005205 type;
5206
5207 if (*option == '+')
5208 break;
5209 i++;
cristybb503372010-05-27 20:51:26 +00005210 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005211 ThrowMogrifyException(OptionError,"MissingArgument",option);
5212 type=ParseMagickOption(MagickLayerOptions,MagickFalse,argv[i]);
5213 if (type < 0)
5214 ThrowMogrifyException(OptionError,"UnrecognizedLayerMethod",
5215 argv[i]);
5216 break;
5217 }
5218 if (LocaleCompare("level",option+1) == 0)
5219 {
5220 i++;
cristybb503372010-05-27 20:51:26 +00005221 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005222 ThrowMogrifyException(OptionError,"MissingArgument",option);
5223 if (IsGeometry(argv[i]) == MagickFalse)
5224 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5225 break;
5226 }
5227 if (LocaleCompare("level-colors",option+1) == 0)
5228 {
5229 i++;
cristybb503372010-05-27 20:51:26 +00005230 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005231 ThrowMogrifyException(OptionError,"MissingArgument",option);
5232 break;
5233 }
5234 if (LocaleCompare("linewidth",option+1) == 0)
5235 {
5236 if (*option == '+')
5237 break;
5238 i++;
cristybb503372010-05-27 20:51:26 +00005239 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005240 ThrowMogrifyException(OptionError,"MissingArgument",option);
5241 if (IsGeometry(argv[i]) == MagickFalse)
5242 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5243 break;
5244 }
5245 if (LocaleCompare("limit",option+1) == 0)
5246 {
5247 char
5248 *p;
5249
5250 double
5251 value;
5252
cristybb503372010-05-27 20:51:26 +00005253 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005254 resource;
5255
5256 if (*option == '+')
5257 break;
5258 i++;
cristybb503372010-05-27 20:51:26 +00005259 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005260 ThrowMogrifyException(OptionError,"MissingArgument",option);
5261 resource=ParseMagickOption(MagickResourceOptions,MagickFalse,
5262 argv[i]);
5263 if (resource < 0)
5264 ThrowMogrifyException(OptionError,"UnrecognizedResourceType",
5265 argv[i]);
5266 i++;
cristybb503372010-05-27 20:51:26 +00005267 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005268 ThrowMogrifyException(OptionError,"MissingArgument",option);
5269 value=strtod(argv[i],&p);
5270 if ((p == argv[i]) && (LocaleCompare("unlimited",argv[i]) != 0))
5271 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5272 break;
5273 }
5274 if (LocaleCompare("liquid-rescale",option+1) == 0)
5275 {
5276 i++;
cristybb503372010-05-27 20:51:26 +00005277 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005278 ThrowMogrifyException(OptionError,"MissingArgument",option);
5279 if (IsGeometry(argv[i]) == MagickFalse)
5280 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5281 break;
5282 }
5283 if (LocaleCompare("list",option+1) == 0)
5284 {
cristybb503372010-05-27 20:51:26 +00005285 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005286 list;
5287
5288 if (*option == '+')
5289 break;
5290 i++;
cristybb503372010-05-27 20:51:26 +00005291 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005292 ThrowMogrifyException(OptionError,"MissingArgument",option);
5293 list=ParseMagickOption(MagickListOptions,MagickFalse,argv[i]);
5294 if (list < 0)
5295 ThrowMogrifyException(OptionError,"UnrecognizedListType",argv[i]);
cristyaeb2cbc2010-05-07 13:28:58 +00005296 status=MogrifyImageInfo(image_info,(int) (i-j+1),(const char **)
cristy3ed852e2009-09-05 21:47:34 +00005297 argv+j,exception);
cristyaeb2cbc2010-05-07 13:28:58 +00005298 return(status != 0 ? MagickFalse : MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00005299 }
5300 if (LocaleCompare("log",option+1) == 0)
5301 {
5302 if (*option == '+')
5303 break;
5304 i++;
cristybb503372010-05-27 20:51:26 +00005305 if ((i == (ssize_t) argc) ||
cristy3ed852e2009-09-05 21:47:34 +00005306 (strchr(argv[i],'%') == (char *) NULL))
5307 ThrowMogrifyException(OptionError,"MissingArgument",option);
5308 break;
5309 }
5310 if (LocaleCompare("loop",option+1) == 0)
5311 {
5312 if (*option == '+')
5313 break;
5314 i++;
cristybb503372010-05-27 20:51:26 +00005315 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005316 ThrowMogrifyException(OptionError,"MissingArgument",option);
5317 if (IsGeometry(argv[i]) == MagickFalse)
5318 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5319 break;
5320 }
5321 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5322 }
5323 case 'm':
5324 {
5325 if (LocaleCompare("map",option+1) == 0)
5326 {
5327 global_colormap=(*option == '+') ? MagickTrue : MagickFalse;
5328 if (*option == '+')
5329 break;
5330 i++;
cristybb503372010-05-27 20:51:26 +00005331 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005332 ThrowMogrifyException(OptionError,"MissingArgument",option);
5333 break;
5334 }
5335 if (LocaleCompare("mask",option+1) == 0)
5336 {
5337 if (*option == '+')
5338 break;
5339 i++;
cristybb503372010-05-27 20:51:26 +00005340 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005341 ThrowMogrifyException(OptionError,"MissingArgument",option);
5342 break;
5343 }
5344 if (LocaleCompare("matte",option+1) == 0)
5345 break;
5346 if (LocaleCompare("mattecolor",option+1) == 0)
5347 {
5348 if (*option == '+')
5349 break;
5350 i++;
cristybb503372010-05-27 20:51:26 +00005351 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005352 ThrowMogrifyException(OptionError,"MissingArgument",option);
5353 break;
5354 }
cristyf40785b2010-03-06 02:27:27 +00005355 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00005356 break;
cristyf40785b2010-03-06 02:27:27 +00005357 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00005358 break;
cristy3ed852e2009-09-05 21:47:34 +00005359 if (LocaleCompare("modulate",option+1) == 0)
5360 {
5361 if (*option == '+')
5362 break;
5363 i++;
cristybb503372010-05-27 20:51:26 +00005364 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005365 ThrowMogrifyException(OptionError,"MissingArgument",option);
5366 if (IsGeometry(argv[i]) == MagickFalse)
5367 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5368 break;
5369 }
5370 if (LocaleCompare("median",option+1) == 0)
5371 {
5372 if (*option == '+')
5373 break;
5374 i++;
cristybb503372010-05-27 20:51:26 +00005375 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005376 ThrowMogrifyException(OptionError,"MissingArgument",option);
5377 if (IsGeometry(argv[i]) == MagickFalse)
5378 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5379 break;
5380 }
5381 if (LocaleCompare("monitor",option+1) == 0)
5382 break;
5383 if (LocaleCompare("monochrome",option+1) == 0)
5384 break;
5385 if (LocaleCompare("morph",option+1) == 0)
5386 {
5387 if (*option == '+')
5388 break;
5389 i++;
cristybb503372010-05-27 20:51:26 +00005390 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005391 ThrowMogrifyException(OptionError,"MissingArgument",option);
5392 if (IsGeometry(argv[i]) == MagickFalse)
5393 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5394 break;
5395 }
anthony29188a82010-01-22 10:12:34 +00005396 if (LocaleCompare("morphology",option+1) == 0)
5397 {
cristybb503372010-05-27 20:51:26 +00005398 ssize_t
anthony29188a82010-01-22 10:12:34 +00005399 op;
5400
5401 char
5402 token[MaxTextExtent];
5403
5404 i++;
cristybb503372010-05-27 20:51:26 +00005405 if (i == (ssize_t) argc)
anthony29188a82010-01-22 10:12:34 +00005406 ThrowMogrifyException(OptionError,"MissingArgument",option);
5407 GetMagickToken(argv[i],NULL,token);
5408 op=ParseMagickOption(MagickMorphologyOptions,MagickFalse,token);
5409 if (op < 0)
5410 ThrowMogrifyException(OptionError,"UnrecognizedMorphologyMethod",
cristyf0c78232010-03-15 12:53:40 +00005411 token);
anthony29188a82010-01-22 10:12:34 +00005412 i++;
cristybb503372010-05-27 20:51:26 +00005413 if (i == (ssize_t) (argc-1))
anthony29188a82010-01-22 10:12:34 +00005414 ThrowMogrifyException(OptionError,"MissingArgument",option);
5415 GetMagickToken(argv[i],NULL,token);
cristyf0c78232010-03-15 12:53:40 +00005416 if (isalpha((int) ((unsigned char) *token)) != 0)
anthony29188a82010-01-22 10:12:34 +00005417 {
5418 op=ParseMagickOption(MagickKernelOptions,MagickFalse,token);
5419 if (op < 0)
5420 ThrowMogrifyException(OptionError,"UnrecognizedKernelType",
cristyf0c78232010-03-15 12:53:40 +00005421 token);
anthony29188a82010-01-22 10:12:34 +00005422 }
anthony29188a82010-01-22 10:12:34 +00005423 break;
5424 }
cristy3ed852e2009-09-05 21:47:34 +00005425 if (LocaleCompare("mosaic",option+1) == 0)
5426 break;
5427 if (LocaleCompare("motion-blur",option+1) == 0)
5428 {
5429 if (*option == '+')
5430 break;
5431 i++;
cristybb503372010-05-27 20:51:26 +00005432 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005433 ThrowMogrifyException(OptionError,"MissingArgument",option);
5434 if (IsGeometry(argv[i]) == MagickFalse)
5435 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5436 break;
5437 }
5438 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5439 }
5440 case 'n':
5441 {
5442 if (LocaleCompare("negate",option+1) == 0)
5443 break;
5444 if (LocaleCompare("noise",option+1) == 0)
5445 {
5446 i++;
cristybb503372010-05-27 20:51:26 +00005447 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005448 ThrowMogrifyException(OptionError,"MissingArgument",option);
5449 if (*option == '+')
5450 {
cristybb503372010-05-27 20:51:26 +00005451 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005452 noise;
5453
5454 noise=ParseMagickOption(MagickNoiseOptions,MagickFalse,argv[i]);
5455 if (noise < 0)
5456 ThrowMogrifyException(OptionError,"UnrecognizedNoiseType",
5457 argv[i]);
5458 break;
5459 }
5460 if (IsGeometry(argv[i]) == MagickFalse)
5461 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5462 break;
5463 }
5464 if (LocaleCompare("noop",option+1) == 0)
5465 break;
5466 if (LocaleCompare("normalize",option+1) == 0)
5467 break;
5468 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5469 }
5470 case 'o':
5471 {
5472 if (LocaleCompare("opaque",option+1) == 0)
5473 {
cristy3ed852e2009-09-05 21:47:34 +00005474 i++;
cristybb503372010-05-27 20:51:26 +00005475 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005476 ThrowMogrifyException(OptionError,"MissingArgument",option);
5477 break;
5478 }
5479 if (LocaleCompare("ordered-dither",option+1) == 0)
5480 {
5481 if (*option == '+')
5482 break;
5483 i++;
cristybb503372010-05-27 20:51:26 +00005484 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005485 ThrowMogrifyException(OptionError,"MissingArgument",option);
5486 break;
5487 }
5488 if (LocaleCompare("orient",option+1) == 0)
5489 {
cristybb503372010-05-27 20:51:26 +00005490 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005491 orientation;
5492
5493 orientation=UndefinedOrientation;
5494 if (*option == '+')
5495 break;
5496 i++;
cristybb503372010-05-27 20:51:26 +00005497 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005498 ThrowMogrifyException(OptionError,"MissingArgument",option);
5499 orientation=ParseMagickOption(MagickOrientationOptions,MagickFalse,
5500 argv[i]);
5501 if (orientation < 0)
5502 ThrowMogrifyException(OptionError,"UnrecognizedImageOrientation",
5503 argv[i]);
5504 break;
5505 }
5506 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5507 }
5508 case 'p':
5509 {
5510 if (LocaleCompare("page",option+1) == 0)
5511 {
5512 if (*option == '+')
5513 break;
5514 i++;
cristybb503372010-05-27 20:51:26 +00005515 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005516 ThrowMogrifyException(OptionError,"MissingArgument",option);
5517 break;
5518 }
5519 if (LocaleCompare("paint",option+1) == 0)
5520 {
5521 if (*option == '+')
5522 break;
5523 i++;
cristybb503372010-05-27 20:51:26 +00005524 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005525 ThrowMogrifyException(OptionError,"MissingArgument",option);
5526 if (IsGeometry(argv[i]) == MagickFalse)
5527 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5528 break;
5529 }
5530 if (LocaleCompare("path",option+1) == 0)
5531 {
5532 (void) CloneString(&path,(char *) NULL);
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 (void) CloneString(&path,argv[i]);
5539 break;
5540 }
5541 if (LocaleCompare("pointsize",option+1) == 0)
5542 {
5543 if (*option == '+')
5544 break;
5545 i++;
cristybb503372010-05-27 20:51:26 +00005546 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005547 ThrowMogrifyException(OptionError,"MissingArgument",option);
5548 if (IsGeometry(argv[i]) == MagickFalse)
5549 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5550 break;
5551 }
5552 if (LocaleCompare("polaroid",option+1) == 0)
5553 {
5554 if (*option == '+')
5555 break;
5556 i++;
cristybb503372010-05-27 20:51:26 +00005557 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005558 ThrowMogrifyException(OptionError,"MissingArgument",option);
5559 if (IsGeometry(argv[i]) == MagickFalse)
5560 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5561 break;
5562 }
5563 if (LocaleCompare("posterize",option+1) == 0)
5564 {
5565 if (*option == '+')
5566 break;
5567 i++;
cristybb503372010-05-27 20:51:26 +00005568 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005569 ThrowMogrifyException(OptionError,"MissingArgument",option);
5570 if (IsGeometry(argv[i]) == MagickFalse)
5571 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5572 break;
5573 }
cristye7f51092010-01-17 00:39:37 +00005574 if (LocaleCompare("precision",option+1) == 0)
5575 {
5576 if (*option == '+')
5577 break;
5578 i++;
cristybb503372010-05-27 20:51:26 +00005579 if (i == (ssize_t) argc)
cristye7f51092010-01-17 00:39:37 +00005580 ThrowMogrifyException(OptionError,"MissingArgument",option);
5581 if (IsGeometry(argv[i]) == MagickFalse)
5582 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5583 break;
5584 }
cristy3ed852e2009-09-05 21:47:34 +00005585 if (LocaleCompare("print",option+1) == 0)
5586 {
5587 if (*option == '+')
5588 break;
5589 i++;
cristybb503372010-05-27 20:51:26 +00005590 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005591 ThrowMogrifyException(OptionError,"MissingArgument",option);
5592 break;
5593 }
5594 if (LocaleCompare("process",option+1) == 0)
5595 {
5596 if (*option == '+')
5597 break;
5598 i++;
cristybb503372010-05-27 20:51:26 +00005599 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005600 ThrowMogrifyException(OptionError,"MissingArgument",option);
5601 break;
5602 }
5603 if (LocaleCompare("profile",option+1) == 0)
5604 {
5605 i++;
cristybb503372010-05-27 20:51:26 +00005606 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005607 ThrowMogrifyException(OptionError,"MissingArgument",option);
5608 break;
5609 }
5610 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5611 }
5612 case 'q':
5613 {
5614 if (LocaleCompare("quality",option+1) == 0)
5615 {
5616 if (*option == '+')
5617 break;
5618 i++;
cristybb503372010-05-27 20:51:26 +00005619 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005620 ThrowMogrifyException(OptionError,"MissingArgument",option);
5621 if (IsGeometry(argv[i]) == MagickFalse)
5622 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5623 break;
5624 }
5625 if (LocaleCompare("quantize",option+1) == 0)
5626 {
cristybb503372010-05-27 20:51:26 +00005627 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005628 colorspace;
5629
5630 if (*option == '+')
5631 break;
5632 i++;
cristybb503372010-05-27 20:51:26 +00005633 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005634 ThrowMogrifyException(OptionError,"MissingArgument",option);
5635 colorspace=ParseMagickOption(MagickColorspaceOptions,MagickFalse,
5636 argv[i]);
5637 if (colorspace < 0)
5638 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
5639 argv[i]);
5640 break;
5641 }
5642 if (LocaleCompare("quiet",option+1) == 0)
5643 break;
5644 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5645 }
5646 case 'r':
5647 {
5648 if (LocaleCompare("radial-blur",option+1) == 0)
5649 {
5650 i++;
cristybb503372010-05-27 20:51:26 +00005651 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005652 ThrowMogrifyException(OptionError,"MissingArgument",option);
5653 if (IsGeometry(argv[i]) == MagickFalse)
5654 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5655 break;
5656 }
5657 if (LocaleCompare("raise",option+1) == 0)
5658 {
5659 i++;
cristybb503372010-05-27 20:51:26 +00005660 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005661 ThrowMogrifyException(OptionError,"MissingArgument",option);
5662 if (IsGeometry(argv[i]) == MagickFalse)
5663 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5664 break;
5665 }
5666 if (LocaleCompare("random-threshold",option+1) == 0)
5667 {
5668 if (*option == '+')
5669 break;
5670 i++;
cristybb503372010-05-27 20:51:26 +00005671 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005672 ThrowMogrifyException(OptionError,"MissingArgument",option);
5673 if (IsGeometry(argv[i]) == MagickFalse)
5674 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5675 break;
5676 }
cristye6365592010-04-02 17:31:23 +00005677 if (LocaleCompare("recolor",option+1) == 0)
5678 {
5679 if (*option == '+')
5680 break;
5681 i++;
cristybb503372010-05-27 20:51:26 +00005682 if (i == (ssize_t) (argc-1))
cristye6365592010-04-02 17:31:23 +00005683 ThrowMogrifyException(OptionError,"MissingArgument",option);
5684 if (IsGeometry(argv[i]) == MagickFalse)
5685 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5686 break;
5687 }
cristy3ed852e2009-09-05 21:47:34 +00005688 if (LocaleCompare("red-primary",option+1) == 0)
5689 {
5690 if (*option == '+')
5691 break;
5692 i++;
cristybb503372010-05-27 20:51:26 +00005693 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005694 ThrowMogrifyException(OptionError,"MissingArgument",option);
5695 if (IsGeometry(argv[i]) == MagickFalse)
5696 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5697 }
cristy9f2083a2010-04-22 19:48:05 +00005698 if (LocaleCompare("regard-warnings",option+1) == 0)
5699 break;
cristy3ed852e2009-09-05 21:47:34 +00005700 if (LocaleCompare("region",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 break;
5710 }
cristyf0c78232010-03-15 12:53:40 +00005711 if (LocaleCompare("remap",option+1) == 0)
5712 {
5713 if (*option == '+')
5714 break;
5715 i++;
cristybb503372010-05-27 20:51:26 +00005716 if (i == (ssize_t) (argc-1))
cristyf0c78232010-03-15 12:53:40 +00005717 ThrowMogrifyException(OptionError,"MissingArgument",option);
5718 break;
5719 }
cristy3ed852e2009-09-05 21:47:34 +00005720 if (LocaleCompare("render",option+1) == 0)
5721 break;
5722 if (LocaleCompare("repage",option+1) == 0)
5723 {
5724 if (*option == '+')
5725 break;
5726 i++;
cristybb503372010-05-27 20:51:26 +00005727 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005728 ThrowMogrifyException(OptionError,"MissingArgument",option);
5729 if (IsGeometry(argv[i]) == MagickFalse)
5730 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5731 break;
5732 }
5733 if (LocaleCompare("resample",option+1) == 0)
5734 {
5735 if (*option == '+')
5736 break;
5737 i++;
cristybb503372010-05-27 20:51:26 +00005738 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005739 ThrowMogrifyException(OptionError,"MissingArgument",option);
5740 if (IsGeometry(argv[i]) == MagickFalse)
5741 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5742 break;
5743 }
5744 if (LocaleCompare("resize",option+1) == 0)
5745 {
5746 if (*option == '+')
5747 break;
5748 i++;
cristybb503372010-05-27 20:51:26 +00005749 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005750 ThrowMogrifyException(OptionError,"MissingArgument",option);
5751 if (IsGeometry(argv[i]) == MagickFalse)
5752 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5753 break;
5754 }
5755 if (LocaleCompare("reverse",option+1) == 0)
5756 break;
5757 if (LocaleCompare("roll",option+1) == 0)
5758 {
5759 if (*option == '+')
5760 break;
5761 i++;
cristybb503372010-05-27 20:51:26 +00005762 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005763 ThrowMogrifyException(OptionError,"MissingArgument",option);
5764 if (IsGeometry(argv[i]) == MagickFalse)
5765 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5766 break;
5767 }
5768 if (LocaleCompare("rotate",option+1) == 0)
5769 {
5770 i++;
cristybb503372010-05-27 20:51:26 +00005771 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005772 ThrowMogrifyException(OptionError,"MissingArgument",option);
5773 if (IsGeometry(argv[i]) == MagickFalse)
5774 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5775 break;
5776 }
5777 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5778 }
5779 case 's':
5780 {
5781 if (LocaleCompare("sample",option+1) == 0)
5782 {
5783 if (*option == '+')
5784 break;
5785 i++;
cristybb503372010-05-27 20:51:26 +00005786 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005787 ThrowMogrifyException(OptionError,"MissingArgument",option);
5788 if (IsGeometry(argv[i]) == MagickFalse)
5789 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5790 break;
5791 }
5792 if (LocaleCompare("sampling-factor",option+1) == 0)
5793 {
5794 if (*option == '+')
5795 break;
5796 i++;
cristybb503372010-05-27 20:51:26 +00005797 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005798 ThrowMogrifyException(OptionError,"MissingArgument",option);
5799 if (IsGeometry(argv[i]) == MagickFalse)
5800 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5801 break;
5802 }
5803 if (LocaleCompare("scale",option+1) == 0)
5804 {
5805 if (*option == '+')
5806 break;
5807 i++;
cristybb503372010-05-27 20:51:26 +00005808 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005809 ThrowMogrifyException(OptionError,"MissingArgument",option);
5810 if (IsGeometry(argv[i]) == MagickFalse)
5811 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5812 break;
5813 }
5814 if (LocaleCompare("scene",option+1) == 0)
5815 {
5816 if (*option == '+')
5817 break;
5818 i++;
cristybb503372010-05-27 20:51:26 +00005819 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005820 ThrowMogrifyException(OptionError,"MissingArgument",option);
5821 if (IsGeometry(argv[i]) == MagickFalse)
5822 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5823 break;
5824 }
5825 if (LocaleCompare("seed",option+1) == 0)
5826 {
5827 if (*option == '+')
5828 break;
5829 i++;
cristybb503372010-05-27 20:51:26 +00005830 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005831 ThrowMogrifyException(OptionError,"MissingArgument",option);
5832 if (IsGeometry(argv[i]) == MagickFalse)
5833 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5834 break;
5835 }
5836 if (LocaleCompare("segment",option+1) == 0)
5837 {
5838 if (*option == '+')
5839 break;
5840 i++;
cristybb503372010-05-27 20:51:26 +00005841 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005842 ThrowMogrifyException(OptionError,"MissingArgument",option);
5843 if (IsGeometry(argv[i]) == MagickFalse)
5844 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5845 break;
5846 }
5847 if (LocaleCompare("selective-blur",option+1) == 0)
5848 {
5849 i++;
cristybb503372010-05-27 20:51:26 +00005850 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005851 ThrowMogrifyException(OptionError,"MissingArgument",option);
5852 if (IsGeometry(argv[i]) == MagickFalse)
5853 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5854 break;
5855 }
5856 if (LocaleCompare("separate",option+1) == 0)
5857 break;
5858 if (LocaleCompare("sepia-tone",option+1) == 0)
5859 {
5860 if (*option == '+')
5861 break;
5862 i++;
cristybb503372010-05-27 20:51:26 +00005863 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005864 ThrowMogrifyException(OptionError,"MissingArgument",option);
5865 if (IsGeometry(argv[i]) == MagickFalse)
5866 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5867 break;
5868 }
5869 if (LocaleCompare("set",option+1) == 0)
5870 {
5871 i++;
cristybb503372010-05-27 20:51:26 +00005872 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005873 ThrowMogrifyException(OptionError,"MissingArgument",option);
5874 if (*option == '+')
5875 break;
5876 i++;
cristybb503372010-05-27 20:51:26 +00005877 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005878 ThrowMogrifyException(OptionError,"MissingArgument",option);
5879 break;
5880 }
5881 if (LocaleCompare("shade",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 (IsGeometry(argv[i]) == MagickFalse)
5887 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5888 break;
5889 }
5890 if (LocaleCompare("shadow",option+1) == 0)
5891 {
5892 if (*option == '+')
5893 break;
5894 i++;
cristybb503372010-05-27 20:51:26 +00005895 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005896 ThrowMogrifyException(OptionError,"MissingArgument",option);
5897 if (IsGeometry(argv[i]) == MagickFalse)
5898 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5899 break;
5900 }
5901 if (LocaleCompare("sharpen",option+1) == 0)
5902 {
5903 i++;
cristybb503372010-05-27 20:51:26 +00005904 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005905 ThrowMogrifyException(OptionError,"MissingArgument",option);
5906 if (IsGeometry(argv[i]) == MagickFalse)
5907 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5908 break;
5909 }
5910 if (LocaleCompare("shave",option+1) == 0)
5911 {
5912 if (*option == '+')
5913 break;
5914 i++;
cristybb503372010-05-27 20:51:26 +00005915 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005916 ThrowMogrifyException(OptionError,"MissingArgument",option);
5917 if (IsGeometry(argv[i]) == MagickFalse)
5918 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5919 break;
5920 }
5921 if (LocaleCompare("shear",option+1) == 0)
5922 {
5923 i++;
cristybb503372010-05-27 20:51:26 +00005924 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005925 ThrowMogrifyException(OptionError,"MissingArgument",option);
5926 if (IsGeometry(argv[i]) == MagickFalse)
5927 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5928 break;
5929 }
5930 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
5931 {
5932 i++;
cristybb503372010-05-27 20:51:26 +00005933 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005934 ThrowMogrifyException(OptionError,"MissingArgument",option);
5935 if (IsGeometry(argv[i]) == MagickFalse)
5936 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5937 break;
5938 }
5939 if (LocaleCompare("size",option+1) == 0)
5940 {
5941 if (*option == '+')
5942 break;
5943 i++;
cristybb503372010-05-27 20:51:26 +00005944 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005945 ThrowMogrifyException(OptionError,"MissingArgument",option);
5946 if (IsGeometry(argv[i]) == MagickFalse)
5947 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5948 break;
5949 }
5950 if (LocaleCompare("sketch",option+1) == 0)
5951 {
5952 if (*option == '+')
5953 break;
5954 i++;
cristybb503372010-05-27 20:51:26 +00005955 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005956 ThrowMogrifyException(OptionError,"MissingArgument",option);
5957 if (IsGeometry(argv[i]) == MagickFalse)
5958 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5959 break;
5960 }
5961 if (LocaleCompare("solarize",option+1) == 0)
5962 {
5963 if (*option == '+')
5964 break;
5965 i++;
cristybb503372010-05-27 20:51:26 +00005966 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005967 ThrowMogrifyException(OptionError,"MissingArgument",option);
5968 if (IsGeometry(argv[i]) == MagickFalse)
5969 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5970 break;
5971 }
5972 if (LocaleCompare("sparse-color",option+1) == 0)
5973 {
cristybb503372010-05-27 20:51:26 +00005974 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005975 op;
5976
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 op=ParseMagickOption(MagickSparseColorOptions,MagickFalse,argv[i]);
5981 if (op < 0)
5982 ThrowMogrifyException(OptionError,"UnrecognizedSparseColorMethod",
5983 argv[i]);
5984 i++;
cristybb503372010-05-27 20:51:26 +00005985 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005986 ThrowMogrifyException(OptionError,"MissingArgument",option);
5987 break;
5988 }
5989 if (LocaleCompare("spread",option+1) == 0)
5990 {
5991 if (*option == '+')
5992 break;
5993 i++;
cristybb503372010-05-27 20:51:26 +00005994 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005995 ThrowMogrifyException(OptionError,"MissingArgument",option);
5996 if (IsGeometry(argv[i]) == MagickFalse)
5997 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5998 break;
5999 }
6000 if (LocaleCompare("stretch",option+1) == 0)
6001 {
cristybb503372010-05-27 20:51:26 +00006002 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006003 stretch;
6004
6005 if (*option == '+')
6006 break;
6007 i++;
cristybb503372010-05-27 20:51:26 +00006008 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006009 ThrowMogrifyException(OptionError,"MissingArgument",option);
6010 stretch=ParseMagickOption(MagickStretchOptions,MagickFalse,argv[i]);
6011 if (stretch < 0)
6012 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
6013 argv[i]);
6014 break;
6015 }
6016 if (LocaleCompare("strip",option+1) == 0)
6017 break;
6018 if (LocaleCompare("stroke",option+1) == 0)
6019 {
6020 if (*option == '+')
6021 break;
6022 i++;
cristybb503372010-05-27 20:51:26 +00006023 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006024 ThrowMogrifyException(OptionError,"MissingArgument",option);
6025 break;
6026 }
6027 if (LocaleCompare("strokewidth",option+1) == 0)
6028 {
6029 if (*option == '+')
6030 break;
6031 i++;
cristybb503372010-05-27 20:51:26 +00006032 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006033 ThrowMogrifyException(OptionError,"MissingArgument",option);
6034 if (IsGeometry(argv[i]) == MagickFalse)
6035 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6036 break;
6037 }
6038 if (LocaleCompare("style",option+1) == 0)
6039 {
cristybb503372010-05-27 20:51:26 +00006040 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006041 style;
6042
6043 if (*option == '+')
6044 break;
6045 i++;
cristybb503372010-05-27 20:51:26 +00006046 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006047 ThrowMogrifyException(OptionError,"MissingArgument",option);
6048 style=ParseMagickOption(MagickStyleOptions,MagickFalse,argv[i]);
6049 if (style < 0)
6050 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
6051 argv[i]);
6052 break;
6053 }
6054 if (LocaleCompare("swirl",option+1) == 0)
6055 {
6056 if (*option == '+')
6057 break;
6058 i++;
cristybb503372010-05-27 20:51:26 +00006059 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006060 ThrowMogrifyException(OptionError,"MissingArgument",option);
6061 if (IsGeometry(argv[i]) == MagickFalse)
6062 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6063 break;
6064 }
6065 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6066 }
6067 case 't':
6068 {
6069 if (LocaleCompare("taint",option+1) == 0)
6070 break;
6071 if (LocaleCompare("texture",option+1) == 0)
6072 {
6073 if (*option == '+')
6074 break;
6075 i++;
cristybb503372010-05-27 20:51:26 +00006076 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006077 ThrowMogrifyException(OptionError,"MissingArgument",option);
6078 break;
6079 }
6080 if (LocaleCompare("tile",option+1) == 0)
6081 {
6082 if (*option == '+')
6083 break;
6084 i++;
cristybb503372010-05-27 20:51:26 +00006085 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006086 ThrowMogrifyException(OptionError,"MissingArgument",option);
6087 break;
6088 }
6089 if (LocaleCompare("tile-offset",option+1) == 0)
6090 {
6091 if (*option == '+')
6092 break;
6093 i++;
cristybb503372010-05-27 20:51:26 +00006094 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006095 ThrowMogrifyException(OptionError,"MissingArgument",option);
6096 if (IsGeometry(argv[i]) == MagickFalse)
6097 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6098 break;
6099 }
6100 if (LocaleCompare("tint",option+1) == 0)
6101 {
6102 if (*option == '+')
6103 break;
6104 i++;
cristybb503372010-05-27 20:51:26 +00006105 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006106 ThrowMogrifyException(OptionError,"MissingArgument",option);
6107 if (IsGeometry(argv[i]) == MagickFalse)
6108 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6109 break;
6110 }
6111 if (LocaleCompare("transform",option+1) == 0)
6112 break;
6113 if (LocaleCompare("transpose",option+1) == 0)
6114 break;
6115 if (LocaleCompare("transverse",option+1) == 0)
6116 break;
6117 if (LocaleCompare("threshold",option+1) == 0)
6118 {
6119 if (*option == '+')
6120 break;
6121 i++;
cristybb503372010-05-27 20:51:26 +00006122 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006123 ThrowMogrifyException(OptionError,"MissingArgument",option);
6124 if (IsGeometry(argv[i]) == MagickFalse)
6125 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6126 break;
6127 }
6128 if (LocaleCompare("thumbnail",option+1) == 0)
6129 {
6130 if (*option == '+')
6131 break;
6132 i++;
cristybb503372010-05-27 20:51:26 +00006133 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006134 ThrowMogrifyException(OptionError,"MissingArgument",option);
6135 if (IsGeometry(argv[i]) == MagickFalse)
6136 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6137 break;
6138 }
6139 if (LocaleCompare("transparent",option+1) == 0)
6140 {
6141 i++;
cristybb503372010-05-27 20:51:26 +00006142 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006143 ThrowMogrifyException(OptionError,"MissingArgument",option);
6144 break;
6145 }
6146 if (LocaleCompare("transparent-color",option+1) == 0)
6147 {
6148 if (*option == '+')
6149 break;
6150 i++;
cristybb503372010-05-27 20:51:26 +00006151 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006152 ThrowMogrifyException(OptionError,"MissingArgument",option);
6153 break;
6154 }
6155 if (LocaleCompare("treedepth",option+1) == 0)
6156 {
6157 if (*option == '+')
6158 break;
6159 i++;
cristybb503372010-05-27 20:51:26 +00006160 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006161 ThrowMogrifyException(OptionError,"MissingArgument",option);
6162 if (IsGeometry(argv[i]) == MagickFalse)
6163 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6164 break;
6165 }
6166 if (LocaleCompare("trim",option+1) == 0)
6167 break;
6168 if (LocaleCompare("type",option+1) == 0)
6169 {
cristybb503372010-05-27 20:51:26 +00006170 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006171 type;
6172
6173 if (*option == '+')
6174 break;
6175 i++;
cristybb503372010-05-27 20:51:26 +00006176 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006177 ThrowMogrifyException(OptionError,"MissingArgument",option);
6178 type=ParseMagickOption(MagickTypeOptions,MagickFalse,argv[i]);
6179 if (type < 0)
6180 ThrowMogrifyException(OptionError,"UnrecognizedImageType",
6181 argv[i]);
6182 break;
6183 }
6184 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6185 }
6186 case 'u':
6187 {
6188 if (LocaleCompare("undercolor",option+1) == 0)
6189 {
6190 if (*option == '+')
6191 break;
6192 i++;
cristybb503372010-05-27 20:51:26 +00006193 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006194 ThrowMogrifyException(OptionError,"MissingArgument",option);
6195 break;
6196 }
6197 if (LocaleCompare("unique-colors",option+1) == 0)
6198 break;
6199 if (LocaleCompare("units",option+1) == 0)
6200 {
cristybb503372010-05-27 20:51:26 +00006201 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006202 units;
6203
6204 if (*option == '+')
6205 break;
6206 i++;
cristybb503372010-05-27 20:51:26 +00006207 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006208 ThrowMogrifyException(OptionError,"MissingArgument",option);
6209 units=ParseMagickOption(MagickResolutionOptions,MagickFalse,
6210 argv[i]);
6211 if (units < 0)
6212 ThrowMogrifyException(OptionError,"UnrecognizedUnitsType",
6213 argv[i]);
6214 break;
6215 }
6216 if (LocaleCompare("unsharp",option+1) == 0)
6217 {
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 if (IsGeometry(argv[i]) == MagickFalse)
6222 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6223 break;
6224 }
6225 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6226 }
6227 case 'v':
6228 {
6229 if (LocaleCompare("verbose",option+1) == 0)
6230 {
6231 image_info->verbose=(*option == '-') ? MagickTrue : MagickFalse;
6232 break;
6233 }
6234 if ((LocaleCompare("version",option+1) == 0) ||
6235 (LocaleCompare("-version",option+1) == 0))
6236 {
6237 (void) fprintf(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +00006238 GetMagickVersion((size_t *) NULL));
cristy610b2e22009-10-22 14:59:43 +00006239 (void) fprintf(stdout,"Copyright: %s\n",GetMagickCopyright());
6240 (void) fprintf(stdout,"Features: %s\n\n",GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00006241 break;
6242 }
6243 if (LocaleCompare("view",option+1) == 0)
6244 {
6245 if (*option == '+')
6246 break;
6247 i++;
cristybb503372010-05-27 20:51:26 +00006248 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006249 ThrowMogrifyException(OptionError,"MissingArgument",option);
6250 break;
6251 }
6252 if (LocaleCompare("vignette",option+1) == 0)
6253 {
6254 if (*option == '+')
6255 break;
6256 i++;
cristybb503372010-05-27 20:51:26 +00006257 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006258 ThrowMogrifyException(OptionError,"MissingArgument",option);
6259 if (IsGeometry(argv[i]) == MagickFalse)
6260 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6261 break;
6262 }
6263 if (LocaleCompare("virtual-pixel",option+1) == 0)
6264 {
cristybb503372010-05-27 20:51:26 +00006265 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006266 method;
6267
6268 if (*option == '+')
6269 break;
6270 i++;
cristybb503372010-05-27 20:51:26 +00006271 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006272 ThrowMogrifyException(OptionError,"MissingArgument",option);
6273 method=ParseMagickOption(MagickVirtualPixelOptions,MagickFalse,
6274 argv[i]);
6275 if (method < 0)
6276 ThrowMogrifyException(OptionError,
6277 "UnrecognizedVirtualPixelMethod",argv[i]);
6278 break;
6279 }
6280 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6281 }
6282 case 'w':
6283 {
6284 if (LocaleCompare("wave",option+1) == 0)
6285 {
6286 i++;
cristybb503372010-05-27 20:51:26 +00006287 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006288 ThrowMogrifyException(OptionError,"MissingArgument",option);
6289 if (IsGeometry(argv[i]) == MagickFalse)
6290 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6291 break;
6292 }
6293 if (LocaleCompare("weight",option+1) == 0)
6294 {
6295 if (*option == '+')
6296 break;
6297 i++;
cristybb503372010-05-27 20:51:26 +00006298 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006299 ThrowMogrifyException(OptionError,"MissingArgument",option);
6300 break;
6301 }
6302 if (LocaleCompare("white-point",option+1) == 0)
6303 {
6304 if (*option == '+')
6305 break;
6306 i++;
cristybb503372010-05-27 20:51:26 +00006307 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006308 ThrowMogrifyException(OptionError,"MissingArgument",option);
6309 if (IsGeometry(argv[i]) == MagickFalse)
6310 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6311 break;
6312 }
6313 if (LocaleCompare("white-threshold",option+1) == 0)
6314 {
6315 if (*option == '+')
6316 break;
6317 i++;
cristybb503372010-05-27 20:51:26 +00006318 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006319 ThrowMogrifyException(OptionError,"MissingArgument",option);
6320 if (IsGeometry(argv[i]) == MagickFalse)
6321 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6322 break;
6323 }
6324 if (LocaleCompare("write",option+1) == 0)
6325 {
6326 i++;
cristybb503372010-05-27 20:51:26 +00006327 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006328 ThrowMogrifyException(OptionError,"MissingArgument",option);
6329 break;
6330 }
6331 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6332 }
6333 case '?':
6334 break;
6335 default:
6336 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6337 }
6338 fire=ParseMagickOption(MagickImageListOptions,MagickFalse,option+1) < 0 ?
6339 MagickFalse : MagickTrue;
6340 if (fire != MagickFalse)
6341 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
6342 }
6343 if (k != 0)
6344 ThrowMogrifyException(OptionError,"UnbalancedParenthesis",argv[i]);
cristycee97112010-05-28 00:44:52 +00006345 if (i != (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006346 ThrowMogrifyException(OptionError,"MissingAnImageFilename",argv[i]);
6347 DestroyMogrify();
6348 return(status != 0 ? MagickTrue : MagickFalse);
6349}
6350
6351/*
6352%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6353% %
6354% %
6355% %
6356+ M o g r i f y I m a g e I n f o %
6357% %
6358% %
6359% %
6360%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6361%
6362% MogrifyImageInfo() applies image processing settings to the image as
6363% prescribed by command line options.
6364%
6365% The format of the MogrifyImageInfo method is:
6366%
6367% MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,const int argc,
6368% const char **argv,ExceptionInfo *exception)
6369%
6370% A description of each parameter follows:
6371%
6372% o image_info: the image info..
6373%
6374% o argc: Specifies a pointer to an integer describing the number of
6375% elements in the argument vector.
6376%
6377% o argv: Specifies a pointer to a text array containing the command line
6378% arguments.
6379%
6380% o exception: return any errors or warnings in this structure.
6381%
6382*/
6383WandExport MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,
6384 const int argc,const char **argv,ExceptionInfo *exception)
6385{
6386 const char
6387 *option;
6388
6389 GeometryInfo
6390 geometry_info;
6391
cristybb503372010-05-27 20:51:26 +00006392 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006393 count;
6394
cristybb503372010-05-27 20:51:26 +00006395 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006396 i;
6397
6398 /*
6399 Initialize method variables.
6400 */
6401 assert(image_info != (ImageInfo *) NULL);
6402 assert(image_info->signature == MagickSignature);
6403 if (image_info->debug != MagickFalse)
6404 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
6405 image_info->filename);
6406 if (argc < 0)
6407 return(MagickTrue);
6408 /*
6409 Set the image settings.
6410 */
cristybb503372010-05-27 20:51:26 +00006411 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00006412 {
6413 option=argv[i];
6414 if (IsMagickOption(option) == MagickFalse)
6415 continue;
6416 count=MagickMax(ParseMagickOption(MagickCommandOptions,MagickFalse,option),
6417 0L);
cristycee97112010-05-28 00:44:52 +00006418 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006419 break;
6420 switch (*(option+1))
6421 {
6422 case 'a':
6423 {
6424 if (LocaleCompare("adjoin",option+1) == 0)
6425 {
6426 image_info->adjoin=(*option == '-') ? MagickTrue : MagickFalse;
6427 break;
6428 }
6429 if (LocaleCompare("antialias",option+1) == 0)
6430 {
6431 image_info->antialias=(*option == '-') ? MagickTrue : MagickFalse;
6432 break;
6433 }
6434 if (LocaleCompare("attenuate",option+1) == 0)
6435 {
6436 if (*option == '+')
6437 {
6438 (void) DeleteImageOption(image_info,option+1);
6439 break;
6440 }
6441 (void) SetImageOption(image_info,option+1,argv[i+1]);
6442 break;
6443 }
6444 if (LocaleCompare("authenticate",option+1) == 0)
6445 {
6446 if (*option == '+')
6447 (void) CloneString(&image_info->authenticate,(char *) NULL);
6448 else
6449 (void) CloneString(&image_info->authenticate,argv[i+1]);
6450 break;
6451 }
6452 break;
6453 }
6454 case 'b':
6455 {
6456 if (LocaleCompare("background",option+1) == 0)
6457 {
6458 if (*option == '+')
6459 {
6460 (void) DeleteImageOption(image_info,option+1);
6461 (void) QueryColorDatabase(BackgroundColor,
6462 &image_info->background_color,exception);
6463 break;
6464 }
6465 (void) SetImageOption(image_info,option+1,argv[i+1]);
6466 (void) QueryColorDatabase(argv[i+1],&image_info->background_color,
6467 exception);
6468 break;
6469 }
6470 if (LocaleCompare("bias",option+1) == 0)
6471 {
6472 if (*option == '+')
6473 {
6474 (void) SetImageOption(image_info,option+1,"0.0");
6475 break;
6476 }
6477 (void) SetImageOption(image_info,option+1,argv[i+1]);
6478 break;
6479 }
6480 if (LocaleCompare("black-point-compensation",option+1) == 0)
6481 {
6482 if (*option == '+')
6483 {
6484 (void) SetImageOption(image_info,option+1,"false");
6485 break;
6486 }
6487 (void) SetImageOption(image_info,option+1,"true");
6488 break;
6489 }
6490 if (LocaleCompare("blue-primary",option+1) == 0)
6491 {
6492 if (*option == '+')
6493 {
6494 (void) SetImageOption(image_info,option+1,"0.0");
6495 break;
6496 }
6497 (void) SetImageOption(image_info,option+1,argv[i+1]);
6498 break;
6499 }
6500 if (LocaleCompare("bordercolor",option+1) == 0)
6501 {
6502 if (*option == '+')
6503 {
6504 (void) DeleteImageOption(image_info,option+1);
6505 (void) QueryColorDatabase(BorderColor,&image_info->border_color,
6506 exception);
6507 break;
6508 }
6509 (void) QueryColorDatabase(argv[i+1],&image_info->border_color,
6510 exception);
6511 (void) SetImageOption(image_info,option+1,argv[i+1]);
6512 break;
6513 }
6514 if (LocaleCompare("box",option+1) == 0)
6515 {
6516 if (*option == '+')
6517 {
6518 (void) SetImageOption(image_info,"undercolor","none");
6519 break;
6520 }
6521 (void) SetImageOption(image_info,"undercolor",argv[i+1]);
6522 break;
6523 }
6524 break;
6525 }
6526 case 'c':
6527 {
6528 if (LocaleCompare("cache",option+1) == 0)
6529 {
6530 MagickSizeType
6531 limit;
6532
6533 limit=MagickResourceInfinity;
6534 if (LocaleCompare("unlimited",argv[i+1]) != 0)
cristyf2f27272009-12-17 14:48:46 +00006535 limit=(MagickSizeType) SiPrefixToDouble(argv[i+1],100.0);
cristy3ed852e2009-09-05 21:47:34 +00006536 (void) SetMagickResourceLimit(MemoryResource,limit);
6537 (void) SetMagickResourceLimit(MapResource,2*limit);
6538 break;
6539 }
6540 if (LocaleCompare("caption",option+1) == 0)
6541 {
6542 if (*option == '+')
6543 {
6544 (void) DeleteImageOption(image_info,option+1);
6545 break;
6546 }
6547 (void) SetImageOption(image_info,option+1,argv[i+1]);
6548 break;
6549 }
6550 if (LocaleCompare("channel",option+1) == 0)
6551 {
6552 if (*option == '+')
6553 {
6554 image_info->channel=DefaultChannels;
6555 break;
6556 }
6557 image_info->channel=(ChannelType) ParseChannelOption(argv[i+1]);
6558 break;
6559 }
6560 if (LocaleCompare("colors",option+1) == 0)
6561 {
cristye27293e2009-12-18 02:53:20 +00006562 image_info->colors=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006563 break;
6564 }
6565 if (LocaleCompare("colorspace",option+1) == 0)
6566 {
6567 if (*option == '+')
6568 {
6569 image_info->colorspace=UndefinedColorspace;
6570 (void) SetImageOption(image_info,option+1,"undefined");
6571 break;
6572 }
6573 image_info->colorspace=(ColorspaceType) ParseMagickOption(
6574 MagickColorspaceOptions,MagickFalse,argv[i+1]);
6575 (void) SetImageOption(image_info,option+1,argv[i+1]);
6576 break;
6577 }
6578 if (LocaleCompare("compress",option+1) == 0)
6579 {
6580 if (*option == '+')
6581 {
6582 image_info->compression=UndefinedCompression;
6583 (void) SetImageOption(image_info,option+1,"undefined");
6584 break;
6585 }
6586 image_info->compression=(CompressionType) ParseMagickOption(
6587 MagickCompressOptions,MagickFalse,argv[i+1]);
6588 (void) SetImageOption(image_info,option+1,argv[i+1]);
6589 break;
6590 }
6591 if (LocaleCompare("comment",option+1) == 0)
6592 {
6593 if (*option == '+')
6594 {
6595 (void) DeleteImageOption(image_info,option+1);
6596 break;
6597 }
6598 (void) SetImageOption(image_info,option+1,argv[i+1]);
6599 break;
6600 }
6601 if (LocaleCompare("compose",option+1) == 0)
6602 {
6603 if (*option == '+')
6604 {
6605 (void) SetImageOption(image_info,option+1,"undefined");
6606 break;
6607 }
6608 (void) SetImageOption(image_info,option+1,argv[i+1]);
6609 break;
6610 }
6611 if (LocaleCompare("compress",option+1) == 0)
6612 {
6613 if (*option == '+')
6614 {
6615 image_info->compression=UndefinedCompression;
6616 (void) SetImageOption(image_info,option+1,"undefined");
6617 break;
6618 }
6619 image_info->compression=(CompressionType) ParseMagickOption(
6620 MagickCompressOptions,MagickFalse,argv[i+1]);
6621 (void) SetImageOption(image_info,option+1,argv[i+1]);
6622 break;
6623 }
6624 break;
6625 }
6626 case 'd':
6627 {
6628 if (LocaleCompare("debug",option+1) == 0)
6629 {
6630 if (*option == '+')
6631 (void) SetLogEventMask("none");
6632 else
6633 (void) SetLogEventMask(argv[i+1]);
6634 image_info->debug=IsEventLogging();
6635 break;
6636 }
6637 if (LocaleCompare("define",option+1) == 0)
6638 {
6639 if (*option == '+')
6640 {
6641 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6642 (void) DeleteImageRegistry(argv[i+1]+9);
6643 else
6644 (void) DeleteImageOption(image_info,argv[i+1]);
6645 break;
6646 }
6647 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6648 {
6649 (void) DefineImageRegistry(StringRegistryType,argv[i+1]+9,
6650 exception);
6651 break;
6652 }
6653 (void) DefineImageOption(image_info,argv[i+1]);
6654 break;
6655 }
6656 if (LocaleCompare("delay",option+1) == 0)
6657 {
6658 if (*option == '+')
6659 {
6660 (void) SetImageOption(image_info,option+1,"0");
6661 break;
6662 }
6663 (void) SetImageOption(image_info,option+1,argv[i+1]);
6664 break;
6665 }
6666 if (LocaleCompare("density",option+1) == 0)
6667 {
6668 /*
6669 Set image density.
6670 */
6671 if (*option == '+')
6672 {
6673 if (image_info->density != (char *) NULL)
6674 image_info->density=DestroyString(image_info->density);
6675 (void) SetImageOption(image_info,option+1,"72");
6676 break;
6677 }
6678 (void) CloneString(&image_info->density,argv[i+1]);
6679 (void) SetImageOption(image_info,option+1,argv[i+1]);
6680 break;
6681 }
6682 if (LocaleCompare("depth",option+1) == 0)
6683 {
6684 if (*option == '+')
6685 {
6686 image_info->depth=MAGICKCORE_QUANTUM_DEPTH;
6687 break;
6688 }
cristye27293e2009-12-18 02:53:20 +00006689 image_info->depth=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006690 break;
6691 }
cristyc9b12952010-03-28 01:12:28 +00006692 if (LocaleCompare("direction",option+1) == 0)
6693 {
6694 if (*option == '+')
6695 {
6696 (void) SetImageOption(image_info,option+1,"undefined");
6697 break;
6698 }
6699 (void) SetImageOption(image_info,option+1,argv[i+1]);
6700 break;
6701 }
cristy3ed852e2009-09-05 21:47:34 +00006702 if (LocaleCompare("display",option+1) == 0)
6703 {
6704 if (*option == '+')
6705 {
6706 if (image_info->server_name != (char *) NULL)
6707 image_info->server_name=DestroyString(
6708 image_info->server_name);
6709 break;
6710 }
6711 (void) CloneString(&image_info->server_name,argv[i+1]);
6712 break;
6713 }
6714 if (LocaleCompare("dispose",option+1) == 0)
6715 {
6716 if (*option == '+')
6717 {
6718 (void) SetImageOption(image_info,option+1,"undefined");
6719 break;
6720 }
6721 (void) SetImageOption(image_info,option+1,argv[i+1]);
6722 break;
6723 }
6724 if (LocaleCompare("dither",option+1) == 0)
6725 {
6726 if (*option == '+')
6727 {
6728 image_info->dither=MagickFalse;
6729 (void) SetImageOption(image_info,option+1,"undefined");
6730 break;
6731 }
6732 (void) SetImageOption(image_info,option+1,argv[i+1]);
6733 image_info->dither=MagickTrue;
6734 break;
6735 }
6736 break;
6737 }
6738 case 'e':
6739 {
6740 if (LocaleCompare("encoding",option+1) == 0)
6741 {
6742 if (*option == '+')
6743 {
6744 (void) SetImageOption(image_info,option+1,"undefined");
6745 break;
6746 }
6747 (void) SetImageOption(image_info,option+1,argv[i+1]);
6748 break;
6749 }
6750 if (LocaleCompare("endian",option+1) == 0)
6751 {
6752 if (*option == '+')
6753 {
6754 image_info->endian=UndefinedEndian;
6755 (void) SetImageOption(image_info,option+1,"undefined");
6756 break;
6757 }
6758 image_info->endian=(EndianType) ParseMagickOption(
6759 MagickEndianOptions,MagickFalse,argv[i+1]);
6760 (void) SetImageOption(image_info,option+1,argv[i+1]);
6761 break;
6762 }
6763 if (LocaleCompare("extract",option+1) == 0)
6764 {
6765 /*
6766 Set image extract geometry.
6767 */
6768 if (*option == '+')
6769 {
6770 if (image_info->extract != (char *) NULL)
6771 image_info->extract=DestroyString(image_info->extract);
6772 break;
6773 }
6774 (void) CloneString(&image_info->extract,argv[i+1]);
6775 break;
6776 }
6777 break;
6778 }
6779 case 'f':
6780 {
6781 if (LocaleCompare("fill",option+1) == 0)
6782 {
6783 if (*option == '+')
6784 {
6785 (void) SetImageOption(image_info,option+1,"none");
6786 break;
6787 }
6788 (void) SetImageOption(image_info,option+1,argv[i+1]);
6789 break;
6790 }
6791 if (LocaleCompare("filter",option+1) == 0)
6792 {
6793 if (*option == '+')
6794 {
6795 (void) SetImageOption(image_info,option+1,"undefined");
6796 break;
6797 }
6798 (void) SetImageOption(image_info,option+1,argv[i+1]);
6799 break;
6800 }
6801 if (LocaleCompare("font",option+1) == 0)
6802 {
6803 if (*option == '+')
6804 {
6805 if (image_info->font != (char *) NULL)
6806 image_info->font=DestroyString(image_info->font);
6807 break;
6808 }
6809 (void) CloneString(&image_info->font,argv[i+1]);
6810 break;
6811 }
6812 if (LocaleCompare("format",option+1) == 0)
6813 {
6814 register const char
6815 *q;
6816
6817 for (q=strchr(argv[i+1],'%'); q != (char *) NULL; q=strchr(q+1,'%'))
6818 if (strchr("gkrz@[#",*(q+1)) != (char *) NULL)
6819 image_info->ping=MagickFalse;
6820 (void) SetImageOption(image_info,option+1,argv[i+1]);
6821 break;
6822 }
6823 if (LocaleCompare("fuzz",option+1) == 0)
6824 {
6825 if (*option == '+')
6826 {
6827 image_info->fuzz=0.0;
6828 (void) SetImageOption(image_info,option+1,"0");
6829 break;
6830 }
cristyf2f27272009-12-17 14:48:46 +00006831 image_info->fuzz=SiPrefixToDouble(argv[i+1],(double) QuantumRange+
cristy3ed852e2009-09-05 21:47:34 +00006832 1.0);
6833 (void) SetImageOption(image_info,option+1,argv[i+1]);
6834 break;
6835 }
6836 break;
6837 }
6838 case 'g':
6839 {
6840 if (LocaleCompare("gravity",option+1) == 0)
6841 {
6842 if (*option == '+')
6843 {
6844 (void) SetImageOption(image_info,option+1,"undefined");
6845 break;
6846 }
6847 (void) SetImageOption(image_info,option+1,argv[i+1]);
6848 break;
6849 }
6850 if (LocaleCompare("green-primary",option+1) == 0)
6851 {
6852 if (*option == '+')
6853 {
6854 (void) SetImageOption(image_info,option+1,"0.0");
6855 break;
6856 }
6857 (void) SetImageOption(image_info,option+1,argv[i+1]);
6858 break;
6859 }
6860 break;
6861 }
6862 case 'i':
6863 {
6864 if (LocaleCompare("intent",option+1) == 0)
6865 {
6866 if (*option == '+')
6867 {
6868 (void) SetImageOption(image_info,option+1,"undefined");
6869 break;
6870 }
6871 (void) SetImageOption(image_info,option+1,argv[i+1]);
6872 break;
6873 }
6874 if (LocaleCompare("interlace",option+1) == 0)
6875 {
6876 if (*option == '+')
6877 {
6878 image_info->interlace=UndefinedInterlace;
6879 (void) SetImageOption(image_info,option+1,"undefined");
6880 break;
6881 }
6882 image_info->interlace=(InterlaceType) ParseMagickOption(
6883 MagickInterlaceOptions,MagickFalse,argv[i+1]);
6884 (void) SetImageOption(image_info,option+1,argv[i+1]);
6885 break;
6886 }
cristyb32b90a2009-09-07 21:45:48 +00006887 if (LocaleCompare("interline-spacing",option+1) == 0)
6888 {
6889 if (*option == '+')
6890 {
6891 (void) SetImageOption(image_info,option+1,"undefined");
6892 break;
6893 }
6894 (void) SetImageOption(image_info,option+1,argv[i+1]);
6895 break;
6896 }
cristy3ed852e2009-09-05 21:47:34 +00006897 if (LocaleCompare("interpolate",option+1) == 0)
6898 {
6899 if (*option == '+')
6900 {
6901 (void) SetImageOption(image_info,option+1,"undefined");
6902 break;
6903 }
6904 (void) SetImageOption(image_info,option+1,argv[i+1]);
6905 break;
6906 }
6907 if (LocaleCompare("interword-spacing",option+1) == 0)
6908 {
6909 if (*option == '+')
6910 {
6911 (void) SetImageOption(image_info,option+1,"undefined");
6912 break;
6913 }
6914 (void) SetImageOption(image_info,option+1,argv[i+1]);
6915 break;
6916 }
6917 break;
6918 }
6919 case 'k':
6920 {
6921 if (LocaleCompare("kerning",option+1) == 0)
6922 {
6923 if (*option == '+')
6924 {
6925 (void) SetImageOption(image_info,option+1,"undefined");
6926 break;
6927 }
6928 (void) SetImageOption(image_info,option+1,argv[i+1]);
6929 break;
6930 }
6931 break;
6932 }
6933 case 'l':
6934 {
6935 if (LocaleCompare("label",option+1) == 0)
6936 {
6937 if (*option == '+')
6938 {
6939 (void) DeleteImageOption(image_info,option+1);
6940 break;
6941 }
6942 (void) SetImageOption(image_info,option+1,argv[i+1]);
6943 break;
6944 }
6945 if (LocaleCompare("limit",option+1) == 0)
6946 {
6947 MagickSizeType
6948 limit;
6949
6950 ResourceType
6951 type;
6952
6953 if (*option == '+')
6954 break;
6955 type=(ResourceType) ParseMagickOption(MagickResourceOptions,
6956 MagickFalse,argv[i+1]);
6957 limit=MagickResourceInfinity;
6958 if (LocaleCompare("unlimited",argv[i+2]) != 0)
cristyf2f27272009-12-17 14:48:46 +00006959 limit=(MagickSizeType) SiPrefixToDouble(argv[i+2],100.0);
cristy3ed852e2009-09-05 21:47:34 +00006960 (void) SetMagickResourceLimit(type,limit);
6961 break;
6962 }
6963 if (LocaleCompare("list",option+1) == 0)
6964 {
cristybb503372010-05-27 20:51:26 +00006965 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006966 list;
6967
6968 /*
6969 Display configuration list.
6970 */
6971 list=ParseMagickOption(MagickListOptions,MagickFalse,argv[i+1]);
6972 switch (list)
6973 {
6974 case MagickCoderOptions:
6975 {
6976 (void) ListCoderInfo((FILE *) NULL,exception);
6977 break;
6978 }
6979 case MagickColorOptions:
6980 {
6981 (void) ListColorInfo((FILE *) NULL,exception);
6982 break;
6983 }
6984 case MagickConfigureOptions:
6985 {
6986 (void) ListConfigureInfo((FILE *) NULL,exception);
6987 break;
6988 }
6989 case MagickDelegateOptions:
6990 {
6991 (void) ListDelegateInfo((FILE *) NULL,exception);
6992 break;
6993 }
6994 case MagickFontOptions:
6995 {
6996 (void) ListTypeInfo((FILE *) NULL,exception);
6997 break;
6998 }
6999 case MagickFormatOptions:
7000 {
7001 (void) ListMagickInfo((FILE *) NULL,exception);
7002 break;
7003 }
7004 case MagickLocaleOptions:
7005 {
7006 (void) ListLocaleInfo((FILE *) NULL,exception);
7007 break;
7008 }
7009 case MagickLogOptions:
7010 {
7011 (void) ListLogInfo((FILE *) NULL,exception);
7012 break;
7013 }
7014 case MagickMagicOptions:
7015 {
7016 (void) ListMagicInfo((FILE *) NULL,exception);
7017 break;
7018 }
7019 case MagickMimeOptions:
7020 {
7021 (void) ListMimeInfo((FILE *) NULL,exception);
7022 break;
7023 }
7024 case MagickModuleOptions:
7025 {
7026 (void) ListModuleInfo((FILE *) NULL,exception);
7027 break;
7028 }
7029 case MagickPolicyOptions:
7030 {
7031 (void) ListPolicyInfo((FILE *) NULL,exception);
7032 break;
7033 }
7034 case MagickResourceOptions:
7035 {
7036 (void) ListMagickResourceInfo((FILE *) NULL,exception);
7037 break;
7038 }
7039 case MagickThresholdOptions:
7040 {
7041 (void) ListThresholdMaps((FILE *) NULL,exception);
7042 break;
7043 }
7044 default:
7045 {
7046 (void) ListMagickOptions((FILE *) NULL,(MagickOption) list,
7047 exception);
7048 break;
7049 }
7050 }
cristyaeb2cbc2010-05-07 13:28:58 +00007051 break;
cristy3ed852e2009-09-05 21:47:34 +00007052 }
7053 if (LocaleCompare("log",option+1) == 0)
7054 {
7055 if (*option == '+')
7056 break;
7057 (void) SetLogFormat(argv[i+1]);
7058 break;
7059 }
7060 if (LocaleCompare("loop",option+1) == 0)
7061 {
7062 if (*option == '+')
7063 {
7064 (void) SetImageOption(image_info,option+1,"0");
7065 break;
7066 }
7067 (void) SetImageOption(image_info,option+1,argv[i+1]);
7068 break;
7069 }
7070 break;
7071 }
7072 case 'm':
7073 {
7074 if (LocaleCompare("matte",option+1) == 0)
7075 {
7076 if (*option == '+')
7077 {
7078 (void) SetImageOption(image_info,option+1,"false");
7079 break;
7080 }
7081 (void) SetImageOption(image_info,option+1,"true");
7082 break;
7083 }
7084 if (LocaleCompare("mattecolor",option+1) == 0)
7085 {
7086 if (*option == '+')
7087 {
7088 (void) SetImageOption(image_info,option+1,argv[i+1]);
7089 (void) QueryColorDatabase(MatteColor,&image_info->matte_color,
7090 exception);
7091 break;
7092 }
7093 (void) SetImageOption(image_info,option+1,argv[i+1]);
7094 (void) QueryColorDatabase(argv[i+1],&image_info->matte_color,
7095 exception);
7096 break;
7097 }
7098 if (LocaleCompare("monitor",option+1) == 0)
7099 {
7100 (void) SetImageInfoProgressMonitor(image_info,MonitorProgress,
7101 (void *) NULL);
7102 break;
7103 }
7104 if (LocaleCompare("monochrome",option+1) == 0)
7105 {
7106 image_info->monochrome=(*option == '-') ? MagickTrue : MagickFalse;
7107 break;
7108 }
7109 break;
7110 }
7111 case 'o':
7112 {
7113 if (LocaleCompare("orient",option+1) == 0)
7114 {
7115 if (*option == '+')
7116 {
7117 image_info->orientation=UndefinedOrientation;
7118 (void) SetImageOption(image_info,option+1,"undefined");
7119 break;
7120 }
7121 image_info->orientation=(OrientationType) ParseMagickOption(
7122 MagickOrientationOptions,MagickFalse,argv[i+1]);
7123 (void) SetImageOption(image_info,option+1,"undefined");
7124 break;
7125 }
7126 }
7127 case 'p':
7128 {
7129 if (LocaleCompare("page",option+1) == 0)
7130 {
7131 char
7132 *canonical_page,
7133 page[MaxTextExtent];
7134
7135 const char
7136 *image_option;
7137
7138 MagickStatusType
7139 flags;
7140
7141 RectangleInfo
7142 geometry;
7143
7144 if (*option == '+')
7145 {
7146 (void) DeleteImageOption(image_info,option+1);
7147 (void) CloneString(&image_info->page,(char *) NULL);
7148 break;
7149 }
7150 (void) ResetMagickMemory(&geometry,0,sizeof(geometry));
7151 image_option=GetImageOption(image_info,"page");
7152 if (image_option != (const char *) NULL)
7153 flags=ParseAbsoluteGeometry(image_option,&geometry);
7154 canonical_page=GetPageGeometry(argv[i+1]);
7155 flags=ParseAbsoluteGeometry(canonical_page,&geometry);
7156 canonical_page=DestroyString(canonical_page);
7157 (void) FormatMagickString(page,MaxTextExtent,"%lux%lu",
7158 geometry.width,geometry.height);
7159 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
7160 (void) FormatMagickString(page,MaxTextExtent,"%lux%lu%+ld%+ld",
7161 geometry.width,geometry.height,geometry.x,geometry.y);
7162 (void) SetImageOption(image_info,option+1,page);
7163 (void) CloneString(&image_info->page,page);
7164 break;
7165 }
7166 if (LocaleCompare("pen",option+1) == 0)
7167 {
7168 if (*option == '+')
7169 {
7170 (void) SetImageOption(image_info,option+1,"none");
7171 break;
7172 }
7173 (void) SetImageOption(image_info,option+1,argv[i+1]);
7174 break;
7175 }
7176 if (LocaleCompare("ping",option+1) == 0)
7177 {
7178 image_info->ping=(*option == '-') ? MagickTrue : MagickFalse;
7179 break;
7180 }
7181 if (LocaleCompare("pointsize",option+1) == 0)
7182 {
7183 if (*option == '+')
7184 geometry_info.rho=0.0;
7185 else
7186 (void) ParseGeometry(argv[i+1],&geometry_info);
7187 image_info->pointsize=geometry_info.rho;
7188 break;
7189 }
cristye7f51092010-01-17 00:39:37 +00007190 if (LocaleCompare("precision",option+1) == 0)
7191 {
cristybf2766a2010-01-17 03:33:23 +00007192 (void) SetMagickPrecision(StringToInteger(argv[i+1]));
cristye7f51092010-01-17 00:39:37 +00007193 break;
7194 }
cristy3ed852e2009-09-05 21:47:34 +00007195 if (LocaleCompare("preview",option+1) == 0)
7196 {
7197 /*
7198 Preview image.
7199 */
7200 if (*option == '+')
7201 {
7202 image_info->preview_type=UndefinedPreview;
7203 break;
7204 }
7205 image_info->preview_type=(PreviewType) ParseMagickOption(
7206 MagickPreviewOptions,MagickFalse,argv[i+1]);
7207 break;
7208 }
7209 break;
7210 }
7211 case 'q':
7212 {
7213 if (LocaleCompare("quality",option+1) == 0)
7214 {
7215 /*
7216 Set image compression quality.
7217 */
7218 if (*option == '+')
7219 {
7220 image_info->quality=UndefinedCompressionQuality;
7221 (void) SetImageOption(image_info,option+1,"0");
7222 break;
7223 }
cristye27293e2009-12-18 02:53:20 +00007224 image_info->quality=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007225 (void) SetImageOption(image_info,option+1,argv[i+1]);
7226 break;
7227 }
7228 if (LocaleCompare("quiet",option+1) == 0)
7229 {
7230 static WarningHandler
7231 warning_handler = (WarningHandler) NULL;
7232
7233 if (*option == '+')
7234 {
7235 /*
7236 Restore error or warning messages.
7237 */
7238 warning_handler=SetWarningHandler(warning_handler);
7239 break;
7240 }
7241 /*
7242 Suppress error or warning messages.
7243 */
7244 warning_handler=SetWarningHandler((WarningHandler) NULL);
7245 break;
7246 }
7247 break;
7248 }
7249 case 'r':
7250 {
7251 if (LocaleCompare("red-primary",option+1) == 0)
7252 {
7253 if (*option == '+')
7254 {
7255 (void) SetImageOption(image_info,option+1,"0.0");
7256 break;
7257 }
7258 (void) SetImageOption(image_info,option+1,argv[i+1]);
7259 break;
7260 }
7261 break;
7262 }
7263 case 's':
7264 {
7265 if (LocaleCompare("sampling-factor",option+1) == 0)
7266 {
7267 /*
7268 Set image sampling factor.
7269 */
7270 if (*option == '+')
7271 {
7272 if (image_info->sampling_factor != (char *) NULL)
7273 image_info->sampling_factor=DestroyString(
7274 image_info->sampling_factor);
7275 break;
7276 }
7277 (void) CloneString(&image_info->sampling_factor,argv[i+1]);
7278 break;
7279 }
7280 if (LocaleCompare("scene",option+1) == 0)
7281 {
7282 /*
7283 Set image scene.
7284 */
7285 if (*option == '+')
7286 {
7287 image_info->scene=0;
7288 (void) SetImageOption(image_info,option+1,"0");
7289 break;
7290 }
cristye27293e2009-12-18 02:53:20 +00007291 image_info->scene=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007292 (void) SetImageOption(image_info,option+1,argv[i+1]);
7293 break;
7294 }
7295 if (LocaleCompare("seed",option+1) == 0)
7296 {
cristybb503372010-05-27 20:51:26 +00007297 size_t
cristy3ed852e2009-09-05 21:47:34 +00007298 seed;
7299
7300 if (*option == '+')
7301 {
cristybb503372010-05-27 20:51:26 +00007302 seed=(size_t) time((time_t *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00007303 SeedPseudoRandomGenerator(seed);
7304 break;
7305 }
cristye27293e2009-12-18 02:53:20 +00007306 seed=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007307 SeedPseudoRandomGenerator(seed);
7308 break;
7309 }
7310 if (LocaleCompare("size",option+1) == 0)
7311 {
7312 if (*option == '+')
7313 {
7314 if (image_info->size != (char *) NULL)
7315 image_info->size=DestroyString(image_info->size);
7316 break;
7317 }
7318 (void) CloneString(&image_info->size,argv[i+1]);
7319 break;
7320 }
7321 if (LocaleCompare("stroke",option+1) == 0)
7322 {
7323 if (*option == '+')
7324 {
7325 (void) SetImageOption(image_info,option+1,"none");
7326 break;
7327 }
7328 (void) SetImageOption(image_info,option+1,argv[i+1]);
7329 break;
7330 }
7331 if (LocaleCompare("strokewidth",option+1) == 0)
7332 {
7333 if (*option == '+')
7334 {
7335 (void) SetImageOption(image_info,option+1,"0");
7336 break;
7337 }
7338 (void) SetImageOption(image_info,option+1,argv[i+1]);
7339 break;
7340 }
7341 break;
7342 }
7343 case 't':
7344 {
7345 if (LocaleCompare("taint",option+1) == 0)
7346 {
7347 if (*option == '+')
7348 {
7349 (void) SetImageOption(image_info,option+1,"false");
7350 break;
7351 }
7352 (void) SetImageOption(image_info,option+1,"true");
7353 break;
7354 }
7355 if (LocaleCompare("texture",option+1) == 0)
7356 {
7357 if (*option == '+')
7358 {
7359 if (image_info->texture != (char *) NULL)
7360 image_info->texture=DestroyString(image_info->texture);
7361 break;
7362 }
7363 (void) CloneString(&image_info->texture,argv[i+1]);
7364 break;
7365 }
7366 if (LocaleCompare("tile-offset",option+1) == 0)
7367 {
7368 if (*option == '+')
7369 {
7370 (void) SetImageOption(image_info,option+1,"0");
7371 break;
7372 }
7373 (void) SetImageOption(image_info,option+1,argv[i+1]);
7374 break;
7375 }
7376 if (LocaleCompare("transparent-color",option+1) == 0)
7377 {
7378 if (*option == '+')
7379 {
7380 (void) QueryColorDatabase("none",&image_info->transparent_color, exception);
7381 (void) SetImageOption(image_info,option+1,"none");
7382 break;
7383 }
7384 (void) QueryColorDatabase(argv[i+1],&image_info->transparent_color,
7385 exception);
7386 (void) SetImageOption(image_info,option+1,argv[i+1]);
7387 break;
7388 }
7389 if (LocaleCompare("type",option+1) == 0)
7390 {
7391 if (*option == '+')
7392 {
7393 image_info->type=UndefinedType;
7394 (void) SetImageOption(image_info,option+1,"undefined");
7395 break;
7396 }
7397 image_info->type=(ImageType) ParseMagickOption(MagickTypeOptions,
7398 MagickFalse,argv[i+1]);
7399 (void) SetImageOption(image_info,option+1,argv[i+1]);
7400 break;
7401 }
7402 break;
7403 }
7404 case 'u':
7405 {
7406 if (LocaleCompare("undercolor",option+1) == 0)
7407 {
7408 if (*option == '+')
7409 {
7410 (void) DeleteImageOption(image_info,option+1);
7411 break;
7412 }
7413 (void) SetImageOption(image_info,option+1,argv[i+1]);
7414 break;
7415 }
7416 if (LocaleCompare("units",option+1) == 0)
7417 {
7418 if (*option == '+')
7419 {
7420 image_info->units=UndefinedResolution;
7421 (void) SetImageOption(image_info,option+1,"undefined");
7422 break;
7423 }
7424 image_info->units=(ResolutionType) ParseMagickOption(
7425 MagickResolutionOptions,MagickFalse,argv[i+1]);
7426 (void) SetImageOption(image_info,option+1,argv[i+1]);
7427 break;
7428 }
7429 break;
7430 }
7431 case 'v':
7432 {
7433 if (LocaleCompare("verbose",option+1) == 0)
7434 {
7435 if (*option == '+')
7436 {
7437 image_info->verbose=MagickFalse;
7438 break;
7439 }
7440 image_info->verbose=MagickTrue;
7441 image_info->ping=MagickFalse;
7442 break;
7443 }
7444 if (LocaleCompare("view",option+1) == 0)
7445 {
7446 if (*option == '+')
7447 {
7448 if (image_info->view != (char *) NULL)
7449 image_info->view=DestroyString(image_info->view);
7450 break;
7451 }
7452 (void) CloneString(&image_info->view,argv[i+1]);
7453 break;
7454 }
7455 if (LocaleCompare("virtual-pixel",option+1) == 0)
7456 {
7457 if (*option == '+')
7458 {
7459 image_info->virtual_pixel_method=UndefinedVirtualPixelMethod;
7460 (void) SetImageOption(image_info,option+1,"undefined");
7461 break;
7462 }
7463 image_info->virtual_pixel_method=(VirtualPixelMethod)
7464 ParseMagickOption(MagickVirtualPixelOptions,MagickFalse,
7465 argv[i+1]);
7466 (void) SetImageOption(image_info,option+1,argv[i+1]);
7467 break;
7468 }
7469 break;
7470 }
7471 case 'w':
7472 {
7473 if (LocaleCompare("white-point",option+1) == 0)
7474 {
7475 if (*option == '+')
7476 {
7477 (void) SetImageOption(image_info,option+1,"0.0");
7478 break;
7479 }
7480 (void) SetImageOption(image_info,option+1,argv[i+1]);
7481 break;
7482 }
7483 break;
7484 }
7485 default:
7486 break;
7487 }
7488 i+=count;
7489 }
7490 return(MagickTrue);
7491}
7492
7493/*
7494%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7495% %
7496% %
7497% %
7498+ M o g r i f y I m a g e L i s t %
7499% %
7500% %
7501% %
7502%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7503%
7504% MogrifyImageList() applies any command line options that might affect the
7505% entire image list (e.g. -append, -coalesce, etc.).
7506%
7507% The format of the MogrifyImage method is:
7508%
7509% MagickBooleanType MogrifyImageList(ImageInfo *image_info,const int argc,
7510% const char **argv,Image **images,ExceptionInfo *exception)
7511%
7512% A description of each parameter follows:
7513%
7514% o image_info: the image info..
7515%
7516% o argc: Specifies a pointer to an integer describing the number of
7517% elements in the argument vector.
7518%
7519% o argv: Specifies a pointer to a text array containing the command line
7520% arguments.
7521%
7522% o images: the images.
7523%
7524% o exception: return any errors or warnings in this structure.
7525%
7526*/
7527WandExport MagickBooleanType MogrifyImageList(ImageInfo *image_info,
7528 const int argc,const char **argv,Image **images,ExceptionInfo *exception)
7529{
7530 ChannelType
7531 channel;
7532
7533 const char
7534 *option;
7535
cristybb503372010-05-27 20:51:26 +00007536 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00007537 count,
7538 index;
7539
7540 MagickStatusType
7541 status;
7542
7543 QuantizeInfo
7544 *quantize_info;
7545
cristybb503372010-05-27 20:51:26 +00007546 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00007547 i;
7548
7549 /*
7550 Apply options to the image list.
7551 */
7552 assert(image_info != (ImageInfo *) NULL);
7553 assert(image_info->signature == MagickSignature);
7554 assert(images != (Image **) NULL);
7555 assert((*images)->signature == MagickSignature);
7556 if ((*images)->debug != MagickFalse)
7557 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
7558 (*images)->filename);
7559 if ((argc <= 0) || (*argv == (char *) NULL))
7560 return(MagickTrue);
7561 quantize_info=AcquireQuantizeInfo(image_info);
7562 channel=image_info->channel;
7563 status=MagickTrue;
cristybb503372010-05-27 20:51:26 +00007564 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00007565 {
cristy74fe8f12009-10-03 19:09:01 +00007566 if (*images == (Image *) NULL)
7567 break;
cristy3ed852e2009-09-05 21:47:34 +00007568 option=argv[i];
7569 if (IsMagickOption(option) == MagickFalse)
7570 continue;
7571 count=MagickMax(ParseMagickOption(MagickCommandOptions,MagickFalse,option),
7572 0L);
cristycee97112010-05-28 00:44:52 +00007573 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00007574 break;
cristycee97112010-05-28 00:44:52 +00007575 status=MogrifyImageInfo(image_info,(int) count+1,argv+i,exception);
cristy3ed852e2009-09-05 21:47:34 +00007576 switch (*(option+1))
7577 {
7578 case 'a':
7579 {
7580 if (LocaleCompare("affinity",option+1) == 0)
7581 {
7582 (void) SyncImagesSettings(image_info,*images);
7583 if (*option == '+')
7584 {
7585 (void) RemapImages(quantize_info,*images,(Image *) NULL);
7586 InheritException(exception,&(*images)->exception);
7587 break;
7588 }
7589 i++;
7590 break;
7591 }
7592 if (LocaleCompare("append",option+1) == 0)
7593 {
7594 Image
7595 *append_image;
7596
7597 (void) SyncImagesSettings(image_info,*images);
7598 append_image=AppendImages(*images,*option == '-' ? MagickTrue :
7599 MagickFalse,exception);
7600 if (append_image == (Image *) NULL)
7601 {
7602 status=MagickFalse;
7603 break;
7604 }
7605 *images=DestroyImageList(*images);
7606 *images=append_image;
7607 break;
7608 }
7609 if (LocaleCompare("average",option+1) == 0)
7610 {
7611 Image
7612 *average_image;
7613
cristyd18ae7c2010-03-07 17:39:52 +00007614 /*
7615 Average an image sequence (deprecated).
7616 */
cristy3ed852e2009-09-05 21:47:34 +00007617 (void) SyncImagesSettings(image_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007618 average_image=EvaluateImages(*images,MeanEvaluateOperator,
7619 exception);
cristy3ed852e2009-09-05 21:47:34 +00007620 if (average_image == (Image *) NULL)
7621 {
7622 status=MagickFalse;
7623 break;
7624 }
7625 *images=DestroyImageList(*images);
7626 *images=average_image;
7627 break;
7628 }
7629 break;
7630 }
7631 case 'c':
7632 {
7633 if (LocaleCompare("channel",option+1) == 0)
7634 {
7635 if (*option == '+')
7636 {
7637 channel=DefaultChannels;
7638 break;
7639 }
7640 channel=(ChannelType) ParseChannelOption(argv[i+1]);
7641 break;
7642 }
7643 if (LocaleCompare("clut",option+1) == 0)
7644 {
7645 Image
7646 *clut_image,
7647 *image;
7648
7649 (void) SyncImagesSettings(image_info,*images);
7650 image=RemoveFirstImageFromList(images);
7651 clut_image=RemoveFirstImageFromList(images);
7652 if (clut_image == (Image *) NULL)
7653 {
7654 status=MagickFalse;
7655 break;
7656 }
7657 (void) ClutImageChannel(image,channel,clut_image);
7658 clut_image=DestroyImage(clut_image);
7659 InheritException(exception,&image->exception);
7660 *images=DestroyImageList(*images);
7661 *images=image;
7662 break;
7663 }
7664 if (LocaleCompare("coalesce",option+1) == 0)
7665 {
7666 Image
7667 *coalesce_image;
7668
7669 (void) SyncImagesSettings(image_info,*images);
7670 coalesce_image=CoalesceImages(*images,exception);
7671 if (coalesce_image == (Image *) NULL)
7672 {
7673 status=MagickFalse;
7674 break;
7675 }
7676 *images=DestroyImageList(*images);
7677 *images=coalesce_image;
7678 break;
7679 }
7680 if (LocaleCompare("combine",option+1) == 0)
7681 {
7682 Image
7683 *combine_image;
7684
7685 (void) SyncImagesSettings(image_info,*images);
7686 combine_image=CombineImages(*images,channel,exception);
7687 if (combine_image == (Image *) NULL)
7688 {
7689 status=MagickFalse;
7690 break;
7691 }
7692 *images=DestroyImageList(*images);
7693 *images=combine_image;
7694 break;
7695 }
7696 if (LocaleCompare("composite",option+1) == 0)
7697 {
7698 Image
7699 *mask_image,
7700 *composite_image,
7701 *image;
7702
7703 RectangleInfo
7704 geometry;
7705
7706 (void) SyncImagesSettings(image_info,*images);
7707 image=RemoveFirstImageFromList(images);
7708 composite_image=RemoveFirstImageFromList(images);
7709 if (composite_image == (Image *) NULL)
7710 {
7711 status=MagickFalse;
7712 break;
7713 }
7714 (void) TransformImage(&composite_image,(char *) NULL,
7715 composite_image->geometry);
7716 SetGeometry(composite_image,&geometry);
7717 (void) ParseAbsoluteGeometry(composite_image->geometry,&geometry);
7718 GravityAdjustGeometry(image->columns,image->rows,image->gravity,
7719 &geometry);
7720 mask_image=RemoveFirstImageFromList(images);
7721 if (mask_image != (Image *) NULL)
7722 {
7723 if ((image->compose == DisplaceCompositeOp) ||
7724 (image->compose == DistortCompositeOp))
7725 {
7726 /*
7727 Merge Y displacement into X displacement image.
7728 */
7729 (void) CompositeImage(composite_image,CopyGreenCompositeOp,
7730 mask_image,0,0);
7731 mask_image=DestroyImage(mask_image);
7732 }
7733 else
7734 {
7735 /*
7736 Set a blending mask for the composition.
7737 */
7738 image->mask=mask_image;
7739 (void) NegateImage(image->mask,MagickFalse);
7740 }
7741 }
7742 (void) CompositeImageChannel(image,channel,image->compose,
7743 composite_image,geometry.x,geometry.y);
7744 if (image->mask != (Image *) NULL)
7745 image->mask=DestroyImage(image->mask);
7746 composite_image=DestroyImage(composite_image);
7747 InheritException(exception,&image->exception);
7748 *images=DestroyImageList(*images);
7749 *images=image;
7750 break;
7751 }
7752 if (LocaleCompare("crop",option+1) == 0)
7753 {
7754 MagickStatusType
7755 flags;
7756
7757 RectangleInfo
7758 geometry;
7759
7760 (void) SyncImagesSettings(image_info,*images);
7761 flags=ParseGravityGeometry(*images,argv[i+1],&geometry,exception);
7762 if (((geometry.width == 0) && (geometry.height == 0)) ||
7763 ((flags & XValue) != 0) || ((flags & YValue) != 0))
7764 break;
7765 (void) TransformImages(images,argv[i+1],(char *) NULL);
7766 InheritException(exception,&(*images)->exception);
7767 break;
7768 }
7769 break;
7770 }
7771 case 'd':
7772 {
7773 if (LocaleCompare("deconstruct",option+1) == 0)
7774 {
7775 Image
7776 *deconstruct_image;
7777
7778 (void) SyncImagesSettings(image_info,*images);
7779 deconstruct_image=DeconstructImages(*images,exception);
7780 if (deconstruct_image == (Image *) NULL)
7781 {
7782 status=MagickFalse;
7783 break;
7784 }
7785 *images=DestroyImageList(*images);
7786 *images=deconstruct_image;
7787 break;
7788 }
7789 if (LocaleCompare("delete",option+1) == 0)
7790 {
7791 if (*option == '+')
7792 DeleteImages(images,"-1",exception);
7793 else
7794 DeleteImages(images,argv[i+1],exception);
7795 break;
7796 }
7797 if (LocaleCompare("dither",option+1) == 0)
7798 {
7799 if (*option == '+')
7800 {
7801 quantize_info->dither=MagickFalse;
7802 break;
7803 }
7804 quantize_info->dither=MagickTrue;
7805 quantize_info->dither_method=(DitherMethod) ParseMagickOption(
7806 MagickDitherOptions,MagickFalse,argv[i+1]);
7807 break;
7808 }
7809 break;
7810 }
cristyd18ae7c2010-03-07 17:39:52 +00007811 case 'e':
7812 {
7813 if (LocaleCompare("evaluate-sequence",option+1) == 0)
7814 {
7815 Image
7816 *evaluate_image;
7817
7818 MagickEvaluateOperator
7819 op;
7820
7821 (void) SyncImageSettings(image_info,*images);
7822 op=(MagickEvaluateOperator) ParseMagickOption(MagickEvaluateOptions,
7823 MagickFalse,argv[i+1]);
7824 evaluate_image=EvaluateImages(*images,op,exception);
7825 if (evaluate_image == (Image *) NULL)
7826 {
7827 status=MagickFalse;
7828 break;
7829 }
7830 *images=DestroyImageList(*images);
7831 *images=evaluate_image;
7832 break;
7833 }
7834 break;
7835 }
cristy3ed852e2009-09-05 21:47:34 +00007836 case 'f':
7837 {
cristyf0a247f2009-10-04 00:20:03 +00007838 if (LocaleCompare("fft",option+1) == 0)
7839 {
7840 Image
7841 *fourier_image;
7842
7843 /*
7844 Implements the discrete Fourier transform (DFT).
7845 */
7846 (void) SyncImageSettings(image_info,*images);
7847 fourier_image=ForwardFourierTransformImage(*images,*option == '-' ?
7848 MagickTrue : MagickFalse,exception);
7849 if (fourier_image == (Image *) NULL)
7850 break;
7851 *images=DestroyImage(*images);
7852 *images=fourier_image;
7853 break;
7854 }
cristy3ed852e2009-09-05 21:47:34 +00007855 if (LocaleCompare("flatten",option+1) == 0)
7856 {
7857 Image
7858 *flatten_image;
7859
7860 (void) SyncImagesSettings(image_info,*images);
7861 flatten_image=MergeImageLayers(*images,FlattenLayer,exception);
7862 if (flatten_image == (Image *) NULL)
7863 break;
7864 *images=DestroyImageList(*images);
7865 *images=flatten_image;
7866 break;
7867 }
7868 if (LocaleCompare("fx",option+1) == 0)
7869 {
7870 Image
7871 *fx_image;
7872
7873 (void) SyncImagesSettings(image_info,*images);
7874 fx_image=FxImageChannel(*images,channel,argv[i+1],exception);
7875 if (fx_image == (Image *) NULL)
7876 {
7877 status=MagickFalse;
7878 break;
7879 }
7880 *images=DestroyImageList(*images);
7881 *images=fx_image;
7882 break;
7883 }
7884 break;
7885 }
7886 case 'h':
7887 {
7888 if (LocaleCompare("hald-clut",option+1) == 0)
7889 {
7890 Image
7891 *hald_image,
7892 *image;
7893
7894 (void) SyncImagesSettings(image_info,*images);
7895 image=RemoveFirstImageFromList(images);
7896 hald_image=RemoveFirstImageFromList(images);
7897 if (hald_image == (Image *) NULL)
7898 {
7899 status=MagickFalse;
7900 break;
7901 }
7902 (void) HaldClutImageChannel(image,channel,hald_image);
7903 hald_image=DestroyImage(hald_image);
7904 InheritException(exception,&image->exception);
cristy0aff6ea2009-11-14 01:40:53 +00007905 if (*images != (Image *) NULL)
7906 *images=DestroyImageList(*images);
cristy3ed852e2009-09-05 21:47:34 +00007907 *images=image;
7908 break;
7909 }
7910 break;
7911 }
7912 case 'i':
7913 {
7914 if (LocaleCompare("ift",option+1) == 0)
7915 {
7916 Image
cristy8587f882009-11-13 20:28:49 +00007917 *fourier_image,
7918 *magnitude_image,
7919 *phase_image;
cristy3ed852e2009-09-05 21:47:34 +00007920
7921 /*
7922 Implements the inverse fourier discrete Fourier transform (DFT).
7923 */
7924 (void) SyncImagesSettings(image_info,*images);
cristy8587f882009-11-13 20:28:49 +00007925 magnitude_image=RemoveFirstImageFromList(images);
7926 phase_image=RemoveFirstImageFromList(images);
7927 if (phase_image == (Image *) NULL)
7928 {
7929 status=MagickFalse;
7930 break;
7931 }
7932 fourier_image=InverseFourierTransformImage(magnitude_image,
7933 phase_image,*option == '-' ? MagickTrue : MagickFalse,exception);
cristy3ed852e2009-09-05 21:47:34 +00007934 if (fourier_image == (Image *) NULL)
7935 break;
cristy0aff6ea2009-11-14 01:40:53 +00007936 if (*images != (Image *) NULL)
7937 *images=DestroyImage(*images);
cristy3ed852e2009-09-05 21:47:34 +00007938 *images=fourier_image;
7939 break;
7940 }
7941 if (LocaleCompare("insert",option+1) == 0)
7942 {
7943 Image
7944 *p,
7945 *q;
7946
7947 index=0;
7948 if (*option != '+')
cristyf2f27272009-12-17 14:48:46 +00007949 index=StringToLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007950 p=RemoveLastImageFromList(images);
7951 if (p == (Image *) NULL)
7952 {
7953 (void) ThrowMagickException(exception,GetMagickModule(),
7954 OptionError,"NoSuchImage","`%s'",argv[i+1]);
7955 status=MagickFalse;
7956 break;
7957 }
7958 q=p;
7959 if (index == 0)
7960 PrependImageToList(images,q);
7961 else
cristybb503372010-05-27 20:51:26 +00007962 if (index == (ssize_t) GetImageListLength(*images))
cristy3ed852e2009-09-05 21:47:34 +00007963 AppendImageToList(images,q);
7964 else
7965 {
7966 q=GetImageFromList(*images,index-1);
7967 if (q == (Image *) NULL)
7968 {
7969 (void) ThrowMagickException(exception,GetMagickModule(),
7970 OptionError,"NoSuchImage","`%s'",argv[i+1]);
7971 status=MagickFalse;
7972 break;
7973 }
7974 InsertImageInList(&q,p);
7975 }
7976 *images=GetFirstImageInList(q);
7977 break;
7978 }
7979 break;
7980 }
7981 case 'l':
7982 {
7983 if (LocaleCompare("layers",option+1) == 0)
7984 {
7985 Image
7986 *layers;
7987
7988 ImageLayerMethod
7989 method;
7990
7991 (void) SyncImagesSettings(image_info,*images);
7992 layers=(Image *) NULL;
7993 method=(ImageLayerMethod) ParseMagickOption(MagickLayerOptions,
7994 MagickFalse,argv[i+1]);
7995 switch (method)
7996 {
7997 case CoalesceLayer:
7998 {
7999 layers=CoalesceImages(*images,exception);
8000 break;
8001 }
8002 case CompareAnyLayer:
8003 case CompareClearLayer:
8004 case CompareOverlayLayer:
8005 default:
8006 {
8007 layers=CompareImageLayers(*images,method,exception);
8008 break;
8009 }
8010 case MergeLayer:
8011 case FlattenLayer:
8012 case MosaicLayer:
8013 case TrimBoundsLayer:
8014 {
8015 layers=MergeImageLayers(*images,method,exception);
8016 break;
8017 }
8018 case DisposeLayer:
8019 {
8020 layers=DisposeImages(*images,exception);
8021 break;
8022 }
8023 case OptimizeImageLayer:
8024 {
8025 layers=OptimizeImageLayers(*images,exception);
8026 break;
8027 }
8028 case OptimizePlusLayer:
8029 {
8030 layers=OptimizePlusImageLayers(*images,exception);
8031 break;
8032 }
8033 case OptimizeTransLayer:
8034 {
8035 OptimizeImageTransparency(*images,exception);
8036 break;
8037 }
8038 case RemoveDupsLayer:
8039 {
8040 RemoveDuplicateLayers(images,exception);
8041 break;
8042 }
8043 case RemoveZeroLayer:
8044 {
8045 RemoveZeroDelayLayers(images,exception);
8046 break;
8047 }
8048 case OptimizeLayer:
8049 {
8050 /*
8051 General Purpose, GIF Animation Optimizer.
8052 */
8053 layers=CoalesceImages(*images,exception);
8054 if (layers == (Image *) NULL)
8055 {
8056 status=MagickFalse;
8057 break;
8058 }
8059 InheritException(exception,&layers->exception);
8060 *images=DestroyImageList(*images);
8061 *images=layers;
8062 layers=OptimizeImageLayers(*images,exception);
8063 if (layers == (Image *) NULL)
8064 {
8065 status=MagickFalse;
8066 break;
8067 }
8068 InheritException(exception,&layers->exception);
8069 *images=DestroyImageList(*images);
8070 *images=layers;
8071 layers=(Image *) NULL;
8072 OptimizeImageTransparency(*images,exception);
8073 InheritException(exception,&(*images)->exception);
8074 (void) RemapImages(quantize_info,*images,(Image *) NULL);
8075 break;
8076 }
8077 case CompositeLayer:
8078 {
8079 CompositeOperator
8080 compose;
8081
8082 Image
8083 *source;
8084
8085 RectangleInfo
8086 geometry;
8087
8088 /*
8089 Split image sequence at the first 'NULL:' image.
8090 */
8091 source=(*images);
8092 while (source != (Image *) NULL)
8093 {
8094 source=GetNextImageInList(source);
8095 if ((source != (Image *) NULL) &&
8096 (LocaleCompare(source->magick,"NULL") == 0))
8097 break;
8098 }
8099 if (source != (Image *) NULL)
8100 {
8101 if ((GetPreviousImageInList(source) == (Image *) NULL) ||
8102 (GetNextImageInList(source) == (Image *) NULL))
8103 source=(Image *) NULL;
8104 else
8105 {
8106 /*
8107 Separate the two lists, junk the null: image.
8108 */
8109 source=SplitImageList(source->previous);
8110 DeleteImageFromList(&source);
8111 }
8112 }
8113 if (source == (Image *) NULL)
8114 {
8115 (void) ThrowMagickException(exception,GetMagickModule(),
8116 OptionError,"MissingNullSeparator","layers Composite");
8117 status=MagickFalse;
8118 break;
8119 }
8120 /*
8121 Adjust offset with gravity and virtual canvas.
8122 */
8123 SetGeometry(*images,&geometry);
8124 (void) ParseAbsoluteGeometry((*images)->geometry,&geometry);
8125 geometry.width=source->page.width != 0 ?
8126 source->page.width : source->columns;
8127 geometry.height=source->page.height != 0 ?
8128 source->page.height : source->rows;
8129 GravityAdjustGeometry((*images)->page.width != 0 ?
8130 (*images)->page.width : (*images)->columns,
8131 (*images)->page.height != 0 ? (*images)->page.height :
8132 (*images)->rows,(*images)->gravity,&geometry);
8133 compose=OverCompositeOp;
8134 option=GetImageOption(image_info,"compose");
8135 if (option != (const char *) NULL)
8136 compose=(CompositeOperator) ParseMagickOption(
8137 MagickComposeOptions,MagickFalse,option);
8138 CompositeLayers(*images,compose,source,geometry.x,geometry.y,
8139 exception);
8140 source=DestroyImageList(source);
8141 break;
8142 }
8143 }
8144 if (layers == (Image *) NULL)
8145 break;
8146 InheritException(exception,&layers->exception);
8147 *images=DestroyImageList(*images);
8148 *images=layers;
8149 break;
8150 }
8151 break;
8152 }
8153 case 'm':
8154 {
8155 if (LocaleCompare("map",option+1) == 0)
8156 {
8157 (void) SyncImagesSettings(image_info,*images);
8158 if (*option == '+')
8159 {
8160 (void) RemapImages(quantize_info,*images,(Image *) NULL);
8161 InheritException(exception,&(*images)->exception);
8162 break;
8163 }
8164 i++;
8165 break;
8166 }
cristyf40785b2010-03-06 02:27:27 +00008167 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00008168 {
8169 Image
cristyf40785b2010-03-06 02:27:27 +00008170 *maximum_image;
cristy1c274c92010-03-06 02:06:45 +00008171
cristyd18ae7c2010-03-07 17:39:52 +00008172 /*
8173 Maximum image sequence (deprecated).
8174 */
cristy1c274c92010-03-06 02:06:45 +00008175 (void) SyncImagesSettings(image_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00008176 maximum_image=EvaluateImages(*images,MaxEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00008177 if (maximum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00008178 {
8179 status=MagickFalse;
8180 break;
8181 }
8182 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00008183 *images=maximum_image;
cristy1c274c92010-03-06 02:06:45 +00008184 break;
8185 }
cristyf40785b2010-03-06 02:27:27 +00008186 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00008187 {
8188 Image
cristyf40785b2010-03-06 02:27:27 +00008189 *minimum_image;
cristy1c274c92010-03-06 02:06:45 +00008190
cristyd18ae7c2010-03-07 17:39:52 +00008191 /*
8192 Minimum image sequence (deprecated).
8193 */
cristy1c274c92010-03-06 02:06:45 +00008194 (void) SyncImagesSettings(image_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00008195 minimum_image=EvaluateImages(*images,MinEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00008196 if (minimum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00008197 {
8198 status=MagickFalse;
8199 break;
8200 }
8201 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00008202 *images=minimum_image;
cristy1c274c92010-03-06 02:06:45 +00008203 break;
8204 }
cristy3ed852e2009-09-05 21:47:34 +00008205 if (LocaleCompare("morph",option+1) == 0)
8206 {
8207 Image
8208 *morph_image;
8209
8210 (void) SyncImagesSettings(image_info,*images);
cristye27293e2009-12-18 02:53:20 +00008211 morph_image=MorphImages(*images,StringToUnsignedLong(argv[i+1]),
cristy3ed852e2009-09-05 21:47:34 +00008212 exception);
8213 if (morph_image == (Image *) NULL)
8214 {
8215 status=MagickFalse;
8216 break;
8217 }
8218 *images=DestroyImageList(*images);
8219 *images=morph_image;
8220 break;
8221 }
8222 if (LocaleCompare("mosaic",option+1) == 0)
8223 {
8224 Image
8225 *mosaic_image;
8226
8227 (void) SyncImagesSettings(image_info,*images);
8228 mosaic_image=MergeImageLayers(*images,MosaicLayer,exception);
8229 if (mosaic_image == (Image *) NULL)
8230 {
8231 status=MagickFalse;
8232 break;
8233 }
8234 *images=DestroyImageList(*images);
8235 *images=mosaic_image;
8236 break;
8237 }
8238 break;
8239 }
8240 case 'p':
8241 {
8242 if (LocaleCompare("print",option+1) == 0)
8243 {
8244 char
8245 *string;
8246
8247 (void) SyncImagesSettings(image_info,*images);
8248 string=InterpretImageProperties(image_info,*images,argv[i+1]);
8249 if (string == (char *) NULL)
8250 break;
8251 InheritException(exception,&(*images)->exception);
8252 (void) fprintf(stdout,"%s",string);
8253 string=DestroyString(string);
8254 }
8255 if (LocaleCompare("process",option+1) == 0)
8256 {
8257 char
8258 **arguments;
8259
8260 int
8261 j,
8262 number_arguments;
8263
8264 (void) SyncImagesSettings(image_info,*images);
8265 arguments=StringToArgv(argv[i+1],&number_arguments);
8266 if (arguments == (char **) NULL)
8267 break;
8268 if ((argc > 1) && (strchr(arguments[1],'=') != (char *) NULL))
8269 {
8270 char
8271 breaker,
8272 quote,
8273 *token;
8274
8275 const char
8276 *arguments;
8277
8278 int
8279 next,
8280 status;
8281
8282 size_t
8283 length;
8284
8285 TokenInfo
8286 *token_info;
8287
8288 /*
8289 Support old style syntax, filter="-option arg".
8290 */
8291 length=strlen(argv[i+1]);
8292 token=(char *) NULL;
8293 if (~length >= MaxTextExtent)
8294 token=(char *) AcquireQuantumMemory(length+MaxTextExtent,
8295 sizeof(*token));
8296 if (token == (char *) NULL)
8297 break;
8298 next=0;
8299 arguments=argv[i+1];
8300 token_info=AcquireTokenInfo();
8301 status=Tokenizer(token_info,0,token,length,arguments,"","=",
8302 "\"",'\0',&breaker,&next,&quote);
8303 token_info=DestroyTokenInfo(token_info);
8304 if (status == 0)
8305 {
8306 const char
8307 *argv;
8308
8309 argv=(&(arguments[next]));
8310 (void) InvokeDynamicImageFilter(token,&(*images),1,&argv,
8311 exception);
8312 }
8313 token=DestroyString(token);
8314 break;
8315 }
cristy91c0da22010-05-02 01:44:07 +00008316 (void) SubstituteString(&arguments[1],"-","");
cristy3ed852e2009-09-05 21:47:34 +00008317 (void) InvokeDynamicImageFilter(arguments[1],&(*images),
8318 number_arguments-2,(const char **) arguments+2,exception);
8319 for (j=0; j < number_arguments; j++)
8320 arguments[j]=DestroyString(arguments[j]);
8321 arguments=(char **) RelinquishMagickMemory(arguments);
8322 break;
8323 }
8324 break;
8325 }
8326 case 'r':
8327 {
8328 if (LocaleCompare("reverse",option+1) == 0)
8329 {
8330 ReverseImageList(images);
8331 InheritException(exception,&(*images)->exception);
8332 break;
8333 }
8334 break;
8335 }
8336 case 's':
8337 {
8338 if (LocaleCompare("swap",option+1) == 0)
8339 {
8340 Image
8341 *p,
8342 *q,
8343 *swap;
8344
cristybb503372010-05-27 20:51:26 +00008345 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00008346 swap_index;
8347
8348 index=(-1);
8349 swap_index=(-2);
8350 if (*option != '+')
8351 {
8352 GeometryInfo
8353 geometry_info;
8354
8355 MagickStatusType
8356 flags;
8357
8358 swap_index=(-1);
8359 flags=ParseGeometry(argv[i+1],&geometry_info);
cristybb503372010-05-27 20:51:26 +00008360 index=(ssize_t) geometry_info.rho;
cristy3ed852e2009-09-05 21:47:34 +00008361 if ((flags & SigmaValue) != 0)
cristybb503372010-05-27 20:51:26 +00008362 swap_index=(ssize_t) geometry_info.sigma;
cristy3ed852e2009-09-05 21:47:34 +00008363 }
8364 p=GetImageFromList(*images,index);
8365 q=GetImageFromList(*images,swap_index);
8366 if ((p == (Image *) NULL) || (q == (Image *) NULL))
8367 {
8368 (void) ThrowMagickException(exception,GetMagickModule(),
8369 OptionError,"NoSuchImage","`%s'",(*images)->filename);
8370 status=MagickFalse;
8371 break;
8372 }
8373 if (p == q)
8374 break;
8375 swap=CloneImage(p,0,0,MagickTrue,exception);
8376 ReplaceImageInList(&p,CloneImage(q,0,0,MagickTrue,exception));
8377 ReplaceImageInList(&q,swap);
8378 *images=GetFirstImageInList(q);
8379 break;
8380 }
8381 break;
8382 }
8383 case 'w':
8384 {
8385 if (LocaleCompare("write",option+1) == 0)
8386 {
cristy071dd7b2010-04-09 13:04:54 +00008387 char
cristy06609ee2010-03-17 20:21:27 +00008388 key[MaxTextExtent];
8389
cristy3ed852e2009-09-05 21:47:34 +00008390 Image
8391 *write_images;
8392
8393 ImageInfo
8394 *write_info;
8395
8396 (void) SyncImagesSettings(image_info,*images);
cristy06609ee2010-03-17 20:21:27 +00008397 (void) FormatMagickString(key,MaxTextExtent,"cache:%s",argv[i+1]);
8398 (void) DeleteImageRegistry(key);
cristy3ed852e2009-09-05 21:47:34 +00008399 write_images=(*images);
8400 if (*option == '+')
8401 write_images=CloneImageList(*images,exception);
8402 write_info=CloneImageInfo(image_info);
8403 status&=WriteImages(write_info,write_images,argv[i+1],exception);
8404 write_info=DestroyImageInfo(write_info);
8405 if (*option == '+')
8406 write_images=DestroyImageList(write_images);
8407 break;
8408 }
8409 break;
8410 }
8411 default:
8412 break;
8413 }
8414 i+=count;
8415 }
8416 quantize_info=DestroyQuantizeInfo(quantize_info);
8417 return(status != 0 ? MagickTrue : MagickFalse);
8418}
8419
8420/*
8421%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8422% %
8423% %
8424% %
8425+ M o g r i f y I m a g e s %
8426% %
8427% %
8428% %
8429%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8430%
8431% MogrifyImages() applies image processing options to a sequence of images as
8432% prescribed by command line options.
8433%
8434% The format of the MogrifyImage method is:
8435%
8436% MagickBooleanType MogrifyImages(ImageInfo *image_info,
8437% const MagickBooleanType post,const int argc,const char **argv,
8438% Image **images,Exceptioninfo *exception)
8439%
8440% A description of each parameter follows:
8441%
8442% o image_info: the image info..
8443%
8444% o post: If true, post process image list operators otherwise pre-process.
8445%
8446% o argc: Specifies a pointer to an integer describing the number of
8447% elements in the argument vector.
8448%
8449% o argv: Specifies a pointer to a text array containing the command line
8450% arguments.
8451%
8452% o images: the images.
8453%
8454% o exception: return any errors or warnings in this structure.
8455%
8456*/
8457WandExport MagickBooleanType MogrifyImages(ImageInfo *image_info,
8458 const MagickBooleanType post,const int argc,const char **argv,
8459 Image **images,ExceptionInfo *exception)
8460{
8461#define MogrifyImageTag "Mogrify/Image"
8462
8463 Image
8464 *image,
8465 *mogrify_images;
8466
cristy0e9f9c12010-02-11 03:00:47 +00008467 MagickBooleanType
8468 proceed;
8469
8470 MagickSizeType
8471 number_images;
8472
cristy3ed852e2009-09-05 21:47:34 +00008473 MagickStatusType
8474 status;
8475
cristybb503372010-05-27 20:51:26 +00008476 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00008477 i;
8478
cristy3ed852e2009-09-05 21:47:34 +00008479 /*
8480 Apply options to individual images in the list.
8481 */
8482 assert(image_info != (ImageInfo *) NULL);
8483 assert(image_info->signature == MagickSignature);
8484 if (images == (Image **) NULL)
8485 return(MogrifyImage(image_info,argc,argv,images,exception));
8486 assert((*images)->signature == MagickSignature);
8487 if ((*images)->debug != MagickFalse)
8488 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
8489 (*images)->filename);
8490 if ((argc <= 0) || (*argv == (char *) NULL))
8491 return(MagickTrue);
8492 (void) SetImageInfoProgressMonitor(image_info,(MagickProgressMonitor) NULL,
8493 (void *) NULL);
8494 mogrify_images=NewImageList();
8495 number_images=GetImageListLength(*images);
8496 status=0;
8497 if (post == MagickFalse)
8498 status&=MogrifyImageList(image_info,argc,argv,images,exception);
cristybb503372010-05-27 20:51:26 +00008499 for (i=0; i < (ssize_t) number_images; i++)
cristy3ed852e2009-09-05 21:47:34 +00008500 {
8501 image=RemoveFirstImageFromList(images);
8502 if (image == (Image *) NULL)
8503 continue;
8504 status&=MogrifyImage(image_info,argc,argv,&image,exception);
8505 AppendImageToList(&mogrify_images,image);
cristy0e9f9c12010-02-11 03:00:47 +00008506 proceed=SetImageProgress(image,MogrifyImageTag,(MagickOffsetType) i,
8507 number_images);
8508 if (proceed == MagickFalse)
8509 break;
cristy3ed852e2009-09-05 21:47:34 +00008510 }
8511 if (post != MagickFalse)
8512 status&=MogrifyImageList(image_info,argc,argv,&mogrify_images,exception);
8513 *images=mogrify_images;
8514 return(status != 0 ? MagickTrue : MagickFalse);
8515}