blob: 0b2e82f99c6261c7b0effc926939ed6c4661f20f [file] [log] [blame]
cristy3ed852e2009-09-05 21:47:34 +00001/*
2%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3% %
4% %
5% %
6% M M OOO GGGGG RRRR IIIII FFFFF Y Y %
7% MM MM O O G R R I F Y Y %
8% M M M O O G GGG RRRR I FFF Y %
9% M M O O G G R R I F Y %
10% M M OOO GGGG R R IIIII F Y %
11% %
12% %
13% MagickWand Module Methods %
14% %
15% Software Design %
16% John Cristy %
17% March 2000 %
18% %
19% %
cristy7e41fe82010-12-04 23:12:08 +000020% Copyright 1999-2011 ImageMagick Studio LLC, a non-profit organization %
cristy3ed852e2009-09-05 21:47:34 +000021% dedicated to making software imaging solutions freely available. %
22% %
23% You may not use this file except in compliance with the License. You may %
24% obtain a copy of the License at %
25% %
26% http://www.imagemagick.org/script/license.php %
27% %
28% Unless required by applicable law or agreed to in writing, software %
29% distributed under the License is distributed on an "AS IS" BASIS, %
30% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
31% See the License for the specific language governing permissions and %
32% limitations under the License. %
33% %
34%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35%
36% Use the mogrify program to resize an image, blur, crop, despeckle, dither,
37% draw on, flip, join, re-sample, and much more. This tool is similiar to
38% convert except that the original image file is overwritten (unless you
39% change the file suffix with the -format option) with any changes you
cristy6a917d92009-10-06 19:23:54 +000040% request.
cristy3ed852e2009-09-05 21:47:34 +000041%
42*/
43
44/*
45 Include declarations.
46*/
cristy4c08aed2011-07-01 19:47:50 +000047#include "MagickWand/studio.h"
48#include "MagickWand/MagickWand.h"
49#include "MagickWand/mogrify-private.h"
50#undef DegreesToRadians
51#undef RadiansToDegrees
52#include "MagickCore/image-private.h"
53#include "MagickCore/monitor-private.h"
54#include "MagickCore/thread-private.h"
55#include "MagickCore/string-private.h"
cristy3ed852e2009-09-05 21:47:34 +000056
57/*
58 Define declarations.
59*/
60#define UndefinedCompressionQuality 0UL
61
62/*
cristy3ed852e2009-09-05 21:47:34 +000063%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
64% %
65% %
66% %
cristy5063d812010-10-19 16:28:10 +000067% M a g i c k C o m m a n d G e n e s i s %
cristy3980b0d2009-10-25 14:37:13 +000068% %
69% %
70% %
71%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
72%
73% MagickCommandGenesis() applies image processing options to an image as
74% prescribed by command line options.
75%
76% The format of the MagickCommandGenesis method is:
77%
78% MagickBooleanType MagickCommandGenesis(ImageInfo *image_info,
cristy5063d812010-10-19 16:28:10 +000079% MagickCommand command,int argc,char **argv,char **metadata,
80% ExceptionInfo *exception)
cristy3980b0d2009-10-25 14:37:13 +000081%
82% A description of each parameter follows:
83%
84% o image_info: the image info.
85%
cristy5063d812010-10-19 16:28:10 +000086% o command: Choose from ConvertImageCommand, IdentifyImageCommand,
cristy8a9106f2011-07-05 14:39:26 +000087% MogrifyImageCommand, CompositeImageCommand, CompareImagesCommand,
cristy5063d812010-10-19 16:28:10 +000088% ConjureImageCommand, StreamImageCommand, ImportImageCommand,
89% DisplayImageCommand, or AnimateImageCommand.
cristy3980b0d2009-10-25 14:37:13 +000090%
91% o argc: Specifies a pointer to an integer describing the number of
92% elements in the argument vector.
93%
94% o argv: Specifies a pointer to a text array containing the command line
95% arguments.
96%
cristy5063d812010-10-19 16:28:10 +000097% o metadata: any metadata is returned here.
cristy3980b0d2009-10-25 14:37:13 +000098%
99% o exception: return any errors or warnings in this structure.
100%
101*/
102WandExport MagickBooleanType MagickCommandGenesis(ImageInfo *image_info,
103 MagickCommand command,int argc,char **argv,char **metadata,
104 ExceptionInfo *exception)
105{
106 char
107 *option;
108
109 double
110 duration,
111 elapsed_time,
112 user_time;
113
cristy3980b0d2009-10-25 14:37:13 +0000114 MagickBooleanType
115 concurrent,
116 regard_warnings,
117 status;
118
cristybb503372010-05-27 20:51:26 +0000119 register ssize_t
cristy3980b0d2009-10-25 14:37:13 +0000120 i;
121
122 TimerInfo
123 *timer;
124
cristybb503372010-05-27 20:51:26 +0000125 size_t
cristy3980b0d2009-10-25 14:37:13 +0000126 iterations;
127
cristyd0a94fa2010-03-12 14:18:11 +0000128 (void) setlocale(LC_ALL,"");
129 (void) setlocale(LC_NUMERIC,"C");
cristy3980b0d2009-10-25 14:37:13 +0000130 concurrent=MagickFalse;
131 duration=(-1.0);
132 iterations=1;
cristy33557d72009-11-06 00:54:33 +0000133 status=MagickFalse;
cristy3980b0d2009-10-25 14:37:13 +0000134 regard_warnings=MagickFalse;
cristybb503372010-05-27 20:51:26 +0000135 for (i=1; i < (ssize_t) (argc-1); i++)
cristy3980b0d2009-10-25 14:37:13 +0000136 {
137 option=argv[i];
138 if ((strlen(option) == 1) || ((*option != '-') && (*option != '+')))
139 continue;
140 if (LocaleCompare("bench",option+1) == 0)
cristye27293e2009-12-18 02:53:20 +0000141 iterations=StringToUnsignedLong(argv[++i]);
cristy3980b0d2009-10-25 14:37:13 +0000142 if (LocaleCompare("concurrent",option+1) == 0)
143 concurrent=MagickTrue;
144 if (LocaleCompare("debug",option+1) == 0)
145 (void) SetLogEventMask(argv[++i]);
146 if (LocaleCompare("duration",option+1) == 0)
cristyc1acd842011-05-19 23:05:47 +0000147 duration=InterpretLocaleValue(argv[++i],(char **) NULL);
cristy3980b0d2009-10-25 14:37:13 +0000148 if (LocaleCompare("regard-warnings",option+1) == 0)
149 regard_warnings=MagickTrue;
150 }
151 timer=AcquireTimerInfo();
cristyceae09d2009-10-28 17:18:47 +0000152 if (concurrent == MagickFalse)
cristy3980b0d2009-10-25 14:37:13 +0000153 {
cristybb503372010-05-27 20:51:26 +0000154 for (i=0; i < (ssize_t) iterations; i++)
cristy3980b0d2009-10-25 14:37:13 +0000155 {
cristy33557d72009-11-06 00:54:33 +0000156 if (status != MagickFalse)
cristyceae09d2009-10-28 17:18:47 +0000157 continue;
158 if (duration > 0)
159 {
160 if (GetElapsedTime(timer) > duration)
161 continue;
162 (void) ContinueTimer(timer);
163 }
164 status=command(image_info,argc,argv,metadata,exception);
cristy3980b0d2009-10-25 14:37:13 +0000165 if (exception->severity != UndefinedException)
166 {
167 if ((exception->severity > ErrorException) ||
168 (regard_warnings != MagickFalse))
169 status=MagickTrue;
170 CatchException(exception);
171 }
cristy3d1a5512009-10-25 21:23:27 +0000172 if ((metadata != (char **) NULL) && (*metadata != (char *) NULL))
cristy3980b0d2009-10-25 14:37:13 +0000173 {
174 (void) fputs(*metadata,stdout);
175 (void) fputc('\n',stdout);
176 *metadata=DestroyString(*metadata);
177 }
178 }
179 }
cristyceae09d2009-10-28 17:18:47 +0000180 else
181 {
182 SetOpenMPNested(1);
cristyb5d5f722009-11-04 03:03:49 +0000183#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristyceae09d2009-10-28 17:18:47 +0000184 # pragma omp parallel for shared(status)
185#endif
cristybb503372010-05-27 20:51:26 +0000186 for (i=0; i < (ssize_t) iterations; i++)
cristyceae09d2009-10-28 17:18:47 +0000187 {
cristy33557d72009-11-06 00:54:33 +0000188 if (status != MagickFalse)
cristyceae09d2009-10-28 17:18:47 +0000189 continue;
190 if (duration > 0)
191 {
192 if (GetElapsedTime(timer) > duration)
193 continue;
194 (void) ContinueTimer(timer);
195 }
196 status=command(image_info,argc,argv,metadata,exception);
cristyb5d5f722009-11-04 03:03:49 +0000197#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy524549f2010-06-20 21:10:20 +0000198 # pragma omp critical (MagickCore_CommandGenesis)
cristyceae09d2009-10-28 17:18:47 +0000199#endif
200 {
201 if (exception->severity != UndefinedException)
202 {
203 if ((exception->severity > ErrorException) ||
204 (regard_warnings != MagickFalse))
205 status=MagickTrue;
206 CatchException(exception);
207 }
208 if ((metadata != (char **) NULL) && (*metadata != (char *) NULL))
209 {
210 (void) fputs(*metadata,stdout);
211 (void) fputc('\n',stdout);
212 *metadata=DestroyString(*metadata);
213 }
214 }
215 }
216 }
cristy3980b0d2009-10-25 14:37:13 +0000217 if (iterations > 1)
218 {
219 elapsed_time=GetElapsedTime(timer);
220 user_time=GetUserTime(timer);
cristyb51dff52011-05-19 16:55:47 +0000221 (void) FormatLocaleFile(stderr,
cristye8c25f92010-06-03 00:53:06 +0000222 "Performance: %.20gi %gips %0.3fu %.20g:%02g.%03g\n",(double)
223 iterations,1.0*iterations/elapsed_time,user_time,(double)
224 (elapsed_time/60.0),floor(fmod(elapsed_time,60.0)),(double)
225 (1000.0*(elapsed_time-floor(elapsed_time))));
cristy524549f2010-06-20 21:10:20 +0000226 (void) fflush(stderr);
cristy3980b0d2009-10-25 14:37:13 +0000227 }
228 timer=DestroyTimerInfo(timer);
cristy1f9e1ed2009-11-18 04:09:38 +0000229 return(status);
cristy3980b0d2009-10-25 14:37:13 +0000230}
231
232/*
233%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
234% %
235% %
236% %
cristy3ed852e2009-09-05 21:47:34 +0000237+ M o g r i f y I m a g e %
238% %
239% %
240% %
241%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
242%
anthonye9c27192011-03-27 08:07:06 +0000243% MogrifyImage() applies simple single image processing options to a single
anthonydf8ebac2011-04-27 09:03:19 +0000244% image that may be part of a large list, but also handles any 'region'
245% image handling.
anthonye9c27192011-03-27 08:07:06 +0000246%
247% The image in the list may be modified in three different ways...
248%
249% * directly modified (EG: -negate, -gamma, -level, -annotate, -draw),
250% * replaced by a new image (EG: -spread, -resize, -rotate, -morphology)
251% * replace by a list of images (only the -separate option!)
252%
253% In each case the result is returned into the list, and a pointer to the
254% modified image (last image added if replaced by a list of images) is
255% returned.
256%
257% ASIDE: The -crop is present but restricted to non-tile single image crops
258%
259% This means if all the images are being processed (such as by
260% MogrifyImages(), next image to be processed will be as per the pointer
261% (*image)->next. Also the image list may grow as a result of some specific
262% operations but as images are never merged or deleted, it will never shrink
263% in length. Typically the list will remain the same length.
264%
265% WARNING: As the image pointed to may be replaced, the first image in the
266% list may also change. GetFirstImageInList() should be used by caller if
267% they wish return the Image pointer to the first image in list.
268%
cristy3ed852e2009-09-05 21:47:34 +0000269%
270% The format of the MogrifyImage method is:
271%
272% MagickBooleanType MogrifyImage(ImageInfo *image_info,const int argc,
273% const char **argv,Image **image)
274%
275% A description of each parameter follows:
276%
277% o image_info: the image info..
278%
279% o argc: Specifies a pointer to an integer describing the number of
280% elements in the argument vector.
281%
282% o argv: Specifies a pointer to a text array containing the command line
283% arguments.
284%
285% o image: the image.
286%
287% o exception: return any errors or warnings in this structure.
288%
289*/
290
cristy4c08aed2011-07-01 19:47:50 +0000291/*
292** GetImageCache() will read an image into a image cache if not already
293** present then return the image that is in the cache under that filename.
294*/
anthonydf8ebac2011-04-27 09:03:19 +0000295static inline Image *GetImageCache(const ImageInfo *image_info,const char *path,
296 ExceptionInfo *exception)
297{
298 char
299 key[MaxTextExtent];
300
301 ExceptionInfo
302 *sans_exception;
303
304 Image
305 *image;
306
307 ImageInfo
308 *read_info;
309
cristyb51dff52011-05-19 16:55:47 +0000310 (void) FormatLocaleString(key,MaxTextExtent,"cache:%s",path);
anthonydf8ebac2011-04-27 09:03:19 +0000311 sans_exception=AcquireExceptionInfo();
312 image=(Image *) GetImageRegistry(ImageRegistryType,key,sans_exception);
313 sans_exception=DestroyExceptionInfo(sans_exception);
314 if (image != (Image *) NULL)
315 return(image);
316 read_info=CloneImageInfo(image_info);
317 (void) CopyMagickString(read_info->filename,path,MaxTextExtent);
318 image=ReadImage(read_info,exception);
319 read_info=DestroyImageInfo(read_info);
320 if (image != (Image *) NULL)
321 (void) SetImageRegistry(ImageRegistryType,key,image,exception);
322 return(image);
323}
324
cristy3ed852e2009-09-05 21:47:34 +0000325static MagickBooleanType IsPathWritable(const char *path)
326{
327 if (IsPathAccessible(path) == MagickFalse)
328 return(MagickFalse);
329 if (access(path,W_OK) != 0)
330 return(MagickFalse);
331 return(MagickTrue);
332}
333
cristybb503372010-05-27 20:51:26 +0000334static inline ssize_t MagickMax(const ssize_t x,const ssize_t y)
cristy3ed852e2009-09-05 21:47:34 +0000335{
336 if (x > y)
337 return(x);
338 return(y);
339}
340
anthonydf8ebac2011-04-27 09:03:19 +0000341static MagickBooleanType MonitorProgress(const char *text,
342 const MagickOffsetType offset,const MagickSizeType extent,
343 void *wand_unused(client_data))
344{
345 char
346 message[MaxTextExtent],
347 tag[MaxTextExtent];
348
349 const char
350 *locale_message;
351
352 register char
353 *p;
354
355 if (extent < 2)
356 return(MagickTrue);
357 (void) CopyMagickMemory(tag,text,MaxTextExtent);
358 p=strrchr(tag,'/');
359 if (p != (char *) NULL)
360 *p='\0';
cristyb51dff52011-05-19 16:55:47 +0000361 (void) FormatLocaleString(message,MaxTextExtent,"Monitor/%s",tag);
anthonydf8ebac2011-04-27 09:03:19 +0000362 locale_message=GetLocaleMessage(message);
363 if (locale_message == message)
364 locale_message=tag;
365 if (p == (char *) NULL)
cristy1e604812011-05-19 18:07:50 +0000366 (void) FormatLocaleFile(stderr,"%s: %ld of %lu, %02ld%% complete\r",
367 locale_message,(long) offset,(unsigned long) extent,(long)
368 (100L*offset/(extent-1)));
anthonydf8ebac2011-04-27 09:03:19 +0000369 else
cristyb51dff52011-05-19 16:55:47 +0000370 (void) FormatLocaleFile(stderr,"%s[%s]: %ld of %lu, %02ld%% complete\r",
anthonydf8ebac2011-04-27 09:03:19 +0000371 locale_message,p+1,(long) offset,(unsigned long) extent,(long)
372 (100L*offset/(extent-1)));
373 if (offset == (MagickOffsetType) (extent-1))
cristyb51dff52011-05-19 16:55:47 +0000374 (void) FormatLocaleFile(stderr,"\n");
anthonydf8ebac2011-04-27 09:03:19 +0000375 (void) fflush(stderr);
376 return(MagickTrue);
377}
378
379/*
anthony3d2f4862011-05-01 13:48:16 +0000380** SparseColorOption() parses the complex -sparse-color argument into an
381** an array of floating point values then calls SparseColorImage().
anthonydf8ebac2011-04-27 09:03:19 +0000382** Argument is a complex mix of floating-point pixel coodinates, and color
383** specifications (or direct floating point numbers). The number of floats
anthony3d2f4862011-05-01 13:48:16 +0000384** needed to represent a color varies depending on the current channel
anthonydf8ebac2011-04-27 09:03:19 +0000385** setting.
386*/
387static Image *SparseColorOption(const Image *image,const ChannelType channel,
388 const SparseColorMethod method,const char *arguments,
389 const MagickBooleanType color_from_image,ExceptionInfo *exception)
390{
391 ChannelType
392 channels;
393
394 char
395 token[MaxTextExtent];
396
397 const char
398 *p;
399
400 double
401 *sparse_arguments;
402
anthonydf8ebac2011-04-27 09:03:19 +0000403 Image
404 *sparse_image;
405
cristy4c08aed2011-07-01 19:47:50 +0000406 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +0000407 color;
408
409 MagickBooleanType
410 error;
411
cristy5f09d852011-05-29 01:39:29 +0000412 register size_t
413 x;
414
415 size_t
416 number_arguments,
417 number_colors;
418
anthonydf8ebac2011-04-27 09:03:19 +0000419 assert(image != (Image *) NULL);
420 assert(image->signature == MagickSignature);
421 if (image->debug != MagickFalse)
422 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
423 assert(exception != (ExceptionInfo *) NULL);
424 assert(exception->signature == MagickSignature);
425 /*
426 Limit channels according to image - and add up number of color channel.
427 */
428 channels=channel;
429 if (image->colorspace != CMYKColorspace)
cristy4c08aed2011-07-01 19:47:50 +0000430 channels=(ChannelType) (channels & ~BlackChannel); /* no black channel */
anthonydf8ebac2011-04-27 09:03:19 +0000431 if (image->matte == MagickFalse)
432 channels=(ChannelType) (channels & ~OpacityChannel); /* no alpha channel */
433 number_colors=0;
434 if ((channels & RedChannel) != 0)
435 number_colors++;
436 if ((channels & GreenChannel) != 0)
437 number_colors++;
438 if ((channels & BlueChannel) != 0)
439 number_colors++;
cristy4c08aed2011-07-01 19:47:50 +0000440 if ((channels & BlackChannel) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000441 number_colors++;
442 if ((channels & OpacityChannel) != 0)
443 number_colors++;
444
445 /*
446 Read string, to determine number of arguments needed,
447 */
448 p=arguments;
449 x=0;
450 while( *p != '\0' )
451 {
452 GetMagickToken(p,&p,token);
453 if ( token[0] == ',' ) continue;
454 if ( isalpha((int) token[0]) || token[0] == '#' ) {
455 if ( color_from_image ) {
456 (void) ThrowMagickException(exception,GetMagickModule(),
457 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
458 "Color arg given, when colors are coming from image");
459 return( (Image *)NULL);
460 }
461 x += number_colors; /* color argument */
462 }
463 else {
464 x++; /* floating point argument */
465 }
466 }
467 error=MagickTrue;
468 if ( color_from_image ) {
469 /* just the control points are being given */
470 error = ( x % 2 != 0 ) ? MagickTrue : MagickFalse;
471 number_arguments=(x/2)*(2+number_colors);
472 }
473 else {
474 /* control points and color values */
475 error = ( x % (2+number_colors) != 0 ) ? MagickTrue : MagickFalse;
476 number_arguments=x;
477 }
478 if ( error ) {
479 (void) ThrowMagickException(exception,GetMagickModule(),
480 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
481 "Invalid number of Arguments");
482 return( (Image *)NULL);
483 }
484
485 /* Allocate and fill in the floating point arguments */
486 sparse_arguments=(double *) AcquireQuantumMemory(number_arguments,
487 sizeof(*sparse_arguments));
488 if (sparse_arguments == (double *) NULL) {
489 (void) ThrowMagickException(exception,GetMagickModule(),ResourceLimitError,
490 "MemoryAllocationFailed","%s","SparseColorOption");
491 return( (Image *)NULL);
492 }
493 (void) ResetMagickMemory(sparse_arguments,0,number_arguments*
494 sizeof(*sparse_arguments));
495 p=arguments;
496 x=0;
497 while( *p != '\0' && x < number_arguments ) {
498 /* X coordinate */
499 token[0]=','; while ( token[0] == ',' ) GetMagickToken(p,&p,token);
500 if ( token[0] == '\0' ) break;
501 if ( isalpha((int) token[0]) || token[0] == '#' ) {
502 (void) ThrowMagickException(exception,GetMagickModule(),
503 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
504 "Color found, instead of X-coord");
505 error = MagickTrue;
506 break;
507 }
cristyc1acd842011-05-19 23:05:47 +0000508 sparse_arguments[x++]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000509 /* Y coordinate */
510 token[0]=','; while ( token[0] == ',' ) GetMagickToken(p,&p,token);
511 if ( token[0] == '\0' ) break;
512 if ( isalpha((int) token[0]) || token[0] == '#' ) {
513 (void) ThrowMagickException(exception,GetMagickModule(),
514 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
515 "Color found, instead of Y-coord");
516 error = MagickTrue;
517 break;
518 }
cristyc1acd842011-05-19 23:05:47 +0000519 sparse_arguments[x++]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000520 /* color values for this control point */
521#if 0
522 if ( (color_from_image ) {
523 /* get color from image */
524 /* HOW??? */
525 }
526 else
527#endif
528 {
529 /* color name or function given in string argument */
530 token[0]=','; while ( token[0] == ',' ) GetMagickToken(p,&p,token);
531 if ( token[0] == '\0' ) break;
532 if ( isalpha((int) token[0]) || token[0] == '#' ) {
533 /* Color string given */
534 (void) QueryMagickColor(token,&color,exception);
cristy4c08aed2011-07-01 19:47:50 +0000535 if (channels & RedChannel)
anthonydf8ebac2011-04-27 09:03:19 +0000536 sparse_arguments[x++] = QuantumScale*color.red;
cristy4c08aed2011-07-01 19:47:50 +0000537 if (channels & GreenChannel)
anthonydf8ebac2011-04-27 09:03:19 +0000538 sparse_arguments[x++] = QuantumScale*color.green;
cristy4c08aed2011-07-01 19:47:50 +0000539 if (channels & BlueChannel)
anthonydf8ebac2011-04-27 09:03:19 +0000540 sparse_arguments[x++] = QuantumScale*color.blue;
cristy4c08aed2011-07-01 19:47:50 +0000541 if (channels & BlackChannel)
542 sparse_arguments[x++] = QuantumScale*color.black;
543 if (channels & OpacityChannel)
544 sparse_arguments[x++] = QuantumScale*color.alpha;
anthonydf8ebac2011-04-27 09:03:19 +0000545 }
546 else {
547 /* Colors given as a set of floating point values - experimental */
548 /* NB: token contains the first floating point value to use! */
549 if ( channels & RedChannel ) {
550 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
551 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
552 break;
cristyc1acd842011-05-19 23:05:47 +0000553 sparse_arguments[x++]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000554 token[0] = ','; /* used this token - get another */
555 }
556 if ( channels & GreenChannel ) {
557 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
558 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
559 break;
cristyc1acd842011-05-19 23:05:47 +0000560 sparse_arguments[x++]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000561 token[0] = ','; /* used this token - get another */
562 }
563 if ( channels & BlueChannel ) {
564 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
565 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
566 break;
cristyc1acd842011-05-19 23:05:47 +0000567 sparse_arguments[x++]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000568 token[0] = ','; /* used this token - get another */
569 }
cristy4c08aed2011-07-01 19:47:50 +0000570 if (channels & BlackChannel) {
anthonydf8ebac2011-04-27 09:03:19 +0000571 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
572 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
573 break;
cristyc1acd842011-05-19 23:05:47 +0000574 sparse_arguments[x++]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000575 token[0] = ','; /* used this token - get another */
576 }
577 if ( channels & OpacityChannel ) {
578 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
579 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
580 break;
cristyc1acd842011-05-19 23:05:47 +0000581 sparse_arguments[x++]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000582 token[0] = ','; /* used this token - get another */
583 }
584 }
585 }
586 }
587 if ( number_arguments != x && !error ) {
588 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
589 "InvalidArgument","`%s': %s","sparse-color","Argument Parsing Error");
590 sparse_arguments=(double *) RelinquishMagickMemory(sparse_arguments);
591 return( (Image *)NULL);
592 }
593 if ( error )
594 return( (Image *)NULL);
595
596 /* Call the Interpolation function with the parsed arguments */
597 sparse_image=SparseColorImage(image,channels,method,number_arguments,
598 sparse_arguments,exception);
599 sparse_arguments=(double *) RelinquishMagickMemory(sparse_arguments);
600 return( sparse_image );
601}
602
cristy3ed852e2009-09-05 21:47:34 +0000603WandExport MagickBooleanType MogrifyImage(ImageInfo *image_info,const int argc,
604 const char **argv,Image **image,ExceptionInfo *exception)
605{
anthonydf8ebac2011-04-27 09:03:19 +0000606 ChannelType
607 channel;
608
609 const char
610 *format,
611 *option;
612
613 DrawInfo
614 *draw_info;
615
616 GeometryInfo
617 geometry_info;
618
cristy3ed852e2009-09-05 21:47:34 +0000619 Image
620 *region_image;
621
anthonydf8ebac2011-04-27 09:03:19 +0000622 ImageInfo
623 *mogrify_info;
624
cristyebbcfea2011-02-25 02:43:54 +0000625 MagickStatusType
cristy3ed852e2009-09-05 21:47:34 +0000626 status;
627
cristy4c08aed2011-07-01 19:47:50 +0000628 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +0000629 fill;
cristy3ed852e2009-09-05 21:47:34 +0000630
anthonydf8ebac2011-04-27 09:03:19 +0000631 MagickStatusType
632 flags;
633
634 QuantizeInfo
635 *quantize_info;
636
637 RectangleInfo
638 geometry,
639 region_geometry;
anthony56ad4222011-04-25 11:04:27 +0000640
cristybb503372010-05-27 20:51:26 +0000641 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000642 i;
643
644 /*
645 Initialize method variables.
646 */
647 assert(image_info != (const ImageInfo *) NULL);
648 assert(image_info->signature == MagickSignature);
649 assert(image != (Image **) NULL);
650 assert((*image)->signature == MagickSignature);
651 if ((*image)->debug != MagickFalse)
652 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",(*image)->filename);
653 if (argc < 0)
654 return(MagickTrue);
cristy6b3da3a2010-06-20 02:21:46 +0000655 mogrify_info=CloneImageInfo(image_info);
anthonydf8ebac2011-04-27 09:03:19 +0000656 draw_info=CloneDrawInfo(mogrify_info,(DrawInfo *) NULL);
657 quantize_info=AcquireQuantizeInfo(mogrify_info);
658 SetGeometryInfo(&geometry_info);
cristy4c08aed2011-07-01 19:47:50 +0000659 GetPixelInfo(*image,&fill);
660 SetPixelInfoPacket(*image,&(*image)->background_color,&fill);
anthonydf8ebac2011-04-27 09:03:19 +0000661 channel=mogrify_info->channel;
662 format=GetImageOption(mogrify_info,"format");
cristy3ed852e2009-09-05 21:47:34 +0000663 SetGeometry(*image,&region_geometry);
664 region_image=NewImageList();
665 /*
666 Transmogrify the image.
667 */
cristybb503372010-05-27 20:51:26 +0000668 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +0000669 {
anthonydf8ebac2011-04-27 09:03:19 +0000670 Image
671 *mogrify_image;
672
anthonye9c27192011-03-27 08:07:06 +0000673 ssize_t
674 count;
675
anthonydf8ebac2011-04-27 09:03:19 +0000676 option=argv[i];
677 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +0000678 continue;
anthonydf8ebac2011-04-27 09:03:19 +0000679 count=MagickMax(ParseCommandOption(MagickCommandOptions,MagickFalse,option),
680 0L);
cristycee97112010-05-28 00:44:52 +0000681 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +0000682 break;
cristy6b3da3a2010-06-20 02:21:46 +0000683 status=MogrifyImageInfo(mogrify_info,(int) count+1,argv+i,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000684 mogrify_image=(Image *)NULL;
685 switch (*(option+1))
686 {
687 case 'a':
cristy3ed852e2009-09-05 21:47:34 +0000688 {
anthonydf8ebac2011-04-27 09:03:19 +0000689 if (LocaleCompare("adaptive-blur",option+1) == 0)
cristy3ed852e2009-09-05 21:47:34 +0000690 {
anthonydf8ebac2011-04-27 09:03:19 +0000691 /*
692 Adaptive blur image.
693 */
694 (void) SyncImageSettings(mogrify_info,*image);
695 flags=ParseGeometry(argv[i+1],&geometry_info);
696 if ((flags & SigmaValue) == 0)
697 geometry_info.sigma=1.0;
698 mogrify_image=AdaptiveBlurImageChannel(*image,channel,
699 geometry_info.rho,geometry_info.sigma,exception);
700 break;
cristy3ed852e2009-09-05 21:47:34 +0000701 }
anthonydf8ebac2011-04-27 09:03:19 +0000702 if (LocaleCompare("adaptive-resize",option+1) == 0)
703 {
704 /*
705 Adaptive resize image.
706 */
707 (void) SyncImageSettings(mogrify_info,*image);
708 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
709 mogrify_image=AdaptiveResizeImage(*image,geometry.width,
710 geometry.height,exception);
711 break;
712 }
713 if (LocaleCompare("adaptive-sharpen",option+1) == 0)
714 {
715 /*
716 Adaptive sharpen image.
717 */
718 (void) SyncImageSettings(mogrify_info,*image);
719 flags=ParseGeometry(argv[i+1],&geometry_info);
720 if ((flags & SigmaValue) == 0)
721 geometry_info.sigma=1.0;
722 mogrify_image=AdaptiveSharpenImageChannel(*image,channel,
723 geometry_info.rho,geometry_info.sigma,exception);
724 break;
725 }
726 if (LocaleCompare("affine",option+1) == 0)
727 {
728 /*
729 Affine matrix.
730 */
731 if (*option == '+')
732 {
733 GetAffineMatrix(&draw_info->affine);
734 break;
735 }
736 (void) ParseAffineGeometry(argv[i+1],&draw_info->affine,exception);
737 break;
738 }
739 if (LocaleCompare("alpha",option+1) == 0)
740 {
741 AlphaChannelType
742 alpha_type;
cristy3ed852e2009-09-05 21:47:34 +0000743
anthonydf8ebac2011-04-27 09:03:19 +0000744 (void) SyncImageSettings(mogrify_info,*image);
745 alpha_type=(AlphaChannelType) ParseCommandOption(MagickAlphaOptions,
746 MagickFalse,argv[i+1]);
747 (void) SetImageAlphaChannel(*image,alpha_type);
748 InheritException(exception,&(*image)->exception);
749 break;
750 }
751 if (LocaleCompare("annotate",option+1) == 0)
752 {
753 char
754 *text,
755 geometry[MaxTextExtent];
756
757 /*
758 Annotate image.
759 */
760 (void) SyncImageSettings(mogrify_info,*image);
761 SetGeometryInfo(&geometry_info);
762 flags=ParseGeometry(argv[i+1],&geometry_info);
763 if ((flags & SigmaValue) == 0)
764 geometry_info.sigma=geometry_info.rho;
765 text=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
766 InheritException(exception,&(*image)->exception);
767 if (text == (char *) NULL)
768 break;
769 (void) CloneString(&draw_info->text,text);
770 text=DestroyString(text);
cristyb51dff52011-05-19 16:55:47 +0000771 (void) FormatLocaleString(geometry,MaxTextExtent,"%+f%+f",
anthonydf8ebac2011-04-27 09:03:19 +0000772 geometry_info.xi,geometry_info.psi);
773 (void) CloneString(&draw_info->geometry,geometry);
774 draw_info->affine.sx=cos(DegreesToRadians(
775 fmod(geometry_info.rho,360.0)));
776 draw_info->affine.rx=sin(DegreesToRadians(
777 fmod(geometry_info.rho,360.0)));
778 draw_info->affine.ry=(-sin(DegreesToRadians(
779 fmod(geometry_info.sigma,360.0))));
780 draw_info->affine.sy=cos(DegreesToRadians(
781 fmod(geometry_info.sigma,360.0)));
782 (void) AnnotateImage(*image,draw_info);
783 InheritException(exception,&(*image)->exception);
784 break;
785 }
786 if (LocaleCompare("antialias",option+1) == 0)
787 {
788 draw_info->stroke_antialias=(*option == '-') ? MagickTrue :
789 MagickFalse;
790 draw_info->text_antialias=(*option == '-') ? MagickTrue :
791 MagickFalse;
792 break;
793 }
794 if (LocaleCompare("auto-gamma",option+1) == 0)
795 {
796 /*
797 Auto Adjust Gamma of image based on its mean
798 */
799 (void) SyncImageSettings(mogrify_info,*image);
cristyab015852011-07-06 01:03:32 +0000800 (void) AutoGammaImage(*image);
anthonydf8ebac2011-04-27 09:03:19 +0000801 break;
802 }
803 if (LocaleCompare("auto-level",option+1) == 0)
804 {
805 /*
806 Perfectly Normalize (max/min stretch) the image
807 */
808 (void) SyncImageSettings(mogrify_info,*image);
cristyab015852011-07-06 01:03:32 +0000809 (void) AutoLevelImage(*image);
anthonydf8ebac2011-04-27 09:03:19 +0000810 break;
811 }
812 if (LocaleCompare("auto-orient",option+1) == 0)
813 {
814 (void) SyncImageSettings(mogrify_info,*image);
815 switch ((*image)->orientation)
816 {
817 case TopRightOrientation:
818 {
819 mogrify_image=FlopImage(*image,exception);
820 break;
821 }
822 case BottomRightOrientation:
823 {
824 mogrify_image=RotateImage(*image,180.0,exception);
825 break;
826 }
827 case BottomLeftOrientation:
828 {
829 mogrify_image=FlipImage(*image,exception);
830 break;
831 }
832 case LeftTopOrientation:
833 {
834 mogrify_image=TransposeImage(*image,exception);
835 break;
836 }
837 case RightTopOrientation:
838 {
839 mogrify_image=RotateImage(*image,90.0,exception);
840 break;
841 }
842 case RightBottomOrientation:
843 {
844 mogrify_image=TransverseImage(*image,exception);
845 break;
846 }
847 case LeftBottomOrientation:
848 {
849 mogrify_image=RotateImage(*image,270.0,exception);
850 break;
851 }
852 default:
853 break;
854 }
855 if (mogrify_image != (Image *) NULL)
856 mogrify_image->orientation=TopLeftOrientation;
857 break;
858 }
859 break;
860 }
861 case 'b':
862 {
863 if (LocaleCompare("black-threshold",option+1) == 0)
864 {
865 /*
866 Black threshold image.
867 */
868 (void) SyncImageSettings(mogrify_info,*image);
869 (void) BlackThresholdImageChannel(*image,channel,argv[i+1],
870 exception);
871 InheritException(exception,&(*image)->exception);
872 break;
873 }
874 if (LocaleCompare("blue-shift",option+1) == 0)
875 {
876 /*
877 Blue shift image.
878 */
879 (void) SyncImageSettings(mogrify_info,*image);
880 geometry_info.rho=1.5;
881 if (*option == '-')
882 flags=ParseGeometry(argv[i+1],&geometry_info);
883 mogrify_image=BlueShiftImage(*image,geometry_info.rho,exception);
884 break;
885 }
886 if (LocaleCompare("blur",option+1) == 0)
887 {
888 /*
889 Gaussian blur image.
890 */
891 (void) SyncImageSettings(mogrify_info,*image);
892 flags=ParseGeometry(argv[i+1],&geometry_info);
893 if ((flags & SigmaValue) == 0)
894 geometry_info.sigma=1.0;
895 mogrify_image=BlurImageChannel(*image,channel,geometry_info.rho,
896 geometry_info.sigma,exception);
897 break;
898 }
899 if (LocaleCompare("border",option+1) == 0)
900 {
901 /*
902 Surround image with a border of solid color.
903 */
904 (void) SyncImageSettings(mogrify_info,*image);
905 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
906 if ((flags & SigmaValue) == 0)
907 geometry.height=geometry.width;
908 mogrify_image=BorderImage(*image,&geometry,exception);
909 break;
910 }
911 if (LocaleCompare("bordercolor",option+1) == 0)
912 {
913 if (*option == '+')
914 {
915 (void) QueryColorDatabase(BorderColor,&draw_info->border_color,
916 exception);
917 break;
918 }
919 (void) QueryColorDatabase(argv[i+1],&draw_info->border_color,
920 exception);
921 break;
922 }
923 if (LocaleCompare("box",option+1) == 0)
924 {
925 (void) QueryColorDatabase(argv[i+1],&draw_info->undercolor,
926 exception);
927 break;
928 }
929 if (LocaleCompare("brightness-contrast",option+1) == 0)
930 {
931 double
932 brightness,
933 contrast;
934
935 GeometryInfo
936 geometry_info;
937
938 MagickStatusType
939 flags;
940
941 /*
942 Brightness / contrast image.
943 */
944 (void) SyncImageSettings(mogrify_info,*image);
945 flags=ParseGeometry(argv[i+1],&geometry_info);
946 brightness=geometry_info.rho;
947 contrast=0.0;
948 if ((flags & SigmaValue) != 0)
949 contrast=geometry_info.sigma;
cristy9ee60942011-07-06 14:54:38 +0000950 (void) BrightnessContrastImage(*image,brightness,contrast);
anthonydf8ebac2011-04-27 09:03:19 +0000951 InheritException(exception,&(*image)->exception);
952 break;
953 }
954 break;
955 }
956 case 'c':
957 {
958 if (LocaleCompare("cdl",option+1) == 0)
959 {
960 char
961 *color_correction_collection;
962
963 /*
964 Color correct with a color decision list.
965 */
966 (void) SyncImageSettings(mogrify_info,*image);
967 color_correction_collection=FileToString(argv[i+1],~0,exception);
968 if (color_correction_collection == (char *) NULL)
969 break;
970 (void) ColorDecisionListImage(*image,color_correction_collection);
971 InheritException(exception,&(*image)->exception);
972 break;
973 }
974 if (LocaleCompare("channel",option+1) == 0)
975 {
976 if (*option == '+')
cristyfa806a72011-07-04 02:06:13 +0000977 channel=DefaultChannels;
anthonydf8ebac2011-04-27 09:03:19 +0000978 else
cristyfa806a72011-07-04 02:06:13 +0000979 channel=(ChannelType) ParseChannelOption(argv[i+1]);
cristy8a9106f2011-07-05 14:39:26 +0000980 SetPixelComponentMap(*image,channel);
anthonydf8ebac2011-04-27 09:03:19 +0000981 break;
982 }
983 if (LocaleCompare("charcoal",option+1) == 0)
984 {
985 /*
986 Charcoal image.
987 */
988 (void) SyncImageSettings(mogrify_info,*image);
989 flags=ParseGeometry(argv[i+1],&geometry_info);
990 if ((flags & SigmaValue) == 0)
991 geometry_info.sigma=1.0;
992 mogrify_image=CharcoalImage(*image,geometry_info.rho,
993 geometry_info.sigma,exception);
994 break;
995 }
996 if (LocaleCompare("chop",option+1) == 0)
997 {
998 /*
999 Chop the image.
1000 */
1001 (void) SyncImageSettings(mogrify_info,*image);
1002 (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1003 mogrify_image=ChopImage(*image,&geometry,exception);
1004 break;
1005 }
1006 if (LocaleCompare("clamp",option+1) == 0)
1007 {
1008 /*
1009 Clamp image.
1010 */
1011 (void) SyncImageSettings(mogrify_info,*image);
1012 (void) ClampImageChannel(*image,channel);
1013 InheritException(exception,&(*image)->exception);
1014 break;
1015 }
1016 if (LocaleCompare("clip",option+1) == 0)
1017 {
1018 (void) SyncImageSettings(mogrify_info,*image);
1019 if (*option == '+')
1020 {
1021 (void) SetImageClipMask(*image,(Image *) NULL);
1022 InheritException(exception,&(*image)->exception);
1023 break;
1024 }
1025 (void) ClipImage(*image);
1026 InheritException(exception,&(*image)->exception);
1027 break;
1028 }
1029 if (LocaleCompare("clip-mask",option+1) == 0)
1030 {
1031 CacheView
1032 *mask_view;
1033
1034 Image
1035 *mask_image;
1036
cristy4c08aed2011-07-01 19:47:50 +00001037 register Quantum
anthonydf8ebac2011-04-27 09:03:19 +00001038 *restrict q;
1039
1040 register ssize_t
1041 x;
1042
1043 ssize_t
1044 y;
1045
1046 (void) SyncImageSettings(mogrify_info,*image);
1047 if (*option == '+')
1048 {
1049 /*
1050 Remove a mask.
1051 */
1052 (void) SetImageMask(*image,(Image *) NULL);
1053 InheritException(exception,&(*image)->exception);
1054 break;
1055 }
1056 /*
1057 Set the image mask.
1058 FUTURE: This Should Be a SetImageAlphaChannel() call, Or two.
1059 */
1060 mask_image=GetImageCache(mogrify_info,argv[i+1],exception);
1061 if (mask_image == (Image *) NULL)
1062 break;
1063 if (SetImageStorageClass(mask_image,DirectClass) == MagickFalse)
1064 return(MagickFalse);
1065 mask_view=AcquireCacheView(mask_image);
1066 for (y=0; y < (ssize_t) mask_image->rows; y++)
1067 {
1068 q=GetCacheViewAuthenticPixels(mask_view,0,y,mask_image->columns,1,
1069 exception);
cristy4c08aed2011-07-01 19:47:50 +00001070 if (q == (const Quantum *) NULL)
anthonydf8ebac2011-04-27 09:03:19 +00001071 break;
1072 for (x=0; x < (ssize_t) mask_image->columns; x++)
1073 {
1074 if (mask_image->matte == MagickFalse)
cristy4c08aed2011-07-01 19:47:50 +00001075 SetPixelAlpha(mask_image,GetPixelIntensity(mask_image,q),q);
1076 SetPixelRed(mask_image,GetPixelAlpha(mask_image,q),q);
1077 SetPixelGreen(mask_image,GetPixelAlpha(mask_image,q),q);
1078 SetPixelBlue(mask_image,GetPixelAlpha(mask_image,q),q);
cristydcfc1ad2011-07-07 16:25:41 +00001079 q+=GetPixelComponents(mask_image);
anthonydf8ebac2011-04-27 09:03:19 +00001080 }
1081 if (SyncCacheViewAuthenticPixels(mask_view,exception) == MagickFalse)
1082 break;
1083 }
1084 mask_view=DestroyCacheView(mask_view);
1085 mask_image->matte=MagickTrue;
1086 (void) SetImageClipMask(*image,mask_image);
1087 mask_image=DestroyImage(mask_image);
1088 InheritException(exception,&(*image)->exception);
1089 break;
1090 }
1091 if (LocaleCompare("clip-path",option+1) == 0)
1092 {
1093 (void) SyncImageSettings(mogrify_info,*image);
1094 (void) ClipImagePath(*image,argv[i+1],*option == '-' ? MagickTrue :
1095 MagickFalse);
1096 InheritException(exception,&(*image)->exception);
1097 break;
1098 }
1099 if (LocaleCompare("colorize",option+1) == 0)
1100 {
1101 /*
1102 Colorize the image.
1103 */
1104 (void) SyncImageSettings(mogrify_info,*image);
1105 mogrify_image=ColorizeImage(*image,argv[i+1],draw_info->fill,
1106 exception);
1107 break;
1108 }
1109 if (LocaleCompare("color-matrix",option+1) == 0)
1110 {
1111 KernelInfo
1112 *kernel;
1113
1114 (void) SyncImageSettings(mogrify_info,*image);
1115 kernel=AcquireKernelInfo(argv[i+1]);
1116 if (kernel == (KernelInfo *) NULL)
1117 break;
1118 mogrify_image=ColorMatrixImage(*image,kernel,exception);
1119 kernel=DestroyKernelInfo(kernel);
1120 break;
1121 }
1122 if (LocaleCompare("colors",option+1) == 0)
1123 {
1124 /*
1125 Reduce the number of colors in the image.
1126 */
1127 (void) SyncImageSettings(mogrify_info,*image);
1128 quantize_info->number_colors=StringToUnsignedLong(argv[i+1]);
1129 if (quantize_info->number_colors == 0)
1130 break;
1131 if (((*image)->storage_class == DirectClass) ||
1132 (*image)->colors > quantize_info->number_colors)
1133 (void) QuantizeImage(quantize_info,*image);
1134 else
1135 (void) CompressImageColormap(*image);
1136 InheritException(exception,&(*image)->exception);
1137 break;
1138 }
1139 if (LocaleCompare("colorspace",option+1) == 0)
1140 {
1141 ColorspaceType
1142 colorspace;
1143
1144 (void) SyncImageSettings(mogrify_info,*image);
1145 if (*option == '+')
1146 {
1147 (void) TransformImageColorspace(*image,RGBColorspace);
1148 InheritException(exception,&(*image)->exception);
1149 break;
1150 }
1151 colorspace=(ColorspaceType) ParseCommandOption(
1152 MagickColorspaceOptions,MagickFalse,argv[i+1]);
1153 (void) TransformImageColorspace(*image,colorspace);
1154 InheritException(exception,&(*image)->exception);
1155 break;
1156 }
1157 if (LocaleCompare("contrast",option+1) == 0)
1158 {
1159 (void) SyncImageSettings(mogrify_info,*image);
1160 (void) ContrastImage(*image,(*option == '-') ? MagickTrue :
1161 MagickFalse);
1162 InheritException(exception,&(*image)->exception);
1163 break;
1164 }
1165 if (LocaleCompare("contrast-stretch",option+1) == 0)
1166 {
1167 double
1168 black_point,
1169 white_point;
1170
1171 MagickStatusType
1172 flags;
1173
1174 /*
1175 Contrast stretch image.
1176 */
1177 (void) SyncImageSettings(mogrify_info,*image);
1178 flags=ParseGeometry(argv[i+1],&geometry_info);
1179 black_point=geometry_info.rho;
1180 white_point=(flags & SigmaValue) != 0 ? geometry_info.sigma :
1181 black_point;
1182 if ((flags & PercentValue) != 0)
1183 {
1184 black_point*=(double) (*image)->columns*(*image)->rows/100.0;
1185 white_point*=(double) (*image)->columns*(*image)->rows/100.0;
1186 }
1187 white_point=(MagickRealType) (*image)->columns*(*image)->rows-
1188 white_point;
cristy50fbc382011-07-07 02:19:17 +00001189 (void) ContrastStretchImage(*image,black_point,white_point);
anthonydf8ebac2011-04-27 09:03:19 +00001190 InheritException(exception,&(*image)->exception);
1191 break;
1192 }
1193 if (LocaleCompare("convolve",option+1) == 0)
1194 {
1195 double
1196 gamma;
1197
1198 KernelInfo
1199 *kernel;
1200
1201 register ssize_t
1202 j;
1203
1204 (void) SyncImageSettings(mogrify_info,*image);
1205 kernel=AcquireKernelInfo(argv[i+1]);
1206 if (kernel == (KernelInfo *) NULL)
1207 break;
1208 gamma=0.0;
1209 for (j=0; j < (ssize_t) (kernel->width*kernel->height); j++)
1210 gamma+=kernel->values[j];
1211 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
1212 for (j=0; j < (ssize_t) (kernel->width*kernel->height); j++)
1213 kernel->values[j]*=gamma;
1214 mogrify_image=FilterImageChannel(*image,channel,kernel,exception);
1215 kernel=DestroyKernelInfo(kernel);
1216 break;
1217 }
1218 if (LocaleCompare("crop",option+1) == 0)
1219 {
1220 /*
1221 Crop a image to a smaller size
1222 */
1223 (void) SyncImageSettings(mogrify_info,*image);
1224#if 0
1225 flags=ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1226 if (((geometry.width != 0) || (geometry.height != 0)) &&
1227 ((flags & XValue) == 0) && ((flags & YValue) == 0))
1228 break;
1229#endif
1230#if 0
1231 mogrify_image=CloneImage(*image,0,0,MagickTrue,&(*image)->exception);
1232 mogrify_image->next = mogrify_image->previous = (Image *)NULL;
1233 (void) TransformImage(&mogrify_image,argv[i+1],(char *) NULL);
1234 InheritException(exception,&mogrify_image->exception);
1235#else
1236 mogrify_image=CropImageToTiles(*image,argv[i+1],exception);
1237#endif
1238 break;
1239 }
1240 if (LocaleCompare("cycle",option+1) == 0)
1241 {
1242 /*
1243 Cycle an image colormap.
1244 */
1245 (void) SyncImageSettings(mogrify_info,*image);
1246 (void) CycleColormapImage(*image,(ssize_t) StringToLong(argv[i+1]));
1247 InheritException(exception,&(*image)->exception);
1248 break;
1249 }
1250 break;
1251 }
1252 case 'd':
1253 {
1254 if (LocaleCompare("decipher",option+1) == 0)
1255 {
1256 StringInfo
1257 *passkey;
1258
1259 /*
1260 Decipher pixels.
1261 */
1262 (void) SyncImageSettings(mogrify_info,*image);
1263 passkey=FileToStringInfo(argv[i+1],~0,exception);
1264 if (passkey != (StringInfo *) NULL)
1265 {
1266 (void) PasskeyDecipherImage(*image,passkey,exception);
1267 passkey=DestroyStringInfo(passkey);
1268 }
1269 break;
1270 }
1271 if (LocaleCompare("density",option+1) == 0)
1272 {
1273 /*
1274 Set image density.
1275 */
1276 (void) CloneString(&draw_info->density,argv[i+1]);
1277 break;
1278 }
1279 if (LocaleCompare("depth",option+1) == 0)
1280 {
1281 (void) SyncImageSettings(mogrify_info,*image);
1282 if (*option == '+')
1283 {
1284 (void) SetImageDepth(*image,MAGICKCORE_QUANTUM_DEPTH);
1285 break;
1286 }
1287 (void) SetImageDepth(*image,StringToUnsignedLong(argv[i+1]));
1288 break;
1289 }
1290 if (LocaleCompare("deskew",option+1) == 0)
1291 {
1292 double
1293 threshold;
1294
1295 /*
1296 Straighten the image.
1297 */
1298 (void) SyncImageSettings(mogrify_info,*image);
1299 if (*option == '+')
1300 threshold=40.0*QuantumRange/100.0;
1301 else
1302 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
1303 mogrify_image=DeskewImage(*image,threshold,exception);
1304 break;
1305 }
1306 if (LocaleCompare("despeckle",option+1) == 0)
1307 {
1308 /*
1309 Reduce the speckles within an image.
1310 */
1311 (void) SyncImageSettings(mogrify_info,*image);
1312 mogrify_image=DespeckleImage(*image,exception);
1313 break;
1314 }
1315 if (LocaleCompare("display",option+1) == 0)
1316 {
1317 (void) CloneString(&draw_info->server_name,argv[i+1]);
1318 break;
1319 }
1320 if (LocaleCompare("distort",option+1) == 0)
1321 {
1322 char
1323 *args,
1324 token[MaxTextExtent];
1325
1326 const char
1327 *p;
1328
1329 DistortImageMethod
1330 method;
1331
1332 double
1333 *arguments;
1334
1335 register ssize_t
1336 x;
1337
1338 size_t
1339 number_arguments;
1340
1341 /*
1342 Distort image.
1343 */
1344 (void) SyncImageSettings(mogrify_info,*image);
1345 method=(DistortImageMethod) ParseCommandOption(MagickDistortOptions,
1346 MagickFalse,argv[i+1]);
1347 if ( method == ResizeDistortion )
1348 {
1349 /* Special Case - Argument is actually a resize geometry!
1350 ** Convert that to an appropriate distortion argument array.
1351 */
1352 double
1353 resize_args[2];
1354 (void) ParseRegionGeometry(*image,argv[i+2],&geometry,
1355 exception);
1356 resize_args[0]=(double)geometry.width;
1357 resize_args[1]=(double)geometry.height;
1358 mogrify_image=DistortImage(*image,method,(size_t)2,
1359 resize_args,MagickTrue,exception);
1360 break;
1361 }
1362 args=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
1363 InheritException(exception,&(*image)->exception);
1364 if (args == (char *) NULL)
1365 break;
1366 p=(char *) args;
1367 for (x=0; *p != '\0'; x++)
1368 {
1369 GetMagickToken(p,&p,token);
1370 if (*token == ',')
1371 GetMagickToken(p,&p,token);
1372 }
1373 number_arguments=(size_t) x;
1374 arguments=(double *) AcquireQuantumMemory(number_arguments,
1375 sizeof(*arguments));
1376 if (arguments == (double *) NULL)
1377 ThrowWandFatalException(ResourceLimitFatalError,
1378 "MemoryAllocationFailed",(*image)->filename);
1379 (void) ResetMagickMemory(arguments,0,number_arguments*
1380 sizeof(*arguments));
1381 p=(char *) args;
1382 for (x=0; (x < (ssize_t) number_arguments) && (*p != '\0'); x++)
1383 {
1384 GetMagickToken(p,&p,token);
1385 if (*token == ',')
1386 GetMagickToken(p,&p,token);
cristyc1acd842011-05-19 23:05:47 +00001387 arguments[x]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001388 }
1389 args=DestroyString(args);
1390 mogrify_image=DistortImage(*image,method,number_arguments,arguments,
1391 (*option == '+') ? MagickTrue : MagickFalse,exception);
1392 arguments=(double *) RelinquishMagickMemory(arguments);
1393 break;
1394 }
1395 if (LocaleCompare("dither",option+1) == 0)
1396 {
1397 if (*option == '+')
1398 {
1399 quantize_info->dither=MagickFalse;
1400 break;
1401 }
1402 quantize_info->dither=MagickTrue;
1403 quantize_info->dither_method=(DitherMethod) ParseCommandOption(
1404 MagickDitherOptions,MagickFalse,argv[i+1]);
1405 if (quantize_info->dither_method == NoDitherMethod)
1406 quantize_info->dither=MagickFalse;
1407 break;
1408 }
1409 if (LocaleCompare("draw",option+1) == 0)
1410 {
1411 /*
1412 Draw image.
1413 */
1414 (void) SyncImageSettings(mogrify_info,*image);
1415 (void) CloneString(&draw_info->primitive,argv[i+1]);
1416 (void) DrawImage(*image,draw_info);
1417 InheritException(exception,&(*image)->exception);
1418 break;
1419 }
1420 break;
1421 }
1422 case 'e':
1423 {
1424 if (LocaleCompare("edge",option+1) == 0)
1425 {
1426 /*
1427 Enhance edges in the image.
1428 */
1429 (void) SyncImageSettings(mogrify_info,*image);
1430 flags=ParseGeometry(argv[i+1],&geometry_info);
1431 if ((flags & SigmaValue) == 0)
1432 geometry_info.sigma=1.0;
1433 mogrify_image=EdgeImage(*image,geometry_info.rho,exception);
1434 break;
1435 }
1436 if (LocaleCompare("emboss",option+1) == 0)
1437 {
1438 /*
1439 Gaussian embossen image.
1440 */
1441 (void) SyncImageSettings(mogrify_info,*image);
1442 flags=ParseGeometry(argv[i+1],&geometry_info);
1443 if ((flags & SigmaValue) == 0)
1444 geometry_info.sigma=1.0;
1445 mogrify_image=EmbossImage(*image,geometry_info.rho,
1446 geometry_info.sigma,exception);
1447 break;
1448 }
1449 if (LocaleCompare("encipher",option+1) == 0)
1450 {
1451 StringInfo
1452 *passkey;
1453
1454 /*
1455 Encipher pixels.
1456 */
1457 (void) SyncImageSettings(mogrify_info,*image);
1458 passkey=FileToStringInfo(argv[i+1],~0,exception);
1459 if (passkey != (StringInfo *) NULL)
1460 {
1461 (void) PasskeyEncipherImage(*image,passkey,exception);
1462 passkey=DestroyStringInfo(passkey);
1463 }
1464 break;
1465 }
1466 if (LocaleCompare("encoding",option+1) == 0)
1467 {
1468 (void) CloneString(&draw_info->encoding,argv[i+1]);
1469 break;
1470 }
1471 if (LocaleCompare("enhance",option+1) == 0)
1472 {
1473 /*
1474 Enhance image.
1475 */
1476 (void) SyncImageSettings(mogrify_info,*image);
1477 mogrify_image=EnhanceImage(*image,exception);
1478 break;
1479 }
1480 if (LocaleCompare("equalize",option+1) == 0)
1481 {
1482 /*
1483 Equalize image.
1484 */
1485 (void) SyncImageSettings(mogrify_info,*image);
cristy50fbc382011-07-07 02:19:17 +00001486 (void) EqualizeImage(*image);
anthonydf8ebac2011-04-27 09:03:19 +00001487 InheritException(exception,&(*image)->exception);
1488 break;
1489 }
1490 if (LocaleCompare("evaluate",option+1) == 0)
1491 {
1492 double
1493 constant;
1494
1495 MagickEvaluateOperator
1496 op;
1497
1498 (void) SyncImageSettings(mogrify_info,*image);
1499 op=(MagickEvaluateOperator) ParseCommandOption(MagickEvaluateOptions,
1500 MagickFalse,argv[i+1]);
1501 constant=SiPrefixToDouble(argv[i+2],QuantumRange);
1502 (void) EvaluateImageChannel(*image,channel,op,constant,exception);
1503 break;
1504 }
1505 if (LocaleCompare("extent",option+1) == 0)
1506 {
1507 /*
1508 Set the image extent.
1509 */
1510 (void) SyncImageSettings(mogrify_info,*image);
1511 flags=ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1512 if (geometry.width == 0)
1513 geometry.width=(*image)->columns;
1514 if (geometry.height == 0)
1515 geometry.height=(*image)->rows;
1516 mogrify_image=ExtentImage(*image,&geometry,exception);
1517 break;
1518 }
1519 break;
1520 }
1521 case 'f':
1522 {
1523 if (LocaleCompare("family",option+1) == 0)
1524 {
1525 if (*option == '+')
1526 {
1527 if (draw_info->family != (char *) NULL)
1528 draw_info->family=DestroyString(draw_info->family);
1529 break;
1530 }
1531 (void) CloneString(&draw_info->family,argv[i+1]);
1532 break;
1533 }
1534 if (LocaleCompare("features",option+1) == 0)
1535 {
1536 if (*option == '+')
1537 {
1538 (void) DeleteImageArtifact(*image,"identify:features");
1539 break;
1540 }
1541 (void) SetImageArtifact(*image,"identify:features",argv[i+1]);
1542 break;
1543 }
1544 if (LocaleCompare("fill",option+1) == 0)
1545 {
1546 ExceptionInfo
1547 *sans;
1548
cristy4c08aed2011-07-01 19:47:50 +00001549 GetPixelInfo(*image,&fill);
anthonydf8ebac2011-04-27 09:03:19 +00001550 if (*option == '+')
1551 {
1552 (void) QueryMagickColor("none",&fill,exception);
1553 (void) QueryColorDatabase("none",&draw_info->fill,exception);
1554 if (draw_info->fill_pattern != (Image *) NULL)
1555 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
1556 break;
1557 }
1558 sans=AcquireExceptionInfo();
1559 (void) QueryMagickColor(argv[i+1],&fill,sans);
1560 status=QueryColorDatabase(argv[i+1],&draw_info->fill,sans);
1561 sans=DestroyExceptionInfo(sans);
1562 if (status == MagickFalse)
1563 draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1],
1564 exception);
1565 break;
1566 }
1567 if (LocaleCompare("flip",option+1) == 0)
1568 {
1569 /*
1570 Flip image scanlines.
1571 */
1572 (void) SyncImageSettings(mogrify_info,*image);
1573 mogrify_image=FlipImage(*image,exception);
1574 break;
1575 }
anthonydf8ebac2011-04-27 09:03:19 +00001576 if (LocaleCompare("floodfill",option+1) == 0)
1577 {
cristy4c08aed2011-07-01 19:47:50 +00001578 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00001579 target;
1580
1581 /*
1582 Floodfill image.
1583 */
1584 (void) SyncImageSettings(mogrify_info,*image);
1585 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
1586 (void) QueryMagickColor(argv[i+2],&target,exception);
1587 (void) FloodfillPaintImage(*image,channel,draw_info,&target,
1588 geometry.x,geometry.y,*option == '-' ? MagickFalse : MagickTrue);
1589 InheritException(exception,&(*image)->exception);
1590 break;
1591 }
anthony3d2f4862011-05-01 13:48:16 +00001592 if (LocaleCompare("flop",option+1) == 0)
1593 {
1594 /*
1595 Flop image scanlines.
1596 */
1597 (void) SyncImageSettings(mogrify_info,*image);
1598 mogrify_image=FlopImage(*image,exception);
1599 break;
1600 }
anthonydf8ebac2011-04-27 09:03:19 +00001601 if (LocaleCompare("font",option+1) == 0)
1602 {
1603 if (*option == '+')
1604 {
1605 if (draw_info->font != (char *) NULL)
1606 draw_info->font=DestroyString(draw_info->font);
1607 break;
1608 }
1609 (void) CloneString(&draw_info->font,argv[i+1]);
1610 break;
1611 }
1612 if (LocaleCompare("format",option+1) == 0)
1613 {
1614 format=argv[i+1];
1615 break;
1616 }
1617 if (LocaleCompare("frame",option+1) == 0)
1618 {
1619 FrameInfo
1620 frame_info;
1621
1622 /*
1623 Surround image with an ornamental border.
1624 */
1625 (void) SyncImageSettings(mogrify_info,*image);
1626 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
1627 frame_info.width=geometry.width;
1628 frame_info.height=geometry.height;
1629 if ((flags & HeightValue) == 0)
1630 frame_info.height=geometry.width;
1631 frame_info.outer_bevel=geometry.x;
1632 frame_info.inner_bevel=geometry.y;
1633 frame_info.x=(ssize_t) frame_info.width;
1634 frame_info.y=(ssize_t) frame_info.height;
1635 frame_info.width=(*image)->columns+2*frame_info.width;
1636 frame_info.height=(*image)->rows+2*frame_info.height;
1637 mogrify_image=FrameImage(*image,&frame_info,exception);
1638 break;
1639 }
1640 if (LocaleCompare("function",option+1) == 0)
1641 {
1642 char
1643 *arguments,
1644 token[MaxTextExtent];
1645
1646 const char
1647 *p;
1648
1649 double
1650 *parameters;
1651
1652 MagickFunction
1653 function;
1654
1655 register ssize_t
1656 x;
1657
1658 size_t
1659 number_parameters;
1660
1661 /*
1662 Function Modify Image Values
1663 */
1664 (void) SyncImageSettings(mogrify_info,*image);
1665 function=(MagickFunction) ParseCommandOption(MagickFunctionOptions,
1666 MagickFalse,argv[i+1]);
1667 arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
1668 InheritException(exception,&(*image)->exception);
1669 if (arguments == (char *) NULL)
1670 break;
1671 p=(char *) arguments;
1672 for (x=0; *p != '\0'; x++)
1673 {
1674 GetMagickToken(p,&p,token);
1675 if (*token == ',')
1676 GetMagickToken(p,&p,token);
1677 }
1678 number_parameters=(size_t) x;
1679 parameters=(double *) AcquireQuantumMemory(number_parameters,
1680 sizeof(*parameters));
1681 if (parameters == (double *) NULL)
1682 ThrowWandFatalException(ResourceLimitFatalError,
1683 "MemoryAllocationFailed",(*image)->filename);
1684 (void) ResetMagickMemory(parameters,0,number_parameters*
1685 sizeof(*parameters));
1686 p=(char *) arguments;
1687 for (x=0; (x < (ssize_t) number_parameters) && (*p != '\0'); x++)
1688 {
1689 GetMagickToken(p,&p,token);
1690 if (*token == ',')
1691 GetMagickToken(p,&p,token);
cristyc1acd842011-05-19 23:05:47 +00001692 parameters[x]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001693 }
1694 arguments=DestroyString(arguments);
1695 (void) FunctionImageChannel(*image,channel,function,
1696 number_parameters,parameters,exception);
1697 parameters=(double *) RelinquishMagickMemory(parameters);
1698 break;
1699 }
1700 break;
1701 }
1702 case 'g':
1703 {
1704 if (LocaleCompare("gamma",option+1) == 0)
1705 {
1706 /*
1707 Gamma image.
1708 */
1709 (void) SyncImageSettings(mogrify_info,*image);
1710 if (*option == '+')
cristyc1acd842011-05-19 23:05:47 +00001711 (*image)->gamma=InterpretLocaleValue(argv[i+1],(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001712 else
1713 {
cristy50fbc382011-07-07 02:19:17 +00001714 (void) GammaImage(*image,InterpretLocaleValue(argv[i+1],
1715 (char **) NULL));
anthonydf8ebac2011-04-27 09:03:19 +00001716 InheritException(exception,&(*image)->exception);
1717 }
1718 break;
1719 }
1720 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
1721 (LocaleCompare("gaussian",option+1) == 0))
1722 {
1723 /*
1724 Gaussian blur image.
1725 */
1726 (void) SyncImageSettings(mogrify_info,*image);
1727 flags=ParseGeometry(argv[i+1],&geometry_info);
1728 if ((flags & SigmaValue) == 0)
1729 geometry_info.sigma=1.0;
1730 mogrify_image=GaussianBlurImageChannel(*image,channel,
1731 geometry_info.rho,geometry_info.sigma,exception);
1732 break;
1733 }
1734 if (LocaleCompare("geometry",option+1) == 0)
1735 {
1736 /*
1737 Record Image offset, Resize last image.
1738 */
1739 (void) SyncImageSettings(mogrify_info,*image);
1740 if (*option == '+')
1741 {
1742 if ((*image)->geometry != (char *) NULL)
1743 (*image)->geometry=DestroyString((*image)->geometry);
1744 break;
1745 }
1746 flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
1747 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
1748 (void) CloneString(&(*image)->geometry,argv[i+1]);
1749 else
1750 mogrify_image=ResizeImage(*image,geometry.width,geometry.height,
1751 (*image)->filter,(*image)->blur,exception);
1752 break;
1753 }
1754 if (LocaleCompare("gravity",option+1) == 0)
1755 {
1756 if (*option == '+')
1757 {
1758 draw_info->gravity=UndefinedGravity;
1759 break;
1760 }
1761 draw_info->gravity=(GravityType) ParseCommandOption(
1762 MagickGravityOptions,MagickFalse,argv[i+1]);
1763 break;
1764 }
1765 break;
1766 }
1767 case 'h':
1768 {
1769 if (LocaleCompare("highlight-color",option+1) == 0)
1770 {
1771 (void) SetImageArtifact(*image,option+1,argv[i+1]);
1772 break;
1773 }
1774 break;
1775 }
1776 case 'i':
1777 {
1778 if (LocaleCompare("identify",option+1) == 0)
1779 {
1780 char
1781 *text;
1782
1783 (void) SyncImageSettings(mogrify_info,*image);
1784 if (format == (char *) NULL)
1785 {
1786 (void) IdentifyImage(*image,stdout,mogrify_info->verbose);
1787 InheritException(exception,&(*image)->exception);
1788 break;
1789 }
1790 text=InterpretImageProperties(mogrify_info,*image,format);
1791 InheritException(exception,&(*image)->exception);
1792 if (text == (char *) NULL)
1793 break;
1794 (void) fputs(text,stdout);
1795 (void) fputc('\n',stdout);
1796 text=DestroyString(text);
1797 break;
1798 }
1799 if (LocaleCompare("implode",option+1) == 0)
1800 {
1801 /*
1802 Implode image.
1803 */
1804 (void) SyncImageSettings(mogrify_info,*image);
1805 (void) ParseGeometry(argv[i+1],&geometry_info);
1806 mogrify_image=ImplodeImage(*image,geometry_info.rho,exception);
1807 break;
1808 }
1809 if (LocaleCompare("interline-spacing",option+1) == 0)
1810 {
1811 if (*option == '+')
1812 (void) ParseGeometry("0",&geometry_info);
1813 else
1814 (void) ParseGeometry(argv[i+1],&geometry_info);
1815 draw_info->interline_spacing=geometry_info.rho;
1816 break;
1817 }
1818 if (LocaleCompare("interword-spacing",option+1) == 0)
1819 {
1820 if (*option == '+')
1821 (void) ParseGeometry("0",&geometry_info);
1822 else
1823 (void) ParseGeometry(argv[i+1],&geometry_info);
1824 draw_info->interword_spacing=geometry_info.rho;
1825 break;
1826 }
1827 break;
1828 }
1829 case 'k':
1830 {
1831 if (LocaleCompare("kerning",option+1) == 0)
1832 {
1833 if (*option == '+')
1834 (void) ParseGeometry("0",&geometry_info);
1835 else
1836 (void) ParseGeometry(argv[i+1],&geometry_info);
1837 draw_info->kerning=geometry_info.rho;
1838 break;
1839 }
1840 break;
1841 }
1842 case 'l':
1843 {
1844 if (LocaleCompare("lat",option+1) == 0)
1845 {
1846 /*
1847 Local adaptive threshold image.
1848 */
1849 (void) SyncImageSettings(mogrify_info,*image);
1850 flags=ParseGeometry(argv[i+1],&geometry_info);
1851 if ((flags & PercentValue) != 0)
1852 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
1853 mogrify_image=AdaptiveThresholdImage(*image,(size_t)
1854 geometry_info.rho,(size_t) geometry_info.sigma,(ssize_t)
1855 geometry_info.xi,exception);
1856 break;
1857 }
1858 if (LocaleCompare("level",option+1) == 0)
1859 {
1860 MagickRealType
1861 black_point,
1862 gamma,
1863 white_point;
1864
1865 MagickStatusType
1866 flags;
1867
1868 /*
1869 Parse levels.
1870 */
1871 (void) SyncImageSettings(mogrify_info,*image);
1872 flags=ParseGeometry(argv[i+1],&geometry_info);
1873 black_point=geometry_info.rho;
1874 white_point=(MagickRealType) QuantumRange;
1875 if ((flags & SigmaValue) != 0)
1876 white_point=geometry_info.sigma;
1877 gamma=1.0;
1878 if ((flags & XiValue) != 0)
1879 gamma=geometry_info.xi;
1880 if ((flags & PercentValue) != 0)
1881 {
1882 black_point*=(MagickRealType) (QuantumRange/100.0);
1883 white_point*=(MagickRealType) (QuantumRange/100.0);
1884 }
1885 if ((flags & SigmaValue) == 0)
1886 white_point=(MagickRealType) QuantumRange-black_point;
1887 if ((*option == '+') || ((flags & AspectValue) != 0))
cristy50fbc382011-07-07 02:19:17 +00001888 (void) LevelizeImage(*image,black_point,white_point,gamma);
anthonydf8ebac2011-04-27 09:03:19 +00001889 else
cristyf89cb1d2011-07-07 01:24:37 +00001890 (void) LevelImage(*image,black_point,white_point,gamma);
anthonydf8ebac2011-04-27 09:03:19 +00001891 InheritException(exception,&(*image)->exception);
1892 break;
1893 }
1894 if (LocaleCompare("level-colors",option+1) == 0)
1895 {
1896 char
1897 token[MaxTextExtent];
1898
1899 const char
1900 *p;
1901
cristy4c08aed2011-07-01 19:47:50 +00001902 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00001903 black_point,
1904 white_point;
1905
1906 p=(const char *) argv[i+1];
1907 GetMagickToken(p,&p,token); /* get black point color */
1908 if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
1909 (void) QueryMagickColor(token,&black_point,exception);
1910 else
1911 (void) QueryMagickColor("#000000",&black_point,exception);
1912 if (isalpha((int) token[0]) || (token[0] == '#'))
1913 GetMagickToken(p,&p,token);
1914 if (*token == '\0')
1915 white_point=black_point; /* set everything to that color */
1916 else
1917 {
1918 if ((isalpha((int) *token) == 0) && ((*token == '#') == 0))
1919 GetMagickToken(p,&p,token); /* Get white point color. */
1920 if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
1921 (void) QueryMagickColor(token,&white_point,exception);
1922 else
1923 (void) QueryMagickColor("#ffffff",&white_point,exception);
1924 }
cristy490408a2011-07-07 14:42:05 +00001925 (void) LevelImageColors(*image,&black_point,&white_point,
1926 *option == '+' ? MagickTrue : MagickFalse);
anthonydf8ebac2011-04-27 09:03:19 +00001927 break;
1928 }
1929 if (LocaleCompare("linear-stretch",option+1) == 0)
1930 {
1931 double
1932 black_point,
1933 white_point;
1934
1935 MagickStatusType
1936 flags;
1937
1938 (void) SyncImageSettings(mogrify_info,*image);
1939 flags=ParseGeometry(argv[i+1],&geometry_info);
1940 black_point=geometry_info.rho;
1941 white_point=(MagickRealType) (*image)->columns*(*image)->rows;
1942 if ((flags & SigmaValue) != 0)
1943 white_point=geometry_info.sigma;
1944 if ((flags & PercentValue) != 0)
1945 {
1946 black_point*=(double) (*image)->columns*(*image)->rows/100.0;
1947 white_point*=(double) (*image)->columns*(*image)->rows/100.0;
1948 }
1949 if ((flags & SigmaValue) == 0)
1950 white_point=(MagickRealType) (*image)->columns*(*image)->rows-
1951 black_point;
1952 (void) LinearStretchImage(*image,black_point,white_point);
1953 InheritException(exception,&(*image)->exception);
1954 break;
1955 }
1956 if (LocaleCompare("linewidth",option+1) == 0)
1957 {
cristyc1acd842011-05-19 23:05:47 +00001958 draw_info->stroke_width=InterpretLocaleValue(argv[i+1],
1959 (char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001960 break;
1961 }
1962 if (LocaleCompare("liquid-rescale",option+1) == 0)
1963 {
1964 /*
1965 Liquid rescale image.
1966 */
1967 (void) SyncImageSettings(mogrify_info,*image);
1968 flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
1969 if ((flags & XValue) == 0)
1970 geometry.x=1;
1971 if ((flags & YValue) == 0)
1972 geometry.y=0;
1973 mogrify_image=LiquidRescaleImage(*image,geometry.width,
1974 geometry.height,1.0*geometry.x,1.0*geometry.y,exception);
1975 break;
1976 }
1977 if (LocaleCompare("lowlight-color",option+1) == 0)
1978 {
1979 (void) SetImageArtifact(*image,option+1,argv[i+1]);
1980 break;
1981 }
1982 break;
1983 }
1984 case 'm':
1985 {
1986 if (LocaleCompare("map",option+1) == 0)
cristy3ed852e2009-09-05 21:47:34 +00001987 {
cristy3ed852e2009-09-05 21:47:34 +00001988 Image
anthonydf8ebac2011-04-27 09:03:19 +00001989 *remap_image;
cristy3ed852e2009-09-05 21:47:34 +00001990
anthonydf8ebac2011-04-27 09:03:19 +00001991 /*
1992 Transform image colors to match this set of colors.
1993 */
1994 (void) SyncImageSettings(mogrify_info,*image);
1995 if (*option == '+')
1996 break;
1997 remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
1998 if (remap_image == (Image *) NULL)
1999 break;
2000 (void) RemapImage(quantize_info,*image,remap_image);
2001 InheritException(exception,&(*image)->exception);
2002 remap_image=DestroyImage(remap_image);
2003 break;
2004 }
2005 if (LocaleCompare("mask",option+1) == 0)
2006 {
2007 Image
2008 *mask;
2009
2010 (void) SyncImageSettings(mogrify_info,*image);
2011 if (*option == '+')
2012 {
2013 /*
2014 Remove a mask.
2015 */
2016 (void) SetImageMask(*image,(Image *) NULL);
2017 InheritException(exception,&(*image)->exception);
2018 break;
2019 }
2020 /*
2021 Set the image mask.
2022 */
2023 mask=GetImageCache(mogrify_info,argv[i+1],exception);
2024 if (mask == (Image *) NULL)
2025 break;
2026 (void) SetImageMask(*image,mask);
2027 mask=DestroyImage(mask);
2028 InheritException(exception,&(*image)->exception);
2029 break;
2030 }
2031 if (LocaleCompare("matte",option+1) == 0)
2032 {
2033 (void) SetImageAlphaChannel(*image,(*option == '-') ?
2034 SetAlphaChannel : DeactivateAlphaChannel );
2035 InheritException(exception,&(*image)->exception);
2036 break;
2037 }
2038 if (LocaleCompare("median",option+1) == 0)
2039 {
2040 /*
2041 Median filter image.
2042 */
2043 (void) SyncImageSettings(mogrify_info,*image);
2044 (void) ParseGeometry(argv[i+1],&geometry_info);
2045 mogrify_image=StatisticImageChannel(*image,channel,MedianStatistic,
2046 (size_t) geometry_info.rho,(size_t) geometry_info.rho,exception);
2047 break;
2048 }
2049 if (LocaleCompare("mode",option+1) == 0)
2050 {
2051 /*
2052 Mode image.
2053 */
2054 (void) SyncImageSettings(mogrify_info,*image);
2055 (void) ParseGeometry(argv[i+1],&geometry_info);
2056 mogrify_image=StatisticImageChannel(*image,channel,ModeStatistic,
2057 (size_t) geometry_info.rho,(size_t) geometry_info.rho,exception);
2058 break;
2059 }
2060 if (LocaleCompare("modulate",option+1) == 0)
2061 {
2062 (void) SyncImageSettings(mogrify_info,*image);
2063 (void) ModulateImage(*image,argv[i+1]);
2064 InheritException(exception,&(*image)->exception);
2065 break;
2066 }
2067 if (LocaleCompare("monitor",option+1) == 0)
2068 {
2069 if (*option == '+')
2070 {
2071 (void) SetImageProgressMonitor(*image,
2072 (MagickProgressMonitor) NULL,(void *) NULL);
2073 break;
2074 }
2075 (void) SetImageProgressMonitor(*image,MonitorProgress,
2076 (void *) NULL);
2077 break;
2078 }
2079 if (LocaleCompare("monochrome",option+1) == 0)
2080 {
2081 (void) SyncImageSettings(mogrify_info,*image);
2082 (void) SetImageType(*image,BilevelType);
2083 InheritException(exception,&(*image)->exception);
2084 break;
2085 }
2086 if (LocaleCompare("morphology",option+1) == 0)
2087 {
2088 char
2089 token[MaxTextExtent];
2090
2091 const char
2092 *p;
2093
2094 KernelInfo
2095 *kernel;
2096
2097 MorphologyMethod
2098 method;
2099
2100 ssize_t
2101 iterations;
2102
2103 /*
2104 Morphological Image Operation
2105 */
2106 (void) SyncImageSettings(mogrify_info,*image);
2107 p=argv[i+1];
2108 GetMagickToken(p,&p,token);
2109 method=(MorphologyMethod) ParseCommandOption(MagickMorphologyOptions,
2110 MagickFalse,token);
2111 iterations=1L;
2112 GetMagickToken(p,&p,token);
2113 if ((*p == ':') || (*p == ','))
2114 GetMagickToken(p,&p,token);
2115 if ((*p != '\0'))
2116 iterations=(ssize_t) StringToLong(p);
2117 kernel=AcquireKernelInfo(argv[i+2]);
2118 if (kernel == (KernelInfo *) NULL)
2119 {
2120 (void) ThrowMagickException(exception,GetMagickModule(),
2121 OptionError,"UnabletoParseKernel","morphology");
2122 status=MagickFalse;
2123 break;
2124 }
2125 mogrify_image=MorphologyImageChannel(*image,channel,method,
2126 iterations,kernel,exception);
2127 kernel=DestroyKernelInfo(kernel);
2128 break;
2129 }
2130 if (LocaleCompare("motion-blur",option+1) == 0)
2131 {
2132 /*
2133 Motion blur image.
2134 */
2135 (void) SyncImageSettings(mogrify_info,*image);
2136 flags=ParseGeometry(argv[i+1],&geometry_info);
2137 if ((flags & SigmaValue) == 0)
2138 geometry_info.sigma=1.0;
2139 mogrify_image=MotionBlurImageChannel(*image,channel,
2140 geometry_info.rho,geometry_info.sigma,geometry_info.xi,exception);
2141 break;
2142 }
2143 break;
2144 }
2145 case 'n':
2146 {
2147 if (LocaleCompare("negate",option+1) == 0)
2148 {
2149 (void) SyncImageSettings(mogrify_info,*image);
cristy50fbc382011-07-07 02:19:17 +00002150 (void) NegateImage(*image,*option == '+' ? MagickTrue :
2151 MagickFalse);
anthonydf8ebac2011-04-27 09:03:19 +00002152 InheritException(exception,&(*image)->exception);
2153 break;
2154 }
2155 if (LocaleCompare("noise",option+1) == 0)
2156 {
2157 (void) SyncImageSettings(mogrify_info,*image);
2158 if (*option == '-')
2159 {
2160 (void) ParseGeometry(argv[i+1],&geometry_info);
2161 mogrify_image=StatisticImageChannel(*image,channel,
2162 NonpeakStatistic,(size_t) geometry_info.rho,(size_t)
2163 geometry_info.rho,exception);
2164 }
2165 else
2166 {
2167 NoiseType
2168 noise;
2169
2170 noise=(NoiseType) ParseCommandOption(MagickNoiseOptions,
2171 MagickFalse,argv[i+1]);
cristy490408a2011-07-07 14:42:05 +00002172 mogrify_image=AddNoiseImage(*image,noise,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002173 }
2174 break;
2175 }
2176 if (LocaleCompare("normalize",option+1) == 0)
2177 {
2178 (void) SyncImageSettings(mogrify_info,*image);
cristy50fbc382011-07-07 02:19:17 +00002179 (void) NormalizeImage(*image);
anthonydf8ebac2011-04-27 09:03:19 +00002180 InheritException(exception,&(*image)->exception);
2181 break;
2182 }
2183 break;
2184 }
2185 case 'o':
2186 {
2187 if (LocaleCompare("opaque",option+1) == 0)
2188 {
cristy4c08aed2011-07-01 19:47:50 +00002189 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00002190 target;
2191
2192 (void) SyncImageSettings(mogrify_info,*image);
2193 (void) QueryMagickColor(argv[i+1],&target,exception);
2194 (void) OpaquePaintImageChannel(*image,channel,&target,&fill,
2195 *option == '-' ? MagickFalse : MagickTrue);
2196 break;
2197 }
2198 if (LocaleCompare("ordered-dither",option+1) == 0)
2199 {
2200 (void) SyncImageSettings(mogrify_info,*image);
2201 (void) OrderedPosterizeImageChannel(*image,channel,argv[i+1],
2202 exception);
2203 break;
2204 }
2205 break;
2206 }
2207 case 'p':
2208 {
2209 if (LocaleCompare("paint",option+1) == 0)
2210 {
anthonydf8ebac2011-04-27 09:03:19 +00002211 (void) SyncImageSettings(mogrify_info,*image);
2212 (void) ParseGeometry(argv[i+1],&geometry_info);
anthony3d2f4862011-05-01 13:48:16 +00002213 mogrify_image=OilPaintImage(*image,geometry_info.rho,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002214 break;
2215 }
2216 if (LocaleCompare("pen",option+1) == 0)
2217 {
2218 if (*option == '+')
2219 {
2220 (void) QueryColorDatabase("none",&draw_info->fill,exception);
2221 break;
2222 }
2223 (void) QueryColorDatabase(argv[i+1],&draw_info->fill,exception);
2224 break;
2225 }
2226 if (LocaleCompare("pointsize",option+1) == 0)
2227 {
2228 if (*option == '+')
2229 (void) ParseGeometry("12",&geometry_info);
2230 else
2231 (void) ParseGeometry(argv[i+1],&geometry_info);
2232 draw_info->pointsize=geometry_info.rho;
2233 break;
2234 }
2235 if (LocaleCompare("polaroid",option+1) == 0)
2236 {
2237 double
2238 angle;
2239
2240 RandomInfo
2241 *random_info;
2242
2243 /*
2244 Simulate a Polaroid picture.
2245 */
2246 (void) SyncImageSettings(mogrify_info,*image);
2247 random_info=AcquireRandomInfo();
2248 angle=22.5*(GetPseudoRandomValue(random_info)-0.5);
2249 random_info=DestroyRandomInfo(random_info);
2250 if (*option == '-')
2251 {
2252 SetGeometryInfo(&geometry_info);
2253 flags=ParseGeometry(argv[i+1],&geometry_info);
2254 angle=geometry_info.rho;
2255 }
2256 mogrify_image=PolaroidImage(*image,draw_info,angle,exception);
2257 break;
2258 }
2259 if (LocaleCompare("posterize",option+1) == 0)
2260 {
2261 /*
2262 Posterize image.
2263 */
2264 (void) SyncImageSettings(mogrify_info,*image);
2265 (void) PosterizeImage(*image,StringToUnsignedLong(argv[i+1]),
2266 quantize_info->dither);
2267 InheritException(exception,&(*image)->exception);
2268 break;
2269 }
2270 if (LocaleCompare("preview",option+1) == 0)
2271 {
2272 PreviewType
2273 preview_type;
2274
2275 /*
2276 Preview image.
2277 */
2278 (void) SyncImageSettings(mogrify_info,*image);
2279 if (*option == '+')
2280 preview_type=UndefinedPreview;
2281 else
2282 preview_type=(PreviewType) ParseCommandOption(MagickPreviewOptions,
2283 MagickFalse,argv[i+1]);
2284 mogrify_image=PreviewImage(*image,preview_type,exception);
2285 break;
2286 }
2287 if (LocaleCompare("profile",option+1) == 0)
2288 {
2289 const char
2290 *name;
2291
2292 const StringInfo
2293 *profile;
2294
2295 Image
2296 *profile_image;
2297
2298 ImageInfo
2299 *profile_info;
2300
2301 (void) SyncImageSettings(mogrify_info,*image);
2302 if (*option == '+')
2303 {
2304 /*
2305 Remove a profile from the image.
2306 */
2307 (void) ProfileImage(*image,argv[i+1],(const unsigned char *)
2308 NULL,0,MagickTrue);
2309 InheritException(exception,&(*image)->exception);
2310 break;
2311 }
2312 /*
2313 Associate a profile with the image.
2314 */
2315 profile_info=CloneImageInfo(mogrify_info);
2316 profile=GetImageProfile(*image,"iptc");
2317 if (profile != (StringInfo *) NULL)
2318 profile_info->profile=(void *) CloneStringInfo(profile);
2319 profile_image=GetImageCache(profile_info,argv[i+1],exception);
2320 profile_info=DestroyImageInfo(profile_info);
2321 if (profile_image == (Image *) NULL)
2322 {
2323 StringInfo
2324 *profile;
2325
2326 profile_info=CloneImageInfo(mogrify_info);
2327 (void) CopyMagickString(profile_info->filename,argv[i+1],
2328 MaxTextExtent);
2329 profile=FileToStringInfo(profile_info->filename,~0UL,exception);
2330 if (profile != (StringInfo *) NULL)
2331 {
2332 (void) ProfileImage(*image,profile_info->magick,
2333 GetStringInfoDatum(profile),(size_t)
2334 GetStringInfoLength(profile),MagickFalse);
2335 profile=DestroyStringInfo(profile);
2336 }
2337 profile_info=DestroyImageInfo(profile_info);
2338 break;
2339 }
2340 ResetImageProfileIterator(profile_image);
2341 name=GetNextImageProfile(profile_image);
2342 while (name != (const char *) NULL)
2343 {
2344 profile=GetImageProfile(profile_image,name);
2345 if (profile != (StringInfo *) NULL)
2346 (void) ProfileImage(*image,name,GetStringInfoDatum(profile),
2347 (size_t) GetStringInfoLength(profile),MagickFalse);
2348 name=GetNextImageProfile(profile_image);
2349 }
2350 profile_image=DestroyImage(profile_image);
2351 break;
2352 }
2353 break;
2354 }
2355 case 'q':
2356 {
2357 if (LocaleCompare("quantize",option+1) == 0)
2358 {
2359 if (*option == '+')
2360 {
2361 quantize_info->colorspace=UndefinedColorspace;
2362 break;
2363 }
2364 quantize_info->colorspace=(ColorspaceType) ParseCommandOption(
2365 MagickColorspaceOptions,MagickFalse,argv[i+1]);
2366 break;
2367 }
2368 break;
2369 }
2370 case 'r':
2371 {
2372 if (LocaleCompare("radial-blur",option+1) == 0)
2373 {
2374 /*
2375 Radial blur image.
2376 */
2377 (void) SyncImageSettings(mogrify_info,*image);
2378 mogrify_image=RadialBlurImageChannel(*image,channel,
cristyc1acd842011-05-19 23:05:47 +00002379 InterpretLocaleValue(argv[i+1],(char **) NULL),exception);
anthonydf8ebac2011-04-27 09:03:19 +00002380 break;
2381 }
2382 if (LocaleCompare("raise",option+1) == 0)
2383 {
2384 /*
2385 Surround image with a raise of solid color.
2386 */
2387 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2388 if ((flags & SigmaValue) == 0)
2389 geometry.height=geometry.width;
2390 (void) RaiseImage(*image,&geometry,*option == '-' ? MagickTrue :
2391 MagickFalse);
2392 InheritException(exception,&(*image)->exception);
2393 break;
2394 }
2395 if (LocaleCompare("random-threshold",option+1) == 0)
2396 {
2397 /*
2398 Threshold image.
2399 */
2400 (void) SyncImageSettings(mogrify_info,*image);
2401 (void) RandomThresholdImageChannel(*image,channel,argv[i+1],
2402 exception);
2403 break;
2404 }
2405 if (LocaleCompare("recolor",option+1) == 0)
2406 {
2407 KernelInfo
2408 *kernel;
2409
2410 (void) SyncImageSettings(mogrify_info,*image);
2411 kernel=AcquireKernelInfo(argv[i+1]);
2412 if (kernel == (KernelInfo *) NULL)
2413 break;
2414 mogrify_image=ColorMatrixImage(*image,kernel,exception);
2415 kernel=DestroyKernelInfo(kernel);
2416 break;
2417 }
2418 if (LocaleCompare("region",option+1) == 0)
2419 {
2420 (void) SyncImageSettings(mogrify_info,*image);
2421 if (region_image != (Image *) NULL)
2422 {
2423 /*
2424 Composite region.
2425 */
2426 (void) CompositeImage(region_image,region_image->matte !=
cristyab015852011-07-06 01:03:32 +00002427 MagickFalse ? CopyCompositeOp : OverCompositeOp,*image,
2428 region_geometry.x,region_geometry.y);
anthonydf8ebac2011-04-27 09:03:19 +00002429 InheritException(exception,&region_image->exception);
2430 *image=DestroyImage(*image);
2431 *image=region_image;
2432 region_image = (Image *) NULL;
2433 }
2434 if (*option == '+')
2435 break;
2436 /*
2437 Apply transformations to a selected region of the image.
2438 */
cristy3ed852e2009-09-05 21:47:34 +00002439 (void) ParseGravityGeometry(*image,argv[i+1],&region_geometry,
2440 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002441 mogrify_image=CropImage(*image,&region_geometry,exception);
2442 if (mogrify_image == (Image *) NULL)
2443 break;
2444 region_image=(*image);
2445 *image=mogrify_image;
2446 mogrify_image=(Image *) NULL;
2447 break;
cristy3ed852e2009-09-05 21:47:34 +00002448 }
anthonydf8ebac2011-04-27 09:03:19 +00002449 if (LocaleCompare("render",option+1) == 0)
2450 {
2451 (void) SyncImageSettings(mogrify_info,*image);
2452 draw_info->render=(*option == '+') ? MagickTrue : MagickFalse;
2453 break;
2454 }
2455 if (LocaleCompare("remap",option+1) == 0)
2456 {
2457 Image
2458 *remap_image;
cristy3ed852e2009-09-05 21:47:34 +00002459
anthonydf8ebac2011-04-27 09:03:19 +00002460 /*
2461 Transform image colors to match this set of colors.
2462 */
2463 (void) SyncImageSettings(mogrify_info,*image);
2464 if (*option == '+')
2465 break;
2466 remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
2467 if (remap_image == (Image *) NULL)
2468 break;
2469 (void) RemapImage(quantize_info,*image,remap_image);
2470 InheritException(exception,&(*image)->exception);
2471 remap_image=DestroyImage(remap_image);
2472 break;
2473 }
2474 if (LocaleCompare("repage",option+1) == 0)
2475 {
2476 if (*option == '+')
2477 {
2478 (void) ParseAbsoluteGeometry("0x0+0+0",&(*image)->page);
2479 break;
2480 }
2481 (void) ResetImagePage(*image,argv[i+1]);
2482 InheritException(exception,&(*image)->exception);
2483 break;
2484 }
2485 if (LocaleCompare("resample",option+1) == 0)
2486 {
2487 /*
2488 Resample image.
2489 */
2490 (void) SyncImageSettings(mogrify_info,*image);
2491 flags=ParseGeometry(argv[i+1],&geometry_info);
2492 if ((flags & SigmaValue) == 0)
2493 geometry_info.sigma=geometry_info.rho;
2494 mogrify_image=ResampleImage(*image,geometry_info.rho,
2495 geometry_info.sigma,(*image)->filter,(*image)->blur,exception);
2496 break;
2497 }
2498 if (LocaleCompare("resize",option+1) == 0)
2499 {
2500 /*
2501 Resize image.
2502 */
2503 (void) SyncImageSettings(mogrify_info,*image);
2504 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2505 mogrify_image=ResizeImage(*image,geometry.width,geometry.height,
2506 (*image)->filter,(*image)->blur,exception);
2507 break;
2508 }
2509 if (LocaleCompare("roll",option+1) == 0)
2510 {
2511 /*
2512 Roll image.
2513 */
2514 (void) SyncImageSettings(mogrify_info,*image);
2515 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2516 mogrify_image=RollImage(*image,geometry.x,geometry.y,exception);
2517 break;
2518 }
2519 if (LocaleCompare("rotate",option+1) == 0)
2520 {
2521 char
2522 *geometry;
2523
2524 /*
2525 Check for conditional image rotation.
2526 */
2527 (void) SyncImageSettings(mogrify_info,*image);
2528 if (strchr(argv[i+1],'>') != (char *) NULL)
2529 if ((*image)->columns <= (*image)->rows)
2530 break;
2531 if (strchr(argv[i+1],'<') != (char *) NULL)
2532 if ((*image)->columns >= (*image)->rows)
2533 break;
2534 /*
2535 Rotate image.
2536 */
2537 geometry=ConstantString(argv[i+1]);
2538 (void) SubstituteString(&geometry,">","");
2539 (void) SubstituteString(&geometry,"<","");
2540 (void) ParseGeometry(geometry,&geometry_info);
2541 geometry=DestroyString(geometry);
2542 mogrify_image=RotateImage(*image,geometry_info.rho,exception);
2543 break;
2544 }
2545 break;
2546 }
2547 case 's':
2548 {
2549 if (LocaleCompare("sample",option+1) == 0)
2550 {
2551 /*
2552 Sample image with pixel replication.
2553 */
2554 (void) SyncImageSettings(mogrify_info,*image);
2555 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2556 mogrify_image=SampleImage(*image,geometry.width,geometry.height,
2557 exception);
2558 break;
2559 }
2560 if (LocaleCompare("scale",option+1) == 0)
2561 {
2562 /*
2563 Resize image.
2564 */
2565 (void) SyncImageSettings(mogrify_info,*image);
2566 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2567 mogrify_image=ScaleImage(*image,geometry.width,geometry.height,
2568 exception);
2569 break;
2570 }
2571 if (LocaleCompare("selective-blur",option+1) == 0)
2572 {
2573 /*
2574 Selectively blur pixels within a contrast threshold.
2575 */
2576 (void) SyncImageSettings(mogrify_info,*image);
2577 flags=ParseGeometry(argv[i+1],&geometry_info);
2578 if ((flags & PercentValue) != 0)
2579 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
2580 mogrify_image=SelectiveBlurImageChannel(*image,channel,
2581 geometry_info.rho,geometry_info.sigma,geometry_info.xi,exception);
2582 break;
2583 }
2584 if (LocaleCompare("separate",option+1) == 0)
2585 {
2586 /*
2587 Break channels into separate images.
anthonydf8ebac2011-04-27 09:03:19 +00002588 */
2589 (void) SyncImageSettings(mogrify_info,*image);
cristy3139dc22011-07-08 00:11:42 +00002590 mogrify_image=SeparateImages(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002591 break;
2592 }
2593 if (LocaleCompare("sepia-tone",option+1) == 0)
2594 {
2595 double
2596 threshold;
2597
2598 /*
2599 Sepia-tone image.
2600 */
2601 (void) SyncImageSettings(mogrify_info,*image);
2602 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
2603 mogrify_image=SepiaToneImage(*image,threshold,exception);
2604 break;
2605 }
2606 if (LocaleCompare("segment",option+1) == 0)
2607 {
2608 /*
2609 Segment image.
2610 */
2611 (void) SyncImageSettings(mogrify_info,*image);
2612 flags=ParseGeometry(argv[i+1],&geometry_info);
2613 if ((flags & SigmaValue) == 0)
2614 geometry_info.sigma=1.0;
2615 (void) SegmentImage(*image,(*image)->colorspace,
2616 mogrify_info->verbose,geometry_info.rho,geometry_info.sigma);
2617 InheritException(exception,&(*image)->exception);
2618 break;
2619 }
2620 if (LocaleCompare("set",option+1) == 0)
2621 {
2622 char
2623 *value;
2624
2625 /*
2626 Set image option.
2627 */
2628 if (*option == '+')
2629 {
2630 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2631 (void) DeleteImageRegistry(argv[i+1]+9);
2632 else
2633 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
2634 {
2635 (void) DeleteImageOption(mogrify_info,argv[i+1]+7);
2636 (void) DeleteImageArtifact(*image,argv[i+1]+7);
2637 }
2638 else
2639 (void) DeleteImageProperty(*image,argv[i+1]);
2640 break;
2641 }
2642 value=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
2643 if (value == (char *) NULL)
2644 break;
2645 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2646 (void) SetImageRegistry(StringRegistryType,argv[i+1]+9,value,
2647 exception);
2648 else
2649 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
2650 {
2651 (void) SetImageOption(image_info,argv[i+1]+7,value);
2652 (void) SetImageOption(mogrify_info,argv[i+1]+7,value);
2653 (void) SetImageArtifact(*image,argv[i+1]+7,value);
2654 }
2655 else
2656 (void) SetImageProperty(*image,argv[i+1],value);
2657 value=DestroyString(value);
2658 break;
2659 }
2660 if (LocaleCompare("shade",option+1) == 0)
2661 {
2662 /*
2663 Shade image.
2664 */
2665 (void) SyncImageSettings(mogrify_info,*image);
2666 flags=ParseGeometry(argv[i+1],&geometry_info);
2667 if ((flags & SigmaValue) == 0)
2668 geometry_info.sigma=1.0;
2669 mogrify_image=ShadeImage(*image,(*option == '-') ? MagickTrue :
2670 MagickFalse,geometry_info.rho,geometry_info.sigma,exception);
2671 break;
2672 }
2673 if (LocaleCompare("shadow",option+1) == 0)
2674 {
2675 /*
2676 Shadow image.
2677 */
2678 (void) SyncImageSettings(mogrify_info,*image);
2679 flags=ParseGeometry(argv[i+1],&geometry_info);
2680 if ((flags & SigmaValue) == 0)
2681 geometry_info.sigma=1.0;
2682 if ((flags & XiValue) == 0)
2683 geometry_info.xi=4.0;
2684 if ((flags & PsiValue) == 0)
2685 geometry_info.psi=4.0;
2686 mogrify_image=ShadowImage(*image,geometry_info.rho,
2687 geometry_info.sigma,(ssize_t) ceil(geometry_info.xi-0.5),(ssize_t)
2688 ceil(geometry_info.psi-0.5),exception);
2689 break;
2690 }
2691 if (LocaleCompare("sharpen",option+1) == 0)
2692 {
2693 /*
2694 Sharpen image.
2695 */
2696 (void) SyncImageSettings(mogrify_info,*image);
2697 flags=ParseGeometry(argv[i+1],&geometry_info);
2698 if ((flags & SigmaValue) == 0)
2699 geometry_info.sigma=1.0;
2700 mogrify_image=SharpenImageChannel(*image,channel,geometry_info.rho,
2701 geometry_info.sigma,exception);
2702 break;
2703 }
2704 if (LocaleCompare("shave",option+1) == 0)
2705 {
2706 /*
2707 Shave the image edges.
2708 */
2709 (void) SyncImageSettings(mogrify_info,*image);
2710 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2711 mogrify_image=ShaveImage(*image,&geometry,exception);
2712 break;
2713 }
2714 if (LocaleCompare("shear",option+1) == 0)
2715 {
2716 /*
2717 Shear image.
2718 */
2719 (void) SyncImageSettings(mogrify_info,*image);
2720 flags=ParseGeometry(argv[i+1],&geometry_info);
2721 if ((flags & SigmaValue) == 0)
2722 geometry_info.sigma=geometry_info.rho;
2723 mogrify_image=ShearImage(*image,geometry_info.rho,
2724 geometry_info.sigma,exception);
2725 break;
2726 }
2727 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
2728 {
2729 /*
2730 Sigmoidal non-linearity contrast control.
2731 */
2732 (void) SyncImageSettings(mogrify_info,*image);
2733 flags=ParseGeometry(argv[i+1],&geometry_info);
2734 if ((flags & SigmaValue) == 0)
2735 geometry_info.sigma=(double) QuantumRange/2.0;
2736 if ((flags & PercentValue) != 0)
2737 geometry_info.sigma=(double) QuantumRange*geometry_info.sigma/
2738 100.0;
cristy9ee60942011-07-06 14:54:38 +00002739 (void) SigmoidalContrastImage(*image,(*option == '-') ?
2740 MagickTrue : MagickFalse,geometry_info.rho,geometry_info.sigma);
anthonydf8ebac2011-04-27 09:03:19 +00002741 InheritException(exception,&(*image)->exception);
2742 break;
2743 }
2744 if (LocaleCompare("sketch",option+1) == 0)
2745 {
2746 /*
2747 Sketch image.
2748 */
2749 (void) SyncImageSettings(mogrify_info,*image);
2750 flags=ParseGeometry(argv[i+1],&geometry_info);
2751 if ((flags & SigmaValue) == 0)
2752 geometry_info.sigma=1.0;
2753 mogrify_image=SketchImage(*image,geometry_info.rho,
2754 geometry_info.sigma,geometry_info.xi,exception);
2755 break;
2756 }
2757 if (LocaleCompare("solarize",option+1) == 0)
2758 {
2759 double
2760 threshold;
2761
2762 (void) SyncImageSettings(mogrify_info,*image);
2763 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
2764 (void) SolarizeImage(*image,threshold);
2765 InheritException(exception,&(*image)->exception);
2766 break;
2767 }
2768 if (LocaleCompare("sparse-color",option+1) == 0)
2769 {
2770 SparseColorMethod
2771 method;
2772
2773 char
2774 *arguments;
2775
2776 /*
2777 Sparse Color Interpolated Gradient
2778 */
2779 (void) SyncImageSettings(mogrify_info,*image);
2780 method=(SparseColorMethod) ParseCommandOption(
2781 MagickSparseColorOptions,MagickFalse,argv[i+1]);
2782 arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
2783 InheritException(exception,&(*image)->exception);
2784 if (arguments == (char *) NULL)
2785 break;
2786 mogrify_image=SparseColorOption(*image,channel,method,arguments,
2787 option[0] == '+' ? MagickTrue : MagickFalse,exception);
2788 arguments=DestroyString(arguments);
2789 break;
2790 }
2791 if (LocaleCompare("splice",option+1) == 0)
2792 {
2793 /*
2794 Splice a solid color into the image.
2795 */
2796 (void) SyncImageSettings(mogrify_info,*image);
2797 (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
2798 mogrify_image=SpliceImage(*image,&geometry,exception);
2799 break;
2800 }
2801 if (LocaleCompare("spread",option+1) == 0)
2802 {
2803 /*
2804 Spread an image.
2805 */
2806 (void) SyncImageSettings(mogrify_info,*image);
2807 (void) ParseGeometry(argv[i+1],&geometry_info);
2808 mogrify_image=SpreadImage(*image,geometry_info.rho,exception);
2809 break;
2810 }
2811 if (LocaleCompare("statistic",option+1) == 0)
2812 {
2813 StatisticType
2814 type;
2815
2816 (void) SyncImageSettings(mogrify_info,*image);
2817 type=(StatisticType) ParseCommandOption(MagickStatisticOptions,
2818 MagickFalse,argv[i+1]);
2819 (void) ParseGeometry(argv[i+2],&geometry_info);
2820 mogrify_image=StatisticImageChannel(*image,channel,type,(size_t)
2821 geometry_info.rho,(size_t) geometry_info.sigma,exception);
2822 break;
2823 }
2824 if (LocaleCompare("stretch",option+1) == 0)
2825 {
2826 if (*option == '+')
2827 {
2828 draw_info->stretch=UndefinedStretch;
2829 break;
2830 }
2831 draw_info->stretch=(StretchType) ParseCommandOption(
2832 MagickStretchOptions,MagickFalse,argv[i+1]);
2833 break;
2834 }
2835 if (LocaleCompare("strip",option+1) == 0)
2836 {
2837 /*
2838 Strip image of profiles and comments.
2839 */
2840 (void) SyncImageSettings(mogrify_info,*image);
2841 (void) StripImage(*image);
2842 InheritException(exception,&(*image)->exception);
2843 break;
2844 }
2845 if (LocaleCompare("stroke",option+1) == 0)
2846 {
2847 ExceptionInfo
2848 *sans;
2849
2850 if (*option == '+')
2851 {
2852 (void) QueryColorDatabase("none",&draw_info->stroke,exception);
2853 if (draw_info->stroke_pattern != (Image *) NULL)
2854 draw_info->stroke_pattern=DestroyImage(
2855 draw_info->stroke_pattern);
2856 break;
2857 }
2858 sans=AcquireExceptionInfo();
2859 status=QueryColorDatabase(argv[i+1],&draw_info->stroke,sans);
2860 sans=DestroyExceptionInfo(sans);
2861 if (status == MagickFalse)
2862 draw_info->stroke_pattern=GetImageCache(mogrify_info,argv[i+1],
2863 exception);
2864 break;
2865 }
2866 if (LocaleCompare("strokewidth",option+1) == 0)
2867 {
cristyc1acd842011-05-19 23:05:47 +00002868 draw_info->stroke_width=InterpretLocaleValue(argv[i+1],
2869 (char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00002870 break;
2871 }
2872 if (LocaleCompare("style",option+1) == 0)
2873 {
2874 if (*option == '+')
2875 {
2876 draw_info->style=UndefinedStyle;
2877 break;
2878 }
2879 draw_info->style=(StyleType) ParseCommandOption(MagickStyleOptions,
2880 MagickFalse,argv[i+1]);
2881 break;
2882 }
2883 if (LocaleCompare("swirl",option+1) == 0)
2884 {
2885 /*
2886 Swirl image.
2887 */
2888 (void) SyncImageSettings(mogrify_info,*image);
2889 (void) ParseGeometry(argv[i+1],&geometry_info);
2890 mogrify_image=SwirlImage(*image,geometry_info.rho,exception);
2891 break;
2892 }
2893 break;
2894 }
2895 case 't':
2896 {
2897 if (LocaleCompare("threshold",option+1) == 0)
2898 {
2899 double
2900 threshold;
2901
2902 /*
2903 Threshold image.
2904 */
2905 (void) SyncImageSettings(mogrify_info,*image);
2906 if (*option == '+')
anthony247a86d2011-05-03 13:18:18 +00002907 threshold=(double) QuantumRange/2;
anthonydf8ebac2011-04-27 09:03:19 +00002908 else
2909 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
2910 (void) BilevelImageChannel(*image,channel,threshold);
2911 InheritException(exception,&(*image)->exception);
2912 break;
2913 }
2914 if (LocaleCompare("thumbnail",option+1) == 0)
2915 {
2916 /*
2917 Thumbnail image.
2918 */
2919 (void) SyncImageSettings(mogrify_info,*image);
2920 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2921 mogrify_image=ThumbnailImage(*image,geometry.width,geometry.height,
2922 exception);
2923 break;
2924 }
2925 if (LocaleCompare("tile",option+1) == 0)
2926 {
2927 if (*option == '+')
2928 {
2929 if (draw_info->fill_pattern != (Image *) NULL)
2930 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
2931 break;
2932 }
2933 draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1],
2934 exception);
2935 break;
2936 }
2937 if (LocaleCompare("tint",option+1) == 0)
2938 {
2939 /*
2940 Tint the image.
2941 */
2942 (void) SyncImageSettings(mogrify_info,*image);
2943 mogrify_image=TintImage(*image,argv[i+1],draw_info->fill,exception);
2944 break;
2945 }
2946 if (LocaleCompare("transform",option+1) == 0)
2947 {
2948 /*
2949 Affine transform image.
2950 */
2951 (void) SyncImageSettings(mogrify_info,*image);
2952 mogrify_image=AffineTransformImage(*image,&draw_info->affine,
2953 exception);
2954 break;
2955 }
2956 if (LocaleCompare("transparent",option+1) == 0)
2957 {
cristy4c08aed2011-07-01 19:47:50 +00002958 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00002959 target;
2960
2961 (void) SyncImageSettings(mogrify_info,*image);
2962 (void) QueryMagickColor(argv[i+1],&target,exception);
2963 (void) TransparentPaintImage(*image,&target,(Quantum)
cristy4c08aed2011-07-01 19:47:50 +00002964 TransparentAlpha,*option == '-' ? MagickFalse : MagickTrue);
anthonydf8ebac2011-04-27 09:03:19 +00002965 InheritException(exception,&(*image)->exception);
2966 break;
2967 }
2968 if (LocaleCompare("transpose",option+1) == 0)
2969 {
2970 /*
2971 Transpose image scanlines.
2972 */
2973 (void) SyncImageSettings(mogrify_info,*image);
2974 mogrify_image=TransposeImage(*image,exception);
2975 break;
2976 }
2977 if (LocaleCompare("transverse",option+1) == 0)
2978 {
2979 /*
2980 Transverse image scanlines.
2981 */
2982 (void) SyncImageSettings(mogrify_info,*image);
2983 mogrify_image=TransverseImage(*image,exception);
2984 break;
2985 }
2986 if (LocaleCompare("treedepth",option+1) == 0)
2987 {
2988 quantize_info->tree_depth=StringToUnsignedLong(argv[i+1]);
2989 break;
2990 }
2991 if (LocaleCompare("trim",option+1) == 0)
2992 {
2993 /*
2994 Trim image.
2995 */
2996 (void) SyncImageSettings(mogrify_info,*image);
2997 mogrify_image=TrimImage(*image,exception);
2998 break;
2999 }
3000 if (LocaleCompare("type",option+1) == 0)
3001 {
3002 ImageType
3003 type;
3004
3005 (void) SyncImageSettings(mogrify_info,*image);
3006 if (*option == '+')
3007 type=UndefinedType;
3008 else
3009 type=(ImageType) ParseCommandOption(MagickTypeOptions,MagickFalse,
3010 argv[i+1]);
3011 (*image)->type=UndefinedType;
3012 (void) SetImageType(*image,type);
3013 InheritException(exception,&(*image)->exception);
3014 break;
3015 }
3016 break;
3017 }
3018 case 'u':
3019 {
3020 if (LocaleCompare("undercolor",option+1) == 0)
3021 {
3022 (void) QueryColorDatabase(argv[i+1],&draw_info->undercolor,
3023 exception);
3024 break;
3025 }
3026 if (LocaleCompare("unique",option+1) == 0)
3027 {
3028 if (*option == '+')
3029 {
3030 (void) DeleteImageArtifact(*image,"identify:unique-colors");
3031 break;
3032 }
3033 (void) SetImageArtifact(*image,"identify:unique-colors","true");
3034 (void) SetImageArtifact(*image,"verbose","true");
3035 break;
3036 }
3037 if (LocaleCompare("unique-colors",option+1) == 0)
3038 {
3039 /*
3040 Unique image colors.
3041 */
3042 (void) SyncImageSettings(mogrify_info,*image);
3043 mogrify_image=UniqueImageColors(*image,exception);
3044 break;
3045 }
3046 if (LocaleCompare("unsharp",option+1) == 0)
3047 {
3048 /*
3049 Unsharp mask image.
3050 */
3051 (void) SyncImageSettings(mogrify_info,*image);
3052 flags=ParseGeometry(argv[i+1],&geometry_info);
3053 if ((flags & SigmaValue) == 0)
3054 geometry_info.sigma=1.0;
3055 if ((flags & XiValue) == 0)
3056 geometry_info.xi=1.0;
3057 if ((flags & PsiValue) == 0)
3058 geometry_info.psi=0.05;
3059 mogrify_image=UnsharpMaskImageChannel(*image,channel,
3060 geometry_info.rho,geometry_info.sigma,geometry_info.xi,
3061 geometry_info.psi,exception);
3062 break;
3063 }
3064 break;
3065 }
3066 case 'v':
3067 {
3068 if (LocaleCompare("verbose",option+1) == 0)
3069 {
3070 (void) SetImageArtifact(*image,option+1,
3071 *option == '+' ? "false" : "true");
3072 break;
3073 }
3074 if (LocaleCompare("vignette",option+1) == 0)
3075 {
3076 /*
3077 Vignette image.
3078 */
3079 (void) SyncImageSettings(mogrify_info,*image);
3080 flags=ParseGeometry(argv[i+1],&geometry_info);
3081 if ((flags & SigmaValue) == 0)
3082 geometry_info.sigma=1.0;
3083 if ((flags & XiValue) == 0)
3084 geometry_info.xi=0.1*(*image)->columns;
3085 if ((flags & PsiValue) == 0)
3086 geometry_info.psi=0.1*(*image)->rows;
3087 mogrify_image=VignetteImage(*image,geometry_info.rho,
3088 geometry_info.sigma,(ssize_t) ceil(geometry_info.xi-0.5),(ssize_t)
3089 ceil(geometry_info.psi-0.5),exception);
3090 break;
3091 }
3092 if (LocaleCompare("virtual-pixel",option+1) == 0)
3093 {
3094 if (*option == '+')
3095 {
3096 (void) SetImageVirtualPixelMethod(*image,
3097 UndefinedVirtualPixelMethod);
3098 break;
3099 }
3100 (void) SetImageVirtualPixelMethod(*image,(VirtualPixelMethod)
3101 ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
3102 argv[i+1]));
3103 break;
3104 }
3105 break;
3106 }
3107 case 'w':
3108 {
3109 if (LocaleCompare("wave",option+1) == 0)
3110 {
3111 /*
3112 Wave image.
3113 */
3114 (void) SyncImageSettings(mogrify_info,*image);
3115 flags=ParseGeometry(argv[i+1],&geometry_info);
3116 if ((flags & SigmaValue) == 0)
3117 geometry_info.sigma=1.0;
3118 mogrify_image=WaveImage(*image,geometry_info.rho,
3119 geometry_info.sigma,exception);
3120 break;
3121 }
3122 if (LocaleCompare("weight",option+1) == 0)
3123 {
3124 draw_info->weight=StringToUnsignedLong(argv[i+1]);
3125 if (LocaleCompare(argv[i+1],"all") == 0)
3126 draw_info->weight=0;
3127 if (LocaleCompare(argv[i+1],"bold") == 0)
3128 draw_info->weight=700;
3129 if (LocaleCompare(argv[i+1],"bolder") == 0)
3130 if (draw_info->weight <= 800)
3131 draw_info->weight+=100;
3132 if (LocaleCompare(argv[i+1],"lighter") == 0)
3133 if (draw_info->weight >= 100)
3134 draw_info->weight-=100;
3135 if (LocaleCompare(argv[i+1],"normal") == 0)
3136 draw_info->weight=400;
3137 break;
3138 }
3139 if (LocaleCompare("white-threshold",option+1) == 0)
3140 {
3141 /*
3142 White threshold image.
3143 */
3144 (void) SyncImageSettings(mogrify_info,*image);
3145 (void) WhiteThresholdImageChannel(*image,channel,argv[i+1],
3146 exception);
3147 InheritException(exception,&(*image)->exception);
3148 break;
3149 }
3150 break;
3151 }
3152 default:
3153 break;
3154 }
3155 /*
3156 Replace current image with any image that was generated
3157 */
3158 if (mogrify_image != (Image *) NULL)
3159 ReplaceImageInListReturnLast(image,mogrify_image);
cristy3ed852e2009-09-05 21:47:34 +00003160 i+=count;
3161 }
3162 if (region_image != (Image *) NULL)
3163 {
anthonydf8ebac2011-04-27 09:03:19 +00003164 /*
3165 Composite transformed region onto image.
3166 */
cristy6b3da3a2010-06-20 02:21:46 +00003167 (void) SyncImageSettings(mogrify_info,*image);
anthonya129f702011-04-14 01:08:48 +00003168 (void) CompositeImage(region_image,region_image->matte !=
cristyab015852011-07-06 01:03:32 +00003169 MagickFalse ? CopyCompositeOp : OverCompositeOp,*image,
3170 region_geometry.x,region_geometry.y);
cristy3ed852e2009-09-05 21:47:34 +00003171 InheritException(exception,&region_image->exception);
3172 *image=DestroyImage(*image);
3173 *image=region_image;
anthonye9c27192011-03-27 08:07:06 +00003174 region_image = (Image *) NULL;
cristy3ed852e2009-09-05 21:47:34 +00003175 }
3176 /*
3177 Free resources.
3178 */
anthonydf8ebac2011-04-27 09:03:19 +00003179 quantize_info=DestroyQuantizeInfo(quantize_info);
3180 draw_info=DestroyDrawInfo(draw_info);
cristy6b3da3a2010-06-20 02:21:46 +00003181 mogrify_info=DestroyImageInfo(mogrify_info);
cristy4c08aed2011-07-01 19:47:50 +00003182 status=(MagickStatusType) ((*image)->exception.severity ==
cristy5f09d852011-05-29 01:39:29 +00003183 UndefinedException ? 1 : 0);
cristy72988482011-03-29 16:34:38 +00003184 return(status == 0 ? MagickFalse : MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00003185}
3186
3187/*
3188%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3189% %
3190% %
3191% %
cristy5063d812010-10-19 16:28:10 +00003192+ M o g r i f y I m a g e C o m m a n d %
cristy3ed852e2009-09-05 21:47:34 +00003193% %
3194% %
3195% %
3196%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3197%
3198% MogrifyImageCommand() transforms an image or a sequence of images. These
3199% transforms include image scaling, image rotation, color reduction, and
3200% others. The transmogrified image overwrites the original image.
3201%
3202% The format of the MogrifyImageCommand method is:
3203%
3204% MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,int argc,
3205% const char **argv,char **metadata,ExceptionInfo *exception)
3206%
3207% A description of each parameter follows:
3208%
3209% o image_info: the image info.
3210%
3211% o argc: the number of elements in the argument vector.
3212%
3213% o argv: A text array containing the command line arguments.
3214%
3215% o metadata: any metadata is returned here.
3216%
3217% o exception: return any errors or warnings in this structure.
3218%
3219*/
3220
3221static MagickBooleanType MogrifyUsage(void)
3222{
3223 static const char
3224 *miscellaneous[]=
3225 {
3226 "-debug events display copious debugging information",
3227 "-help print program options",
3228 "-list type print a list of supported option arguments",
3229 "-log format format of debugging information",
3230 "-version print version information",
3231 (char *) NULL
3232 },
3233 *operators[]=
3234 {
3235 "-adaptive-blur geometry",
3236 " adaptively blur pixels; decrease effect near edges",
3237 "-adaptive-resize geometry",
3238 " adaptively resize image using 'mesh' interpolation",
3239 "-adaptive-sharpen geometry",
3240 " adaptively sharpen pixels; increase effect near edges",
3241 "-alpha option on, activate, off, deactivate, set, opaque, copy",
3242 " transparent, extract, background, or shape",
3243 "-annotate geometry text",
3244 " annotate the image with text",
3245 "-auto-gamma automagically adjust gamma level of image",
3246 "-auto-level automagically adjust color levels of image",
3247 "-auto-orient automagically orient (rotate) image",
3248 "-bench iterations measure performance",
3249 "-black-threshold value",
3250 " force all pixels below the threshold into black",
3251 "-blue-shift simulate a scene at nighttime in the moonlight",
3252 "-blur geometry reduce image noise and reduce detail levels",
3253 "-border geometry surround image with a border of color",
3254 "-bordercolor color border color",
cristya28d6b82010-01-11 20:03:47 +00003255 "-brightness-contrast geometry",
3256 " improve brightness / contrast of the image",
cristy3ed852e2009-09-05 21:47:34 +00003257 "-cdl filename color correct with a color decision list",
3258 "-charcoal radius simulate a charcoal drawing",
3259 "-chop geometry remove pixels from the image interior",
cristyecb0c6d2009-09-25 16:50:09 +00003260 "-clamp restrict pixel range from 0 to the quantum depth",
cristycee97112010-05-28 00:44:52 +00003261 "-clip clip along the first path from the 8BIM profile",
cristy3ed852e2009-09-05 21:47:34 +00003262 "-clip-mask filename associate a clip mask with the image",
cristycee97112010-05-28 00:44:52 +00003263 "-clip-path id clip along a named path from the 8BIM profile",
cristy3ed852e2009-09-05 21:47:34 +00003264 "-colorize value colorize the image with the fill color",
cristye6365592010-04-02 17:31:23 +00003265 "-color-matrix matrix apply color correction to the image",
cristy3ed852e2009-09-05 21:47:34 +00003266 "-contrast enhance or reduce the image contrast",
3267 "-contrast-stretch geometry",
3268 " improve contrast by `stretching' the intensity range",
3269 "-convolve coefficients",
3270 " apply a convolution kernel to the image",
3271 "-cycle amount cycle the image colormap",
3272 "-decipher filename convert cipher pixels to plain pixels",
3273 "-deskew threshold straighten an image",
3274 "-despeckle reduce the speckles within an image",
3275 "-distort method args",
3276 " distort images according to given method ad args",
3277 "-draw string annotate the image with a graphic primitive",
3278 "-edge radius apply a filter to detect edges in the image",
3279 "-encipher filename convert plain pixels to cipher pixels",
3280 "-emboss radius emboss an image",
3281 "-enhance apply a digital filter to enhance a noisy image",
3282 "-equalize perform histogram equalization to an image",
3283 "-evaluate operator value",
cristyd18ae7c2010-03-07 17:39:52 +00003284 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003285 "-extent geometry set the image size",
3286 "-extract geometry extract area from image",
3287 "-fft implements the discrete Fourier transform (DFT)",
3288 "-flip flip image vertically",
3289 "-floodfill geometry color",
3290 " floodfill the image with color",
3291 "-flop flop image horizontally",
3292 "-frame geometry surround image with an ornamental border",
cristyc2b730e2009-11-24 14:32:09 +00003293 "-function name parameters",
cristy3ed852e2009-09-05 21:47:34 +00003294 " apply function over image values",
3295 "-gamma value level of gamma correction",
3296 "-gaussian-blur geometry",
3297 " reduce image noise and reduce detail levels",
cristy901f09d2009-10-16 22:56:10 +00003298 "-geometry geometry preferred size or location of the image",
cristy3ed852e2009-09-05 21:47:34 +00003299 "-identify identify the format and characteristics of the image",
3300 "-ift implements the inverse discrete Fourier transform (DFT)",
3301 "-implode amount implode image pixels about the center",
3302 "-lat geometry local adaptive thresholding",
3303 "-layers method optimize, merge, or compare image layers",
3304 "-level value adjust the level of image contrast",
3305 "-level-colors color,color",
cristyee0f8d72009-09-19 00:58:29 +00003306 " level image with the given colors",
cristy3ed852e2009-09-05 21:47:34 +00003307 "-linear-stretch geometry",
3308 " improve contrast by `stretching with saturation'",
3309 "-liquid-rescale geometry",
3310 " rescale image with seam-carving",
cristy3c741502011-04-01 23:21:16 +00003311 "-median geometry apply a median filter to the image",
glennrp30d2dc62011-06-25 03:17:16 +00003312 "-mode geometry make each pixel the 'predominant color' of the neighborhood",
cristy3ed852e2009-09-05 21:47:34 +00003313 "-modulate value vary the brightness, saturation, and hue",
3314 "-monochrome transform image to black and white",
cristy7c1b9fd2010-02-02 14:36:00 +00003315 "-morphology method kernel",
anthony29188a82010-01-22 10:12:34 +00003316 " apply a morphology method to the image",
cristy3ed852e2009-09-05 21:47:34 +00003317 "-motion-blur geometry",
3318 " simulate motion blur",
3319 "-negate replace every pixel with its complementary color ",
cristy3c741502011-04-01 23:21:16 +00003320 "-noise geometry add or reduce noise in an image",
cristy3ed852e2009-09-05 21:47:34 +00003321 "-normalize transform image to span the full range of colors",
3322 "-opaque color change this color to the fill color",
3323 "-ordered-dither NxN",
3324 " add a noise pattern to the image with specific",
3325 " amplitudes",
3326 "-paint radius simulate an oil painting",
3327 "-polaroid angle simulate a Polaroid picture",
3328 "-posterize levels reduce the image to a limited number of color levels",
cristy3ed852e2009-09-05 21:47:34 +00003329 "-profile filename add, delete, or apply an image profile",
3330 "-quantize colorspace reduce colors in this colorspace",
3331 "-radial-blur angle radial blur the image",
3332 "-raise value lighten/darken image edges to create a 3-D effect",
3333 "-random-threshold low,high",
3334 " random threshold the image",
cristy3ed852e2009-09-05 21:47:34 +00003335 "-region geometry apply options to a portion of the image",
3336 "-render render vector graphics",
3337 "-repage geometry size and location of an image canvas",
3338 "-resample geometry change the resolution of an image",
3339 "-resize geometry resize the image",
3340 "-roll geometry roll an image vertically or horizontally",
3341 "-rotate degrees apply Paeth rotation to the image",
3342 "-sample geometry scale image with pixel sampling",
3343 "-scale geometry scale the image",
3344 "-segment values segment an image",
3345 "-selective-blur geometry",
3346 " selectively blur pixels within a contrast threshold",
3347 "-sepia-tone threshold",
3348 " simulate a sepia-toned photo",
3349 "-set property value set an image property",
3350 "-shade degrees shade the image using a distant light source",
3351 "-shadow geometry simulate an image shadow",
3352 "-sharpen geometry sharpen the image",
3353 "-shave geometry shave pixels from the image edges",
cristycee97112010-05-28 00:44:52 +00003354 "-shear geometry slide one edge of the image along the X or Y axis",
cristy3ed852e2009-09-05 21:47:34 +00003355 "-sigmoidal-contrast geometry",
3356 " increase the contrast without saturating highlights or shadows",
3357 "-sketch geometry simulate a pencil sketch",
3358 "-solarize threshold negate all pixels above the threshold level",
3359 "-sparse-color method args",
3360 " fill in a image based on a few color points",
3361 "-splice geometry splice the background color into the image",
3362 "-spread radius displace image pixels by a random amount",
cristy0834d642011-03-18 18:26:08 +00003363 "-statistic type radius",
3364 " replace each pixel with corresponding statistic from the neighborhood",
cristy3ed852e2009-09-05 21:47:34 +00003365 "-strip strip image of all profiles and comments",
3366 "-swirl degrees swirl image pixels about the center",
3367 "-threshold value threshold the image",
3368 "-thumbnail geometry create a thumbnail of the image",
3369 "-tile filename tile image when filling a graphic primitive",
3370 "-tint value tint the image with the fill color",
3371 "-transform affine transform image",
3372 "-transparent color make this color transparent within the image",
3373 "-transpose flip image vertically and rotate 90 degrees",
3374 "-transverse flop image horizontally and rotate 270 degrees",
3375 "-trim trim image edges",
3376 "-type type image type",
3377 "-unique-colors discard all but one of any pixel color",
3378 "-unsharp geometry sharpen the image",
3379 "-vignette geometry soften the edges of the image in vignette style",
cristycee97112010-05-28 00:44:52 +00003380 "-wave geometry alter an image along a sine wave",
cristy3ed852e2009-09-05 21:47:34 +00003381 "-white-threshold value",
3382 " force all pixels above the threshold into white",
3383 (char *) NULL
3384 },
3385 *sequence_operators[]=
3386 {
cristy4285d782011-02-09 20:12:28 +00003387 "-append append an image sequence",
cristy3ed852e2009-09-05 21:47:34 +00003388 "-clut apply a color lookup table to the image",
3389 "-coalesce merge a sequence of images",
3390 "-combine combine a sequence of images",
3391 "-composite composite image",
3392 "-crop geometry cut out a rectangular region of the image",
3393 "-deconstruct break down an image sequence into constituent parts",
cristyd18ae7c2010-03-07 17:39:52 +00003394 "-evaluate-sequence operator",
3395 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003396 "-flatten flatten a sequence of images",
3397 "-fx expression apply mathematical expression to an image channel(s)",
3398 "-hald-clut apply a Hald color lookup table to the image",
3399 "-morph value morph an image sequence",
3400 "-mosaic create a mosaic from an image sequence",
cristy36b94822010-05-20 12:48:16 +00003401 "-print string interpret string and print to console",
cristy3ed852e2009-09-05 21:47:34 +00003402 "-process arguments process the image with a custom image filter",
cristy3ed852e2009-09-05 21:47:34 +00003403 "-separate separate an image channel into a grayscale image",
cristy4285d782011-02-09 20:12:28 +00003404 "-smush geometry smush an image sequence together",
cristy3ed852e2009-09-05 21:47:34 +00003405 "-write filename write images to this file",
3406 (char *) NULL
3407 },
3408 *settings[]=
3409 {
3410 "-adjoin join images into a single multi-image file",
3411 "-affine matrix affine transform matrix",
3412 "-alpha option activate, deactivate, reset, or set the alpha channel",
3413 "-antialias remove pixel-aliasing",
3414 "-authenticate password",
3415 " decipher image with this password",
3416 "-attenuate value lessen (or intensify) when adding noise to an image",
3417 "-background color background color",
3418 "-bias value add bias when convolving an image",
3419 "-black-point-compensation",
3420 " use black point compensation",
3421 "-blue-primary point chromaticity blue primary point",
3422 "-bordercolor color border color",
3423 "-caption string assign a caption to an image",
3424 "-channel type apply option to select image channels",
3425 "-colors value preferred number of colors in the image",
3426 "-colorspace type alternate image colorspace",
3427 "-comment string annotate image with comment",
3428 "-compose operator set image composite operator",
3429 "-compress type type of pixel compression when writing the image",
3430 "-define format:option",
3431 " define one or more image format options",
3432 "-delay value display the next image after pausing",
3433 "-density geometry horizontal and vertical density of the image",
3434 "-depth value image depth",
cristyc9b12952010-03-28 01:12:28 +00003435 "-direction type render text right-to-left or left-to-right",
cristy3ed852e2009-09-05 21:47:34 +00003436 "-display server get image or font from this X server",
3437 "-dispose method layer disposal method",
3438 "-dither method apply error diffusion to image",
3439 "-encoding type text encoding type",
3440 "-endian type endianness (MSB or LSB) of the image",
3441 "-family name render text with this font family",
3442 "-fill color color to use when filling a graphic primitive",
3443 "-filter type use this filter when resizing an image",
3444 "-font name render text with this font",
3445 "-format \"string\" output formatted image characteristics",
3446 "-fuzz distance colors within this distance are considered equal",
3447 "-gravity type horizontal and vertical text placement",
3448 "-green-primary point chromaticity green primary point",
3449 "-intent type type of rendering intent when managing the image color",
3450 "-interlace type type of image interlacing scheme",
cristyb32b90a2009-09-07 21:45:48 +00003451 "-interline-spacing value",
3452 " set the space between two text lines",
cristy3ed852e2009-09-05 21:47:34 +00003453 "-interpolate method pixel color interpolation method",
3454 "-interword-spacing value",
3455 " set the space between two words",
3456 "-kerning value set the space between two letters",
3457 "-label string assign a label to an image",
3458 "-limit type value pixel cache resource limit",
3459 "-loop iterations add Netscape loop extension to your GIF animation",
3460 "-mask filename associate a mask with the image",
3461 "-mattecolor color frame color",
3462 "-monitor monitor progress",
3463 "-orient type image orientation",
3464 "-page geometry size and location of an image canvas (setting)",
3465 "-ping efficiently determine image attributes",
3466 "-pointsize value font point size",
cristy7c1b9fd2010-02-02 14:36:00 +00003467 "-precision value maximum number of significant digits to print",
cristy3ed852e2009-09-05 21:47:34 +00003468 "-preview type image preview type",
3469 "-quality value JPEG/MIFF/PNG compression level",
3470 "-quiet suppress all warning messages",
3471 "-red-primary point chromaticity red primary point",
3472 "-regard-warnings pay attention to warning messages",
3473 "-remap filename transform image colors to match this set of colors",
3474 "-respect-parentheses settings remain in effect until parenthesis boundary",
3475 "-sampling-factor geometry",
3476 " horizontal and vertical sampling factor",
3477 "-scene value image scene number",
3478 "-seed value seed a new sequence of pseudo-random numbers",
3479 "-size geometry width and height of image",
3480 "-stretch type render text with this font stretch",
3481 "-stroke color graphic primitive stroke color",
3482 "-strokewidth value graphic primitive stroke width",
3483 "-style type render text with this font style",
cristyd9a29192010-10-16 16:49:53 +00003484 "-synchronize synchronize image to storage device",
3485 "-taint declare the image as modified",
cristy3ed852e2009-09-05 21:47:34 +00003486 "-texture filename name of texture to tile onto the image background",
3487 "-tile-offset geometry",
3488 " tile offset",
3489 "-treedepth value color tree depth",
3490 "-transparent-color color",
3491 " transparent color",
3492 "-undercolor color annotation bounding box color",
3493 "-units type the units of image resolution",
3494 "-verbose print detailed information about the image",
3495 "-view FlashPix viewing transforms",
3496 "-virtual-pixel method",
3497 " virtual pixel access method",
3498 "-weight type render text with this font weight",
3499 "-white-point point chromaticity white point",
3500 (char *) NULL
3501 },
3502 *stack_operators[]=
3503 {
anthonyb69c4b32011-03-23 04:37:44 +00003504 "-delete indexes delete the image from the image sequence",
3505 "-duplicate count,indexes",
cristyecb10ff2011-03-22 13:14:03 +00003506 " duplicate an image one or more times",
cristy3ed852e2009-09-05 21:47:34 +00003507 "-insert index insert last image into the image sequence",
anthony9bd15492011-03-23 02:11:13 +00003508 "-reverse reverse image sequence",
cristy3ed852e2009-09-05 21:47:34 +00003509 "-swap indexes swap two images in the image sequence",
3510 (char *) NULL
3511 };
3512
3513 const char
3514 **p;
3515
cristybb503372010-05-27 20:51:26 +00003516 (void) printf("Version: %s\n",GetMagickVersion((size_t *) NULL));
cristy610b2e22009-10-22 14:59:43 +00003517 (void) printf("Copyright: %s\n",GetMagickCopyright());
3518 (void) printf("Features: %s\n\n",GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00003519 (void) printf("Usage: %s [options ...] file [ [options ...] file ...]\n",
3520 GetClientName());
3521 (void) printf("\nImage Settings:\n");
3522 for (p=settings; *p != (char *) NULL; p++)
3523 (void) printf(" %s\n",*p);
3524 (void) printf("\nImage Operators:\n");
3525 for (p=operators; *p != (char *) NULL; p++)
3526 (void) printf(" %s\n",*p);
3527 (void) printf("\nImage Sequence Operators:\n");
3528 for (p=sequence_operators; *p != (char *) NULL; p++)
3529 (void) printf(" %s\n",*p);
3530 (void) printf("\nImage Stack Operators:\n");
3531 for (p=stack_operators; *p != (char *) NULL; p++)
3532 (void) printf(" %s\n",*p);
3533 (void) printf("\nMiscellaneous Options:\n");
3534 for (p=miscellaneous; *p != (char *) NULL; p++)
3535 (void) printf(" %s\n",*p);
3536 (void) printf(
3537 "\nBy default, the image format of `file' is determined by its magic\n");
3538 (void) printf(
3539 "number. To specify a particular image format, precede the filename\n");
3540 (void) printf(
3541 "with an image format name and a colon (i.e. ps:image) or specify the\n");
3542 (void) printf(
3543 "image type as the filename suffix (i.e. image.ps). Specify 'file' as\n");
3544 (void) printf("'-' for standard input or output.\n");
3545 return(MagickFalse);
3546}
3547
3548WandExport MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,
3549 int argc,char **argv,char **wand_unused(metadata),ExceptionInfo *exception)
3550{
3551#define DestroyMogrify() \
3552{ \
3553 if (format != (char *) NULL) \
3554 format=DestroyString(format); \
3555 if (path != (char *) NULL) \
3556 path=DestroyString(path); \
3557 DestroyImageStack(); \
cristybb503372010-05-27 20:51:26 +00003558 for (i=0; i < (ssize_t) argc; i++) \
cristy3ed852e2009-09-05 21:47:34 +00003559 argv[i]=DestroyString(argv[i]); \
3560 argv=(char **) RelinquishMagickMemory(argv); \
3561}
3562#define ThrowMogrifyException(asperity,tag,option) \
3563{ \
3564 (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag,"`%s'", \
3565 option); \
3566 DestroyMogrify(); \
3567 return(MagickFalse); \
3568}
3569#define ThrowMogrifyInvalidArgumentException(option,argument) \
3570{ \
3571 (void) ThrowMagickException(exception,GetMagickModule(),OptionError, \
3572 "InvalidArgument","`%s': %s",argument,option); \
3573 DestroyMogrify(); \
3574 return(MagickFalse); \
3575}
3576
3577 char
3578 *format,
3579 *option,
3580 *path;
3581
3582 Image
3583 *image;
3584
3585 ImageStack
3586 image_stack[MaxImageStackDepth+1];
3587
cristy3ed852e2009-09-05 21:47:34 +00003588 MagickBooleanType
3589 global_colormap;
3590
3591 MagickBooleanType
3592 fire,
cristyebbcfea2011-02-25 02:43:54 +00003593 pend,
3594 respect_parenthesis;
cristy3ed852e2009-09-05 21:47:34 +00003595
3596 MagickStatusType
3597 status;
3598
cristyebbcfea2011-02-25 02:43:54 +00003599 register ssize_t
3600 i;
3601
3602 ssize_t
3603 j,
3604 k;
3605
cristy3ed852e2009-09-05 21:47:34 +00003606 /*
3607 Set defaults.
3608 */
3609 assert(image_info != (ImageInfo *) NULL);
3610 assert(image_info->signature == MagickSignature);
3611 if (image_info->debug != MagickFalse)
3612 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3613 assert(exception != (ExceptionInfo *) NULL);
3614 if (argc == 2)
3615 {
3616 option=argv[1];
3617 if ((LocaleCompare("version",option+1) == 0) ||
3618 (LocaleCompare("-version",option+1) == 0))
3619 {
cristyb51dff52011-05-19 16:55:47 +00003620 (void) FormatLocaleFile(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +00003621 GetMagickVersion((size_t *) NULL));
cristy1e604812011-05-19 18:07:50 +00003622 (void) FormatLocaleFile(stdout,"Copyright: %s\n",
3623 GetMagickCopyright());
3624 (void) FormatLocaleFile(stdout,"Features: %s\n\n",
3625 GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00003626 return(MagickFalse);
3627 }
3628 }
3629 if (argc < 2)
cristy13e61a12010-02-04 20:19:00 +00003630 return(MogrifyUsage());
cristy3ed852e2009-09-05 21:47:34 +00003631 format=(char *) NULL;
3632 path=(char *) NULL;
3633 global_colormap=MagickFalse;
3634 k=0;
3635 j=1;
3636 NewImageStack();
3637 option=(char *) NULL;
3638 pend=MagickFalse;
cristyebbcfea2011-02-25 02:43:54 +00003639 respect_parenthesis=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00003640 status=MagickTrue;
3641 /*
3642 Parse command line.
3643 */
3644 ReadCommandlLine(argc,&argv);
3645 status=ExpandFilenames(&argc,&argv);
3646 if (status == MagickFalse)
3647 ThrowMogrifyException(ResourceLimitError,"MemoryAllocationFailed",
3648 GetExceptionMessage(errno));
cristybb503372010-05-27 20:51:26 +00003649 for (i=1; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00003650 {
3651 option=argv[i];
3652 if (LocaleCompare(option,"(") == 0)
3653 {
3654 FireImageStack(MagickFalse,MagickTrue,pend);
3655 if (k == MaxImageStackDepth)
3656 ThrowMogrifyException(OptionError,"ParenthesisNestedTooDeeply",
3657 option);
3658 PushImageStack();
3659 continue;
3660 }
3661 if (LocaleCompare(option,")") == 0)
3662 {
3663 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
3664 if (k == 0)
3665 ThrowMogrifyException(OptionError,"UnableToParseExpression",option);
3666 PopImageStack();
3667 continue;
3668 }
cristy042ee782011-04-22 18:48:30 +00003669 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00003670 {
3671 char
3672 backup_filename[MaxTextExtent],
3673 *filename;
3674
3675 Image
3676 *images;
3677
3678 /*
3679 Option is a file name: begin by reading image from specified file.
3680 */
3681 FireImageStack(MagickFalse,MagickFalse,pend);
3682 filename=argv[i];
cristycee97112010-05-28 00:44:52 +00003683 if ((LocaleCompare(filename,"--") == 0) && (i < (ssize_t) (argc-1)))
cristy3ed852e2009-09-05 21:47:34 +00003684 filename=argv[++i];
3685 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
3686 images=ReadImages(image_info,exception);
3687 status&=(images != (Image *) NULL) &&
3688 (exception->severity < ErrorException);
3689 if (images == (Image *) NULL)
3690 continue;
cristydaa76602010-06-30 13:05:11 +00003691 if (format != (char *) NULL)
3692 (void) CopyMagickString(images->filename,images->magick_filename,
3693 MaxTextExtent);
cristy3ed852e2009-09-05 21:47:34 +00003694 if (path != (char *) NULL)
3695 {
3696 GetPathComponent(option,TailPath,filename);
cristyb51dff52011-05-19 16:55:47 +00003697 (void) FormatLocaleString(images->filename,MaxTextExtent,"%s%c%s",
cristy3ed852e2009-09-05 21:47:34 +00003698 path,*DirectorySeparator,filename);
3699 }
3700 if (format != (char *) NULL)
cristydaa76602010-06-30 13:05:11 +00003701 AppendImageFormat(format,images->filename);
cristy3ed852e2009-09-05 21:47:34 +00003702 AppendImageStack(images);
3703 FinalizeImageSettings(image_info,image,MagickFalse);
3704 if (global_colormap != MagickFalse)
3705 {
3706 QuantizeInfo
3707 *quantize_info;
3708
3709 quantize_info=AcquireQuantizeInfo(image_info);
3710 (void) RemapImages(quantize_info,images,(Image *) NULL);
3711 quantize_info=DestroyQuantizeInfo(quantize_info);
3712 }
3713 *backup_filename='\0';
3714 if ((LocaleCompare(image->filename,"-") != 0) &&
3715 (IsPathWritable(image->filename) != MagickFalse))
3716 {
cristybb503372010-05-27 20:51:26 +00003717 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003718 i;
3719
3720 /*
3721 Rename image file as backup.
3722 */
3723 (void) CopyMagickString(backup_filename,image->filename,
3724 MaxTextExtent);
3725 for (i=0; i < 6; i++)
3726 {
3727 (void) ConcatenateMagickString(backup_filename,"~",MaxTextExtent);
3728 if (IsPathAccessible(backup_filename) == MagickFalse)
3729 break;
3730 }
3731 if ((IsPathAccessible(backup_filename) != MagickFalse) ||
3732 (rename(image->filename,backup_filename) != 0))
3733 *backup_filename='\0';
3734 }
3735 /*
3736 Write transmogrified image to disk.
3737 */
3738 image_info->synchronize=MagickTrue;
3739 status&=WriteImages(image_info,image,image->filename,exception);
3740 if ((status == MagickFalse) && (*backup_filename != '\0'))
3741 (void) remove(backup_filename);
3742 RemoveAllImageStack();
3743 continue;
3744 }
3745 pend=image != (Image *) NULL ? MagickTrue : MagickFalse;
3746 switch (*(option+1))
3747 {
3748 case 'a':
3749 {
3750 if (LocaleCompare("adaptive-blur",option+1) == 0)
3751 {
3752 i++;
cristybb503372010-05-27 20:51:26 +00003753 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003754 ThrowMogrifyException(OptionError,"MissingArgument",option);
3755 if (IsGeometry(argv[i]) == MagickFalse)
3756 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3757 break;
3758 }
3759 if (LocaleCompare("adaptive-resize",option+1) == 0)
3760 {
3761 i++;
cristybb503372010-05-27 20:51:26 +00003762 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003763 ThrowMogrifyException(OptionError,"MissingArgument",option);
3764 if (IsGeometry(argv[i]) == MagickFalse)
3765 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3766 break;
3767 }
3768 if (LocaleCompare("adaptive-sharpen",option+1) == 0)
3769 {
3770 i++;
cristybb503372010-05-27 20:51:26 +00003771 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003772 ThrowMogrifyException(OptionError,"MissingArgument",option);
3773 if (IsGeometry(argv[i]) == MagickFalse)
3774 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3775 break;
3776 }
3777 if (LocaleCompare("affine",option+1) == 0)
3778 {
3779 if (*option == '+')
3780 break;
3781 i++;
cristybb503372010-05-27 20:51:26 +00003782 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003783 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy3ed852e2009-09-05 21:47:34 +00003784 break;
3785 }
3786 if (LocaleCompare("alpha",option+1) == 0)
3787 {
cristybb503372010-05-27 20:51:26 +00003788 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003789 type;
3790
3791 if (*option == '+')
3792 break;
3793 i++;
cristybb503372010-05-27 20:51:26 +00003794 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003795 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00003796 type=ParseCommandOption(MagickAlphaOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00003797 if (type < 0)
3798 ThrowMogrifyException(OptionError,"UnrecognizedAlphaChannelType",
3799 argv[i]);
3800 break;
3801 }
3802 if (LocaleCompare("annotate",option+1) == 0)
3803 {
3804 if (*option == '+')
3805 break;
3806 i++;
cristybb503372010-05-27 20:51:26 +00003807 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003808 ThrowMogrifyException(OptionError,"MissingArgument",option);
3809 if (IsGeometry(argv[i]) == MagickFalse)
3810 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristybb503372010-05-27 20:51:26 +00003811 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003812 ThrowMogrifyException(OptionError,"MissingArgument",option);
3813 i++;
3814 break;
3815 }
3816 if (LocaleCompare("antialias",option+1) == 0)
3817 break;
3818 if (LocaleCompare("append",option+1) == 0)
3819 break;
3820 if (LocaleCompare("attenuate",option+1) == 0)
3821 {
3822 if (*option == '+')
3823 break;
3824 i++;
cristybb503372010-05-27 20:51:26 +00003825 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003826 ThrowMogrifyException(OptionError,"MissingArgument",option);
3827 if (IsGeometry(argv[i]) == MagickFalse)
3828 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3829 break;
3830 }
3831 if (LocaleCompare("authenticate",option+1) == 0)
3832 {
3833 if (*option == '+')
3834 break;
3835 i++;
cristybb503372010-05-27 20:51:26 +00003836 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003837 ThrowMogrifyException(OptionError,"MissingArgument",option);
3838 break;
3839 }
3840 if (LocaleCompare("auto-gamma",option+1) == 0)
3841 break;
3842 if (LocaleCompare("auto-level",option+1) == 0)
3843 break;
3844 if (LocaleCompare("auto-orient",option+1) == 0)
3845 break;
3846 if (LocaleCompare("average",option+1) == 0)
3847 break;
3848 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
3849 }
3850 case 'b':
3851 {
3852 if (LocaleCompare("background",option+1) == 0)
3853 {
3854 if (*option == '+')
3855 break;
3856 i++;
cristybb503372010-05-27 20:51:26 +00003857 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003858 ThrowMogrifyException(OptionError,"MissingArgument",option);
3859 break;
3860 }
3861 if (LocaleCompare("bias",option+1) == 0)
3862 {
3863 if (*option == '+')
3864 break;
3865 i++;
cristybb503372010-05-27 20:51:26 +00003866 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003867 ThrowMogrifyException(OptionError,"MissingArgument",option);
3868 if (IsGeometry(argv[i]) == MagickFalse)
3869 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3870 break;
3871 }
3872 if (LocaleCompare("black-point-compensation",option+1) == 0)
3873 break;
3874 if (LocaleCompare("black-threshold",option+1) == 0)
3875 {
3876 if (*option == '+')
3877 break;
3878 i++;
cristybb503372010-05-27 20:51:26 +00003879 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003880 ThrowMogrifyException(OptionError,"MissingArgument",option);
3881 if (IsGeometry(argv[i]) == MagickFalse)
3882 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3883 break;
3884 }
3885 if (LocaleCompare("blue-primary",option+1) == 0)
3886 {
3887 if (*option == '+')
3888 break;
3889 i++;
cristybb503372010-05-27 20:51:26 +00003890 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003891 ThrowMogrifyException(OptionError,"MissingArgument",option);
3892 if (IsGeometry(argv[i]) == MagickFalse)
3893 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3894 break;
3895 }
3896 if (LocaleCompare("blue-shift",option+1) == 0)
3897 {
3898 i++;
cristybb503372010-05-27 20:51:26 +00003899 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003900 ThrowMogrifyException(OptionError,"MissingArgument",option);
3901 if (IsGeometry(argv[i]) == MagickFalse)
3902 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3903 break;
3904 }
3905 if (LocaleCompare("blur",option+1) == 0)
3906 {
3907 i++;
cristybb503372010-05-27 20:51:26 +00003908 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003909 ThrowMogrifyException(OptionError,"MissingArgument",option);
3910 if (IsGeometry(argv[i]) == MagickFalse)
3911 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3912 break;
3913 }
3914 if (LocaleCompare("border",option+1) == 0)
3915 {
3916 if (*option == '+')
3917 break;
3918 i++;
cristybb503372010-05-27 20:51:26 +00003919 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003920 ThrowMogrifyException(OptionError,"MissingArgument",option);
3921 if (IsGeometry(argv[i]) == MagickFalse)
3922 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3923 break;
3924 }
3925 if (LocaleCompare("bordercolor",option+1) == 0)
3926 {
3927 if (*option == '+')
3928 break;
3929 i++;
cristybb503372010-05-27 20:51:26 +00003930 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003931 ThrowMogrifyException(OptionError,"MissingArgument",option);
3932 break;
3933 }
3934 if (LocaleCompare("box",option+1) == 0)
3935 {
3936 if (*option == '+')
3937 break;
3938 i++;
cristybb503372010-05-27 20:51:26 +00003939 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003940 ThrowMogrifyException(OptionError,"MissingArgument",option);
3941 break;
3942 }
cristya28d6b82010-01-11 20:03:47 +00003943 if (LocaleCompare("brightness-contrast",option+1) == 0)
3944 {
3945 i++;
cristybb503372010-05-27 20:51:26 +00003946 if (i == (ssize_t) argc)
cristya28d6b82010-01-11 20:03:47 +00003947 ThrowMogrifyException(OptionError,"MissingArgument",option);
3948 if (IsGeometry(argv[i]) == MagickFalse)
3949 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3950 break;
3951 }
cristy3ed852e2009-09-05 21:47:34 +00003952 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
3953 }
3954 case 'c':
3955 {
3956 if (LocaleCompare("cache",option+1) == 0)
3957 {
3958 if (*option == '+')
3959 break;
3960 i++;
cristybb503372010-05-27 20:51:26 +00003961 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003962 ThrowMogrifyException(OptionError,"MissingArgument",option);
3963 if (IsGeometry(argv[i]) == MagickFalse)
3964 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3965 break;
3966 }
3967 if (LocaleCompare("caption",option+1) == 0)
3968 {
3969 if (*option == '+')
3970 break;
3971 i++;
cristybb503372010-05-27 20:51:26 +00003972 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003973 ThrowMogrifyException(OptionError,"MissingArgument",option);
3974 break;
3975 }
3976 if (LocaleCompare("channel",option+1) == 0)
3977 {
cristybb503372010-05-27 20:51:26 +00003978 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003979 channel;
3980
3981 if (*option == '+')
3982 break;
3983 i++;
cristybb503372010-05-27 20:51:26 +00003984 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003985 ThrowMogrifyException(OptionError,"MissingArgument",option);
3986 channel=ParseChannelOption(argv[i]);
3987 if (channel < 0)
3988 ThrowMogrifyException(OptionError,"UnrecognizedChannelType",
3989 argv[i]);
3990 break;
3991 }
3992 if (LocaleCompare("cdl",option+1) == 0)
3993 {
3994 if (*option == '+')
3995 break;
3996 i++;
cristybb503372010-05-27 20:51:26 +00003997 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003998 ThrowMogrifyException(OptionError,"MissingArgument",option);
3999 break;
4000 }
4001 if (LocaleCompare("charcoal",option+1) == 0)
4002 {
4003 if (*option == '+')
4004 break;
4005 i++;
cristybb503372010-05-27 20:51:26 +00004006 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004007 ThrowMogrifyException(OptionError,"MissingArgument",option);
4008 if (IsGeometry(argv[i]) == MagickFalse)
4009 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4010 break;
4011 }
4012 if (LocaleCompare("chop",option+1) == 0)
4013 {
4014 if (*option == '+')
4015 break;
4016 i++;
cristybb503372010-05-27 20:51:26 +00004017 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004018 ThrowMogrifyException(OptionError,"MissingArgument",option);
4019 if (IsGeometry(argv[i]) == MagickFalse)
4020 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4021 break;
4022 }
cristy1eb45dd2009-09-25 16:38:06 +00004023 if (LocaleCompare("clamp",option+1) == 0)
4024 break;
4025 if (LocaleCompare("clip",option+1) == 0)
4026 break;
cristy3ed852e2009-09-05 21:47:34 +00004027 if (LocaleCompare("clip-mask",option+1) == 0)
4028 {
4029 if (*option == '+')
4030 break;
4031 i++;
cristybb503372010-05-27 20:51:26 +00004032 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004033 ThrowMogrifyException(OptionError,"MissingArgument",option);
4034 break;
4035 }
4036 if (LocaleCompare("clut",option+1) == 0)
4037 break;
4038 if (LocaleCompare("coalesce",option+1) == 0)
4039 break;
4040 if (LocaleCompare("colorize",option+1) == 0)
4041 {
4042 if (*option == '+')
4043 break;
4044 i++;
cristybb503372010-05-27 20:51:26 +00004045 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004046 ThrowMogrifyException(OptionError,"MissingArgument",option);
4047 if (IsGeometry(argv[i]) == MagickFalse)
4048 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4049 break;
4050 }
cristye6365592010-04-02 17:31:23 +00004051 if (LocaleCompare("color-matrix",option+1) == 0)
4052 {
cristyb6bd4ad2010-08-08 01:12:27 +00004053 KernelInfo
4054 *kernel_info;
4055
cristye6365592010-04-02 17:31:23 +00004056 if (*option == '+')
4057 break;
4058 i++;
cristybb503372010-05-27 20:51:26 +00004059 if (i == (ssize_t) (argc-1))
cristye6365592010-04-02 17:31:23 +00004060 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00004061 kernel_info=AcquireKernelInfo(argv[i]);
4062 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00004063 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00004064 kernel_info=DestroyKernelInfo(kernel_info);
cristye6365592010-04-02 17:31:23 +00004065 break;
4066 }
cristy3ed852e2009-09-05 21:47:34 +00004067 if (LocaleCompare("colors",option+1) == 0)
4068 {
4069 if (*option == '+')
4070 break;
4071 i++;
cristybb503372010-05-27 20:51:26 +00004072 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004073 ThrowMogrifyException(OptionError,"MissingArgument",option);
4074 if (IsGeometry(argv[i]) == MagickFalse)
4075 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4076 break;
4077 }
4078 if (LocaleCompare("colorspace",option+1) == 0)
4079 {
cristybb503372010-05-27 20:51:26 +00004080 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004081 colorspace;
4082
4083 if (*option == '+')
4084 break;
4085 i++;
cristybb503372010-05-27 20:51:26 +00004086 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004087 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004088 colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004089 argv[i]);
4090 if (colorspace < 0)
4091 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
4092 argv[i]);
4093 break;
4094 }
4095 if (LocaleCompare("combine",option+1) == 0)
4096 break;
4097 if (LocaleCompare("comment",option+1) == 0)
4098 {
4099 if (*option == '+')
4100 break;
4101 i++;
cristybb503372010-05-27 20:51:26 +00004102 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004103 ThrowMogrifyException(OptionError,"MissingArgument",option);
4104 break;
4105 }
4106 if (LocaleCompare("composite",option+1) == 0)
4107 break;
4108 if (LocaleCompare("compress",option+1) == 0)
4109 {
cristybb503372010-05-27 20:51:26 +00004110 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004111 compress;
4112
4113 if (*option == '+')
4114 break;
4115 i++;
cristybb503372010-05-27 20:51:26 +00004116 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004117 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004118 compress=ParseCommandOption(MagickCompressOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004119 argv[i]);
4120 if (compress < 0)
4121 ThrowMogrifyException(OptionError,"UnrecognizedImageCompression",
4122 argv[i]);
4123 break;
4124 }
cristy22879752009-10-25 23:55:40 +00004125 if (LocaleCompare("concurrent",option+1) == 0)
4126 break;
cristy3ed852e2009-09-05 21:47:34 +00004127 if (LocaleCompare("contrast",option+1) == 0)
4128 break;
4129 if (LocaleCompare("contrast-stretch",option+1) == 0)
4130 {
4131 i++;
cristybb503372010-05-27 20:51:26 +00004132 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004133 ThrowMogrifyException(OptionError,"MissingArgument",option);
4134 if (IsGeometry(argv[i]) == MagickFalse)
4135 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4136 break;
4137 }
4138 if (LocaleCompare("convolve",option+1) == 0)
4139 {
cristyb6bd4ad2010-08-08 01:12:27 +00004140 KernelInfo
4141 *kernel_info;
4142
cristy3ed852e2009-09-05 21:47:34 +00004143 if (*option == '+')
4144 break;
4145 i++;
cristybb503372010-05-27 20:51:26 +00004146 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004147 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00004148 kernel_info=AcquireKernelInfo(argv[i]);
4149 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00004150 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00004151 kernel_info=DestroyKernelInfo(kernel_info);
cristy3ed852e2009-09-05 21:47:34 +00004152 break;
4153 }
4154 if (LocaleCompare("crop",option+1) == 0)
4155 {
4156 if (*option == '+')
4157 break;
4158 i++;
cristybb503372010-05-27 20:51:26 +00004159 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004160 ThrowMogrifyException(OptionError,"MissingArgument",option);
4161 if (IsGeometry(argv[i]) == MagickFalse)
4162 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4163 break;
4164 }
4165 if (LocaleCompare("cycle",option+1) == 0)
4166 {
4167 if (*option == '+')
4168 break;
4169 i++;
cristybb503372010-05-27 20:51:26 +00004170 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004171 ThrowMogrifyException(OptionError,"MissingArgument",option);
4172 if (IsGeometry(argv[i]) == MagickFalse)
4173 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4174 break;
4175 }
4176 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4177 }
4178 case 'd':
4179 {
4180 if (LocaleCompare("decipher",option+1) == 0)
4181 {
4182 if (*option == '+')
4183 break;
4184 i++;
cristybb503372010-05-27 20:51:26 +00004185 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004186 ThrowMogrifyException(OptionError,"MissingArgument",option);
4187 break;
4188 }
4189 if (LocaleCompare("deconstruct",option+1) == 0)
4190 break;
4191 if (LocaleCompare("debug",option+1) == 0)
4192 {
cristybb503372010-05-27 20:51:26 +00004193 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004194 event;
4195
4196 if (*option == '+')
4197 break;
4198 i++;
cristybb503372010-05-27 20:51:26 +00004199 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004200 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004201 event=ParseCommandOption(MagickLogEventOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004202 if (event < 0)
4203 ThrowMogrifyException(OptionError,"UnrecognizedEventType",
4204 argv[i]);
4205 (void) SetLogEventMask(argv[i]);
4206 break;
4207 }
4208 if (LocaleCompare("define",option+1) == 0)
4209 {
4210 i++;
cristybb503372010-05-27 20:51:26 +00004211 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004212 ThrowMogrifyException(OptionError,"MissingArgument",option);
4213 if (*option == '+')
4214 {
4215 const char
4216 *define;
4217
4218 define=GetImageOption(image_info,argv[i]);
4219 if (define == (const char *) NULL)
4220 ThrowMogrifyException(OptionError,"NoSuchOption",argv[i]);
4221 break;
4222 }
4223 break;
4224 }
4225 if (LocaleCompare("delay",option+1) == 0)
4226 {
4227 if (*option == '+')
4228 break;
4229 i++;
cristybb503372010-05-27 20:51:26 +00004230 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004231 ThrowMogrifyException(OptionError,"MissingArgument",option);
4232 if (IsGeometry(argv[i]) == MagickFalse)
4233 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4234 break;
4235 }
cristyecb10ff2011-03-22 13:14:03 +00004236 if (LocaleCompare("delete",option+1) == 0)
4237 {
4238 if (*option == '+')
4239 break;
4240 i++;
4241 if (i == (ssize_t) (argc-1))
4242 ThrowMogrifyException(OptionError,"MissingArgument",option);
4243 if (IsGeometry(argv[i]) == MagickFalse)
4244 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4245 break;
4246 }
cristy3ed852e2009-09-05 21:47:34 +00004247 if (LocaleCompare("density",option+1) == 0)
4248 {
4249 if (*option == '+')
4250 break;
4251 i++;
cristybb503372010-05-27 20:51:26 +00004252 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004253 ThrowMogrifyException(OptionError,"MissingArgument",option);
4254 if (IsGeometry(argv[i]) == MagickFalse)
4255 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4256 break;
4257 }
4258 if (LocaleCompare("depth",option+1) == 0)
4259 {
4260 if (*option == '+')
4261 break;
4262 i++;
cristybb503372010-05-27 20:51:26 +00004263 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004264 ThrowMogrifyException(OptionError,"MissingArgument",option);
4265 if (IsGeometry(argv[i]) == MagickFalse)
4266 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4267 break;
4268 }
4269 if (LocaleCompare("deskew",option+1) == 0)
4270 {
4271 if (*option == '+')
4272 break;
4273 i++;
cristybb503372010-05-27 20:51:26 +00004274 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004275 ThrowMogrifyException(OptionError,"MissingArgument",option);
4276 if (IsGeometry(argv[i]) == MagickFalse)
4277 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4278 break;
4279 }
4280 if (LocaleCompare("despeckle",option+1) == 0)
4281 break;
4282 if (LocaleCompare("dft",option+1) == 0)
4283 break;
cristyc9b12952010-03-28 01:12:28 +00004284 if (LocaleCompare("direction",option+1) == 0)
4285 {
cristybb503372010-05-27 20:51:26 +00004286 ssize_t
cristyc9b12952010-03-28 01:12:28 +00004287 direction;
4288
4289 if (*option == '+')
4290 break;
4291 i++;
cristybb503372010-05-27 20:51:26 +00004292 if (i == (ssize_t) argc)
cristyc9b12952010-03-28 01:12:28 +00004293 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004294 direction=ParseCommandOption(MagickDirectionOptions,MagickFalse,
cristyc9b12952010-03-28 01:12:28 +00004295 argv[i]);
4296 if (direction < 0)
4297 ThrowMogrifyException(OptionError,"UnrecognizedDirectionType",
4298 argv[i]);
4299 break;
4300 }
cristy3ed852e2009-09-05 21:47:34 +00004301 if (LocaleCompare("display",option+1) == 0)
4302 {
4303 if (*option == '+')
4304 break;
4305 i++;
cristybb503372010-05-27 20:51:26 +00004306 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004307 ThrowMogrifyException(OptionError,"MissingArgument",option);
4308 break;
4309 }
4310 if (LocaleCompare("dispose",option+1) == 0)
4311 {
cristybb503372010-05-27 20:51:26 +00004312 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004313 dispose;
4314
4315 if (*option == '+')
4316 break;
4317 i++;
cristybb503372010-05-27 20:51:26 +00004318 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004319 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004320 dispose=ParseCommandOption(MagickDisposeOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004321 if (dispose < 0)
4322 ThrowMogrifyException(OptionError,"UnrecognizedDisposeMethod",
4323 argv[i]);
4324 break;
4325 }
4326 if (LocaleCompare("distort",option+1) == 0)
4327 {
cristybb503372010-05-27 20:51:26 +00004328 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004329 op;
4330
4331 i++;
cristybb503372010-05-27 20:51:26 +00004332 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004333 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004334 op=ParseCommandOption(MagickDistortOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004335 if (op < 0)
4336 ThrowMogrifyException(OptionError,"UnrecognizedDistortMethod",
4337 argv[i]);
4338 i++;
cristybb503372010-05-27 20:51:26 +00004339 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004340 ThrowMogrifyException(OptionError,"MissingArgument",option);
4341 break;
4342 }
4343 if (LocaleCompare("dither",option+1) == 0)
4344 {
cristybb503372010-05-27 20:51:26 +00004345 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004346 method;
4347
4348 if (*option == '+')
4349 break;
4350 i++;
cristybb503372010-05-27 20:51:26 +00004351 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004352 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004353 method=ParseCommandOption(MagickDitherOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004354 if (method < 0)
4355 ThrowMogrifyException(OptionError,"UnrecognizedDitherMethod",
4356 argv[i]);
4357 break;
4358 }
4359 if (LocaleCompare("draw",option+1) == 0)
4360 {
4361 if (*option == '+')
4362 break;
4363 i++;
cristybb503372010-05-27 20:51:26 +00004364 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004365 ThrowMogrifyException(OptionError,"MissingArgument",option);
4366 break;
4367 }
cristyecb10ff2011-03-22 13:14:03 +00004368 if (LocaleCompare("duplicate",option+1) == 0)
4369 {
4370 if (*option == '+')
4371 break;
4372 i++;
4373 if (i == (ssize_t) (argc-1))
4374 ThrowMogrifyException(OptionError,"MissingArgument",option);
4375 if (IsGeometry(argv[i]) == MagickFalse)
4376 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4377 break;
4378 }
cristy22879752009-10-25 23:55:40 +00004379 if (LocaleCompare("duration",option+1) == 0)
4380 {
4381 if (*option == '+')
4382 break;
4383 i++;
cristybb503372010-05-27 20:51:26 +00004384 if (i == (ssize_t) (argc-1))
cristy22879752009-10-25 23:55:40 +00004385 ThrowMogrifyException(OptionError,"MissingArgument",option);
4386 if (IsGeometry(argv[i]) == MagickFalse)
4387 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4388 break;
4389 }
cristy3ed852e2009-09-05 21:47:34 +00004390 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4391 }
4392 case 'e':
4393 {
4394 if (LocaleCompare("edge",option+1) == 0)
4395 {
4396 if (*option == '+')
4397 break;
4398 i++;
cristybb503372010-05-27 20:51:26 +00004399 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004400 ThrowMogrifyException(OptionError,"MissingArgument",option);
4401 if (IsGeometry(argv[i]) == MagickFalse)
4402 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4403 break;
4404 }
4405 if (LocaleCompare("emboss",option+1) == 0)
4406 {
4407 if (*option == '+')
4408 break;
4409 i++;
cristybb503372010-05-27 20:51:26 +00004410 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004411 ThrowMogrifyException(OptionError,"MissingArgument",option);
4412 if (IsGeometry(argv[i]) == MagickFalse)
4413 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4414 break;
4415 }
4416 if (LocaleCompare("encipher",option+1) == 0)
4417 {
4418 if (*option == '+')
4419 break;
4420 i++;
cristybb503372010-05-27 20:51:26 +00004421 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004422 ThrowMogrifyException(OptionError,"MissingArgument",option);
4423 break;
4424 }
4425 if (LocaleCompare("encoding",option+1) == 0)
4426 {
4427 if (*option == '+')
4428 break;
4429 i++;
cristybb503372010-05-27 20:51:26 +00004430 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004431 ThrowMogrifyException(OptionError,"MissingArgument",option);
4432 break;
4433 }
4434 if (LocaleCompare("endian",option+1) == 0)
4435 {
cristybb503372010-05-27 20:51:26 +00004436 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004437 endian;
4438
4439 if (*option == '+')
4440 break;
4441 i++;
cristybb503372010-05-27 20:51:26 +00004442 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004443 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004444 endian=ParseCommandOption(MagickEndianOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004445 if (endian < 0)
4446 ThrowMogrifyException(OptionError,"UnrecognizedEndianType",
4447 argv[i]);
4448 break;
4449 }
4450 if (LocaleCompare("enhance",option+1) == 0)
4451 break;
4452 if (LocaleCompare("equalize",option+1) == 0)
4453 break;
4454 if (LocaleCompare("evaluate",option+1) == 0)
4455 {
cristybb503372010-05-27 20:51:26 +00004456 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004457 op;
4458
4459 if (*option == '+')
4460 break;
4461 i++;
cristybb503372010-05-27 20:51:26 +00004462 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004463 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004464 op=ParseCommandOption(MagickEvaluateOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004465 if (op < 0)
4466 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4467 argv[i]);
4468 i++;
cristybb503372010-05-27 20:51:26 +00004469 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004470 ThrowMogrifyException(OptionError,"MissingArgument",option);
4471 if (IsGeometry(argv[i]) == MagickFalse)
4472 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4473 break;
4474 }
cristyd18ae7c2010-03-07 17:39:52 +00004475 if (LocaleCompare("evaluate-sequence",option+1) == 0)
4476 {
cristybb503372010-05-27 20:51:26 +00004477 ssize_t
cristyd18ae7c2010-03-07 17:39:52 +00004478 op;
4479
4480 if (*option == '+')
4481 break;
4482 i++;
cristybb503372010-05-27 20:51:26 +00004483 if (i == (ssize_t) argc)
cristyd18ae7c2010-03-07 17:39:52 +00004484 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004485 op=ParseCommandOption(MagickEvaluateOptions,MagickFalse,argv[i]);
cristyd18ae7c2010-03-07 17:39:52 +00004486 if (op < 0)
4487 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4488 argv[i]);
4489 break;
4490 }
cristy3ed852e2009-09-05 21:47:34 +00004491 if (LocaleCompare("extent",option+1) == 0)
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 if (IsGeometry(argv[i]) == MagickFalse)
4499 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4500 break;
4501 }
4502 if (LocaleCompare("extract",option+1) == 0)
4503 {
4504 if (*option == '+')
4505 break;
4506 i++;
cristybb503372010-05-27 20:51:26 +00004507 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004508 ThrowMogrifyException(OptionError,"MissingArgument",option);
4509 if (IsGeometry(argv[i]) == MagickFalse)
4510 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4511 break;
4512 }
4513 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4514 }
4515 case 'f':
4516 {
4517 if (LocaleCompare("family",option+1) == 0)
4518 {
4519 if (*option == '+')
4520 break;
4521 i++;
cristybb503372010-05-27 20:51:26 +00004522 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004523 ThrowMogrifyException(OptionError,"MissingArgument",option);
4524 break;
4525 }
4526 if (LocaleCompare("fill",option+1) == 0)
4527 {
4528 if (*option == '+')
4529 break;
4530 i++;
cristybb503372010-05-27 20:51:26 +00004531 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004532 ThrowMogrifyException(OptionError,"MissingArgument",option);
4533 break;
4534 }
4535 if (LocaleCompare("filter",option+1) == 0)
4536 {
cristybb503372010-05-27 20:51:26 +00004537 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004538 filter;
4539
4540 if (*option == '+')
4541 break;
4542 i++;
cristybb503372010-05-27 20:51:26 +00004543 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004544 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004545 filter=ParseCommandOption(MagickFilterOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004546 if (filter < 0)
4547 ThrowMogrifyException(OptionError,"UnrecognizedImageFilter",
4548 argv[i]);
4549 break;
4550 }
4551 if (LocaleCompare("flatten",option+1) == 0)
4552 break;
4553 if (LocaleCompare("flip",option+1) == 0)
4554 break;
4555 if (LocaleCompare("flop",option+1) == 0)
4556 break;
4557 if (LocaleCompare("floodfill",option+1) == 0)
4558 {
4559 if (*option == '+')
4560 break;
4561 i++;
cristybb503372010-05-27 20:51:26 +00004562 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004563 ThrowMogrifyException(OptionError,"MissingArgument",option);
4564 if (IsGeometry(argv[i]) == MagickFalse)
4565 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4566 i++;
cristybb503372010-05-27 20:51:26 +00004567 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004568 ThrowMogrifyException(OptionError,"MissingArgument",option);
4569 break;
4570 }
4571 if (LocaleCompare("font",option+1) == 0)
4572 {
4573 if (*option == '+')
4574 break;
4575 i++;
cristybb503372010-05-27 20:51:26 +00004576 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004577 ThrowMogrifyException(OptionError,"MissingArgument",option);
4578 break;
4579 }
4580 if (LocaleCompare("format",option+1) == 0)
4581 {
4582 (void) CopyMagickString(argv[i]+1,"sans",MaxTextExtent);
4583 (void) CloneString(&format,(char *) NULL);
4584 if (*option == '+')
4585 break;
4586 i++;
cristybb503372010-05-27 20:51:26 +00004587 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004588 ThrowMogrifyException(OptionError,"MissingArgument",option);
4589 (void) CloneString(&format,argv[i]);
4590 (void) CopyMagickString(image_info->filename,format,MaxTextExtent);
4591 (void) ConcatenateMagickString(image_info->filename,":",
4592 MaxTextExtent);
cristyd965a422010-03-03 17:47:35 +00004593 (void) SetImageInfo(image_info,0,exception);
cristy3ed852e2009-09-05 21:47:34 +00004594 if (*image_info->magick == '\0')
4595 ThrowMogrifyException(OptionError,"UnrecognizedImageFormat",
4596 format);
4597 break;
4598 }
4599 if (LocaleCompare("frame",option+1) == 0)
4600 {
4601 if (*option == '+')
4602 break;
4603 i++;
cristybb503372010-05-27 20:51:26 +00004604 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004605 ThrowMogrifyException(OptionError,"MissingArgument",option);
4606 if (IsGeometry(argv[i]) == MagickFalse)
4607 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4608 break;
4609 }
4610 if (LocaleCompare("function",option+1) == 0)
4611 {
cristybb503372010-05-27 20:51:26 +00004612 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004613 op;
4614
4615 if (*option == '+')
4616 break;
4617 i++;
cristybb503372010-05-27 20:51:26 +00004618 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004619 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004620 op=ParseCommandOption(MagickFunctionOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004621 if (op < 0)
4622 ThrowMogrifyException(OptionError,"UnrecognizedFunction",argv[i]);
4623 i++;
cristybb503372010-05-27 20:51:26 +00004624 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004625 ThrowMogrifyException(OptionError,"MissingArgument",option);
4626 break;
4627 }
4628 if (LocaleCompare("fuzz",option+1) == 0)
4629 {
4630 if (*option == '+')
4631 break;
4632 i++;
cristybb503372010-05-27 20:51:26 +00004633 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004634 ThrowMogrifyException(OptionError,"MissingArgument",option);
4635 if (IsGeometry(argv[i]) == MagickFalse)
4636 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4637 break;
4638 }
4639 if (LocaleCompare("fx",option+1) == 0)
4640 {
4641 if (*option == '+')
4642 break;
4643 i++;
cristybb503372010-05-27 20:51:26 +00004644 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004645 ThrowMogrifyException(OptionError,"MissingArgument",option);
4646 break;
4647 }
4648 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4649 }
4650 case 'g':
4651 {
4652 if (LocaleCompare("gamma",option+1) == 0)
4653 {
4654 i++;
cristybb503372010-05-27 20:51:26 +00004655 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004656 ThrowMogrifyException(OptionError,"MissingArgument",option);
4657 if (IsGeometry(argv[i]) == MagickFalse)
4658 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4659 break;
4660 }
4661 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
4662 (LocaleCompare("gaussian",option+1) == 0))
4663 {
4664 i++;
cristybb503372010-05-27 20:51:26 +00004665 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004666 ThrowMogrifyException(OptionError,"MissingArgument",option);
4667 if (IsGeometry(argv[i]) == MagickFalse)
4668 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4669 break;
4670 }
4671 if (LocaleCompare("geometry",option+1) == 0)
4672 {
4673 if (*option == '+')
4674 break;
4675 i++;
cristybb503372010-05-27 20:51:26 +00004676 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004677 ThrowMogrifyException(OptionError,"MissingArgument",option);
4678 if (IsGeometry(argv[i]) == MagickFalse)
4679 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4680 break;
4681 }
4682 if (LocaleCompare("gravity",option+1) == 0)
4683 {
cristybb503372010-05-27 20:51:26 +00004684 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004685 gravity;
4686
4687 if (*option == '+')
4688 break;
4689 i++;
cristybb503372010-05-27 20:51:26 +00004690 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004691 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004692 gravity=ParseCommandOption(MagickGravityOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004693 if (gravity < 0)
4694 ThrowMogrifyException(OptionError,"UnrecognizedGravityType",
4695 argv[i]);
4696 break;
4697 }
4698 if (LocaleCompare("green-primary",option+1) == 0)
4699 {
4700 if (*option == '+')
4701 break;
4702 i++;
cristybb503372010-05-27 20:51:26 +00004703 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004704 ThrowMogrifyException(OptionError,"MissingArgument",option);
4705 if (IsGeometry(argv[i]) == MagickFalse)
4706 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4707 break;
4708 }
4709 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4710 }
4711 case 'h':
4712 {
4713 if (LocaleCompare("hald-clut",option+1) == 0)
4714 break;
4715 if ((LocaleCompare("help",option+1) == 0) ||
4716 (LocaleCompare("-help",option+1) == 0))
4717 return(MogrifyUsage());
4718 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4719 }
4720 case 'i':
4721 {
4722 if (LocaleCompare("identify",option+1) == 0)
4723 break;
4724 if (LocaleCompare("idft",option+1) == 0)
4725 break;
4726 if (LocaleCompare("implode",option+1) == 0)
4727 {
4728 if (*option == '+')
4729 break;
4730 i++;
cristybb503372010-05-27 20:51:26 +00004731 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004732 ThrowMogrifyException(OptionError,"MissingArgument",option);
4733 if (IsGeometry(argv[i]) == MagickFalse)
4734 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4735 break;
4736 }
4737 if (LocaleCompare("intent",option+1) == 0)
4738 {
cristybb503372010-05-27 20:51:26 +00004739 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004740 intent;
4741
4742 if (*option == '+')
4743 break;
4744 i++;
cristybb503372010-05-27 20:51:26 +00004745 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004746 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004747 intent=ParseCommandOption(MagickIntentOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004748 if (intent < 0)
4749 ThrowMogrifyException(OptionError,"UnrecognizedIntentType",
4750 argv[i]);
4751 break;
4752 }
4753 if (LocaleCompare("interlace",option+1) == 0)
4754 {
cristybb503372010-05-27 20:51:26 +00004755 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004756 interlace;
4757
4758 if (*option == '+')
4759 break;
4760 i++;
cristybb503372010-05-27 20:51:26 +00004761 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004762 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004763 interlace=ParseCommandOption(MagickInterlaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004764 argv[i]);
4765 if (interlace < 0)
4766 ThrowMogrifyException(OptionError,"UnrecognizedInterlaceType",
4767 argv[i]);
4768 break;
4769 }
cristyb32b90a2009-09-07 21:45:48 +00004770 if (LocaleCompare("interline-spacing",option+1) == 0)
4771 {
4772 if (*option == '+')
4773 break;
4774 i++;
cristybb503372010-05-27 20:51:26 +00004775 if (i == (ssize_t) (argc-1))
cristyb32b90a2009-09-07 21:45:48 +00004776 ThrowMogrifyException(OptionError,"MissingArgument",option);
4777 if (IsGeometry(argv[i]) == MagickFalse)
4778 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4779 break;
4780 }
cristy3ed852e2009-09-05 21:47:34 +00004781 if (LocaleCompare("interpolate",option+1) == 0)
4782 {
cristybb503372010-05-27 20:51:26 +00004783 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004784 interpolate;
4785
4786 if (*option == '+')
4787 break;
4788 i++;
cristybb503372010-05-27 20:51:26 +00004789 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004790 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004791 interpolate=ParseCommandOption(MagickInterpolateOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004792 argv[i]);
4793 if (interpolate < 0)
4794 ThrowMogrifyException(OptionError,"UnrecognizedInterpolateMethod",
4795 argv[i]);
4796 break;
4797 }
4798 if (LocaleCompare("interword-spacing",option+1) == 0)
4799 {
4800 if (*option == '+')
4801 break;
4802 i++;
cristybb503372010-05-27 20:51:26 +00004803 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004804 ThrowMogrifyException(OptionError,"MissingArgument",option);
4805 if (IsGeometry(argv[i]) == MagickFalse)
4806 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4807 break;
4808 }
4809 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4810 }
4811 case 'k':
4812 {
4813 if (LocaleCompare("kerning",option+1) == 0)
4814 {
4815 if (*option == '+')
4816 break;
4817 i++;
cristybb503372010-05-27 20:51:26 +00004818 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004819 ThrowMogrifyException(OptionError,"MissingArgument",option);
4820 if (IsGeometry(argv[i]) == MagickFalse)
4821 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4822 break;
4823 }
4824 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4825 }
4826 case 'l':
4827 {
4828 if (LocaleCompare("label",option+1) == 0)
4829 {
4830 if (*option == '+')
4831 break;
4832 i++;
cristybb503372010-05-27 20:51:26 +00004833 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004834 ThrowMogrifyException(OptionError,"MissingArgument",option);
4835 break;
4836 }
4837 if (LocaleCompare("lat",option+1) == 0)
4838 {
4839 if (*option == '+')
4840 break;
4841 i++;
cristybb503372010-05-27 20:51:26 +00004842 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004843 ThrowMogrifyException(OptionError,"MissingArgument",option);
4844 if (IsGeometry(argv[i]) == MagickFalse)
4845 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4846 }
4847 if (LocaleCompare("layers",option+1) == 0)
4848 {
cristybb503372010-05-27 20:51:26 +00004849 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004850 type;
4851
4852 if (*option == '+')
4853 break;
4854 i++;
cristybb503372010-05-27 20:51:26 +00004855 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004856 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004857 type=ParseCommandOption(MagickLayerOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004858 if (type < 0)
4859 ThrowMogrifyException(OptionError,"UnrecognizedLayerMethod",
4860 argv[i]);
4861 break;
4862 }
4863 if (LocaleCompare("level",option+1) == 0)
4864 {
4865 i++;
cristybb503372010-05-27 20:51:26 +00004866 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004867 ThrowMogrifyException(OptionError,"MissingArgument",option);
4868 if (IsGeometry(argv[i]) == MagickFalse)
4869 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4870 break;
4871 }
4872 if (LocaleCompare("level-colors",option+1) == 0)
4873 {
4874 i++;
cristybb503372010-05-27 20:51:26 +00004875 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004876 ThrowMogrifyException(OptionError,"MissingArgument",option);
4877 break;
4878 }
4879 if (LocaleCompare("linewidth",option+1) == 0)
4880 {
4881 if (*option == '+')
4882 break;
4883 i++;
cristybb503372010-05-27 20:51:26 +00004884 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004885 ThrowMogrifyException(OptionError,"MissingArgument",option);
4886 if (IsGeometry(argv[i]) == MagickFalse)
4887 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4888 break;
4889 }
4890 if (LocaleCompare("limit",option+1) == 0)
4891 {
4892 char
4893 *p;
4894
4895 double
4896 value;
4897
cristybb503372010-05-27 20:51:26 +00004898 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004899 resource;
4900
4901 if (*option == '+')
4902 break;
4903 i++;
cristybb503372010-05-27 20:51:26 +00004904 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004905 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004906 resource=ParseCommandOption(MagickResourceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004907 argv[i]);
4908 if (resource < 0)
4909 ThrowMogrifyException(OptionError,"UnrecognizedResourceType",
4910 argv[i]);
4911 i++;
cristybb503372010-05-27 20:51:26 +00004912 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004913 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyc1acd842011-05-19 23:05:47 +00004914 value=InterpretLocaleValue(argv[i],&p);
cristyda16f162011-02-19 23:52:17 +00004915 (void) value;
cristy3ed852e2009-09-05 21:47:34 +00004916 if ((p == argv[i]) && (LocaleCompare("unlimited",argv[i]) != 0))
4917 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4918 break;
4919 }
4920 if (LocaleCompare("liquid-rescale",option+1) == 0)
4921 {
4922 i++;
cristybb503372010-05-27 20:51:26 +00004923 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004924 ThrowMogrifyException(OptionError,"MissingArgument",option);
4925 if (IsGeometry(argv[i]) == MagickFalse)
4926 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4927 break;
4928 }
4929 if (LocaleCompare("list",option+1) == 0)
4930 {
cristybb503372010-05-27 20:51:26 +00004931 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004932 list;
4933
4934 if (*option == '+')
4935 break;
4936 i++;
cristybb503372010-05-27 20:51:26 +00004937 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004938 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004939 list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004940 if (list < 0)
4941 ThrowMogrifyException(OptionError,"UnrecognizedListType",argv[i]);
cristyaeb2cbc2010-05-07 13:28:58 +00004942 status=MogrifyImageInfo(image_info,(int) (i-j+1),(const char **)
cristy3ed852e2009-09-05 21:47:34 +00004943 argv+j,exception);
cristyaeb2cbc2010-05-07 13:28:58 +00004944 return(status != 0 ? MagickFalse : MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00004945 }
4946 if (LocaleCompare("log",option+1) == 0)
4947 {
4948 if (*option == '+')
4949 break;
4950 i++;
cristybb503372010-05-27 20:51:26 +00004951 if ((i == (ssize_t) argc) ||
cristy3ed852e2009-09-05 21:47:34 +00004952 (strchr(argv[i],'%') == (char *) NULL))
4953 ThrowMogrifyException(OptionError,"MissingArgument",option);
4954 break;
4955 }
4956 if (LocaleCompare("loop",option+1) == 0)
4957 {
4958 if (*option == '+')
4959 break;
4960 i++;
cristybb503372010-05-27 20:51:26 +00004961 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004962 ThrowMogrifyException(OptionError,"MissingArgument",option);
4963 if (IsGeometry(argv[i]) == MagickFalse)
4964 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4965 break;
4966 }
4967 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4968 }
4969 case 'm':
4970 {
4971 if (LocaleCompare("map",option+1) == 0)
4972 {
4973 global_colormap=(*option == '+') ? MagickTrue : MagickFalse;
4974 if (*option == '+')
4975 break;
4976 i++;
cristybb503372010-05-27 20:51:26 +00004977 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004978 ThrowMogrifyException(OptionError,"MissingArgument",option);
4979 break;
4980 }
4981 if (LocaleCompare("mask",option+1) == 0)
4982 {
4983 if (*option == '+')
4984 break;
4985 i++;
cristybb503372010-05-27 20:51:26 +00004986 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004987 ThrowMogrifyException(OptionError,"MissingArgument",option);
4988 break;
4989 }
4990 if (LocaleCompare("matte",option+1) == 0)
4991 break;
4992 if (LocaleCompare("mattecolor",option+1) == 0)
4993 {
4994 if (*option == '+')
4995 break;
4996 i++;
cristybb503372010-05-27 20:51:26 +00004997 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004998 ThrowMogrifyException(OptionError,"MissingArgument",option);
4999 break;
5000 }
cristyf40785b2010-03-06 02:27:27 +00005001 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00005002 break;
cristyf40785b2010-03-06 02:27:27 +00005003 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00005004 break;
cristy3ed852e2009-09-05 21:47:34 +00005005 if (LocaleCompare("modulate",option+1) == 0)
5006 {
5007 if (*option == '+')
5008 break;
5009 i++;
cristybb503372010-05-27 20:51:26 +00005010 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005011 ThrowMogrifyException(OptionError,"MissingArgument",option);
5012 if (IsGeometry(argv[i]) == MagickFalse)
5013 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5014 break;
5015 }
5016 if (LocaleCompare("median",option+1) == 0)
5017 {
5018 if (*option == '+')
5019 break;
5020 i++;
cristybb503372010-05-27 20:51:26 +00005021 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005022 ThrowMogrifyException(OptionError,"MissingArgument",option);
5023 if (IsGeometry(argv[i]) == MagickFalse)
5024 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5025 break;
5026 }
cristy69ec32d2011-02-27 23:57:09 +00005027 if (LocaleCompare("mode",option+1) == 0)
5028 {
5029 if (*option == '+')
5030 break;
5031 i++;
5032 if (i == (ssize_t) argc)
5033 ThrowMogrifyException(OptionError,"MissingArgument",option);
5034 if (IsGeometry(argv[i]) == MagickFalse)
5035 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5036 break;
5037 }
cristy3ed852e2009-09-05 21:47:34 +00005038 if (LocaleCompare("monitor",option+1) == 0)
5039 break;
5040 if (LocaleCompare("monochrome",option+1) == 0)
5041 break;
5042 if (LocaleCompare("morph",option+1) == 0)
5043 {
5044 if (*option == '+')
5045 break;
5046 i++;
cristybb503372010-05-27 20:51:26 +00005047 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005048 ThrowMogrifyException(OptionError,"MissingArgument",option);
5049 if (IsGeometry(argv[i]) == MagickFalse)
5050 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5051 break;
5052 }
anthony29188a82010-01-22 10:12:34 +00005053 if (LocaleCompare("morphology",option+1) == 0)
5054 {
anthony29188a82010-01-22 10:12:34 +00005055 char
5056 token[MaxTextExtent];
5057
cristyb6bd4ad2010-08-08 01:12:27 +00005058 KernelInfo
5059 *kernel_info;
5060
5061 ssize_t
5062 op;
5063
anthony29188a82010-01-22 10:12:34 +00005064 i++;
cristybb503372010-05-27 20:51:26 +00005065 if (i == (ssize_t) argc)
anthony29188a82010-01-22 10:12:34 +00005066 ThrowMogrifyException(OptionError,"MissingArgument",option);
5067 GetMagickToken(argv[i],NULL,token);
cristy042ee782011-04-22 18:48:30 +00005068 op=ParseCommandOption(MagickMorphologyOptions,MagickFalse,token);
anthony29188a82010-01-22 10:12:34 +00005069 if (op < 0)
5070 ThrowMogrifyException(OptionError,"UnrecognizedMorphologyMethod",
cristyf0c78232010-03-15 12:53:40 +00005071 token);
anthony29188a82010-01-22 10:12:34 +00005072 i++;
cristybb503372010-05-27 20:51:26 +00005073 if (i == (ssize_t) (argc-1))
anthony29188a82010-01-22 10:12:34 +00005074 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00005075 kernel_info=AcquireKernelInfo(argv[i]);
5076 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00005077 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00005078 kernel_info=DestroyKernelInfo(kernel_info);
anthony29188a82010-01-22 10:12:34 +00005079 break;
5080 }
cristy3ed852e2009-09-05 21:47:34 +00005081 if (LocaleCompare("mosaic",option+1) == 0)
5082 break;
5083 if (LocaleCompare("motion-blur",option+1) == 0)
5084 {
5085 if (*option == '+')
5086 break;
5087 i++;
cristybb503372010-05-27 20:51:26 +00005088 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005089 ThrowMogrifyException(OptionError,"MissingArgument",option);
5090 if (IsGeometry(argv[i]) == MagickFalse)
5091 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5092 break;
5093 }
5094 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5095 }
5096 case 'n':
5097 {
5098 if (LocaleCompare("negate",option+1) == 0)
5099 break;
5100 if (LocaleCompare("noise",option+1) == 0)
5101 {
5102 i++;
cristybb503372010-05-27 20:51:26 +00005103 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005104 ThrowMogrifyException(OptionError,"MissingArgument",option);
5105 if (*option == '+')
5106 {
cristybb503372010-05-27 20:51:26 +00005107 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005108 noise;
5109
cristy042ee782011-04-22 18:48:30 +00005110 noise=ParseCommandOption(MagickNoiseOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005111 if (noise < 0)
5112 ThrowMogrifyException(OptionError,"UnrecognizedNoiseType",
5113 argv[i]);
5114 break;
5115 }
5116 if (IsGeometry(argv[i]) == MagickFalse)
5117 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5118 break;
5119 }
5120 if (LocaleCompare("noop",option+1) == 0)
5121 break;
5122 if (LocaleCompare("normalize",option+1) == 0)
5123 break;
5124 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5125 }
5126 case 'o':
5127 {
5128 if (LocaleCompare("opaque",option+1) == 0)
5129 {
cristy3ed852e2009-09-05 21:47:34 +00005130 i++;
cristybb503372010-05-27 20:51:26 +00005131 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005132 ThrowMogrifyException(OptionError,"MissingArgument",option);
5133 break;
5134 }
5135 if (LocaleCompare("ordered-dither",option+1) == 0)
5136 {
5137 if (*option == '+')
5138 break;
5139 i++;
cristybb503372010-05-27 20:51:26 +00005140 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005141 ThrowMogrifyException(OptionError,"MissingArgument",option);
5142 break;
5143 }
5144 if (LocaleCompare("orient",option+1) == 0)
5145 {
cristybb503372010-05-27 20:51:26 +00005146 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005147 orientation;
5148
5149 orientation=UndefinedOrientation;
5150 if (*option == '+')
5151 break;
5152 i++;
cristybb503372010-05-27 20:51:26 +00005153 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005154 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005155 orientation=ParseCommandOption(MagickOrientationOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005156 argv[i]);
5157 if (orientation < 0)
5158 ThrowMogrifyException(OptionError,"UnrecognizedImageOrientation",
5159 argv[i]);
5160 break;
5161 }
5162 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5163 }
5164 case 'p':
5165 {
5166 if (LocaleCompare("page",option+1) == 0)
5167 {
5168 if (*option == '+')
5169 break;
5170 i++;
cristybb503372010-05-27 20:51:26 +00005171 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005172 ThrowMogrifyException(OptionError,"MissingArgument",option);
5173 break;
5174 }
5175 if (LocaleCompare("paint",option+1) == 0)
5176 {
5177 if (*option == '+')
5178 break;
5179 i++;
cristybb503372010-05-27 20:51:26 +00005180 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005181 ThrowMogrifyException(OptionError,"MissingArgument",option);
5182 if (IsGeometry(argv[i]) == MagickFalse)
5183 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5184 break;
5185 }
5186 if (LocaleCompare("path",option+1) == 0)
5187 {
5188 (void) CloneString(&path,(char *) NULL);
5189 if (*option == '+')
5190 break;
5191 i++;
cristybb503372010-05-27 20:51:26 +00005192 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005193 ThrowMogrifyException(OptionError,"MissingArgument",option);
5194 (void) CloneString(&path,argv[i]);
5195 break;
5196 }
5197 if (LocaleCompare("pointsize",option+1) == 0)
5198 {
5199 if (*option == '+')
5200 break;
5201 i++;
cristybb503372010-05-27 20:51:26 +00005202 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005203 ThrowMogrifyException(OptionError,"MissingArgument",option);
5204 if (IsGeometry(argv[i]) == MagickFalse)
5205 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5206 break;
5207 }
5208 if (LocaleCompare("polaroid",option+1) == 0)
5209 {
5210 if (*option == '+')
5211 break;
5212 i++;
cristybb503372010-05-27 20:51:26 +00005213 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005214 ThrowMogrifyException(OptionError,"MissingArgument",option);
5215 if (IsGeometry(argv[i]) == MagickFalse)
5216 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5217 break;
5218 }
5219 if (LocaleCompare("posterize",option+1) == 0)
5220 {
5221 if (*option == '+')
5222 break;
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 }
cristye7f51092010-01-17 00:39:37 +00005230 if (LocaleCompare("precision",option+1) == 0)
5231 {
5232 if (*option == '+')
5233 break;
5234 i++;
cristybb503372010-05-27 20:51:26 +00005235 if (i == (ssize_t) argc)
cristye7f51092010-01-17 00:39:37 +00005236 ThrowMogrifyException(OptionError,"MissingArgument",option);
5237 if (IsGeometry(argv[i]) == MagickFalse)
5238 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5239 break;
5240 }
cristy3ed852e2009-09-05 21:47:34 +00005241 if (LocaleCompare("print",option+1) == 0)
5242 {
5243 if (*option == '+')
5244 break;
5245 i++;
cristybb503372010-05-27 20:51:26 +00005246 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005247 ThrowMogrifyException(OptionError,"MissingArgument",option);
5248 break;
5249 }
5250 if (LocaleCompare("process",option+1) == 0)
5251 {
5252 if (*option == '+')
5253 break;
5254 i++;
cristybb503372010-05-27 20:51:26 +00005255 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005256 ThrowMogrifyException(OptionError,"MissingArgument",option);
5257 break;
5258 }
5259 if (LocaleCompare("profile",option+1) == 0)
5260 {
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 break;
5265 }
5266 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5267 }
5268 case 'q':
5269 {
5270 if (LocaleCompare("quality",option+1) == 0)
5271 {
5272 if (*option == '+')
5273 break;
5274 i++;
cristybb503372010-05-27 20:51:26 +00005275 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005276 ThrowMogrifyException(OptionError,"MissingArgument",option);
5277 if (IsGeometry(argv[i]) == MagickFalse)
5278 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5279 break;
5280 }
5281 if (LocaleCompare("quantize",option+1) == 0)
5282 {
cristybb503372010-05-27 20:51:26 +00005283 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005284 colorspace;
5285
5286 if (*option == '+')
5287 break;
5288 i++;
cristybb503372010-05-27 20:51:26 +00005289 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005290 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005291 colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005292 argv[i]);
5293 if (colorspace < 0)
5294 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
5295 argv[i]);
5296 break;
5297 }
5298 if (LocaleCompare("quiet",option+1) == 0)
5299 break;
5300 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5301 }
5302 case 'r':
5303 {
5304 if (LocaleCompare("radial-blur",option+1) == 0)
5305 {
5306 i++;
cristybb503372010-05-27 20:51:26 +00005307 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005308 ThrowMogrifyException(OptionError,"MissingArgument",option);
5309 if (IsGeometry(argv[i]) == MagickFalse)
5310 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5311 break;
5312 }
5313 if (LocaleCompare("raise",option+1) == 0)
5314 {
5315 i++;
cristybb503372010-05-27 20:51:26 +00005316 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005317 ThrowMogrifyException(OptionError,"MissingArgument",option);
5318 if (IsGeometry(argv[i]) == MagickFalse)
5319 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5320 break;
5321 }
5322 if (LocaleCompare("random-threshold",option+1) == 0)
5323 {
5324 if (*option == '+')
5325 break;
5326 i++;
cristybb503372010-05-27 20:51:26 +00005327 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005328 ThrowMogrifyException(OptionError,"MissingArgument",option);
5329 if (IsGeometry(argv[i]) == MagickFalse)
5330 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5331 break;
5332 }
cristye6365592010-04-02 17:31:23 +00005333 if (LocaleCompare("recolor",option+1) == 0)
5334 {
5335 if (*option == '+')
5336 break;
5337 i++;
cristybb503372010-05-27 20:51:26 +00005338 if (i == (ssize_t) (argc-1))
cristye6365592010-04-02 17:31:23 +00005339 ThrowMogrifyException(OptionError,"MissingArgument",option);
5340 if (IsGeometry(argv[i]) == MagickFalse)
5341 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5342 break;
5343 }
cristy3ed852e2009-09-05 21:47:34 +00005344 if (LocaleCompare("red-primary",option+1) == 0)
5345 {
5346 if (*option == '+')
5347 break;
5348 i++;
cristybb503372010-05-27 20:51:26 +00005349 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005350 ThrowMogrifyException(OptionError,"MissingArgument",option);
5351 if (IsGeometry(argv[i]) == MagickFalse)
5352 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5353 }
cristy9f2083a2010-04-22 19:48:05 +00005354 if (LocaleCompare("regard-warnings",option+1) == 0)
5355 break;
cristy3ed852e2009-09-05 21:47:34 +00005356 if (LocaleCompare("region",option+1) == 0)
5357 {
5358 if (*option == '+')
5359 break;
5360 i++;
cristybb503372010-05-27 20:51:26 +00005361 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005362 ThrowMogrifyException(OptionError,"MissingArgument",option);
5363 if (IsGeometry(argv[i]) == MagickFalse)
5364 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5365 break;
5366 }
cristyf0c78232010-03-15 12:53:40 +00005367 if (LocaleCompare("remap",option+1) == 0)
5368 {
5369 if (*option == '+')
5370 break;
5371 i++;
cristybb503372010-05-27 20:51:26 +00005372 if (i == (ssize_t) (argc-1))
cristyf0c78232010-03-15 12:53:40 +00005373 ThrowMogrifyException(OptionError,"MissingArgument",option);
5374 break;
5375 }
cristy3ed852e2009-09-05 21:47:34 +00005376 if (LocaleCompare("render",option+1) == 0)
5377 break;
5378 if (LocaleCompare("repage",option+1) == 0)
5379 {
5380 if (*option == '+')
5381 break;
5382 i++;
cristybb503372010-05-27 20:51:26 +00005383 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005384 ThrowMogrifyException(OptionError,"MissingArgument",option);
5385 if (IsGeometry(argv[i]) == MagickFalse)
5386 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5387 break;
5388 }
5389 if (LocaleCompare("resample",option+1) == 0)
5390 {
5391 if (*option == '+')
5392 break;
5393 i++;
cristybb503372010-05-27 20:51:26 +00005394 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005395 ThrowMogrifyException(OptionError,"MissingArgument",option);
5396 if (IsGeometry(argv[i]) == MagickFalse)
5397 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5398 break;
5399 }
5400 if (LocaleCompare("resize",option+1) == 0)
5401 {
5402 if (*option == '+')
5403 break;
5404 i++;
cristybb503372010-05-27 20:51:26 +00005405 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005406 ThrowMogrifyException(OptionError,"MissingArgument",option);
5407 if (IsGeometry(argv[i]) == MagickFalse)
5408 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5409 break;
5410 }
cristyebbcfea2011-02-25 02:43:54 +00005411 if (LocaleNCompare("respect-parentheses",option+1,17) == 0)
5412 {
5413 respect_parenthesis=(*option == '-') ? MagickTrue : MagickFalse;
5414 break;
5415 }
cristy3ed852e2009-09-05 21:47:34 +00005416 if (LocaleCompare("reverse",option+1) == 0)
5417 break;
5418 if (LocaleCompare("roll",option+1) == 0)
5419 {
5420 if (*option == '+')
5421 break;
5422 i++;
cristybb503372010-05-27 20:51:26 +00005423 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005424 ThrowMogrifyException(OptionError,"MissingArgument",option);
5425 if (IsGeometry(argv[i]) == MagickFalse)
5426 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5427 break;
5428 }
5429 if (LocaleCompare("rotate",option+1) == 0)
5430 {
5431 i++;
cristybb503372010-05-27 20:51:26 +00005432 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005433 ThrowMogrifyException(OptionError,"MissingArgument",option);
5434 if (IsGeometry(argv[i]) == MagickFalse)
5435 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5436 break;
5437 }
5438 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5439 }
5440 case 's':
5441 {
5442 if (LocaleCompare("sample",option+1) == 0)
5443 {
5444 if (*option == '+')
5445 break;
5446 i++;
cristybb503372010-05-27 20:51:26 +00005447 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005448 ThrowMogrifyException(OptionError,"MissingArgument",option);
5449 if (IsGeometry(argv[i]) == MagickFalse)
5450 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5451 break;
5452 }
5453 if (LocaleCompare("sampling-factor",option+1) == 0)
5454 {
5455 if (*option == '+')
5456 break;
5457 i++;
cristybb503372010-05-27 20:51:26 +00005458 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005459 ThrowMogrifyException(OptionError,"MissingArgument",option);
5460 if (IsGeometry(argv[i]) == MagickFalse)
5461 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5462 break;
5463 }
5464 if (LocaleCompare("scale",option+1) == 0)
5465 {
5466 if (*option == '+')
5467 break;
5468 i++;
cristybb503372010-05-27 20:51:26 +00005469 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005470 ThrowMogrifyException(OptionError,"MissingArgument",option);
5471 if (IsGeometry(argv[i]) == MagickFalse)
5472 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5473 break;
5474 }
5475 if (LocaleCompare("scene",option+1) == 0)
5476 {
5477 if (*option == '+')
5478 break;
5479 i++;
cristybb503372010-05-27 20:51:26 +00005480 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005481 ThrowMogrifyException(OptionError,"MissingArgument",option);
5482 if (IsGeometry(argv[i]) == MagickFalse)
5483 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5484 break;
5485 }
5486 if (LocaleCompare("seed",option+1) == 0)
5487 {
5488 if (*option == '+')
5489 break;
5490 i++;
cristybb503372010-05-27 20:51:26 +00005491 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005492 ThrowMogrifyException(OptionError,"MissingArgument",option);
5493 if (IsGeometry(argv[i]) == MagickFalse)
5494 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5495 break;
5496 }
5497 if (LocaleCompare("segment",option+1) == 0)
5498 {
5499 if (*option == '+')
5500 break;
5501 i++;
cristybb503372010-05-27 20:51:26 +00005502 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005503 ThrowMogrifyException(OptionError,"MissingArgument",option);
5504 if (IsGeometry(argv[i]) == MagickFalse)
5505 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5506 break;
5507 }
5508 if (LocaleCompare("selective-blur",option+1) == 0)
5509 {
5510 i++;
cristybb503372010-05-27 20:51:26 +00005511 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005512 ThrowMogrifyException(OptionError,"MissingArgument",option);
5513 if (IsGeometry(argv[i]) == MagickFalse)
5514 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5515 break;
5516 }
5517 if (LocaleCompare("separate",option+1) == 0)
5518 break;
5519 if (LocaleCompare("sepia-tone",option+1) == 0)
5520 {
5521 if (*option == '+')
5522 break;
5523 i++;
cristybb503372010-05-27 20:51:26 +00005524 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005525 ThrowMogrifyException(OptionError,"MissingArgument",option);
5526 if (IsGeometry(argv[i]) == MagickFalse)
5527 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5528 break;
5529 }
5530 if (LocaleCompare("set",option+1) == 0)
5531 {
5532 i++;
cristybb503372010-05-27 20:51:26 +00005533 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005534 ThrowMogrifyException(OptionError,"MissingArgument",option);
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 break;
5541 }
5542 if (LocaleCompare("shade",option+1) == 0)
5543 {
5544 i++;
cristybb503372010-05-27 20:51:26 +00005545 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005546 ThrowMogrifyException(OptionError,"MissingArgument",option);
5547 if (IsGeometry(argv[i]) == MagickFalse)
5548 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5549 break;
5550 }
5551 if (LocaleCompare("shadow",option+1) == 0)
5552 {
5553 if (*option == '+')
5554 break;
5555 i++;
cristybb503372010-05-27 20:51:26 +00005556 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005557 ThrowMogrifyException(OptionError,"MissingArgument",option);
5558 if (IsGeometry(argv[i]) == MagickFalse)
5559 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5560 break;
5561 }
5562 if (LocaleCompare("sharpen",option+1) == 0)
5563 {
5564 i++;
cristybb503372010-05-27 20:51:26 +00005565 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005566 ThrowMogrifyException(OptionError,"MissingArgument",option);
5567 if (IsGeometry(argv[i]) == MagickFalse)
5568 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5569 break;
5570 }
5571 if (LocaleCompare("shave",option+1) == 0)
5572 {
5573 if (*option == '+')
5574 break;
5575 i++;
cristybb503372010-05-27 20:51:26 +00005576 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005577 ThrowMogrifyException(OptionError,"MissingArgument",option);
5578 if (IsGeometry(argv[i]) == MagickFalse)
5579 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5580 break;
5581 }
5582 if (LocaleCompare("shear",option+1) == 0)
5583 {
5584 i++;
cristybb503372010-05-27 20:51:26 +00005585 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005586 ThrowMogrifyException(OptionError,"MissingArgument",option);
5587 if (IsGeometry(argv[i]) == MagickFalse)
5588 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5589 break;
5590 }
5591 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
5592 {
5593 i++;
cristybb503372010-05-27 20:51:26 +00005594 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005595 ThrowMogrifyException(OptionError,"MissingArgument",option);
5596 if (IsGeometry(argv[i]) == MagickFalse)
5597 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5598 break;
5599 }
5600 if (LocaleCompare("size",option+1) == 0)
5601 {
5602 if (*option == '+')
5603 break;
5604 i++;
cristybb503372010-05-27 20:51:26 +00005605 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005606 ThrowMogrifyException(OptionError,"MissingArgument",option);
5607 if (IsGeometry(argv[i]) == MagickFalse)
5608 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5609 break;
5610 }
5611 if (LocaleCompare("sketch",option+1) == 0)
5612 {
5613 if (*option == '+')
5614 break;
5615 i++;
cristybb503372010-05-27 20:51:26 +00005616 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005617 ThrowMogrifyException(OptionError,"MissingArgument",option);
5618 if (IsGeometry(argv[i]) == MagickFalse)
5619 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5620 break;
5621 }
cristy4285d782011-02-09 20:12:28 +00005622 if (LocaleCompare("smush",option+1) == 0)
5623 {
cristy4285d782011-02-09 20:12:28 +00005624 i++;
5625 if (i == (ssize_t) argc)
5626 ThrowMogrifyException(OptionError,"MissingArgument",option);
5627 if (IsGeometry(argv[i]) == MagickFalse)
5628 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristy4285d782011-02-09 20:12:28 +00005629 i++;
5630 break;
5631 }
cristy3ed852e2009-09-05 21:47:34 +00005632 if (LocaleCompare("solarize",option+1) == 0)
5633 {
5634 if (*option == '+')
5635 break;
5636 i++;
cristybb503372010-05-27 20:51:26 +00005637 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005638 ThrowMogrifyException(OptionError,"MissingArgument",option);
5639 if (IsGeometry(argv[i]) == MagickFalse)
5640 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5641 break;
5642 }
5643 if (LocaleCompare("sparse-color",option+1) == 0)
5644 {
cristybb503372010-05-27 20:51:26 +00005645 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005646 op;
5647
5648 i++;
cristybb503372010-05-27 20:51:26 +00005649 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005650 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005651 op=ParseCommandOption(MagickSparseColorOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005652 if (op < 0)
5653 ThrowMogrifyException(OptionError,"UnrecognizedSparseColorMethod",
5654 argv[i]);
5655 i++;
cristybb503372010-05-27 20:51:26 +00005656 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005657 ThrowMogrifyException(OptionError,"MissingArgument",option);
5658 break;
5659 }
5660 if (LocaleCompare("spread",option+1) == 0)
5661 {
5662 if (*option == '+')
5663 break;
5664 i++;
cristybb503372010-05-27 20:51:26 +00005665 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005666 ThrowMogrifyException(OptionError,"MissingArgument",option);
5667 if (IsGeometry(argv[i]) == MagickFalse)
5668 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5669 break;
5670 }
cristy0834d642011-03-18 18:26:08 +00005671 if (LocaleCompare("statistic",option+1) == 0)
5672 {
5673 ssize_t
5674 op;
5675
5676 if (*option == '+')
5677 break;
5678 i++;
5679 if (i == (ssize_t) argc)
5680 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005681 op=ParseCommandOption(MagickStatisticOptions,MagickFalse,argv[i]);
cristy0834d642011-03-18 18:26:08 +00005682 if (op < 0)
5683 ThrowMogrifyException(OptionError,"UnrecognizedStatisticType",
5684 argv[i]);
5685 i++;
5686 if (i == (ssize_t) (argc-1))
5687 ThrowMogrifyException(OptionError,"MissingArgument",option);
5688 if (IsGeometry(argv[i]) == MagickFalse)
5689 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5690 break;
5691 }
cristy3ed852e2009-09-05 21:47:34 +00005692 if (LocaleCompare("stretch",option+1) == 0)
5693 {
cristybb503372010-05-27 20:51:26 +00005694 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005695 stretch;
5696
5697 if (*option == '+')
5698 break;
5699 i++;
cristybb503372010-05-27 20:51:26 +00005700 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005701 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005702 stretch=ParseCommandOption(MagickStretchOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005703 if (stretch < 0)
5704 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
5705 argv[i]);
5706 break;
5707 }
5708 if (LocaleCompare("strip",option+1) == 0)
5709 break;
5710 if (LocaleCompare("stroke",option+1) == 0)
5711 {
5712 if (*option == '+')
5713 break;
5714 i++;
cristybb503372010-05-27 20:51:26 +00005715 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005716 ThrowMogrifyException(OptionError,"MissingArgument",option);
5717 break;
5718 }
5719 if (LocaleCompare("strokewidth",option+1) == 0)
5720 {
5721 if (*option == '+')
5722 break;
5723 i++;
cristybb503372010-05-27 20:51:26 +00005724 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005725 ThrowMogrifyException(OptionError,"MissingArgument",option);
5726 if (IsGeometry(argv[i]) == MagickFalse)
5727 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5728 break;
5729 }
5730 if (LocaleCompare("style",option+1) == 0)
5731 {
cristybb503372010-05-27 20:51:26 +00005732 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005733 style;
5734
5735 if (*option == '+')
5736 break;
5737 i++;
cristybb503372010-05-27 20:51:26 +00005738 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005739 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005740 style=ParseCommandOption(MagickStyleOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005741 if (style < 0)
5742 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
5743 argv[i]);
5744 break;
5745 }
cristyecb10ff2011-03-22 13:14:03 +00005746 if (LocaleCompare("swap",option+1) == 0)
5747 {
5748 if (*option == '+')
5749 break;
5750 i++;
5751 if (i == (ssize_t) (argc-1))
5752 ThrowMogrifyException(OptionError,"MissingArgument",option);
5753 if (IsGeometry(argv[i]) == MagickFalse)
5754 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5755 break;
5756 }
cristy3ed852e2009-09-05 21:47:34 +00005757 if (LocaleCompare("swirl",option+1) == 0)
5758 {
5759 if (*option == '+')
5760 break;
5761 i++;
cristybb503372010-05-27 20:51:26 +00005762 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005763 ThrowMogrifyException(OptionError,"MissingArgument",option);
5764 if (IsGeometry(argv[i]) == MagickFalse)
5765 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5766 break;
5767 }
cristyd9a29192010-10-16 16:49:53 +00005768 if (LocaleCompare("synchronize",option+1) == 0)
5769 break;
cristy3ed852e2009-09-05 21:47:34 +00005770 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5771 }
5772 case 't':
5773 {
5774 if (LocaleCompare("taint",option+1) == 0)
5775 break;
5776 if (LocaleCompare("texture",option+1) == 0)
5777 {
5778 if (*option == '+')
5779 break;
5780 i++;
cristybb503372010-05-27 20:51:26 +00005781 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005782 ThrowMogrifyException(OptionError,"MissingArgument",option);
5783 break;
5784 }
5785 if (LocaleCompare("tile",option+1) == 0)
5786 {
5787 if (*option == '+')
5788 break;
5789 i++;
cristybb503372010-05-27 20:51:26 +00005790 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005791 ThrowMogrifyException(OptionError,"MissingArgument",option);
5792 break;
5793 }
5794 if (LocaleCompare("tile-offset",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("tint",option+1) == 0)
5806 {
5807 if (*option == '+')
5808 break;
5809 i++;
cristybb503372010-05-27 20:51:26 +00005810 if (i == (ssize_t) (argc-1))
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("transform",option+1) == 0)
5817 break;
5818 if (LocaleCompare("transpose",option+1) == 0)
5819 break;
5820 if (LocaleCompare("transverse",option+1) == 0)
5821 break;
5822 if (LocaleCompare("threshold",option+1) == 0)
5823 {
5824 if (*option == '+')
5825 break;
5826 i++;
cristybb503372010-05-27 20:51:26 +00005827 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005828 ThrowMogrifyException(OptionError,"MissingArgument",option);
5829 if (IsGeometry(argv[i]) == MagickFalse)
5830 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5831 break;
5832 }
5833 if (LocaleCompare("thumbnail",option+1) == 0)
5834 {
5835 if (*option == '+')
5836 break;
5837 i++;
cristybb503372010-05-27 20:51:26 +00005838 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005839 ThrowMogrifyException(OptionError,"MissingArgument",option);
5840 if (IsGeometry(argv[i]) == MagickFalse)
5841 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5842 break;
5843 }
5844 if (LocaleCompare("transparent",option+1) == 0)
5845 {
5846 i++;
cristybb503372010-05-27 20:51:26 +00005847 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005848 ThrowMogrifyException(OptionError,"MissingArgument",option);
5849 break;
5850 }
5851 if (LocaleCompare("transparent-color",option+1) == 0)
5852 {
5853 if (*option == '+')
5854 break;
5855 i++;
cristybb503372010-05-27 20:51:26 +00005856 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005857 ThrowMogrifyException(OptionError,"MissingArgument",option);
5858 break;
5859 }
5860 if (LocaleCompare("treedepth",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("trim",option+1) == 0)
5872 break;
5873 if (LocaleCompare("type",option+1) == 0)
5874 {
cristybb503372010-05-27 20:51:26 +00005875 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005876 type;
5877
5878 if (*option == '+')
5879 break;
5880 i++;
cristybb503372010-05-27 20:51:26 +00005881 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005882 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005883 type=ParseCommandOption(MagickTypeOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005884 if (type < 0)
5885 ThrowMogrifyException(OptionError,"UnrecognizedImageType",
5886 argv[i]);
5887 break;
5888 }
5889 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5890 }
5891 case 'u':
5892 {
5893 if (LocaleCompare("undercolor",option+1) == 0)
5894 {
5895 if (*option == '+')
5896 break;
5897 i++;
cristybb503372010-05-27 20:51:26 +00005898 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005899 ThrowMogrifyException(OptionError,"MissingArgument",option);
5900 break;
5901 }
5902 if (LocaleCompare("unique-colors",option+1) == 0)
5903 break;
5904 if (LocaleCompare("units",option+1) == 0)
5905 {
cristybb503372010-05-27 20:51:26 +00005906 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005907 units;
5908
5909 if (*option == '+')
5910 break;
5911 i++;
cristybb503372010-05-27 20:51:26 +00005912 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005913 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005914 units=ParseCommandOption(MagickResolutionOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005915 argv[i]);
5916 if (units < 0)
5917 ThrowMogrifyException(OptionError,"UnrecognizedUnitsType",
5918 argv[i]);
5919 break;
5920 }
5921 if (LocaleCompare("unsharp",option+1) == 0)
5922 {
5923 i++;
cristybb503372010-05-27 20:51:26 +00005924 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005925 ThrowMogrifyException(OptionError,"MissingArgument",option);
5926 if (IsGeometry(argv[i]) == MagickFalse)
5927 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5928 break;
5929 }
5930 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5931 }
5932 case 'v':
5933 {
5934 if (LocaleCompare("verbose",option+1) == 0)
5935 {
5936 image_info->verbose=(*option == '-') ? MagickTrue : MagickFalse;
5937 break;
5938 }
5939 if ((LocaleCompare("version",option+1) == 0) ||
5940 (LocaleCompare("-version",option+1) == 0))
5941 {
cristyb51dff52011-05-19 16:55:47 +00005942 (void) FormatLocaleFile(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +00005943 GetMagickVersion((size_t *) NULL));
cristy1e604812011-05-19 18:07:50 +00005944 (void) FormatLocaleFile(stdout,"Copyright: %s\n",
5945 GetMagickCopyright());
5946 (void) FormatLocaleFile(stdout,"Features: %s\n\n",
5947 GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00005948 break;
5949 }
5950 if (LocaleCompare("view",option+1) == 0)
5951 {
5952 if (*option == '+')
5953 break;
5954 i++;
cristybb503372010-05-27 20:51:26 +00005955 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005956 ThrowMogrifyException(OptionError,"MissingArgument",option);
5957 break;
5958 }
5959 if (LocaleCompare("vignette",option+1) == 0)
5960 {
5961 if (*option == '+')
5962 break;
5963 i++;
cristybb503372010-05-27 20:51:26 +00005964 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005965 ThrowMogrifyException(OptionError,"MissingArgument",option);
5966 if (IsGeometry(argv[i]) == MagickFalse)
5967 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5968 break;
5969 }
5970 if (LocaleCompare("virtual-pixel",option+1) == 0)
5971 {
cristybb503372010-05-27 20:51:26 +00005972 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005973 method;
5974
5975 if (*option == '+')
5976 break;
5977 i++;
cristybb503372010-05-27 20:51:26 +00005978 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005979 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005980 method=ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005981 argv[i]);
5982 if (method < 0)
5983 ThrowMogrifyException(OptionError,
5984 "UnrecognizedVirtualPixelMethod",argv[i]);
5985 break;
5986 }
5987 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5988 }
5989 case 'w':
5990 {
5991 if (LocaleCompare("wave",option+1) == 0)
5992 {
5993 i++;
cristybb503372010-05-27 20:51:26 +00005994 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005995 ThrowMogrifyException(OptionError,"MissingArgument",option);
5996 if (IsGeometry(argv[i]) == MagickFalse)
5997 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5998 break;
5999 }
6000 if (LocaleCompare("weight",option+1) == 0)
6001 {
6002 if (*option == '+')
6003 break;
6004 i++;
cristybb503372010-05-27 20:51:26 +00006005 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006006 ThrowMogrifyException(OptionError,"MissingArgument",option);
6007 break;
6008 }
6009 if (LocaleCompare("white-point",option+1) == 0)
6010 {
6011 if (*option == '+')
6012 break;
6013 i++;
cristybb503372010-05-27 20:51:26 +00006014 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006015 ThrowMogrifyException(OptionError,"MissingArgument",option);
6016 if (IsGeometry(argv[i]) == MagickFalse)
6017 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6018 break;
6019 }
6020 if (LocaleCompare("white-threshold",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 if (IsGeometry(argv[i]) == MagickFalse)
6028 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6029 break;
6030 }
6031 if (LocaleCompare("write",option+1) == 0)
6032 {
6033 i++;
cristybb503372010-05-27 20:51:26 +00006034 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006035 ThrowMogrifyException(OptionError,"MissingArgument",option);
6036 break;
6037 }
6038 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6039 }
6040 case '?':
6041 break;
6042 default:
6043 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6044 }
cristy042ee782011-04-22 18:48:30 +00006045 fire=(GetCommandOptionFlags(MagickCommandOptions,MagickFalse,option) &
6046 FireOptionFlag) == 0 ? MagickFalse : MagickTrue;
cristy3ed852e2009-09-05 21:47:34 +00006047 if (fire != MagickFalse)
6048 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
6049 }
6050 if (k != 0)
6051 ThrowMogrifyException(OptionError,"UnbalancedParenthesis",argv[i]);
cristycee97112010-05-28 00:44:52 +00006052 if (i != (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006053 ThrowMogrifyException(OptionError,"MissingAnImageFilename",argv[i]);
6054 DestroyMogrify();
6055 return(status != 0 ? MagickTrue : MagickFalse);
6056}
6057
6058/*
6059%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6060% %
6061% %
6062% %
6063+ M o g r i f y I m a g e I n f o %
6064% %
6065% %
6066% %
6067%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6068%
6069% MogrifyImageInfo() applies image processing settings to the image as
6070% prescribed by command line options.
6071%
6072% The format of the MogrifyImageInfo method is:
6073%
6074% MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,const int argc,
6075% const char **argv,ExceptionInfo *exception)
6076%
6077% A description of each parameter follows:
6078%
6079% o image_info: the image info..
6080%
6081% o argc: Specifies a pointer to an integer describing the number of
6082% elements in the argument vector.
6083%
6084% o argv: Specifies a pointer to a text array containing the command line
6085% arguments.
6086%
6087% o exception: return any errors or warnings in this structure.
6088%
6089*/
6090WandExport MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,
6091 const int argc,const char **argv,ExceptionInfo *exception)
6092{
6093 const char
6094 *option;
6095
6096 GeometryInfo
6097 geometry_info;
6098
cristybb503372010-05-27 20:51:26 +00006099 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006100 count;
6101
cristybb503372010-05-27 20:51:26 +00006102 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006103 i;
6104
6105 /*
6106 Initialize method variables.
6107 */
6108 assert(image_info != (ImageInfo *) NULL);
6109 assert(image_info->signature == MagickSignature);
6110 if (image_info->debug != MagickFalse)
6111 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
6112 image_info->filename);
6113 if (argc < 0)
6114 return(MagickTrue);
6115 /*
6116 Set the image settings.
6117 */
cristybb503372010-05-27 20:51:26 +00006118 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00006119 {
6120 option=argv[i];
cristy042ee782011-04-22 18:48:30 +00006121 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00006122 continue;
cristy042ee782011-04-22 18:48:30 +00006123 count=ParseCommandOption(MagickCommandOptions,MagickFalse,option);
anthonyce2716b2011-04-22 09:51:34 +00006124 count=MagickMax(count,0L);
cristycee97112010-05-28 00:44:52 +00006125 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006126 break;
6127 switch (*(option+1))
6128 {
6129 case 'a':
6130 {
6131 if (LocaleCompare("adjoin",option+1) == 0)
6132 {
6133 image_info->adjoin=(*option == '-') ? MagickTrue : MagickFalse;
6134 break;
6135 }
6136 if (LocaleCompare("antialias",option+1) == 0)
6137 {
6138 image_info->antialias=(*option == '-') ? MagickTrue : MagickFalse;
6139 break;
6140 }
6141 if (LocaleCompare("attenuate",option+1) == 0)
6142 {
6143 if (*option == '+')
6144 {
6145 (void) DeleteImageOption(image_info,option+1);
6146 break;
6147 }
6148 (void) SetImageOption(image_info,option+1,argv[i+1]);
6149 break;
6150 }
6151 if (LocaleCompare("authenticate",option+1) == 0)
6152 {
6153 if (*option == '+')
6154 (void) CloneString(&image_info->authenticate,(char *) NULL);
6155 else
6156 (void) CloneString(&image_info->authenticate,argv[i+1]);
6157 break;
6158 }
6159 break;
6160 }
6161 case 'b':
6162 {
6163 if (LocaleCompare("background",option+1) == 0)
6164 {
6165 if (*option == '+')
6166 {
6167 (void) DeleteImageOption(image_info,option+1);
6168 (void) QueryColorDatabase(BackgroundColor,
6169 &image_info->background_color,exception);
6170 break;
6171 }
6172 (void) SetImageOption(image_info,option+1,argv[i+1]);
6173 (void) QueryColorDatabase(argv[i+1],&image_info->background_color,
6174 exception);
6175 break;
6176 }
6177 if (LocaleCompare("bias",option+1) == 0)
6178 {
6179 if (*option == '+')
6180 {
6181 (void) SetImageOption(image_info,option+1,"0.0");
6182 break;
6183 }
6184 (void) SetImageOption(image_info,option+1,argv[i+1]);
6185 break;
6186 }
6187 if (LocaleCompare("black-point-compensation",option+1) == 0)
6188 {
6189 if (*option == '+')
6190 {
6191 (void) SetImageOption(image_info,option+1,"false");
6192 break;
6193 }
6194 (void) SetImageOption(image_info,option+1,"true");
6195 break;
6196 }
6197 if (LocaleCompare("blue-primary",option+1) == 0)
6198 {
6199 if (*option == '+')
6200 {
6201 (void) SetImageOption(image_info,option+1,"0.0");
6202 break;
6203 }
6204 (void) SetImageOption(image_info,option+1,argv[i+1]);
6205 break;
6206 }
6207 if (LocaleCompare("bordercolor",option+1) == 0)
6208 {
6209 if (*option == '+')
6210 {
6211 (void) DeleteImageOption(image_info,option+1);
6212 (void) QueryColorDatabase(BorderColor,&image_info->border_color,
6213 exception);
6214 break;
6215 }
6216 (void) QueryColorDatabase(argv[i+1],&image_info->border_color,
6217 exception);
6218 (void) SetImageOption(image_info,option+1,argv[i+1]);
6219 break;
6220 }
6221 if (LocaleCompare("box",option+1) == 0)
6222 {
6223 if (*option == '+')
6224 {
6225 (void) SetImageOption(image_info,"undercolor","none");
6226 break;
6227 }
6228 (void) SetImageOption(image_info,"undercolor",argv[i+1]);
6229 break;
6230 }
6231 break;
6232 }
6233 case 'c':
6234 {
6235 if (LocaleCompare("cache",option+1) == 0)
6236 {
6237 MagickSizeType
6238 limit;
6239
6240 limit=MagickResourceInfinity;
6241 if (LocaleCompare("unlimited",argv[i+1]) != 0)
cristyf2f27272009-12-17 14:48:46 +00006242 limit=(MagickSizeType) SiPrefixToDouble(argv[i+1],100.0);
cristy3ed852e2009-09-05 21:47:34 +00006243 (void) SetMagickResourceLimit(MemoryResource,limit);
6244 (void) SetMagickResourceLimit(MapResource,2*limit);
6245 break;
6246 }
6247 if (LocaleCompare("caption",option+1) == 0)
6248 {
6249 if (*option == '+')
6250 {
6251 (void) DeleteImageOption(image_info,option+1);
6252 break;
6253 }
6254 (void) SetImageOption(image_info,option+1,argv[i+1]);
6255 break;
6256 }
6257 if (LocaleCompare("channel",option+1) == 0)
6258 {
6259 if (*option == '+')
6260 {
6261 image_info->channel=DefaultChannels;
6262 break;
6263 }
6264 image_info->channel=(ChannelType) ParseChannelOption(argv[i+1]);
6265 break;
6266 }
6267 if (LocaleCompare("colors",option+1) == 0)
6268 {
cristye27293e2009-12-18 02:53:20 +00006269 image_info->colors=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006270 break;
6271 }
6272 if (LocaleCompare("colorspace",option+1) == 0)
6273 {
6274 if (*option == '+')
6275 {
6276 image_info->colorspace=UndefinedColorspace;
6277 (void) SetImageOption(image_info,option+1,"undefined");
6278 break;
6279 }
cristy042ee782011-04-22 18:48:30 +00006280 image_info->colorspace=(ColorspaceType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006281 MagickColorspaceOptions,MagickFalse,argv[i+1]);
6282 (void) SetImageOption(image_info,option+1,argv[i+1]);
6283 break;
6284 }
cristy3ed852e2009-09-05 21:47:34 +00006285 if (LocaleCompare("comment",option+1) == 0)
6286 {
6287 if (*option == '+')
6288 {
6289 (void) DeleteImageOption(image_info,option+1);
6290 break;
6291 }
6292 (void) SetImageOption(image_info,option+1,argv[i+1]);
6293 break;
6294 }
6295 if (LocaleCompare("compose",option+1) == 0)
6296 {
6297 if (*option == '+')
6298 {
6299 (void) SetImageOption(image_info,option+1,"undefined");
6300 break;
6301 }
6302 (void) SetImageOption(image_info,option+1,argv[i+1]);
6303 break;
6304 }
6305 if (LocaleCompare("compress",option+1) == 0)
6306 {
6307 if (*option == '+')
6308 {
6309 image_info->compression=UndefinedCompression;
6310 (void) SetImageOption(image_info,option+1,"undefined");
6311 break;
6312 }
cristy042ee782011-04-22 18:48:30 +00006313 image_info->compression=(CompressionType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006314 MagickCompressOptions,MagickFalse,argv[i+1]);
6315 (void) SetImageOption(image_info,option+1,argv[i+1]);
6316 break;
6317 }
6318 break;
6319 }
6320 case 'd':
6321 {
6322 if (LocaleCompare("debug",option+1) == 0)
6323 {
6324 if (*option == '+')
6325 (void) SetLogEventMask("none");
6326 else
6327 (void) SetLogEventMask(argv[i+1]);
6328 image_info->debug=IsEventLogging();
6329 break;
6330 }
6331 if (LocaleCompare("define",option+1) == 0)
6332 {
6333 if (*option == '+')
6334 {
6335 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6336 (void) DeleteImageRegistry(argv[i+1]+9);
6337 else
6338 (void) DeleteImageOption(image_info,argv[i+1]);
6339 break;
6340 }
6341 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6342 {
6343 (void) DefineImageRegistry(StringRegistryType,argv[i+1]+9,
6344 exception);
6345 break;
6346 }
6347 (void) DefineImageOption(image_info,argv[i+1]);
6348 break;
6349 }
6350 if (LocaleCompare("delay",option+1) == 0)
6351 {
6352 if (*option == '+')
6353 {
6354 (void) SetImageOption(image_info,option+1,"0");
6355 break;
6356 }
6357 (void) SetImageOption(image_info,option+1,argv[i+1]);
6358 break;
6359 }
6360 if (LocaleCompare("density",option+1) == 0)
6361 {
6362 /*
6363 Set image density.
6364 */
6365 if (*option == '+')
6366 {
6367 if (image_info->density != (char *) NULL)
6368 image_info->density=DestroyString(image_info->density);
6369 (void) SetImageOption(image_info,option+1,"72");
6370 break;
6371 }
6372 (void) CloneString(&image_info->density,argv[i+1]);
6373 (void) SetImageOption(image_info,option+1,argv[i+1]);
6374 break;
6375 }
6376 if (LocaleCompare("depth",option+1) == 0)
6377 {
6378 if (*option == '+')
6379 {
6380 image_info->depth=MAGICKCORE_QUANTUM_DEPTH;
6381 break;
6382 }
cristye27293e2009-12-18 02:53:20 +00006383 image_info->depth=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006384 break;
6385 }
cristyc9b12952010-03-28 01:12:28 +00006386 if (LocaleCompare("direction",option+1) == 0)
6387 {
6388 if (*option == '+')
6389 {
6390 (void) SetImageOption(image_info,option+1,"undefined");
6391 break;
6392 }
6393 (void) SetImageOption(image_info,option+1,argv[i+1]);
6394 break;
6395 }
cristy3ed852e2009-09-05 21:47:34 +00006396 if (LocaleCompare("display",option+1) == 0)
6397 {
6398 if (*option == '+')
6399 {
6400 if (image_info->server_name != (char *) NULL)
6401 image_info->server_name=DestroyString(
6402 image_info->server_name);
6403 break;
6404 }
6405 (void) CloneString(&image_info->server_name,argv[i+1]);
6406 break;
6407 }
6408 if (LocaleCompare("dispose",option+1) == 0)
6409 {
6410 if (*option == '+')
6411 {
6412 (void) SetImageOption(image_info,option+1,"undefined");
6413 break;
6414 }
6415 (void) SetImageOption(image_info,option+1,argv[i+1]);
6416 break;
6417 }
6418 if (LocaleCompare("dither",option+1) == 0)
6419 {
6420 if (*option == '+')
6421 {
6422 image_info->dither=MagickFalse;
cristyd5acfd12010-06-15 00:11:38 +00006423 (void) SetImageOption(image_info,option+1,"none");
cristy3ed852e2009-09-05 21:47:34 +00006424 break;
6425 }
6426 (void) SetImageOption(image_info,option+1,argv[i+1]);
6427 image_info->dither=MagickTrue;
6428 break;
6429 }
6430 break;
6431 }
6432 case 'e':
6433 {
6434 if (LocaleCompare("encoding",option+1) == 0)
6435 {
6436 if (*option == '+')
6437 {
6438 (void) SetImageOption(image_info,option+1,"undefined");
6439 break;
6440 }
6441 (void) SetImageOption(image_info,option+1,argv[i+1]);
6442 break;
6443 }
6444 if (LocaleCompare("endian",option+1) == 0)
6445 {
6446 if (*option == '+')
6447 {
6448 image_info->endian=UndefinedEndian;
6449 (void) SetImageOption(image_info,option+1,"undefined");
6450 break;
6451 }
cristy042ee782011-04-22 18:48:30 +00006452 image_info->endian=(EndianType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006453 MagickEndianOptions,MagickFalse,argv[i+1]);
6454 (void) SetImageOption(image_info,option+1,argv[i+1]);
6455 break;
6456 }
6457 if (LocaleCompare("extract",option+1) == 0)
6458 {
6459 /*
6460 Set image extract geometry.
6461 */
6462 if (*option == '+')
6463 {
6464 if (image_info->extract != (char *) NULL)
6465 image_info->extract=DestroyString(image_info->extract);
6466 break;
6467 }
6468 (void) CloneString(&image_info->extract,argv[i+1]);
6469 break;
6470 }
6471 break;
6472 }
6473 case 'f':
6474 {
6475 if (LocaleCompare("fill",option+1) == 0)
6476 {
6477 if (*option == '+')
6478 {
6479 (void) SetImageOption(image_info,option+1,"none");
6480 break;
6481 }
6482 (void) SetImageOption(image_info,option+1,argv[i+1]);
6483 break;
6484 }
6485 if (LocaleCompare("filter",option+1) == 0)
6486 {
6487 if (*option == '+')
6488 {
6489 (void) SetImageOption(image_info,option+1,"undefined");
6490 break;
6491 }
6492 (void) SetImageOption(image_info,option+1,argv[i+1]);
6493 break;
6494 }
6495 if (LocaleCompare("font",option+1) == 0)
6496 {
6497 if (*option == '+')
6498 {
6499 if (image_info->font != (char *) NULL)
6500 image_info->font=DestroyString(image_info->font);
6501 break;
6502 }
6503 (void) CloneString(&image_info->font,argv[i+1]);
6504 break;
6505 }
6506 if (LocaleCompare("format",option+1) == 0)
6507 {
6508 register const char
6509 *q;
6510
6511 for (q=strchr(argv[i+1],'%'); q != (char *) NULL; q=strchr(q+1,'%'))
cristy9ed85672011-03-02 00:19:13 +00006512 if (strchr("Agkrz@[#",*(q+1)) != (char *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00006513 image_info->ping=MagickFalse;
6514 (void) SetImageOption(image_info,option+1,argv[i+1]);
6515 break;
6516 }
6517 if (LocaleCompare("fuzz",option+1) == 0)
6518 {
6519 if (*option == '+')
6520 {
6521 image_info->fuzz=0.0;
6522 (void) SetImageOption(image_info,option+1,"0");
6523 break;
6524 }
cristyf2f27272009-12-17 14:48:46 +00006525 image_info->fuzz=SiPrefixToDouble(argv[i+1],(double) QuantumRange+
cristy3ed852e2009-09-05 21:47:34 +00006526 1.0);
6527 (void) SetImageOption(image_info,option+1,argv[i+1]);
6528 break;
6529 }
6530 break;
6531 }
6532 case 'g':
6533 {
6534 if (LocaleCompare("gravity",option+1) == 0)
6535 {
6536 if (*option == '+')
6537 {
6538 (void) SetImageOption(image_info,option+1,"undefined");
6539 break;
6540 }
6541 (void) SetImageOption(image_info,option+1,argv[i+1]);
6542 break;
6543 }
6544 if (LocaleCompare("green-primary",option+1) == 0)
6545 {
6546 if (*option == '+')
6547 {
6548 (void) SetImageOption(image_info,option+1,"0.0");
6549 break;
6550 }
6551 (void) SetImageOption(image_info,option+1,argv[i+1]);
6552 break;
6553 }
6554 break;
6555 }
6556 case 'i':
6557 {
6558 if (LocaleCompare("intent",option+1) == 0)
6559 {
6560 if (*option == '+')
6561 {
6562 (void) SetImageOption(image_info,option+1,"undefined");
6563 break;
6564 }
6565 (void) SetImageOption(image_info,option+1,argv[i+1]);
6566 break;
6567 }
6568 if (LocaleCompare("interlace",option+1) == 0)
6569 {
6570 if (*option == '+')
6571 {
6572 image_info->interlace=UndefinedInterlace;
6573 (void) SetImageOption(image_info,option+1,"undefined");
6574 break;
6575 }
cristy042ee782011-04-22 18:48:30 +00006576 image_info->interlace=(InterlaceType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006577 MagickInterlaceOptions,MagickFalse,argv[i+1]);
6578 (void) SetImageOption(image_info,option+1,argv[i+1]);
6579 break;
6580 }
cristyb32b90a2009-09-07 21:45:48 +00006581 if (LocaleCompare("interline-spacing",option+1) == 0)
6582 {
6583 if (*option == '+')
6584 {
6585 (void) SetImageOption(image_info,option+1,"undefined");
6586 break;
6587 }
6588 (void) SetImageOption(image_info,option+1,argv[i+1]);
6589 break;
6590 }
cristy3ed852e2009-09-05 21:47:34 +00006591 if (LocaleCompare("interpolate",option+1) == 0)
6592 {
6593 if (*option == '+')
6594 {
6595 (void) SetImageOption(image_info,option+1,"undefined");
6596 break;
6597 }
6598 (void) SetImageOption(image_info,option+1,argv[i+1]);
6599 break;
6600 }
6601 if (LocaleCompare("interword-spacing",option+1) == 0)
6602 {
6603 if (*option == '+')
6604 {
6605 (void) SetImageOption(image_info,option+1,"undefined");
6606 break;
6607 }
6608 (void) SetImageOption(image_info,option+1,argv[i+1]);
6609 break;
6610 }
6611 break;
6612 }
6613 case 'k':
6614 {
6615 if (LocaleCompare("kerning",option+1) == 0)
6616 {
6617 if (*option == '+')
6618 {
6619 (void) SetImageOption(image_info,option+1,"undefined");
6620 break;
6621 }
6622 (void) SetImageOption(image_info,option+1,argv[i+1]);
6623 break;
6624 }
6625 break;
6626 }
6627 case 'l':
6628 {
6629 if (LocaleCompare("label",option+1) == 0)
6630 {
6631 if (*option == '+')
6632 {
6633 (void) DeleteImageOption(image_info,option+1);
6634 break;
6635 }
6636 (void) SetImageOption(image_info,option+1,argv[i+1]);
6637 break;
6638 }
6639 if (LocaleCompare("limit",option+1) == 0)
6640 {
6641 MagickSizeType
6642 limit;
6643
6644 ResourceType
6645 type;
6646
6647 if (*option == '+')
6648 break;
cristy042ee782011-04-22 18:48:30 +00006649 type=(ResourceType) ParseCommandOption(MagickResourceOptions,
cristy3ed852e2009-09-05 21:47:34 +00006650 MagickFalse,argv[i+1]);
6651 limit=MagickResourceInfinity;
6652 if (LocaleCompare("unlimited",argv[i+2]) != 0)
cristyf2f27272009-12-17 14:48:46 +00006653 limit=(MagickSizeType) SiPrefixToDouble(argv[i+2],100.0);
cristy3ed852e2009-09-05 21:47:34 +00006654 (void) SetMagickResourceLimit(type,limit);
6655 break;
6656 }
6657 if (LocaleCompare("list",option+1) == 0)
6658 {
cristybb503372010-05-27 20:51:26 +00006659 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006660 list;
6661
6662 /*
6663 Display configuration list.
6664 */
cristy042ee782011-04-22 18:48:30 +00006665 list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006666 switch (list)
6667 {
6668 case MagickCoderOptions:
6669 {
6670 (void) ListCoderInfo((FILE *) NULL,exception);
6671 break;
6672 }
6673 case MagickColorOptions:
6674 {
6675 (void) ListColorInfo((FILE *) NULL,exception);
6676 break;
6677 }
6678 case MagickConfigureOptions:
6679 {
6680 (void) ListConfigureInfo((FILE *) NULL,exception);
6681 break;
6682 }
6683 case MagickDelegateOptions:
6684 {
6685 (void) ListDelegateInfo((FILE *) NULL,exception);
6686 break;
6687 }
6688 case MagickFontOptions:
6689 {
6690 (void) ListTypeInfo((FILE *) NULL,exception);
6691 break;
6692 }
6693 case MagickFormatOptions:
6694 {
6695 (void) ListMagickInfo((FILE *) NULL,exception);
6696 break;
6697 }
6698 case MagickLocaleOptions:
6699 {
6700 (void) ListLocaleInfo((FILE *) NULL,exception);
6701 break;
6702 }
6703 case MagickLogOptions:
6704 {
6705 (void) ListLogInfo((FILE *) NULL,exception);
6706 break;
6707 }
6708 case MagickMagicOptions:
6709 {
6710 (void) ListMagicInfo((FILE *) NULL,exception);
6711 break;
6712 }
6713 case MagickMimeOptions:
6714 {
6715 (void) ListMimeInfo((FILE *) NULL,exception);
6716 break;
6717 }
6718 case MagickModuleOptions:
6719 {
6720 (void) ListModuleInfo((FILE *) NULL,exception);
6721 break;
6722 }
6723 case MagickPolicyOptions:
6724 {
6725 (void) ListPolicyInfo((FILE *) NULL,exception);
6726 break;
6727 }
6728 case MagickResourceOptions:
6729 {
6730 (void) ListMagickResourceInfo((FILE *) NULL,exception);
6731 break;
6732 }
6733 case MagickThresholdOptions:
6734 {
6735 (void) ListThresholdMaps((FILE *) NULL,exception);
6736 break;
6737 }
6738 default:
6739 {
cristy042ee782011-04-22 18:48:30 +00006740 (void) ListCommandOptions((FILE *) NULL,(CommandOption) list,
cristy3ed852e2009-09-05 21:47:34 +00006741 exception);
6742 break;
6743 }
6744 }
cristyaeb2cbc2010-05-07 13:28:58 +00006745 break;
cristy3ed852e2009-09-05 21:47:34 +00006746 }
6747 if (LocaleCompare("log",option+1) == 0)
6748 {
6749 if (*option == '+')
6750 break;
6751 (void) SetLogFormat(argv[i+1]);
6752 break;
6753 }
6754 if (LocaleCompare("loop",option+1) == 0)
6755 {
6756 if (*option == '+')
6757 {
6758 (void) SetImageOption(image_info,option+1,"0");
6759 break;
6760 }
6761 (void) SetImageOption(image_info,option+1,argv[i+1]);
6762 break;
6763 }
6764 break;
6765 }
6766 case 'm':
6767 {
6768 if (LocaleCompare("matte",option+1) == 0)
6769 {
6770 if (*option == '+')
6771 {
6772 (void) SetImageOption(image_info,option+1,"false");
6773 break;
6774 }
6775 (void) SetImageOption(image_info,option+1,"true");
6776 break;
6777 }
6778 if (LocaleCompare("mattecolor",option+1) == 0)
6779 {
6780 if (*option == '+')
6781 {
6782 (void) SetImageOption(image_info,option+1,argv[i+1]);
6783 (void) QueryColorDatabase(MatteColor,&image_info->matte_color,
6784 exception);
6785 break;
6786 }
6787 (void) SetImageOption(image_info,option+1,argv[i+1]);
6788 (void) QueryColorDatabase(argv[i+1],&image_info->matte_color,
6789 exception);
6790 break;
6791 }
6792 if (LocaleCompare("monitor",option+1) == 0)
6793 {
6794 (void) SetImageInfoProgressMonitor(image_info,MonitorProgress,
6795 (void *) NULL);
6796 break;
6797 }
6798 if (LocaleCompare("monochrome",option+1) == 0)
6799 {
6800 image_info->monochrome=(*option == '-') ? MagickTrue : MagickFalse;
6801 break;
6802 }
6803 break;
6804 }
6805 case 'o':
6806 {
6807 if (LocaleCompare("orient",option+1) == 0)
6808 {
6809 if (*option == '+')
6810 {
6811 image_info->orientation=UndefinedOrientation;
6812 (void) SetImageOption(image_info,option+1,"undefined");
6813 break;
6814 }
cristy042ee782011-04-22 18:48:30 +00006815 image_info->orientation=(OrientationType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006816 MagickOrientationOptions,MagickFalse,argv[i+1]);
cristyc6e214d2010-08-08 00:31:08 +00006817 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006818 break;
6819 }
6820 }
6821 case 'p':
6822 {
6823 if (LocaleCompare("page",option+1) == 0)
6824 {
6825 char
6826 *canonical_page,
6827 page[MaxTextExtent];
6828
6829 const char
6830 *image_option;
6831
6832 MagickStatusType
6833 flags;
6834
6835 RectangleInfo
6836 geometry;
6837
6838 if (*option == '+')
6839 {
6840 (void) DeleteImageOption(image_info,option+1);
6841 (void) CloneString(&image_info->page,(char *) NULL);
6842 break;
6843 }
6844 (void) ResetMagickMemory(&geometry,0,sizeof(geometry));
6845 image_option=GetImageOption(image_info,"page");
6846 if (image_option != (const char *) NULL)
6847 flags=ParseAbsoluteGeometry(image_option,&geometry);
6848 canonical_page=GetPageGeometry(argv[i+1]);
6849 flags=ParseAbsoluteGeometry(canonical_page,&geometry);
6850 canonical_page=DestroyString(canonical_page);
cristyb51dff52011-05-19 16:55:47 +00006851 (void) FormatLocaleString(page,MaxTextExtent,"%lux%lu",
cristyf2faecf2010-05-28 19:19:36 +00006852 (unsigned long) geometry.width,(unsigned long) geometry.height);
cristy3ed852e2009-09-05 21:47:34 +00006853 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
cristyb51dff52011-05-19 16:55:47 +00006854 (void) FormatLocaleString(page,MaxTextExtent,"%lux%lu%+ld%+ld",
cristyf2faecf2010-05-28 19:19:36 +00006855 (unsigned long) geometry.width,(unsigned long) geometry.height,
6856 (long) geometry.x,(long) geometry.y);
cristy3ed852e2009-09-05 21:47:34 +00006857 (void) SetImageOption(image_info,option+1,page);
6858 (void) CloneString(&image_info->page,page);
6859 break;
6860 }
6861 if (LocaleCompare("pen",option+1) == 0)
6862 {
6863 if (*option == '+')
6864 {
6865 (void) SetImageOption(image_info,option+1,"none");
6866 break;
6867 }
6868 (void) SetImageOption(image_info,option+1,argv[i+1]);
6869 break;
6870 }
6871 if (LocaleCompare("ping",option+1) == 0)
6872 {
6873 image_info->ping=(*option == '-') ? MagickTrue : MagickFalse;
6874 break;
6875 }
6876 if (LocaleCompare("pointsize",option+1) == 0)
6877 {
6878 if (*option == '+')
6879 geometry_info.rho=0.0;
6880 else
6881 (void) ParseGeometry(argv[i+1],&geometry_info);
6882 image_info->pointsize=geometry_info.rho;
6883 break;
6884 }
cristye7f51092010-01-17 00:39:37 +00006885 if (LocaleCompare("precision",option+1) == 0)
6886 {
cristybf2766a2010-01-17 03:33:23 +00006887 (void) SetMagickPrecision(StringToInteger(argv[i+1]));
cristye7f51092010-01-17 00:39:37 +00006888 break;
6889 }
cristy3ed852e2009-09-05 21:47:34 +00006890 if (LocaleCompare("preview",option+1) == 0)
6891 {
6892 /*
6893 Preview image.
6894 */
6895 if (*option == '+')
6896 {
6897 image_info->preview_type=UndefinedPreview;
6898 break;
6899 }
cristy042ee782011-04-22 18:48:30 +00006900 image_info->preview_type=(PreviewType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006901 MagickPreviewOptions,MagickFalse,argv[i+1]);
6902 break;
6903 }
6904 break;
6905 }
6906 case 'q':
6907 {
6908 if (LocaleCompare("quality",option+1) == 0)
6909 {
6910 /*
6911 Set image compression quality.
6912 */
6913 if (*option == '+')
6914 {
6915 image_info->quality=UndefinedCompressionQuality;
6916 (void) SetImageOption(image_info,option+1,"0");
6917 break;
6918 }
cristye27293e2009-12-18 02:53:20 +00006919 image_info->quality=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006920 (void) SetImageOption(image_info,option+1,argv[i+1]);
6921 break;
6922 }
6923 if (LocaleCompare("quiet",option+1) == 0)
6924 {
6925 static WarningHandler
6926 warning_handler = (WarningHandler) NULL;
6927
6928 if (*option == '+')
6929 {
6930 /*
6931 Restore error or warning messages.
6932 */
6933 warning_handler=SetWarningHandler(warning_handler);
6934 break;
6935 }
6936 /*
6937 Suppress error or warning messages.
6938 */
6939 warning_handler=SetWarningHandler((WarningHandler) NULL);
6940 break;
6941 }
6942 break;
6943 }
6944 case 'r':
6945 {
6946 if (LocaleCompare("red-primary",option+1) == 0)
6947 {
6948 if (*option == '+')
6949 {
6950 (void) SetImageOption(image_info,option+1,"0.0");
6951 break;
6952 }
6953 (void) SetImageOption(image_info,option+1,argv[i+1]);
6954 break;
6955 }
6956 break;
6957 }
6958 case 's':
6959 {
6960 if (LocaleCompare("sampling-factor",option+1) == 0)
6961 {
6962 /*
6963 Set image sampling factor.
6964 */
6965 if (*option == '+')
6966 {
6967 if (image_info->sampling_factor != (char *) NULL)
6968 image_info->sampling_factor=DestroyString(
6969 image_info->sampling_factor);
6970 break;
6971 }
6972 (void) CloneString(&image_info->sampling_factor,argv[i+1]);
6973 break;
6974 }
6975 if (LocaleCompare("scene",option+1) == 0)
6976 {
6977 /*
6978 Set image scene.
6979 */
6980 if (*option == '+')
6981 {
6982 image_info->scene=0;
6983 (void) SetImageOption(image_info,option+1,"0");
6984 break;
6985 }
cristye27293e2009-12-18 02:53:20 +00006986 image_info->scene=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006987 (void) SetImageOption(image_info,option+1,argv[i+1]);
6988 break;
6989 }
6990 if (LocaleCompare("seed",option+1) == 0)
6991 {
cristybb503372010-05-27 20:51:26 +00006992 size_t
cristy3ed852e2009-09-05 21:47:34 +00006993 seed;
6994
6995 if (*option == '+')
6996 {
cristybb503372010-05-27 20:51:26 +00006997 seed=(size_t) time((time_t *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00006998 SeedPseudoRandomGenerator(seed);
6999 break;
7000 }
cristye27293e2009-12-18 02:53:20 +00007001 seed=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007002 SeedPseudoRandomGenerator(seed);
7003 break;
7004 }
7005 if (LocaleCompare("size",option+1) == 0)
7006 {
7007 if (*option == '+')
7008 {
7009 if (image_info->size != (char *) NULL)
7010 image_info->size=DestroyString(image_info->size);
7011 break;
7012 }
7013 (void) CloneString(&image_info->size,argv[i+1]);
7014 break;
7015 }
7016 if (LocaleCompare("stroke",option+1) == 0)
7017 {
7018 if (*option == '+')
7019 {
7020 (void) SetImageOption(image_info,option+1,"none");
7021 break;
7022 }
7023 (void) SetImageOption(image_info,option+1,argv[i+1]);
7024 break;
7025 }
7026 if (LocaleCompare("strokewidth",option+1) == 0)
7027 {
7028 if (*option == '+')
7029 {
7030 (void) SetImageOption(image_info,option+1,"0");
7031 break;
7032 }
7033 (void) SetImageOption(image_info,option+1,argv[i+1]);
7034 break;
7035 }
cristyd9a29192010-10-16 16:49:53 +00007036 if (LocaleCompare("synchronize",option+1) == 0)
7037 {
7038 if (*option == '+')
7039 {
7040 image_info->synchronize=MagickFalse;
7041 break;
7042 }
7043 image_info->synchronize=MagickTrue;
7044 break;
7045 }
cristy3ed852e2009-09-05 21:47:34 +00007046 break;
7047 }
7048 case 't':
7049 {
7050 if (LocaleCompare("taint",option+1) == 0)
7051 {
7052 if (*option == '+')
7053 {
7054 (void) SetImageOption(image_info,option+1,"false");
7055 break;
7056 }
7057 (void) SetImageOption(image_info,option+1,"true");
7058 break;
7059 }
7060 if (LocaleCompare("texture",option+1) == 0)
7061 {
7062 if (*option == '+')
7063 {
7064 if (image_info->texture != (char *) NULL)
7065 image_info->texture=DestroyString(image_info->texture);
7066 break;
7067 }
7068 (void) CloneString(&image_info->texture,argv[i+1]);
7069 break;
7070 }
7071 if (LocaleCompare("tile-offset",option+1) == 0)
7072 {
7073 if (*option == '+')
7074 {
7075 (void) SetImageOption(image_info,option+1,"0");
7076 break;
7077 }
7078 (void) SetImageOption(image_info,option+1,argv[i+1]);
7079 break;
7080 }
7081 if (LocaleCompare("transparent-color",option+1) == 0)
7082 {
7083 if (*option == '+')
7084 {
7085 (void) QueryColorDatabase("none",&image_info->transparent_color, exception);
7086 (void) SetImageOption(image_info,option+1,"none");
7087 break;
7088 }
7089 (void) QueryColorDatabase(argv[i+1],&image_info->transparent_color,
7090 exception);
7091 (void) SetImageOption(image_info,option+1,argv[i+1]);
7092 break;
7093 }
7094 if (LocaleCompare("type",option+1) == 0)
7095 {
7096 if (*option == '+')
7097 {
cristy5f1c1ff2010-12-23 21:38:06 +00007098 image_info->type=UndefinedType;
cristy3ed852e2009-09-05 21:47:34 +00007099 (void) SetImageOption(image_info,option+1,"undefined");
7100 break;
7101 }
cristy042ee782011-04-22 18:48:30 +00007102 image_info->type=(ImageType) ParseCommandOption(MagickTypeOptions,
cristy3ed852e2009-09-05 21:47:34 +00007103 MagickFalse,argv[i+1]);
7104 (void) SetImageOption(image_info,option+1,argv[i+1]);
7105 break;
7106 }
7107 break;
7108 }
7109 case 'u':
7110 {
7111 if (LocaleCompare("undercolor",option+1) == 0)
7112 {
7113 if (*option == '+')
7114 {
7115 (void) DeleteImageOption(image_info,option+1);
7116 break;
7117 }
7118 (void) SetImageOption(image_info,option+1,argv[i+1]);
7119 break;
7120 }
7121 if (LocaleCompare("units",option+1) == 0)
7122 {
7123 if (*option == '+')
7124 {
7125 image_info->units=UndefinedResolution;
7126 (void) SetImageOption(image_info,option+1,"undefined");
7127 break;
7128 }
cristy042ee782011-04-22 18:48:30 +00007129 image_info->units=(ResolutionType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007130 MagickResolutionOptions,MagickFalse,argv[i+1]);
7131 (void) SetImageOption(image_info,option+1,argv[i+1]);
7132 break;
7133 }
7134 break;
7135 }
7136 case 'v':
7137 {
7138 if (LocaleCompare("verbose",option+1) == 0)
7139 {
7140 if (*option == '+')
7141 {
7142 image_info->verbose=MagickFalse;
7143 break;
7144 }
7145 image_info->verbose=MagickTrue;
7146 image_info->ping=MagickFalse;
7147 break;
7148 }
7149 if (LocaleCompare("view",option+1) == 0)
7150 {
7151 if (*option == '+')
7152 {
7153 if (image_info->view != (char *) NULL)
7154 image_info->view=DestroyString(image_info->view);
7155 break;
7156 }
7157 (void) CloneString(&image_info->view,argv[i+1]);
7158 break;
7159 }
7160 if (LocaleCompare("virtual-pixel",option+1) == 0)
7161 {
7162 if (*option == '+')
7163 {
7164 image_info->virtual_pixel_method=UndefinedVirtualPixelMethod;
7165 (void) SetImageOption(image_info,option+1,"undefined");
7166 break;
7167 }
7168 image_info->virtual_pixel_method=(VirtualPixelMethod)
cristy042ee782011-04-22 18:48:30 +00007169 ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00007170 argv[i+1]);
7171 (void) SetImageOption(image_info,option+1,argv[i+1]);
7172 break;
7173 }
7174 break;
7175 }
7176 case 'w':
7177 {
7178 if (LocaleCompare("white-point",option+1) == 0)
7179 {
7180 if (*option == '+')
7181 {
7182 (void) SetImageOption(image_info,option+1,"0.0");
7183 break;
7184 }
7185 (void) SetImageOption(image_info,option+1,argv[i+1]);
7186 break;
7187 }
7188 break;
7189 }
7190 default:
7191 break;
7192 }
7193 i+=count;
7194 }
7195 return(MagickTrue);
7196}
7197
7198/*
7199%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7200% %
7201% %
7202% %
7203+ M o g r i f y I m a g e L i s t %
7204% %
7205% %
7206% %
7207%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7208%
7209% MogrifyImageList() applies any command line options that might affect the
7210% entire image list (e.g. -append, -coalesce, etc.).
7211%
7212% The format of the MogrifyImage method is:
7213%
7214% MagickBooleanType MogrifyImageList(ImageInfo *image_info,const int argc,
7215% const char **argv,Image **images,ExceptionInfo *exception)
7216%
7217% A description of each parameter follows:
7218%
7219% o image_info: the image info..
7220%
7221% o argc: Specifies a pointer to an integer describing the number of
7222% elements in the argument vector.
7223%
7224% o argv: Specifies a pointer to a text array containing the command line
7225% arguments.
7226%
anthonye9c27192011-03-27 08:07:06 +00007227% o images: pointer to pointer of the first image in image list.
cristy3ed852e2009-09-05 21:47:34 +00007228%
7229% o exception: return any errors or warnings in this structure.
7230%
7231*/
7232WandExport MagickBooleanType MogrifyImageList(ImageInfo *image_info,
7233 const int argc,const char **argv,Image **images,ExceptionInfo *exception)
7234{
7235 ChannelType
7236 channel;
7237
7238 const char
7239 *option;
7240
cristy6b3da3a2010-06-20 02:21:46 +00007241 ImageInfo
7242 *mogrify_info;
cristy3ed852e2009-09-05 21:47:34 +00007243
7244 MagickStatusType
7245 status;
7246
7247 QuantizeInfo
7248 *quantize_info;
7249
cristybb503372010-05-27 20:51:26 +00007250 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00007251 i;
7252
cristy6b3da3a2010-06-20 02:21:46 +00007253 ssize_t
7254 count,
7255 index;
7256
cristy3ed852e2009-09-05 21:47:34 +00007257 /*
7258 Apply options to the image list.
7259 */
7260 assert(image_info != (ImageInfo *) NULL);
7261 assert(image_info->signature == MagickSignature);
7262 assert(images != (Image **) NULL);
anthonye9c27192011-03-27 08:07:06 +00007263 assert((*images)->previous == (Image *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00007264 assert((*images)->signature == MagickSignature);
7265 if ((*images)->debug != MagickFalse)
7266 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
7267 (*images)->filename);
7268 if ((argc <= 0) || (*argv == (char *) NULL))
7269 return(MagickTrue);
cristy6b3da3a2010-06-20 02:21:46 +00007270 mogrify_info=CloneImageInfo(image_info);
7271 quantize_info=AcquireQuantizeInfo(mogrify_info);
7272 channel=mogrify_info->channel;
cristy3ed852e2009-09-05 21:47:34 +00007273 status=MagickTrue;
cristybb503372010-05-27 20:51:26 +00007274 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00007275 {
cristy74fe8f12009-10-03 19:09:01 +00007276 if (*images == (Image *) NULL)
7277 break;
cristy3ed852e2009-09-05 21:47:34 +00007278 option=argv[i];
cristy042ee782011-04-22 18:48:30 +00007279 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00007280 continue;
cristy042ee782011-04-22 18:48:30 +00007281 count=ParseCommandOption(MagickCommandOptions,MagickFalse,option);
anthonyce2716b2011-04-22 09:51:34 +00007282 count=MagickMax(count,0L);
cristycee97112010-05-28 00:44:52 +00007283 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00007284 break;
cristy6b3da3a2010-06-20 02:21:46 +00007285 status=MogrifyImageInfo(mogrify_info,(int) count+1,argv+i,exception);
cristy3ed852e2009-09-05 21:47:34 +00007286 switch (*(option+1))
7287 {
7288 case 'a':
7289 {
7290 if (LocaleCompare("affinity",option+1) == 0)
7291 {
cristy6b3da3a2010-06-20 02:21:46 +00007292 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007293 if (*option == '+')
7294 {
7295 (void) RemapImages(quantize_info,*images,(Image *) NULL);
7296 InheritException(exception,&(*images)->exception);
7297 break;
7298 }
7299 i++;
7300 break;
7301 }
7302 if (LocaleCompare("append",option+1) == 0)
7303 {
7304 Image
7305 *append_image;
7306
cristy6b3da3a2010-06-20 02:21:46 +00007307 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007308 append_image=AppendImages(*images,*option == '-' ? MagickTrue :
7309 MagickFalse,exception);
7310 if (append_image == (Image *) NULL)
7311 {
7312 status=MagickFalse;
7313 break;
7314 }
7315 *images=DestroyImageList(*images);
7316 *images=append_image;
7317 break;
7318 }
7319 if (LocaleCompare("average",option+1) == 0)
7320 {
7321 Image
7322 *average_image;
7323
cristyd18ae7c2010-03-07 17:39:52 +00007324 /*
7325 Average an image sequence (deprecated).
7326 */
cristy6b3da3a2010-06-20 02:21:46 +00007327 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007328 average_image=EvaluateImages(*images,MeanEvaluateOperator,
7329 exception);
cristy3ed852e2009-09-05 21:47:34 +00007330 if (average_image == (Image *) NULL)
7331 {
7332 status=MagickFalse;
7333 break;
7334 }
7335 *images=DestroyImageList(*images);
7336 *images=average_image;
7337 break;
7338 }
7339 break;
7340 }
7341 case 'c':
7342 {
7343 if (LocaleCompare("channel",option+1) == 0)
7344 {
7345 if (*option == '+')
7346 {
7347 channel=DefaultChannels;
7348 break;
7349 }
7350 channel=(ChannelType) ParseChannelOption(argv[i+1]);
7351 break;
7352 }
7353 if (LocaleCompare("clut",option+1) == 0)
7354 {
7355 Image
7356 *clut_image,
7357 *image;
7358
cristy6b3da3a2010-06-20 02:21:46 +00007359 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007360 image=RemoveFirstImageFromList(images);
7361 clut_image=RemoveFirstImageFromList(images);
7362 if (clut_image == (Image *) NULL)
7363 {
7364 status=MagickFalse;
7365 break;
7366 }
cristyf89cb1d2011-07-07 01:24:37 +00007367 (void) ClutImage(image,clut_image);
cristy3ed852e2009-09-05 21:47:34 +00007368 clut_image=DestroyImage(clut_image);
7369 InheritException(exception,&image->exception);
7370 *images=DestroyImageList(*images);
7371 *images=image;
7372 break;
7373 }
7374 if (LocaleCompare("coalesce",option+1) == 0)
7375 {
7376 Image
7377 *coalesce_image;
7378
cristy6b3da3a2010-06-20 02:21:46 +00007379 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007380 coalesce_image=CoalesceImages(*images,exception);
7381 if (coalesce_image == (Image *) NULL)
7382 {
7383 status=MagickFalse;
7384 break;
7385 }
7386 *images=DestroyImageList(*images);
7387 *images=coalesce_image;
7388 break;
7389 }
7390 if (LocaleCompare("combine",option+1) == 0)
7391 {
7392 Image
7393 *combine_image;
7394
cristy6b3da3a2010-06-20 02:21:46 +00007395 (void) SyncImagesSettings(mogrify_info,*images);
cristy3139dc22011-07-08 00:11:42 +00007396 combine_image=CombineImages(*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007397 if (combine_image == (Image *) NULL)
7398 {
7399 status=MagickFalse;
7400 break;
7401 }
7402 *images=DestroyImageList(*images);
7403 *images=combine_image;
7404 break;
7405 }
7406 if (LocaleCompare("composite",option+1) == 0)
7407 {
7408 Image
7409 *mask_image,
7410 *composite_image,
7411 *image;
7412
7413 RectangleInfo
7414 geometry;
7415
cristy6b3da3a2010-06-20 02:21:46 +00007416 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007417 image=RemoveFirstImageFromList(images);
7418 composite_image=RemoveFirstImageFromList(images);
7419 if (composite_image == (Image *) NULL)
7420 {
7421 status=MagickFalse;
7422 break;
7423 }
7424 (void) TransformImage(&composite_image,(char *) NULL,
7425 composite_image->geometry);
7426 SetGeometry(composite_image,&geometry);
7427 (void) ParseAbsoluteGeometry(composite_image->geometry,&geometry);
7428 GravityAdjustGeometry(image->columns,image->rows,image->gravity,
7429 &geometry);
7430 mask_image=RemoveFirstImageFromList(images);
7431 if (mask_image != (Image *) NULL)
7432 {
7433 if ((image->compose == DisplaceCompositeOp) ||
7434 (image->compose == DistortCompositeOp))
7435 {
7436 /*
7437 Merge Y displacement into X displacement image.
7438 */
7439 (void) CompositeImage(composite_image,CopyGreenCompositeOp,
7440 mask_image,0,0);
7441 mask_image=DestroyImage(mask_image);
7442 }
7443 else
7444 {
7445 /*
7446 Set a blending mask for the composition.
7447 */
anthonya129f702011-04-14 01:08:48 +00007448 /* POSIBLE ERROR; what if image->mask already set */
cristy3ed852e2009-09-05 21:47:34 +00007449 image->mask=mask_image;
7450 (void) NegateImage(image->mask,MagickFalse);
7451 }
7452 }
cristyab015852011-07-06 01:03:32 +00007453 (void) CompositeImageChannel(image,channel,image->compose,
7454 composite_image,geometry.x,geometry.y);
anthonya129f702011-04-14 01:08:48 +00007455 if (mask_image != (Image *) NULL)
7456 mask_image=image->mask=DestroyImage(image->mask);
cristy3ed852e2009-09-05 21:47:34 +00007457 composite_image=DestroyImage(composite_image);
7458 InheritException(exception,&image->exception);
7459 *images=DestroyImageList(*images);
7460 *images=image;
7461 break;
7462 }
anthony9f4f0342011-03-28 11:47:22 +00007463#if 0
7464This has been merged completely into MogrifyImage()
cristy3ed852e2009-09-05 21:47:34 +00007465 if (LocaleCompare("crop",option+1) == 0)
7466 {
7467 MagickStatusType
7468 flags;
7469
7470 RectangleInfo
7471 geometry;
7472
anthonye9c27192011-03-27 08:07:06 +00007473 /*
anthony9f4f0342011-03-28 11:47:22 +00007474 Crop Image.
anthonye9c27192011-03-27 08:07:06 +00007475 */
cristy6b3da3a2010-06-20 02:21:46 +00007476 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007477 flags=ParseGravityGeometry(*images,argv[i+1],&geometry,exception);
7478 if (((geometry.width == 0) && (geometry.height == 0)) ||
7479 ((flags & XValue) != 0) || ((flags & YValue) != 0))
7480 break;
7481 (void) TransformImages(images,argv[i+1],(char *) NULL);
7482 InheritException(exception,&(*images)->exception);
7483 break;
7484 }
anthony9f4f0342011-03-28 11:47:22 +00007485#endif
cristy3ed852e2009-09-05 21:47:34 +00007486 break;
7487 }
7488 case 'd':
7489 {
7490 if (LocaleCompare("deconstruct",option+1) == 0)
7491 {
7492 Image
7493 *deconstruct_image;
7494
cristy6b3da3a2010-06-20 02:21:46 +00007495 (void) SyncImagesSettings(mogrify_info,*images);
cristy8a9106f2011-07-05 14:39:26 +00007496 deconstruct_image=CompareImagesLayers(*images,CompareAnyLayer,
cristy4c08aed2011-07-01 19:47:50 +00007497 exception);
cristy3ed852e2009-09-05 21:47:34 +00007498 if (deconstruct_image == (Image *) NULL)
7499 {
7500 status=MagickFalse;
7501 break;
7502 }
7503 *images=DestroyImageList(*images);
7504 *images=deconstruct_image;
7505 break;
7506 }
7507 if (LocaleCompare("delete",option+1) == 0)
7508 {
7509 if (*option == '+')
7510 DeleteImages(images,"-1",exception);
7511 else
7512 DeleteImages(images,argv[i+1],exception);
7513 break;
7514 }
7515 if (LocaleCompare("dither",option+1) == 0)
7516 {
7517 if (*option == '+')
7518 {
7519 quantize_info->dither=MagickFalse;
7520 break;
7521 }
7522 quantize_info->dither=MagickTrue;
cristy042ee782011-04-22 18:48:30 +00007523 quantize_info->dither_method=(DitherMethod) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007524 MagickDitherOptions,MagickFalse,argv[i+1]);
7525 break;
7526 }
cristyecb10ff2011-03-22 13:14:03 +00007527 if (LocaleCompare("duplicate",option+1) == 0)
7528 {
cristy72988482011-03-29 16:34:38 +00007529 Image
7530 *duplicate_images;
cristybf95deb2011-03-23 00:25:36 +00007531
anthony2b6bcae2011-03-23 13:05:34 +00007532 if (*option == '+')
cristy72988482011-03-29 16:34:38 +00007533 duplicate_images=DuplicateImages(*images,1,"-1",exception);
7534 else
7535 {
7536 const char
7537 *p;
7538
anthony2b6bcae2011-03-23 13:05:34 +00007539 size_t
7540 number_duplicates;
anthony9bd15492011-03-23 02:11:13 +00007541
anthony2b6bcae2011-03-23 13:05:34 +00007542 number_duplicates=(size_t) StringToLong(argv[i+1]);
cristy72988482011-03-29 16:34:38 +00007543 p=strchr(argv[i+1],',');
7544 if (p == (const char *) NULL)
7545 duplicate_images=DuplicateImages(*images,number_duplicates,
7546 "-1",exception);
anthony2b6bcae2011-03-23 13:05:34 +00007547 else
cristy72988482011-03-29 16:34:38 +00007548 duplicate_images=DuplicateImages(*images,number_duplicates,p,
7549 exception);
anthony2b6bcae2011-03-23 13:05:34 +00007550 }
7551 AppendImageToList(images, duplicate_images);
7552 (void) SyncImagesSettings(mogrify_info,*images);
cristyecb10ff2011-03-22 13:14:03 +00007553 break;
7554 }
cristy3ed852e2009-09-05 21:47:34 +00007555 break;
7556 }
cristyd18ae7c2010-03-07 17:39:52 +00007557 case 'e':
7558 {
7559 if (LocaleCompare("evaluate-sequence",option+1) == 0)
7560 {
7561 Image
7562 *evaluate_image;
7563
7564 MagickEvaluateOperator
7565 op;
7566
cristy6b3da3a2010-06-20 02:21:46 +00007567 (void) SyncImageSettings(mogrify_info,*images);
cristy042ee782011-04-22 18:48:30 +00007568 op=(MagickEvaluateOperator) ParseCommandOption(MagickEvaluateOptions,
cristyd18ae7c2010-03-07 17:39:52 +00007569 MagickFalse,argv[i+1]);
7570 evaluate_image=EvaluateImages(*images,op,exception);
7571 if (evaluate_image == (Image *) NULL)
7572 {
7573 status=MagickFalse;
7574 break;
7575 }
7576 *images=DestroyImageList(*images);
7577 *images=evaluate_image;
7578 break;
7579 }
7580 break;
7581 }
cristy3ed852e2009-09-05 21:47:34 +00007582 case 'f':
7583 {
cristyf0a247f2009-10-04 00:20:03 +00007584 if (LocaleCompare("fft",option+1) == 0)
7585 {
7586 Image
7587 *fourier_image;
7588
7589 /*
7590 Implements the discrete Fourier transform (DFT).
7591 */
cristy6b3da3a2010-06-20 02:21:46 +00007592 (void) SyncImageSettings(mogrify_info,*images);
cristyf0a247f2009-10-04 00:20:03 +00007593 fourier_image=ForwardFourierTransformImage(*images,*option == '-' ?
7594 MagickTrue : MagickFalse,exception);
7595 if (fourier_image == (Image *) NULL)
7596 break;
7597 *images=DestroyImage(*images);
7598 *images=fourier_image;
7599 break;
7600 }
cristy3ed852e2009-09-05 21:47:34 +00007601 if (LocaleCompare("flatten",option+1) == 0)
7602 {
7603 Image
7604 *flatten_image;
7605
cristy6b3da3a2010-06-20 02:21:46 +00007606 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007607 flatten_image=MergeImageLayers(*images,FlattenLayer,exception);
7608 if (flatten_image == (Image *) NULL)
7609 break;
7610 *images=DestroyImageList(*images);
7611 *images=flatten_image;
7612 break;
7613 }
7614 if (LocaleCompare("fx",option+1) == 0)
7615 {
7616 Image
7617 *fx_image;
7618
cristy6b3da3a2010-06-20 02:21:46 +00007619 (void) SyncImagesSettings(mogrify_info,*images);
cristy490408a2011-07-07 14:42:05 +00007620 fx_image=FxImage(*images,argv[i+1],exception);
cristy3ed852e2009-09-05 21:47:34 +00007621 if (fx_image == (Image *) NULL)
7622 {
7623 status=MagickFalse;
7624 break;
7625 }
7626 *images=DestroyImageList(*images);
7627 *images=fx_image;
7628 break;
7629 }
7630 break;
7631 }
7632 case 'h':
7633 {
7634 if (LocaleCompare("hald-clut",option+1) == 0)
7635 {
7636 Image
7637 *hald_image,
7638 *image;
7639
cristy6b3da3a2010-06-20 02:21:46 +00007640 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007641 image=RemoveFirstImageFromList(images);
7642 hald_image=RemoveFirstImageFromList(images);
7643 if (hald_image == (Image *) NULL)
7644 {
7645 status=MagickFalse;
7646 break;
7647 }
cristyf89cb1d2011-07-07 01:24:37 +00007648 (void) HaldClutImage(image,hald_image);
cristy3ed852e2009-09-05 21:47:34 +00007649 hald_image=DestroyImage(hald_image);
7650 InheritException(exception,&image->exception);
cristy0aff6ea2009-11-14 01:40:53 +00007651 if (*images != (Image *) NULL)
7652 *images=DestroyImageList(*images);
cristy3ed852e2009-09-05 21:47:34 +00007653 *images=image;
7654 break;
7655 }
7656 break;
7657 }
7658 case 'i':
7659 {
7660 if (LocaleCompare("ift",option+1) == 0)
7661 {
7662 Image
cristy8587f882009-11-13 20:28:49 +00007663 *fourier_image,
7664 *magnitude_image,
7665 *phase_image;
cristy3ed852e2009-09-05 21:47:34 +00007666
7667 /*
7668 Implements the inverse fourier discrete Fourier transform (DFT).
7669 */
cristy6b3da3a2010-06-20 02:21:46 +00007670 (void) SyncImagesSettings(mogrify_info,*images);
cristy8587f882009-11-13 20:28:49 +00007671 magnitude_image=RemoveFirstImageFromList(images);
7672 phase_image=RemoveFirstImageFromList(images);
7673 if (phase_image == (Image *) NULL)
7674 {
7675 status=MagickFalse;
7676 break;
7677 }
7678 fourier_image=InverseFourierTransformImage(magnitude_image,
7679 phase_image,*option == '-' ? MagickTrue : MagickFalse,exception);
cristy3ed852e2009-09-05 21:47:34 +00007680 if (fourier_image == (Image *) NULL)
7681 break;
cristy0aff6ea2009-11-14 01:40:53 +00007682 if (*images != (Image *) NULL)
7683 *images=DestroyImage(*images);
cristy3ed852e2009-09-05 21:47:34 +00007684 *images=fourier_image;
7685 break;
7686 }
7687 if (LocaleCompare("insert",option+1) == 0)
7688 {
7689 Image
7690 *p,
7691 *q;
7692
7693 index=0;
7694 if (*option != '+')
cristy32c2aea2010-12-01 01:00:50 +00007695 index=(ssize_t) StringToLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007696 p=RemoveLastImageFromList(images);
7697 if (p == (Image *) NULL)
7698 {
7699 (void) ThrowMagickException(exception,GetMagickModule(),
7700 OptionError,"NoSuchImage","`%s'",argv[i+1]);
7701 status=MagickFalse;
7702 break;
7703 }
7704 q=p;
7705 if (index == 0)
7706 PrependImageToList(images,q);
7707 else
cristybb503372010-05-27 20:51:26 +00007708 if (index == (ssize_t) GetImageListLength(*images))
cristy3ed852e2009-09-05 21:47:34 +00007709 AppendImageToList(images,q);
7710 else
7711 {
7712 q=GetImageFromList(*images,index-1);
7713 if (q == (Image *) NULL)
7714 {
7715 (void) ThrowMagickException(exception,GetMagickModule(),
7716 OptionError,"NoSuchImage","`%s'",argv[i+1]);
7717 status=MagickFalse;
7718 break;
7719 }
7720 InsertImageInList(&q,p);
7721 }
7722 *images=GetFirstImageInList(q);
7723 break;
7724 }
7725 break;
7726 }
7727 case 'l':
7728 {
7729 if (LocaleCompare("layers",option+1) == 0)
7730 {
7731 Image
7732 *layers;
7733
7734 ImageLayerMethod
7735 method;
7736
cristy6b3da3a2010-06-20 02:21:46 +00007737 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007738 layers=(Image *) NULL;
cristy042ee782011-04-22 18:48:30 +00007739 method=(ImageLayerMethod) ParseCommandOption(MagickLayerOptions,
cristy3ed852e2009-09-05 21:47:34 +00007740 MagickFalse,argv[i+1]);
7741 switch (method)
7742 {
7743 case CoalesceLayer:
7744 {
7745 layers=CoalesceImages(*images,exception);
7746 break;
7747 }
7748 case CompareAnyLayer:
7749 case CompareClearLayer:
7750 case CompareOverlayLayer:
7751 default:
7752 {
cristy8a9106f2011-07-05 14:39:26 +00007753 layers=CompareImagesLayers(*images,method,exception);
cristy3ed852e2009-09-05 21:47:34 +00007754 break;
7755 }
7756 case MergeLayer:
7757 case FlattenLayer:
7758 case MosaicLayer:
7759 case TrimBoundsLayer:
7760 {
7761 layers=MergeImageLayers(*images,method,exception);
7762 break;
7763 }
7764 case DisposeLayer:
7765 {
7766 layers=DisposeImages(*images,exception);
7767 break;
7768 }
7769 case OptimizeImageLayer:
7770 {
7771 layers=OptimizeImageLayers(*images,exception);
7772 break;
7773 }
7774 case OptimizePlusLayer:
7775 {
7776 layers=OptimizePlusImageLayers(*images,exception);
7777 break;
7778 }
7779 case OptimizeTransLayer:
7780 {
7781 OptimizeImageTransparency(*images,exception);
7782 break;
7783 }
7784 case RemoveDupsLayer:
7785 {
7786 RemoveDuplicateLayers(images,exception);
7787 break;
7788 }
7789 case RemoveZeroLayer:
7790 {
7791 RemoveZeroDelayLayers(images,exception);
7792 break;
7793 }
7794 case OptimizeLayer:
7795 {
7796 /*
7797 General Purpose, GIF Animation Optimizer.
7798 */
7799 layers=CoalesceImages(*images,exception);
7800 if (layers == (Image *) NULL)
7801 {
7802 status=MagickFalse;
7803 break;
7804 }
7805 InheritException(exception,&layers->exception);
7806 *images=DestroyImageList(*images);
7807 *images=layers;
7808 layers=OptimizeImageLayers(*images,exception);
7809 if (layers == (Image *) NULL)
7810 {
7811 status=MagickFalse;
7812 break;
7813 }
7814 InheritException(exception,&layers->exception);
7815 *images=DestroyImageList(*images);
7816 *images=layers;
7817 layers=(Image *) NULL;
7818 OptimizeImageTransparency(*images,exception);
7819 InheritException(exception,&(*images)->exception);
7820 (void) RemapImages(quantize_info,*images,(Image *) NULL);
7821 break;
7822 }
7823 case CompositeLayer:
7824 {
7825 CompositeOperator
7826 compose;
7827
7828 Image
7829 *source;
7830
7831 RectangleInfo
7832 geometry;
7833
7834 /*
7835 Split image sequence at the first 'NULL:' image.
7836 */
7837 source=(*images);
7838 while (source != (Image *) NULL)
7839 {
7840 source=GetNextImageInList(source);
7841 if ((source != (Image *) NULL) &&
7842 (LocaleCompare(source->magick,"NULL") == 0))
7843 break;
7844 }
7845 if (source != (Image *) NULL)
7846 {
7847 if ((GetPreviousImageInList(source) == (Image *) NULL) ||
7848 (GetNextImageInList(source) == (Image *) NULL))
7849 source=(Image *) NULL;
7850 else
7851 {
7852 /*
7853 Separate the two lists, junk the null: image.
7854 */
7855 source=SplitImageList(source->previous);
7856 DeleteImageFromList(&source);
7857 }
7858 }
7859 if (source == (Image *) NULL)
7860 {
7861 (void) ThrowMagickException(exception,GetMagickModule(),
7862 OptionError,"MissingNullSeparator","layers Composite");
7863 status=MagickFalse;
7864 break;
7865 }
7866 /*
7867 Adjust offset with gravity and virtual canvas.
7868 */
7869 SetGeometry(*images,&geometry);
7870 (void) ParseAbsoluteGeometry((*images)->geometry,&geometry);
7871 geometry.width=source->page.width != 0 ?
7872 source->page.width : source->columns;
7873 geometry.height=source->page.height != 0 ?
7874 source->page.height : source->rows;
7875 GravityAdjustGeometry((*images)->page.width != 0 ?
7876 (*images)->page.width : (*images)->columns,
7877 (*images)->page.height != 0 ? (*images)->page.height :
7878 (*images)->rows,(*images)->gravity,&geometry);
7879 compose=OverCompositeOp;
cristy6b3da3a2010-06-20 02:21:46 +00007880 option=GetImageOption(mogrify_info,"compose");
cristy3ed852e2009-09-05 21:47:34 +00007881 if (option != (const char *) NULL)
cristy042ee782011-04-22 18:48:30 +00007882 compose=(CompositeOperator) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007883 MagickComposeOptions,MagickFalse,option);
7884 CompositeLayers(*images,compose,source,geometry.x,geometry.y,
7885 exception);
7886 source=DestroyImageList(source);
7887 break;
7888 }
7889 }
7890 if (layers == (Image *) NULL)
7891 break;
7892 InheritException(exception,&layers->exception);
7893 *images=DestroyImageList(*images);
7894 *images=layers;
7895 break;
7896 }
7897 break;
7898 }
7899 case 'm':
7900 {
7901 if (LocaleCompare("map",option+1) == 0)
7902 {
cristy6b3da3a2010-06-20 02:21:46 +00007903 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007904 if (*option == '+')
7905 {
7906 (void) RemapImages(quantize_info,*images,(Image *) NULL);
7907 InheritException(exception,&(*images)->exception);
7908 break;
7909 }
7910 i++;
7911 break;
7912 }
cristyf40785b2010-03-06 02:27:27 +00007913 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00007914 {
7915 Image
cristyf40785b2010-03-06 02:27:27 +00007916 *maximum_image;
cristy1c274c92010-03-06 02:06:45 +00007917
cristyd18ae7c2010-03-07 17:39:52 +00007918 /*
7919 Maximum image sequence (deprecated).
7920 */
cristy6b3da3a2010-06-20 02:21:46 +00007921 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007922 maximum_image=EvaluateImages(*images,MaxEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00007923 if (maximum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00007924 {
7925 status=MagickFalse;
7926 break;
7927 }
7928 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00007929 *images=maximum_image;
cristy1c274c92010-03-06 02:06:45 +00007930 break;
7931 }
cristyf40785b2010-03-06 02:27:27 +00007932 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00007933 {
7934 Image
cristyf40785b2010-03-06 02:27:27 +00007935 *minimum_image;
cristy1c274c92010-03-06 02:06:45 +00007936
cristyd18ae7c2010-03-07 17:39:52 +00007937 /*
7938 Minimum image sequence (deprecated).
7939 */
cristy6b3da3a2010-06-20 02:21:46 +00007940 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007941 minimum_image=EvaluateImages(*images,MinEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00007942 if (minimum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00007943 {
7944 status=MagickFalse;
7945 break;
7946 }
7947 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00007948 *images=minimum_image;
cristy1c274c92010-03-06 02:06:45 +00007949 break;
7950 }
cristy3ed852e2009-09-05 21:47:34 +00007951 if (LocaleCompare("morph",option+1) == 0)
7952 {
7953 Image
7954 *morph_image;
7955
cristy6b3da3a2010-06-20 02:21:46 +00007956 (void) SyncImagesSettings(mogrify_info,*images);
cristye27293e2009-12-18 02:53:20 +00007957 morph_image=MorphImages(*images,StringToUnsignedLong(argv[i+1]),
cristy3ed852e2009-09-05 21:47:34 +00007958 exception);
7959 if (morph_image == (Image *) NULL)
7960 {
7961 status=MagickFalse;
7962 break;
7963 }
7964 *images=DestroyImageList(*images);
7965 *images=morph_image;
7966 break;
7967 }
7968 if (LocaleCompare("mosaic",option+1) == 0)
7969 {
7970 Image
7971 *mosaic_image;
7972
cristy6b3da3a2010-06-20 02:21:46 +00007973 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007974 mosaic_image=MergeImageLayers(*images,MosaicLayer,exception);
7975 if (mosaic_image == (Image *) NULL)
7976 {
7977 status=MagickFalse;
7978 break;
7979 }
7980 *images=DestroyImageList(*images);
7981 *images=mosaic_image;
7982 break;
7983 }
7984 break;
7985 }
7986 case 'p':
7987 {
7988 if (LocaleCompare("print",option+1) == 0)
7989 {
7990 char
7991 *string;
7992
cristy6b3da3a2010-06-20 02:21:46 +00007993 (void) SyncImagesSettings(mogrify_info,*images);
7994 string=InterpretImageProperties(mogrify_info,*images,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007995 if (string == (char *) NULL)
7996 break;
7997 InheritException(exception,&(*images)->exception);
cristyb51dff52011-05-19 16:55:47 +00007998 (void) FormatLocaleFile(stdout,"%s",string);
cristy3ed852e2009-09-05 21:47:34 +00007999 string=DestroyString(string);
8000 }
8001 if (LocaleCompare("process",option+1) == 0)
8002 {
8003 char
8004 **arguments;
8005
8006 int
8007 j,
8008 number_arguments;
8009
cristy6b3da3a2010-06-20 02:21:46 +00008010 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00008011 arguments=StringToArgv(argv[i+1],&number_arguments);
8012 if (arguments == (char **) NULL)
8013 break;
8014 if ((argc > 1) && (strchr(arguments[1],'=') != (char *) NULL))
8015 {
8016 char
8017 breaker,
8018 quote,
8019 *token;
8020
8021 const char
8022 *arguments;
8023
8024 int
8025 next,
8026 status;
8027
8028 size_t
8029 length;
8030
8031 TokenInfo
8032 *token_info;
8033
8034 /*
8035 Support old style syntax, filter="-option arg".
8036 */
8037 length=strlen(argv[i+1]);
8038 token=(char *) NULL;
cristy37e0b382011-06-07 13:31:21 +00008039 if (~length >= (MaxTextExtent-1))
cristy3ed852e2009-09-05 21:47:34 +00008040 token=(char *) AcquireQuantumMemory(length+MaxTextExtent,
8041 sizeof(*token));
8042 if (token == (char *) NULL)
8043 break;
8044 next=0;
8045 arguments=argv[i+1];
8046 token_info=AcquireTokenInfo();
8047 status=Tokenizer(token_info,0,token,length,arguments,"","=",
8048 "\"",'\0',&breaker,&next,&quote);
8049 token_info=DestroyTokenInfo(token_info);
8050 if (status == 0)
8051 {
8052 const char
8053 *argv;
8054
8055 argv=(&(arguments[next]));
8056 (void) InvokeDynamicImageFilter(token,&(*images),1,&argv,
8057 exception);
8058 }
8059 token=DestroyString(token);
8060 break;
8061 }
cristy91c0da22010-05-02 01:44:07 +00008062 (void) SubstituteString(&arguments[1],"-","");
cristy3ed852e2009-09-05 21:47:34 +00008063 (void) InvokeDynamicImageFilter(arguments[1],&(*images),
8064 number_arguments-2,(const char **) arguments+2,exception);
8065 for (j=0; j < number_arguments; j++)
8066 arguments[j]=DestroyString(arguments[j]);
8067 arguments=(char **) RelinquishMagickMemory(arguments);
8068 break;
8069 }
8070 break;
8071 }
8072 case 'r':
8073 {
8074 if (LocaleCompare("reverse",option+1) == 0)
8075 {
8076 ReverseImageList(images);
8077 InheritException(exception,&(*images)->exception);
8078 break;
8079 }
8080 break;
8081 }
8082 case 's':
8083 {
cristy4285d782011-02-09 20:12:28 +00008084 if (LocaleCompare("smush",option+1) == 0)
8085 {
8086 Image
8087 *smush_image;
8088
8089 ssize_t
8090 offset;
8091
8092 (void) SyncImagesSettings(mogrify_info,*images);
8093 offset=(ssize_t) StringToLong(argv[i+1]);
8094 smush_image=SmushImages(*images,*option == '-' ? MagickTrue :
8095 MagickFalse,offset,exception);
8096 if (smush_image == (Image *) NULL)
8097 {
8098 status=MagickFalse;
8099 break;
8100 }
8101 *images=DestroyImageList(*images);
8102 *images=smush_image;
8103 break;
8104 }
cristy3ed852e2009-09-05 21:47:34 +00008105 if (LocaleCompare("swap",option+1) == 0)
8106 {
8107 Image
8108 *p,
8109 *q,
8110 *swap;
8111
cristybb503372010-05-27 20:51:26 +00008112 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00008113 swap_index;
8114
8115 index=(-1);
8116 swap_index=(-2);
8117 if (*option != '+')
8118 {
8119 GeometryInfo
8120 geometry_info;
8121
8122 MagickStatusType
8123 flags;
8124
8125 swap_index=(-1);
8126 flags=ParseGeometry(argv[i+1],&geometry_info);
cristybb503372010-05-27 20:51:26 +00008127 index=(ssize_t) geometry_info.rho;
cristy3ed852e2009-09-05 21:47:34 +00008128 if ((flags & SigmaValue) != 0)
cristybb503372010-05-27 20:51:26 +00008129 swap_index=(ssize_t) geometry_info.sigma;
cristy3ed852e2009-09-05 21:47:34 +00008130 }
8131 p=GetImageFromList(*images,index);
8132 q=GetImageFromList(*images,swap_index);
8133 if ((p == (Image *) NULL) || (q == (Image *) NULL))
8134 {
8135 (void) ThrowMagickException(exception,GetMagickModule(),
8136 OptionError,"NoSuchImage","`%s'",(*images)->filename);
8137 status=MagickFalse;
8138 break;
8139 }
8140 if (p == q)
8141 break;
8142 swap=CloneImage(p,0,0,MagickTrue,exception);
8143 ReplaceImageInList(&p,CloneImage(q,0,0,MagickTrue,exception));
8144 ReplaceImageInList(&q,swap);
8145 *images=GetFirstImageInList(q);
8146 break;
8147 }
8148 break;
8149 }
8150 case 'w':
8151 {
8152 if (LocaleCompare("write",option+1) == 0)
8153 {
cristy071dd7b2010-04-09 13:04:54 +00008154 char
cristy06609ee2010-03-17 20:21:27 +00008155 key[MaxTextExtent];
8156
cristy3ed852e2009-09-05 21:47:34 +00008157 Image
8158 *write_images;
8159
8160 ImageInfo
8161 *write_info;
8162
cristy6b3da3a2010-06-20 02:21:46 +00008163 (void) SyncImagesSettings(mogrify_info,*images);
cristyb51dff52011-05-19 16:55:47 +00008164 (void) FormatLocaleString(key,MaxTextExtent,"cache:%s",argv[i+1]);
cristy06609ee2010-03-17 20:21:27 +00008165 (void) DeleteImageRegistry(key);
cristy3ed852e2009-09-05 21:47:34 +00008166 write_images=(*images);
8167 if (*option == '+')
8168 write_images=CloneImageList(*images,exception);
cristy6b3da3a2010-06-20 02:21:46 +00008169 write_info=CloneImageInfo(mogrify_info);
cristy3ed852e2009-09-05 21:47:34 +00008170 status&=WriteImages(write_info,write_images,argv[i+1],exception);
8171 write_info=DestroyImageInfo(write_info);
8172 if (*option == '+')
8173 write_images=DestroyImageList(write_images);
8174 break;
8175 }
8176 break;
8177 }
8178 default:
8179 break;
8180 }
8181 i+=count;
8182 }
8183 quantize_info=DestroyQuantizeInfo(quantize_info);
cristy6b3da3a2010-06-20 02:21:46 +00008184 mogrify_info=DestroyImageInfo(mogrify_info);
8185 status&=MogrifyImageInfo(image_info,argc,argv,exception);
cristy3ed852e2009-09-05 21:47:34 +00008186 return(status != 0 ? MagickTrue : MagickFalse);
8187}
8188
8189/*
8190%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8191% %
8192% %
8193% %
8194+ M o g r i f y I m a g e s %
8195% %
8196% %
8197% %
8198%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8199%
8200% MogrifyImages() applies image processing options to a sequence of images as
8201% prescribed by command line options.
8202%
8203% The format of the MogrifyImage method is:
8204%
8205% MagickBooleanType MogrifyImages(ImageInfo *image_info,
8206% const MagickBooleanType post,const int argc,const char **argv,
8207% Image **images,Exceptioninfo *exception)
8208%
8209% A description of each parameter follows:
8210%
8211% o image_info: the image info..
8212%
8213% o post: If true, post process image list operators otherwise pre-process.
8214%
8215% o argc: Specifies a pointer to an integer describing the number of
8216% elements in the argument vector.
8217%
8218% o argv: Specifies a pointer to a text array containing the command line
8219% arguments.
8220%
anthonye9c27192011-03-27 08:07:06 +00008221% o images: pointer to a pointer of the first image in image list.
cristy3ed852e2009-09-05 21:47:34 +00008222%
8223% o exception: return any errors or warnings in this structure.
8224%
8225*/
8226WandExport MagickBooleanType MogrifyImages(ImageInfo *image_info,
8227 const MagickBooleanType post,const int argc,const char **argv,
8228 Image **images,ExceptionInfo *exception)
8229{
8230#define MogrifyImageTag "Mogrify/Image"
8231
anthonye9c27192011-03-27 08:07:06 +00008232 MagickStatusType
8233 status;
cristy3ed852e2009-09-05 21:47:34 +00008234
cristy0e9f9c12010-02-11 03:00:47 +00008235 MagickBooleanType
8236 proceed;
8237
anthonye9c27192011-03-27 08:07:06 +00008238 size_t
8239 n;
cristy3ed852e2009-09-05 21:47:34 +00008240
cristybb503372010-05-27 20:51:26 +00008241 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00008242 i;
8243
cristy3ed852e2009-09-05 21:47:34 +00008244 assert(image_info != (ImageInfo *) NULL);
8245 assert(image_info->signature == MagickSignature);
8246 if (images == (Image **) NULL)
8247 return(MogrifyImage(image_info,argc,argv,images,exception));
anthonye9c27192011-03-27 08:07:06 +00008248 assert((*images)->previous == (Image *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00008249 assert((*images)->signature == MagickSignature);
8250 if ((*images)->debug != MagickFalse)
8251 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
8252 (*images)->filename);
8253 if ((argc <= 0) || (*argv == (char *) NULL))
8254 return(MagickTrue);
8255 (void) SetImageInfoProgressMonitor(image_info,(MagickProgressMonitor) NULL,
8256 (void *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00008257 status=0;
anthonye9c27192011-03-27 08:07:06 +00008258
anthonyce2716b2011-04-22 09:51:34 +00008259#if 0
cristy1e604812011-05-19 18:07:50 +00008260 (void) FormatLocaleFile(stderr, "mogrify start %s %d (%s)\n",argv[0],argc,
8261 post?"post":"pre");
anthonyce2716b2011-04-22 09:51:34 +00008262#endif
8263
anthonye9c27192011-03-27 08:07:06 +00008264 /*
8265 Pre-process multi-image sequence operators
8266 */
cristy3ed852e2009-09-05 21:47:34 +00008267 if (post == MagickFalse)
8268 status&=MogrifyImageList(image_info,argc,argv,images,exception);
anthonye9c27192011-03-27 08:07:06 +00008269 /*
8270 For each image, process simple single image operators
8271 */
8272 i=0;
8273 n=GetImageListLength(*images);
8274 for (;;)
cristy3ed852e2009-09-05 21:47:34 +00008275 {
anthonyce2716b2011-04-22 09:51:34 +00008276#if 0
cristy1e604812011-05-19 18:07:50 +00008277 (void) FormatLocaleFile(stderr,"mogrify %ld of %ld\n",(long)
8278 GetImageIndexInList(*images),(long)GetImageListLength(*images));
anthonyce2716b2011-04-22 09:51:34 +00008279#endif
anthonye9c27192011-03-27 08:07:06 +00008280 status&=MogrifyImage(image_info,argc,argv,images,exception);
8281 proceed=SetImageProgress(*images,MogrifyImageTag,(MagickOffsetType) i, n);
cristy0e9f9c12010-02-11 03:00:47 +00008282 if (proceed == MagickFalse)
8283 break;
anthonye9c27192011-03-27 08:07:06 +00008284 if ( (*images)->next == (Image *) NULL )
8285 break;
8286 *images=(*images)->next;
8287 i++;
cristy3ed852e2009-09-05 21:47:34 +00008288 }
anthonye9c27192011-03-27 08:07:06 +00008289 assert( *images != (Image *) NULL );
anthonyce2716b2011-04-22 09:51:34 +00008290#if 0
cristy1e604812011-05-19 18:07:50 +00008291 (void) FormatLocaleFile(stderr,"mogrify end %ld of %ld\n",(long)
8292 GetImageIndexInList(*images),(long)GetImageListLength(*images));
anthonyce2716b2011-04-22 09:51:34 +00008293#endif
anthonye9c27192011-03-27 08:07:06 +00008294
8295 /*
8296 Post-process, multi-image sequence operators
8297 */
8298 *images=GetFirstImageInList(*images);
cristy3ed852e2009-09-05 21:47:34 +00008299 if (post != MagickFalse)
anthonye9c27192011-03-27 08:07:06 +00008300 status&=MogrifyImageList(image_info,argc,argv,images,exception);
cristy3ed852e2009-09-05 21:47:34 +00008301 return(status != 0 ? MagickTrue : MagickFalse);
8302}