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