blob: a0cada2d5aa440fdc5bd77c9b467998ac5105bff [file] [log] [blame]
cristy3ed852e2009-09-05 21:47:34 +00001/*
2%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3% %
4% %
5% %
6% M M OOO GGGGG RRRR IIIII FFFFF Y Y %
7% MM MM O O G R R I F Y Y %
8% M M M O O G GGG RRRR I FFF Y %
9% M M O O G G R R I F Y %
10% M M OOO GGGG R R IIIII F Y %
11% %
12% %
13% MagickWand Module Methods %
14% %
15% Software Design %
16% John Cristy %
17% March 2000 %
18% %
19% %
cristy16af1cb2009-12-11 21:38:29 +000020% Copyright 1999-2010 ImageMagick Studio LLC, a non-profit organization %
cristy3ed852e2009-09-05 21:47:34 +000021% dedicated to making software imaging solutions freely available. %
22% %
23% You may not use this file except in compliance with the License. You may %
24% obtain a copy of the License at %
25% %
26% http://www.imagemagick.org/script/license.php %
27% %
28% Unless required by applicable law or agreed to in writing, software %
29% distributed under the License is distributed on an "AS IS" BASIS, %
30% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
31% See the License for the specific language governing permissions and %
32% limitations under the License. %
33% %
34%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35%
36% Use the mogrify program to resize an image, blur, crop, despeckle, dither,
37% draw on, flip, join, re-sample, and much more. This tool is similiar to
38% convert except that the original image file is overwritten (unless you
39% change the file suffix with the -format option) with any changes you
cristy6a917d92009-10-06 19:23:54 +000040% request.
cristy3ed852e2009-09-05 21:47:34 +000041%
42*/
43
44/*
45 Include declarations.
46*/
47#include "wand/studio.h"
48#include "wand/MagickWand.h"
49#include "wand/mogrify-private.h"
cristy0e9f9c12010-02-11 03:00:47 +000050#include "magick/monitor-private.h"
cristy3980b0d2009-10-25 14:37:13 +000051#include "magick/thread-private.h"
cristyf2f27272009-12-17 14:48:46 +000052#include "magick/string-private.h"
cristy3ed852e2009-09-05 21:47:34 +000053
54/*
55 Define declarations.
56*/
57#define UndefinedCompressionQuality 0UL
58
59/*
60 Constant declaration.
61*/
62static const char
cristy7138c592009-09-08 13:58:52 +000063 BackgroundColor[] = "#fff", /* white */
64 BorderColor[] = "#dfdfdf", /* gray */
65 MatteColor[] = "#bdbdbd"; /* gray */
cristy3ed852e2009-09-05 21:47:34 +000066
67/*
68%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
69% %
70% %
71% %
cristy3980b0d2009-10-25 14:37:13 +000072+ M a g i c k C o m m a n d G e n e s i s %
73% %
74% %
75% %
76%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
77%
78% MagickCommandGenesis() applies image processing options to an image as
79% prescribed by command line options.
80%
81% The format of the MagickCommandGenesis method is:
82%
83% MagickBooleanType MagickCommandGenesis(ImageInfo *image_info,
84% MagickCommand command,const int argc,const char **argv,Image **image)
85%
86% A description of each parameter follows:
87%
88% o image_info: the image info.
89%
90% o command: the magick command.
91%
92% o argc: Specifies a pointer to an integer describing the number of
93% elements in the argument vector.
94%
95% o argv: Specifies a pointer to a text array containing the command line
96% arguments.
97%
98% o image: the image.
99%
100% o exception: return any errors or warnings in this structure.
101%
102*/
103WandExport MagickBooleanType MagickCommandGenesis(ImageInfo *image_info,
104 MagickCommand command,int argc,char **argv,char **metadata,
105 ExceptionInfo *exception)
106{
107 char
108 *option;
109
110 double
111 duration,
112 elapsed_time,
113 user_time;
114
cristy3980b0d2009-10-25 14:37:13 +0000115 MagickBooleanType
116 concurrent,
117 regard_warnings,
118 status;
119
cristybb503372010-05-27 20:51:26 +0000120 register ssize_t
cristy3980b0d2009-10-25 14:37:13 +0000121 i;
122
123 TimerInfo
124 *timer;
125
cristybb503372010-05-27 20:51:26 +0000126 size_t
cristy3980b0d2009-10-25 14:37:13 +0000127 iterations;
128
cristyd0a94fa2010-03-12 14:18:11 +0000129 (void) setlocale(LC_ALL,"");
130 (void) setlocale(LC_NUMERIC,"C");
cristy3980b0d2009-10-25 14:37:13 +0000131 concurrent=MagickFalse;
132 duration=(-1.0);
133 iterations=1;
cristy33557d72009-11-06 00:54:33 +0000134 status=MagickFalse;
cristy3980b0d2009-10-25 14:37:13 +0000135 regard_warnings=MagickFalse;
cristybb503372010-05-27 20:51:26 +0000136 for (i=1; i < (ssize_t) (argc-1); i++)
cristy3980b0d2009-10-25 14:37:13 +0000137 {
138 option=argv[i];
139 if ((strlen(option) == 1) || ((*option != '-') && (*option != '+')))
140 continue;
141 if (LocaleCompare("bench",option+1) == 0)
cristye27293e2009-12-18 02:53:20 +0000142 iterations=StringToUnsignedLong(argv[++i]);
cristy3980b0d2009-10-25 14:37:13 +0000143 if (LocaleCompare("concurrent",option+1) == 0)
144 concurrent=MagickTrue;
145 if (LocaleCompare("debug",option+1) == 0)
146 (void) SetLogEventMask(argv[++i]);
147 if (LocaleCompare("duration",option+1) == 0)
cristyf2f27272009-12-17 14:48:46 +0000148 duration=StringToDouble(argv[++i]);
cristy3980b0d2009-10-25 14:37:13 +0000149 if (LocaleCompare("regard-warnings",option+1) == 0)
150 regard_warnings=MagickTrue;
151 }
152 timer=AcquireTimerInfo();
cristyceae09d2009-10-28 17:18:47 +0000153 if (concurrent == MagickFalse)
cristy3980b0d2009-10-25 14:37:13 +0000154 {
cristybb503372010-05-27 20:51:26 +0000155 for (i=0; i < (ssize_t) iterations; i++)
cristy3980b0d2009-10-25 14:37:13 +0000156 {
cristy33557d72009-11-06 00:54:33 +0000157 if (status != MagickFalse)
cristyceae09d2009-10-28 17:18:47 +0000158 continue;
159 if (duration > 0)
160 {
161 if (GetElapsedTime(timer) > duration)
162 continue;
163 (void) ContinueTimer(timer);
164 }
165 status=command(image_info,argc,argv,metadata,exception);
cristy3980b0d2009-10-25 14:37:13 +0000166 if (exception->severity != UndefinedException)
167 {
168 if ((exception->severity > ErrorException) ||
169 (regard_warnings != MagickFalse))
170 status=MagickTrue;
171 CatchException(exception);
172 }
cristy3d1a5512009-10-25 21:23:27 +0000173 if ((metadata != (char **) NULL) && (*metadata != (char *) NULL))
cristy3980b0d2009-10-25 14:37:13 +0000174 {
175 (void) fputs(*metadata,stdout);
176 (void) fputc('\n',stdout);
177 *metadata=DestroyString(*metadata);
178 }
179 }
180 }
cristyceae09d2009-10-28 17:18:47 +0000181 else
182 {
183 SetOpenMPNested(1);
cristyb5d5f722009-11-04 03:03:49 +0000184#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristyceae09d2009-10-28 17:18:47 +0000185 # pragma omp parallel for shared(status)
186#endif
cristybb503372010-05-27 20:51:26 +0000187 for (i=0; i < (ssize_t) iterations; i++)
cristyceae09d2009-10-28 17:18:47 +0000188 {
cristy33557d72009-11-06 00:54:33 +0000189 if (status != MagickFalse)
cristyceae09d2009-10-28 17:18:47 +0000190 continue;
191 if (duration > 0)
192 {
193 if (GetElapsedTime(timer) > duration)
194 continue;
195 (void) ContinueTimer(timer);
196 }
197 status=command(image_info,argc,argv,metadata,exception);
cristyb5d5f722009-11-04 03:03:49 +0000198#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy524549f2010-06-20 21:10:20 +0000199 # pragma omp critical (MagickCore_CommandGenesis)
cristyceae09d2009-10-28 17:18:47 +0000200#endif
201 {
202 if (exception->severity != UndefinedException)
203 {
204 if ((exception->severity > ErrorException) ||
205 (regard_warnings != MagickFalse))
206 status=MagickTrue;
207 CatchException(exception);
208 }
209 if ((metadata != (char **) NULL) && (*metadata != (char *) NULL))
210 {
211 (void) fputs(*metadata,stdout);
212 (void) fputc('\n',stdout);
213 *metadata=DestroyString(*metadata);
214 }
215 }
216 }
217 }
cristy3980b0d2009-10-25 14:37:13 +0000218 if (iterations > 1)
219 {
220 elapsed_time=GetElapsedTime(timer);
221 user_time=GetUserTime(timer);
cristy8cd5b312010-01-07 01:10:24 +0000222 (void) fprintf(stderr,
cristye8c25f92010-06-03 00:53:06 +0000223 "Performance: %.20gi %gips %0.3fu %.20g:%02g.%03g\n",(double)
224 iterations,1.0*iterations/elapsed_time,user_time,(double)
225 (elapsed_time/60.0),floor(fmod(elapsed_time,60.0)),(double)
226 (1000.0*(elapsed_time-floor(elapsed_time))));
cristy524549f2010-06-20 21:10:20 +0000227 (void) fflush(stderr);
cristy3980b0d2009-10-25 14:37:13 +0000228 }
229 timer=DestroyTimerInfo(timer);
cristy1f9e1ed2009-11-18 04:09:38 +0000230 return(status);
cristy3980b0d2009-10-25 14:37:13 +0000231}
232
233/*
234%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
235% %
236% %
237% %
cristy3ed852e2009-09-05 21:47:34 +0000238+ M o g r i f y I m a g e %
239% %
240% %
241% %
242%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
243%
244% MogrifyImage() applies image processing options to an image as prescribed
245% by command line options.
246%
247% The format of the MogrifyImage method is:
248%
249% MagickBooleanType MogrifyImage(ImageInfo *image_info,const int argc,
250% const char **argv,Image **image)
251%
252% A description of each parameter follows:
253%
254% o image_info: the image info..
255%
256% o argc: Specifies a pointer to an integer describing the number of
257% elements in the argument vector.
258%
259% o argv: Specifies a pointer to a text array containing the command line
260% arguments.
261%
262% o image: the image.
263%
264% o exception: return any errors or warnings in this structure.
265%
266*/
267
268static inline Image *GetImageCache(const ImageInfo *image_info,const char *path,
269 ExceptionInfo *exception)
270{
271 char
272 key[MaxTextExtent];
273
274 ExceptionInfo
275 *sans_exception;
276
277 Image
278 *image;
279
280 ImageInfo
281 *read_info;
282
283 (void) FormatMagickString(key,MaxTextExtent,"cache:%s",path);
284 sans_exception=AcquireExceptionInfo();
285 image=(Image *) GetImageRegistry(ImageRegistryType,key,sans_exception);
286 sans_exception=DestroyExceptionInfo(sans_exception);
287 if (image != (Image *) NULL)
288 return(image);
289 read_info=CloneImageInfo(image_info);
290 (void) CopyMagickString(read_info->filename,path,MaxTextExtent);
291 image=ReadImage(read_info,exception);
292 read_info=DestroyImageInfo(read_info);
293 if (image != (Image *) NULL)
294 (void) SetImageRegistry(ImageRegistryType,key,image,exception);
295 return(image);
296}
297
cristy3ed852e2009-09-05 21:47:34 +0000298static MagickBooleanType IsPathWritable(const char *path)
299{
300 if (IsPathAccessible(path) == MagickFalse)
301 return(MagickFalse);
302 if (access(path,W_OK) != 0)
303 return(MagickFalse);
304 return(MagickTrue);
305}
306
cristybb503372010-05-27 20:51:26 +0000307static inline ssize_t MagickMax(const ssize_t x,const ssize_t y)
cristy3ed852e2009-09-05 21:47:34 +0000308{
309 if (x > y)
310 return(x);
311 return(y);
312}
313
314static MagickBooleanType MonitorProgress(const char *text,
cristyb32b90a2009-09-07 21:45:48 +0000315 const MagickOffsetType offset,const MagickSizeType extent,
cristy3ed852e2009-09-05 21:47:34 +0000316 void *wand_unused(client_data))
317{
318 char
319 message[MaxTextExtent],
320 tag[MaxTextExtent];
321
322 const char
323 *locale_message;
324
325 register char
326 *p;
327
cristyb32b90a2009-09-07 21:45:48 +0000328 if (extent < 2)
cristy3ed852e2009-09-05 21:47:34 +0000329 return(MagickTrue);
330 (void) CopyMagickMemory(tag,text,MaxTextExtent);
331 p=strrchr(tag,'/');
332 if (p != (char *) NULL)
333 *p='\0';
334 (void) FormatMagickString(message,MaxTextExtent,"Monitor/%s",tag);
335 locale_message=GetLocaleMessage(message);
336 if (locale_message == message)
337 locale_message=tag;
338 if (p == (char *) NULL)
cristyb32b90a2009-09-07 21:45:48 +0000339 (void) fprintf(stderr,"%s: %ld of %lu, %02ld%% complete\r",locale_message,
cristyf2faecf2010-05-28 19:19:36 +0000340 (long) offset,(unsigned long) extent,(long) (100L*offset/(extent-1)));
cristy3ed852e2009-09-05 21:47:34 +0000341 else
cristyb32b90a2009-09-07 21:45:48 +0000342 (void) fprintf(stderr,"%s[%s]: %ld of %lu, %02ld%% complete\r",
cristyf2faecf2010-05-28 19:19:36 +0000343 locale_message,p+1,(long) offset,(unsigned long) extent,(long)
cristyb32b90a2009-09-07 21:45:48 +0000344 (100L*offset/(extent-1)));
345 if (offset == (MagickOffsetType) (extent-1))
cristy3ed852e2009-09-05 21:47:34 +0000346 (void) fprintf(stderr,"\n");
347 (void) fflush(stderr);
348 return(MagickTrue);
349}
350
351static Image *SparseColorOption(const Image *image,const ChannelType channel,
352 const SparseColorMethod method,const char *arguments,
353 const MagickBooleanType color_from_image,ExceptionInfo *exception)
354{
355 ChannelType
356 channels;
357
358 char
359 token[MaxTextExtent];
360
361 const char
362 *p;
363
364 double
365 *sparse_arguments;
366
cristybb503372010-05-27 20:51:26 +0000367 register size_t
cristy3ed852e2009-09-05 21:47:34 +0000368 x;
369
cristybb503372010-05-27 20:51:26 +0000370 size_t
cristy3ed852e2009-09-05 21:47:34 +0000371 number_arguments;
372
cristybb503372010-05-27 20:51:26 +0000373 size_t
cristy3ed852e2009-09-05 21:47:34 +0000374 number_colors;
375
376 Image
377 *sparse_image;
378
379 MagickPixelPacket
380 color;
381
382 MagickBooleanType
383 error;
384
385 assert(image != (Image *) NULL);
386 assert(image->signature == MagickSignature);
387 if (image->debug != MagickFalse)
388 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
389 assert(exception != (ExceptionInfo *) NULL);
390 assert(exception->signature == MagickSignature);
391 /*
392 Limit channels according to image - and add up number of color channel.
393 */
394 channels=channel;
395 if (image->colorspace != CMYKColorspace)
396 channels=(ChannelType) (channels & ~IndexChannel); /* no index channel */
397 if (image->matte == MagickFalse)
398 channels=(ChannelType) (channels & ~OpacityChannel); /* no alpha channel */
399 number_colors=0;
400 if ((channels & RedChannel) != 0)
401 number_colors++;
402 if ((channels & GreenChannel) != 0)
403 number_colors++;
404 if ((channels & BlueChannel) != 0)
405 number_colors++;
406 if ((channels & IndexChannel) != 0)
407 number_colors++;
408 if ((channels & OpacityChannel) != 0)
409 number_colors++;
410 /*
411 Read string, to determine number of arguments needed,
412 */
413 p=arguments;
414 x=0;
415 while( *p != '\0' )
416 {
417 GetMagickToken(p,&p,token);
418 if ( token[0] == ',' ) continue;
419 if ( isalpha((int) token[0]) || token[0] == '#' ) {
420 if ( color_from_image ) {
421 (void) ThrowMagickException(exception,GetMagickModule(),
422 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
423 "Color arg given, when colors are coming from image");
424 return( (Image *)NULL);
425 }
426 x += number_colors; /* color argument */
427 }
428 else {
429 x++; /* floating point argument */
430 }
431 }
432 error=MagickTrue;
433 if ( color_from_image ) {
434 /* just the control points are being given */
435 error = ( x % 2 != 0 ) ? MagickTrue : MagickFalse;
436 number_arguments=(x/2)*(2+number_colors);
437 }
438 else {
439 /* control points and color values */
440 error = ( x % (2+number_colors) != 0 ) ? MagickTrue : MagickFalse;
441 number_arguments=x;
442 }
443 if ( error ) {
444 (void) ThrowMagickException(exception,GetMagickModule(),
445 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
446 "Invalid number of Arguments");
447 return( (Image *)NULL);
448 }
449
450 /* Allocate and fill in the floating point arguments */
451 sparse_arguments=(double *) AcquireQuantumMemory(number_arguments,
452 sizeof(*sparse_arguments));
453 if (sparse_arguments == (double *) NULL) {
454 (void) ThrowMagickException(exception,GetMagickModule(),ResourceLimitError,
455 "MemoryAllocationFailed","%s","SparseColorOption");
456 return( (Image *)NULL);
457 }
458 (void) ResetMagickMemory(sparse_arguments,0,number_arguments*
459 sizeof(*sparse_arguments));
460 p=arguments;
461 x=0;
462 while( *p != '\0' && x < number_arguments ) {
463 /* X coordinate */
464 token[0]=','; while ( token[0] == ',' ) GetMagickToken(p,&p,token);
465 if ( token[0] == '\0' ) break;
466 if ( isalpha((int) token[0]) || token[0] == '#' ) {
467 (void) ThrowMagickException(exception,GetMagickModule(),
468 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
469 "Color found, instead of X-coord");
470 error = MagickTrue;
471 break;
472 }
cristyf2f27272009-12-17 14:48:46 +0000473 sparse_arguments[x++]=StringToDouble(token);
cristy3ed852e2009-09-05 21:47:34 +0000474 /* Y coordinate */
475 token[0]=','; while ( token[0] == ',' ) GetMagickToken(p,&p,token);
476 if ( token[0] == '\0' ) break;
477 if ( isalpha((int) token[0]) || token[0] == '#' ) {
478 (void) ThrowMagickException(exception,GetMagickModule(),
479 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
480 "Color found, instead of Y-coord");
481 error = MagickTrue;
482 break;
483 }
cristyf2f27272009-12-17 14:48:46 +0000484 sparse_arguments[x++]=StringToDouble(token);
cristy3ed852e2009-09-05 21:47:34 +0000485 /* color values for this control point */
486#if 0
487 if ( (color_from_image ) {
488 /* get color from image */
489 /* HOW??? */
490 }
491 else
492#endif
493 {
494 /* color name or function given in string argument */
495 token[0]=','; while ( token[0] == ',' ) GetMagickToken(p,&p,token);
496 if ( token[0] == '\0' ) break;
497 if ( isalpha((int) token[0]) || token[0] == '#' ) {
498 /* Color string given */
499 (void) QueryMagickColor(token,&color,exception);
500 if ( channels & RedChannel )
501 sparse_arguments[x++] = QuantumScale*color.red;
502 if ( channels & GreenChannel )
503 sparse_arguments[x++] = QuantumScale*color.green;
504 if ( channels & BlueChannel )
505 sparse_arguments[x++] = QuantumScale*color.blue;
506 if ( channels & IndexChannel )
507 sparse_arguments[x++] = QuantumScale*color.index;
508 if ( channels & OpacityChannel )
509 sparse_arguments[x++] = QuantumScale*color.opacity;
510 }
511 else {
512#if 0
513 /* the color name/function/value was not found - error */
514 break;
515#else
516 /* Colors given as a set of floating point values - experimental */
517 /* NB: token contains the first floating point value to use! */
518 if ( channels & RedChannel ) {
519 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
520 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
521 break;
cristy0f19e682009-12-17 14:55:51 +0000522 sparse_arguments[x++]=StringToDouble(token);
cristy3ed852e2009-09-05 21:47:34 +0000523 token[0] = ','; /* used this token - get another */
524 }
525 if ( channels & GreenChannel ) {
526 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
527 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
528 break;
cristy0f19e682009-12-17 14:55:51 +0000529 sparse_arguments[x++]=StringToDouble(token);
cristy3ed852e2009-09-05 21:47:34 +0000530 token[0] = ','; /* used this token - get another */
531 }
532 if ( channels & BlueChannel ) {
533 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
534 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
535 break;
cristy0f19e682009-12-17 14:55:51 +0000536 sparse_arguments[x++]=StringToDouble(token);
cristy3ed852e2009-09-05 21:47:34 +0000537 token[0] = ','; /* used this token - get another */
538 }
539 if ( channels & IndexChannel ) {
540 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
541 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
542 break;
cristy0f19e682009-12-17 14:55:51 +0000543 sparse_arguments[x++]=StringToDouble(token);
cristy3ed852e2009-09-05 21:47:34 +0000544 token[0] = ','; /* used this token - get another */
545 }
546 if ( channels & OpacityChannel ) {
547 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
548 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
549 break;
cristy0f19e682009-12-17 14:55:51 +0000550 sparse_arguments[x++]=StringToDouble(token);
cristy3ed852e2009-09-05 21:47:34 +0000551 token[0] = ','; /* used this token - get another */
552 }
553#endif
554 }
555 }
556 }
557 if ( number_arguments != x && !error ) {
558 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
559 "InvalidArgument","`%s': %s","sparse-color","Argument Parsing Error");
560 sparse_arguments=(double *) RelinquishMagickMemory(sparse_arguments);
561 return( (Image *)NULL);
562 }
563 if ( error )
564 return( (Image *)NULL);
565
566 /* Call the Interpolation function with the parsed arguments */
567 sparse_image=SparseColorImage(image,channels,method,number_arguments,
568 sparse_arguments,exception);
569 sparse_arguments=(double *) RelinquishMagickMemory(sparse_arguments);
570 return( sparse_image );
571}
572
573WandExport MagickBooleanType MogrifyImage(ImageInfo *image_info,const int argc,
574 const char **argv,Image **image,ExceptionInfo *exception)
575{
576 ChannelType
577 channel;
578
579 const char
580 *format,
581 *option;
582
583 DrawInfo
584 *draw_info;
585
586 GeometryInfo
587 geometry_info;
588
589 Image
590 *region_image;
591
cristy6b3da3a2010-06-20 02:21:46 +0000592 ImageInfo
593 *mogrify_info;
594
cristybb503372010-05-27 20:51:26 +0000595 ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000596 count;
597
598 MagickBooleanType
599 status;
600
601 MagickPixelPacket
602 fill;
603
604 MagickStatusType
605 flags;
606
607 QuantizeInfo
608 *quantize_info;
609
610 RectangleInfo
611 geometry,
612 region_geometry;
613
cristybb503372010-05-27 20:51:26 +0000614 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000615 i;
616
617 /*
618 Initialize method variables.
619 */
620 assert(image_info != (const ImageInfo *) NULL);
621 assert(image_info->signature == MagickSignature);
622 assert(image != (Image **) NULL);
623 assert((*image)->signature == MagickSignature);
624 if ((*image)->debug != MagickFalse)
625 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",(*image)->filename);
626 if (argc < 0)
627 return(MagickTrue);
cristy6b3da3a2010-06-20 02:21:46 +0000628 mogrify_info=CloneImageInfo(image_info);
629 draw_info=CloneDrawInfo(mogrify_info,(DrawInfo *) NULL);
630 quantize_info=AcquireQuantizeInfo(mogrify_info);
cristy3ed852e2009-09-05 21:47:34 +0000631 SetGeometryInfo(&geometry_info);
632 GetMagickPixelPacket(*image,&fill);
633 SetMagickPixelPacket(*image,&(*image)->background_color,(IndexPacket *) NULL,
634 &fill);
cristy6b3da3a2010-06-20 02:21:46 +0000635 channel=mogrify_info->channel;
636 format=GetImageOption(mogrify_info,"format");
cristy3ed852e2009-09-05 21:47:34 +0000637 SetGeometry(*image,&region_geometry);
638 region_image=NewImageList();
639 /*
640 Transmogrify the image.
641 */
cristybb503372010-05-27 20:51:26 +0000642 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +0000643 {
644 option=argv[i];
645 if (IsMagickOption(option) == MagickFalse)
646 continue;
647 count=MagickMax(ParseMagickOption(MagickCommandOptions,MagickFalse,option),
648 0L);
cristycee97112010-05-28 00:44:52 +0000649 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +0000650 break;
cristy6b3da3a2010-06-20 02:21:46 +0000651 status=MogrifyImageInfo(mogrify_info,(int) count+1,argv+i,exception);
cristy3ed852e2009-09-05 21:47:34 +0000652 switch (*(option+1))
653 {
654 case 'a':
655 {
656 if (LocaleCompare("adaptive-blur",option+1) == 0)
657 {
658 Image
659 *blur_image;
660
661 /*
662 Adaptive blur image.
663 */
cristy6b3da3a2010-06-20 02:21:46 +0000664 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000665 flags=ParseGeometry(argv[i+1],&geometry_info);
666 if ((flags & SigmaValue) == 0)
667 geometry_info.sigma=1.0;
668 blur_image=AdaptiveBlurImageChannel(*image,channel,
669 geometry_info.rho,geometry_info.sigma,exception);
670 if (blur_image == (Image *) NULL)
671 break;
672 *image=DestroyImage(*image);
673 *image=blur_image;
674 break;
675 }
676 if (LocaleCompare("adaptive-resize",option+1) == 0)
677 {
678 Image
679 *resize_image;
680
681 /*
682 Adaptive resize image.
683 */
cristy6b3da3a2010-06-20 02:21:46 +0000684 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000685 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
686 resize_image=AdaptiveResizeImage(*image,geometry.width,
687 geometry.height,exception);
688 if (resize_image == (Image *) NULL)
689 break;
690 *image=DestroyImage(*image);
691 *image=resize_image;
692 break;
693 }
694 if (LocaleCompare("adaptive-sharpen",option+1) == 0)
695 {
696 Image
697 *sharp_image;
698
699 /*
700 Adaptive sharpen image.
701 */
cristy6b3da3a2010-06-20 02:21:46 +0000702 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000703 flags=ParseGeometry(argv[i+1],&geometry_info);
704 if ((flags & SigmaValue) == 0)
705 geometry_info.sigma=1.0;
706 sharp_image=AdaptiveSharpenImageChannel(*image,channel,
707 geometry_info.rho,geometry_info.sigma,exception);
708 if (sharp_image == (Image *) NULL)
709 break;
710 *image=DestroyImage(*image);
711 *image=sharp_image;
712 break;
713 }
714 if (LocaleCompare("affine",option+1) == 0)
715 {
716 /*
717 Affine matrix.
718 */
719 if (*option == '+')
720 {
721 GetAffineMatrix(&draw_info->affine);
722 break;
723 }
724 (void) ParseAffineGeometry(argv[i+1],&draw_info->affine,exception);
725 break;
726 }
727 if (LocaleCompare("alpha",option+1) == 0)
728 {
729 AlphaChannelType
730 alpha_type;
731
cristy6b3da3a2010-06-20 02:21:46 +0000732 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000733 alpha_type=(AlphaChannelType) ParseMagickOption(MagickAlphaOptions,
734 MagickFalse,argv[i+1]);
735 (void) SetImageAlphaChannel(*image,alpha_type);
736 InheritException(exception,&(*image)->exception);
737 break;
738 }
739 if (LocaleCompare("annotate",option+1) == 0)
740 {
741 char
742 *text,
743 geometry[MaxTextExtent];
744
745 /*
746 Annotate image.
747 */
cristy6b3da3a2010-06-20 02:21:46 +0000748 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000749 SetGeometryInfo(&geometry_info);
750 flags=ParseGeometry(argv[i+1],&geometry_info);
751 if ((flags & SigmaValue) == 0)
752 geometry_info.sigma=geometry_info.rho;
cristy6b3da3a2010-06-20 02:21:46 +0000753 text=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
cristy3ed852e2009-09-05 21:47:34 +0000754 InheritException(exception,&(*image)->exception);
755 if (text == (char *) NULL)
756 break;
757 (void) CloneString(&draw_info->text,text);
758 text=DestroyString(text);
759 (void) FormatMagickString(geometry,MaxTextExtent,"%+f%+f",
760 geometry_info.xi,geometry_info.psi);
761 (void) CloneString(&draw_info->geometry,geometry);
762 draw_info->affine.sx=cos(DegreesToRadians(
763 fmod(geometry_info.rho,360.0)));
764 draw_info->affine.rx=sin(DegreesToRadians(
765 fmod(geometry_info.rho,360.0)));
766 draw_info->affine.ry=(-sin(DegreesToRadians(
767 fmod(geometry_info.sigma,360.0))));
768 draw_info->affine.sy=cos(DegreesToRadians(
769 fmod(geometry_info.sigma,360.0)));
770 (void) AnnotateImage(*image,draw_info);
771 InheritException(exception,&(*image)->exception);
772 break;
773 }
774 if (LocaleCompare("antialias",option+1) == 0)
775 {
776 draw_info->stroke_antialias=(*option == '-') ? MagickTrue :
777 MagickFalse;
778 draw_info->text_antialias=(*option == '-') ? MagickTrue :
779 MagickFalse;
780 break;
781 }
782 if (LocaleCompare("auto-gamma",option+1) == 0)
783 {
784 /*
785 Auto Adjust Gamma of image based on its mean
786 */
cristy6b3da3a2010-06-20 02:21:46 +0000787 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000788 (void) AutoGammaImageChannel(*image,channel);
789 break;
790 }
791 if (LocaleCompare("auto-level",option+1) == 0)
792 {
793 /*
794 Perfectly Normalize (max/min stretch) the image
795 */
cristy6b3da3a2010-06-20 02:21:46 +0000796 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000797 (void) AutoLevelImageChannel(*image,channel);
798 break;
799 }
800 if (LocaleCompare("auto-orient",option+1) == 0)
801 {
802 Image
803 *orient_image;
804
cristy6b3da3a2010-06-20 02:21:46 +0000805 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000806 orient_image=NewImageList();
807 switch ((*image)->orientation)
808 {
809 case TopRightOrientation:
810 {
811 orient_image=FlopImage(*image,exception);
812 break;
813 }
814 case BottomRightOrientation:
815 {
816 orient_image=RotateImage(*image,180.0,exception);
817 break;
818 }
819 case BottomLeftOrientation:
820 {
821 orient_image=FlipImage(*image,exception);
822 break;
823 }
824 case LeftTopOrientation:
825 {
826 orient_image=TransposeImage(*image,exception);
827 break;
828 }
829 case RightTopOrientation:
830 {
831 orient_image=RotateImage(*image,90.0,exception);
832 break;
833 }
834 case RightBottomOrientation:
835 {
836 orient_image=TransverseImage(*image,exception);
837 break;
838 }
839 case LeftBottomOrientation:
840 {
841 orient_image=RotateImage(*image,270.0,exception);
842 break;
843 }
844 default:
845 break;
846 }
847 if (orient_image == (Image *) NULL)
848 break;
849 orient_image->orientation=TopLeftOrientation;
850 *image=DestroyImage(*image);
851 *image=orient_image;
852 break;
853 }
854 break;
855 }
856 case 'b':
857 {
858 if (LocaleCompare("black-threshold",option+1) == 0)
859 {
860 /*
861 Black threshold image.
862 */
cristy6b3da3a2010-06-20 02:21:46 +0000863 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000864 (void) BlackThresholdImageChannel(*image,channel,argv[i+1],
865 exception);
866 InheritException(exception,&(*image)->exception);
867 break;
868 }
869 if (LocaleCompare("blue-shift",option+1) == 0)
870 {
871 Image
872 *shift_image;
873
874 /*
875 Blue shift image.
876 */
cristy6b3da3a2010-06-20 02:21:46 +0000877 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000878 geometry_info.rho=1.5;
879 if (*option == '-')
880 flags=ParseGeometry(argv[i+1],&geometry_info);
881 shift_image=BlueShiftImage(*image,geometry_info.rho,exception);
882 if (shift_image == (Image *) NULL)
883 break;
884 *image=DestroyImage(*image);
885 *image=shift_image;
886 break;
887 }
888 if (LocaleCompare("blur",option+1) == 0)
889 {
890 Image
891 *blur_image;
892
893 /*
894 Gaussian blur image.
895 */
cristy6b3da3a2010-06-20 02:21:46 +0000896 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000897 flags=ParseGeometry(argv[i+1],&geometry_info);
898 if ((flags & SigmaValue) == 0)
899 geometry_info.sigma=1.0;
900 blur_image=BlurImageChannel(*image,channel,geometry_info.rho,
901 geometry_info.sigma,exception);
902 if (blur_image == (Image *) NULL)
903 break;
904 *image=DestroyImage(*image);
905 *image=blur_image;
906 break;
907 }
908 if (LocaleCompare("border",option+1) == 0)
909 {
910 Image
911 *border_image;
912
913 /*
914 Surround image with a border of solid color.
915 */
cristy6b3da3a2010-06-20 02:21:46 +0000916 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000917 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
918 if ((flags & SigmaValue) == 0)
919 geometry.height=geometry.width;
920 border_image=BorderImage(*image,&geometry,exception);
921 if (border_image == (Image *) NULL)
922 break;
923 *image=DestroyImage(*image);
924 *image=border_image;
925 break;
926 }
927 if (LocaleCompare("bordercolor",option+1) == 0)
928 {
929 if (*option == '+')
930 {
931 (void) QueryColorDatabase(BorderColor,&draw_info->border_color,
932 exception);
933 break;
934 }
935 (void) QueryColorDatabase(argv[i+1],&draw_info->border_color,
936 exception);
937 break;
938 }
939 if (LocaleCompare("box",option+1) == 0)
940 {
941 (void) QueryColorDatabase(argv[i+1],&draw_info->undercolor,
942 exception);
943 break;
944 }
cristya28d6b82010-01-11 20:03:47 +0000945 if (LocaleCompare("brightness-contrast",option+1) == 0)
946 {
947 double
948 brightness,
949 contrast;
950
951 GeometryInfo
952 geometry_info;
953
954 MagickStatusType
955 flags;
956
957 /*
958 Brightness / contrast image.
959 */
cristy6b3da3a2010-06-20 02:21:46 +0000960 (void) SyncImageSettings(mogrify_info,*image);
cristya28d6b82010-01-11 20:03:47 +0000961 flags=ParseGeometry(argv[i+1],&geometry_info);
962 brightness=geometry_info.rho;
cristy81fbc8b2010-01-11 20:04:07 +0000963 contrast=0.0;
cristya28d6b82010-01-11 20:03:47 +0000964 if ((flags & SigmaValue) != 0)
965 contrast=geometry_info.sigma;
cristy02cc0f22010-01-12 00:02:32 +0000966 (void) BrightnessContrastImageChannel(*image,channel,brightness,
967 contrast);
cristya28d6b82010-01-11 20:03:47 +0000968 InheritException(exception,&(*image)->exception);
969 break;
970 }
cristy3ed852e2009-09-05 21:47:34 +0000971 break;
972 }
973 case 'c':
974 {
975 if (LocaleCompare("cdl",option+1) == 0)
976 {
977 char
978 *color_correction_collection;
979
980 /*
981 Color correct with a color decision list.
982 */
cristy6b3da3a2010-06-20 02:21:46 +0000983 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000984 color_correction_collection=FileToString(argv[i+1],~0,exception);
985 if (color_correction_collection == (char *) NULL)
986 break;
987 (void) ColorDecisionListImage(*image,color_correction_collection);
988 InheritException(exception,&(*image)->exception);
989 break;
990 }
991 if (LocaleCompare("channel",option+1) == 0)
992 {
993 if (*option == '+')
994 {
995 channel=DefaultChannels;
996 break;
997 }
998 channel=(ChannelType) ParseChannelOption(argv[i+1]);
999 break;
1000 }
1001 if (LocaleCompare("charcoal",option+1) == 0)
1002 {
1003 Image
1004 *charcoal_image;
1005
1006 /*
1007 Charcoal image.
1008 */
cristy6b3da3a2010-06-20 02:21:46 +00001009 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001010 flags=ParseGeometry(argv[i+1],&geometry_info);
1011 if ((flags & SigmaValue) == 0)
1012 geometry_info.sigma=1.0;
1013 charcoal_image=CharcoalImage(*image,geometry_info.rho,
1014 geometry_info.sigma,exception);
1015 if (charcoal_image == (Image *) NULL)
1016 break;
1017 *image=DestroyImage(*image);
1018 *image=charcoal_image;
1019 break;
1020 }
1021 if (LocaleCompare("chop",option+1) == 0)
1022 {
1023 Image
1024 *chop_image;
1025
1026 /*
1027 Chop the image.
1028 */
cristy6b3da3a2010-06-20 02:21:46 +00001029 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001030 (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1031 chop_image=ChopImage(*image,&geometry,exception);
1032 if (chop_image == (Image *) NULL)
1033 break;
1034 *image=DestroyImage(*image);
1035 *image=chop_image;
1036 break;
1037 }
cristy1eb45dd2009-09-25 16:38:06 +00001038 if (LocaleCompare("clamp",option+1) == 0)
1039 {
1040 /*
1041 Clamp image.
1042 */
cristy6b3da3a2010-06-20 02:21:46 +00001043 (void) SyncImageSettings(mogrify_info,*image);
cristy1eb45dd2009-09-25 16:38:06 +00001044 (void) ClampImageChannel(*image,channel);
1045 InheritException(exception,&(*image)->exception);
1046 break;
1047 }
cristy3ed852e2009-09-05 21:47:34 +00001048 if (LocaleCompare("clip",option+1) == 0)
1049 {
cristy6b3da3a2010-06-20 02:21:46 +00001050 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001051 if (*option == '+')
1052 {
1053 (void) SetImageClipMask(*image,(Image *) NULL);
1054 InheritException(exception,&(*image)->exception);
1055 break;
1056 }
1057 (void) ClipImage(*image);
1058 InheritException(exception,&(*image)->exception);
1059 break;
1060 }
1061 if (LocaleCompare("clip-mask",option+1) == 0)
1062 {
cristyb0d3bb92010-09-22 14:37:58 +00001063 CacheView
1064 *mask_view;
1065
cristy3ed852e2009-09-05 21:47:34 +00001066 Image
cristyb0d3bb92010-09-22 14:37:58 +00001067 *mask_image;
cristy3ed852e2009-09-05 21:47:34 +00001068
cristybb503372010-05-27 20:51:26 +00001069 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001070 y;
1071
cristybb503372010-05-27 20:51:26 +00001072 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001073 x;
1074
1075 register PixelPacket
cristyc47d1f82009-11-26 01:44:43 +00001076 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00001077
cristy6b3da3a2010-06-20 02:21:46 +00001078 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001079 if (*option == '+')
1080 {
1081 /*
1082 Remove a mask.
1083 */
1084 (void) SetImageMask(*image,(Image *) NULL);
1085 InheritException(exception,&(*image)->exception);
1086 break;
1087 }
1088 /*
1089 Set the image mask.
1090 */
cristyb0d3bb92010-09-22 14:37:58 +00001091 mask_image=GetImageCache(mogrify_info,argv[i+1],exception);
1092 if (mask_image == (Image *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001093 break;
cristyb0d3bb92010-09-22 14:37:58 +00001094 if (SetImageStorageClass(mask_image,DirectClass) == MagickFalse)
1095 return(MagickFalse);
1096 mask_view=AcquireCacheView(mask_image);
1097 for (y=0; y < (ssize_t) mask_image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00001098 {
cristyb0d3bb92010-09-22 14:37:58 +00001099 q=GetCacheViewAuthenticPixels(mask_view,0,y,mask_image->columns,1,
1100 exception);
cristy3ed852e2009-09-05 21:47:34 +00001101 if (q == (PixelPacket *) NULL)
1102 break;
cristyb0d3bb92010-09-22 14:37:58 +00001103 for (x=0; x < (ssize_t) mask_image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00001104 {
cristyb0d3bb92010-09-22 14:37:58 +00001105 if (mask_image->matte == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00001106 q->opacity=PixelIntensityToQuantum(q);
1107 q->red=q->opacity;
1108 q->green=q->opacity;
1109 q->blue=q->opacity;
1110 q++;
1111 }
cristyb0d3bb92010-09-22 14:37:58 +00001112 if (SyncCacheViewAuthenticPixels(mask_view,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00001113 break;
1114 }
cristyb0d3bb92010-09-22 14:37:58 +00001115 mask_view=DestroyCacheView(mask_view);
1116 mask_image->matte=MagickTrue;
1117 (void) SetImageClipMask(*image,mask_image);
1118 mask_image=DestroyImage(mask_image);
cristy3ed852e2009-09-05 21:47:34 +00001119 InheritException(exception,&(*image)->exception);
1120 break;
1121 }
1122 if (LocaleCompare("clip-path",option+1) == 0)
1123 {
cristy6b3da3a2010-06-20 02:21:46 +00001124 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001125 (void) ClipImagePath(*image,argv[i+1],*option == '-' ? MagickTrue :
1126 MagickFalse);
1127 InheritException(exception,&(*image)->exception);
1128 break;
1129 }
1130 if (LocaleCompare("colorize",option+1) == 0)
1131 {
1132 Image
1133 *colorize_image;
1134
1135 /*
1136 Colorize the image.
1137 */
cristy6b3da3a2010-06-20 02:21:46 +00001138 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001139 colorize_image=ColorizeImage(*image,argv[i+1],draw_info->fill,
1140 exception);
1141 if (colorize_image == (Image *) NULL)
1142 break;
1143 *image=DestroyImage(*image);
1144 *image=colorize_image;
1145 break;
1146 }
cristye6365592010-04-02 17:31:23 +00001147 if (LocaleCompare("color-matrix",option+1) == 0)
1148 {
1149 Image
1150 *color_image;
1151
1152 KernelInfo
1153 *kernel;
1154
cristy6b3da3a2010-06-20 02:21:46 +00001155 (void) SyncImageSettings(mogrify_info,*image);
cristye6365592010-04-02 17:31:23 +00001156 kernel=AcquireKernelInfo(argv[i+1]);
1157 if (kernel == (KernelInfo *) NULL)
1158 break;
1159 color_image=ColorMatrixImage(*image,kernel,exception);
1160 kernel=DestroyKernelInfo(kernel);
1161 if (color_image == (Image *) NULL)
1162 break;
1163 *image=DestroyImage(*image);
1164 *image=color_image;
1165 break;
1166 }
cristy3ed852e2009-09-05 21:47:34 +00001167 if (LocaleCompare("colors",option+1) == 0)
1168 {
1169 /*
1170 Reduce the number of colors in the image.
1171 */
cristy6b3da3a2010-06-20 02:21:46 +00001172 (void) SyncImageSettings(mogrify_info,*image);
cristye27293e2009-12-18 02:53:20 +00001173 quantize_info->number_colors=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00001174 if (quantize_info->number_colors == 0)
1175 break;
1176 if (((*image)->storage_class == DirectClass) ||
1177 (*image)->colors > quantize_info->number_colors)
1178 (void) QuantizeImage(quantize_info,*image);
1179 else
1180 (void) CompressImageColormap(*image);
1181 InheritException(exception,&(*image)->exception);
1182 break;
1183 }
1184 if (LocaleCompare("colorspace",option+1) == 0)
1185 {
1186 ColorspaceType
1187 colorspace;
1188
cristy6b3da3a2010-06-20 02:21:46 +00001189 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001190 if (*option == '+')
1191 {
1192 (void) TransformImageColorspace(*image,RGBColorspace);
1193 InheritException(exception,&(*image)->exception);
1194 break;
1195 }
1196 colorspace=(ColorspaceType) ParseMagickOption(
1197 MagickColorspaceOptions,MagickFalse,argv[i+1]);
1198 (void) TransformImageColorspace(*image,colorspace);
1199 InheritException(exception,&(*image)->exception);
1200 break;
1201 }
1202 if (LocaleCompare("contrast",option+1) == 0)
1203 {
cristy6b3da3a2010-06-20 02:21:46 +00001204 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001205 (void) ContrastImage(*image,(*option == '-') ? MagickTrue :
1206 MagickFalse);
1207 InheritException(exception,&(*image)->exception);
1208 break;
1209 }
1210 if (LocaleCompare("contrast-stretch",option+1) == 0)
1211 {
1212 double
1213 black_point,
1214 white_point;
1215
cristy3ed852e2009-09-05 21:47:34 +00001216 MagickStatusType
1217 flags;
1218
1219 /*
1220 Contrast stretch image.
1221 */
cristy6b3da3a2010-06-20 02:21:46 +00001222 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001223 flags=ParseGeometry(argv[i+1],&geometry_info);
1224 black_point=geometry_info.rho;
1225 white_point=(flags & SigmaValue) != 0 ? geometry_info.sigma :
1226 black_point;
1227 if ((flags & PercentValue) != 0)
1228 {
1229 black_point*=(double) (*image)->columns*(*image)->rows/100.0;
1230 white_point*=(double) (*image)->columns*(*image)->rows/100.0;
1231 }
1232 white_point=(MagickRealType) (*image)->columns*(*image)->rows-
1233 white_point;
1234 (void) ContrastStretchImageChannel(*image,channel,black_point,
1235 white_point);
1236 InheritException(exception,&(*image)->exception);
1237 break;
1238 }
1239 if (LocaleCompare("convolve",option+1) == 0)
1240 {
cristy36826ab2010-03-06 01:29:30 +00001241 double
1242 gamma;
1243
cristy3ed852e2009-09-05 21:47:34 +00001244 Image
1245 *convolve_image;
1246
cristy2be15382010-01-21 02:38:03 +00001247 KernelInfo
cristy56a9e512010-01-06 18:18:55 +00001248 *kernel;
cristy3ed852e2009-09-05 21:47:34 +00001249
cristybb503372010-05-27 20:51:26 +00001250 register ssize_t
cristy36826ab2010-03-06 01:29:30 +00001251 j;
1252
cristy6b3da3a2010-06-20 02:21:46 +00001253 (void) SyncImageSettings(mogrify_info,*image);
cristy2be15382010-01-21 02:38:03 +00001254 kernel=AcquireKernelInfo(argv[i+1]);
1255 if (kernel == (KernelInfo *) NULL)
cristy56a9e512010-01-06 18:18:55 +00001256 break;
cristy36826ab2010-03-06 01:29:30 +00001257 gamma=0.0;
cristybb503372010-05-27 20:51:26 +00001258 for (j=0; j < (ssize_t) (kernel->width*kernel->height); j++)
cristy36826ab2010-03-06 01:29:30 +00001259 gamma+=kernel->values[j];
1260 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
cristybb503372010-05-27 20:51:26 +00001261 for (j=0; j < (ssize_t) (kernel->width*kernel->height); j++)
cristy36826ab2010-03-06 01:29:30 +00001262 kernel->values[j]*=gamma;
cristy6771f1e2010-03-05 19:43:39 +00001263 convolve_image=FilterImageChannel(*image,channel,kernel,exception);
anthony83ba99b2010-01-24 08:48:15 +00001264 kernel=DestroyKernelInfo(kernel);
cristy3ed852e2009-09-05 21:47:34 +00001265 if (convolve_image == (Image *) NULL)
1266 break;
1267 *image=DestroyImage(*image);
1268 *image=convolve_image;
1269 break;
1270 }
1271 if (LocaleCompare("crop",option+1) == 0)
1272 {
cristy6b3da3a2010-06-20 02:21:46 +00001273 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001274 flags=ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1275 if (((geometry.width != 0) || (geometry.height != 0)) &&
1276 ((flags & XValue) == 0) && ((flags & YValue) == 0))
1277 break;
1278 (void) TransformImage(image,argv[i+1],(char *) NULL);
1279 InheritException(exception,&(*image)->exception);
1280 break;
1281 }
1282 if (LocaleCompare("cycle",option+1) == 0)
1283 {
1284 /*
1285 Cycle an image colormap.
1286 */
cristy6b3da3a2010-06-20 02:21:46 +00001287 (void) SyncImageSettings(mogrify_info,*image);
cristyf2f27272009-12-17 14:48:46 +00001288 (void) CycleColormapImage(*image,StringToLong(argv[i+1]));
cristy3ed852e2009-09-05 21:47:34 +00001289 InheritException(exception,&(*image)->exception);
1290 break;
1291 }
1292 break;
1293 }
1294 case 'd':
1295 {
1296 if (LocaleCompare("decipher",option+1) == 0)
1297 {
1298 StringInfo
1299 *passkey;
1300
1301 /*
1302 Decipher pixels.
1303 */
cristy6b3da3a2010-06-20 02:21:46 +00001304 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001305 passkey=FileToStringInfo(argv[i+1],~0,exception);
1306 if (passkey != (StringInfo *) NULL)
1307 {
1308 (void) PasskeyDecipherImage(*image,passkey,exception);
1309 passkey=DestroyStringInfo(passkey);
1310 }
1311 break;
1312 }
1313 if (LocaleCompare("density",option+1) == 0)
1314 {
1315 /*
1316 Set image density.
1317 */
1318 (void) CloneString(&draw_info->density,argv[i+1]);
1319 break;
1320 }
1321 if (LocaleCompare("depth",option+1) == 0)
1322 {
cristy6b3da3a2010-06-20 02:21:46 +00001323 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001324 if (*option == '+')
1325 {
1326 (void) SetImageDepth(*image,MAGICKCORE_QUANTUM_DEPTH);
1327 break;
1328 }
cristye27293e2009-12-18 02:53:20 +00001329 (void) SetImageDepth(*image,StringToUnsignedLong(argv[i+1]));
cristy3ed852e2009-09-05 21:47:34 +00001330 break;
1331 }
1332 if (LocaleCompare("deskew",option+1) == 0)
1333 {
1334 double
1335 threshold;
1336
1337 Image
1338 *deskew_image;
1339
1340 /*
1341 Straighten the image.
1342 */
cristy6b3da3a2010-06-20 02:21:46 +00001343 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001344 if (*option == '+')
1345 threshold=40.0*QuantumRange/100.0;
1346 else
cristyf2f27272009-12-17 14:48:46 +00001347 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
cristy3ed852e2009-09-05 21:47:34 +00001348 deskew_image=DeskewImage(*image,threshold,exception);
1349 if (deskew_image == (Image *) NULL)
1350 break;
1351 *image=DestroyImage(*image);
1352 *image=deskew_image;
1353 break;
1354 }
1355 if (LocaleCompare("despeckle",option+1) == 0)
1356 {
1357 Image
1358 *despeckle_image;
1359
1360 /*
1361 Reduce the speckles within an image.
1362 */
cristy6b3da3a2010-06-20 02:21:46 +00001363 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001364 despeckle_image=DespeckleImage(*image,exception);
1365 if (despeckle_image == (Image *) NULL)
1366 break;
1367 *image=DestroyImage(*image);
1368 *image=despeckle_image;
1369 break;
1370 }
1371 if (LocaleCompare("display",option+1) == 0)
1372 {
1373 (void) CloneString(&draw_info->server_name,argv[i+1]);
1374 break;
1375 }
cristy3ed852e2009-09-05 21:47:34 +00001376 if (LocaleCompare("distort",option+1) == 0)
1377 {
1378 char
1379 *args,
1380 token[MaxTextExtent];
1381
1382 const char
1383 *p;
1384
1385 DistortImageMethod
1386 method;
1387
1388 double
1389 *arguments;
1390
1391 Image
1392 *distort_image;
1393
cristybb503372010-05-27 20:51:26 +00001394 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001395 x;
1396
cristybb503372010-05-27 20:51:26 +00001397 size_t
cristy3ed852e2009-09-05 21:47:34 +00001398 number_arguments;
1399
1400 /*
1401 Distort image.
1402 */
cristy6b3da3a2010-06-20 02:21:46 +00001403 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001404 method=(DistortImageMethod) ParseMagickOption(MagickDistortOptions,
1405 MagickFalse,argv[i+1]);
cristy6b3da3a2010-06-20 02:21:46 +00001406 args=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
cristy3ed852e2009-09-05 21:47:34 +00001407 InheritException(exception,&(*image)->exception);
1408 if (args == (char *) NULL)
1409 break;
1410 p=(char *) args;
1411 for (x=0; *p != '\0'; x++)
1412 {
1413 GetMagickToken(p,&p,token);
1414 if (*token == ',')
1415 GetMagickToken(p,&p,token);
1416 }
cristybb503372010-05-27 20:51:26 +00001417 number_arguments=(size_t) x;
cristy3ed852e2009-09-05 21:47:34 +00001418 arguments=(double *) AcquireQuantumMemory(number_arguments,
1419 sizeof(*arguments));
1420 if (arguments == (double *) NULL)
1421 ThrowWandFatalException(ResourceLimitFatalError,
1422 "MemoryAllocationFailed",(*image)->filename);
1423 (void) ResetMagickMemory(arguments,0,number_arguments*
1424 sizeof(*arguments));
1425 p=(char *) args;
cristybb503372010-05-27 20:51:26 +00001426 for (x=0; (x < (ssize_t) number_arguments) && (*p != '\0'); x++)
cristy3ed852e2009-09-05 21:47:34 +00001427 {
1428 GetMagickToken(p,&p,token);
1429 if (*token == ',')
1430 GetMagickToken(p,&p,token);
cristyf2f27272009-12-17 14:48:46 +00001431 arguments[x]=StringToDouble(token);
cristy3ed852e2009-09-05 21:47:34 +00001432 }
1433 args=DestroyString(args);
1434 distort_image=DistortImage(*image,method,number_arguments,arguments,
1435 (*option == '+') ? MagickTrue : MagickFalse,exception);
1436 arguments=(double *) RelinquishMagickMemory(arguments);
1437 if (distort_image == (Image *) NULL)
1438 break;
1439 *image=DestroyImage(*image);
1440 *image=distort_image;
1441 break;
1442 }
1443 if (LocaleCompare("dither",option+1) == 0)
1444 {
1445 if (*option == '+')
1446 {
1447 quantize_info->dither=MagickFalse;
1448 break;
1449 }
1450 quantize_info->dither=MagickTrue;
1451 quantize_info->dither_method=(DitherMethod) ParseMagickOption(
1452 MagickDitherOptions,MagickFalse,argv[i+1]);
1453 if (quantize_info->dither_method == NoDitherMethod)
1454 quantize_info->dither=MagickFalse;
1455 break;
1456 }
1457 if (LocaleCompare("draw",option+1) == 0)
1458 {
1459 /*
1460 Draw image.
1461 */
cristy6b3da3a2010-06-20 02:21:46 +00001462 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001463 (void) CloneString(&draw_info->primitive,argv[i+1]);
1464 (void) DrawImage(*image,draw_info);
1465 InheritException(exception,&(*image)->exception);
1466 break;
1467 }
1468 break;
1469 }
1470 case 'e':
1471 {
1472 if (LocaleCompare("edge",option+1) == 0)
1473 {
1474 Image
1475 *edge_image;
1476
1477 /*
1478 Enhance edges in the image.
1479 */
cristy6b3da3a2010-06-20 02:21:46 +00001480 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001481 flags=ParseGeometry(argv[i+1],&geometry_info);
1482 if ((flags & SigmaValue) == 0)
1483 geometry_info.sigma=1.0;
1484 edge_image=EdgeImage(*image,geometry_info.rho,exception);
1485 if (edge_image == (Image *) NULL)
1486 break;
1487 *image=DestroyImage(*image);
1488 *image=edge_image;
1489 break;
1490 }
1491 if (LocaleCompare("emboss",option+1) == 0)
1492 {
1493 Image
1494 *emboss_image;
1495
1496 /*
1497 Gaussian embossen image.
1498 */
cristy6b3da3a2010-06-20 02:21:46 +00001499 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001500 flags=ParseGeometry(argv[i+1],&geometry_info);
1501 if ((flags & SigmaValue) == 0)
1502 geometry_info.sigma=1.0;
1503 emboss_image=EmbossImage(*image,geometry_info.rho,
1504 geometry_info.sigma,exception);
1505 if (emboss_image == (Image *) NULL)
1506 break;
1507 *image=DestroyImage(*image);
1508 *image=emboss_image;
1509 break;
1510 }
1511 if (LocaleCompare("encipher",option+1) == 0)
1512 {
1513 StringInfo
1514 *passkey;
1515
1516 /*
1517 Encipher pixels.
1518 */
cristy6b3da3a2010-06-20 02:21:46 +00001519 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001520 passkey=FileToStringInfo(argv[i+1],~0,exception);
1521 if (passkey != (StringInfo *) NULL)
1522 {
1523 (void) PasskeyEncipherImage(*image,passkey,exception);
1524 passkey=DestroyStringInfo(passkey);
1525 }
1526 break;
1527 }
1528 if (LocaleCompare("encoding",option+1) == 0)
1529 {
1530 (void) CloneString(&draw_info->encoding,argv[i+1]);
1531 break;
1532 }
1533 if (LocaleCompare("enhance",option+1) == 0)
1534 {
1535 Image
1536 *enhance_image;
1537
1538 /*
1539 Enhance image.
1540 */
cristy6b3da3a2010-06-20 02:21:46 +00001541 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001542 enhance_image=EnhanceImage(*image,exception);
1543 if (enhance_image == (Image *) NULL)
1544 break;
1545 *image=DestroyImage(*image);
1546 *image=enhance_image;
1547 break;
1548 }
1549 if (LocaleCompare("equalize",option+1) == 0)
1550 {
1551 /*
1552 Equalize image.
1553 */
cristy6b3da3a2010-06-20 02:21:46 +00001554 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001555 (void) EqualizeImageChannel(*image,channel);
1556 InheritException(exception,&(*image)->exception);
1557 break;
1558 }
1559 if (LocaleCompare("evaluate",option+1) == 0)
1560 {
1561 double
1562 constant;
1563
1564 MagickEvaluateOperator
1565 op;
1566
cristy6b3da3a2010-06-20 02:21:46 +00001567 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001568 op=(MagickEvaluateOperator) ParseMagickOption(MagickEvaluateOptions,
1569 MagickFalse,argv[i+1]);
cristyf2f27272009-12-17 14:48:46 +00001570 constant=SiPrefixToDouble(argv[i+2],QuantumRange);
cristy3ed852e2009-09-05 21:47:34 +00001571 (void) EvaluateImageChannel(*image,channel,op,constant,exception);
1572 break;
1573 }
1574 if (LocaleCompare("extent",option+1) == 0)
1575 {
1576 Image
1577 *extent_image;
1578
1579 /*
1580 Set the image extent.
1581 */
cristy6b3da3a2010-06-20 02:21:46 +00001582 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001583 flags=ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
cristyf0bbfd92009-11-25 14:12:31 +00001584 if (geometry.width == 0)
cristy2ea9a4e2009-11-25 14:30:22 +00001585 geometry.width=(*image)->columns;
cristyf0bbfd92009-11-25 14:12:31 +00001586 if (geometry.height == 0)
cristy2ea9a4e2009-11-25 14:30:22 +00001587 geometry.height=(*image)->rows;
cristy3ed852e2009-09-05 21:47:34 +00001588 extent_image=ExtentImage(*image,&geometry,exception);
1589 if (extent_image == (Image *) NULL)
1590 break;
1591 *image=DestroyImage(*image);
1592 *image=extent_image;
1593 break;
1594 }
1595 break;
1596 }
1597 case 'f':
1598 {
1599 if (LocaleCompare("family",option+1) == 0)
1600 {
1601 if (*option == '+')
1602 {
1603 if (draw_info->family != (char *) NULL)
1604 draw_info->family=DestroyString(draw_info->family);
1605 break;
1606 }
1607 (void) CloneString(&draw_info->family,argv[i+1]);
1608 break;
1609 }
cristy0fe961c2010-01-30 03:09:54 +00001610 if (LocaleCompare("features",option+1) == 0)
1611 {
1612 if (*option == '+')
1613 {
1614 (void) DeleteImageArtifact(*image,"identify:features");
1615 break;
1616 }
1617 (void) SetImageArtifact(*image,"identify:features",argv[i+1]);
1618 break;
1619 }
cristy3ed852e2009-09-05 21:47:34 +00001620 if (LocaleCompare("fill",option+1) == 0)
1621 {
1622 ExceptionInfo
1623 *sans;
1624
1625 GetMagickPixelPacket(*image,&fill);
1626 if (*option == '+')
1627 {
1628 (void) QueryMagickColor("none",&fill,exception);
1629 (void) QueryColorDatabase("none",&draw_info->fill,exception);
1630 if (draw_info->fill_pattern != (Image *) NULL)
1631 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
1632 break;
1633 }
1634 sans=AcquireExceptionInfo();
1635 (void) QueryMagickColor(argv[i+1],&fill,sans);
1636 status=QueryColorDatabase(argv[i+1],&draw_info->fill,sans);
1637 sans=DestroyExceptionInfo(sans);
1638 if (status == MagickFalse)
cristy6b3da3a2010-06-20 02:21:46 +00001639 draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1],
cristy3ed852e2009-09-05 21:47:34 +00001640 exception);
1641 break;
1642 }
1643 if (LocaleCompare("flip",option+1) == 0)
1644 {
1645 Image
1646 *flip_image;
1647
1648 /*
1649 Flip image scanlines.
1650 */
cristy6b3da3a2010-06-20 02:21:46 +00001651 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001652 flip_image=FlipImage(*image,exception);
1653 if (flip_image == (Image *) NULL)
1654 break;
1655 *image=DestroyImage(*image);
1656 *image=flip_image;
1657 break;
1658 }
1659 if (LocaleCompare("flop",option+1) == 0)
1660 {
1661 Image
1662 *flop_image;
1663
1664 /*
1665 Flop image scanlines.
1666 */
cristy6b3da3a2010-06-20 02:21:46 +00001667 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001668 flop_image=FlopImage(*image,exception);
1669 if (flop_image == (Image *) NULL)
1670 break;
1671 *image=DestroyImage(*image);
1672 *image=flop_image;
1673 break;
1674 }
1675 if (LocaleCompare("floodfill",option+1) == 0)
1676 {
1677 MagickPixelPacket
1678 target;
1679
1680 /*
1681 Floodfill image.
1682 */
cristy6b3da3a2010-06-20 02:21:46 +00001683 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001684 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
1685 (void) QueryMagickColor(argv[i+2],&target,exception);
1686 (void) FloodfillPaintImage(*image,channel,draw_info,&target,
1687 geometry.x,geometry.y,*option == '-' ? MagickFalse : MagickTrue);
1688 InheritException(exception,&(*image)->exception);
1689 break;
1690 }
1691 if (LocaleCompare("font",option+1) == 0)
1692 {
1693 if (*option == '+')
1694 {
1695 if (draw_info->font != (char *) NULL)
1696 draw_info->font=DestroyString(draw_info->font);
1697 break;
1698 }
1699 (void) CloneString(&draw_info->font,argv[i+1]);
1700 break;
1701 }
1702 if (LocaleCompare("format",option+1) == 0)
1703 {
1704 format=argv[i+1];
1705 break;
1706 }
1707 if (LocaleCompare("frame",option+1) == 0)
1708 {
1709 FrameInfo
1710 frame_info;
1711
1712 Image
1713 *frame_image;
1714
1715 /*
1716 Surround image with an ornamental border.
1717 */
cristy6b3da3a2010-06-20 02:21:46 +00001718 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001719 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
1720 frame_info.width=geometry.width;
1721 frame_info.height=geometry.height;
1722 if ((flags & HeightValue) == 0)
1723 frame_info.height=geometry.width;
1724 frame_info.outer_bevel=geometry.x;
1725 frame_info.inner_bevel=geometry.y;
cristybb503372010-05-27 20:51:26 +00001726 frame_info.x=(ssize_t) frame_info.width;
1727 frame_info.y=(ssize_t) frame_info.height;
cristy3ed852e2009-09-05 21:47:34 +00001728 frame_info.width=(*image)->columns+2*frame_info.width;
1729 frame_info.height=(*image)->rows+2*frame_info.height;
1730 frame_image=FrameImage(*image,&frame_info,exception);
1731 if (frame_image == (Image *) NULL)
1732 break;
1733 *image=DestroyImage(*image);
1734 *image=frame_image;
1735 break;
1736 }
1737 if (LocaleCompare("function",option+1) == 0)
1738 {
1739 char
1740 *arguments,
1741 token[MaxTextExtent];
1742
1743 const char
1744 *p;
1745
1746 double
1747 *parameters;
1748
1749 MagickFunction
1750 function;
1751
cristybb503372010-05-27 20:51:26 +00001752 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001753 x;
1754
cristybb503372010-05-27 20:51:26 +00001755 size_t
cristy3ed852e2009-09-05 21:47:34 +00001756 number_parameters;
1757
1758 /*
1759 Function Modify Image Values
1760 */
cristy6b3da3a2010-06-20 02:21:46 +00001761 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001762 function=(MagickFunction) ParseMagickOption(MagickFunctionOptions,
1763 MagickFalse,argv[i+1]);
cristy6b3da3a2010-06-20 02:21:46 +00001764 arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
cristy3ed852e2009-09-05 21:47:34 +00001765 InheritException(exception,&(*image)->exception);
1766 if (arguments == (char *) NULL)
1767 break;
1768 p=(char *) arguments;
1769 for (x=0; *p != '\0'; x++)
1770 {
1771 GetMagickToken(p,&p,token);
1772 if (*token == ',')
1773 GetMagickToken(p,&p,token);
1774 }
cristybb503372010-05-27 20:51:26 +00001775 number_parameters=(size_t) x;
cristy3ed852e2009-09-05 21:47:34 +00001776 parameters=(double *) AcquireQuantumMemory(number_parameters,
1777 sizeof(*parameters));
1778 if (parameters == (double *) NULL)
1779 ThrowWandFatalException(ResourceLimitFatalError,
1780 "MemoryAllocationFailed",(*image)->filename);
1781 (void) ResetMagickMemory(parameters,0,number_parameters*
1782 sizeof(*parameters));
1783 p=(char *) arguments;
cristybb503372010-05-27 20:51:26 +00001784 for (x=0; (x < (ssize_t) number_parameters) && (*p != '\0'); x++)
cristy3ed852e2009-09-05 21:47:34 +00001785 {
1786 GetMagickToken(p,&p,token);
1787 if (*token == ',')
1788 GetMagickToken(p,&p,token);
cristyf2f27272009-12-17 14:48:46 +00001789 parameters[x]=StringToDouble(token);
cristy3ed852e2009-09-05 21:47:34 +00001790 }
1791 arguments=DestroyString(arguments);
1792 (void) FunctionImageChannel(*image,channel,function,
1793 number_parameters,parameters,exception);
1794 parameters=(double *) RelinquishMagickMemory(parameters);
1795 break;
1796 }
1797 break;
1798 }
1799 case 'g':
1800 {
1801 if (LocaleCompare("gamma",option+1) == 0)
1802 {
1803 /*
1804 Gamma image.
1805 */
cristy6b3da3a2010-06-20 02:21:46 +00001806 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001807 if (*option == '+')
cristyf2f27272009-12-17 14:48:46 +00001808 (*image)->gamma=StringToDouble(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00001809 else
1810 {
1811 if (strchr(argv[i+1],',') != (char *) NULL)
1812 (void) GammaImage(*image,argv[i+1]);
1813 else
cristya5447be2010-01-11 00:20:51 +00001814 (void) GammaImageChannel(*image,channel,
1815 StringToDouble(argv[i+1]));
cristy3ed852e2009-09-05 21:47:34 +00001816 InheritException(exception,&(*image)->exception);
1817 }
1818 break;
1819 }
1820 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
1821 (LocaleCompare("gaussian",option+1) == 0))
1822 {
1823 Image
1824 *gaussian_image;
1825
1826 /*
1827 Gaussian blur image.
1828 */
cristy6b3da3a2010-06-20 02:21:46 +00001829 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001830 flags=ParseGeometry(argv[i+1],&geometry_info);
1831 if ((flags & SigmaValue) == 0)
1832 geometry_info.sigma=1.0;
1833 gaussian_image=GaussianBlurImageChannel(*image,channel,
1834 geometry_info.rho,geometry_info.sigma,exception);
1835 if (gaussian_image == (Image *) NULL)
1836 break;
1837 *image=DestroyImage(*image);
1838 *image=gaussian_image;
1839 break;
1840 }
1841 if (LocaleCompare("geometry",option+1) == 0)
1842 {
cristy6b3da3a2010-06-20 02:21:46 +00001843 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001844 if (*option == '+')
1845 {
1846 if ((*image)->geometry != (char *) NULL)
1847 (*image)->geometry=DestroyString((*image)->geometry);
1848 break;
1849 }
1850 flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
1851 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
1852 (void) CloneString(&(*image)->geometry,argv[i+1]);
1853 else
1854 {
1855 Image
cristy15b98cd2010-09-12 19:42:50 +00001856 *resize_image;
cristy3ed852e2009-09-05 21:47:34 +00001857
1858 /*
1859 Resize image.
1860 */
cristy15b98cd2010-09-12 19:42:50 +00001861 resize_image=ResizeImage(*image,geometry.width,geometry.height,
1862 (*image)->filter,(*image)->blur,exception);
1863 if (resize_image == (Image *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001864 break;
1865 *image=DestroyImage(*image);
cristy15b98cd2010-09-12 19:42:50 +00001866 *image=resize_image;
cristy3ed852e2009-09-05 21:47:34 +00001867 }
1868 break;
1869 }
1870 if (LocaleCompare("gravity",option+1) == 0)
1871 {
1872 if (*option == '+')
1873 {
1874 draw_info->gravity=UndefinedGravity;
1875 break;
1876 }
1877 draw_info->gravity=(GravityType) ParseMagickOption(
1878 MagickGravityOptions,MagickFalse,argv[i+1]);
1879 break;
1880 }
1881 break;
1882 }
1883 case 'h':
1884 {
1885 if (LocaleCompare("highlight-color",option+1) == 0)
1886 {
1887 (void) SetImageArtifact(*image,option+1,argv[i+1]);
1888 break;
1889 }
1890 break;
1891 }
1892 case 'i':
1893 {
1894 if (LocaleCompare("identify",option+1) == 0)
1895 {
1896 char
1897 *text;
1898
cristy6b3da3a2010-06-20 02:21:46 +00001899 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001900 if (format == (char *) NULL)
1901 {
cristy6b3da3a2010-06-20 02:21:46 +00001902 (void) IdentifyImage(*image,stdout,mogrify_info->verbose);
cristy3ed852e2009-09-05 21:47:34 +00001903 InheritException(exception,&(*image)->exception);
1904 break;
1905 }
cristy6b3da3a2010-06-20 02:21:46 +00001906 text=InterpretImageProperties(mogrify_info,*image,format);
cristy3ed852e2009-09-05 21:47:34 +00001907 InheritException(exception,&(*image)->exception);
1908 if (text == (char *) NULL)
1909 break;
1910 (void) fputs(text,stdout);
1911 (void) fputc('\n',stdout);
1912 text=DestroyString(text);
1913 break;
1914 }
1915 if (LocaleCompare("implode",option+1) == 0)
1916 {
1917 Image
1918 *implode_image;
1919
1920 /*
1921 Implode image.
1922 */
cristy6b3da3a2010-06-20 02:21:46 +00001923 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001924 (void) ParseGeometry(argv[i+1],&geometry_info);
1925 implode_image=ImplodeImage(*image,geometry_info.rho,exception);
1926 if (implode_image == (Image *) NULL)
1927 break;
1928 *image=DestroyImage(*image);
1929 *image=implode_image;
1930 break;
1931 }
cristyb32b90a2009-09-07 21:45:48 +00001932 if (LocaleCompare("interline-spacing",option+1) == 0)
1933 {
1934 if (*option == '+')
1935 (void) ParseGeometry("0",&geometry_info);
1936 else
1937 (void) ParseGeometry(argv[i+1],&geometry_info);
1938 draw_info->interline_spacing=geometry_info.rho;
1939 break;
1940 }
cristy3ed852e2009-09-05 21:47:34 +00001941 if (LocaleCompare("interword-spacing",option+1) == 0)
1942 {
1943 if (*option == '+')
1944 (void) ParseGeometry("0",&geometry_info);
1945 else
1946 (void) ParseGeometry(argv[i+1],&geometry_info);
1947 draw_info->interword_spacing=geometry_info.rho;
1948 break;
1949 }
1950 break;
1951 }
1952 case 'k':
1953 {
1954 if (LocaleCompare("kerning",option+1) == 0)
1955 {
1956 if (*option == '+')
1957 (void) ParseGeometry("0",&geometry_info);
1958 else
1959 (void) ParseGeometry(argv[i+1],&geometry_info);
1960 draw_info->kerning=geometry_info.rho;
1961 break;
1962 }
1963 break;
1964 }
1965 case 'l':
1966 {
1967 if (LocaleCompare("lat",option+1) == 0)
1968 {
1969 Image
1970 *threshold_image;
1971
1972 /*
1973 Local adaptive threshold image.
1974 */
cristy6b3da3a2010-06-20 02:21:46 +00001975 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001976 flags=ParseGeometry(argv[i+1],&geometry_info);
1977 if ((flags & PercentValue) != 0)
1978 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
cristybb503372010-05-27 20:51:26 +00001979 threshold_image=AdaptiveThresholdImage(*image,(size_t)
1980 geometry_info.rho,(size_t) geometry_info.sigma,
1981 (ssize_t) geometry_info.xi,exception);
cristy3ed852e2009-09-05 21:47:34 +00001982 if (threshold_image == (Image *) NULL)
1983 break;
1984 *image=DestroyImage(*image);
1985 *image=threshold_image;
1986 break;
1987 }
1988 if (LocaleCompare("level",option+1) == 0)
1989 {
cristy3ed852e2009-09-05 21:47:34 +00001990 MagickRealType
1991 black_point,
1992 gamma,
1993 white_point;
1994
1995 MagickStatusType
1996 flags;
1997
1998 /*
1999 Parse levels.
2000 */
cristy6b3da3a2010-06-20 02:21:46 +00002001 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002002 flags=ParseGeometry(argv[i+1],&geometry_info);
2003 black_point=geometry_info.rho;
2004 white_point=(MagickRealType) QuantumRange;
2005 if ((flags & SigmaValue) != 0)
2006 white_point=geometry_info.sigma;
2007 gamma=1.0;
2008 if ((flags & XiValue) != 0)
2009 gamma=geometry_info.xi;
2010 if ((flags & PercentValue) != 0)
2011 {
2012 black_point*=(MagickRealType) (QuantumRange/100.0);
2013 white_point*=(MagickRealType) (QuantumRange/100.0);
2014 }
2015 if ((flags & SigmaValue) == 0)
2016 white_point=(MagickRealType) QuantumRange-black_point;
2017 if ((*option == '+') || ((flags & AspectValue) != 0))
2018 (void) LevelizeImageChannel(*image,channel,black_point,
2019 white_point,gamma);
2020 else
2021 (void) LevelImageChannel(*image,channel,black_point,white_point,
2022 gamma);
2023 InheritException(exception,&(*image)->exception);
2024 break;
2025 }
2026 if (LocaleCompare("level-colors",option+1) == 0)
2027 {
2028 char
2029 token[MaxTextExtent];
2030
2031 const char
2032 *p;
2033
2034 MagickPixelPacket
2035 black_point,
2036 white_point;
2037
2038 p=(const char *) argv[i+1];
2039 GetMagickToken(p,&p,token); /* get black point color */
cristyee0f8d72009-09-19 00:58:29 +00002040 if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
cristy3ed852e2009-09-05 21:47:34 +00002041 (void) QueryMagickColor(token,&black_point,exception);
2042 else
cristyee0f8d72009-09-19 00:58:29 +00002043 (void) QueryMagickColor("#000000",&black_point,exception);
cristy3ed852e2009-09-05 21:47:34 +00002044 if (isalpha((int) token[0]) || (token[0] == '#'))
2045 GetMagickToken(p,&p,token);
cristyee0f8d72009-09-19 00:58:29 +00002046 if (*token == '\0')
cristy3ed852e2009-09-05 21:47:34 +00002047 white_point=black_point; /* set everything to that color */
2048 else
2049 {
2050 /*
2051 Get white point color.
2052 */
cristyee0f8d72009-09-19 00:58:29 +00002053 if ((isalpha((int) *token) == 0) && ((*token == '#') == 0))
cristy3ed852e2009-09-05 21:47:34 +00002054 GetMagickToken(p,&p,token);
cristyee0f8d72009-09-19 00:58:29 +00002055 if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
cristy3ed852e2009-09-05 21:47:34 +00002056 (void) QueryMagickColor(token,&white_point,exception);
2057 else
cristyee0f8d72009-09-19 00:58:29 +00002058 (void) QueryMagickColor("#ffffff",&white_point,exception);
cristy3ed852e2009-09-05 21:47:34 +00002059 }
cristy74fe8f12009-10-03 19:09:01 +00002060 (void) LevelColorsImageChannel(*image,channel,&black_point,
2061 &white_point,*option == '+' ? MagickTrue : MagickFalse);
cristy3ed852e2009-09-05 21:47:34 +00002062 break;
2063 }
2064 if (LocaleCompare("linear-stretch",option+1) == 0)
2065 {
2066 double
2067 black_point,
2068 white_point;
2069
cristy3ed852e2009-09-05 21:47:34 +00002070 MagickStatusType
2071 flags;
2072
cristy6b3da3a2010-06-20 02:21:46 +00002073 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002074 flags=ParseGeometry(argv[i+1],&geometry_info);
2075 black_point=geometry_info.rho;
2076 white_point=(MagickRealType) (*image)->columns*(*image)->rows;
2077 if ((flags & SigmaValue) != 0)
2078 white_point=geometry_info.sigma;
2079 if ((flags & PercentValue) != 0)
2080 {
2081 black_point*=(double) (*image)->columns*(*image)->rows/100.0;
2082 white_point*=(double) (*image)->columns*(*image)->rows/100.0;
2083 }
2084 if ((flags & SigmaValue) == 0)
2085 white_point=(MagickRealType) (*image)->columns*(*image)->rows-
2086 black_point;
2087 (void) LinearStretchImage(*image,black_point,white_point);
2088 InheritException(exception,&(*image)->exception);
2089 break;
2090 }
2091 if (LocaleCompare("linewidth",option+1) == 0)
2092 {
cristyf2f27272009-12-17 14:48:46 +00002093 draw_info->stroke_width=StringToDouble(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00002094 break;
2095 }
2096 if (LocaleCompare("liquid-rescale",option+1) == 0)
2097 {
2098 Image
2099 *resize_image;
2100
2101 /*
2102 Liquid rescale image.
2103 */
cristy6b3da3a2010-06-20 02:21:46 +00002104 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002105 flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2106 if ((flags & XValue) == 0)
2107 geometry.x=1;
2108 if ((flags & YValue) == 0)
2109 geometry.y=0;
2110 resize_image=LiquidRescaleImage(*image,geometry.width,
2111 geometry.height,1.0*geometry.x,1.0*geometry.y,exception);
2112 if (resize_image == (Image *) NULL)
2113 break;
2114 *image=DestroyImage(*image);
2115 *image=resize_image;
2116 break;
2117 }
2118 if (LocaleCompare("lowlight-color",option+1) == 0)
2119 {
2120 (void) SetImageArtifact(*image,option+1,argv[i+1]);
2121 break;
2122 }
2123 break;
2124 }
2125 case 'm':
2126 {
2127 if (LocaleCompare("map",option+1) == 0)
2128 {
2129 Image
2130 *remap_image;
2131
2132 /*
2133 Transform image colors to match this set of colors.
2134 */
cristy6b3da3a2010-06-20 02:21:46 +00002135 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002136 if (*option == '+')
2137 break;
cristy6b3da3a2010-06-20 02:21:46 +00002138 remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
cristy3ed852e2009-09-05 21:47:34 +00002139 if (remap_image == (Image *) NULL)
2140 break;
2141 (void) RemapImage(quantize_info,*image,remap_image);
2142 InheritException(exception,&(*image)->exception);
2143 remap_image=DestroyImage(remap_image);
2144 break;
2145 }
2146 if (LocaleCompare("mask",option+1) == 0)
2147 {
2148 Image
2149 *mask;
2150
cristy6b3da3a2010-06-20 02:21:46 +00002151 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002152 if (*option == '+')
2153 {
2154 /*
2155 Remove a mask.
2156 */
2157 (void) SetImageMask(*image,(Image *) NULL);
2158 InheritException(exception,&(*image)->exception);
2159 break;
2160 }
2161 /*
2162 Set the image mask.
2163 */
cristy6b3da3a2010-06-20 02:21:46 +00002164 mask=GetImageCache(mogrify_info,argv[i+1],exception);
cristy3ed852e2009-09-05 21:47:34 +00002165 if (mask == (Image *) NULL)
2166 break;
2167 (void) SetImageMask(*image,mask);
2168 mask=DestroyImage(mask);
2169 InheritException(exception,&(*image)->exception);
2170 break;
2171 }
2172 if (LocaleCompare("matte",option+1) == 0)
2173 {
2174 (void) SetImageAlphaChannel(*image,(*option == '-') ?
2175 SetAlphaChannel : DeactivateAlphaChannel );
2176 InheritException(exception,&(*image)->exception);
2177 break;
2178 }
2179 if (LocaleCompare("median",option+1) == 0)
2180 {
2181 Image
2182 *median_image;
2183
2184 /*
2185 Median filter image.
2186 */
cristy6b3da3a2010-06-20 02:21:46 +00002187 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002188 (void) ParseGeometry(argv[i+1],&geometry_info);
2189 median_image=MedianFilterImage(*image,geometry_info.rho,exception);
2190 if (median_image == (Image *) NULL)
2191 break;
2192 *image=DestroyImage(*image);
2193 *image=median_image;
2194 break;
2195 }
2196 if (LocaleCompare("modulate",option+1) == 0)
2197 {
cristy6b3da3a2010-06-20 02:21:46 +00002198 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002199 (void) ModulateImage(*image,argv[i+1]);
2200 InheritException(exception,&(*image)->exception);
2201 break;
2202 }
2203 if (LocaleCompare("monitor",option+1) == 0)
2204 {
cristy7d34ef22010-03-25 01:11:22 +00002205 if (*option == '+')
2206 {
2207 (void) SetImageProgressMonitor(*image,
2208 (MagickProgressMonitor) NULL,(void *) NULL);
2209 break;
2210 }
cristy3ed852e2009-09-05 21:47:34 +00002211 (void) SetImageProgressMonitor(*image,MonitorProgress,
2212 (void *) NULL);
2213 break;
2214 }
2215 if (LocaleCompare("monochrome",option+1) == 0)
2216 {
cristy6b3da3a2010-06-20 02:21:46 +00002217 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002218 (void) SetImageType(*image,BilevelType);
2219 InheritException(exception,&(*image)->exception);
2220 break;
2221 }
anthony29188a82010-01-22 10:12:34 +00002222 if (LocaleCompare("morphology",option+1) == 0)
2223 {
anthony29188a82010-01-22 10:12:34 +00002224 char
2225 token[MaxTextExtent];
2226
2227 const char
2228 *p;
2229
cristye96405a2010-05-19 02:24:31 +00002230 Image
2231 *morphology_image;
2232
2233 KernelInfo
2234 *kernel;
2235
cristybb503372010-05-27 20:51:26 +00002236 ssize_t
anthony29188a82010-01-22 10:12:34 +00002237 iterations;
2238
cristye96405a2010-05-19 02:24:31 +00002239 MorphologyMethod
2240 method;
2241
anthony29188a82010-01-22 10:12:34 +00002242 /*
2243 Morphological Image Operation
2244 */
cristy6b3da3a2010-06-20 02:21:46 +00002245 (void) SyncImageSettings(mogrify_info,*image);
anthony29188a82010-01-22 10:12:34 +00002246 p=argv[i+1];
2247 GetMagickToken(p,&p,token);
2248 method=(MorphologyMethod) ParseMagickOption(MagickMorphologyOptions,
cristyd2c1e1e2010-05-08 01:05:44 +00002249 MagickFalse,token);
cristyef656912010-03-05 19:54:59 +00002250 iterations=1L;
anthony29188a82010-01-22 10:12:34 +00002251 GetMagickToken(p,&p,token);
cristyef656912010-03-05 19:54:59 +00002252 if ((*p == ':') || (*p == ','))
anthony29188a82010-01-22 10:12:34 +00002253 GetMagickToken(p,&p,token);
cristyef656912010-03-05 19:54:59 +00002254 if ((*p != '\0'))
2255 iterations=StringToLong(p);
anthony29188a82010-01-22 10:12:34 +00002256 kernel=AcquireKernelInfo(argv[i+2]);
2257 if (kernel == (KernelInfo *) NULL)
cristye96405a2010-05-19 02:24:31 +00002258 {
2259 (void) ThrowMagickException(exception,GetMagickModule(),
2260 OptionError,"UnabletoParseKernel","morphology");
2261 status=MagickFalse;
2262 break;
2263 }
anthony29188a82010-01-22 10:12:34 +00002264 morphology_image=MorphologyImageChannel(*image,channel,method,
cristy02d5b4f2010-02-01 01:08:27 +00002265 iterations,kernel,exception);
anthony83ba99b2010-01-24 08:48:15 +00002266 kernel=DestroyKernelInfo(kernel);
anthony29188a82010-01-22 10:12:34 +00002267 if (morphology_image == (Image *) NULL)
2268 break;
2269 *image=DestroyImage(*image);
2270 *image=morphology_image;
2271 break;
2272 }
cristy3ed852e2009-09-05 21:47:34 +00002273 if (LocaleCompare("motion-blur",option+1) == 0)
2274 {
2275 Image
2276 *blur_image;
2277
2278 /*
2279 Motion blur image.
2280 */
cristy6b3da3a2010-06-20 02:21:46 +00002281 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002282 flags=ParseGeometry(argv[i+1],&geometry_info);
2283 if ((flags & SigmaValue) == 0)
2284 geometry_info.sigma=1.0;
2285 blur_image=MotionBlurImageChannel(*image,channel,geometry_info.rho,
2286 geometry_info.sigma,geometry_info.xi,exception);
2287 if (blur_image == (Image *) NULL)
2288 break;
2289 *image=DestroyImage(*image);
2290 *image=blur_image;
2291 break;
2292 }
2293 break;
2294 }
2295 case 'n':
2296 {
2297 if (LocaleCompare("negate",option+1) == 0)
2298 {
cristy6b3da3a2010-06-20 02:21:46 +00002299 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002300 (void) NegateImageChannel(*image,channel,*option == '+' ?
2301 MagickTrue : MagickFalse);
2302 InheritException(exception,&(*image)->exception);
2303 break;
2304 }
2305 if (LocaleCompare("noise",option+1) == 0)
2306 {
2307 Image
2308 *noisy_image;
2309
cristy6b3da3a2010-06-20 02:21:46 +00002310 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002311 if (*option == '-')
2312 {
2313 (void) ParseGeometry(argv[i+1],&geometry_info);
2314 noisy_image=ReduceNoiseImage(*image,geometry_info.rho,
2315 exception);
2316 }
2317 else
2318 {
2319 NoiseType
2320 noise;
2321
2322 noise=(NoiseType) ParseMagickOption(MagickNoiseOptions,
2323 MagickFalse,argv[i+1]);
2324 noisy_image=AddNoiseImageChannel(*image,channel,noise,
2325 exception);
2326 }
2327 if (noisy_image == (Image *) NULL)
2328 break;
2329 *image=DestroyImage(*image);
2330 *image=noisy_image;
2331 break;
2332 }
2333 if (LocaleCompare("normalize",option+1) == 0)
2334 {
cristy6b3da3a2010-06-20 02:21:46 +00002335 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002336 (void) NormalizeImageChannel(*image,channel);
2337 InheritException(exception,&(*image)->exception);
2338 break;
2339 }
2340 break;
2341 }
2342 case 'o':
2343 {
2344 if (LocaleCompare("opaque",option+1) == 0)
2345 {
2346 MagickPixelPacket
2347 target;
2348
cristy6b3da3a2010-06-20 02:21:46 +00002349 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002350 (void) QueryMagickColor(argv[i+1],&target,exception);
2351 (void) OpaquePaintImageChannel(*image,channel,&target,&fill,
2352 *option == '-' ? MagickFalse : MagickTrue);
2353 break;
2354 }
2355 if (LocaleCompare("ordered-dither",option+1) == 0)
2356 {
cristy6b3da3a2010-06-20 02:21:46 +00002357 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002358 (void) OrderedPosterizeImageChannel(*image,channel,argv[i+1],
2359 exception);
2360 break;
2361 }
2362 break;
2363 }
2364 case 'p':
2365 {
2366 if (LocaleCompare("paint",option+1) == 0)
2367 {
2368 Image
2369 *paint_image;
2370
2371 /*
2372 Oil paint image.
2373 */
cristy6b3da3a2010-06-20 02:21:46 +00002374 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002375 (void) ParseGeometry(argv[i+1],&geometry_info);
2376 paint_image=OilPaintImage(*image,geometry_info.rho,exception);
2377 if (paint_image == (Image *) NULL)
2378 break;
2379 *image=DestroyImage(*image);
2380 *image=paint_image;
2381 break;
2382 }
2383 if (LocaleCompare("pen",option+1) == 0)
2384 {
2385 if (*option == '+')
2386 {
2387 (void) QueryColorDatabase("none",&draw_info->fill,exception);
2388 break;
2389 }
2390 (void) QueryColorDatabase(argv[i+1],&draw_info->fill,exception);
2391 break;
2392 }
2393 if (LocaleCompare("pointsize",option+1) == 0)
2394 {
2395 if (*option == '+')
2396 (void) ParseGeometry("12",&geometry_info);
2397 else
2398 (void) ParseGeometry(argv[i+1],&geometry_info);
2399 draw_info->pointsize=geometry_info.rho;
2400 break;
2401 }
2402 if (LocaleCompare("polaroid",option+1) == 0)
2403 {
2404 double
2405 angle;
2406
2407 Image
2408 *polaroid_image;
2409
2410 RandomInfo
2411 *random_info;
2412
2413 /*
2414 Simulate a Polaroid picture.
2415 */
cristy6b3da3a2010-06-20 02:21:46 +00002416 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002417 random_info=AcquireRandomInfo();
2418 angle=22.5*(GetPseudoRandomValue(random_info)-0.5);
2419 random_info=DestroyRandomInfo(random_info);
2420 if (*option == '-')
2421 {
2422 SetGeometryInfo(&geometry_info);
2423 flags=ParseGeometry(argv[i+1],&geometry_info);
2424 angle=geometry_info.rho;
2425 }
2426 polaroid_image=PolaroidImage(*image,draw_info,angle,exception);
2427 if (polaroid_image == (Image *) NULL)
2428 break;
2429 *image=DestroyImage(*image);
2430 *image=polaroid_image;
2431 break;
2432 }
2433 if (LocaleCompare("posterize",option+1) == 0)
2434 {
2435 /*
2436 Posterize image.
2437 */
cristy6b3da3a2010-06-20 02:21:46 +00002438 (void) SyncImageSettings(mogrify_info,*image);
cristye27293e2009-12-18 02:53:20 +00002439 (void) PosterizeImage(*image,StringToUnsignedLong(argv[i+1]),
cristy3ed852e2009-09-05 21:47:34 +00002440 quantize_info->dither);
2441 InheritException(exception,&(*image)->exception);
2442 break;
2443 }
2444 if (LocaleCompare("preview",option+1) == 0)
2445 {
2446 Image
2447 *preview_image;
2448
2449 PreviewType
2450 preview_type;
2451
2452 /*
2453 Preview image.
2454 */
cristy6b3da3a2010-06-20 02:21:46 +00002455 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002456 if (*option == '+')
2457 preview_type=UndefinedPreview;
2458 else
2459 preview_type=(PreviewType) ParseMagickOption(MagickPreviewOptions,
2460 MagickFalse,argv[i+1]);
2461 preview_image=PreviewImage(*image,preview_type,exception);
2462 if (preview_image == (Image *) NULL)
2463 break;
2464 *image=DestroyImage(*image);
2465 *image=preview_image;
2466 break;
2467 }
2468 if (LocaleCompare("profile",option+1) == 0)
2469 {
2470 const char
2471 *name;
2472
2473 const StringInfo
2474 *profile;
2475
2476 Image
2477 *profile_image;
2478
2479 ImageInfo
2480 *profile_info;
2481
cristy6b3da3a2010-06-20 02:21:46 +00002482 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002483 if (*option == '+')
2484 {
2485 /*
2486 Remove a profile from the image.
2487 */
2488 (void) ProfileImage(*image,argv[i+1],(const unsigned char *)
2489 NULL,0,MagickTrue);
2490 InheritException(exception,&(*image)->exception);
2491 break;
2492 }
2493 /*
2494 Associate a profile with the image.
2495 */
cristy6b3da3a2010-06-20 02:21:46 +00002496 profile_info=CloneImageInfo(mogrify_info);
cristy3ed852e2009-09-05 21:47:34 +00002497 profile=GetImageProfile(*image,"iptc");
2498 if (profile != (StringInfo *) NULL)
2499 profile_info->profile=(void *) CloneStringInfo(profile);
2500 profile_image=GetImageCache(profile_info,argv[i+1],exception);
2501 profile_info=DestroyImageInfo(profile_info);
2502 if (profile_image == (Image *) NULL)
2503 {
cristy3ed852e2009-09-05 21:47:34 +00002504 StringInfo
2505 *profile;
2506
cristy6b3da3a2010-06-20 02:21:46 +00002507 profile_info=CloneImageInfo(mogrify_info);
cristy071dd7b2010-04-09 13:04:54 +00002508 (void) CopyMagickString(profile_info->filename,argv[i+1],
2509 MaxTextExtent);
2510 profile=FileToStringInfo(profile_info->filename,~0UL,exception);
cristy3ed852e2009-09-05 21:47:34 +00002511 if (profile != (StringInfo *) NULL)
2512 {
cristy071dd7b2010-04-09 13:04:54 +00002513 (void) ProfileImage(*image,profile_info->magick,
cristybb503372010-05-27 20:51:26 +00002514 GetStringInfoDatum(profile),(size_t)
cristy071dd7b2010-04-09 13:04:54 +00002515 GetStringInfoLength(profile),MagickFalse);
cristy3ed852e2009-09-05 21:47:34 +00002516 profile=DestroyStringInfo(profile);
2517 }
cristy071dd7b2010-04-09 13:04:54 +00002518 profile_info=DestroyImageInfo(profile_info);
cristy3ed852e2009-09-05 21:47:34 +00002519 break;
2520 }
2521 ResetImageProfileIterator(profile_image);
2522 name=GetNextImageProfile(profile_image);
2523 while (name != (const char *) NULL)
2524 {
2525 profile=GetImageProfile(profile_image,name);
2526 if (profile != (StringInfo *) NULL)
2527 (void) ProfileImage(*image,name,GetStringInfoDatum(profile),
cristybb503372010-05-27 20:51:26 +00002528 (size_t) GetStringInfoLength(profile),MagickFalse);
cristy3ed852e2009-09-05 21:47:34 +00002529 name=GetNextImageProfile(profile_image);
2530 }
2531 profile_image=DestroyImage(profile_image);
2532 break;
2533 }
2534 break;
2535 }
2536 case 'q':
2537 {
2538 if (LocaleCompare("quantize",option+1) == 0)
2539 {
2540 if (*option == '+')
2541 {
2542 quantize_info->colorspace=UndefinedColorspace;
2543 break;
2544 }
2545 quantize_info->colorspace=(ColorspaceType) ParseMagickOption(
2546 MagickColorspaceOptions,MagickFalse,argv[i+1]);
2547 break;
2548 }
2549 break;
2550 }
2551 case 'r':
2552 {
2553 if (LocaleCompare("radial-blur",option+1) == 0)
2554 {
2555 Image
2556 *blur_image;
2557
2558 /*
2559 Radial blur image.
2560 */
cristy6b3da3a2010-06-20 02:21:46 +00002561 (void) SyncImageSettings(mogrify_info,*image);
cristya5447be2010-01-11 00:20:51 +00002562 blur_image=RadialBlurImageChannel(*image,channel,
2563 StringToDouble(argv[i+1]),exception);
cristy3ed852e2009-09-05 21:47:34 +00002564 if (blur_image == (Image *) NULL)
2565 break;
2566 *image=DestroyImage(*image);
2567 *image=blur_image;
2568 break;
2569 }
2570 if (LocaleCompare("raise",option+1) == 0)
2571 {
2572 /*
2573 Surround image with a raise of solid color.
2574 */
2575 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2576 if ((flags & SigmaValue) == 0)
2577 geometry.height=geometry.width;
2578 (void) RaiseImage(*image,&geometry,*option == '-' ? MagickTrue :
2579 MagickFalse);
2580 InheritException(exception,&(*image)->exception);
2581 break;
2582 }
2583 if (LocaleCompare("random-threshold",option+1) == 0)
2584 {
2585 /*
2586 Threshold image.
2587 */
cristy6b3da3a2010-06-20 02:21:46 +00002588 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002589 (void) RandomThresholdImageChannel(*image,channel,argv[i+1],
2590 exception);
2591 break;
2592 }
2593 if (LocaleCompare("recolor",option+1) == 0)
2594 {
cristy3ed852e2009-09-05 21:47:34 +00002595 Image
cristyf055ae42010-04-02 23:01:38 +00002596 *color_image;
cristy3ed852e2009-09-05 21:47:34 +00002597
cristyf055ae42010-04-02 23:01:38 +00002598 KernelInfo
2599 *kernel;
cristy3ed852e2009-09-05 21:47:34 +00002600
cristy6b3da3a2010-06-20 02:21:46 +00002601 (void) SyncImageSettings(mogrify_info,*image);
cristyf055ae42010-04-02 23:01:38 +00002602 kernel=AcquireKernelInfo(argv[i+1]);
2603 if (kernel == (KernelInfo *) NULL)
2604 break;
2605 color_image=ColorMatrixImage(*image,kernel,exception);
2606 kernel=DestroyKernelInfo(kernel);
2607 if (color_image == (Image *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002608 break;
2609 *image=DestroyImage(*image);
cristyf055ae42010-04-02 23:01:38 +00002610 *image=color_image;
cristy3ed852e2009-09-05 21:47:34 +00002611 break;
2612 }
2613 if (LocaleCompare("region",option+1) == 0)
2614 {
2615 Image
2616 *crop_image;
2617
cristy6b3da3a2010-06-20 02:21:46 +00002618 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002619 if (region_image != (Image *) NULL)
2620 {
2621 /*
2622 Composite region.
2623 */
2624 (void) CompositeImage(region_image,(*image)->matte !=
2625 MagickFalse ? OverCompositeOp : CopyCompositeOp,*image,
2626 region_geometry.x,region_geometry.y);
2627 InheritException(exception,&region_image->exception);
2628 *image=DestroyImage(*image);
2629 *image=region_image;
2630 }
2631 if (*option == '+')
2632 {
2633 if (region_image != (Image *) NULL)
cristyb0a6e432010-10-09 13:26:15 +00002634 region_image=(Image *) NULL;
cristy3ed852e2009-09-05 21:47:34 +00002635 break;
2636 }
2637 /*
2638 Apply transformations to a selected region of the image.
2639 */
2640 (void) ParseGravityGeometry(*image,argv[i+1],&region_geometry,
2641 exception);
2642 crop_image=CropImage(*image,&region_geometry,exception);
2643 if (crop_image == (Image *) NULL)
2644 break;
2645 region_image=(*image);
2646 *image=crop_image;
2647 break;
2648 }
2649 if (LocaleCompare("render",option+1) == 0)
2650 {
cristy6b3da3a2010-06-20 02:21:46 +00002651 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002652 draw_info->render=(*option == '+') ? MagickTrue : MagickFalse;
2653 break;
2654 }
2655 if (LocaleCompare("remap",option+1) == 0)
2656 {
2657 Image
2658 *remap_image;
2659
2660 /*
2661 Transform image colors to match this set of colors.
2662 */
cristy6b3da3a2010-06-20 02:21:46 +00002663 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002664 if (*option == '+')
2665 break;
cristy6b3da3a2010-06-20 02:21:46 +00002666 remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
cristy3ed852e2009-09-05 21:47:34 +00002667 if (remap_image == (Image *) NULL)
2668 break;
2669 (void) RemapImage(quantize_info,*image,remap_image);
2670 InheritException(exception,&(*image)->exception);
2671 remap_image=DestroyImage(remap_image);
2672 break;
2673 }
2674 if (LocaleCompare("repage",option+1) == 0)
2675 {
2676 if (*option == '+')
2677 {
2678 (void) ParseAbsoluteGeometry("0x0+0+0",&(*image)->page);
2679 break;
2680 }
2681 (void) ResetImagePage(*image,argv[i+1]);
2682 InheritException(exception,&(*image)->exception);
2683 break;
2684 }
2685 if (LocaleCompare("resample",option+1) == 0)
2686 {
2687 Image
2688 *resample_image;
2689
2690 /*
2691 Resample image.
2692 */
cristy6b3da3a2010-06-20 02:21:46 +00002693 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002694 flags=ParseGeometry(argv[i+1],&geometry_info);
2695 if ((flags & SigmaValue) == 0)
2696 geometry_info.sigma=geometry_info.rho;
2697 resample_image=ResampleImage(*image,geometry_info.rho,
2698 geometry_info.sigma,(*image)->filter,(*image)->blur,exception);
2699 if (resample_image == (Image *) NULL)
2700 break;
2701 *image=DestroyImage(*image);
2702 *image=resample_image;
2703 break;
2704 }
2705 if (LocaleCompare("resize",option+1) == 0)
2706 {
2707 Image
2708 *resize_image;
2709
2710 /*
2711 Resize image.
2712 */
cristy6b3da3a2010-06-20 02:21:46 +00002713 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002714 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2715 resize_image=ResizeImage(*image,geometry.width,geometry.height,
2716 (*image)->filter,(*image)->blur,exception);
2717 if (resize_image == (Image *) NULL)
2718 break;
2719 *image=DestroyImage(*image);
2720 *image=resize_image;
2721 break;
2722 }
2723 if (LocaleNCompare("respect-parentheses",option+1,17) == 0)
2724 {
2725 respect_parenthesis=(*option == '-') ? MagickTrue : MagickFalse;
2726 break;
2727 }
2728 if (LocaleCompare("roll",option+1) == 0)
2729 {
2730 Image
2731 *roll_image;
2732
2733 /*
2734 Roll image.
2735 */
cristy6b3da3a2010-06-20 02:21:46 +00002736 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002737 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2738 roll_image=RollImage(*image,geometry.x,geometry.y,exception);
2739 if (roll_image == (Image *) NULL)
2740 break;
2741 *image=DestroyImage(*image);
2742 *image=roll_image;
2743 break;
2744 }
2745 if (LocaleCompare("rotate",option+1) == 0)
2746 {
2747 char
2748 *geometry;
2749
2750 Image
2751 *rotate_image;
2752
2753 /*
2754 Check for conditional image rotation.
2755 */
cristy6b3da3a2010-06-20 02:21:46 +00002756 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002757 if (strchr(argv[i+1],'>') != (char *) NULL)
2758 if ((*image)->columns <= (*image)->rows)
2759 break;
2760 if (strchr(argv[i+1],'<') != (char *) NULL)
2761 if ((*image)->columns >= (*image)->rows)
2762 break;
2763 /*
2764 Rotate image.
2765 */
2766 geometry=ConstantString(argv[i+1]);
2767 (void) SubstituteString(&geometry,">","");
2768 (void) SubstituteString(&geometry,"<","");
2769 (void) ParseGeometry(geometry,&geometry_info);
2770 geometry=DestroyString(geometry);
2771 rotate_image=RotateImage(*image,geometry_info.rho,exception);
2772 if (rotate_image == (Image *) NULL)
2773 break;
2774 *image=DestroyImage(*image);
2775 *image=rotate_image;
2776 break;
2777 }
2778 break;
2779 }
2780 case 's':
2781 {
2782 if (LocaleCompare("sample",option+1) == 0)
2783 {
2784 Image
2785 *sample_image;
2786
2787 /*
2788 Sample image with pixel replication.
2789 */
cristy6b3da3a2010-06-20 02:21:46 +00002790 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002791 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2792 sample_image=SampleImage(*image,geometry.width,geometry.height,
2793 exception);
2794 if (sample_image == (Image *) NULL)
2795 break;
2796 *image=DestroyImage(*image);
2797 *image=sample_image;
2798 break;
2799 }
2800 if (LocaleCompare("scale",option+1) == 0)
2801 {
2802 Image
2803 *scale_image;
2804
2805 /*
2806 Resize image.
2807 */
cristy6b3da3a2010-06-20 02:21:46 +00002808 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002809 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2810 scale_image=ScaleImage(*image,geometry.width,geometry.height,
2811 exception);
2812 if (scale_image == (Image *) NULL)
2813 break;
2814 *image=DestroyImage(*image);
2815 *image=scale_image;
2816 break;
2817 }
2818 if (LocaleCompare("selective-blur",option+1) == 0)
2819 {
2820 Image
2821 *blur_image;
2822
2823 /*
2824 Selectively blur pixels within a contrast threshold.
2825 */
cristy6b3da3a2010-06-20 02:21:46 +00002826 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002827 flags=ParseGeometry(argv[i+1],&geometry_info);
2828 if ((flags & PercentValue) != 0)
2829 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
2830 blur_image=SelectiveBlurImageChannel(*image,channel,
2831 geometry_info.rho,geometry_info.sigma,geometry_info.xi,exception);
2832 if (blur_image == (Image *) NULL)
2833 break;
2834 *image=DestroyImage(*image);
2835 *image=blur_image;
2836 break;
2837 }
2838 if (LocaleCompare("separate",option+1) == 0)
2839 {
2840 Image
2841 *separate_images;
2842
2843 /*
2844 Break channels into separate images.
2845 */
cristy6b3da3a2010-06-20 02:21:46 +00002846 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002847 separate_images=SeparateImages(*image,channel,exception);
2848 if (separate_images == (Image *) NULL)
2849 break;
2850 *image=DestroyImage(*image);
2851 *image=separate_images;
2852 break;
2853 }
2854 if (LocaleCompare("sepia-tone",option+1) == 0)
2855 {
2856 double
2857 threshold;
2858
2859 Image
2860 *sepia_image;
2861
2862 /*
2863 Sepia-tone image.
2864 */
cristy6b3da3a2010-06-20 02:21:46 +00002865 (void) SyncImageSettings(mogrify_info,*image);
cristyf2f27272009-12-17 14:48:46 +00002866 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
cristy3ed852e2009-09-05 21:47:34 +00002867 sepia_image=SepiaToneImage(*image,threshold,exception);
2868 if (sepia_image == (Image *) NULL)
2869 break;
2870 *image=DestroyImage(*image);
2871 *image=sepia_image;
2872 break;
2873 }
2874 if (LocaleCompare("segment",option+1) == 0)
2875 {
2876 /*
2877 Segment image.
2878 */
cristy6b3da3a2010-06-20 02:21:46 +00002879 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002880 flags=ParseGeometry(argv[i+1],&geometry_info);
2881 if ((flags & SigmaValue) == 0)
2882 geometry_info.sigma=1.0;
cristy7e6164a2010-07-22 20:43:57 +00002883 (void) SegmentImage(*image,(*image)->colorspace,
2884 mogrify_info->verbose,geometry_info.rho,geometry_info.sigma);
cristy3ed852e2009-09-05 21:47:34 +00002885 InheritException(exception,&(*image)->exception);
2886 break;
2887 }
2888 if (LocaleCompare("set",option+1) == 0)
2889 {
cristy6d9a1292010-05-31 14:17:06 +00002890 char
2891 *value;
2892
cristy3ed852e2009-09-05 21:47:34 +00002893 /*
2894 Set image option.
2895 */
cristy6d9a1292010-05-31 14:17:06 +00002896 if (*option == '+')
2897 {
2898 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2899 (void) DeleteImageRegistry(argv[i+1]+9);
2900 else
2901 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
cristy7e109582010-06-01 12:56:44 +00002902 {
cristy6b3da3a2010-06-20 02:21:46 +00002903 (void) DeleteImageOption(mogrify_info,argv[i+1]+7);
cristy7e109582010-06-01 12:56:44 +00002904 (void) DeleteImageArtifact(*image,argv[i+1]+7);
2905 }
cristy6d9a1292010-05-31 14:17:06 +00002906 else
2907 (void) DeleteImageProperty(*image,argv[i+1]);
2908 break;
2909 }
cristy6b3da3a2010-06-20 02:21:46 +00002910 value=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
cristy6d9a1292010-05-31 14:17:06 +00002911 if (value == (char *) NULL)
2912 break;
cristy3ed852e2009-09-05 21:47:34 +00002913 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
cristy6d9a1292010-05-31 14:17:06 +00002914 (void) SetImageRegistry(StringRegistryType,argv[i+1]+9,value,
2915 exception);
cristy3ed852e2009-09-05 21:47:34 +00002916 else
2917 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
cristy6d9a1292010-05-31 14:17:06 +00002918 {
cristy7f02ba12010-09-21 12:39:28 +00002919 (void) SetImageOption(image_info,argv[i+1]+7,value);
cristy6b3da3a2010-06-20 02:21:46 +00002920 (void) SetImageOption(mogrify_info,argv[i+1]+7,value);
cristy6d9a1292010-05-31 14:17:06 +00002921 (void) SetImageArtifact(*image,argv[i+1]+7,value);
2922 }
cristy3ed852e2009-09-05 21:47:34 +00002923 else
cristy6d9a1292010-05-31 14:17:06 +00002924 (void) SetImageProperty(*image,argv[i+1],value);
2925 value=DestroyString(value);
cristy3ed852e2009-09-05 21:47:34 +00002926 break;
2927 }
2928 if (LocaleCompare("shade",option+1) == 0)
2929 {
2930 Image
2931 *shade_image;
2932
2933 /*
2934 Shade image.
2935 */
cristy6b3da3a2010-06-20 02:21:46 +00002936 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002937 flags=ParseGeometry(argv[i+1],&geometry_info);
2938 if ((flags & SigmaValue) == 0)
2939 geometry_info.sigma=1.0;
2940 shade_image=ShadeImage(*image,(*option == '-') ? MagickTrue :
2941 MagickFalse,geometry_info.rho,geometry_info.sigma,exception);
2942 if (shade_image == (Image *) NULL)
2943 break;
2944 *image=DestroyImage(*image);
2945 *image=shade_image;
2946 break;
2947 }
2948 if (LocaleCompare("shadow",option+1) == 0)
2949 {
2950 Image
2951 *shadow_image;
2952
2953 /*
2954 Shadow image.
2955 */
cristy6b3da3a2010-06-20 02:21:46 +00002956 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002957 flags=ParseGeometry(argv[i+1],&geometry_info);
2958 if ((flags & SigmaValue) == 0)
2959 geometry_info.sigma=1.0;
2960 if ((flags & XiValue) == 0)
2961 geometry_info.xi=4.0;
2962 if ((flags & PsiValue) == 0)
2963 geometry_info.psi=4.0;
2964 shadow_image=ShadowImage(*image,geometry_info.rho,
cristybb503372010-05-27 20:51:26 +00002965 geometry_info.sigma,(ssize_t) ceil(geometry_info.xi-0.5),(ssize_t)
cristy0534a6b2010-03-18 01:19:38 +00002966 ceil(geometry_info.psi-0.5),exception);
cristy3ed852e2009-09-05 21:47:34 +00002967 if (shadow_image == (Image *) NULL)
2968 break;
2969 *image=DestroyImage(*image);
2970 *image=shadow_image;
2971 break;
2972 }
2973 if (LocaleCompare("sharpen",option+1) == 0)
2974 {
2975 Image
2976 *sharp_image;
2977
2978 /*
2979 Sharpen image.
2980 */
cristy6b3da3a2010-06-20 02:21:46 +00002981 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002982 flags=ParseGeometry(argv[i+1],&geometry_info);
2983 if ((flags & SigmaValue) == 0)
2984 geometry_info.sigma=1.0;
2985 sharp_image=SharpenImageChannel(*image,channel,geometry_info.rho,
2986 geometry_info.sigma,exception);
2987 if (sharp_image == (Image *) NULL)
2988 break;
2989 *image=DestroyImage(*image);
2990 *image=sharp_image;
2991 break;
2992 }
2993 if (LocaleCompare("shave",option+1) == 0)
2994 {
2995 Image
2996 *shave_image;
2997
2998 /*
2999 Shave the image edges.
3000 */
cristy6b3da3a2010-06-20 02:21:46 +00003001 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003002 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
3003 shave_image=ShaveImage(*image,&geometry,exception);
3004 if (shave_image == (Image *) NULL)
3005 break;
3006 *image=DestroyImage(*image);
3007 *image=shave_image;
3008 break;
3009 }
3010 if (LocaleCompare("shear",option+1) == 0)
3011 {
3012 Image
3013 *shear_image;
3014
3015 /*
3016 Shear image.
3017 */
cristy6b3da3a2010-06-20 02:21:46 +00003018 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003019 flags=ParseGeometry(argv[i+1],&geometry_info);
3020 if ((flags & SigmaValue) == 0)
3021 geometry_info.sigma=geometry_info.rho;
3022 shear_image=ShearImage(*image,geometry_info.rho,geometry_info.sigma,
3023 exception);
3024 if (shear_image == (Image *) NULL)
3025 break;
3026 *image=DestroyImage(*image);
3027 *image=shear_image;
3028 break;
3029 }
3030 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
3031 {
3032 /*
3033 Sigmoidal non-linearity contrast control.
3034 */
cristy6b3da3a2010-06-20 02:21:46 +00003035 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003036 flags=ParseGeometry(argv[i+1],&geometry_info);
3037 if ((flags & SigmaValue) == 0)
3038 geometry_info.sigma=(double) QuantumRange/2.0;
3039 if ((flags & PercentValue) != 0)
3040 geometry_info.sigma=(double) QuantumRange*geometry_info.sigma/
3041 100.0;
3042 (void) SigmoidalContrastImageChannel(*image,channel,
3043 (*option == '-') ? MagickTrue : MagickFalse,geometry_info.rho,
3044 geometry_info.sigma);
3045 InheritException(exception,&(*image)->exception);
3046 break;
3047 }
3048 if (LocaleCompare("sketch",option+1) == 0)
3049 {
3050 Image
3051 *sketch_image;
3052
3053 /*
3054 Sketch image.
3055 */
cristy6b3da3a2010-06-20 02:21:46 +00003056 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003057 flags=ParseGeometry(argv[i+1],&geometry_info);
3058 if ((flags & SigmaValue) == 0)
3059 geometry_info.sigma=1.0;
3060 sketch_image=SketchImage(*image,geometry_info.rho,
3061 geometry_info.sigma,geometry_info.xi,exception);
3062 if (sketch_image == (Image *) NULL)
3063 break;
3064 *image=DestroyImage(*image);
3065 *image=sketch_image;
3066 break;
3067 }
3068 if (LocaleCompare("solarize",option+1) == 0)
3069 {
3070 double
3071 threshold;
3072
cristy6b3da3a2010-06-20 02:21:46 +00003073 (void) SyncImageSettings(mogrify_info,*image);
cristyf2f27272009-12-17 14:48:46 +00003074 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
cristy3ed852e2009-09-05 21:47:34 +00003075 (void) SolarizeImage(*image,threshold);
3076 InheritException(exception,&(*image)->exception);
3077 break;
3078 }
3079 if (LocaleCompare("sparse-color",option+1) == 0)
3080 {
3081 Image
3082 *sparse_image;
3083
3084 SparseColorMethod
3085 method;
3086
3087 char
3088 *arguments;
3089
3090 /*
3091 Sparse Color Interpolated Gradient
3092 */
cristy6b3da3a2010-06-20 02:21:46 +00003093 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003094 method=(SparseColorMethod) ParseMagickOption(
3095 MagickSparseColorOptions,MagickFalse,argv[i+1]);
cristy6b3da3a2010-06-20 02:21:46 +00003096 arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
cristy3ed852e2009-09-05 21:47:34 +00003097 InheritException(exception,&(*image)->exception);
3098 if (arguments == (char *) NULL)
3099 break;
3100 sparse_image=SparseColorOption(*image,channel,method,arguments,
3101 option[0] == '+' ? MagickTrue : MagickFalse,exception);
3102 arguments=DestroyString(arguments);
3103 if (sparse_image == (Image *) NULL)
3104 break;
3105 *image=DestroyImage(*image);
3106 *image=sparse_image;
3107 break;
3108 }
3109 if (LocaleCompare("splice",option+1) == 0)
3110 {
3111 Image
3112 *splice_image;
3113
3114 /*
3115 Splice a solid color into the image.
3116 */
cristy6b3da3a2010-06-20 02:21:46 +00003117 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003118 (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
3119 splice_image=SpliceImage(*image,&geometry,exception);
3120 if (splice_image == (Image *) NULL)
3121 break;
3122 *image=DestroyImage(*image);
3123 *image=splice_image;
3124 break;
3125 }
3126 if (LocaleCompare("spread",option+1) == 0)
3127 {
3128 Image
3129 *spread_image;
3130
3131 /*
3132 Spread an image.
3133 */
cristy6b3da3a2010-06-20 02:21:46 +00003134 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003135 (void) ParseGeometry(argv[i+1],&geometry_info);
3136 spread_image=SpreadImage(*image,geometry_info.rho,exception);
3137 if (spread_image == (Image *) NULL)
3138 break;
3139 *image=DestroyImage(*image);
3140 *image=spread_image;
3141 break;
3142 }
3143 if (LocaleCompare("stretch",option+1) == 0)
3144 {
3145 if (*option == '+')
3146 {
3147 draw_info->stretch=UndefinedStretch;
3148 break;
3149 }
3150 draw_info->stretch=(StretchType) ParseMagickOption(
3151 MagickStretchOptions,MagickFalse,argv[i+1]);
3152 break;
3153 }
3154 if (LocaleCompare("strip",option+1) == 0)
3155 {
3156 /*
3157 Strip image of profiles and comments.
3158 */
cristy6b3da3a2010-06-20 02:21:46 +00003159 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003160 (void) StripImage(*image);
3161 InheritException(exception,&(*image)->exception);
3162 break;
3163 }
3164 if (LocaleCompare("stroke",option+1) == 0)
3165 {
3166 ExceptionInfo
3167 *sans;
3168
3169 if (*option == '+')
3170 {
3171 (void) QueryColorDatabase("none",&draw_info->stroke,exception);
3172 if (draw_info->stroke_pattern != (Image *) NULL)
3173 draw_info->stroke_pattern=DestroyImage(
3174 draw_info->stroke_pattern);
3175 break;
3176 }
3177 sans=AcquireExceptionInfo();
3178 status=QueryColorDatabase(argv[i+1],&draw_info->stroke,sans);
3179 sans=DestroyExceptionInfo(sans);
3180 if (status == MagickFalse)
cristy6b3da3a2010-06-20 02:21:46 +00003181 draw_info->stroke_pattern=GetImageCache(mogrify_info,argv[i+1],
cristy3ed852e2009-09-05 21:47:34 +00003182 exception);
3183 break;
3184 }
3185 if (LocaleCompare("strokewidth",option+1) == 0)
3186 {
cristyf2f27272009-12-17 14:48:46 +00003187 draw_info->stroke_width=StringToDouble(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00003188 break;
3189 }
3190 if (LocaleCompare("style",option+1) == 0)
3191 {
3192 if (*option == '+')
3193 {
3194 draw_info->style=UndefinedStyle;
3195 break;
3196 }
3197 draw_info->style=(StyleType) ParseMagickOption(MagickStyleOptions,
3198 MagickFalse,argv[i+1]);
3199 break;
3200 }
3201 if (LocaleCompare("swirl",option+1) == 0)
3202 {
3203 Image
3204 *swirl_image;
3205
3206 /*
3207 Swirl image.
3208 */
cristy6b3da3a2010-06-20 02:21:46 +00003209 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003210 (void) ParseGeometry(argv[i+1],&geometry_info);
3211 swirl_image=SwirlImage(*image,geometry_info.rho,exception);
3212 if (swirl_image == (Image *) NULL)
3213 break;
3214 *image=DestroyImage(*image);
3215 *image=swirl_image;
3216 break;
3217 }
3218 break;
3219 }
3220 case 't':
3221 {
3222 if (LocaleCompare("threshold",option+1) == 0)
3223 {
3224 double
3225 threshold;
3226
3227 /*
3228 Threshold image.
3229 */
cristy6b3da3a2010-06-20 02:21:46 +00003230 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003231 if (*option == '+')
3232 threshold=(double) QuantumRange/2.5;
3233 else
cristyf2f27272009-12-17 14:48:46 +00003234 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
cristy3ed852e2009-09-05 21:47:34 +00003235 (void) BilevelImageChannel(*image,channel,threshold);
3236 InheritException(exception,&(*image)->exception);
3237 break;
3238 }
3239 if (LocaleCompare("thumbnail",option+1) == 0)
3240 {
3241 Image
3242 *thumbnail_image;
3243
3244 /*
3245 Thumbnail image.
3246 */
cristy6b3da3a2010-06-20 02:21:46 +00003247 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003248 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
3249 thumbnail_image=ThumbnailImage(*image,geometry.width,
3250 geometry.height,exception);
3251 if (thumbnail_image == (Image *) NULL)
3252 break;
3253 *image=DestroyImage(*image);
3254 *image=thumbnail_image;
3255 break;
3256 }
3257 if (LocaleCompare("tile",option+1) == 0)
3258 {
3259 if (*option == '+')
3260 {
3261 if (draw_info->fill_pattern != (Image *) NULL)
3262 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
3263 break;
3264 }
cristy6b3da3a2010-06-20 02:21:46 +00003265 draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1],
cristy3ed852e2009-09-05 21:47:34 +00003266 exception);
3267 break;
3268 }
3269 if (LocaleCompare("tint",option+1) == 0)
3270 {
3271 Image
3272 *tint_image;
3273
3274 /*
3275 Tint the image.
3276 */
cristy6b3da3a2010-06-20 02:21:46 +00003277 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003278 tint_image=TintImage(*image,argv[i+1],draw_info->fill,exception);
3279 if (tint_image == (Image *) NULL)
3280 break;
3281 *image=DestroyImage(*image);
3282 *image=tint_image;
3283 break;
3284 }
3285 if (LocaleCompare("transform",option+1) == 0)
3286 {
3287 Image
3288 *transform_image;
3289
3290 /*
3291 Affine transform image.
3292 */
cristy6b3da3a2010-06-20 02:21:46 +00003293 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003294 transform_image=AffineTransformImage(*image,&draw_info->affine,
3295 exception);
3296 if (transform_image == (Image *) NULL)
3297 break;
3298 *image=DestroyImage(*image);
3299 *image=transform_image;
3300 break;
3301 }
3302 if (LocaleCompare("transparent",option+1) == 0)
3303 {
3304 MagickPixelPacket
3305 target;
3306
cristy6b3da3a2010-06-20 02:21:46 +00003307 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003308 (void) QueryMagickColor(argv[i+1],&target,exception);
3309 (void) TransparentPaintImage(*image,&target,(Quantum)
3310 TransparentOpacity,*option == '-' ? MagickFalse : MagickTrue);
3311 InheritException(exception,&(*image)->exception);
3312 break;
3313 }
3314 if (LocaleCompare("transpose",option+1) == 0)
3315 {
3316 Image
3317 *transpose_image;
3318
3319 /*
3320 Transpose image scanlines.
3321 */
cristy6b3da3a2010-06-20 02:21:46 +00003322 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003323 transpose_image=TransposeImage(*image,exception);
3324 if (transpose_image == (Image *) NULL)
3325 break;
3326 *image=DestroyImage(*image);
3327 *image=transpose_image;
3328 break;
3329 }
3330 if (LocaleCompare("transverse",option+1) == 0)
3331 {
3332 Image
3333 *transverse_image;
3334
3335 /*
3336 Transverse image scanlines.
3337 */
cristy6b3da3a2010-06-20 02:21:46 +00003338 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003339 transverse_image=TransverseImage(*image,exception);
3340 if (transverse_image == (Image *) NULL)
3341 break;
3342 *image=DestroyImage(*image);
3343 *image=transverse_image;
3344 break;
3345 }
3346 if (LocaleCompare("treedepth",option+1) == 0)
3347 {
cristye27293e2009-12-18 02:53:20 +00003348 quantize_info->tree_depth=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00003349 break;
3350 }
3351 if (LocaleCompare("trim",option+1) == 0)
3352 {
3353 Image
3354 *trim_image;
3355
3356 /*
3357 Trim image.
3358 */
cristy6b3da3a2010-06-20 02:21:46 +00003359 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003360 trim_image=TrimImage(*image,exception);
3361 if (trim_image == (Image *) NULL)
3362 break;
3363 *image=DestroyImage(*image);
3364 *image=trim_image;
3365 break;
3366 }
3367 if (LocaleCompare("type",option+1) == 0)
3368 {
3369 ImageType
3370 type;
3371
cristy6b3da3a2010-06-20 02:21:46 +00003372 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003373 if (*option == '+')
3374 type=UndefinedType;
3375 else
3376 type=(ImageType) ParseMagickOption(MagickTypeOptions,MagickFalse,
3377 argv[i+1]);
3378 (*image)->type=UndefinedType;
3379 (void) SetImageType(*image,type);
3380 InheritException(exception,&(*image)->exception);
3381 break;
3382 }
3383 break;
3384 }
3385 case 'u':
3386 {
3387 if (LocaleCompare("undercolor",option+1) == 0)
3388 {
3389 (void) QueryColorDatabase(argv[i+1],&draw_info->undercolor,
3390 exception);
3391 break;
3392 }
cristy045bd902010-01-30 18:56:24 +00003393 if (LocaleCompare("unique",option+1) == 0)
3394 {
3395 if (*option == '+')
3396 {
cristy83fae872010-04-22 15:04:16 +00003397 (void) DeleteImageArtifact(*image,"identify:unique-colors");
cristy045bd902010-01-30 18:56:24 +00003398 break;
3399 }
cristy83fae872010-04-22 15:04:16 +00003400 (void) SetImageArtifact(*image,"identify:unique-colors","true");
cristy7e6164a2010-07-22 20:43:57 +00003401 (void) SetImageArtifact(*image,"identify:verbose","true");
cristy045bd902010-01-30 18:56:24 +00003402 break;
3403 }
cristy3ed852e2009-09-05 21:47:34 +00003404 if (LocaleCompare("unique-colors",option+1) == 0)
3405 {
3406 Image
3407 *unique_image;
3408
3409 /*
3410 Unique image colors.
3411 */
cristy6b3da3a2010-06-20 02:21:46 +00003412 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003413 unique_image=UniqueImageColors(*image,exception);
3414 if (unique_image == (Image *) NULL)
3415 break;
3416 *image=DestroyImage(*image);
3417 *image=unique_image;
3418 break;
3419 }
3420 if (LocaleCompare("unsharp",option+1) == 0)
3421 {
3422 Image
3423 *unsharp_image;
3424
3425 /*
3426 Unsharp mask image.
3427 */
cristy6b3da3a2010-06-20 02:21:46 +00003428 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003429 flags=ParseGeometry(argv[i+1],&geometry_info);
3430 if ((flags & SigmaValue) == 0)
3431 geometry_info.sigma=1.0;
3432 if ((flags & XiValue) == 0)
3433 geometry_info.xi=1.0;
3434 if ((flags & PsiValue) == 0)
3435 geometry_info.psi=0.05;
3436 unsharp_image=UnsharpMaskImageChannel(*image,channel,
3437 geometry_info.rho,geometry_info.sigma,geometry_info.xi,
3438 geometry_info.psi,exception);
3439 if (unsharp_image == (Image *) NULL)
3440 break;
3441 *image=DestroyImage(*image);
3442 *image=unsharp_image;
3443 break;
3444 }
3445 break;
3446 }
3447 case 'v':
3448 {
3449 if (LocaleCompare("verbose",option+1) == 0)
3450 {
3451 (void) SetImageArtifact(*image,option+1,
3452 *option == '+' ? "false" : "true");
3453 break;
3454 }
3455 if (LocaleCompare("vignette",option+1) == 0)
3456 {
3457 Image
3458 *vignette_image;
3459
3460 /*
3461 Vignette image.
3462 */
cristy6b3da3a2010-06-20 02:21:46 +00003463 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003464 flags=ParseGeometry(argv[i+1],&geometry_info);
3465 if ((flags & SigmaValue) == 0)
3466 geometry_info.sigma=1.0;
3467 if ((flags & XiValue) == 0)
3468 geometry_info.xi=0.1*(*image)->columns;
3469 if ((flags & PsiValue) == 0)
3470 geometry_info.psi=0.1*(*image)->rows;
3471 vignette_image=VignetteImage(*image,geometry_info.rho,
cristybb503372010-05-27 20:51:26 +00003472 geometry_info.sigma,(ssize_t) ceil(geometry_info.xi-0.5),(ssize_t)
cristy0534a6b2010-03-18 01:19:38 +00003473 ceil(geometry_info.psi-0.5),exception);
cristy3ed852e2009-09-05 21:47:34 +00003474 if (vignette_image == (Image *) NULL)
3475 break;
3476 *image=DestroyImage(*image);
3477 *image=vignette_image;
3478 break;
3479 }
3480 if (LocaleCompare("virtual-pixel",option+1) == 0)
3481 {
3482 if (*option == '+')
3483 {
3484 (void) SetImageVirtualPixelMethod(*image,
3485 UndefinedVirtualPixelMethod);
3486 break;
3487 }
3488 (void) SetImageVirtualPixelMethod(*image,(VirtualPixelMethod)
3489 ParseMagickOption(MagickVirtualPixelOptions,MagickFalse,
3490 argv[i+1]));
3491 break;
3492 }
3493 break;
3494 }
3495 case 'w':
3496 {
3497 if (LocaleCompare("wave",option+1) == 0)
3498 {
3499 Image
3500 *wave_image;
3501
3502 /*
3503 Wave image.
3504 */
cristy6b3da3a2010-06-20 02:21:46 +00003505 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003506 flags=ParseGeometry(argv[i+1],&geometry_info);
3507 if ((flags & SigmaValue) == 0)
3508 geometry_info.sigma=1.0;
3509 wave_image=WaveImage(*image,geometry_info.rho,geometry_info.sigma,
3510 exception);
3511 if (wave_image == (Image *) NULL)
3512 break;
3513 *image=DestroyImage(*image);
3514 *image=wave_image;
3515 break;
3516 }
3517 if (LocaleCompare("weight",option+1) == 0)
3518 {
cristye27293e2009-12-18 02:53:20 +00003519 draw_info->weight=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00003520 if (LocaleCompare(argv[i+1],"all") == 0)
3521 draw_info->weight=0;
3522 if (LocaleCompare(argv[i+1],"bold") == 0)
3523 draw_info->weight=700;
3524 if (LocaleCompare(argv[i+1],"bolder") == 0)
3525 if (draw_info->weight <= 800)
3526 draw_info->weight+=100;
3527 if (LocaleCompare(argv[i+1],"lighter") == 0)
3528 if (draw_info->weight >= 100)
3529 draw_info->weight-=100;
3530 if (LocaleCompare(argv[i+1],"normal") == 0)
3531 draw_info->weight=400;
3532 break;
3533 }
3534 if (LocaleCompare("white-threshold",option+1) == 0)
3535 {
3536 /*
3537 White threshold image.
3538 */
cristy6b3da3a2010-06-20 02:21:46 +00003539 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003540 (void) WhiteThresholdImageChannel(*image,channel,argv[i+1],
3541 exception);
3542 InheritException(exception,&(*image)->exception);
3543 break;
3544 }
3545 break;
3546 }
3547 default:
3548 break;
3549 }
3550 i+=count;
3551 }
3552 if (region_image != (Image *) NULL)
3553 {
3554 /*
3555 Composite transformed region onto image.
3556 */
cristy6b3da3a2010-06-20 02:21:46 +00003557 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003558 (void) CompositeImage(region_image,(*image)->matte != MagickFalse ?
3559 OverCompositeOp : CopyCompositeOp,*image,region_geometry.x,
3560 region_geometry.y);
3561 InheritException(exception,&region_image->exception);
3562 *image=DestroyImage(*image);
3563 *image=region_image;
3564 }
3565 /*
3566 Free resources.
3567 */
3568 quantize_info=DestroyQuantizeInfo(quantize_info);
3569 draw_info=DestroyDrawInfo(draw_info);
cristy6b3da3a2010-06-20 02:21:46 +00003570 mogrify_info=DestroyImageInfo(mogrify_info);
3571 status=(*image)->exception.severity == UndefinedException ? MagickTrue :
3572 MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00003573 return(status);
3574}
3575
3576/*
3577%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3578% %
3579% %
3580% %
3581% M o g r i f y I m a g e C o m m a n d %
3582% %
3583% %
3584% %
3585%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3586%
3587% MogrifyImageCommand() transforms an image or a sequence of images. These
3588% transforms include image scaling, image rotation, color reduction, and
3589% others. The transmogrified image overwrites the original image.
3590%
3591% The format of the MogrifyImageCommand method is:
3592%
3593% MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,int argc,
3594% const char **argv,char **metadata,ExceptionInfo *exception)
3595%
3596% A description of each parameter follows:
3597%
3598% o image_info: the image info.
3599%
3600% o argc: the number of elements in the argument vector.
3601%
3602% o argv: A text array containing the command line arguments.
3603%
3604% o metadata: any metadata is returned here.
3605%
3606% o exception: return any errors or warnings in this structure.
3607%
3608*/
3609
3610static MagickBooleanType MogrifyUsage(void)
3611{
3612 static const char
3613 *miscellaneous[]=
3614 {
3615 "-debug events display copious debugging information",
3616 "-help print program options",
3617 "-list type print a list of supported option arguments",
3618 "-log format format of debugging information",
3619 "-version print version information",
3620 (char *) NULL
3621 },
3622 *operators[]=
3623 {
3624 "-adaptive-blur geometry",
3625 " adaptively blur pixels; decrease effect near edges",
3626 "-adaptive-resize geometry",
3627 " adaptively resize image using 'mesh' interpolation",
3628 "-adaptive-sharpen geometry",
3629 " adaptively sharpen pixels; increase effect near edges",
3630 "-alpha option on, activate, off, deactivate, set, opaque, copy",
3631 " transparent, extract, background, or shape",
3632 "-annotate geometry text",
3633 " annotate the image with text",
3634 "-auto-gamma automagically adjust gamma level of image",
3635 "-auto-level automagically adjust color levels of image",
3636 "-auto-orient automagically orient (rotate) image",
3637 "-bench iterations measure performance",
3638 "-black-threshold value",
3639 " force all pixels below the threshold into black",
3640 "-blue-shift simulate a scene at nighttime in the moonlight",
3641 "-blur geometry reduce image noise and reduce detail levels",
3642 "-border geometry surround image with a border of color",
3643 "-bordercolor color border color",
cristya28d6b82010-01-11 20:03:47 +00003644 "-brightness-contrast geometry",
3645 " improve brightness / contrast of the image",
cristy3ed852e2009-09-05 21:47:34 +00003646 "-cdl filename color correct with a color decision list",
3647 "-charcoal radius simulate a charcoal drawing",
3648 "-chop geometry remove pixels from the image interior",
cristyecb0c6d2009-09-25 16:50:09 +00003649 "-clamp restrict pixel range from 0 to the quantum depth",
cristycee97112010-05-28 00:44:52 +00003650 "-clip clip along the first path from the 8BIM profile",
cristy3ed852e2009-09-05 21:47:34 +00003651 "-clip-mask filename associate a clip mask with the image",
cristycee97112010-05-28 00:44:52 +00003652 "-clip-path id clip along a named path from the 8BIM profile",
cristy3ed852e2009-09-05 21:47:34 +00003653 "-colorize value colorize the image with the fill color",
cristye6365592010-04-02 17:31:23 +00003654 "-color-matrix matrix apply color correction to the image",
cristy3ed852e2009-09-05 21:47:34 +00003655 "-contrast enhance or reduce the image contrast",
3656 "-contrast-stretch geometry",
3657 " improve contrast by `stretching' the intensity range",
3658 "-convolve coefficients",
3659 " apply a convolution kernel to the image",
3660 "-cycle amount cycle the image colormap",
3661 "-decipher filename convert cipher pixels to plain pixels",
3662 "-deskew threshold straighten an image",
3663 "-despeckle reduce the speckles within an image",
3664 "-distort method args",
3665 " distort images according to given method ad args",
3666 "-draw string annotate the image with a graphic primitive",
3667 "-edge radius apply a filter to detect edges in the image",
3668 "-encipher filename convert plain pixels to cipher pixels",
3669 "-emboss radius emboss an image",
3670 "-enhance apply a digital filter to enhance a noisy image",
3671 "-equalize perform histogram equalization to an image",
3672 "-evaluate operator value",
cristyd18ae7c2010-03-07 17:39:52 +00003673 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003674 "-extent geometry set the image size",
3675 "-extract geometry extract area from image",
3676 "-fft implements the discrete Fourier transform (DFT)",
3677 "-flip flip image vertically",
3678 "-floodfill geometry color",
3679 " floodfill the image with color",
3680 "-flop flop image horizontally",
3681 "-frame geometry surround image with an ornamental border",
cristyc2b730e2009-11-24 14:32:09 +00003682 "-function name parameters",
cristy3ed852e2009-09-05 21:47:34 +00003683 " apply function over image values",
3684 "-gamma value level of gamma correction",
3685 "-gaussian-blur geometry",
3686 " reduce image noise and reduce detail levels",
cristy901f09d2009-10-16 22:56:10 +00003687 "-geometry geometry preferred size or location of the image",
cristy3ed852e2009-09-05 21:47:34 +00003688 "-identify identify the format and characteristics of the image",
3689 "-ift implements the inverse discrete Fourier transform (DFT)",
3690 "-implode amount implode image pixels about the center",
3691 "-lat geometry local adaptive thresholding",
3692 "-layers method optimize, merge, or compare image layers",
3693 "-level value adjust the level of image contrast",
3694 "-level-colors color,color",
cristyee0f8d72009-09-19 00:58:29 +00003695 " level image with the given colors",
cristy3ed852e2009-09-05 21:47:34 +00003696 "-linear-stretch geometry",
3697 " improve contrast by `stretching with saturation'",
3698 "-liquid-rescale geometry",
3699 " rescale image with seam-carving",
3700 "-median radius apply a median filter to the image",
3701 "-modulate value vary the brightness, saturation, and hue",
3702 "-monochrome transform image to black and white",
cristy7c1b9fd2010-02-02 14:36:00 +00003703 "-morphology method kernel",
anthony29188a82010-01-22 10:12:34 +00003704 " apply a morphology method to the image",
cristy3ed852e2009-09-05 21:47:34 +00003705 "-motion-blur geometry",
3706 " simulate motion blur",
3707 "-negate replace every pixel with its complementary color ",
3708 "-noise radius add or reduce noise in an image",
3709 "-normalize transform image to span the full range of colors",
3710 "-opaque color change this color to the fill color",
3711 "-ordered-dither NxN",
3712 " add a noise pattern to the image with specific",
3713 " amplitudes",
3714 "-paint radius simulate an oil painting",
3715 "-polaroid angle simulate a Polaroid picture",
3716 "-posterize levels reduce the image to a limited number of color levels",
cristy3ed852e2009-09-05 21:47:34 +00003717 "-profile filename add, delete, or apply an image profile",
3718 "-quantize colorspace reduce colors in this colorspace",
3719 "-radial-blur angle radial blur the image",
3720 "-raise value lighten/darken image edges to create a 3-D effect",
3721 "-random-threshold low,high",
3722 " random threshold the image",
cristy3ed852e2009-09-05 21:47:34 +00003723 "-region geometry apply options to a portion of the image",
3724 "-render render vector graphics",
3725 "-repage geometry size and location of an image canvas",
3726 "-resample geometry change the resolution of an image",
3727 "-resize geometry resize the image",
3728 "-roll geometry roll an image vertically or horizontally",
3729 "-rotate degrees apply Paeth rotation to the image",
3730 "-sample geometry scale image with pixel sampling",
3731 "-scale geometry scale the image",
3732 "-segment values segment an image",
3733 "-selective-blur geometry",
3734 " selectively blur pixels within a contrast threshold",
3735 "-sepia-tone threshold",
3736 " simulate a sepia-toned photo",
3737 "-set property value set an image property",
3738 "-shade degrees shade the image using a distant light source",
3739 "-shadow geometry simulate an image shadow",
3740 "-sharpen geometry sharpen the image",
3741 "-shave geometry shave pixels from the image edges",
cristycee97112010-05-28 00:44:52 +00003742 "-shear geometry slide one edge of the image along the X or Y axis",
cristy3ed852e2009-09-05 21:47:34 +00003743 "-sigmoidal-contrast geometry",
3744 " increase the contrast without saturating highlights or shadows",
3745 "-sketch geometry simulate a pencil sketch",
3746 "-solarize threshold negate all pixels above the threshold level",
3747 "-sparse-color method args",
3748 " fill in a image based on a few color points",
3749 "-splice geometry splice the background color into the image",
3750 "-spread radius displace image pixels by a random amount",
3751 "-strip strip image of all profiles and comments",
3752 "-swirl degrees swirl image pixels about the center",
3753 "-threshold value threshold the image",
3754 "-thumbnail geometry create a thumbnail of the image",
3755 "-tile filename tile image when filling a graphic primitive",
3756 "-tint value tint the image with the fill color",
3757 "-transform affine transform image",
3758 "-transparent color make this color transparent within the image",
3759 "-transpose flip image vertically and rotate 90 degrees",
3760 "-transverse flop image horizontally and rotate 270 degrees",
3761 "-trim trim image edges",
3762 "-type type image type",
3763 "-unique-colors discard all but one of any pixel color",
3764 "-unsharp geometry sharpen the image",
3765 "-vignette geometry soften the edges of the image in vignette style",
cristycee97112010-05-28 00:44:52 +00003766 "-wave geometry alter an image along a sine wave",
cristy3ed852e2009-09-05 21:47:34 +00003767 "-white-threshold value",
3768 " force all pixels above the threshold into white",
3769 (char *) NULL
3770 },
3771 *sequence_operators[]=
3772 {
cristyde5f6c62010-09-13 17:16:07 +00003773 "-append append an image sequence top to bottom",
cristy3ed852e2009-09-05 21:47:34 +00003774 "-clut apply a color lookup table to the image",
3775 "-coalesce merge a sequence of images",
3776 "-combine combine a sequence of images",
3777 "-composite composite image",
3778 "-crop geometry cut out a rectangular region of the image",
3779 "-deconstruct break down an image sequence into constituent parts",
cristyd18ae7c2010-03-07 17:39:52 +00003780 "-evaluate-sequence operator",
3781 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003782 "-flatten flatten a sequence of images",
3783 "-fx expression apply mathematical expression to an image channel(s)",
3784 "-hald-clut apply a Hald color lookup table to the image",
3785 "-morph value morph an image sequence",
3786 "-mosaic create a mosaic from an image sequence",
cristy36b94822010-05-20 12:48:16 +00003787 "-print string interpret string and print to console",
cristy3ed852e2009-09-05 21:47:34 +00003788 "-process arguments process the image with a custom image filter",
3789 "-reverse reverse image sequence",
3790 "-separate separate an image channel into a grayscale image",
3791 "-write filename write images to this file",
3792 (char *) NULL
3793 },
3794 *settings[]=
3795 {
3796 "-adjoin join images into a single multi-image file",
3797 "-affine matrix affine transform matrix",
3798 "-alpha option activate, deactivate, reset, or set the alpha channel",
3799 "-antialias remove pixel-aliasing",
3800 "-authenticate password",
3801 " decipher image with this password",
3802 "-attenuate value lessen (or intensify) when adding noise to an image",
3803 "-background color background color",
3804 "-bias value add bias when convolving an image",
3805 "-black-point-compensation",
3806 " use black point compensation",
3807 "-blue-primary point chromaticity blue primary point",
3808 "-bordercolor color border color",
3809 "-caption string assign a caption to an image",
3810 "-channel type apply option to select image channels",
3811 "-colors value preferred number of colors in the image",
3812 "-colorspace type alternate image colorspace",
3813 "-comment string annotate image with comment",
3814 "-compose operator set image composite operator",
3815 "-compress type type of pixel compression when writing the image",
3816 "-define format:option",
3817 " define one or more image format options",
3818 "-delay value display the next image after pausing",
3819 "-density geometry horizontal and vertical density of the image",
3820 "-depth value image depth",
cristyc9b12952010-03-28 01:12:28 +00003821 "-direction type render text right-to-left or left-to-right",
cristy3ed852e2009-09-05 21:47:34 +00003822 "-display server get image or font from this X server",
3823 "-dispose method layer disposal method",
3824 "-dither method apply error diffusion to image",
3825 "-encoding type text encoding type",
3826 "-endian type endianness (MSB or LSB) of the image",
3827 "-family name render text with this font family",
3828 "-fill color color to use when filling a graphic primitive",
3829 "-filter type use this filter when resizing an image",
3830 "-font name render text with this font",
3831 "-format \"string\" output formatted image characteristics",
3832 "-fuzz distance colors within this distance are considered equal",
3833 "-gravity type horizontal and vertical text placement",
3834 "-green-primary point chromaticity green primary point",
3835 "-intent type type of rendering intent when managing the image color",
3836 "-interlace type type of image interlacing scheme",
cristyb32b90a2009-09-07 21:45:48 +00003837 "-interline-spacing value",
3838 " set the space between two text lines",
cristy3ed852e2009-09-05 21:47:34 +00003839 "-interpolate method pixel color interpolation method",
3840 "-interword-spacing value",
3841 " set the space between two words",
3842 "-kerning value set the space between two letters",
3843 "-label string assign a label to an image",
3844 "-limit type value pixel cache resource limit",
3845 "-loop iterations add Netscape loop extension to your GIF animation",
3846 "-mask filename associate a mask with the image",
3847 "-mattecolor color frame color",
3848 "-monitor monitor progress",
3849 "-orient type image orientation",
3850 "-page geometry size and location of an image canvas (setting)",
3851 "-ping efficiently determine image attributes",
3852 "-pointsize value font point size",
cristy7c1b9fd2010-02-02 14:36:00 +00003853 "-precision value maximum number of significant digits to print",
cristy3ed852e2009-09-05 21:47:34 +00003854 "-preview type image preview type",
3855 "-quality value JPEG/MIFF/PNG compression level",
3856 "-quiet suppress all warning messages",
3857 "-red-primary point chromaticity red primary point",
3858 "-regard-warnings pay attention to warning messages",
3859 "-remap filename transform image colors to match this set of colors",
3860 "-respect-parentheses settings remain in effect until parenthesis boundary",
3861 "-sampling-factor geometry",
3862 " horizontal and vertical sampling factor",
3863 "-scene value image scene number",
3864 "-seed value seed a new sequence of pseudo-random numbers",
3865 "-size geometry width and height of image",
3866 "-stretch type render text with this font stretch",
3867 "-stroke color graphic primitive stroke color",
3868 "-strokewidth value graphic primitive stroke width",
3869 "-style type render text with this font style",
cristyd9a29192010-10-16 16:49:53 +00003870 "-synchronize synchronize image to storage device",
3871 "-taint declare the image as modified",
cristy3ed852e2009-09-05 21:47:34 +00003872 "-texture filename name of texture to tile onto the image background",
3873 "-tile-offset geometry",
3874 " tile offset",
3875 "-treedepth value color tree depth",
3876 "-transparent-color color",
3877 " transparent color",
3878 "-undercolor color annotation bounding box color",
3879 "-units type the units of image resolution",
3880 "-verbose print detailed information about the image",
3881 "-view FlashPix viewing transforms",
3882 "-virtual-pixel method",
3883 " virtual pixel access method",
3884 "-weight type render text with this font weight",
3885 "-white-point point chromaticity white point",
3886 (char *) NULL
3887 },
3888 *stack_operators[]=
3889 {
3890 "-clone index clone an image",
3891 "-delete index delete the image from the image sequence",
3892 "-insert index insert last image into the image sequence",
3893 "-swap indexes swap two images in the image sequence",
3894 (char *) NULL
3895 };
3896
3897 const char
3898 **p;
3899
cristybb503372010-05-27 20:51:26 +00003900 (void) printf("Version: %s\n",GetMagickVersion((size_t *) NULL));
cristy610b2e22009-10-22 14:59:43 +00003901 (void) printf("Copyright: %s\n",GetMagickCopyright());
3902 (void) printf("Features: %s\n\n",GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00003903 (void) printf("Usage: %s [options ...] file [ [options ...] file ...]\n",
3904 GetClientName());
3905 (void) printf("\nImage Settings:\n");
3906 for (p=settings; *p != (char *) NULL; p++)
3907 (void) printf(" %s\n",*p);
3908 (void) printf("\nImage Operators:\n");
3909 for (p=operators; *p != (char *) NULL; p++)
3910 (void) printf(" %s\n",*p);
3911 (void) printf("\nImage Sequence Operators:\n");
3912 for (p=sequence_operators; *p != (char *) NULL; p++)
3913 (void) printf(" %s\n",*p);
3914 (void) printf("\nImage Stack Operators:\n");
3915 for (p=stack_operators; *p != (char *) NULL; p++)
3916 (void) printf(" %s\n",*p);
3917 (void) printf("\nMiscellaneous Options:\n");
3918 for (p=miscellaneous; *p != (char *) NULL; p++)
3919 (void) printf(" %s\n",*p);
3920 (void) printf(
3921 "\nBy default, the image format of `file' is determined by its magic\n");
3922 (void) printf(
3923 "number. To specify a particular image format, precede the filename\n");
3924 (void) printf(
3925 "with an image format name and a colon (i.e. ps:image) or specify the\n");
3926 (void) printf(
3927 "image type as the filename suffix (i.e. image.ps). Specify 'file' as\n");
3928 (void) printf("'-' for standard input or output.\n");
3929 return(MagickFalse);
3930}
3931
3932WandExport MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,
3933 int argc,char **argv,char **wand_unused(metadata),ExceptionInfo *exception)
3934{
3935#define DestroyMogrify() \
3936{ \
3937 if (format != (char *) NULL) \
3938 format=DestroyString(format); \
3939 if (path != (char *) NULL) \
3940 path=DestroyString(path); \
3941 DestroyImageStack(); \
cristybb503372010-05-27 20:51:26 +00003942 for (i=0; i < (ssize_t) argc; i++) \
cristy3ed852e2009-09-05 21:47:34 +00003943 argv[i]=DestroyString(argv[i]); \
3944 argv=(char **) RelinquishMagickMemory(argv); \
3945}
3946#define ThrowMogrifyException(asperity,tag,option) \
3947{ \
3948 (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag,"`%s'", \
3949 option); \
3950 DestroyMogrify(); \
3951 return(MagickFalse); \
3952}
3953#define ThrowMogrifyInvalidArgumentException(option,argument) \
3954{ \
3955 (void) ThrowMagickException(exception,GetMagickModule(),OptionError, \
3956 "InvalidArgument","`%s': %s",argument,option); \
3957 DestroyMogrify(); \
3958 return(MagickFalse); \
3959}
3960
3961 char
3962 *format,
3963 *option,
3964 *path;
3965
3966 Image
3967 *image;
3968
3969 ImageStack
3970 image_stack[MaxImageStackDepth+1];
3971
cristybb503372010-05-27 20:51:26 +00003972 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003973 j,
3974 k;
3975
cristybb503372010-05-27 20:51:26 +00003976 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003977 i;
3978
3979 MagickBooleanType
3980 global_colormap;
3981
3982 MagickBooleanType
3983 fire,
3984 pend;
3985
3986 MagickStatusType
3987 status;
3988
3989 /*
3990 Set defaults.
3991 */
3992 assert(image_info != (ImageInfo *) NULL);
3993 assert(image_info->signature == MagickSignature);
3994 if (image_info->debug != MagickFalse)
3995 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3996 assert(exception != (ExceptionInfo *) NULL);
3997 if (argc == 2)
3998 {
3999 option=argv[1];
4000 if ((LocaleCompare("version",option+1) == 0) ||
4001 (LocaleCompare("-version",option+1) == 0))
4002 {
4003 (void) fprintf(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +00004004 GetMagickVersion((size_t *) NULL));
cristy610b2e22009-10-22 14:59:43 +00004005 (void) fprintf(stdout,"Copyright: %s\n",GetMagickCopyright());
4006 (void) fprintf(stdout,"Features: %s\n\n",GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00004007 return(MagickFalse);
4008 }
4009 }
4010 if (argc < 2)
cristy13e61a12010-02-04 20:19:00 +00004011 return(MogrifyUsage());
cristy3ed852e2009-09-05 21:47:34 +00004012 format=(char *) NULL;
4013 path=(char *) NULL;
4014 global_colormap=MagickFalse;
4015 k=0;
4016 j=1;
4017 NewImageStack();
4018 option=(char *) NULL;
4019 pend=MagickFalse;
4020 status=MagickTrue;
4021 /*
4022 Parse command line.
4023 */
4024 ReadCommandlLine(argc,&argv);
4025 status=ExpandFilenames(&argc,&argv);
4026 if (status == MagickFalse)
4027 ThrowMogrifyException(ResourceLimitError,"MemoryAllocationFailed",
4028 GetExceptionMessage(errno));
cristybb503372010-05-27 20:51:26 +00004029 for (i=1; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00004030 {
4031 option=argv[i];
4032 if (LocaleCompare(option,"(") == 0)
4033 {
4034 FireImageStack(MagickFalse,MagickTrue,pend);
4035 if (k == MaxImageStackDepth)
4036 ThrowMogrifyException(OptionError,"ParenthesisNestedTooDeeply",
4037 option);
4038 PushImageStack();
4039 continue;
4040 }
4041 if (LocaleCompare(option,")") == 0)
4042 {
4043 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
4044 if (k == 0)
4045 ThrowMogrifyException(OptionError,"UnableToParseExpression",option);
4046 PopImageStack();
4047 continue;
4048 }
4049 if (IsMagickOption(option) == MagickFalse)
4050 {
4051 char
4052 backup_filename[MaxTextExtent],
4053 *filename;
4054
4055 Image
4056 *images;
4057
4058 /*
4059 Option is a file name: begin by reading image from specified file.
4060 */
4061 FireImageStack(MagickFalse,MagickFalse,pend);
4062 filename=argv[i];
cristycee97112010-05-28 00:44:52 +00004063 if ((LocaleCompare(filename,"--") == 0) && (i < (ssize_t) (argc-1)))
cristy3ed852e2009-09-05 21:47:34 +00004064 filename=argv[++i];
4065 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
4066 images=ReadImages(image_info,exception);
4067 status&=(images != (Image *) NULL) &&
4068 (exception->severity < ErrorException);
4069 if (images == (Image *) NULL)
4070 continue;
cristydaa76602010-06-30 13:05:11 +00004071 if (format != (char *) NULL)
4072 (void) CopyMagickString(images->filename,images->magick_filename,
4073 MaxTextExtent);
cristy3ed852e2009-09-05 21:47:34 +00004074 if (path != (char *) NULL)
4075 {
4076 GetPathComponent(option,TailPath,filename);
4077 (void) FormatMagickString(images->filename,MaxTextExtent,"%s%c%s",
4078 path,*DirectorySeparator,filename);
4079 }
4080 if (format != (char *) NULL)
cristydaa76602010-06-30 13:05:11 +00004081 AppendImageFormat(format,images->filename);
cristy3ed852e2009-09-05 21:47:34 +00004082 AppendImageStack(images);
4083 FinalizeImageSettings(image_info,image,MagickFalse);
4084 if (global_colormap != MagickFalse)
4085 {
4086 QuantizeInfo
4087 *quantize_info;
4088
4089 quantize_info=AcquireQuantizeInfo(image_info);
4090 (void) RemapImages(quantize_info,images,(Image *) NULL);
4091 quantize_info=DestroyQuantizeInfo(quantize_info);
4092 }
4093 *backup_filename='\0';
4094 if ((LocaleCompare(image->filename,"-") != 0) &&
4095 (IsPathWritable(image->filename) != MagickFalse))
4096 {
cristybb503372010-05-27 20:51:26 +00004097 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004098 i;
4099
4100 /*
4101 Rename image file as backup.
4102 */
4103 (void) CopyMagickString(backup_filename,image->filename,
4104 MaxTextExtent);
4105 for (i=0; i < 6; i++)
4106 {
4107 (void) ConcatenateMagickString(backup_filename,"~",MaxTextExtent);
4108 if (IsPathAccessible(backup_filename) == MagickFalse)
4109 break;
4110 }
4111 if ((IsPathAccessible(backup_filename) != MagickFalse) ||
4112 (rename(image->filename,backup_filename) != 0))
4113 *backup_filename='\0';
4114 }
4115 /*
4116 Write transmogrified image to disk.
4117 */
4118 image_info->synchronize=MagickTrue;
4119 status&=WriteImages(image_info,image,image->filename,exception);
4120 if ((status == MagickFalse) && (*backup_filename != '\0'))
4121 (void) remove(backup_filename);
4122 RemoveAllImageStack();
4123 continue;
4124 }
4125 pend=image != (Image *) NULL ? MagickTrue : MagickFalse;
4126 switch (*(option+1))
4127 {
4128 case 'a':
4129 {
4130 if (LocaleCompare("adaptive-blur",option+1) == 0)
4131 {
4132 i++;
cristybb503372010-05-27 20:51:26 +00004133 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004134 ThrowMogrifyException(OptionError,"MissingArgument",option);
4135 if (IsGeometry(argv[i]) == MagickFalse)
4136 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4137 break;
4138 }
4139 if (LocaleCompare("adaptive-resize",option+1) == 0)
4140 {
4141 i++;
cristybb503372010-05-27 20:51:26 +00004142 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004143 ThrowMogrifyException(OptionError,"MissingArgument",option);
4144 if (IsGeometry(argv[i]) == MagickFalse)
4145 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4146 break;
4147 }
4148 if (LocaleCompare("adaptive-sharpen",option+1) == 0)
4149 {
4150 i++;
cristybb503372010-05-27 20:51:26 +00004151 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004152 ThrowMogrifyException(OptionError,"MissingArgument",option);
4153 if (IsGeometry(argv[i]) == MagickFalse)
4154 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4155 break;
4156 }
4157 if (LocaleCompare("affine",option+1) == 0)
4158 {
4159 if (*option == '+')
4160 break;
4161 i++;
cristybb503372010-05-27 20:51:26 +00004162 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004163 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy3ed852e2009-09-05 21:47:34 +00004164 break;
4165 }
4166 if (LocaleCompare("alpha",option+1) == 0)
4167 {
cristybb503372010-05-27 20:51:26 +00004168 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004169 type;
4170
4171 if (*option == '+')
4172 break;
4173 i++;
cristybb503372010-05-27 20:51:26 +00004174 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004175 ThrowMogrifyException(OptionError,"MissingArgument",option);
4176 type=ParseMagickOption(MagickAlphaOptions,MagickFalse,argv[i]);
4177 if (type < 0)
4178 ThrowMogrifyException(OptionError,"UnrecognizedAlphaChannelType",
4179 argv[i]);
4180 break;
4181 }
4182 if (LocaleCompare("annotate",option+1) == 0)
4183 {
4184 if (*option == '+')
4185 break;
4186 i++;
cristybb503372010-05-27 20:51:26 +00004187 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004188 ThrowMogrifyException(OptionError,"MissingArgument",option);
4189 if (IsGeometry(argv[i]) == MagickFalse)
4190 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristybb503372010-05-27 20:51:26 +00004191 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004192 ThrowMogrifyException(OptionError,"MissingArgument",option);
4193 i++;
4194 break;
4195 }
4196 if (LocaleCompare("antialias",option+1) == 0)
4197 break;
4198 if (LocaleCompare("append",option+1) == 0)
4199 break;
4200 if (LocaleCompare("attenuate",option+1) == 0)
4201 {
4202 if (*option == '+')
4203 break;
4204 i++;
cristybb503372010-05-27 20:51:26 +00004205 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004206 ThrowMogrifyException(OptionError,"MissingArgument",option);
4207 if (IsGeometry(argv[i]) == MagickFalse)
4208 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4209 break;
4210 }
4211 if (LocaleCompare("authenticate",option+1) == 0)
4212 {
4213 if (*option == '+')
4214 break;
4215 i++;
cristybb503372010-05-27 20:51:26 +00004216 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004217 ThrowMogrifyException(OptionError,"MissingArgument",option);
4218 break;
4219 }
4220 if (LocaleCompare("auto-gamma",option+1) == 0)
4221 break;
4222 if (LocaleCompare("auto-level",option+1) == 0)
4223 break;
4224 if (LocaleCompare("auto-orient",option+1) == 0)
4225 break;
4226 if (LocaleCompare("average",option+1) == 0)
4227 break;
4228 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4229 }
4230 case 'b':
4231 {
4232 if (LocaleCompare("background",option+1) == 0)
4233 {
4234 if (*option == '+')
4235 break;
4236 i++;
cristybb503372010-05-27 20:51:26 +00004237 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004238 ThrowMogrifyException(OptionError,"MissingArgument",option);
4239 break;
4240 }
4241 if (LocaleCompare("bias",option+1) == 0)
4242 {
4243 if (*option == '+')
4244 break;
4245 i++;
cristybb503372010-05-27 20:51:26 +00004246 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004247 ThrowMogrifyException(OptionError,"MissingArgument",option);
4248 if (IsGeometry(argv[i]) == MagickFalse)
4249 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4250 break;
4251 }
4252 if (LocaleCompare("black-point-compensation",option+1) == 0)
4253 break;
4254 if (LocaleCompare("black-threshold",option+1) == 0)
4255 {
4256 if (*option == '+')
4257 break;
4258 i++;
cristybb503372010-05-27 20:51:26 +00004259 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004260 ThrowMogrifyException(OptionError,"MissingArgument",option);
4261 if (IsGeometry(argv[i]) == MagickFalse)
4262 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4263 break;
4264 }
4265 if (LocaleCompare("blue-primary",option+1) == 0)
4266 {
4267 if (*option == '+')
4268 break;
4269 i++;
cristybb503372010-05-27 20:51:26 +00004270 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004271 ThrowMogrifyException(OptionError,"MissingArgument",option);
4272 if (IsGeometry(argv[i]) == MagickFalse)
4273 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4274 break;
4275 }
4276 if (LocaleCompare("blue-shift",option+1) == 0)
4277 {
4278 i++;
cristybb503372010-05-27 20:51:26 +00004279 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004280 ThrowMogrifyException(OptionError,"MissingArgument",option);
4281 if (IsGeometry(argv[i]) == MagickFalse)
4282 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4283 break;
4284 }
4285 if (LocaleCompare("blur",option+1) == 0)
4286 {
4287 i++;
cristybb503372010-05-27 20:51:26 +00004288 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004289 ThrowMogrifyException(OptionError,"MissingArgument",option);
4290 if (IsGeometry(argv[i]) == MagickFalse)
4291 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4292 break;
4293 }
4294 if (LocaleCompare("border",option+1) == 0)
4295 {
4296 if (*option == '+')
4297 break;
4298 i++;
cristybb503372010-05-27 20:51:26 +00004299 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004300 ThrowMogrifyException(OptionError,"MissingArgument",option);
4301 if (IsGeometry(argv[i]) == MagickFalse)
4302 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4303 break;
4304 }
4305 if (LocaleCompare("bordercolor",option+1) == 0)
4306 {
4307 if (*option == '+')
4308 break;
4309 i++;
cristybb503372010-05-27 20:51:26 +00004310 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004311 ThrowMogrifyException(OptionError,"MissingArgument",option);
4312 break;
4313 }
4314 if (LocaleCompare("box",option+1) == 0)
4315 {
4316 if (*option == '+')
4317 break;
4318 i++;
cristybb503372010-05-27 20:51:26 +00004319 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004320 ThrowMogrifyException(OptionError,"MissingArgument",option);
4321 break;
4322 }
cristya28d6b82010-01-11 20:03:47 +00004323 if (LocaleCompare("brightness-contrast",option+1) == 0)
4324 {
4325 i++;
cristybb503372010-05-27 20:51:26 +00004326 if (i == (ssize_t) argc)
cristya28d6b82010-01-11 20:03:47 +00004327 ThrowMogrifyException(OptionError,"MissingArgument",option);
4328 if (IsGeometry(argv[i]) == MagickFalse)
4329 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4330 break;
4331 }
cristy3ed852e2009-09-05 21:47:34 +00004332 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4333 }
4334 case 'c':
4335 {
4336 if (LocaleCompare("cache",option+1) == 0)
4337 {
4338 if (*option == '+')
4339 break;
4340 i++;
cristybb503372010-05-27 20:51:26 +00004341 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004342 ThrowMogrifyException(OptionError,"MissingArgument",option);
4343 if (IsGeometry(argv[i]) == MagickFalse)
4344 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4345 break;
4346 }
4347 if (LocaleCompare("caption",option+1) == 0)
4348 {
4349 if (*option == '+')
4350 break;
4351 i++;
cristybb503372010-05-27 20:51:26 +00004352 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004353 ThrowMogrifyException(OptionError,"MissingArgument",option);
4354 break;
4355 }
4356 if (LocaleCompare("channel",option+1) == 0)
4357 {
cristybb503372010-05-27 20:51:26 +00004358 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004359 channel;
4360
4361 if (*option == '+')
4362 break;
4363 i++;
cristybb503372010-05-27 20:51:26 +00004364 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004365 ThrowMogrifyException(OptionError,"MissingArgument",option);
4366 channel=ParseChannelOption(argv[i]);
4367 if (channel < 0)
4368 ThrowMogrifyException(OptionError,"UnrecognizedChannelType",
4369 argv[i]);
4370 break;
4371 }
4372 if (LocaleCompare("cdl",option+1) == 0)
4373 {
4374 if (*option == '+')
4375 break;
4376 i++;
cristybb503372010-05-27 20:51:26 +00004377 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004378 ThrowMogrifyException(OptionError,"MissingArgument",option);
4379 break;
4380 }
4381 if (LocaleCompare("charcoal",option+1) == 0)
4382 {
4383 if (*option == '+')
4384 break;
4385 i++;
cristybb503372010-05-27 20:51:26 +00004386 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004387 ThrowMogrifyException(OptionError,"MissingArgument",option);
4388 if (IsGeometry(argv[i]) == MagickFalse)
4389 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4390 break;
4391 }
4392 if (LocaleCompare("chop",option+1) == 0)
4393 {
4394 if (*option == '+')
4395 break;
4396 i++;
cristybb503372010-05-27 20:51:26 +00004397 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004398 ThrowMogrifyException(OptionError,"MissingArgument",option);
4399 if (IsGeometry(argv[i]) == MagickFalse)
4400 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4401 break;
4402 }
cristy1eb45dd2009-09-25 16:38:06 +00004403 if (LocaleCompare("clamp",option+1) == 0)
4404 break;
4405 if (LocaleCompare("clip",option+1) == 0)
4406 break;
cristy3ed852e2009-09-05 21:47:34 +00004407 if (LocaleCompare("clip-mask",option+1) == 0)
4408 {
4409 if (*option == '+')
4410 break;
4411 i++;
cristybb503372010-05-27 20:51:26 +00004412 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004413 ThrowMogrifyException(OptionError,"MissingArgument",option);
4414 break;
4415 }
4416 if (LocaleCompare("clut",option+1) == 0)
4417 break;
4418 if (LocaleCompare("coalesce",option+1) == 0)
4419 break;
4420 if (LocaleCompare("colorize",option+1) == 0)
4421 {
4422 if (*option == '+')
4423 break;
4424 i++;
cristybb503372010-05-27 20:51:26 +00004425 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004426 ThrowMogrifyException(OptionError,"MissingArgument",option);
4427 if (IsGeometry(argv[i]) == MagickFalse)
4428 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4429 break;
4430 }
cristye6365592010-04-02 17:31:23 +00004431 if (LocaleCompare("color-matrix",option+1) == 0)
4432 {
cristyb6bd4ad2010-08-08 01:12:27 +00004433 KernelInfo
4434 *kernel_info;
4435
cristye6365592010-04-02 17:31:23 +00004436 if (*option == '+')
4437 break;
4438 i++;
cristybb503372010-05-27 20:51:26 +00004439 if (i == (ssize_t) (argc-1))
cristye6365592010-04-02 17:31:23 +00004440 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00004441 kernel_info=AcquireKernelInfo(argv[i]);
4442 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00004443 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00004444 kernel_info=DestroyKernelInfo(kernel_info);
cristye6365592010-04-02 17:31:23 +00004445 break;
4446 }
cristy3ed852e2009-09-05 21:47:34 +00004447 if (LocaleCompare("colors",option+1) == 0)
4448 {
4449 if (*option == '+')
4450 break;
4451 i++;
cristybb503372010-05-27 20:51:26 +00004452 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004453 ThrowMogrifyException(OptionError,"MissingArgument",option);
4454 if (IsGeometry(argv[i]) == MagickFalse)
4455 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4456 break;
4457 }
4458 if (LocaleCompare("colorspace",option+1) == 0)
4459 {
cristybb503372010-05-27 20:51:26 +00004460 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004461 colorspace;
4462
4463 if (*option == '+')
4464 break;
4465 i++;
cristybb503372010-05-27 20:51:26 +00004466 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004467 ThrowMogrifyException(OptionError,"MissingArgument",option);
4468 colorspace=ParseMagickOption(MagickColorspaceOptions,MagickFalse,
4469 argv[i]);
4470 if (colorspace < 0)
4471 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
4472 argv[i]);
4473 break;
4474 }
4475 if (LocaleCompare("combine",option+1) == 0)
4476 break;
4477 if (LocaleCompare("comment",option+1) == 0)
4478 {
4479 if (*option == '+')
4480 break;
4481 i++;
cristybb503372010-05-27 20:51:26 +00004482 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004483 ThrowMogrifyException(OptionError,"MissingArgument",option);
4484 break;
4485 }
4486 if (LocaleCompare("composite",option+1) == 0)
4487 break;
4488 if (LocaleCompare("compress",option+1) == 0)
4489 {
cristybb503372010-05-27 20:51:26 +00004490 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004491 compress;
4492
4493 if (*option == '+')
4494 break;
4495 i++;
cristybb503372010-05-27 20:51:26 +00004496 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004497 ThrowMogrifyException(OptionError,"MissingArgument",option);
4498 compress=ParseMagickOption(MagickCompressOptions,MagickFalse,
4499 argv[i]);
4500 if (compress < 0)
4501 ThrowMogrifyException(OptionError,"UnrecognizedImageCompression",
4502 argv[i]);
4503 break;
4504 }
cristy22879752009-10-25 23:55:40 +00004505 if (LocaleCompare("concurrent",option+1) == 0)
4506 break;
cristy3ed852e2009-09-05 21:47:34 +00004507 if (LocaleCompare("contrast",option+1) == 0)
4508 break;
4509 if (LocaleCompare("contrast-stretch",option+1) == 0)
4510 {
4511 i++;
cristybb503372010-05-27 20:51:26 +00004512 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004513 ThrowMogrifyException(OptionError,"MissingArgument",option);
4514 if (IsGeometry(argv[i]) == MagickFalse)
4515 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4516 break;
4517 }
4518 if (LocaleCompare("convolve",option+1) == 0)
4519 {
cristyb6bd4ad2010-08-08 01:12:27 +00004520 KernelInfo
4521 *kernel_info;
4522
cristy3ed852e2009-09-05 21:47:34 +00004523 if (*option == '+')
4524 break;
4525 i++;
cristybb503372010-05-27 20:51:26 +00004526 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004527 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00004528 kernel_info=AcquireKernelInfo(argv[i]);
4529 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00004530 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00004531 kernel_info=DestroyKernelInfo(kernel_info);
cristy3ed852e2009-09-05 21:47:34 +00004532 break;
4533 }
4534 if (LocaleCompare("crop",option+1) == 0)
4535 {
4536 if (*option == '+')
4537 break;
4538 i++;
cristybb503372010-05-27 20:51:26 +00004539 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004540 ThrowMogrifyException(OptionError,"MissingArgument",option);
4541 if (IsGeometry(argv[i]) == MagickFalse)
4542 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4543 break;
4544 }
4545 if (LocaleCompare("cycle",option+1) == 0)
4546 {
4547 if (*option == '+')
4548 break;
4549 i++;
cristybb503372010-05-27 20:51:26 +00004550 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004551 ThrowMogrifyException(OptionError,"MissingArgument",option);
4552 if (IsGeometry(argv[i]) == MagickFalse)
4553 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4554 break;
4555 }
4556 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4557 }
4558 case 'd':
4559 {
4560 if (LocaleCompare("decipher",option+1) == 0)
4561 {
4562 if (*option == '+')
4563 break;
4564 i++;
cristybb503372010-05-27 20:51:26 +00004565 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004566 ThrowMogrifyException(OptionError,"MissingArgument",option);
4567 break;
4568 }
4569 if (LocaleCompare("deconstruct",option+1) == 0)
4570 break;
4571 if (LocaleCompare("debug",option+1) == 0)
4572 {
cristybb503372010-05-27 20:51:26 +00004573 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004574 event;
4575
4576 if (*option == '+')
4577 break;
4578 i++;
cristybb503372010-05-27 20:51:26 +00004579 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004580 ThrowMogrifyException(OptionError,"MissingArgument",option);
4581 event=ParseMagickOption(MagickLogEventOptions,MagickFalse,argv[i]);
4582 if (event < 0)
4583 ThrowMogrifyException(OptionError,"UnrecognizedEventType",
4584 argv[i]);
4585 (void) SetLogEventMask(argv[i]);
4586 break;
4587 }
4588 if (LocaleCompare("define",option+1) == 0)
4589 {
4590 i++;
cristybb503372010-05-27 20:51:26 +00004591 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004592 ThrowMogrifyException(OptionError,"MissingArgument",option);
4593 if (*option == '+')
4594 {
4595 const char
4596 *define;
4597
4598 define=GetImageOption(image_info,argv[i]);
4599 if (define == (const char *) NULL)
4600 ThrowMogrifyException(OptionError,"NoSuchOption",argv[i]);
4601 break;
4602 }
4603 break;
4604 }
4605 if (LocaleCompare("delay",option+1) == 0)
4606 {
4607 if (*option == '+')
4608 break;
4609 i++;
cristybb503372010-05-27 20:51:26 +00004610 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004611 ThrowMogrifyException(OptionError,"MissingArgument",option);
4612 if (IsGeometry(argv[i]) == MagickFalse)
4613 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4614 break;
4615 }
4616 if (LocaleCompare("density",option+1) == 0)
4617 {
4618 if (*option == '+')
4619 break;
4620 i++;
cristybb503372010-05-27 20:51:26 +00004621 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004622 ThrowMogrifyException(OptionError,"MissingArgument",option);
4623 if (IsGeometry(argv[i]) == MagickFalse)
4624 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4625 break;
4626 }
4627 if (LocaleCompare("depth",option+1) == 0)
4628 {
4629 if (*option == '+')
4630 break;
4631 i++;
cristybb503372010-05-27 20:51:26 +00004632 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004633 ThrowMogrifyException(OptionError,"MissingArgument",option);
4634 if (IsGeometry(argv[i]) == MagickFalse)
4635 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4636 break;
4637 }
4638 if (LocaleCompare("deskew",option+1) == 0)
4639 {
4640 if (*option == '+')
4641 break;
4642 i++;
cristybb503372010-05-27 20:51:26 +00004643 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004644 ThrowMogrifyException(OptionError,"MissingArgument",option);
4645 if (IsGeometry(argv[i]) == MagickFalse)
4646 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4647 break;
4648 }
4649 if (LocaleCompare("despeckle",option+1) == 0)
4650 break;
4651 if (LocaleCompare("dft",option+1) == 0)
4652 break;
cristyc9b12952010-03-28 01:12:28 +00004653 if (LocaleCompare("direction",option+1) == 0)
4654 {
cristybb503372010-05-27 20:51:26 +00004655 ssize_t
cristyc9b12952010-03-28 01:12:28 +00004656 direction;
4657
4658 if (*option == '+')
4659 break;
4660 i++;
cristybb503372010-05-27 20:51:26 +00004661 if (i == (ssize_t) argc)
cristyc9b12952010-03-28 01:12:28 +00004662 ThrowMogrifyException(OptionError,"MissingArgument",option);
4663 direction=ParseMagickOption(MagickDirectionOptions,MagickFalse,
4664 argv[i]);
4665 if (direction < 0)
4666 ThrowMogrifyException(OptionError,"UnrecognizedDirectionType",
4667 argv[i]);
4668 break;
4669 }
cristy3ed852e2009-09-05 21:47:34 +00004670 if (LocaleCompare("display",option+1) == 0)
4671 {
4672 if (*option == '+')
4673 break;
4674 i++;
cristybb503372010-05-27 20:51:26 +00004675 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004676 ThrowMogrifyException(OptionError,"MissingArgument",option);
4677 break;
4678 }
4679 if (LocaleCompare("dispose",option+1) == 0)
4680 {
cristybb503372010-05-27 20:51:26 +00004681 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004682 dispose;
4683
4684 if (*option == '+')
4685 break;
4686 i++;
cristybb503372010-05-27 20:51:26 +00004687 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004688 ThrowMogrifyException(OptionError,"MissingArgument",option);
4689 dispose=ParseMagickOption(MagickDisposeOptions,MagickFalse,argv[i]);
4690 if (dispose < 0)
4691 ThrowMogrifyException(OptionError,"UnrecognizedDisposeMethod",
4692 argv[i]);
4693 break;
4694 }
4695 if (LocaleCompare("distort",option+1) == 0)
4696 {
cristybb503372010-05-27 20:51:26 +00004697 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004698 op;
4699
4700 i++;
cristybb503372010-05-27 20:51:26 +00004701 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004702 ThrowMogrifyException(OptionError,"MissingArgument",option);
4703 op=ParseMagickOption(MagickDistortOptions,MagickFalse,argv[i]);
4704 if (op < 0)
4705 ThrowMogrifyException(OptionError,"UnrecognizedDistortMethod",
4706 argv[i]);
4707 i++;
cristybb503372010-05-27 20:51:26 +00004708 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004709 ThrowMogrifyException(OptionError,"MissingArgument",option);
4710 break;
4711 }
4712 if (LocaleCompare("dither",option+1) == 0)
4713 {
cristybb503372010-05-27 20:51:26 +00004714 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004715 method;
4716
4717 if (*option == '+')
4718 break;
4719 i++;
cristybb503372010-05-27 20:51:26 +00004720 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004721 ThrowMogrifyException(OptionError,"MissingArgument",option);
4722 method=ParseMagickOption(MagickDitherOptions,MagickFalse,argv[i]);
4723 if (method < 0)
4724 ThrowMogrifyException(OptionError,"UnrecognizedDitherMethod",
4725 argv[i]);
4726 break;
4727 }
4728 if (LocaleCompare("draw",option+1) == 0)
4729 {
4730 if (*option == '+')
4731 break;
4732 i++;
cristybb503372010-05-27 20:51:26 +00004733 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004734 ThrowMogrifyException(OptionError,"MissingArgument",option);
4735 break;
4736 }
cristy22879752009-10-25 23:55:40 +00004737 if (LocaleCompare("duration",option+1) == 0)
4738 {
4739 if (*option == '+')
4740 break;
4741 i++;
cristybb503372010-05-27 20:51:26 +00004742 if (i == (ssize_t) (argc-1))
cristy22879752009-10-25 23:55:40 +00004743 ThrowMogrifyException(OptionError,"MissingArgument",option);
4744 if (IsGeometry(argv[i]) == MagickFalse)
4745 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4746 break;
4747 }
cristy3ed852e2009-09-05 21:47:34 +00004748 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4749 }
4750 case 'e':
4751 {
4752 if (LocaleCompare("edge",option+1) == 0)
4753 {
4754 if (*option == '+')
4755 break;
4756 i++;
cristybb503372010-05-27 20:51:26 +00004757 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004758 ThrowMogrifyException(OptionError,"MissingArgument",option);
4759 if (IsGeometry(argv[i]) == MagickFalse)
4760 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4761 break;
4762 }
4763 if (LocaleCompare("emboss",option+1) == 0)
4764 {
4765 if (*option == '+')
4766 break;
4767 i++;
cristybb503372010-05-27 20:51:26 +00004768 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004769 ThrowMogrifyException(OptionError,"MissingArgument",option);
4770 if (IsGeometry(argv[i]) == MagickFalse)
4771 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4772 break;
4773 }
4774 if (LocaleCompare("encipher",option+1) == 0)
4775 {
4776 if (*option == '+')
4777 break;
4778 i++;
cristybb503372010-05-27 20:51:26 +00004779 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004780 ThrowMogrifyException(OptionError,"MissingArgument",option);
4781 break;
4782 }
4783 if (LocaleCompare("encoding",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("endian",option+1) == 0)
4793 {
cristybb503372010-05-27 20:51:26 +00004794 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004795 endian;
4796
4797 if (*option == '+')
4798 break;
4799 i++;
cristybb503372010-05-27 20:51:26 +00004800 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004801 ThrowMogrifyException(OptionError,"MissingArgument",option);
4802 endian=ParseMagickOption(MagickEndianOptions,MagickFalse,argv[i]);
4803 if (endian < 0)
4804 ThrowMogrifyException(OptionError,"UnrecognizedEndianType",
4805 argv[i]);
4806 break;
4807 }
4808 if (LocaleCompare("enhance",option+1) == 0)
4809 break;
4810 if (LocaleCompare("equalize",option+1) == 0)
4811 break;
4812 if (LocaleCompare("evaluate",option+1) == 0)
4813 {
cristybb503372010-05-27 20:51:26 +00004814 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004815 op;
4816
4817 if (*option == '+')
4818 break;
4819 i++;
cristybb503372010-05-27 20:51:26 +00004820 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004821 ThrowMogrifyException(OptionError,"MissingArgument",option);
4822 op=ParseMagickOption(MagickEvaluateOptions,MagickFalse,argv[i]);
4823 if (op < 0)
4824 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4825 argv[i]);
4826 i++;
cristybb503372010-05-27 20:51:26 +00004827 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004828 ThrowMogrifyException(OptionError,"MissingArgument",option);
4829 if (IsGeometry(argv[i]) == MagickFalse)
4830 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4831 break;
4832 }
cristyd18ae7c2010-03-07 17:39:52 +00004833 if (LocaleCompare("evaluate-sequence",option+1) == 0)
4834 {
cristybb503372010-05-27 20:51:26 +00004835 ssize_t
cristyd18ae7c2010-03-07 17:39:52 +00004836 op;
4837
4838 if (*option == '+')
4839 break;
4840 i++;
cristybb503372010-05-27 20:51:26 +00004841 if (i == (ssize_t) argc)
cristyd18ae7c2010-03-07 17:39:52 +00004842 ThrowMogrifyException(OptionError,"MissingArgument",option);
4843 op=ParseMagickOption(MagickEvaluateOptions,MagickFalse,argv[i]);
4844 if (op < 0)
4845 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4846 argv[i]);
4847 break;
4848 }
cristy3ed852e2009-09-05 21:47:34 +00004849 if (LocaleCompare("extent",option+1) == 0)
4850 {
4851 if (*option == '+')
4852 break;
4853 i++;
cristybb503372010-05-27 20:51:26 +00004854 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004855 ThrowMogrifyException(OptionError,"MissingArgument",option);
4856 if (IsGeometry(argv[i]) == MagickFalse)
4857 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4858 break;
4859 }
4860 if (LocaleCompare("extract",option+1) == 0)
4861 {
4862 if (*option == '+')
4863 break;
4864 i++;
cristybb503372010-05-27 20:51:26 +00004865 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004866 ThrowMogrifyException(OptionError,"MissingArgument",option);
4867 if (IsGeometry(argv[i]) == MagickFalse)
4868 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4869 break;
4870 }
4871 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4872 }
4873 case 'f':
4874 {
4875 if (LocaleCompare("family",option+1) == 0)
4876 {
4877 if (*option == '+')
4878 break;
4879 i++;
cristybb503372010-05-27 20:51:26 +00004880 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004881 ThrowMogrifyException(OptionError,"MissingArgument",option);
4882 break;
4883 }
4884 if (LocaleCompare("fill",option+1) == 0)
4885 {
4886 if (*option == '+')
4887 break;
4888 i++;
cristybb503372010-05-27 20:51:26 +00004889 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004890 ThrowMogrifyException(OptionError,"MissingArgument",option);
4891 break;
4892 }
4893 if (LocaleCompare("filter",option+1) == 0)
4894 {
cristybb503372010-05-27 20:51:26 +00004895 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004896 filter;
4897
4898 if (*option == '+')
4899 break;
4900 i++;
cristybb503372010-05-27 20:51:26 +00004901 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004902 ThrowMogrifyException(OptionError,"MissingArgument",option);
4903 filter=ParseMagickOption(MagickFilterOptions,MagickFalse,argv[i]);
4904 if (filter < 0)
4905 ThrowMogrifyException(OptionError,"UnrecognizedImageFilter",
4906 argv[i]);
4907 break;
4908 }
4909 if (LocaleCompare("flatten",option+1) == 0)
4910 break;
4911 if (LocaleCompare("flip",option+1) == 0)
4912 break;
4913 if (LocaleCompare("flop",option+1) == 0)
4914 break;
4915 if (LocaleCompare("floodfill",option+1) == 0)
4916 {
4917 if (*option == '+')
4918 break;
4919 i++;
cristybb503372010-05-27 20:51:26 +00004920 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004921 ThrowMogrifyException(OptionError,"MissingArgument",option);
4922 if (IsGeometry(argv[i]) == MagickFalse)
4923 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4924 i++;
cristybb503372010-05-27 20:51:26 +00004925 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004926 ThrowMogrifyException(OptionError,"MissingArgument",option);
4927 break;
4928 }
4929 if (LocaleCompare("font",option+1) == 0)
4930 {
4931 if (*option == '+')
4932 break;
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("format",option+1) == 0)
4939 {
4940 (void) CopyMagickString(argv[i]+1,"sans",MaxTextExtent);
4941 (void) CloneString(&format,(char *) NULL);
4942 if (*option == '+')
4943 break;
4944 i++;
cristybb503372010-05-27 20:51:26 +00004945 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004946 ThrowMogrifyException(OptionError,"MissingArgument",option);
4947 (void) CloneString(&format,argv[i]);
4948 (void) CopyMagickString(image_info->filename,format,MaxTextExtent);
4949 (void) ConcatenateMagickString(image_info->filename,":",
4950 MaxTextExtent);
cristyd965a422010-03-03 17:47:35 +00004951 (void) SetImageInfo(image_info,0,exception);
cristy3ed852e2009-09-05 21:47:34 +00004952 if (*image_info->magick == '\0')
4953 ThrowMogrifyException(OptionError,"UnrecognizedImageFormat",
4954 format);
4955 break;
4956 }
4957 if (LocaleCompare("frame",option+1) == 0)
4958 {
4959 if (*option == '+')
4960 break;
4961 i++;
cristybb503372010-05-27 20:51:26 +00004962 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004963 ThrowMogrifyException(OptionError,"MissingArgument",option);
4964 if (IsGeometry(argv[i]) == MagickFalse)
4965 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4966 break;
4967 }
4968 if (LocaleCompare("function",option+1) == 0)
4969 {
cristybb503372010-05-27 20:51:26 +00004970 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004971 op;
4972
4973 if (*option == '+')
4974 break;
4975 i++;
cristybb503372010-05-27 20:51:26 +00004976 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004977 ThrowMogrifyException(OptionError,"MissingArgument",option);
4978 op=ParseMagickOption(MagickFunctionOptions,MagickFalse,argv[i]);
4979 if (op < 0)
4980 ThrowMogrifyException(OptionError,"UnrecognizedFunction",argv[i]);
4981 i++;
cristybb503372010-05-27 20:51:26 +00004982 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004983 ThrowMogrifyException(OptionError,"MissingArgument",option);
4984 break;
4985 }
4986 if (LocaleCompare("fuzz",option+1) == 0)
4987 {
4988 if (*option == '+')
4989 break;
4990 i++;
cristybb503372010-05-27 20:51:26 +00004991 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004992 ThrowMogrifyException(OptionError,"MissingArgument",option);
4993 if (IsGeometry(argv[i]) == MagickFalse)
4994 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4995 break;
4996 }
4997 if (LocaleCompare("fx",option+1) == 0)
4998 {
4999 if (*option == '+')
5000 break;
5001 i++;
cristybb503372010-05-27 20:51:26 +00005002 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005003 ThrowMogrifyException(OptionError,"MissingArgument",option);
5004 break;
5005 }
5006 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5007 }
5008 case 'g':
5009 {
5010 if (LocaleCompare("gamma",option+1) == 0)
5011 {
5012 i++;
cristybb503372010-05-27 20:51:26 +00005013 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005014 ThrowMogrifyException(OptionError,"MissingArgument",option);
5015 if (IsGeometry(argv[i]) == MagickFalse)
5016 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5017 break;
5018 }
5019 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
5020 (LocaleCompare("gaussian",option+1) == 0))
5021 {
5022 i++;
cristybb503372010-05-27 20:51:26 +00005023 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005024 ThrowMogrifyException(OptionError,"MissingArgument",option);
5025 if (IsGeometry(argv[i]) == MagickFalse)
5026 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5027 break;
5028 }
5029 if (LocaleCompare("geometry",option+1) == 0)
5030 {
5031 if (*option == '+')
5032 break;
5033 i++;
cristybb503372010-05-27 20:51:26 +00005034 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005035 ThrowMogrifyException(OptionError,"MissingArgument",option);
5036 if (IsGeometry(argv[i]) == MagickFalse)
5037 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5038 break;
5039 }
5040 if (LocaleCompare("gravity",option+1) == 0)
5041 {
cristybb503372010-05-27 20:51:26 +00005042 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005043 gravity;
5044
5045 if (*option == '+')
5046 break;
5047 i++;
cristybb503372010-05-27 20:51:26 +00005048 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005049 ThrowMogrifyException(OptionError,"MissingArgument",option);
5050 gravity=ParseMagickOption(MagickGravityOptions,MagickFalse,argv[i]);
5051 if (gravity < 0)
5052 ThrowMogrifyException(OptionError,"UnrecognizedGravityType",
5053 argv[i]);
5054 break;
5055 }
5056 if (LocaleCompare("green-primary",option+1) == 0)
5057 {
5058 if (*option == '+')
5059 break;
5060 i++;
cristybb503372010-05-27 20:51:26 +00005061 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005062 ThrowMogrifyException(OptionError,"MissingArgument",option);
5063 if (IsGeometry(argv[i]) == MagickFalse)
5064 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5065 break;
5066 }
5067 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5068 }
5069 case 'h':
5070 {
5071 if (LocaleCompare("hald-clut",option+1) == 0)
5072 break;
5073 if ((LocaleCompare("help",option+1) == 0) ||
5074 (LocaleCompare("-help",option+1) == 0))
5075 return(MogrifyUsage());
5076 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5077 }
5078 case 'i':
5079 {
5080 if (LocaleCompare("identify",option+1) == 0)
5081 break;
5082 if (LocaleCompare("idft",option+1) == 0)
5083 break;
5084 if (LocaleCompare("implode",option+1) == 0)
5085 {
5086 if (*option == '+')
5087 break;
5088 i++;
cristybb503372010-05-27 20:51:26 +00005089 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005090 ThrowMogrifyException(OptionError,"MissingArgument",option);
5091 if (IsGeometry(argv[i]) == MagickFalse)
5092 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5093 break;
5094 }
5095 if (LocaleCompare("intent",option+1) == 0)
5096 {
cristybb503372010-05-27 20:51:26 +00005097 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005098 intent;
5099
5100 if (*option == '+')
5101 break;
5102 i++;
cristybb503372010-05-27 20:51:26 +00005103 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005104 ThrowMogrifyException(OptionError,"MissingArgument",option);
5105 intent=ParseMagickOption(MagickIntentOptions,MagickFalse,argv[i]);
5106 if (intent < 0)
5107 ThrowMogrifyException(OptionError,"UnrecognizedIntentType",
5108 argv[i]);
5109 break;
5110 }
5111 if (LocaleCompare("interlace",option+1) == 0)
5112 {
cristybb503372010-05-27 20:51:26 +00005113 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005114 interlace;
5115
5116 if (*option == '+')
5117 break;
5118 i++;
cristybb503372010-05-27 20:51:26 +00005119 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005120 ThrowMogrifyException(OptionError,"MissingArgument",option);
5121 interlace=ParseMagickOption(MagickInterlaceOptions,MagickFalse,
5122 argv[i]);
5123 if (interlace < 0)
5124 ThrowMogrifyException(OptionError,"UnrecognizedInterlaceType",
5125 argv[i]);
5126 break;
5127 }
cristyb32b90a2009-09-07 21:45:48 +00005128 if (LocaleCompare("interline-spacing",option+1) == 0)
5129 {
5130 if (*option == '+')
5131 break;
5132 i++;
cristybb503372010-05-27 20:51:26 +00005133 if (i == (ssize_t) (argc-1))
cristyb32b90a2009-09-07 21:45:48 +00005134 ThrowMogrifyException(OptionError,"MissingArgument",option);
5135 if (IsGeometry(argv[i]) == MagickFalse)
5136 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5137 break;
5138 }
cristy3ed852e2009-09-05 21:47:34 +00005139 if (LocaleCompare("interpolate",option+1) == 0)
5140 {
cristybb503372010-05-27 20:51:26 +00005141 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005142 interpolate;
5143
5144 if (*option == '+')
5145 break;
5146 i++;
cristybb503372010-05-27 20:51:26 +00005147 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005148 ThrowMogrifyException(OptionError,"MissingArgument",option);
5149 interpolate=ParseMagickOption(MagickInterpolateOptions,MagickFalse,
5150 argv[i]);
5151 if (interpolate < 0)
5152 ThrowMogrifyException(OptionError,"UnrecognizedInterpolateMethod",
5153 argv[i]);
5154 break;
5155 }
5156 if (LocaleCompare("interword-spacing",option+1) == 0)
5157 {
5158 if (*option == '+')
5159 break;
5160 i++;
cristybb503372010-05-27 20:51:26 +00005161 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005162 ThrowMogrifyException(OptionError,"MissingArgument",option);
5163 if (IsGeometry(argv[i]) == MagickFalse)
5164 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5165 break;
5166 }
5167 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5168 }
5169 case 'k':
5170 {
5171 if (LocaleCompare("kerning",option+1) == 0)
5172 {
5173 if (*option == '+')
5174 break;
5175 i++;
cristybb503372010-05-27 20:51:26 +00005176 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005177 ThrowMogrifyException(OptionError,"MissingArgument",option);
5178 if (IsGeometry(argv[i]) == MagickFalse)
5179 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5180 break;
5181 }
5182 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5183 }
5184 case 'l':
5185 {
5186 if (LocaleCompare("label",option+1) == 0)
5187 {
5188 if (*option == '+')
5189 break;
5190 i++;
cristybb503372010-05-27 20:51:26 +00005191 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005192 ThrowMogrifyException(OptionError,"MissingArgument",option);
5193 break;
5194 }
5195 if (LocaleCompare("lat",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 if (IsGeometry(argv[i]) == MagickFalse)
5203 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5204 }
5205 if (LocaleCompare("layers",option+1) == 0)
5206 {
cristybb503372010-05-27 20:51:26 +00005207 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005208 type;
5209
5210 if (*option == '+')
5211 break;
5212 i++;
cristybb503372010-05-27 20:51:26 +00005213 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005214 ThrowMogrifyException(OptionError,"MissingArgument",option);
5215 type=ParseMagickOption(MagickLayerOptions,MagickFalse,argv[i]);
5216 if (type < 0)
5217 ThrowMogrifyException(OptionError,"UnrecognizedLayerMethod",
5218 argv[i]);
5219 break;
5220 }
5221 if (LocaleCompare("level",option+1) == 0)
5222 {
5223 i++;
cristybb503372010-05-27 20:51:26 +00005224 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005225 ThrowMogrifyException(OptionError,"MissingArgument",option);
5226 if (IsGeometry(argv[i]) == MagickFalse)
5227 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5228 break;
5229 }
5230 if (LocaleCompare("level-colors",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 break;
5236 }
5237 if (LocaleCompare("linewidth",option+1) == 0)
5238 {
5239 if (*option == '+')
5240 break;
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 if (IsGeometry(argv[i]) == MagickFalse)
5245 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5246 break;
5247 }
5248 if (LocaleCompare("limit",option+1) == 0)
5249 {
5250 char
5251 *p;
5252
5253 double
5254 value;
5255
cristybb503372010-05-27 20:51:26 +00005256 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005257 resource;
5258
5259 if (*option == '+')
5260 break;
5261 i++;
cristybb503372010-05-27 20:51:26 +00005262 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005263 ThrowMogrifyException(OptionError,"MissingArgument",option);
5264 resource=ParseMagickOption(MagickResourceOptions,MagickFalse,
5265 argv[i]);
5266 if (resource < 0)
5267 ThrowMogrifyException(OptionError,"UnrecognizedResourceType",
5268 argv[i]);
5269 i++;
cristybb503372010-05-27 20:51:26 +00005270 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005271 ThrowMogrifyException(OptionError,"MissingArgument",option);
5272 value=strtod(argv[i],&p);
5273 if ((p == argv[i]) && (LocaleCompare("unlimited",argv[i]) != 0))
5274 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5275 break;
5276 }
5277 if (LocaleCompare("liquid-rescale",option+1) == 0)
5278 {
5279 i++;
cristybb503372010-05-27 20:51:26 +00005280 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005281 ThrowMogrifyException(OptionError,"MissingArgument",option);
5282 if (IsGeometry(argv[i]) == MagickFalse)
5283 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5284 break;
5285 }
5286 if (LocaleCompare("list",option+1) == 0)
5287 {
cristybb503372010-05-27 20:51:26 +00005288 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005289 list;
5290
5291 if (*option == '+')
5292 break;
5293 i++;
cristybb503372010-05-27 20:51:26 +00005294 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005295 ThrowMogrifyException(OptionError,"MissingArgument",option);
5296 list=ParseMagickOption(MagickListOptions,MagickFalse,argv[i]);
5297 if (list < 0)
5298 ThrowMogrifyException(OptionError,"UnrecognizedListType",argv[i]);
cristyaeb2cbc2010-05-07 13:28:58 +00005299 status=MogrifyImageInfo(image_info,(int) (i-j+1),(const char **)
cristy3ed852e2009-09-05 21:47:34 +00005300 argv+j,exception);
cristyaeb2cbc2010-05-07 13:28:58 +00005301 return(status != 0 ? MagickFalse : MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00005302 }
5303 if (LocaleCompare("log",option+1) == 0)
5304 {
5305 if (*option == '+')
5306 break;
5307 i++;
cristybb503372010-05-27 20:51:26 +00005308 if ((i == (ssize_t) argc) ||
cristy3ed852e2009-09-05 21:47:34 +00005309 (strchr(argv[i],'%') == (char *) NULL))
5310 ThrowMogrifyException(OptionError,"MissingArgument",option);
5311 break;
5312 }
5313 if (LocaleCompare("loop",option+1) == 0)
5314 {
5315 if (*option == '+')
5316 break;
5317 i++;
cristybb503372010-05-27 20:51:26 +00005318 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005319 ThrowMogrifyException(OptionError,"MissingArgument",option);
5320 if (IsGeometry(argv[i]) == MagickFalse)
5321 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5322 break;
5323 }
5324 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5325 }
5326 case 'm':
5327 {
5328 if (LocaleCompare("map",option+1) == 0)
5329 {
5330 global_colormap=(*option == '+') ? MagickTrue : MagickFalse;
5331 if (*option == '+')
5332 break;
5333 i++;
cristybb503372010-05-27 20:51:26 +00005334 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005335 ThrowMogrifyException(OptionError,"MissingArgument",option);
5336 break;
5337 }
5338 if (LocaleCompare("mask",option+1) == 0)
5339 {
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("matte",option+1) == 0)
5348 break;
5349 if (LocaleCompare("mattecolor",option+1) == 0)
5350 {
5351 if (*option == '+')
5352 break;
5353 i++;
cristybb503372010-05-27 20:51:26 +00005354 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005355 ThrowMogrifyException(OptionError,"MissingArgument",option);
5356 break;
5357 }
cristyf40785b2010-03-06 02:27:27 +00005358 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00005359 break;
cristyf40785b2010-03-06 02:27:27 +00005360 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00005361 break;
cristy3ed852e2009-09-05 21:47:34 +00005362 if (LocaleCompare("modulate",option+1) == 0)
5363 {
5364 if (*option == '+')
5365 break;
5366 i++;
cristybb503372010-05-27 20:51:26 +00005367 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005368 ThrowMogrifyException(OptionError,"MissingArgument",option);
5369 if (IsGeometry(argv[i]) == MagickFalse)
5370 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5371 break;
5372 }
5373 if (LocaleCompare("median",option+1) == 0)
5374 {
5375 if (*option == '+')
5376 break;
5377 i++;
cristybb503372010-05-27 20:51:26 +00005378 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005379 ThrowMogrifyException(OptionError,"MissingArgument",option);
5380 if (IsGeometry(argv[i]) == MagickFalse)
5381 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5382 break;
5383 }
5384 if (LocaleCompare("monitor",option+1) == 0)
5385 break;
5386 if (LocaleCompare("monochrome",option+1) == 0)
5387 break;
5388 if (LocaleCompare("morph",option+1) == 0)
5389 {
5390 if (*option == '+')
5391 break;
5392 i++;
cristybb503372010-05-27 20:51:26 +00005393 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005394 ThrowMogrifyException(OptionError,"MissingArgument",option);
5395 if (IsGeometry(argv[i]) == MagickFalse)
5396 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5397 break;
5398 }
anthony29188a82010-01-22 10:12:34 +00005399 if (LocaleCompare("morphology",option+1) == 0)
5400 {
anthony29188a82010-01-22 10:12:34 +00005401 char
5402 token[MaxTextExtent];
5403
cristyb6bd4ad2010-08-08 01:12:27 +00005404 KernelInfo
5405 *kernel_info;
5406
5407 ssize_t
5408 op;
5409
anthony29188a82010-01-22 10:12:34 +00005410 i++;
cristybb503372010-05-27 20:51:26 +00005411 if (i == (ssize_t) argc)
anthony29188a82010-01-22 10:12:34 +00005412 ThrowMogrifyException(OptionError,"MissingArgument",option);
5413 GetMagickToken(argv[i],NULL,token);
5414 op=ParseMagickOption(MagickMorphologyOptions,MagickFalse,token);
5415 if (op < 0)
5416 ThrowMogrifyException(OptionError,"UnrecognizedMorphologyMethod",
cristyf0c78232010-03-15 12:53:40 +00005417 token);
anthony29188a82010-01-22 10:12:34 +00005418 i++;
cristybb503372010-05-27 20:51:26 +00005419 if (i == (ssize_t) (argc-1))
anthony29188a82010-01-22 10:12:34 +00005420 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00005421 kernel_info=AcquireKernelInfo(argv[i]);
5422 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00005423 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00005424 kernel_info=DestroyKernelInfo(kernel_info);
anthony29188a82010-01-22 10:12:34 +00005425 break;
5426 }
cristy3ed852e2009-09-05 21:47:34 +00005427 if (LocaleCompare("mosaic",option+1) == 0)
5428 break;
5429 if (LocaleCompare("motion-blur",option+1) == 0)
5430 {
5431 if (*option == '+')
5432 break;
5433 i++;
cristybb503372010-05-27 20:51:26 +00005434 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005435 ThrowMogrifyException(OptionError,"MissingArgument",option);
5436 if (IsGeometry(argv[i]) == MagickFalse)
5437 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5438 break;
5439 }
5440 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5441 }
5442 case 'n':
5443 {
5444 if (LocaleCompare("negate",option+1) == 0)
5445 break;
5446 if (LocaleCompare("noise",option+1) == 0)
5447 {
5448 i++;
cristybb503372010-05-27 20:51:26 +00005449 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005450 ThrowMogrifyException(OptionError,"MissingArgument",option);
5451 if (*option == '+')
5452 {
cristybb503372010-05-27 20:51:26 +00005453 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005454 noise;
5455
5456 noise=ParseMagickOption(MagickNoiseOptions,MagickFalse,argv[i]);
5457 if (noise < 0)
5458 ThrowMogrifyException(OptionError,"UnrecognizedNoiseType",
5459 argv[i]);
5460 break;
5461 }
5462 if (IsGeometry(argv[i]) == MagickFalse)
5463 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5464 break;
5465 }
5466 if (LocaleCompare("noop",option+1) == 0)
5467 break;
5468 if (LocaleCompare("normalize",option+1) == 0)
5469 break;
5470 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5471 }
5472 case 'o':
5473 {
5474 if (LocaleCompare("opaque",option+1) == 0)
5475 {
cristy3ed852e2009-09-05 21:47:34 +00005476 i++;
cristybb503372010-05-27 20:51:26 +00005477 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005478 ThrowMogrifyException(OptionError,"MissingArgument",option);
5479 break;
5480 }
5481 if (LocaleCompare("ordered-dither",option+1) == 0)
5482 {
5483 if (*option == '+')
5484 break;
5485 i++;
cristybb503372010-05-27 20:51:26 +00005486 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005487 ThrowMogrifyException(OptionError,"MissingArgument",option);
5488 break;
5489 }
5490 if (LocaleCompare("orient",option+1) == 0)
5491 {
cristybb503372010-05-27 20:51:26 +00005492 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005493 orientation;
5494
5495 orientation=UndefinedOrientation;
5496 if (*option == '+')
5497 break;
5498 i++;
cristybb503372010-05-27 20:51:26 +00005499 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005500 ThrowMogrifyException(OptionError,"MissingArgument",option);
5501 orientation=ParseMagickOption(MagickOrientationOptions,MagickFalse,
5502 argv[i]);
5503 if (orientation < 0)
5504 ThrowMogrifyException(OptionError,"UnrecognizedImageOrientation",
5505 argv[i]);
5506 break;
5507 }
5508 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5509 }
5510 case 'p':
5511 {
5512 if (LocaleCompare("page",option+1) == 0)
5513 {
5514 if (*option == '+')
5515 break;
5516 i++;
cristybb503372010-05-27 20:51:26 +00005517 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005518 ThrowMogrifyException(OptionError,"MissingArgument",option);
5519 break;
5520 }
5521 if (LocaleCompare("paint",option+1) == 0)
5522 {
5523 if (*option == '+')
5524 break;
5525 i++;
cristybb503372010-05-27 20:51:26 +00005526 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005527 ThrowMogrifyException(OptionError,"MissingArgument",option);
5528 if (IsGeometry(argv[i]) == MagickFalse)
5529 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5530 break;
5531 }
5532 if (LocaleCompare("path",option+1) == 0)
5533 {
5534 (void) CloneString(&path,(char *) NULL);
5535 if (*option == '+')
5536 break;
5537 i++;
cristybb503372010-05-27 20:51:26 +00005538 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005539 ThrowMogrifyException(OptionError,"MissingArgument",option);
5540 (void) CloneString(&path,argv[i]);
5541 break;
5542 }
5543 if (LocaleCompare("pointsize",option+1) == 0)
5544 {
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 if (IsGeometry(argv[i]) == MagickFalse)
5551 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5552 break;
5553 }
5554 if (LocaleCompare("polaroid",option+1) == 0)
5555 {
5556 if (*option == '+')
5557 break;
5558 i++;
cristybb503372010-05-27 20:51:26 +00005559 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005560 ThrowMogrifyException(OptionError,"MissingArgument",option);
5561 if (IsGeometry(argv[i]) == MagickFalse)
5562 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5563 break;
5564 }
5565 if (LocaleCompare("posterize",option+1) == 0)
5566 {
5567 if (*option == '+')
5568 break;
5569 i++;
cristybb503372010-05-27 20:51:26 +00005570 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005571 ThrowMogrifyException(OptionError,"MissingArgument",option);
5572 if (IsGeometry(argv[i]) == MagickFalse)
5573 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5574 break;
5575 }
cristye7f51092010-01-17 00:39:37 +00005576 if (LocaleCompare("precision",option+1) == 0)
5577 {
5578 if (*option == '+')
5579 break;
5580 i++;
cristybb503372010-05-27 20:51:26 +00005581 if (i == (ssize_t) argc)
cristye7f51092010-01-17 00:39:37 +00005582 ThrowMogrifyException(OptionError,"MissingArgument",option);
5583 if (IsGeometry(argv[i]) == MagickFalse)
5584 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5585 break;
5586 }
cristy3ed852e2009-09-05 21:47:34 +00005587 if (LocaleCompare("print",option+1) == 0)
5588 {
5589 if (*option == '+')
5590 break;
5591 i++;
cristybb503372010-05-27 20:51:26 +00005592 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005593 ThrowMogrifyException(OptionError,"MissingArgument",option);
5594 break;
5595 }
5596 if (LocaleCompare("process",option+1) == 0)
5597 {
5598 if (*option == '+')
5599 break;
5600 i++;
cristybb503372010-05-27 20:51:26 +00005601 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005602 ThrowMogrifyException(OptionError,"MissingArgument",option);
5603 break;
5604 }
5605 if (LocaleCompare("profile",option+1) == 0)
5606 {
5607 i++;
cristybb503372010-05-27 20:51:26 +00005608 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005609 ThrowMogrifyException(OptionError,"MissingArgument",option);
5610 break;
5611 }
5612 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5613 }
5614 case 'q':
5615 {
5616 if (LocaleCompare("quality",option+1) == 0)
5617 {
5618 if (*option == '+')
5619 break;
5620 i++;
cristybb503372010-05-27 20:51:26 +00005621 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005622 ThrowMogrifyException(OptionError,"MissingArgument",option);
5623 if (IsGeometry(argv[i]) == MagickFalse)
5624 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5625 break;
5626 }
5627 if (LocaleCompare("quantize",option+1) == 0)
5628 {
cristybb503372010-05-27 20:51:26 +00005629 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005630 colorspace;
5631
5632 if (*option == '+')
5633 break;
5634 i++;
cristybb503372010-05-27 20:51:26 +00005635 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005636 ThrowMogrifyException(OptionError,"MissingArgument",option);
5637 colorspace=ParseMagickOption(MagickColorspaceOptions,MagickFalse,
5638 argv[i]);
5639 if (colorspace < 0)
5640 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
5641 argv[i]);
5642 break;
5643 }
5644 if (LocaleCompare("quiet",option+1) == 0)
5645 break;
5646 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5647 }
5648 case 'r':
5649 {
5650 if (LocaleCompare("radial-blur",option+1) == 0)
5651 {
5652 i++;
cristybb503372010-05-27 20:51:26 +00005653 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005654 ThrowMogrifyException(OptionError,"MissingArgument",option);
5655 if (IsGeometry(argv[i]) == MagickFalse)
5656 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5657 break;
5658 }
5659 if (LocaleCompare("raise",option+1) == 0)
5660 {
5661 i++;
cristybb503372010-05-27 20:51:26 +00005662 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005663 ThrowMogrifyException(OptionError,"MissingArgument",option);
5664 if (IsGeometry(argv[i]) == MagickFalse)
5665 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5666 break;
5667 }
5668 if (LocaleCompare("random-threshold",option+1) == 0)
5669 {
5670 if (*option == '+')
5671 break;
5672 i++;
cristybb503372010-05-27 20:51:26 +00005673 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005674 ThrowMogrifyException(OptionError,"MissingArgument",option);
5675 if (IsGeometry(argv[i]) == MagickFalse)
5676 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5677 break;
5678 }
cristye6365592010-04-02 17:31:23 +00005679 if (LocaleCompare("recolor",option+1) == 0)
5680 {
5681 if (*option == '+')
5682 break;
5683 i++;
cristybb503372010-05-27 20:51:26 +00005684 if (i == (ssize_t) (argc-1))
cristye6365592010-04-02 17:31:23 +00005685 ThrowMogrifyException(OptionError,"MissingArgument",option);
5686 if (IsGeometry(argv[i]) == MagickFalse)
5687 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5688 break;
5689 }
cristy3ed852e2009-09-05 21:47:34 +00005690 if (LocaleCompare("red-primary",option+1) == 0)
5691 {
5692 if (*option == '+')
5693 break;
5694 i++;
cristybb503372010-05-27 20:51:26 +00005695 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005696 ThrowMogrifyException(OptionError,"MissingArgument",option);
5697 if (IsGeometry(argv[i]) == MagickFalse)
5698 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5699 }
cristy9f2083a2010-04-22 19:48:05 +00005700 if (LocaleCompare("regard-warnings",option+1) == 0)
5701 break;
cristy3ed852e2009-09-05 21:47:34 +00005702 if (LocaleCompare("region",option+1) == 0)
5703 {
5704 if (*option == '+')
5705 break;
5706 i++;
cristybb503372010-05-27 20:51:26 +00005707 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005708 ThrowMogrifyException(OptionError,"MissingArgument",option);
5709 if (IsGeometry(argv[i]) == MagickFalse)
5710 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5711 break;
5712 }
cristyf0c78232010-03-15 12:53:40 +00005713 if (LocaleCompare("remap",option+1) == 0)
5714 {
5715 if (*option == '+')
5716 break;
5717 i++;
cristybb503372010-05-27 20:51:26 +00005718 if (i == (ssize_t) (argc-1))
cristyf0c78232010-03-15 12:53:40 +00005719 ThrowMogrifyException(OptionError,"MissingArgument",option);
5720 break;
5721 }
cristy3ed852e2009-09-05 21:47:34 +00005722 if (LocaleCompare("render",option+1) == 0)
5723 break;
5724 if (LocaleCompare("repage",option+1) == 0)
5725 {
5726 if (*option == '+')
5727 break;
5728 i++;
cristybb503372010-05-27 20:51:26 +00005729 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005730 ThrowMogrifyException(OptionError,"MissingArgument",option);
5731 if (IsGeometry(argv[i]) == MagickFalse)
5732 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5733 break;
5734 }
5735 if (LocaleCompare("resample",option+1) == 0)
5736 {
5737 if (*option == '+')
5738 break;
5739 i++;
cristybb503372010-05-27 20:51:26 +00005740 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005741 ThrowMogrifyException(OptionError,"MissingArgument",option);
5742 if (IsGeometry(argv[i]) == MagickFalse)
5743 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5744 break;
5745 }
5746 if (LocaleCompare("resize",option+1) == 0)
5747 {
5748 if (*option == '+')
5749 break;
5750 i++;
cristybb503372010-05-27 20:51:26 +00005751 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005752 ThrowMogrifyException(OptionError,"MissingArgument",option);
5753 if (IsGeometry(argv[i]) == MagickFalse)
5754 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5755 break;
5756 }
5757 if (LocaleCompare("reverse",option+1) == 0)
5758 break;
5759 if (LocaleCompare("roll",option+1) == 0)
5760 {
5761 if (*option == '+')
5762 break;
5763 i++;
cristybb503372010-05-27 20:51:26 +00005764 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005765 ThrowMogrifyException(OptionError,"MissingArgument",option);
5766 if (IsGeometry(argv[i]) == MagickFalse)
5767 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5768 break;
5769 }
5770 if (LocaleCompare("rotate",option+1) == 0)
5771 {
5772 i++;
cristybb503372010-05-27 20:51:26 +00005773 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005774 ThrowMogrifyException(OptionError,"MissingArgument",option);
5775 if (IsGeometry(argv[i]) == MagickFalse)
5776 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5777 break;
5778 }
5779 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5780 }
5781 case 's':
5782 {
5783 if (LocaleCompare("sample",option+1) == 0)
5784 {
5785 if (*option == '+')
5786 break;
5787 i++;
cristybb503372010-05-27 20:51:26 +00005788 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005789 ThrowMogrifyException(OptionError,"MissingArgument",option);
5790 if (IsGeometry(argv[i]) == MagickFalse)
5791 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5792 break;
5793 }
5794 if (LocaleCompare("sampling-factor",option+1) == 0)
5795 {
5796 if (*option == '+')
5797 break;
5798 i++;
cristybb503372010-05-27 20:51:26 +00005799 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005800 ThrowMogrifyException(OptionError,"MissingArgument",option);
5801 if (IsGeometry(argv[i]) == MagickFalse)
5802 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5803 break;
5804 }
5805 if (LocaleCompare("scale",option+1) == 0)
5806 {
5807 if (*option == '+')
5808 break;
5809 i++;
cristybb503372010-05-27 20:51:26 +00005810 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005811 ThrowMogrifyException(OptionError,"MissingArgument",option);
5812 if (IsGeometry(argv[i]) == MagickFalse)
5813 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5814 break;
5815 }
5816 if (LocaleCompare("scene",option+1) == 0)
5817 {
5818 if (*option == '+')
5819 break;
5820 i++;
cristybb503372010-05-27 20:51:26 +00005821 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005822 ThrowMogrifyException(OptionError,"MissingArgument",option);
5823 if (IsGeometry(argv[i]) == MagickFalse)
5824 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5825 break;
5826 }
5827 if (LocaleCompare("seed",option+1) == 0)
5828 {
5829 if (*option == '+')
5830 break;
5831 i++;
cristybb503372010-05-27 20:51:26 +00005832 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005833 ThrowMogrifyException(OptionError,"MissingArgument",option);
5834 if (IsGeometry(argv[i]) == MagickFalse)
5835 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5836 break;
5837 }
5838 if (LocaleCompare("segment",option+1) == 0)
5839 {
5840 if (*option == '+')
5841 break;
5842 i++;
cristybb503372010-05-27 20:51:26 +00005843 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005844 ThrowMogrifyException(OptionError,"MissingArgument",option);
5845 if (IsGeometry(argv[i]) == MagickFalse)
5846 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5847 break;
5848 }
5849 if (LocaleCompare("selective-blur",option+1) == 0)
5850 {
5851 i++;
cristybb503372010-05-27 20:51:26 +00005852 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005853 ThrowMogrifyException(OptionError,"MissingArgument",option);
5854 if (IsGeometry(argv[i]) == MagickFalse)
5855 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5856 break;
5857 }
5858 if (LocaleCompare("separate",option+1) == 0)
5859 break;
5860 if (LocaleCompare("sepia-tone",option+1) == 0)
5861 {
5862 if (*option == '+')
5863 break;
5864 i++;
cristybb503372010-05-27 20:51:26 +00005865 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005866 ThrowMogrifyException(OptionError,"MissingArgument",option);
5867 if (IsGeometry(argv[i]) == MagickFalse)
5868 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5869 break;
5870 }
5871 if (LocaleCompare("set",option+1) == 0)
5872 {
5873 i++;
cristybb503372010-05-27 20:51:26 +00005874 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005875 ThrowMogrifyException(OptionError,"MissingArgument",option);
5876 if (*option == '+')
5877 break;
5878 i++;
cristybb503372010-05-27 20:51:26 +00005879 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005880 ThrowMogrifyException(OptionError,"MissingArgument",option);
5881 break;
5882 }
5883 if (LocaleCompare("shade",option+1) == 0)
5884 {
5885 i++;
cristybb503372010-05-27 20:51:26 +00005886 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005887 ThrowMogrifyException(OptionError,"MissingArgument",option);
5888 if (IsGeometry(argv[i]) == MagickFalse)
5889 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5890 break;
5891 }
5892 if (LocaleCompare("shadow",option+1) == 0)
5893 {
5894 if (*option == '+')
5895 break;
5896 i++;
cristybb503372010-05-27 20:51:26 +00005897 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005898 ThrowMogrifyException(OptionError,"MissingArgument",option);
5899 if (IsGeometry(argv[i]) == MagickFalse)
5900 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5901 break;
5902 }
5903 if (LocaleCompare("sharpen",option+1) == 0)
5904 {
5905 i++;
cristybb503372010-05-27 20:51:26 +00005906 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005907 ThrowMogrifyException(OptionError,"MissingArgument",option);
5908 if (IsGeometry(argv[i]) == MagickFalse)
5909 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5910 break;
5911 }
5912 if (LocaleCompare("shave",option+1) == 0)
5913 {
5914 if (*option == '+')
5915 break;
5916 i++;
cristybb503372010-05-27 20:51:26 +00005917 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005918 ThrowMogrifyException(OptionError,"MissingArgument",option);
5919 if (IsGeometry(argv[i]) == MagickFalse)
5920 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5921 break;
5922 }
5923 if (LocaleCompare("shear",option+1) == 0)
5924 {
5925 i++;
cristybb503372010-05-27 20:51:26 +00005926 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005927 ThrowMogrifyException(OptionError,"MissingArgument",option);
5928 if (IsGeometry(argv[i]) == MagickFalse)
5929 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5930 break;
5931 }
5932 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
5933 {
5934 i++;
cristybb503372010-05-27 20:51:26 +00005935 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005936 ThrowMogrifyException(OptionError,"MissingArgument",option);
5937 if (IsGeometry(argv[i]) == MagickFalse)
5938 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5939 break;
5940 }
5941 if (LocaleCompare("size",option+1) == 0)
5942 {
5943 if (*option == '+')
5944 break;
5945 i++;
cristybb503372010-05-27 20:51:26 +00005946 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005947 ThrowMogrifyException(OptionError,"MissingArgument",option);
5948 if (IsGeometry(argv[i]) == MagickFalse)
5949 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5950 break;
5951 }
5952 if (LocaleCompare("sketch",option+1) == 0)
5953 {
5954 if (*option == '+')
5955 break;
5956 i++;
cristybb503372010-05-27 20:51:26 +00005957 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005958 ThrowMogrifyException(OptionError,"MissingArgument",option);
5959 if (IsGeometry(argv[i]) == MagickFalse)
5960 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5961 break;
5962 }
5963 if (LocaleCompare("solarize",option+1) == 0)
5964 {
5965 if (*option == '+')
5966 break;
5967 i++;
cristybb503372010-05-27 20:51:26 +00005968 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005969 ThrowMogrifyException(OptionError,"MissingArgument",option);
5970 if (IsGeometry(argv[i]) == MagickFalse)
5971 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5972 break;
5973 }
5974 if (LocaleCompare("sparse-color",option+1) == 0)
5975 {
cristybb503372010-05-27 20:51:26 +00005976 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005977 op;
5978
5979 i++;
cristybb503372010-05-27 20:51:26 +00005980 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005981 ThrowMogrifyException(OptionError,"MissingArgument",option);
5982 op=ParseMagickOption(MagickSparseColorOptions,MagickFalse,argv[i]);
5983 if (op < 0)
5984 ThrowMogrifyException(OptionError,"UnrecognizedSparseColorMethod",
5985 argv[i]);
5986 i++;
cristybb503372010-05-27 20:51:26 +00005987 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005988 ThrowMogrifyException(OptionError,"MissingArgument",option);
5989 break;
5990 }
5991 if (LocaleCompare("spread",option+1) == 0)
5992 {
5993 if (*option == '+')
5994 break;
5995 i++;
cristybb503372010-05-27 20:51:26 +00005996 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005997 ThrowMogrifyException(OptionError,"MissingArgument",option);
5998 if (IsGeometry(argv[i]) == MagickFalse)
5999 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6000 break;
6001 }
6002 if (LocaleCompare("stretch",option+1) == 0)
6003 {
cristybb503372010-05-27 20:51:26 +00006004 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006005 stretch;
6006
6007 if (*option == '+')
6008 break;
6009 i++;
cristybb503372010-05-27 20:51:26 +00006010 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006011 ThrowMogrifyException(OptionError,"MissingArgument",option);
6012 stretch=ParseMagickOption(MagickStretchOptions,MagickFalse,argv[i]);
6013 if (stretch < 0)
6014 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
6015 argv[i]);
6016 break;
6017 }
6018 if (LocaleCompare("strip",option+1) == 0)
6019 break;
6020 if (LocaleCompare("stroke",option+1) == 0)
6021 {
6022 if (*option == '+')
6023 break;
6024 i++;
cristybb503372010-05-27 20:51:26 +00006025 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006026 ThrowMogrifyException(OptionError,"MissingArgument",option);
6027 break;
6028 }
6029 if (LocaleCompare("strokewidth",option+1) == 0)
6030 {
6031 if (*option == '+')
6032 break;
6033 i++;
cristybb503372010-05-27 20:51:26 +00006034 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006035 ThrowMogrifyException(OptionError,"MissingArgument",option);
6036 if (IsGeometry(argv[i]) == MagickFalse)
6037 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6038 break;
6039 }
6040 if (LocaleCompare("style",option+1) == 0)
6041 {
cristybb503372010-05-27 20:51:26 +00006042 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006043 style;
6044
6045 if (*option == '+')
6046 break;
6047 i++;
cristybb503372010-05-27 20:51:26 +00006048 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006049 ThrowMogrifyException(OptionError,"MissingArgument",option);
6050 style=ParseMagickOption(MagickStyleOptions,MagickFalse,argv[i]);
6051 if (style < 0)
6052 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
6053 argv[i]);
6054 break;
6055 }
6056 if (LocaleCompare("swirl",option+1) == 0)
6057 {
6058 if (*option == '+')
6059 break;
6060 i++;
cristybb503372010-05-27 20:51:26 +00006061 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006062 ThrowMogrifyException(OptionError,"MissingArgument",option);
6063 if (IsGeometry(argv[i]) == MagickFalse)
6064 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6065 break;
6066 }
cristyd9a29192010-10-16 16:49:53 +00006067 if (LocaleCompare("synchronize",option+1) == 0)
6068 break;
cristy3ed852e2009-09-05 21:47:34 +00006069 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6070 }
6071 case 't':
6072 {
6073 if (LocaleCompare("taint",option+1) == 0)
6074 break;
6075 if (LocaleCompare("texture",option+1) == 0)
6076 {
6077 if (*option == '+')
6078 break;
6079 i++;
cristybb503372010-05-27 20:51:26 +00006080 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006081 ThrowMogrifyException(OptionError,"MissingArgument",option);
6082 break;
6083 }
6084 if (LocaleCompare("tile",option+1) == 0)
6085 {
6086 if (*option == '+')
6087 break;
6088 i++;
cristybb503372010-05-27 20:51:26 +00006089 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006090 ThrowMogrifyException(OptionError,"MissingArgument",option);
6091 break;
6092 }
6093 if (LocaleCompare("tile-offset",option+1) == 0)
6094 {
6095 if (*option == '+')
6096 break;
6097 i++;
cristybb503372010-05-27 20:51:26 +00006098 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006099 ThrowMogrifyException(OptionError,"MissingArgument",option);
6100 if (IsGeometry(argv[i]) == MagickFalse)
6101 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6102 break;
6103 }
6104 if (LocaleCompare("tint",option+1) == 0)
6105 {
6106 if (*option == '+')
6107 break;
6108 i++;
cristybb503372010-05-27 20:51:26 +00006109 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006110 ThrowMogrifyException(OptionError,"MissingArgument",option);
6111 if (IsGeometry(argv[i]) == MagickFalse)
6112 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6113 break;
6114 }
6115 if (LocaleCompare("transform",option+1) == 0)
6116 break;
6117 if (LocaleCompare("transpose",option+1) == 0)
6118 break;
6119 if (LocaleCompare("transverse",option+1) == 0)
6120 break;
6121 if (LocaleCompare("threshold",option+1) == 0)
6122 {
6123 if (*option == '+')
6124 break;
6125 i++;
cristybb503372010-05-27 20:51:26 +00006126 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006127 ThrowMogrifyException(OptionError,"MissingArgument",option);
6128 if (IsGeometry(argv[i]) == MagickFalse)
6129 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6130 break;
6131 }
6132 if (LocaleCompare("thumbnail",option+1) == 0)
6133 {
6134 if (*option == '+')
6135 break;
6136 i++;
cristybb503372010-05-27 20:51:26 +00006137 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006138 ThrowMogrifyException(OptionError,"MissingArgument",option);
6139 if (IsGeometry(argv[i]) == MagickFalse)
6140 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6141 break;
6142 }
6143 if (LocaleCompare("transparent",option+1) == 0)
6144 {
6145 i++;
cristybb503372010-05-27 20:51:26 +00006146 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006147 ThrowMogrifyException(OptionError,"MissingArgument",option);
6148 break;
6149 }
6150 if (LocaleCompare("transparent-color",option+1) == 0)
6151 {
6152 if (*option == '+')
6153 break;
6154 i++;
cristybb503372010-05-27 20:51:26 +00006155 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006156 ThrowMogrifyException(OptionError,"MissingArgument",option);
6157 break;
6158 }
6159 if (LocaleCompare("treedepth",option+1) == 0)
6160 {
6161 if (*option == '+')
6162 break;
6163 i++;
cristybb503372010-05-27 20:51:26 +00006164 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006165 ThrowMogrifyException(OptionError,"MissingArgument",option);
6166 if (IsGeometry(argv[i]) == MagickFalse)
6167 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6168 break;
6169 }
6170 if (LocaleCompare("trim",option+1) == 0)
6171 break;
6172 if (LocaleCompare("type",option+1) == 0)
6173 {
cristybb503372010-05-27 20:51:26 +00006174 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006175 type;
6176
6177 if (*option == '+')
6178 break;
6179 i++;
cristybb503372010-05-27 20:51:26 +00006180 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006181 ThrowMogrifyException(OptionError,"MissingArgument",option);
6182 type=ParseMagickOption(MagickTypeOptions,MagickFalse,argv[i]);
6183 if (type < 0)
6184 ThrowMogrifyException(OptionError,"UnrecognizedImageType",
6185 argv[i]);
6186 break;
6187 }
6188 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6189 }
6190 case 'u':
6191 {
6192 if (LocaleCompare("undercolor",option+1) == 0)
6193 {
6194 if (*option == '+')
6195 break;
6196 i++;
cristybb503372010-05-27 20:51:26 +00006197 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006198 ThrowMogrifyException(OptionError,"MissingArgument",option);
6199 break;
6200 }
6201 if (LocaleCompare("unique-colors",option+1) == 0)
6202 break;
6203 if (LocaleCompare("units",option+1) == 0)
6204 {
cristybb503372010-05-27 20:51:26 +00006205 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006206 units;
6207
6208 if (*option == '+')
6209 break;
6210 i++;
cristybb503372010-05-27 20:51:26 +00006211 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006212 ThrowMogrifyException(OptionError,"MissingArgument",option);
6213 units=ParseMagickOption(MagickResolutionOptions,MagickFalse,
6214 argv[i]);
6215 if (units < 0)
6216 ThrowMogrifyException(OptionError,"UnrecognizedUnitsType",
6217 argv[i]);
6218 break;
6219 }
6220 if (LocaleCompare("unsharp",option+1) == 0)
6221 {
6222 i++;
cristybb503372010-05-27 20:51:26 +00006223 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006224 ThrowMogrifyException(OptionError,"MissingArgument",option);
6225 if (IsGeometry(argv[i]) == MagickFalse)
6226 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6227 break;
6228 }
6229 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6230 }
6231 case 'v':
6232 {
6233 if (LocaleCompare("verbose",option+1) == 0)
6234 {
6235 image_info->verbose=(*option == '-') ? MagickTrue : MagickFalse;
6236 break;
6237 }
6238 if ((LocaleCompare("version",option+1) == 0) ||
6239 (LocaleCompare("-version",option+1) == 0))
6240 {
6241 (void) fprintf(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +00006242 GetMagickVersion((size_t *) NULL));
cristy610b2e22009-10-22 14:59:43 +00006243 (void) fprintf(stdout,"Copyright: %s\n",GetMagickCopyright());
6244 (void) fprintf(stdout,"Features: %s\n\n",GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00006245 break;
6246 }
6247 if (LocaleCompare("view",option+1) == 0)
6248 {
6249 if (*option == '+')
6250 break;
6251 i++;
cristybb503372010-05-27 20:51:26 +00006252 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006253 ThrowMogrifyException(OptionError,"MissingArgument",option);
6254 break;
6255 }
6256 if (LocaleCompare("vignette",option+1) == 0)
6257 {
6258 if (*option == '+')
6259 break;
6260 i++;
cristybb503372010-05-27 20:51:26 +00006261 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006262 ThrowMogrifyException(OptionError,"MissingArgument",option);
6263 if (IsGeometry(argv[i]) == MagickFalse)
6264 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6265 break;
6266 }
6267 if (LocaleCompare("virtual-pixel",option+1) == 0)
6268 {
cristybb503372010-05-27 20:51:26 +00006269 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006270 method;
6271
6272 if (*option == '+')
6273 break;
6274 i++;
cristybb503372010-05-27 20:51:26 +00006275 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006276 ThrowMogrifyException(OptionError,"MissingArgument",option);
6277 method=ParseMagickOption(MagickVirtualPixelOptions,MagickFalse,
6278 argv[i]);
6279 if (method < 0)
6280 ThrowMogrifyException(OptionError,
6281 "UnrecognizedVirtualPixelMethod",argv[i]);
6282 break;
6283 }
6284 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6285 }
6286 case 'w':
6287 {
6288 if (LocaleCompare("wave",option+1) == 0)
6289 {
6290 i++;
cristybb503372010-05-27 20:51:26 +00006291 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006292 ThrowMogrifyException(OptionError,"MissingArgument",option);
6293 if (IsGeometry(argv[i]) == MagickFalse)
6294 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6295 break;
6296 }
6297 if (LocaleCompare("weight",option+1) == 0)
6298 {
6299 if (*option == '+')
6300 break;
6301 i++;
cristybb503372010-05-27 20:51:26 +00006302 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006303 ThrowMogrifyException(OptionError,"MissingArgument",option);
6304 break;
6305 }
6306 if (LocaleCompare("white-point",option+1) == 0)
6307 {
6308 if (*option == '+')
6309 break;
6310 i++;
cristybb503372010-05-27 20:51:26 +00006311 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006312 ThrowMogrifyException(OptionError,"MissingArgument",option);
6313 if (IsGeometry(argv[i]) == MagickFalse)
6314 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6315 break;
6316 }
6317 if (LocaleCompare("white-threshold",option+1) == 0)
6318 {
6319 if (*option == '+')
6320 break;
6321 i++;
cristybb503372010-05-27 20:51:26 +00006322 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006323 ThrowMogrifyException(OptionError,"MissingArgument",option);
6324 if (IsGeometry(argv[i]) == MagickFalse)
6325 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6326 break;
6327 }
6328 if (LocaleCompare("write",option+1) == 0)
6329 {
6330 i++;
cristybb503372010-05-27 20:51:26 +00006331 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006332 ThrowMogrifyException(OptionError,"MissingArgument",option);
6333 break;
6334 }
6335 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6336 }
6337 case '?':
6338 break;
6339 default:
6340 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6341 }
6342 fire=ParseMagickOption(MagickImageListOptions,MagickFalse,option+1) < 0 ?
6343 MagickFalse : MagickTrue;
6344 if (fire != MagickFalse)
6345 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
6346 }
6347 if (k != 0)
6348 ThrowMogrifyException(OptionError,"UnbalancedParenthesis",argv[i]);
cristycee97112010-05-28 00:44:52 +00006349 if (i != (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006350 ThrowMogrifyException(OptionError,"MissingAnImageFilename",argv[i]);
6351 DestroyMogrify();
6352 return(status != 0 ? MagickTrue : MagickFalse);
6353}
6354
6355/*
6356%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6357% %
6358% %
6359% %
6360+ M o g r i f y I m a g e I n f o %
6361% %
6362% %
6363% %
6364%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6365%
6366% MogrifyImageInfo() applies image processing settings to the image as
6367% prescribed by command line options.
6368%
6369% The format of the MogrifyImageInfo method is:
6370%
6371% MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,const int argc,
6372% const char **argv,ExceptionInfo *exception)
6373%
6374% A description of each parameter follows:
6375%
6376% o image_info: the image info..
6377%
6378% o argc: Specifies a pointer to an integer describing the number of
6379% elements in the argument vector.
6380%
6381% o argv: Specifies a pointer to a text array containing the command line
6382% arguments.
6383%
6384% o exception: return any errors or warnings in this structure.
6385%
6386*/
6387WandExport MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,
6388 const int argc,const char **argv,ExceptionInfo *exception)
6389{
6390 const char
6391 *option;
6392
6393 GeometryInfo
6394 geometry_info;
6395
cristybb503372010-05-27 20:51:26 +00006396 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006397 count;
6398
cristybb503372010-05-27 20:51:26 +00006399 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006400 i;
6401
6402 /*
6403 Initialize method variables.
6404 */
6405 assert(image_info != (ImageInfo *) NULL);
6406 assert(image_info->signature == MagickSignature);
6407 if (image_info->debug != MagickFalse)
6408 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
6409 image_info->filename);
6410 if (argc < 0)
6411 return(MagickTrue);
6412 /*
6413 Set the image settings.
6414 */
cristybb503372010-05-27 20:51:26 +00006415 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00006416 {
6417 option=argv[i];
6418 if (IsMagickOption(option) == MagickFalse)
6419 continue;
6420 count=MagickMax(ParseMagickOption(MagickCommandOptions,MagickFalse,option),
6421 0L);
cristycee97112010-05-28 00:44:52 +00006422 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006423 break;
6424 switch (*(option+1))
6425 {
6426 case 'a':
6427 {
6428 if (LocaleCompare("adjoin",option+1) == 0)
6429 {
6430 image_info->adjoin=(*option == '-') ? MagickTrue : MagickFalse;
6431 break;
6432 }
6433 if (LocaleCompare("antialias",option+1) == 0)
6434 {
6435 image_info->antialias=(*option == '-') ? MagickTrue : MagickFalse;
6436 break;
6437 }
6438 if (LocaleCompare("attenuate",option+1) == 0)
6439 {
6440 if (*option == '+')
6441 {
6442 (void) DeleteImageOption(image_info,option+1);
6443 break;
6444 }
6445 (void) SetImageOption(image_info,option+1,argv[i+1]);
6446 break;
6447 }
6448 if (LocaleCompare("authenticate",option+1) == 0)
6449 {
6450 if (*option == '+')
6451 (void) CloneString(&image_info->authenticate,(char *) NULL);
6452 else
6453 (void) CloneString(&image_info->authenticate,argv[i+1]);
6454 break;
6455 }
6456 break;
6457 }
6458 case 'b':
6459 {
6460 if (LocaleCompare("background",option+1) == 0)
6461 {
6462 if (*option == '+')
6463 {
6464 (void) DeleteImageOption(image_info,option+1);
6465 (void) QueryColorDatabase(BackgroundColor,
6466 &image_info->background_color,exception);
6467 break;
6468 }
6469 (void) SetImageOption(image_info,option+1,argv[i+1]);
6470 (void) QueryColorDatabase(argv[i+1],&image_info->background_color,
6471 exception);
6472 break;
6473 }
6474 if (LocaleCompare("bias",option+1) == 0)
6475 {
6476 if (*option == '+')
6477 {
6478 (void) SetImageOption(image_info,option+1,"0.0");
6479 break;
6480 }
6481 (void) SetImageOption(image_info,option+1,argv[i+1]);
6482 break;
6483 }
6484 if (LocaleCompare("black-point-compensation",option+1) == 0)
6485 {
6486 if (*option == '+')
6487 {
6488 (void) SetImageOption(image_info,option+1,"false");
6489 break;
6490 }
6491 (void) SetImageOption(image_info,option+1,"true");
6492 break;
6493 }
6494 if (LocaleCompare("blue-primary",option+1) == 0)
6495 {
6496 if (*option == '+')
6497 {
6498 (void) SetImageOption(image_info,option+1,"0.0");
6499 break;
6500 }
6501 (void) SetImageOption(image_info,option+1,argv[i+1]);
6502 break;
6503 }
6504 if (LocaleCompare("bordercolor",option+1) == 0)
6505 {
6506 if (*option == '+')
6507 {
6508 (void) DeleteImageOption(image_info,option+1);
6509 (void) QueryColorDatabase(BorderColor,&image_info->border_color,
6510 exception);
6511 break;
6512 }
6513 (void) QueryColorDatabase(argv[i+1],&image_info->border_color,
6514 exception);
6515 (void) SetImageOption(image_info,option+1,argv[i+1]);
6516 break;
6517 }
6518 if (LocaleCompare("box",option+1) == 0)
6519 {
6520 if (*option == '+')
6521 {
6522 (void) SetImageOption(image_info,"undercolor","none");
6523 break;
6524 }
6525 (void) SetImageOption(image_info,"undercolor",argv[i+1]);
6526 break;
6527 }
6528 break;
6529 }
6530 case 'c':
6531 {
6532 if (LocaleCompare("cache",option+1) == 0)
6533 {
6534 MagickSizeType
6535 limit;
6536
6537 limit=MagickResourceInfinity;
6538 if (LocaleCompare("unlimited",argv[i+1]) != 0)
cristyf2f27272009-12-17 14:48:46 +00006539 limit=(MagickSizeType) SiPrefixToDouble(argv[i+1],100.0);
cristy3ed852e2009-09-05 21:47:34 +00006540 (void) SetMagickResourceLimit(MemoryResource,limit);
6541 (void) SetMagickResourceLimit(MapResource,2*limit);
6542 break;
6543 }
6544 if (LocaleCompare("caption",option+1) == 0)
6545 {
6546 if (*option == '+')
6547 {
6548 (void) DeleteImageOption(image_info,option+1);
6549 break;
6550 }
6551 (void) SetImageOption(image_info,option+1,argv[i+1]);
6552 break;
6553 }
6554 if (LocaleCompare("channel",option+1) == 0)
6555 {
6556 if (*option == '+')
6557 {
6558 image_info->channel=DefaultChannels;
6559 break;
6560 }
6561 image_info->channel=(ChannelType) ParseChannelOption(argv[i+1]);
6562 break;
6563 }
6564 if (LocaleCompare("colors",option+1) == 0)
6565 {
cristye27293e2009-12-18 02:53:20 +00006566 image_info->colors=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006567 break;
6568 }
6569 if (LocaleCompare("colorspace",option+1) == 0)
6570 {
6571 if (*option == '+')
6572 {
6573 image_info->colorspace=UndefinedColorspace;
6574 (void) SetImageOption(image_info,option+1,"undefined");
6575 break;
6576 }
6577 image_info->colorspace=(ColorspaceType) ParseMagickOption(
6578 MagickColorspaceOptions,MagickFalse,argv[i+1]);
6579 (void) SetImageOption(image_info,option+1,argv[i+1]);
6580 break;
6581 }
6582 if (LocaleCompare("compress",option+1) == 0)
6583 {
6584 if (*option == '+')
6585 {
6586 image_info->compression=UndefinedCompression;
6587 (void) SetImageOption(image_info,option+1,"undefined");
6588 break;
6589 }
6590 image_info->compression=(CompressionType) ParseMagickOption(
6591 MagickCompressOptions,MagickFalse,argv[i+1]);
6592 (void) SetImageOption(image_info,option+1,argv[i+1]);
6593 break;
6594 }
6595 if (LocaleCompare("comment",option+1) == 0)
6596 {
6597 if (*option == '+')
6598 {
6599 (void) DeleteImageOption(image_info,option+1);
6600 break;
6601 }
6602 (void) SetImageOption(image_info,option+1,argv[i+1]);
6603 break;
6604 }
6605 if (LocaleCompare("compose",option+1) == 0)
6606 {
6607 if (*option == '+')
6608 {
6609 (void) SetImageOption(image_info,option+1,"undefined");
6610 break;
6611 }
6612 (void) SetImageOption(image_info,option+1,argv[i+1]);
6613 break;
6614 }
6615 if (LocaleCompare("compress",option+1) == 0)
6616 {
6617 if (*option == '+')
6618 {
6619 image_info->compression=UndefinedCompression;
6620 (void) SetImageOption(image_info,option+1,"undefined");
6621 break;
6622 }
6623 image_info->compression=(CompressionType) ParseMagickOption(
6624 MagickCompressOptions,MagickFalse,argv[i+1]);
6625 (void) SetImageOption(image_info,option+1,argv[i+1]);
6626 break;
6627 }
6628 break;
6629 }
6630 case 'd':
6631 {
6632 if (LocaleCompare("debug",option+1) == 0)
6633 {
6634 if (*option == '+')
6635 (void) SetLogEventMask("none");
6636 else
6637 (void) SetLogEventMask(argv[i+1]);
6638 image_info->debug=IsEventLogging();
6639 break;
6640 }
6641 if (LocaleCompare("define",option+1) == 0)
6642 {
6643 if (*option == '+')
6644 {
6645 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6646 (void) DeleteImageRegistry(argv[i+1]+9);
6647 else
6648 (void) DeleteImageOption(image_info,argv[i+1]);
6649 break;
6650 }
6651 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6652 {
6653 (void) DefineImageRegistry(StringRegistryType,argv[i+1]+9,
6654 exception);
6655 break;
6656 }
6657 (void) DefineImageOption(image_info,argv[i+1]);
6658 break;
6659 }
6660 if (LocaleCompare("delay",option+1) == 0)
6661 {
6662 if (*option == '+')
6663 {
6664 (void) SetImageOption(image_info,option+1,"0");
6665 break;
6666 }
6667 (void) SetImageOption(image_info,option+1,argv[i+1]);
6668 break;
6669 }
6670 if (LocaleCompare("density",option+1) == 0)
6671 {
6672 /*
6673 Set image density.
6674 */
6675 if (*option == '+')
6676 {
6677 if (image_info->density != (char *) NULL)
6678 image_info->density=DestroyString(image_info->density);
6679 (void) SetImageOption(image_info,option+1,"72");
6680 break;
6681 }
6682 (void) CloneString(&image_info->density,argv[i+1]);
6683 (void) SetImageOption(image_info,option+1,argv[i+1]);
6684 break;
6685 }
6686 if (LocaleCompare("depth",option+1) == 0)
6687 {
6688 if (*option == '+')
6689 {
6690 image_info->depth=MAGICKCORE_QUANTUM_DEPTH;
6691 break;
6692 }
cristye27293e2009-12-18 02:53:20 +00006693 image_info->depth=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006694 break;
6695 }
cristyc9b12952010-03-28 01:12:28 +00006696 if (LocaleCompare("direction",option+1) == 0)
6697 {
6698 if (*option == '+')
6699 {
6700 (void) SetImageOption(image_info,option+1,"undefined");
6701 break;
6702 }
6703 (void) SetImageOption(image_info,option+1,argv[i+1]);
6704 break;
6705 }
cristy3ed852e2009-09-05 21:47:34 +00006706 if (LocaleCompare("display",option+1) == 0)
6707 {
6708 if (*option == '+')
6709 {
6710 if (image_info->server_name != (char *) NULL)
6711 image_info->server_name=DestroyString(
6712 image_info->server_name);
6713 break;
6714 }
6715 (void) CloneString(&image_info->server_name,argv[i+1]);
6716 break;
6717 }
6718 if (LocaleCompare("dispose",option+1) == 0)
6719 {
6720 if (*option == '+')
6721 {
6722 (void) SetImageOption(image_info,option+1,"undefined");
6723 break;
6724 }
6725 (void) SetImageOption(image_info,option+1,argv[i+1]);
6726 break;
6727 }
6728 if (LocaleCompare("dither",option+1) == 0)
6729 {
6730 if (*option == '+')
6731 {
6732 image_info->dither=MagickFalse;
cristyd5acfd12010-06-15 00:11:38 +00006733 (void) SetImageOption(image_info,option+1,"none");
cristy3ed852e2009-09-05 21:47:34 +00006734 break;
6735 }
6736 (void) SetImageOption(image_info,option+1,argv[i+1]);
6737 image_info->dither=MagickTrue;
6738 break;
6739 }
6740 break;
6741 }
6742 case 'e':
6743 {
6744 if (LocaleCompare("encoding",option+1) == 0)
6745 {
6746 if (*option == '+')
6747 {
6748 (void) SetImageOption(image_info,option+1,"undefined");
6749 break;
6750 }
6751 (void) SetImageOption(image_info,option+1,argv[i+1]);
6752 break;
6753 }
6754 if (LocaleCompare("endian",option+1) == 0)
6755 {
6756 if (*option == '+')
6757 {
6758 image_info->endian=UndefinedEndian;
6759 (void) SetImageOption(image_info,option+1,"undefined");
6760 break;
6761 }
6762 image_info->endian=(EndianType) ParseMagickOption(
6763 MagickEndianOptions,MagickFalse,argv[i+1]);
6764 (void) SetImageOption(image_info,option+1,argv[i+1]);
6765 break;
6766 }
6767 if (LocaleCompare("extract",option+1) == 0)
6768 {
6769 /*
6770 Set image extract geometry.
6771 */
6772 if (*option == '+')
6773 {
6774 if (image_info->extract != (char *) NULL)
6775 image_info->extract=DestroyString(image_info->extract);
6776 break;
6777 }
6778 (void) CloneString(&image_info->extract,argv[i+1]);
6779 break;
6780 }
6781 break;
6782 }
6783 case 'f':
6784 {
6785 if (LocaleCompare("fill",option+1) == 0)
6786 {
6787 if (*option == '+')
6788 {
6789 (void) SetImageOption(image_info,option+1,"none");
6790 break;
6791 }
6792 (void) SetImageOption(image_info,option+1,argv[i+1]);
6793 break;
6794 }
6795 if (LocaleCompare("filter",option+1) == 0)
6796 {
6797 if (*option == '+')
6798 {
6799 (void) SetImageOption(image_info,option+1,"undefined");
6800 break;
6801 }
6802 (void) SetImageOption(image_info,option+1,argv[i+1]);
6803 break;
6804 }
6805 if (LocaleCompare("font",option+1) == 0)
6806 {
6807 if (*option == '+')
6808 {
6809 if (image_info->font != (char *) NULL)
6810 image_info->font=DestroyString(image_info->font);
6811 break;
6812 }
6813 (void) CloneString(&image_info->font,argv[i+1]);
6814 break;
6815 }
6816 if (LocaleCompare("format",option+1) == 0)
6817 {
6818 register const char
6819 *q;
6820
6821 for (q=strchr(argv[i+1],'%'); q != (char *) NULL; q=strchr(q+1,'%'))
6822 if (strchr("gkrz@[#",*(q+1)) != (char *) NULL)
6823 image_info->ping=MagickFalse;
6824 (void) SetImageOption(image_info,option+1,argv[i+1]);
6825 break;
6826 }
6827 if (LocaleCompare("fuzz",option+1) == 0)
6828 {
6829 if (*option == '+')
6830 {
6831 image_info->fuzz=0.0;
6832 (void) SetImageOption(image_info,option+1,"0");
6833 break;
6834 }
cristyf2f27272009-12-17 14:48:46 +00006835 image_info->fuzz=SiPrefixToDouble(argv[i+1],(double) QuantumRange+
cristy3ed852e2009-09-05 21:47:34 +00006836 1.0);
6837 (void) SetImageOption(image_info,option+1,argv[i+1]);
6838 break;
6839 }
6840 break;
6841 }
6842 case 'g':
6843 {
6844 if (LocaleCompare("gravity",option+1) == 0)
6845 {
6846 if (*option == '+')
6847 {
6848 (void) SetImageOption(image_info,option+1,"undefined");
6849 break;
6850 }
6851 (void) SetImageOption(image_info,option+1,argv[i+1]);
6852 break;
6853 }
6854 if (LocaleCompare("green-primary",option+1) == 0)
6855 {
6856 if (*option == '+')
6857 {
6858 (void) SetImageOption(image_info,option+1,"0.0");
6859 break;
6860 }
6861 (void) SetImageOption(image_info,option+1,argv[i+1]);
6862 break;
6863 }
6864 break;
6865 }
6866 case 'i':
6867 {
6868 if (LocaleCompare("intent",option+1) == 0)
6869 {
6870 if (*option == '+')
6871 {
6872 (void) SetImageOption(image_info,option+1,"undefined");
6873 break;
6874 }
6875 (void) SetImageOption(image_info,option+1,argv[i+1]);
6876 break;
6877 }
6878 if (LocaleCompare("interlace",option+1) == 0)
6879 {
6880 if (*option == '+')
6881 {
6882 image_info->interlace=UndefinedInterlace;
6883 (void) SetImageOption(image_info,option+1,"undefined");
6884 break;
6885 }
6886 image_info->interlace=(InterlaceType) ParseMagickOption(
6887 MagickInterlaceOptions,MagickFalse,argv[i+1]);
6888 (void) SetImageOption(image_info,option+1,argv[i+1]);
6889 break;
6890 }
cristyb32b90a2009-09-07 21:45:48 +00006891 if (LocaleCompare("interline-spacing",option+1) == 0)
6892 {
6893 if (*option == '+')
6894 {
6895 (void) SetImageOption(image_info,option+1,"undefined");
6896 break;
6897 }
6898 (void) SetImageOption(image_info,option+1,argv[i+1]);
6899 break;
6900 }
cristy3ed852e2009-09-05 21:47:34 +00006901 if (LocaleCompare("interpolate",option+1) == 0)
6902 {
6903 if (*option == '+')
6904 {
6905 (void) SetImageOption(image_info,option+1,"undefined");
6906 break;
6907 }
6908 (void) SetImageOption(image_info,option+1,argv[i+1]);
6909 break;
6910 }
6911 if (LocaleCompare("interword-spacing",option+1) == 0)
6912 {
6913 if (*option == '+')
6914 {
6915 (void) SetImageOption(image_info,option+1,"undefined");
6916 break;
6917 }
6918 (void) SetImageOption(image_info,option+1,argv[i+1]);
6919 break;
6920 }
6921 break;
6922 }
6923 case 'k':
6924 {
6925 if (LocaleCompare("kerning",option+1) == 0)
6926 {
6927 if (*option == '+')
6928 {
6929 (void) SetImageOption(image_info,option+1,"undefined");
6930 break;
6931 }
6932 (void) SetImageOption(image_info,option+1,argv[i+1]);
6933 break;
6934 }
6935 break;
6936 }
6937 case 'l':
6938 {
6939 if (LocaleCompare("label",option+1) == 0)
6940 {
6941 if (*option == '+')
6942 {
6943 (void) DeleteImageOption(image_info,option+1);
6944 break;
6945 }
6946 (void) SetImageOption(image_info,option+1,argv[i+1]);
6947 break;
6948 }
6949 if (LocaleCompare("limit",option+1) == 0)
6950 {
6951 MagickSizeType
6952 limit;
6953
6954 ResourceType
6955 type;
6956
6957 if (*option == '+')
6958 break;
6959 type=(ResourceType) ParseMagickOption(MagickResourceOptions,
6960 MagickFalse,argv[i+1]);
6961 limit=MagickResourceInfinity;
6962 if (LocaleCompare("unlimited",argv[i+2]) != 0)
cristyf2f27272009-12-17 14:48:46 +00006963 limit=(MagickSizeType) SiPrefixToDouble(argv[i+2],100.0);
cristy3ed852e2009-09-05 21:47:34 +00006964 (void) SetMagickResourceLimit(type,limit);
6965 break;
6966 }
6967 if (LocaleCompare("list",option+1) == 0)
6968 {
cristybb503372010-05-27 20:51:26 +00006969 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006970 list;
6971
6972 /*
6973 Display configuration list.
6974 */
6975 list=ParseMagickOption(MagickListOptions,MagickFalse,argv[i+1]);
6976 switch (list)
6977 {
6978 case MagickCoderOptions:
6979 {
6980 (void) ListCoderInfo((FILE *) NULL,exception);
6981 break;
6982 }
6983 case MagickColorOptions:
6984 {
6985 (void) ListColorInfo((FILE *) NULL,exception);
6986 break;
6987 }
6988 case MagickConfigureOptions:
6989 {
6990 (void) ListConfigureInfo((FILE *) NULL,exception);
6991 break;
6992 }
6993 case MagickDelegateOptions:
6994 {
6995 (void) ListDelegateInfo((FILE *) NULL,exception);
6996 break;
6997 }
6998 case MagickFontOptions:
6999 {
7000 (void) ListTypeInfo((FILE *) NULL,exception);
7001 break;
7002 }
7003 case MagickFormatOptions:
7004 {
7005 (void) ListMagickInfo((FILE *) NULL,exception);
7006 break;
7007 }
7008 case MagickLocaleOptions:
7009 {
7010 (void) ListLocaleInfo((FILE *) NULL,exception);
7011 break;
7012 }
7013 case MagickLogOptions:
7014 {
7015 (void) ListLogInfo((FILE *) NULL,exception);
7016 break;
7017 }
7018 case MagickMagicOptions:
7019 {
7020 (void) ListMagicInfo((FILE *) NULL,exception);
7021 break;
7022 }
7023 case MagickMimeOptions:
7024 {
7025 (void) ListMimeInfo((FILE *) NULL,exception);
7026 break;
7027 }
7028 case MagickModuleOptions:
7029 {
7030 (void) ListModuleInfo((FILE *) NULL,exception);
7031 break;
7032 }
7033 case MagickPolicyOptions:
7034 {
7035 (void) ListPolicyInfo((FILE *) NULL,exception);
7036 break;
7037 }
7038 case MagickResourceOptions:
7039 {
7040 (void) ListMagickResourceInfo((FILE *) NULL,exception);
7041 break;
7042 }
7043 case MagickThresholdOptions:
7044 {
7045 (void) ListThresholdMaps((FILE *) NULL,exception);
7046 break;
7047 }
7048 default:
7049 {
7050 (void) ListMagickOptions((FILE *) NULL,(MagickOption) list,
7051 exception);
7052 break;
7053 }
7054 }
cristyaeb2cbc2010-05-07 13:28:58 +00007055 break;
cristy3ed852e2009-09-05 21:47:34 +00007056 }
7057 if (LocaleCompare("log",option+1) == 0)
7058 {
7059 if (*option == '+')
7060 break;
7061 (void) SetLogFormat(argv[i+1]);
7062 break;
7063 }
7064 if (LocaleCompare("loop",option+1) == 0)
7065 {
7066 if (*option == '+')
7067 {
7068 (void) SetImageOption(image_info,option+1,"0");
7069 break;
7070 }
7071 (void) SetImageOption(image_info,option+1,argv[i+1]);
7072 break;
7073 }
7074 break;
7075 }
7076 case 'm':
7077 {
7078 if (LocaleCompare("matte",option+1) == 0)
7079 {
7080 if (*option == '+')
7081 {
7082 (void) SetImageOption(image_info,option+1,"false");
7083 break;
7084 }
7085 (void) SetImageOption(image_info,option+1,"true");
7086 break;
7087 }
7088 if (LocaleCompare("mattecolor",option+1) == 0)
7089 {
7090 if (*option == '+')
7091 {
7092 (void) SetImageOption(image_info,option+1,argv[i+1]);
7093 (void) QueryColorDatabase(MatteColor,&image_info->matte_color,
7094 exception);
7095 break;
7096 }
7097 (void) SetImageOption(image_info,option+1,argv[i+1]);
7098 (void) QueryColorDatabase(argv[i+1],&image_info->matte_color,
7099 exception);
7100 break;
7101 }
7102 if (LocaleCompare("monitor",option+1) == 0)
7103 {
7104 (void) SetImageInfoProgressMonitor(image_info,MonitorProgress,
7105 (void *) NULL);
7106 break;
7107 }
7108 if (LocaleCompare("monochrome",option+1) == 0)
7109 {
7110 image_info->monochrome=(*option == '-') ? MagickTrue : MagickFalse;
7111 break;
7112 }
7113 break;
7114 }
7115 case 'o':
7116 {
7117 if (LocaleCompare("orient",option+1) == 0)
7118 {
7119 if (*option == '+')
7120 {
7121 image_info->orientation=UndefinedOrientation;
7122 (void) SetImageOption(image_info,option+1,"undefined");
7123 break;
7124 }
7125 image_info->orientation=(OrientationType) ParseMagickOption(
7126 MagickOrientationOptions,MagickFalse,argv[i+1]);
cristyc6e214d2010-08-08 00:31:08 +00007127 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007128 break;
7129 }
7130 }
7131 case 'p':
7132 {
7133 if (LocaleCompare("page",option+1) == 0)
7134 {
7135 char
7136 *canonical_page,
7137 page[MaxTextExtent];
7138
7139 const char
7140 *image_option;
7141
7142 MagickStatusType
7143 flags;
7144
7145 RectangleInfo
7146 geometry;
7147
7148 if (*option == '+')
7149 {
7150 (void) DeleteImageOption(image_info,option+1);
7151 (void) CloneString(&image_info->page,(char *) NULL);
7152 break;
7153 }
7154 (void) ResetMagickMemory(&geometry,0,sizeof(geometry));
7155 image_option=GetImageOption(image_info,"page");
7156 if (image_option != (const char *) NULL)
7157 flags=ParseAbsoluteGeometry(image_option,&geometry);
7158 canonical_page=GetPageGeometry(argv[i+1]);
7159 flags=ParseAbsoluteGeometry(canonical_page,&geometry);
7160 canonical_page=DestroyString(canonical_page);
7161 (void) FormatMagickString(page,MaxTextExtent,"%lux%lu",
cristyf2faecf2010-05-28 19:19:36 +00007162 (unsigned long) geometry.width,(unsigned long) geometry.height);
cristy3ed852e2009-09-05 21:47:34 +00007163 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
7164 (void) FormatMagickString(page,MaxTextExtent,"%lux%lu%+ld%+ld",
cristyf2faecf2010-05-28 19:19:36 +00007165 (unsigned long) geometry.width,(unsigned long) geometry.height,
7166 (long) geometry.x,(long) geometry.y);
cristy3ed852e2009-09-05 21:47:34 +00007167 (void) SetImageOption(image_info,option+1,page);
7168 (void) CloneString(&image_info->page,page);
7169 break;
7170 }
7171 if (LocaleCompare("pen",option+1) == 0)
7172 {
7173 if (*option == '+')
7174 {
7175 (void) SetImageOption(image_info,option+1,"none");
7176 break;
7177 }
7178 (void) SetImageOption(image_info,option+1,argv[i+1]);
7179 break;
7180 }
7181 if (LocaleCompare("ping",option+1) == 0)
7182 {
7183 image_info->ping=(*option == '-') ? MagickTrue : MagickFalse;
7184 break;
7185 }
7186 if (LocaleCompare("pointsize",option+1) == 0)
7187 {
7188 if (*option == '+')
7189 geometry_info.rho=0.0;
7190 else
7191 (void) ParseGeometry(argv[i+1],&geometry_info);
7192 image_info->pointsize=geometry_info.rho;
7193 break;
7194 }
cristye7f51092010-01-17 00:39:37 +00007195 if (LocaleCompare("precision",option+1) == 0)
7196 {
cristybf2766a2010-01-17 03:33:23 +00007197 (void) SetMagickPrecision(StringToInteger(argv[i+1]));
cristye7f51092010-01-17 00:39:37 +00007198 break;
7199 }
cristy3ed852e2009-09-05 21:47:34 +00007200 if (LocaleCompare("preview",option+1) == 0)
7201 {
7202 /*
7203 Preview image.
7204 */
7205 if (*option == '+')
7206 {
7207 image_info->preview_type=UndefinedPreview;
7208 break;
7209 }
7210 image_info->preview_type=(PreviewType) ParseMagickOption(
7211 MagickPreviewOptions,MagickFalse,argv[i+1]);
7212 break;
7213 }
7214 break;
7215 }
7216 case 'q':
7217 {
7218 if (LocaleCompare("quality",option+1) == 0)
7219 {
7220 /*
7221 Set image compression quality.
7222 */
7223 if (*option == '+')
7224 {
7225 image_info->quality=UndefinedCompressionQuality;
7226 (void) SetImageOption(image_info,option+1,"0");
7227 break;
7228 }
cristye27293e2009-12-18 02:53:20 +00007229 image_info->quality=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007230 (void) SetImageOption(image_info,option+1,argv[i+1]);
7231 break;
7232 }
7233 if (LocaleCompare("quiet",option+1) == 0)
7234 {
7235 static WarningHandler
7236 warning_handler = (WarningHandler) NULL;
7237
7238 if (*option == '+')
7239 {
7240 /*
7241 Restore error or warning messages.
7242 */
7243 warning_handler=SetWarningHandler(warning_handler);
7244 break;
7245 }
7246 /*
7247 Suppress error or warning messages.
7248 */
7249 warning_handler=SetWarningHandler((WarningHandler) NULL);
7250 break;
7251 }
7252 break;
7253 }
7254 case 'r':
7255 {
7256 if (LocaleCompare("red-primary",option+1) == 0)
7257 {
7258 if (*option == '+')
7259 {
7260 (void) SetImageOption(image_info,option+1,"0.0");
7261 break;
7262 }
7263 (void) SetImageOption(image_info,option+1,argv[i+1]);
7264 break;
7265 }
7266 break;
7267 }
7268 case 's':
7269 {
7270 if (LocaleCompare("sampling-factor",option+1) == 0)
7271 {
7272 /*
7273 Set image sampling factor.
7274 */
7275 if (*option == '+')
7276 {
7277 if (image_info->sampling_factor != (char *) NULL)
7278 image_info->sampling_factor=DestroyString(
7279 image_info->sampling_factor);
7280 break;
7281 }
7282 (void) CloneString(&image_info->sampling_factor,argv[i+1]);
7283 break;
7284 }
7285 if (LocaleCompare("scene",option+1) == 0)
7286 {
7287 /*
7288 Set image scene.
7289 */
7290 if (*option == '+')
7291 {
7292 image_info->scene=0;
7293 (void) SetImageOption(image_info,option+1,"0");
7294 break;
7295 }
cristye27293e2009-12-18 02:53:20 +00007296 image_info->scene=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007297 (void) SetImageOption(image_info,option+1,argv[i+1]);
7298 break;
7299 }
7300 if (LocaleCompare("seed",option+1) == 0)
7301 {
cristybb503372010-05-27 20:51:26 +00007302 size_t
cristy3ed852e2009-09-05 21:47:34 +00007303 seed;
7304
7305 if (*option == '+')
7306 {
cristybb503372010-05-27 20:51:26 +00007307 seed=(size_t) time((time_t *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00007308 SeedPseudoRandomGenerator(seed);
7309 break;
7310 }
cristye27293e2009-12-18 02:53:20 +00007311 seed=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007312 SeedPseudoRandomGenerator(seed);
7313 break;
7314 }
7315 if (LocaleCompare("size",option+1) == 0)
7316 {
7317 if (*option == '+')
7318 {
7319 if (image_info->size != (char *) NULL)
7320 image_info->size=DestroyString(image_info->size);
7321 break;
7322 }
7323 (void) CloneString(&image_info->size,argv[i+1]);
7324 break;
7325 }
7326 if (LocaleCompare("stroke",option+1) == 0)
7327 {
7328 if (*option == '+')
7329 {
7330 (void) SetImageOption(image_info,option+1,"none");
7331 break;
7332 }
7333 (void) SetImageOption(image_info,option+1,argv[i+1]);
7334 break;
7335 }
7336 if (LocaleCompare("strokewidth",option+1) == 0)
7337 {
7338 if (*option == '+')
7339 {
7340 (void) SetImageOption(image_info,option+1,"0");
7341 break;
7342 }
7343 (void) SetImageOption(image_info,option+1,argv[i+1]);
7344 break;
7345 }
cristyd9a29192010-10-16 16:49:53 +00007346 if (LocaleCompare("synchronize",option+1) == 0)
7347 {
7348 if (*option == '+')
7349 {
7350 image_info->synchronize=MagickFalse;
7351 break;
7352 }
7353 image_info->synchronize=MagickTrue;
7354 break;
7355 }
cristy3ed852e2009-09-05 21:47:34 +00007356 break;
7357 }
7358 case 't':
7359 {
7360 if (LocaleCompare("taint",option+1) == 0)
7361 {
7362 if (*option == '+')
7363 {
7364 (void) SetImageOption(image_info,option+1,"false");
7365 break;
7366 }
7367 (void) SetImageOption(image_info,option+1,"true");
7368 break;
7369 }
7370 if (LocaleCompare("texture",option+1) == 0)
7371 {
7372 if (*option == '+')
7373 {
7374 if (image_info->texture != (char *) NULL)
7375 image_info->texture=DestroyString(image_info->texture);
7376 break;
7377 }
7378 (void) CloneString(&image_info->texture,argv[i+1]);
7379 break;
7380 }
7381 if (LocaleCompare("tile-offset",option+1) == 0)
7382 {
7383 if (*option == '+')
7384 {
7385 (void) SetImageOption(image_info,option+1,"0");
7386 break;
7387 }
7388 (void) SetImageOption(image_info,option+1,argv[i+1]);
7389 break;
7390 }
7391 if (LocaleCompare("transparent-color",option+1) == 0)
7392 {
7393 if (*option == '+')
7394 {
7395 (void) QueryColorDatabase("none",&image_info->transparent_color, exception);
7396 (void) SetImageOption(image_info,option+1,"none");
7397 break;
7398 }
7399 (void) QueryColorDatabase(argv[i+1],&image_info->transparent_color,
7400 exception);
7401 (void) SetImageOption(image_info,option+1,argv[i+1]);
7402 break;
7403 }
7404 if (LocaleCompare("type",option+1) == 0)
7405 {
7406 if (*option == '+')
7407 {
7408 image_info->type=UndefinedType;
7409 (void) SetImageOption(image_info,option+1,"undefined");
7410 break;
7411 }
7412 image_info->type=(ImageType) ParseMagickOption(MagickTypeOptions,
7413 MagickFalse,argv[i+1]);
7414 (void) SetImageOption(image_info,option+1,argv[i+1]);
7415 break;
7416 }
7417 break;
7418 }
7419 case 'u':
7420 {
7421 if (LocaleCompare("undercolor",option+1) == 0)
7422 {
7423 if (*option == '+')
7424 {
7425 (void) DeleteImageOption(image_info,option+1);
7426 break;
7427 }
7428 (void) SetImageOption(image_info,option+1,argv[i+1]);
7429 break;
7430 }
7431 if (LocaleCompare("units",option+1) == 0)
7432 {
7433 if (*option == '+')
7434 {
7435 image_info->units=UndefinedResolution;
7436 (void) SetImageOption(image_info,option+1,"undefined");
7437 break;
7438 }
7439 image_info->units=(ResolutionType) ParseMagickOption(
7440 MagickResolutionOptions,MagickFalse,argv[i+1]);
7441 (void) SetImageOption(image_info,option+1,argv[i+1]);
7442 break;
7443 }
7444 break;
7445 }
7446 case 'v':
7447 {
7448 if (LocaleCompare("verbose",option+1) == 0)
7449 {
7450 if (*option == '+')
7451 {
7452 image_info->verbose=MagickFalse;
7453 break;
7454 }
7455 image_info->verbose=MagickTrue;
7456 image_info->ping=MagickFalse;
7457 break;
7458 }
7459 if (LocaleCompare("view",option+1) == 0)
7460 {
7461 if (*option == '+')
7462 {
7463 if (image_info->view != (char *) NULL)
7464 image_info->view=DestroyString(image_info->view);
7465 break;
7466 }
7467 (void) CloneString(&image_info->view,argv[i+1]);
7468 break;
7469 }
7470 if (LocaleCompare("virtual-pixel",option+1) == 0)
7471 {
7472 if (*option == '+')
7473 {
7474 image_info->virtual_pixel_method=UndefinedVirtualPixelMethod;
7475 (void) SetImageOption(image_info,option+1,"undefined");
7476 break;
7477 }
7478 image_info->virtual_pixel_method=(VirtualPixelMethod)
7479 ParseMagickOption(MagickVirtualPixelOptions,MagickFalse,
7480 argv[i+1]);
7481 (void) SetImageOption(image_info,option+1,argv[i+1]);
7482 break;
7483 }
7484 break;
7485 }
7486 case 'w':
7487 {
7488 if (LocaleCompare("white-point",option+1) == 0)
7489 {
7490 if (*option == '+')
7491 {
7492 (void) SetImageOption(image_info,option+1,"0.0");
7493 break;
7494 }
7495 (void) SetImageOption(image_info,option+1,argv[i+1]);
7496 break;
7497 }
7498 break;
7499 }
7500 default:
7501 break;
7502 }
7503 i+=count;
7504 }
7505 return(MagickTrue);
7506}
7507
7508/*
7509%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7510% %
7511% %
7512% %
7513+ M o g r i f y I m a g e L i s t %
7514% %
7515% %
7516% %
7517%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7518%
7519% MogrifyImageList() applies any command line options that might affect the
7520% entire image list (e.g. -append, -coalesce, etc.).
7521%
7522% The format of the MogrifyImage method is:
7523%
7524% MagickBooleanType MogrifyImageList(ImageInfo *image_info,const int argc,
7525% const char **argv,Image **images,ExceptionInfo *exception)
7526%
7527% A description of each parameter follows:
7528%
7529% o image_info: the image info..
7530%
7531% o argc: Specifies a pointer to an integer describing the number of
7532% elements in the argument vector.
7533%
7534% o argv: Specifies a pointer to a text array containing the command line
7535% arguments.
7536%
7537% o images: the images.
7538%
7539% o exception: return any errors or warnings in this structure.
7540%
7541*/
7542WandExport MagickBooleanType MogrifyImageList(ImageInfo *image_info,
7543 const int argc,const char **argv,Image **images,ExceptionInfo *exception)
7544{
7545 ChannelType
7546 channel;
7547
7548 const char
7549 *option;
7550
cristy6b3da3a2010-06-20 02:21:46 +00007551 ImageInfo
7552 *mogrify_info;
cristy3ed852e2009-09-05 21:47:34 +00007553
7554 MagickStatusType
7555 status;
7556
7557 QuantizeInfo
7558 *quantize_info;
7559
cristybb503372010-05-27 20:51:26 +00007560 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00007561 i;
7562
cristy6b3da3a2010-06-20 02:21:46 +00007563 ssize_t
7564 count,
7565 index;
7566
cristy3ed852e2009-09-05 21:47:34 +00007567 /*
7568 Apply options to the image list.
7569 */
7570 assert(image_info != (ImageInfo *) NULL);
7571 assert(image_info->signature == MagickSignature);
7572 assert(images != (Image **) NULL);
7573 assert((*images)->signature == MagickSignature);
7574 if ((*images)->debug != MagickFalse)
7575 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
7576 (*images)->filename);
7577 if ((argc <= 0) || (*argv == (char *) NULL))
7578 return(MagickTrue);
cristy6b3da3a2010-06-20 02:21:46 +00007579 mogrify_info=CloneImageInfo(image_info);
7580 quantize_info=AcquireQuantizeInfo(mogrify_info);
7581 channel=mogrify_info->channel;
cristy3ed852e2009-09-05 21:47:34 +00007582 status=MagickTrue;
cristybb503372010-05-27 20:51:26 +00007583 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00007584 {
cristy74fe8f12009-10-03 19:09:01 +00007585 if (*images == (Image *) NULL)
7586 break;
cristy3ed852e2009-09-05 21:47:34 +00007587 option=argv[i];
7588 if (IsMagickOption(option) == MagickFalse)
7589 continue;
7590 count=MagickMax(ParseMagickOption(MagickCommandOptions,MagickFalse,option),
7591 0L);
cristycee97112010-05-28 00:44:52 +00007592 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00007593 break;
cristy6b3da3a2010-06-20 02:21:46 +00007594 status=MogrifyImageInfo(mogrify_info,(int) count+1,argv+i,exception);
cristy3ed852e2009-09-05 21:47:34 +00007595 switch (*(option+1))
7596 {
7597 case 'a':
7598 {
7599 if (LocaleCompare("affinity",option+1) == 0)
7600 {
cristy6b3da3a2010-06-20 02:21:46 +00007601 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007602 if (*option == '+')
7603 {
7604 (void) RemapImages(quantize_info,*images,(Image *) NULL);
7605 InheritException(exception,&(*images)->exception);
7606 break;
7607 }
7608 i++;
7609 break;
7610 }
7611 if (LocaleCompare("append",option+1) == 0)
7612 {
7613 Image
7614 *append_image;
7615
cristy6b3da3a2010-06-20 02:21:46 +00007616 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007617 append_image=AppendImages(*images,*option == '-' ? MagickTrue :
7618 MagickFalse,exception);
7619 if (append_image == (Image *) NULL)
7620 {
7621 status=MagickFalse;
7622 break;
7623 }
7624 *images=DestroyImageList(*images);
7625 *images=append_image;
7626 break;
7627 }
7628 if (LocaleCompare("average",option+1) == 0)
7629 {
7630 Image
7631 *average_image;
7632
cristyd18ae7c2010-03-07 17:39:52 +00007633 /*
7634 Average an image sequence (deprecated).
7635 */
cristy6b3da3a2010-06-20 02:21:46 +00007636 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007637 average_image=EvaluateImages(*images,MeanEvaluateOperator,
7638 exception);
cristy3ed852e2009-09-05 21:47:34 +00007639 if (average_image == (Image *) NULL)
7640 {
7641 status=MagickFalse;
7642 break;
7643 }
7644 *images=DestroyImageList(*images);
7645 *images=average_image;
7646 break;
7647 }
7648 break;
7649 }
7650 case 'c':
7651 {
7652 if (LocaleCompare("channel",option+1) == 0)
7653 {
7654 if (*option == '+')
7655 {
7656 channel=DefaultChannels;
7657 break;
7658 }
7659 channel=(ChannelType) ParseChannelOption(argv[i+1]);
7660 break;
7661 }
7662 if (LocaleCompare("clut",option+1) == 0)
7663 {
7664 Image
7665 *clut_image,
7666 *image;
7667
cristy6b3da3a2010-06-20 02:21:46 +00007668 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007669 image=RemoveFirstImageFromList(images);
7670 clut_image=RemoveFirstImageFromList(images);
7671 if (clut_image == (Image *) NULL)
7672 {
7673 status=MagickFalse;
7674 break;
7675 }
7676 (void) ClutImageChannel(image,channel,clut_image);
7677 clut_image=DestroyImage(clut_image);
7678 InheritException(exception,&image->exception);
7679 *images=DestroyImageList(*images);
7680 *images=image;
7681 break;
7682 }
7683 if (LocaleCompare("coalesce",option+1) == 0)
7684 {
7685 Image
7686 *coalesce_image;
7687
cristy6b3da3a2010-06-20 02:21:46 +00007688 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007689 coalesce_image=CoalesceImages(*images,exception);
7690 if (coalesce_image == (Image *) NULL)
7691 {
7692 status=MagickFalse;
7693 break;
7694 }
7695 *images=DestroyImageList(*images);
7696 *images=coalesce_image;
7697 break;
7698 }
7699 if (LocaleCompare("combine",option+1) == 0)
7700 {
7701 Image
7702 *combine_image;
7703
cristy6b3da3a2010-06-20 02:21:46 +00007704 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007705 combine_image=CombineImages(*images,channel,exception);
7706 if (combine_image == (Image *) NULL)
7707 {
7708 status=MagickFalse;
7709 break;
7710 }
7711 *images=DestroyImageList(*images);
7712 *images=combine_image;
7713 break;
7714 }
7715 if (LocaleCompare("composite",option+1) == 0)
7716 {
7717 Image
7718 *mask_image,
7719 *composite_image,
7720 *image;
7721
7722 RectangleInfo
7723 geometry;
7724
cristy6b3da3a2010-06-20 02:21:46 +00007725 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007726 image=RemoveFirstImageFromList(images);
7727 composite_image=RemoveFirstImageFromList(images);
7728 if (composite_image == (Image *) NULL)
7729 {
7730 status=MagickFalse;
7731 break;
7732 }
7733 (void) TransformImage(&composite_image,(char *) NULL,
7734 composite_image->geometry);
7735 SetGeometry(composite_image,&geometry);
7736 (void) ParseAbsoluteGeometry(composite_image->geometry,&geometry);
7737 GravityAdjustGeometry(image->columns,image->rows,image->gravity,
7738 &geometry);
7739 mask_image=RemoveFirstImageFromList(images);
7740 if (mask_image != (Image *) NULL)
7741 {
7742 if ((image->compose == DisplaceCompositeOp) ||
7743 (image->compose == DistortCompositeOp))
7744 {
7745 /*
7746 Merge Y displacement into X displacement image.
7747 */
7748 (void) CompositeImage(composite_image,CopyGreenCompositeOp,
7749 mask_image,0,0);
7750 mask_image=DestroyImage(mask_image);
7751 }
7752 else
7753 {
7754 /*
7755 Set a blending mask for the composition.
7756 */
7757 image->mask=mask_image;
7758 (void) NegateImage(image->mask,MagickFalse);
7759 }
7760 }
7761 (void) CompositeImageChannel(image,channel,image->compose,
7762 composite_image,geometry.x,geometry.y);
7763 if (image->mask != (Image *) NULL)
7764 image->mask=DestroyImage(image->mask);
7765 composite_image=DestroyImage(composite_image);
7766 InheritException(exception,&image->exception);
7767 *images=DestroyImageList(*images);
7768 *images=image;
7769 break;
7770 }
7771 if (LocaleCompare("crop",option+1) == 0)
7772 {
7773 MagickStatusType
7774 flags;
7775
7776 RectangleInfo
7777 geometry;
7778
cristy6b3da3a2010-06-20 02:21:46 +00007779 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007780 flags=ParseGravityGeometry(*images,argv[i+1],&geometry,exception);
7781 if (((geometry.width == 0) && (geometry.height == 0)) ||
7782 ((flags & XValue) != 0) || ((flags & YValue) != 0))
7783 break;
7784 (void) TransformImages(images,argv[i+1],(char *) NULL);
7785 InheritException(exception,&(*images)->exception);
7786 break;
7787 }
7788 break;
7789 }
7790 case 'd':
7791 {
7792 if (LocaleCompare("deconstruct",option+1) == 0)
7793 {
7794 Image
7795 *deconstruct_image;
7796
cristy6b3da3a2010-06-20 02:21:46 +00007797 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007798 deconstruct_image=DeconstructImages(*images,exception);
7799 if (deconstruct_image == (Image *) NULL)
7800 {
7801 status=MagickFalse;
7802 break;
7803 }
7804 *images=DestroyImageList(*images);
7805 *images=deconstruct_image;
7806 break;
7807 }
7808 if (LocaleCompare("delete",option+1) == 0)
7809 {
7810 if (*option == '+')
7811 DeleteImages(images,"-1",exception);
7812 else
7813 DeleteImages(images,argv[i+1],exception);
7814 break;
7815 }
7816 if (LocaleCompare("dither",option+1) == 0)
7817 {
7818 if (*option == '+')
7819 {
7820 quantize_info->dither=MagickFalse;
7821 break;
7822 }
7823 quantize_info->dither=MagickTrue;
7824 quantize_info->dither_method=(DitherMethod) ParseMagickOption(
7825 MagickDitherOptions,MagickFalse,argv[i+1]);
7826 break;
7827 }
7828 break;
7829 }
cristyd18ae7c2010-03-07 17:39:52 +00007830 case 'e':
7831 {
7832 if (LocaleCompare("evaluate-sequence",option+1) == 0)
7833 {
7834 Image
7835 *evaluate_image;
7836
7837 MagickEvaluateOperator
7838 op;
7839
cristy6b3da3a2010-06-20 02:21:46 +00007840 (void) SyncImageSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007841 op=(MagickEvaluateOperator) ParseMagickOption(MagickEvaluateOptions,
7842 MagickFalse,argv[i+1]);
7843 evaluate_image=EvaluateImages(*images,op,exception);
7844 if (evaluate_image == (Image *) NULL)
7845 {
7846 status=MagickFalse;
7847 break;
7848 }
7849 *images=DestroyImageList(*images);
7850 *images=evaluate_image;
7851 break;
7852 }
7853 break;
7854 }
cristy3ed852e2009-09-05 21:47:34 +00007855 case 'f':
7856 {
cristyf0a247f2009-10-04 00:20:03 +00007857 if (LocaleCompare("fft",option+1) == 0)
7858 {
7859 Image
7860 *fourier_image;
7861
7862 /*
7863 Implements the discrete Fourier transform (DFT).
7864 */
cristy6b3da3a2010-06-20 02:21:46 +00007865 (void) SyncImageSettings(mogrify_info,*images);
cristyf0a247f2009-10-04 00:20:03 +00007866 fourier_image=ForwardFourierTransformImage(*images,*option == '-' ?
7867 MagickTrue : MagickFalse,exception);
7868 if (fourier_image == (Image *) NULL)
7869 break;
7870 *images=DestroyImage(*images);
7871 *images=fourier_image;
7872 break;
7873 }
cristy3ed852e2009-09-05 21:47:34 +00007874 if (LocaleCompare("flatten",option+1) == 0)
7875 {
7876 Image
7877 *flatten_image;
7878
cristy6b3da3a2010-06-20 02:21:46 +00007879 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007880 flatten_image=MergeImageLayers(*images,FlattenLayer,exception);
7881 if (flatten_image == (Image *) NULL)
7882 break;
7883 *images=DestroyImageList(*images);
7884 *images=flatten_image;
7885 break;
7886 }
7887 if (LocaleCompare("fx",option+1) == 0)
7888 {
7889 Image
7890 *fx_image;
7891
cristy6b3da3a2010-06-20 02:21:46 +00007892 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007893 fx_image=FxImageChannel(*images,channel,argv[i+1],exception);
7894 if (fx_image == (Image *) NULL)
7895 {
7896 status=MagickFalse;
7897 break;
7898 }
7899 *images=DestroyImageList(*images);
7900 *images=fx_image;
7901 break;
7902 }
7903 break;
7904 }
7905 case 'h':
7906 {
7907 if (LocaleCompare("hald-clut",option+1) == 0)
7908 {
7909 Image
7910 *hald_image,
7911 *image;
7912
cristy6b3da3a2010-06-20 02:21:46 +00007913 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007914 image=RemoveFirstImageFromList(images);
7915 hald_image=RemoveFirstImageFromList(images);
7916 if (hald_image == (Image *) NULL)
7917 {
7918 status=MagickFalse;
7919 break;
7920 }
7921 (void) HaldClutImageChannel(image,channel,hald_image);
7922 hald_image=DestroyImage(hald_image);
7923 InheritException(exception,&image->exception);
cristy0aff6ea2009-11-14 01:40:53 +00007924 if (*images != (Image *) NULL)
7925 *images=DestroyImageList(*images);
cristy3ed852e2009-09-05 21:47:34 +00007926 *images=image;
7927 break;
7928 }
7929 break;
7930 }
7931 case 'i':
7932 {
7933 if (LocaleCompare("ift",option+1) == 0)
7934 {
7935 Image
cristy8587f882009-11-13 20:28:49 +00007936 *fourier_image,
7937 *magnitude_image,
7938 *phase_image;
cristy3ed852e2009-09-05 21:47:34 +00007939
7940 /*
7941 Implements the inverse fourier discrete Fourier transform (DFT).
7942 */
cristy6b3da3a2010-06-20 02:21:46 +00007943 (void) SyncImagesSettings(mogrify_info,*images);
cristy8587f882009-11-13 20:28:49 +00007944 magnitude_image=RemoveFirstImageFromList(images);
7945 phase_image=RemoveFirstImageFromList(images);
7946 if (phase_image == (Image *) NULL)
7947 {
7948 status=MagickFalse;
7949 break;
7950 }
7951 fourier_image=InverseFourierTransformImage(magnitude_image,
7952 phase_image,*option == '-' ? MagickTrue : MagickFalse,exception);
cristy3ed852e2009-09-05 21:47:34 +00007953 if (fourier_image == (Image *) NULL)
7954 break;
cristy0aff6ea2009-11-14 01:40:53 +00007955 if (*images != (Image *) NULL)
7956 *images=DestroyImage(*images);
cristy3ed852e2009-09-05 21:47:34 +00007957 *images=fourier_image;
7958 break;
7959 }
7960 if (LocaleCompare("insert",option+1) == 0)
7961 {
7962 Image
7963 *p,
7964 *q;
7965
7966 index=0;
7967 if (*option != '+')
cristyf2f27272009-12-17 14:48:46 +00007968 index=StringToLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007969 p=RemoveLastImageFromList(images);
7970 if (p == (Image *) NULL)
7971 {
7972 (void) ThrowMagickException(exception,GetMagickModule(),
7973 OptionError,"NoSuchImage","`%s'",argv[i+1]);
7974 status=MagickFalse;
7975 break;
7976 }
7977 q=p;
7978 if (index == 0)
7979 PrependImageToList(images,q);
7980 else
cristybb503372010-05-27 20:51:26 +00007981 if (index == (ssize_t) GetImageListLength(*images))
cristy3ed852e2009-09-05 21:47:34 +00007982 AppendImageToList(images,q);
7983 else
7984 {
7985 q=GetImageFromList(*images,index-1);
7986 if (q == (Image *) NULL)
7987 {
7988 (void) ThrowMagickException(exception,GetMagickModule(),
7989 OptionError,"NoSuchImage","`%s'",argv[i+1]);
7990 status=MagickFalse;
7991 break;
7992 }
7993 InsertImageInList(&q,p);
7994 }
7995 *images=GetFirstImageInList(q);
7996 break;
7997 }
7998 break;
7999 }
8000 case 'l':
8001 {
8002 if (LocaleCompare("layers",option+1) == 0)
8003 {
8004 Image
8005 *layers;
8006
8007 ImageLayerMethod
8008 method;
8009
cristy6b3da3a2010-06-20 02:21:46 +00008010 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00008011 layers=(Image *) NULL;
8012 method=(ImageLayerMethod) ParseMagickOption(MagickLayerOptions,
8013 MagickFalse,argv[i+1]);
8014 switch (method)
8015 {
8016 case CoalesceLayer:
8017 {
8018 layers=CoalesceImages(*images,exception);
8019 break;
8020 }
8021 case CompareAnyLayer:
8022 case CompareClearLayer:
8023 case CompareOverlayLayer:
8024 default:
8025 {
8026 layers=CompareImageLayers(*images,method,exception);
8027 break;
8028 }
8029 case MergeLayer:
8030 case FlattenLayer:
8031 case MosaicLayer:
8032 case TrimBoundsLayer:
8033 {
8034 layers=MergeImageLayers(*images,method,exception);
8035 break;
8036 }
8037 case DisposeLayer:
8038 {
8039 layers=DisposeImages(*images,exception);
8040 break;
8041 }
8042 case OptimizeImageLayer:
8043 {
8044 layers=OptimizeImageLayers(*images,exception);
8045 break;
8046 }
8047 case OptimizePlusLayer:
8048 {
8049 layers=OptimizePlusImageLayers(*images,exception);
8050 break;
8051 }
8052 case OptimizeTransLayer:
8053 {
8054 OptimizeImageTransparency(*images,exception);
8055 break;
8056 }
8057 case RemoveDupsLayer:
8058 {
8059 RemoveDuplicateLayers(images,exception);
8060 break;
8061 }
8062 case RemoveZeroLayer:
8063 {
8064 RemoveZeroDelayLayers(images,exception);
8065 break;
8066 }
8067 case OptimizeLayer:
8068 {
8069 /*
8070 General Purpose, GIF Animation Optimizer.
8071 */
8072 layers=CoalesceImages(*images,exception);
8073 if (layers == (Image *) NULL)
8074 {
8075 status=MagickFalse;
8076 break;
8077 }
8078 InheritException(exception,&layers->exception);
8079 *images=DestroyImageList(*images);
8080 *images=layers;
8081 layers=OptimizeImageLayers(*images,exception);
8082 if (layers == (Image *) NULL)
8083 {
8084 status=MagickFalse;
8085 break;
8086 }
8087 InheritException(exception,&layers->exception);
8088 *images=DestroyImageList(*images);
8089 *images=layers;
8090 layers=(Image *) NULL;
8091 OptimizeImageTransparency(*images,exception);
8092 InheritException(exception,&(*images)->exception);
8093 (void) RemapImages(quantize_info,*images,(Image *) NULL);
8094 break;
8095 }
8096 case CompositeLayer:
8097 {
8098 CompositeOperator
8099 compose;
8100
8101 Image
8102 *source;
8103
8104 RectangleInfo
8105 geometry;
8106
8107 /*
8108 Split image sequence at the first 'NULL:' image.
8109 */
8110 source=(*images);
8111 while (source != (Image *) NULL)
8112 {
8113 source=GetNextImageInList(source);
8114 if ((source != (Image *) NULL) &&
8115 (LocaleCompare(source->magick,"NULL") == 0))
8116 break;
8117 }
8118 if (source != (Image *) NULL)
8119 {
8120 if ((GetPreviousImageInList(source) == (Image *) NULL) ||
8121 (GetNextImageInList(source) == (Image *) NULL))
8122 source=(Image *) NULL;
8123 else
8124 {
8125 /*
8126 Separate the two lists, junk the null: image.
8127 */
8128 source=SplitImageList(source->previous);
8129 DeleteImageFromList(&source);
8130 }
8131 }
8132 if (source == (Image *) NULL)
8133 {
8134 (void) ThrowMagickException(exception,GetMagickModule(),
8135 OptionError,"MissingNullSeparator","layers Composite");
8136 status=MagickFalse;
8137 break;
8138 }
8139 /*
8140 Adjust offset with gravity and virtual canvas.
8141 */
8142 SetGeometry(*images,&geometry);
8143 (void) ParseAbsoluteGeometry((*images)->geometry,&geometry);
8144 geometry.width=source->page.width != 0 ?
8145 source->page.width : source->columns;
8146 geometry.height=source->page.height != 0 ?
8147 source->page.height : source->rows;
8148 GravityAdjustGeometry((*images)->page.width != 0 ?
8149 (*images)->page.width : (*images)->columns,
8150 (*images)->page.height != 0 ? (*images)->page.height :
8151 (*images)->rows,(*images)->gravity,&geometry);
8152 compose=OverCompositeOp;
cristy6b3da3a2010-06-20 02:21:46 +00008153 option=GetImageOption(mogrify_info,"compose");
cristy3ed852e2009-09-05 21:47:34 +00008154 if (option != (const char *) NULL)
8155 compose=(CompositeOperator) ParseMagickOption(
8156 MagickComposeOptions,MagickFalse,option);
8157 CompositeLayers(*images,compose,source,geometry.x,geometry.y,
8158 exception);
8159 source=DestroyImageList(source);
8160 break;
8161 }
8162 }
8163 if (layers == (Image *) NULL)
8164 break;
8165 InheritException(exception,&layers->exception);
8166 *images=DestroyImageList(*images);
8167 *images=layers;
8168 break;
8169 }
8170 break;
8171 }
8172 case 'm':
8173 {
8174 if (LocaleCompare("map",option+1) == 0)
8175 {
cristy6b3da3a2010-06-20 02:21:46 +00008176 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00008177 if (*option == '+')
8178 {
8179 (void) RemapImages(quantize_info,*images,(Image *) NULL);
8180 InheritException(exception,&(*images)->exception);
8181 break;
8182 }
8183 i++;
8184 break;
8185 }
cristyf40785b2010-03-06 02:27:27 +00008186 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00008187 {
8188 Image
cristyf40785b2010-03-06 02:27:27 +00008189 *maximum_image;
cristy1c274c92010-03-06 02:06:45 +00008190
cristyd18ae7c2010-03-07 17:39:52 +00008191 /*
8192 Maximum image sequence (deprecated).
8193 */
cristy6b3da3a2010-06-20 02:21:46 +00008194 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00008195 maximum_image=EvaluateImages(*images,MaxEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00008196 if (maximum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00008197 {
8198 status=MagickFalse;
8199 break;
8200 }
8201 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00008202 *images=maximum_image;
cristy1c274c92010-03-06 02:06:45 +00008203 break;
8204 }
cristyf40785b2010-03-06 02:27:27 +00008205 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00008206 {
8207 Image
cristyf40785b2010-03-06 02:27:27 +00008208 *minimum_image;
cristy1c274c92010-03-06 02:06:45 +00008209
cristyd18ae7c2010-03-07 17:39:52 +00008210 /*
8211 Minimum image sequence (deprecated).
8212 */
cristy6b3da3a2010-06-20 02:21:46 +00008213 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00008214 minimum_image=EvaluateImages(*images,MinEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00008215 if (minimum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00008216 {
8217 status=MagickFalse;
8218 break;
8219 }
8220 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00008221 *images=minimum_image;
cristy1c274c92010-03-06 02:06:45 +00008222 break;
8223 }
cristy3ed852e2009-09-05 21:47:34 +00008224 if (LocaleCompare("morph",option+1) == 0)
8225 {
8226 Image
8227 *morph_image;
8228
cristy6b3da3a2010-06-20 02:21:46 +00008229 (void) SyncImagesSettings(mogrify_info,*images);
cristye27293e2009-12-18 02:53:20 +00008230 morph_image=MorphImages(*images,StringToUnsignedLong(argv[i+1]),
cristy3ed852e2009-09-05 21:47:34 +00008231 exception);
8232 if (morph_image == (Image *) NULL)
8233 {
8234 status=MagickFalse;
8235 break;
8236 }
8237 *images=DestroyImageList(*images);
8238 *images=morph_image;
8239 break;
8240 }
8241 if (LocaleCompare("mosaic",option+1) == 0)
8242 {
8243 Image
8244 *mosaic_image;
8245
cristy6b3da3a2010-06-20 02:21:46 +00008246 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00008247 mosaic_image=MergeImageLayers(*images,MosaicLayer,exception);
8248 if (mosaic_image == (Image *) NULL)
8249 {
8250 status=MagickFalse;
8251 break;
8252 }
8253 *images=DestroyImageList(*images);
8254 *images=mosaic_image;
8255 break;
8256 }
8257 break;
8258 }
8259 case 'p':
8260 {
8261 if (LocaleCompare("print",option+1) == 0)
8262 {
8263 char
8264 *string;
8265
cristy6b3da3a2010-06-20 02:21:46 +00008266 (void) SyncImagesSettings(mogrify_info,*images);
8267 string=InterpretImageProperties(mogrify_info,*images,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00008268 if (string == (char *) NULL)
8269 break;
8270 InheritException(exception,&(*images)->exception);
8271 (void) fprintf(stdout,"%s",string);
8272 string=DestroyString(string);
8273 }
8274 if (LocaleCompare("process",option+1) == 0)
8275 {
8276 char
8277 **arguments;
8278
8279 int
8280 j,
8281 number_arguments;
8282
cristy6b3da3a2010-06-20 02:21:46 +00008283 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00008284 arguments=StringToArgv(argv[i+1],&number_arguments);
8285 if (arguments == (char **) NULL)
8286 break;
8287 if ((argc > 1) && (strchr(arguments[1],'=') != (char *) NULL))
8288 {
8289 char
8290 breaker,
8291 quote,
8292 *token;
8293
8294 const char
8295 *arguments;
8296
8297 int
8298 next,
8299 status;
8300
8301 size_t
8302 length;
8303
8304 TokenInfo
8305 *token_info;
8306
8307 /*
8308 Support old style syntax, filter="-option arg".
8309 */
8310 length=strlen(argv[i+1]);
8311 token=(char *) NULL;
8312 if (~length >= MaxTextExtent)
8313 token=(char *) AcquireQuantumMemory(length+MaxTextExtent,
8314 sizeof(*token));
8315 if (token == (char *) NULL)
8316 break;
8317 next=0;
8318 arguments=argv[i+1];
8319 token_info=AcquireTokenInfo();
8320 status=Tokenizer(token_info,0,token,length,arguments,"","=",
8321 "\"",'\0',&breaker,&next,&quote);
8322 token_info=DestroyTokenInfo(token_info);
8323 if (status == 0)
8324 {
8325 const char
8326 *argv;
8327
8328 argv=(&(arguments[next]));
8329 (void) InvokeDynamicImageFilter(token,&(*images),1,&argv,
8330 exception);
8331 }
8332 token=DestroyString(token);
8333 break;
8334 }
cristy91c0da22010-05-02 01:44:07 +00008335 (void) SubstituteString(&arguments[1],"-","");
cristy3ed852e2009-09-05 21:47:34 +00008336 (void) InvokeDynamicImageFilter(arguments[1],&(*images),
8337 number_arguments-2,(const char **) arguments+2,exception);
8338 for (j=0; j < number_arguments; j++)
8339 arguments[j]=DestroyString(arguments[j]);
8340 arguments=(char **) RelinquishMagickMemory(arguments);
8341 break;
8342 }
8343 break;
8344 }
8345 case 'r':
8346 {
8347 if (LocaleCompare("reverse",option+1) == 0)
8348 {
8349 ReverseImageList(images);
8350 InheritException(exception,&(*images)->exception);
8351 break;
8352 }
8353 break;
8354 }
8355 case 's':
8356 {
8357 if (LocaleCompare("swap",option+1) == 0)
8358 {
8359 Image
8360 *p,
8361 *q,
8362 *swap;
8363
cristybb503372010-05-27 20:51:26 +00008364 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00008365 swap_index;
8366
8367 index=(-1);
8368 swap_index=(-2);
8369 if (*option != '+')
8370 {
8371 GeometryInfo
8372 geometry_info;
8373
8374 MagickStatusType
8375 flags;
8376
8377 swap_index=(-1);
8378 flags=ParseGeometry(argv[i+1],&geometry_info);
cristybb503372010-05-27 20:51:26 +00008379 index=(ssize_t) geometry_info.rho;
cristy3ed852e2009-09-05 21:47:34 +00008380 if ((flags & SigmaValue) != 0)
cristybb503372010-05-27 20:51:26 +00008381 swap_index=(ssize_t) geometry_info.sigma;
cristy3ed852e2009-09-05 21:47:34 +00008382 }
8383 p=GetImageFromList(*images,index);
8384 q=GetImageFromList(*images,swap_index);
8385 if ((p == (Image *) NULL) || (q == (Image *) NULL))
8386 {
8387 (void) ThrowMagickException(exception,GetMagickModule(),
8388 OptionError,"NoSuchImage","`%s'",(*images)->filename);
8389 status=MagickFalse;
8390 break;
8391 }
8392 if (p == q)
8393 break;
8394 swap=CloneImage(p,0,0,MagickTrue,exception);
8395 ReplaceImageInList(&p,CloneImage(q,0,0,MagickTrue,exception));
8396 ReplaceImageInList(&q,swap);
8397 *images=GetFirstImageInList(q);
8398 break;
8399 }
8400 break;
8401 }
8402 case 'w':
8403 {
8404 if (LocaleCompare("write",option+1) == 0)
8405 {
cristy071dd7b2010-04-09 13:04:54 +00008406 char
cristy06609ee2010-03-17 20:21:27 +00008407 key[MaxTextExtent];
8408
cristy3ed852e2009-09-05 21:47:34 +00008409 Image
8410 *write_images;
8411
8412 ImageInfo
8413 *write_info;
8414
cristy6b3da3a2010-06-20 02:21:46 +00008415 (void) SyncImagesSettings(mogrify_info,*images);
cristy06609ee2010-03-17 20:21:27 +00008416 (void) FormatMagickString(key,MaxTextExtent,"cache:%s",argv[i+1]);
8417 (void) DeleteImageRegistry(key);
cristy3ed852e2009-09-05 21:47:34 +00008418 write_images=(*images);
8419 if (*option == '+')
8420 write_images=CloneImageList(*images,exception);
cristy6b3da3a2010-06-20 02:21:46 +00008421 write_info=CloneImageInfo(mogrify_info);
cristy3ed852e2009-09-05 21:47:34 +00008422 status&=WriteImages(write_info,write_images,argv[i+1],exception);
8423 write_info=DestroyImageInfo(write_info);
8424 if (*option == '+')
8425 write_images=DestroyImageList(write_images);
8426 break;
8427 }
8428 break;
8429 }
8430 default:
8431 break;
8432 }
8433 i+=count;
8434 }
8435 quantize_info=DestroyQuantizeInfo(quantize_info);
cristy6b3da3a2010-06-20 02:21:46 +00008436 mogrify_info=DestroyImageInfo(mogrify_info);
8437 status&=MogrifyImageInfo(image_info,argc,argv,exception);
cristy3ed852e2009-09-05 21:47:34 +00008438 return(status != 0 ? MagickTrue : MagickFalse);
8439}
8440
8441/*
8442%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8443% %
8444% %
8445% %
8446+ M o g r i f y I m a g e s %
8447% %
8448% %
8449% %
8450%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8451%
8452% MogrifyImages() applies image processing options to a sequence of images as
8453% prescribed by command line options.
8454%
8455% The format of the MogrifyImage method is:
8456%
8457% MagickBooleanType MogrifyImages(ImageInfo *image_info,
8458% const MagickBooleanType post,const int argc,const char **argv,
8459% Image **images,Exceptioninfo *exception)
8460%
8461% A description of each parameter follows:
8462%
8463% o image_info: the image info..
8464%
8465% o post: If true, post process image list operators otherwise pre-process.
8466%
8467% o argc: Specifies a pointer to an integer describing the number of
8468% elements in the argument vector.
8469%
8470% o argv: Specifies a pointer to a text array containing the command line
8471% arguments.
8472%
8473% o images: the images.
8474%
8475% o exception: return any errors or warnings in this structure.
8476%
8477*/
8478WandExport MagickBooleanType MogrifyImages(ImageInfo *image_info,
8479 const MagickBooleanType post,const int argc,const char **argv,
8480 Image **images,ExceptionInfo *exception)
8481{
8482#define MogrifyImageTag "Mogrify/Image"
8483
8484 Image
8485 *image,
8486 *mogrify_images;
8487
cristy0e9f9c12010-02-11 03:00:47 +00008488 MagickBooleanType
8489 proceed;
8490
8491 MagickSizeType
8492 number_images;
8493
cristy3ed852e2009-09-05 21:47:34 +00008494 MagickStatusType
8495 status;
8496
cristybb503372010-05-27 20:51:26 +00008497 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00008498 i;
8499
cristy3ed852e2009-09-05 21:47:34 +00008500 /*
8501 Apply options to individual images in the list.
8502 */
8503 assert(image_info != (ImageInfo *) NULL);
8504 assert(image_info->signature == MagickSignature);
8505 if (images == (Image **) NULL)
8506 return(MogrifyImage(image_info,argc,argv,images,exception));
8507 assert((*images)->signature == MagickSignature);
8508 if ((*images)->debug != MagickFalse)
8509 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
8510 (*images)->filename);
8511 if ((argc <= 0) || (*argv == (char *) NULL))
8512 return(MagickTrue);
8513 (void) SetImageInfoProgressMonitor(image_info,(MagickProgressMonitor) NULL,
8514 (void *) NULL);
8515 mogrify_images=NewImageList();
8516 number_images=GetImageListLength(*images);
8517 status=0;
8518 if (post == MagickFalse)
8519 status&=MogrifyImageList(image_info,argc,argv,images,exception);
cristybb503372010-05-27 20:51:26 +00008520 for (i=0; i < (ssize_t) number_images; i++)
cristy3ed852e2009-09-05 21:47:34 +00008521 {
8522 image=RemoveFirstImageFromList(images);
8523 if (image == (Image *) NULL)
8524 continue;
8525 status&=MogrifyImage(image_info,argc,argv,&image,exception);
8526 AppendImageToList(&mogrify_images,image);
cristy0e9f9c12010-02-11 03:00:47 +00008527 proceed=SetImageProgress(image,MogrifyImageTag,(MagickOffsetType) i,
8528 number_images);
8529 if (proceed == MagickFalse)
8530 break;
cristy3ed852e2009-09-05 21:47:34 +00008531 }
8532 if (post != MagickFalse)
8533 status&=MogrifyImageList(image_info,argc,argv,&mogrify_images,exception);
8534 *images=mogrify_images;
8535 return(status != 0 ? MagickTrue : MagickFalse);
8536}