blob: 5c83795c7857e13787cc30220a16aaa8f2102510 [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;
cristyf4ad9df2011-07-08 16:49:03 +0000698 mogrify_image=AdaptiveBlurImage(*image,geometry_info.rho,
699 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000700 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;
cristyf4ad9df2011-07-08 16:49:03 +0000722 mogrify_image=AdaptiveSharpenImage(*image,geometry_info.rho,
723 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000724 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);
cristyf4ad9df2011-07-08 16:49:03 +0000869 (void) BlackThresholdImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +0000870 InheritException(exception,&(*image)->exception);
871 break;
872 }
873 if (LocaleCompare("blue-shift",option+1) == 0)
874 {
875 /*
876 Blue shift image.
877 */
878 (void) SyncImageSettings(mogrify_info,*image);
879 geometry_info.rho=1.5;
880 if (*option == '-')
881 flags=ParseGeometry(argv[i+1],&geometry_info);
882 mogrify_image=BlueShiftImage(*image,geometry_info.rho,exception);
883 break;
884 }
885 if (LocaleCompare("blur",option+1) == 0)
886 {
887 /*
888 Gaussian blur image.
889 */
890 (void) SyncImageSettings(mogrify_info,*image);
891 flags=ParseGeometry(argv[i+1],&geometry_info);
892 if ((flags & SigmaValue) == 0)
893 geometry_info.sigma=1.0;
cristyf4ad9df2011-07-08 16:49:03 +0000894 mogrify_image=BlurImage(*image,geometry_info.rho,
anthonydf8ebac2011-04-27 09:03:19 +0000895 geometry_info.sigma,exception);
896 break;
897 }
898 if (LocaleCompare("border",option+1) == 0)
899 {
900 /*
901 Surround image with a border of solid color.
902 */
903 (void) SyncImageSettings(mogrify_info,*image);
904 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
905 if ((flags & SigmaValue) == 0)
906 geometry.height=geometry.width;
907 mogrify_image=BorderImage(*image,&geometry,exception);
908 break;
909 }
910 if (LocaleCompare("bordercolor",option+1) == 0)
911 {
912 if (*option == '+')
913 {
914 (void) QueryColorDatabase(BorderColor,&draw_info->border_color,
915 exception);
916 break;
917 }
918 (void) QueryColorDatabase(argv[i+1],&draw_info->border_color,
919 exception);
920 break;
921 }
922 if (LocaleCompare("box",option+1) == 0)
923 {
924 (void) QueryColorDatabase(argv[i+1],&draw_info->undercolor,
925 exception);
926 break;
927 }
928 if (LocaleCompare("brightness-contrast",option+1) == 0)
929 {
930 double
931 brightness,
932 contrast;
933
934 GeometryInfo
935 geometry_info;
936
937 MagickStatusType
938 flags;
939
940 /*
941 Brightness / contrast image.
942 */
943 (void) SyncImageSettings(mogrify_info,*image);
944 flags=ParseGeometry(argv[i+1],&geometry_info);
945 brightness=geometry_info.rho;
946 contrast=0.0;
947 if ((flags & SigmaValue) != 0)
948 contrast=geometry_info.sigma;
cristy9ee60942011-07-06 14:54:38 +0000949 (void) BrightnessContrastImage(*image,brightness,contrast);
anthonydf8ebac2011-04-27 09:03:19 +0000950 InheritException(exception,&(*image)->exception);
951 break;
952 }
953 break;
954 }
955 case 'c':
956 {
957 if (LocaleCompare("cdl",option+1) == 0)
958 {
959 char
960 *color_correction_collection;
961
962 /*
963 Color correct with a color decision list.
964 */
965 (void) SyncImageSettings(mogrify_info,*image);
966 color_correction_collection=FileToString(argv[i+1],~0,exception);
967 if (color_correction_collection == (char *) NULL)
968 break;
969 (void) ColorDecisionListImage(*image,color_correction_collection);
970 InheritException(exception,&(*image)->exception);
971 break;
972 }
973 if (LocaleCompare("channel",option+1) == 0)
974 {
975 if (*option == '+')
cristyfa806a72011-07-04 02:06:13 +0000976 channel=DefaultChannels;
anthonydf8ebac2011-04-27 09:03:19 +0000977 else
cristyfa806a72011-07-04 02:06:13 +0000978 channel=(ChannelType) ParseChannelOption(argv[i+1]);
cristy8a9106f2011-07-05 14:39:26 +0000979 SetPixelComponentMap(*image,channel);
anthonydf8ebac2011-04-27 09:03:19 +0000980 break;
981 }
982 if (LocaleCompare("charcoal",option+1) == 0)
983 {
984 /*
985 Charcoal image.
986 */
987 (void) SyncImageSettings(mogrify_info,*image);
988 flags=ParseGeometry(argv[i+1],&geometry_info);
989 if ((flags & SigmaValue) == 0)
990 geometry_info.sigma=1.0;
991 mogrify_image=CharcoalImage(*image,geometry_info.rho,
992 geometry_info.sigma,exception);
993 break;
994 }
995 if (LocaleCompare("chop",option+1) == 0)
996 {
997 /*
998 Chop the image.
999 */
1000 (void) SyncImageSettings(mogrify_info,*image);
1001 (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1002 mogrify_image=ChopImage(*image,&geometry,exception);
1003 break;
1004 }
1005 if (LocaleCompare("clamp",option+1) == 0)
1006 {
1007 /*
1008 Clamp image.
1009 */
1010 (void) SyncImageSettings(mogrify_info,*image);
cristyf4ad9df2011-07-08 16:49:03 +00001011 (void) ClampImage(*image);
anthonydf8ebac2011-04-27 09:03:19 +00001012 InheritException(exception,&(*image)->exception);
1013 break;
1014 }
1015 if (LocaleCompare("clip",option+1) == 0)
1016 {
1017 (void) SyncImageSettings(mogrify_info,*image);
1018 if (*option == '+')
1019 {
1020 (void) SetImageClipMask(*image,(Image *) NULL);
1021 InheritException(exception,&(*image)->exception);
1022 break;
1023 }
1024 (void) ClipImage(*image);
1025 InheritException(exception,&(*image)->exception);
1026 break;
1027 }
1028 if (LocaleCompare("clip-mask",option+1) == 0)
1029 {
1030 CacheView
1031 *mask_view;
1032
1033 Image
1034 *mask_image;
1035
cristy4c08aed2011-07-01 19:47:50 +00001036 register Quantum
anthonydf8ebac2011-04-27 09:03:19 +00001037 *restrict q;
1038
1039 register ssize_t
1040 x;
1041
1042 ssize_t
1043 y;
1044
1045 (void) SyncImageSettings(mogrify_info,*image);
1046 if (*option == '+')
1047 {
1048 /*
1049 Remove a mask.
1050 */
1051 (void) SetImageMask(*image,(Image *) NULL);
1052 InheritException(exception,&(*image)->exception);
1053 break;
1054 }
1055 /*
1056 Set the image mask.
1057 FUTURE: This Should Be a SetImageAlphaChannel() call, Or two.
1058 */
1059 mask_image=GetImageCache(mogrify_info,argv[i+1],exception);
1060 if (mask_image == (Image *) NULL)
1061 break;
1062 if (SetImageStorageClass(mask_image,DirectClass) == MagickFalse)
1063 return(MagickFalse);
1064 mask_view=AcquireCacheView(mask_image);
1065 for (y=0; y < (ssize_t) mask_image->rows; y++)
1066 {
1067 q=GetCacheViewAuthenticPixels(mask_view,0,y,mask_image->columns,1,
1068 exception);
cristy4c08aed2011-07-01 19:47:50 +00001069 if (q == (const Quantum *) NULL)
anthonydf8ebac2011-04-27 09:03:19 +00001070 break;
1071 for (x=0; x < (ssize_t) mask_image->columns; x++)
1072 {
1073 if (mask_image->matte == MagickFalse)
cristy4c08aed2011-07-01 19:47:50 +00001074 SetPixelAlpha(mask_image,GetPixelIntensity(mask_image,q),q);
1075 SetPixelRed(mask_image,GetPixelAlpha(mask_image,q),q);
1076 SetPixelGreen(mask_image,GetPixelAlpha(mask_image,q),q);
1077 SetPixelBlue(mask_image,GetPixelAlpha(mask_image,q),q);
cristydcfc1ad2011-07-07 16:25:41 +00001078 q+=GetPixelComponents(mask_image);
anthonydf8ebac2011-04-27 09:03:19 +00001079 }
1080 if (SyncCacheViewAuthenticPixels(mask_view,exception) == MagickFalse)
1081 break;
1082 }
1083 mask_view=DestroyCacheView(mask_view);
1084 mask_image->matte=MagickTrue;
1085 (void) SetImageClipMask(*image,mask_image);
1086 mask_image=DestroyImage(mask_image);
1087 InheritException(exception,&(*image)->exception);
1088 break;
1089 }
1090 if (LocaleCompare("clip-path",option+1) == 0)
1091 {
1092 (void) SyncImageSettings(mogrify_info,*image);
1093 (void) ClipImagePath(*image,argv[i+1],*option == '-' ? MagickTrue :
1094 MagickFalse);
1095 InheritException(exception,&(*image)->exception);
1096 break;
1097 }
1098 if (LocaleCompare("colorize",option+1) == 0)
1099 {
1100 /*
1101 Colorize the image.
1102 */
1103 (void) SyncImageSettings(mogrify_info,*image);
1104 mogrify_image=ColorizeImage(*image,argv[i+1],draw_info->fill,
1105 exception);
1106 break;
1107 }
1108 if (LocaleCompare("color-matrix",option+1) == 0)
1109 {
1110 KernelInfo
1111 *kernel;
1112
1113 (void) SyncImageSettings(mogrify_info,*image);
1114 kernel=AcquireKernelInfo(argv[i+1]);
1115 if (kernel == (KernelInfo *) NULL)
1116 break;
1117 mogrify_image=ColorMatrixImage(*image,kernel,exception);
1118 kernel=DestroyKernelInfo(kernel);
1119 break;
1120 }
1121 if (LocaleCompare("colors",option+1) == 0)
1122 {
1123 /*
1124 Reduce the number of colors in the image.
1125 */
1126 (void) SyncImageSettings(mogrify_info,*image);
1127 quantize_info->number_colors=StringToUnsignedLong(argv[i+1]);
1128 if (quantize_info->number_colors == 0)
1129 break;
1130 if (((*image)->storage_class == DirectClass) ||
1131 (*image)->colors > quantize_info->number_colors)
1132 (void) QuantizeImage(quantize_info,*image);
1133 else
1134 (void) CompressImageColormap(*image);
1135 InheritException(exception,&(*image)->exception);
1136 break;
1137 }
1138 if (LocaleCompare("colorspace",option+1) == 0)
1139 {
1140 ColorspaceType
1141 colorspace;
1142
1143 (void) SyncImageSettings(mogrify_info,*image);
1144 if (*option == '+')
1145 {
1146 (void) TransformImageColorspace(*image,RGBColorspace);
1147 InheritException(exception,&(*image)->exception);
1148 break;
1149 }
1150 colorspace=(ColorspaceType) ParseCommandOption(
1151 MagickColorspaceOptions,MagickFalse,argv[i+1]);
1152 (void) TransformImageColorspace(*image,colorspace);
1153 InheritException(exception,&(*image)->exception);
1154 break;
1155 }
1156 if (LocaleCompare("contrast",option+1) == 0)
1157 {
1158 (void) SyncImageSettings(mogrify_info,*image);
1159 (void) ContrastImage(*image,(*option == '-') ? MagickTrue :
1160 MagickFalse);
1161 InheritException(exception,&(*image)->exception);
1162 break;
1163 }
1164 if (LocaleCompare("contrast-stretch",option+1) == 0)
1165 {
1166 double
1167 black_point,
1168 white_point;
1169
1170 MagickStatusType
1171 flags;
1172
1173 /*
1174 Contrast stretch image.
1175 */
1176 (void) SyncImageSettings(mogrify_info,*image);
1177 flags=ParseGeometry(argv[i+1],&geometry_info);
1178 black_point=geometry_info.rho;
1179 white_point=(flags & SigmaValue) != 0 ? geometry_info.sigma :
1180 black_point;
1181 if ((flags & PercentValue) != 0)
1182 {
1183 black_point*=(double) (*image)->columns*(*image)->rows/100.0;
1184 white_point*=(double) (*image)->columns*(*image)->rows/100.0;
1185 }
1186 white_point=(MagickRealType) (*image)->columns*(*image)->rows-
1187 white_point;
cristy50fbc382011-07-07 02:19:17 +00001188 (void) ContrastStretchImage(*image,black_point,white_point);
anthonydf8ebac2011-04-27 09:03:19 +00001189 InheritException(exception,&(*image)->exception);
1190 break;
1191 }
1192 if (LocaleCompare("convolve",option+1) == 0)
1193 {
1194 double
1195 gamma;
1196
1197 KernelInfo
1198 *kernel;
1199
1200 register ssize_t
1201 j;
1202
1203 (void) SyncImageSettings(mogrify_info,*image);
1204 kernel=AcquireKernelInfo(argv[i+1]);
1205 if (kernel == (KernelInfo *) NULL)
1206 break;
1207 gamma=0.0;
1208 for (j=0; j < (ssize_t) (kernel->width*kernel->height); j++)
1209 gamma+=kernel->values[j];
1210 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
1211 for (j=0; j < (ssize_t) (kernel->width*kernel->height); j++)
1212 kernel->values[j]*=gamma;
cristyf4ad9df2011-07-08 16:49:03 +00001213 mogrify_image=FilterImage(*image,kernel,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001214 kernel=DestroyKernelInfo(kernel);
1215 break;
1216 }
1217 if (LocaleCompare("crop",option+1) == 0)
1218 {
1219 /*
1220 Crop a image to a smaller size
1221 */
1222 (void) SyncImageSettings(mogrify_info,*image);
1223#if 0
1224 flags=ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1225 if (((geometry.width != 0) || (geometry.height != 0)) &&
1226 ((flags & XValue) == 0) && ((flags & YValue) == 0))
1227 break;
1228#endif
1229#if 0
1230 mogrify_image=CloneImage(*image,0,0,MagickTrue,&(*image)->exception);
1231 mogrify_image->next = mogrify_image->previous = (Image *)NULL;
1232 (void) TransformImage(&mogrify_image,argv[i+1],(char *) NULL);
1233 InheritException(exception,&mogrify_image->exception);
1234#else
1235 mogrify_image=CropImageToTiles(*image,argv[i+1],exception);
1236#endif
1237 break;
1238 }
1239 if (LocaleCompare("cycle",option+1) == 0)
1240 {
1241 /*
1242 Cycle an image colormap.
1243 */
1244 (void) SyncImageSettings(mogrify_info,*image);
1245 (void) CycleColormapImage(*image,(ssize_t) StringToLong(argv[i+1]));
1246 InheritException(exception,&(*image)->exception);
1247 break;
1248 }
1249 break;
1250 }
1251 case 'd':
1252 {
1253 if (LocaleCompare("decipher",option+1) == 0)
1254 {
1255 StringInfo
1256 *passkey;
1257
1258 /*
1259 Decipher pixels.
1260 */
1261 (void) SyncImageSettings(mogrify_info,*image);
1262 passkey=FileToStringInfo(argv[i+1],~0,exception);
1263 if (passkey != (StringInfo *) NULL)
1264 {
1265 (void) PasskeyDecipherImage(*image,passkey,exception);
1266 passkey=DestroyStringInfo(passkey);
1267 }
1268 break;
1269 }
1270 if (LocaleCompare("density",option+1) == 0)
1271 {
1272 /*
1273 Set image density.
1274 */
1275 (void) CloneString(&draw_info->density,argv[i+1]);
1276 break;
1277 }
1278 if (LocaleCompare("depth",option+1) == 0)
1279 {
1280 (void) SyncImageSettings(mogrify_info,*image);
1281 if (*option == '+')
1282 {
1283 (void) SetImageDepth(*image,MAGICKCORE_QUANTUM_DEPTH);
1284 break;
1285 }
1286 (void) SetImageDepth(*image,StringToUnsignedLong(argv[i+1]));
1287 break;
1288 }
1289 if (LocaleCompare("deskew",option+1) == 0)
1290 {
1291 double
1292 threshold;
1293
1294 /*
1295 Straighten the image.
1296 */
1297 (void) SyncImageSettings(mogrify_info,*image);
1298 if (*option == '+')
1299 threshold=40.0*QuantumRange/100.0;
1300 else
1301 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
1302 mogrify_image=DeskewImage(*image,threshold,exception);
1303 break;
1304 }
1305 if (LocaleCompare("despeckle",option+1) == 0)
1306 {
1307 /*
1308 Reduce the speckles within an image.
1309 */
1310 (void) SyncImageSettings(mogrify_info,*image);
1311 mogrify_image=DespeckleImage(*image,exception);
1312 break;
1313 }
1314 if (LocaleCompare("display",option+1) == 0)
1315 {
1316 (void) CloneString(&draw_info->server_name,argv[i+1]);
1317 break;
1318 }
1319 if (LocaleCompare("distort",option+1) == 0)
1320 {
1321 char
1322 *args,
1323 token[MaxTextExtent];
1324
1325 const char
1326 *p;
1327
1328 DistortImageMethod
1329 method;
1330
1331 double
1332 *arguments;
1333
1334 register ssize_t
1335 x;
1336
1337 size_t
1338 number_arguments;
1339
1340 /*
1341 Distort image.
1342 */
1343 (void) SyncImageSettings(mogrify_info,*image);
1344 method=(DistortImageMethod) ParseCommandOption(MagickDistortOptions,
1345 MagickFalse,argv[i+1]);
1346 if ( method == ResizeDistortion )
1347 {
1348 /* Special Case - Argument is actually a resize geometry!
1349 ** Convert that to an appropriate distortion argument array.
1350 */
1351 double
1352 resize_args[2];
1353 (void) ParseRegionGeometry(*image,argv[i+2],&geometry,
1354 exception);
1355 resize_args[0]=(double)geometry.width;
1356 resize_args[1]=(double)geometry.height;
1357 mogrify_image=DistortImage(*image,method,(size_t)2,
1358 resize_args,MagickTrue,exception);
1359 break;
1360 }
1361 args=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
1362 InheritException(exception,&(*image)->exception);
1363 if (args == (char *) NULL)
1364 break;
1365 p=(char *) args;
1366 for (x=0; *p != '\0'; x++)
1367 {
1368 GetMagickToken(p,&p,token);
1369 if (*token == ',')
1370 GetMagickToken(p,&p,token);
1371 }
1372 number_arguments=(size_t) x;
1373 arguments=(double *) AcquireQuantumMemory(number_arguments,
1374 sizeof(*arguments));
1375 if (arguments == (double *) NULL)
1376 ThrowWandFatalException(ResourceLimitFatalError,
1377 "MemoryAllocationFailed",(*image)->filename);
1378 (void) ResetMagickMemory(arguments,0,number_arguments*
1379 sizeof(*arguments));
1380 p=(char *) args;
1381 for (x=0; (x < (ssize_t) number_arguments) && (*p != '\0'); x++)
1382 {
1383 GetMagickToken(p,&p,token);
1384 if (*token == ',')
1385 GetMagickToken(p,&p,token);
cristyc1acd842011-05-19 23:05:47 +00001386 arguments[x]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001387 }
1388 args=DestroyString(args);
1389 mogrify_image=DistortImage(*image,method,number_arguments,arguments,
1390 (*option == '+') ? MagickTrue : MagickFalse,exception);
1391 arguments=(double *) RelinquishMagickMemory(arguments);
1392 break;
1393 }
1394 if (LocaleCompare("dither",option+1) == 0)
1395 {
1396 if (*option == '+')
1397 {
1398 quantize_info->dither=MagickFalse;
1399 break;
1400 }
1401 quantize_info->dither=MagickTrue;
1402 quantize_info->dither_method=(DitherMethod) ParseCommandOption(
1403 MagickDitherOptions,MagickFalse,argv[i+1]);
1404 if (quantize_info->dither_method == NoDitherMethod)
1405 quantize_info->dither=MagickFalse;
1406 break;
1407 }
1408 if (LocaleCompare("draw",option+1) == 0)
1409 {
1410 /*
1411 Draw image.
1412 */
1413 (void) SyncImageSettings(mogrify_info,*image);
1414 (void) CloneString(&draw_info->primitive,argv[i+1]);
1415 (void) DrawImage(*image,draw_info);
1416 InheritException(exception,&(*image)->exception);
1417 break;
1418 }
1419 break;
1420 }
1421 case 'e':
1422 {
1423 if (LocaleCompare("edge",option+1) == 0)
1424 {
1425 /*
1426 Enhance edges in the image.
1427 */
1428 (void) SyncImageSettings(mogrify_info,*image);
1429 flags=ParseGeometry(argv[i+1],&geometry_info);
1430 if ((flags & SigmaValue) == 0)
1431 geometry_info.sigma=1.0;
1432 mogrify_image=EdgeImage(*image,geometry_info.rho,exception);
1433 break;
1434 }
1435 if (LocaleCompare("emboss",option+1) == 0)
1436 {
1437 /*
1438 Gaussian embossen image.
1439 */
1440 (void) SyncImageSettings(mogrify_info,*image);
1441 flags=ParseGeometry(argv[i+1],&geometry_info);
1442 if ((flags & SigmaValue) == 0)
1443 geometry_info.sigma=1.0;
1444 mogrify_image=EmbossImage(*image,geometry_info.rho,
1445 geometry_info.sigma,exception);
1446 break;
1447 }
1448 if (LocaleCompare("encipher",option+1) == 0)
1449 {
1450 StringInfo
1451 *passkey;
1452
1453 /*
1454 Encipher pixels.
1455 */
1456 (void) SyncImageSettings(mogrify_info,*image);
1457 passkey=FileToStringInfo(argv[i+1],~0,exception);
1458 if (passkey != (StringInfo *) NULL)
1459 {
1460 (void) PasskeyEncipherImage(*image,passkey,exception);
1461 passkey=DestroyStringInfo(passkey);
1462 }
1463 break;
1464 }
1465 if (LocaleCompare("encoding",option+1) == 0)
1466 {
1467 (void) CloneString(&draw_info->encoding,argv[i+1]);
1468 break;
1469 }
1470 if (LocaleCompare("enhance",option+1) == 0)
1471 {
1472 /*
1473 Enhance image.
1474 */
1475 (void) SyncImageSettings(mogrify_info,*image);
1476 mogrify_image=EnhanceImage(*image,exception);
1477 break;
1478 }
1479 if (LocaleCompare("equalize",option+1) == 0)
1480 {
1481 /*
1482 Equalize image.
1483 */
1484 (void) SyncImageSettings(mogrify_info,*image);
cristy50fbc382011-07-07 02:19:17 +00001485 (void) EqualizeImage(*image);
anthonydf8ebac2011-04-27 09:03:19 +00001486 InheritException(exception,&(*image)->exception);
1487 break;
1488 }
1489 if (LocaleCompare("evaluate",option+1) == 0)
1490 {
1491 double
1492 constant;
1493
1494 MagickEvaluateOperator
1495 op;
1496
1497 (void) SyncImageSettings(mogrify_info,*image);
cristyd42d9952011-07-08 14:21:50 +00001498 op=(MagickEvaluateOperator) ParseCommandOption(
1499 MagickEvaluateOptions,MagickFalse,argv[i+1]);
anthonydf8ebac2011-04-27 09:03:19 +00001500 constant=SiPrefixToDouble(argv[i+2],QuantumRange);
cristyd42d9952011-07-08 14:21:50 +00001501 (void) EvaluateImage(*image,op,constant,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001502 break;
1503 }
1504 if (LocaleCompare("extent",option+1) == 0)
1505 {
1506 /*
1507 Set the image extent.
1508 */
1509 (void) SyncImageSettings(mogrify_info,*image);
1510 flags=ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1511 if (geometry.width == 0)
1512 geometry.width=(*image)->columns;
1513 if (geometry.height == 0)
1514 geometry.height=(*image)->rows;
1515 mogrify_image=ExtentImage(*image,&geometry,exception);
1516 break;
1517 }
1518 break;
1519 }
1520 case 'f':
1521 {
1522 if (LocaleCompare("family",option+1) == 0)
1523 {
1524 if (*option == '+')
1525 {
1526 if (draw_info->family != (char *) NULL)
1527 draw_info->family=DestroyString(draw_info->family);
1528 break;
1529 }
1530 (void) CloneString(&draw_info->family,argv[i+1]);
1531 break;
1532 }
1533 if (LocaleCompare("features",option+1) == 0)
1534 {
1535 if (*option == '+')
1536 {
1537 (void) DeleteImageArtifact(*image,"identify:features");
1538 break;
1539 }
1540 (void) SetImageArtifact(*image,"identify:features",argv[i+1]);
1541 break;
1542 }
1543 if (LocaleCompare("fill",option+1) == 0)
1544 {
1545 ExceptionInfo
1546 *sans;
1547
cristy4c08aed2011-07-01 19:47:50 +00001548 GetPixelInfo(*image,&fill);
anthonydf8ebac2011-04-27 09:03:19 +00001549 if (*option == '+')
1550 {
1551 (void) QueryMagickColor("none",&fill,exception);
1552 (void) QueryColorDatabase("none",&draw_info->fill,exception);
1553 if (draw_info->fill_pattern != (Image *) NULL)
1554 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
1555 break;
1556 }
1557 sans=AcquireExceptionInfo();
1558 (void) QueryMagickColor(argv[i+1],&fill,sans);
1559 status=QueryColorDatabase(argv[i+1],&draw_info->fill,sans);
1560 sans=DestroyExceptionInfo(sans);
1561 if (status == MagickFalse)
1562 draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1],
1563 exception);
1564 break;
1565 }
1566 if (LocaleCompare("flip",option+1) == 0)
1567 {
1568 /*
1569 Flip image scanlines.
1570 */
1571 (void) SyncImageSettings(mogrify_info,*image);
1572 mogrify_image=FlipImage(*image,exception);
1573 break;
1574 }
anthonydf8ebac2011-04-27 09:03:19 +00001575 if (LocaleCompare("floodfill",option+1) == 0)
1576 {
cristy4c08aed2011-07-01 19:47:50 +00001577 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00001578 target;
1579
1580 /*
1581 Floodfill image.
1582 */
1583 (void) SyncImageSettings(mogrify_info,*image);
1584 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
1585 (void) QueryMagickColor(argv[i+2],&target,exception);
cristyd42d9952011-07-08 14:21:50 +00001586 (void) FloodfillPaintImage(*image,draw_info,&target,geometry.x,
1587 geometry.y,*option == '-' ? MagickFalse : MagickTrue);
anthonydf8ebac2011-04-27 09:03:19 +00001588 InheritException(exception,&(*image)->exception);
1589 break;
1590 }
anthony3d2f4862011-05-01 13:48:16 +00001591 if (LocaleCompare("flop",option+1) == 0)
1592 {
1593 /*
1594 Flop image scanlines.
1595 */
1596 (void) SyncImageSettings(mogrify_info,*image);
1597 mogrify_image=FlopImage(*image,exception);
1598 break;
1599 }
anthonydf8ebac2011-04-27 09:03:19 +00001600 if (LocaleCompare("font",option+1) == 0)
1601 {
1602 if (*option == '+')
1603 {
1604 if (draw_info->font != (char *) NULL)
1605 draw_info->font=DestroyString(draw_info->font);
1606 break;
1607 }
1608 (void) CloneString(&draw_info->font,argv[i+1]);
1609 break;
1610 }
1611 if (LocaleCompare("format",option+1) == 0)
1612 {
1613 format=argv[i+1];
1614 break;
1615 }
1616 if (LocaleCompare("frame",option+1) == 0)
1617 {
1618 FrameInfo
1619 frame_info;
1620
1621 /*
1622 Surround image with an ornamental border.
1623 */
1624 (void) SyncImageSettings(mogrify_info,*image);
1625 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
1626 frame_info.width=geometry.width;
1627 frame_info.height=geometry.height;
1628 if ((flags & HeightValue) == 0)
1629 frame_info.height=geometry.width;
1630 frame_info.outer_bevel=geometry.x;
1631 frame_info.inner_bevel=geometry.y;
1632 frame_info.x=(ssize_t) frame_info.width;
1633 frame_info.y=(ssize_t) frame_info.height;
1634 frame_info.width=(*image)->columns+2*frame_info.width;
1635 frame_info.height=(*image)->rows+2*frame_info.height;
1636 mogrify_image=FrameImage(*image,&frame_info,exception);
1637 break;
1638 }
1639 if (LocaleCompare("function",option+1) == 0)
1640 {
1641 char
1642 *arguments,
1643 token[MaxTextExtent];
1644
1645 const char
1646 *p;
1647
1648 double
1649 *parameters;
1650
1651 MagickFunction
1652 function;
1653
1654 register ssize_t
1655 x;
1656
1657 size_t
1658 number_parameters;
1659
1660 /*
1661 Function Modify Image Values
1662 */
1663 (void) SyncImageSettings(mogrify_info,*image);
1664 function=(MagickFunction) ParseCommandOption(MagickFunctionOptions,
1665 MagickFalse,argv[i+1]);
1666 arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
1667 InheritException(exception,&(*image)->exception);
1668 if (arguments == (char *) NULL)
1669 break;
1670 p=(char *) arguments;
1671 for (x=0; *p != '\0'; x++)
1672 {
1673 GetMagickToken(p,&p,token);
1674 if (*token == ',')
1675 GetMagickToken(p,&p,token);
1676 }
1677 number_parameters=(size_t) x;
1678 parameters=(double *) AcquireQuantumMemory(number_parameters,
1679 sizeof(*parameters));
1680 if (parameters == (double *) NULL)
1681 ThrowWandFatalException(ResourceLimitFatalError,
1682 "MemoryAllocationFailed",(*image)->filename);
1683 (void) ResetMagickMemory(parameters,0,number_parameters*
1684 sizeof(*parameters));
1685 p=(char *) arguments;
1686 for (x=0; (x < (ssize_t) number_parameters) && (*p != '\0'); x++)
1687 {
1688 GetMagickToken(p,&p,token);
1689 if (*token == ',')
1690 GetMagickToken(p,&p,token);
cristyc1acd842011-05-19 23:05:47 +00001691 parameters[x]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001692 }
1693 arguments=DestroyString(arguments);
cristyd42d9952011-07-08 14:21:50 +00001694 (void) FunctionImage(*image,function,number_parameters,parameters,
1695 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001696 parameters=(double *) RelinquishMagickMemory(parameters);
1697 break;
1698 }
1699 break;
1700 }
1701 case 'g':
1702 {
1703 if (LocaleCompare("gamma",option+1) == 0)
1704 {
1705 /*
1706 Gamma image.
1707 */
1708 (void) SyncImageSettings(mogrify_info,*image);
1709 if (*option == '+')
cristyc1acd842011-05-19 23:05:47 +00001710 (*image)->gamma=InterpretLocaleValue(argv[i+1],(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001711 else
1712 {
cristy50fbc382011-07-07 02:19:17 +00001713 (void) GammaImage(*image,InterpretLocaleValue(argv[i+1],
1714 (char **) NULL));
anthonydf8ebac2011-04-27 09:03:19 +00001715 InheritException(exception,&(*image)->exception);
1716 }
1717 break;
1718 }
1719 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
1720 (LocaleCompare("gaussian",option+1) == 0))
1721 {
1722 /*
1723 Gaussian blur image.
1724 */
1725 (void) SyncImageSettings(mogrify_info,*image);
1726 flags=ParseGeometry(argv[i+1],&geometry_info);
1727 if ((flags & SigmaValue) == 0)
1728 geometry_info.sigma=1.0;
cristyf4ad9df2011-07-08 16:49:03 +00001729 mogrify_image=GaussianBlurImage(*image,geometry_info.rho,
1730 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001731 break;
1732 }
1733 if (LocaleCompare("geometry",option+1) == 0)
1734 {
1735 /*
1736 Record Image offset, Resize last image.
1737 */
1738 (void) SyncImageSettings(mogrify_info,*image);
1739 if (*option == '+')
1740 {
1741 if ((*image)->geometry != (char *) NULL)
1742 (*image)->geometry=DestroyString((*image)->geometry);
1743 break;
1744 }
1745 flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
1746 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
1747 (void) CloneString(&(*image)->geometry,argv[i+1]);
1748 else
1749 mogrify_image=ResizeImage(*image,geometry.width,geometry.height,
1750 (*image)->filter,(*image)->blur,exception);
1751 break;
1752 }
1753 if (LocaleCompare("gravity",option+1) == 0)
1754 {
1755 if (*option == '+')
1756 {
1757 draw_info->gravity=UndefinedGravity;
1758 break;
1759 }
1760 draw_info->gravity=(GravityType) ParseCommandOption(
1761 MagickGravityOptions,MagickFalse,argv[i+1]);
1762 break;
1763 }
1764 break;
1765 }
1766 case 'h':
1767 {
1768 if (LocaleCompare("highlight-color",option+1) == 0)
1769 {
1770 (void) SetImageArtifact(*image,option+1,argv[i+1]);
1771 break;
1772 }
1773 break;
1774 }
1775 case 'i':
1776 {
1777 if (LocaleCompare("identify",option+1) == 0)
1778 {
1779 char
1780 *text;
1781
1782 (void) SyncImageSettings(mogrify_info,*image);
1783 if (format == (char *) NULL)
1784 {
1785 (void) IdentifyImage(*image,stdout,mogrify_info->verbose);
1786 InheritException(exception,&(*image)->exception);
1787 break;
1788 }
1789 text=InterpretImageProperties(mogrify_info,*image,format);
1790 InheritException(exception,&(*image)->exception);
1791 if (text == (char *) NULL)
1792 break;
1793 (void) fputs(text,stdout);
1794 (void) fputc('\n',stdout);
1795 text=DestroyString(text);
1796 break;
1797 }
1798 if (LocaleCompare("implode",option+1) == 0)
1799 {
1800 /*
1801 Implode image.
1802 */
1803 (void) SyncImageSettings(mogrify_info,*image);
1804 (void) ParseGeometry(argv[i+1],&geometry_info);
1805 mogrify_image=ImplodeImage(*image,geometry_info.rho,exception);
1806 break;
1807 }
1808 if (LocaleCompare("interline-spacing",option+1) == 0)
1809 {
1810 if (*option == '+')
1811 (void) ParseGeometry("0",&geometry_info);
1812 else
1813 (void) ParseGeometry(argv[i+1],&geometry_info);
1814 draw_info->interline_spacing=geometry_info.rho;
1815 break;
1816 }
1817 if (LocaleCompare("interword-spacing",option+1) == 0)
1818 {
1819 if (*option == '+')
1820 (void) ParseGeometry("0",&geometry_info);
1821 else
1822 (void) ParseGeometry(argv[i+1],&geometry_info);
1823 draw_info->interword_spacing=geometry_info.rho;
1824 break;
1825 }
1826 break;
1827 }
1828 case 'k':
1829 {
1830 if (LocaleCompare("kerning",option+1) == 0)
1831 {
1832 if (*option == '+')
1833 (void) ParseGeometry("0",&geometry_info);
1834 else
1835 (void) ParseGeometry(argv[i+1],&geometry_info);
1836 draw_info->kerning=geometry_info.rho;
1837 break;
1838 }
1839 break;
1840 }
1841 case 'l':
1842 {
1843 if (LocaleCompare("lat",option+1) == 0)
1844 {
1845 /*
1846 Local adaptive threshold image.
1847 */
1848 (void) SyncImageSettings(mogrify_info,*image);
1849 flags=ParseGeometry(argv[i+1],&geometry_info);
1850 if ((flags & PercentValue) != 0)
1851 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
1852 mogrify_image=AdaptiveThresholdImage(*image,(size_t)
1853 geometry_info.rho,(size_t) geometry_info.sigma,(ssize_t)
1854 geometry_info.xi,exception);
1855 break;
1856 }
1857 if (LocaleCompare("level",option+1) == 0)
1858 {
1859 MagickRealType
1860 black_point,
1861 gamma,
1862 white_point;
1863
1864 MagickStatusType
1865 flags;
1866
1867 /*
1868 Parse levels.
1869 */
1870 (void) SyncImageSettings(mogrify_info,*image);
1871 flags=ParseGeometry(argv[i+1],&geometry_info);
1872 black_point=geometry_info.rho;
1873 white_point=(MagickRealType) QuantumRange;
1874 if ((flags & SigmaValue) != 0)
1875 white_point=geometry_info.sigma;
1876 gamma=1.0;
1877 if ((flags & XiValue) != 0)
1878 gamma=geometry_info.xi;
1879 if ((flags & PercentValue) != 0)
1880 {
1881 black_point*=(MagickRealType) (QuantumRange/100.0);
1882 white_point*=(MagickRealType) (QuantumRange/100.0);
1883 }
1884 if ((flags & SigmaValue) == 0)
1885 white_point=(MagickRealType) QuantumRange-black_point;
1886 if ((*option == '+') || ((flags & AspectValue) != 0))
cristy50fbc382011-07-07 02:19:17 +00001887 (void) LevelizeImage(*image,black_point,white_point,gamma);
anthonydf8ebac2011-04-27 09:03:19 +00001888 else
cristyf89cb1d2011-07-07 01:24:37 +00001889 (void) LevelImage(*image,black_point,white_point,gamma);
anthonydf8ebac2011-04-27 09:03:19 +00001890 InheritException(exception,&(*image)->exception);
1891 break;
1892 }
1893 if (LocaleCompare("level-colors",option+1) == 0)
1894 {
1895 char
1896 token[MaxTextExtent];
1897
1898 const char
1899 *p;
1900
cristy4c08aed2011-07-01 19:47:50 +00001901 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00001902 black_point,
1903 white_point;
1904
1905 p=(const char *) argv[i+1];
1906 GetMagickToken(p,&p,token); /* get black point color */
1907 if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
1908 (void) QueryMagickColor(token,&black_point,exception);
1909 else
1910 (void) QueryMagickColor("#000000",&black_point,exception);
1911 if (isalpha((int) token[0]) || (token[0] == '#'))
1912 GetMagickToken(p,&p,token);
1913 if (*token == '\0')
1914 white_point=black_point; /* set everything to that color */
1915 else
1916 {
1917 if ((isalpha((int) *token) == 0) && ((*token == '#') == 0))
1918 GetMagickToken(p,&p,token); /* Get white point color. */
1919 if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
1920 (void) QueryMagickColor(token,&white_point,exception);
1921 else
1922 (void) QueryMagickColor("#ffffff",&white_point,exception);
1923 }
cristy490408a2011-07-07 14:42:05 +00001924 (void) LevelImageColors(*image,&black_point,&white_point,
1925 *option == '+' ? MagickTrue : MagickFalse);
anthonydf8ebac2011-04-27 09:03:19 +00001926 break;
1927 }
1928 if (LocaleCompare("linear-stretch",option+1) == 0)
1929 {
1930 double
1931 black_point,
1932 white_point;
1933
1934 MagickStatusType
1935 flags;
1936
1937 (void) SyncImageSettings(mogrify_info,*image);
1938 flags=ParseGeometry(argv[i+1],&geometry_info);
1939 black_point=geometry_info.rho;
1940 white_point=(MagickRealType) (*image)->columns*(*image)->rows;
1941 if ((flags & SigmaValue) != 0)
1942 white_point=geometry_info.sigma;
1943 if ((flags & PercentValue) != 0)
1944 {
1945 black_point*=(double) (*image)->columns*(*image)->rows/100.0;
1946 white_point*=(double) (*image)->columns*(*image)->rows/100.0;
1947 }
1948 if ((flags & SigmaValue) == 0)
1949 white_point=(MagickRealType) (*image)->columns*(*image)->rows-
1950 black_point;
1951 (void) LinearStretchImage(*image,black_point,white_point);
1952 InheritException(exception,&(*image)->exception);
1953 break;
1954 }
1955 if (LocaleCompare("linewidth",option+1) == 0)
1956 {
cristyc1acd842011-05-19 23:05:47 +00001957 draw_info->stroke_width=InterpretLocaleValue(argv[i+1],
1958 (char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001959 break;
1960 }
1961 if (LocaleCompare("liquid-rescale",option+1) == 0)
1962 {
1963 /*
1964 Liquid rescale image.
1965 */
1966 (void) SyncImageSettings(mogrify_info,*image);
1967 flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
1968 if ((flags & XValue) == 0)
1969 geometry.x=1;
1970 if ((flags & YValue) == 0)
1971 geometry.y=0;
1972 mogrify_image=LiquidRescaleImage(*image,geometry.width,
1973 geometry.height,1.0*geometry.x,1.0*geometry.y,exception);
1974 break;
1975 }
1976 if (LocaleCompare("lowlight-color",option+1) == 0)
1977 {
1978 (void) SetImageArtifact(*image,option+1,argv[i+1]);
1979 break;
1980 }
1981 break;
1982 }
1983 case 'm':
1984 {
1985 if (LocaleCompare("map",option+1) == 0)
cristy3ed852e2009-09-05 21:47:34 +00001986 {
cristy3ed852e2009-09-05 21:47:34 +00001987 Image
anthonydf8ebac2011-04-27 09:03:19 +00001988 *remap_image;
cristy3ed852e2009-09-05 21:47:34 +00001989
anthonydf8ebac2011-04-27 09:03:19 +00001990 /*
1991 Transform image colors to match this set of colors.
1992 */
1993 (void) SyncImageSettings(mogrify_info,*image);
1994 if (*option == '+')
1995 break;
1996 remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
1997 if (remap_image == (Image *) NULL)
1998 break;
1999 (void) RemapImage(quantize_info,*image,remap_image);
2000 InheritException(exception,&(*image)->exception);
2001 remap_image=DestroyImage(remap_image);
2002 break;
2003 }
2004 if (LocaleCompare("mask",option+1) == 0)
2005 {
2006 Image
2007 *mask;
2008
2009 (void) SyncImageSettings(mogrify_info,*image);
2010 if (*option == '+')
2011 {
2012 /*
2013 Remove a mask.
2014 */
2015 (void) SetImageMask(*image,(Image *) NULL);
2016 InheritException(exception,&(*image)->exception);
2017 break;
2018 }
2019 /*
2020 Set the image mask.
2021 */
2022 mask=GetImageCache(mogrify_info,argv[i+1],exception);
2023 if (mask == (Image *) NULL)
2024 break;
2025 (void) SetImageMask(*image,mask);
2026 mask=DestroyImage(mask);
2027 InheritException(exception,&(*image)->exception);
2028 break;
2029 }
2030 if (LocaleCompare("matte",option+1) == 0)
2031 {
2032 (void) SetImageAlphaChannel(*image,(*option == '-') ?
2033 SetAlphaChannel : DeactivateAlphaChannel );
2034 InheritException(exception,&(*image)->exception);
2035 break;
2036 }
2037 if (LocaleCompare("median",option+1) == 0)
2038 {
2039 /*
2040 Median filter image.
2041 */
2042 (void) SyncImageSettings(mogrify_info,*image);
2043 (void) ParseGeometry(argv[i+1],&geometry_info);
cristyf4ad9df2011-07-08 16:49:03 +00002044 mogrify_image=StatisticImage(*image,MedianStatistic,(size_t)
2045 geometry_info.rho,(size_t) geometry_info.rho,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002046 break;
2047 }
2048 if (LocaleCompare("mode",option+1) == 0)
2049 {
2050 /*
2051 Mode image.
2052 */
2053 (void) SyncImageSettings(mogrify_info,*image);
2054 (void) ParseGeometry(argv[i+1],&geometry_info);
cristyf4ad9df2011-07-08 16:49:03 +00002055 mogrify_image=StatisticImage(*image,ModeStatistic,(size_t)
2056 geometry_info.rho,(size_t) geometry_info.rho,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002057 break;
2058 }
2059 if (LocaleCompare("modulate",option+1) == 0)
2060 {
2061 (void) SyncImageSettings(mogrify_info,*image);
2062 (void) ModulateImage(*image,argv[i+1]);
2063 InheritException(exception,&(*image)->exception);
2064 break;
2065 }
2066 if (LocaleCompare("monitor",option+1) == 0)
2067 {
2068 if (*option == '+')
2069 {
2070 (void) SetImageProgressMonitor(*image,
2071 (MagickProgressMonitor) NULL,(void *) NULL);
2072 break;
2073 }
2074 (void) SetImageProgressMonitor(*image,MonitorProgress,
2075 (void *) NULL);
2076 break;
2077 }
2078 if (LocaleCompare("monochrome",option+1) == 0)
2079 {
2080 (void) SyncImageSettings(mogrify_info,*image);
2081 (void) SetImageType(*image,BilevelType);
2082 InheritException(exception,&(*image)->exception);
2083 break;
2084 }
2085 if (LocaleCompare("morphology",option+1) == 0)
2086 {
2087 char
2088 token[MaxTextExtent];
2089
2090 const char
2091 *p;
2092
2093 KernelInfo
2094 *kernel;
2095
2096 MorphologyMethod
2097 method;
2098
2099 ssize_t
2100 iterations;
2101
2102 /*
2103 Morphological Image Operation
2104 */
2105 (void) SyncImageSettings(mogrify_info,*image);
2106 p=argv[i+1];
2107 GetMagickToken(p,&p,token);
2108 method=(MorphologyMethod) ParseCommandOption(MagickMorphologyOptions,
2109 MagickFalse,token);
2110 iterations=1L;
2111 GetMagickToken(p,&p,token);
2112 if ((*p == ':') || (*p == ','))
2113 GetMagickToken(p,&p,token);
2114 if ((*p != '\0'))
2115 iterations=(ssize_t) StringToLong(p);
2116 kernel=AcquireKernelInfo(argv[i+2]);
2117 if (kernel == (KernelInfo *) NULL)
2118 {
2119 (void) ThrowMagickException(exception,GetMagickModule(),
2120 OptionError,"UnabletoParseKernel","morphology");
2121 status=MagickFalse;
2122 break;
2123 }
cristyf4ad9df2011-07-08 16:49:03 +00002124 mogrify_image=MorphologyImage(*image,method,iterations,kernel,
2125 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002126 kernel=DestroyKernelInfo(kernel);
2127 break;
2128 }
2129 if (LocaleCompare("motion-blur",option+1) == 0)
2130 {
2131 /*
2132 Motion blur image.
2133 */
2134 (void) SyncImageSettings(mogrify_info,*image);
2135 flags=ParseGeometry(argv[i+1],&geometry_info);
2136 if ((flags & SigmaValue) == 0)
2137 geometry_info.sigma=1.0;
cristyf4ad9df2011-07-08 16:49:03 +00002138 mogrify_image=MotionBlurImage(*image,geometry_info.rho,
2139 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002140 break;
2141 }
2142 break;
2143 }
2144 case 'n':
2145 {
2146 if (LocaleCompare("negate",option+1) == 0)
2147 {
2148 (void) SyncImageSettings(mogrify_info,*image);
cristy50fbc382011-07-07 02:19:17 +00002149 (void) NegateImage(*image,*option == '+' ? MagickTrue :
2150 MagickFalse);
anthonydf8ebac2011-04-27 09:03:19 +00002151 InheritException(exception,&(*image)->exception);
2152 break;
2153 }
2154 if (LocaleCompare("noise",option+1) == 0)
2155 {
2156 (void) SyncImageSettings(mogrify_info,*image);
2157 if (*option == '-')
2158 {
2159 (void) ParseGeometry(argv[i+1],&geometry_info);
cristyf4ad9df2011-07-08 16:49:03 +00002160 mogrify_image=StatisticImage(*image,NonpeakStatistic,(size_t)
2161 geometry_info.rho,(size_t) geometry_info.rho,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002162 }
2163 else
2164 {
2165 NoiseType
2166 noise;
2167
2168 noise=(NoiseType) ParseCommandOption(MagickNoiseOptions,
2169 MagickFalse,argv[i+1]);
cristy490408a2011-07-07 14:42:05 +00002170 mogrify_image=AddNoiseImage(*image,noise,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002171 }
2172 break;
2173 }
2174 if (LocaleCompare("normalize",option+1) == 0)
2175 {
2176 (void) SyncImageSettings(mogrify_info,*image);
cristy50fbc382011-07-07 02:19:17 +00002177 (void) NormalizeImage(*image);
anthonydf8ebac2011-04-27 09:03:19 +00002178 InheritException(exception,&(*image)->exception);
2179 break;
2180 }
2181 break;
2182 }
2183 case 'o':
2184 {
2185 if (LocaleCompare("opaque",option+1) == 0)
2186 {
cristy4c08aed2011-07-01 19:47:50 +00002187 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00002188 target;
2189
2190 (void) SyncImageSettings(mogrify_info,*image);
2191 (void) QueryMagickColor(argv[i+1],&target,exception);
cristyd42d9952011-07-08 14:21:50 +00002192 (void) OpaquePaintImage(*image,&target,&fill,*option == '-' ?
2193 MagickFalse : MagickTrue);
anthonydf8ebac2011-04-27 09:03:19 +00002194 break;
2195 }
2196 if (LocaleCompare("ordered-dither",option+1) == 0)
2197 {
2198 (void) SyncImageSettings(mogrify_info,*image);
cristy13020672011-07-08 02:33:26 +00002199 (void) OrderedPosterizeImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00002200 break;
2201 }
2202 break;
2203 }
2204 case 'p':
2205 {
2206 if (LocaleCompare("paint",option+1) == 0)
2207 {
anthonydf8ebac2011-04-27 09:03:19 +00002208 (void) SyncImageSettings(mogrify_info,*image);
2209 (void) ParseGeometry(argv[i+1],&geometry_info);
anthony3d2f4862011-05-01 13:48:16 +00002210 mogrify_image=OilPaintImage(*image,geometry_info.rho,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002211 break;
2212 }
2213 if (LocaleCompare("pen",option+1) == 0)
2214 {
2215 if (*option == '+')
2216 {
2217 (void) QueryColorDatabase("none",&draw_info->fill,exception);
2218 break;
2219 }
2220 (void) QueryColorDatabase(argv[i+1],&draw_info->fill,exception);
2221 break;
2222 }
2223 if (LocaleCompare("pointsize",option+1) == 0)
2224 {
2225 if (*option == '+')
2226 (void) ParseGeometry("12",&geometry_info);
2227 else
2228 (void) ParseGeometry(argv[i+1],&geometry_info);
2229 draw_info->pointsize=geometry_info.rho;
2230 break;
2231 }
2232 if (LocaleCompare("polaroid",option+1) == 0)
2233 {
2234 double
2235 angle;
2236
2237 RandomInfo
2238 *random_info;
2239
2240 /*
2241 Simulate a Polaroid picture.
2242 */
2243 (void) SyncImageSettings(mogrify_info,*image);
2244 random_info=AcquireRandomInfo();
2245 angle=22.5*(GetPseudoRandomValue(random_info)-0.5);
2246 random_info=DestroyRandomInfo(random_info);
2247 if (*option == '-')
2248 {
2249 SetGeometryInfo(&geometry_info);
2250 flags=ParseGeometry(argv[i+1],&geometry_info);
2251 angle=geometry_info.rho;
2252 }
2253 mogrify_image=PolaroidImage(*image,draw_info,angle,exception);
2254 break;
2255 }
2256 if (LocaleCompare("posterize",option+1) == 0)
2257 {
2258 /*
2259 Posterize image.
2260 */
2261 (void) SyncImageSettings(mogrify_info,*image);
2262 (void) PosterizeImage(*image,StringToUnsignedLong(argv[i+1]),
2263 quantize_info->dither);
2264 InheritException(exception,&(*image)->exception);
2265 break;
2266 }
2267 if (LocaleCompare("preview",option+1) == 0)
2268 {
2269 PreviewType
2270 preview_type;
2271
2272 /*
2273 Preview image.
2274 */
2275 (void) SyncImageSettings(mogrify_info,*image);
2276 if (*option == '+')
2277 preview_type=UndefinedPreview;
2278 else
2279 preview_type=(PreviewType) ParseCommandOption(MagickPreviewOptions,
2280 MagickFalse,argv[i+1]);
2281 mogrify_image=PreviewImage(*image,preview_type,exception);
2282 break;
2283 }
2284 if (LocaleCompare("profile",option+1) == 0)
2285 {
2286 const char
2287 *name;
2288
2289 const StringInfo
2290 *profile;
2291
2292 Image
2293 *profile_image;
2294
2295 ImageInfo
2296 *profile_info;
2297
2298 (void) SyncImageSettings(mogrify_info,*image);
2299 if (*option == '+')
2300 {
2301 /*
2302 Remove a profile from the image.
2303 */
2304 (void) ProfileImage(*image,argv[i+1],(const unsigned char *)
2305 NULL,0,MagickTrue);
2306 InheritException(exception,&(*image)->exception);
2307 break;
2308 }
2309 /*
2310 Associate a profile with the image.
2311 */
2312 profile_info=CloneImageInfo(mogrify_info);
2313 profile=GetImageProfile(*image,"iptc");
2314 if (profile != (StringInfo *) NULL)
2315 profile_info->profile=(void *) CloneStringInfo(profile);
2316 profile_image=GetImageCache(profile_info,argv[i+1],exception);
2317 profile_info=DestroyImageInfo(profile_info);
2318 if (profile_image == (Image *) NULL)
2319 {
2320 StringInfo
2321 *profile;
2322
2323 profile_info=CloneImageInfo(mogrify_info);
2324 (void) CopyMagickString(profile_info->filename,argv[i+1],
2325 MaxTextExtent);
2326 profile=FileToStringInfo(profile_info->filename,~0UL,exception);
2327 if (profile != (StringInfo *) NULL)
2328 {
2329 (void) ProfileImage(*image,profile_info->magick,
2330 GetStringInfoDatum(profile),(size_t)
2331 GetStringInfoLength(profile),MagickFalse);
2332 profile=DestroyStringInfo(profile);
2333 }
2334 profile_info=DestroyImageInfo(profile_info);
2335 break;
2336 }
2337 ResetImageProfileIterator(profile_image);
2338 name=GetNextImageProfile(profile_image);
2339 while (name != (const char *) NULL)
2340 {
2341 profile=GetImageProfile(profile_image,name);
2342 if (profile != (StringInfo *) NULL)
2343 (void) ProfileImage(*image,name,GetStringInfoDatum(profile),
2344 (size_t) GetStringInfoLength(profile),MagickFalse);
2345 name=GetNextImageProfile(profile_image);
2346 }
2347 profile_image=DestroyImage(profile_image);
2348 break;
2349 }
2350 break;
2351 }
2352 case 'q':
2353 {
2354 if (LocaleCompare("quantize",option+1) == 0)
2355 {
2356 if (*option == '+')
2357 {
2358 quantize_info->colorspace=UndefinedColorspace;
2359 break;
2360 }
2361 quantize_info->colorspace=(ColorspaceType) ParseCommandOption(
2362 MagickColorspaceOptions,MagickFalse,argv[i+1]);
2363 break;
2364 }
2365 break;
2366 }
2367 case 'r':
2368 {
2369 if (LocaleCompare("radial-blur",option+1) == 0)
2370 {
2371 /*
2372 Radial blur image.
2373 */
2374 (void) SyncImageSettings(mogrify_info,*image);
cristyf4ad9df2011-07-08 16:49:03 +00002375 mogrify_image=RadialBlurImage(*image,InterpretLocaleValue(argv[i+1],
2376 (char **) NULL),exception);
anthonydf8ebac2011-04-27 09:03:19 +00002377 break;
2378 }
2379 if (LocaleCompare("raise",option+1) == 0)
2380 {
2381 /*
2382 Surround image with a raise of solid color.
2383 */
2384 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2385 if ((flags & SigmaValue) == 0)
2386 geometry.height=geometry.width;
2387 (void) RaiseImage(*image,&geometry,*option == '-' ? MagickTrue :
2388 MagickFalse);
2389 InheritException(exception,&(*image)->exception);
2390 break;
2391 }
2392 if (LocaleCompare("random-threshold",option+1) == 0)
2393 {
2394 /*
2395 Threshold image.
2396 */
2397 (void) SyncImageSettings(mogrify_info,*image);
cristyf4ad9df2011-07-08 16:49:03 +00002398 (void) RandomThresholdImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00002399 break;
2400 }
2401 if (LocaleCompare("recolor",option+1) == 0)
2402 {
2403 KernelInfo
2404 *kernel;
2405
2406 (void) SyncImageSettings(mogrify_info,*image);
2407 kernel=AcquireKernelInfo(argv[i+1]);
2408 if (kernel == (KernelInfo *) NULL)
2409 break;
2410 mogrify_image=ColorMatrixImage(*image,kernel,exception);
2411 kernel=DestroyKernelInfo(kernel);
2412 break;
2413 }
2414 if (LocaleCompare("region",option+1) == 0)
2415 {
2416 (void) SyncImageSettings(mogrify_info,*image);
2417 if (region_image != (Image *) NULL)
2418 {
2419 /*
2420 Composite region.
2421 */
2422 (void) CompositeImage(region_image,region_image->matte !=
cristyf4ad9df2011-07-08 16:49:03 +00002423 MagickFalse ? CopyCompositeOp : OverCompositeOp,*image,
2424 region_geometry.x,region_geometry.y);
anthonydf8ebac2011-04-27 09:03:19 +00002425 InheritException(exception,&region_image->exception);
2426 *image=DestroyImage(*image);
2427 *image=region_image;
2428 region_image = (Image *) NULL;
2429 }
2430 if (*option == '+')
2431 break;
2432 /*
2433 Apply transformations to a selected region of the image.
2434 */
cristy3ed852e2009-09-05 21:47:34 +00002435 (void) ParseGravityGeometry(*image,argv[i+1],&region_geometry,
2436 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002437 mogrify_image=CropImage(*image,&region_geometry,exception);
2438 if (mogrify_image == (Image *) NULL)
2439 break;
2440 region_image=(*image);
2441 *image=mogrify_image;
2442 mogrify_image=(Image *) NULL;
2443 break;
cristy3ed852e2009-09-05 21:47:34 +00002444 }
anthonydf8ebac2011-04-27 09:03:19 +00002445 if (LocaleCompare("render",option+1) == 0)
2446 {
2447 (void) SyncImageSettings(mogrify_info,*image);
2448 draw_info->render=(*option == '+') ? MagickTrue : MagickFalse;
2449 break;
2450 }
2451 if (LocaleCompare("remap",option+1) == 0)
2452 {
2453 Image
2454 *remap_image;
cristy3ed852e2009-09-05 21:47:34 +00002455
anthonydf8ebac2011-04-27 09:03:19 +00002456 /*
2457 Transform image colors to match this set of colors.
2458 */
2459 (void) SyncImageSettings(mogrify_info,*image);
2460 if (*option == '+')
2461 break;
2462 remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
2463 if (remap_image == (Image *) NULL)
2464 break;
2465 (void) RemapImage(quantize_info,*image,remap_image);
2466 InheritException(exception,&(*image)->exception);
2467 remap_image=DestroyImage(remap_image);
2468 break;
2469 }
2470 if (LocaleCompare("repage",option+1) == 0)
2471 {
2472 if (*option == '+')
2473 {
2474 (void) ParseAbsoluteGeometry("0x0+0+0",&(*image)->page);
2475 break;
2476 }
2477 (void) ResetImagePage(*image,argv[i+1]);
2478 InheritException(exception,&(*image)->exception);
2479 break;
2480 }
2481 if (LocaleCompare("resample",option+1) == 0)
2482 {
2483 /*
2484 Resample image.
2485 */
2486 (void) SyncImageSettings(mogrify_info,*image);
2487 flags=ParseGeometry(argv[i+1],&geometry_info);
2488 if ((flags & SigmaValue) == 0)
2489 geometry_info.sigma=geometry_info.rho;
2490 mogrify_image=ResampleImage(*image,geometry_info.rho,
2491 geometry_info.sigma,(*image)->filter,(*image)->blur,exception);
2492 break;
2493 }
2494 if (LocaleCompare("resize",option+1) == 0)
2495 {
2496 /*
2497 Resize image.
2498 */
2499 (void) SyncImageSettings(mogrify_info,*image);
2500 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2501 mogrify_image=ResizeImage(*image,geometry.width,geometry.height,
2502 (*image)->filter,(*image)->blur,exception);
2503 break;
2504 }
2505 if (LocaleCompare("roll",option+1) == 0)
2506 {
2507 /*
2508 Roll image.
2509 */
2510 (void) SyncImageSettings(mogrify_info,*image);
2511 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2512 mogrify_image=RollImage(*image,geometry.x,geometry.y,exception);
2513 break;
2514 }
2515 if (LocaleCompare("rotate",option+1) == 0)
2516 {
2517 char
2518 *geometry;
2519
2520 /*
2521 Check for conditional image rotation.
2522 */
2523 (void) SyncImageSettings(mogrify_info,*image);
2524 if (strchr(argv[i+1],'>') != (char *) NULL)
2525 if ((*image)->columns <= (*image)->rows)
2526 break;
2527 if (strchr(argv[i+1],'<') != (char *) NULL)
2528 if ((*image)->columns >= (*image)->rows)
2529 break;
2530 /*
2531 Rotate image.
2532 */
2533 geometry=ConstantString(argv[i+1]);
2534 (void) SubstituteString(&geometry,">","");
2535 (void) SubstituteString(&geometry,"<","");
2536 (void) ParseGeometry(geometry,&geometry_info);
2537 geometry=DestroyString(geometry);
2538 mogrify_image=RotateImage(*image,geometry_info.rho,exception);
2539 break;
2540 }
2541 break;
2542 }
2543 case 's':
2544 {
2545 if (LocaleCompare("sample",option+1) == 0)
2546 {
2547 /*
2548 Sample image with pixel replication.
2549 */
2550 (void) SyncImageSettings(mogrify_info,*image);
2551 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2552 mogrify_image=SampleImage(*image,geometry.width,geometry.height,
2553 exception);
2554 break;
2555 }
2556 if (LocaleCompare("scale",option+1) == 0)
2557 {
2558 /*
2559 Resize image.
2560 */
2561 (void) SyncImageSettings(mogrify_info,*image);
2562 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2563 mogrify_image=ScaleImage(*image,geometry.width,geometry.height,
2564 exception);
2565 break;
2566 }
2567 if (LocaleCompare("selective-blur",option+1) == 0)
2568 {
2569 /*
2570 Selectively blur pixels within a contrast threshold.
2571 */
2572 (void) SyncImageSettings(mogrify_info,*image);
2573 flags=ParseGeometry(argv[i+1],&geometry_info);
2574 if ((flags & PercentValue) != 0)
2575 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
cristyf4ad9df2011-07-08 16:49:03 +00002576 mogrify_image=SelectiveBlurImage(*image,geometry_info.rho,
2577 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002578 break;
2579 }
2580 if (LocaleCompare("separate",option+1) == 0)
2581 {
2582 /*
2583 Break channels into separate images.
anthonydf8ebac2011-04-27 09:03:19 +00002584 */
2585 (void) SyncImageSettings(mogrify_info,*image);
cristy3139dc22011-07-08 00:11:42 +00002586 mogrify_image=SeparateImages(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002587 break;
2588 }
2589 if (LocaleCompare("sepia-tone",option+1) == 0)
2590 {
2591 double
2592 threshold;
2593
2594 /*
2595 Sepia-tone image.
2596 */
2597 (void) SyncImageSettings(mogrify_info,*image);
2598 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
2599 mogrify_image=SepiaToneImage(*image,threshold,exception);
2600 break;
2601 }
2602 if (LocaleCompare("segment",option+1) == 0)
2603 {
2604 /*
2605 Segment image.
2606 */
2607 (void) SyncImageSettings(mogrify_info,*image);
2608 flags=ParseGeometry(argv[i+1],&geometry_info);
2609 if ((flags & SigmaValue) == 0)
2610 geometry_info.sigma=1.0;
2611 (void) SegmentImage(*image,(*image)->colorspace,
2612 mogrify_info->verbose,geometry_info.rho,geometry_info.sigma);
2613 InheritException(exception,&(*image)->exception);
2614 break;
2615 }
2616 if (LocaleCompare("set",option+1) == 0)
2617 {
2618 char
2619 *value;
2620
2621 /*
2622 Set image option.
2623 */
2624 if (*option == '+')
2625 {
2626 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2627 (void) DeleteImageRegistry(argv[i+1]+9);
2628 else
2629 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
2630 {
2631 (void) DeleteImageOption(mogrify_info,argv[i+1]+7);
2632 (void) DeleteImageArtifact(*image,argv[i+1]+7);
2633 }
2634 else
2635 (void) DeleteImageProperty(*image,argv[i+1]);
2636 break;
2637 }
2638 value=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
2639 if (value == (char *) NULL)
2640 break;
2641 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2642 (void) SetImageRegistry(StringRegistryType,argv[i+1]+9,value,
2643 exception);
2644 else
2645 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
2646 {
2647 (void) SetImageOption(image_info,argv[i+1]+7,value);
2648 (void) SetImageOption(mogrify_info,argv[i+1]+7,value);
2649 (void) SetImageArtifact(*image,argv[i+1]+7,value);
2650 }
2651 else
2652 (void) SetImageProperty(*image,argv[i+1],value);
2653 value=DestroyString(value);
2654 break;
2655 }
2656 if (LocaleCompare("shade",option+1) == 0)
2657 {
2658 /*
2659 Shade image.
2660 */
2661 (void) SyncImageSettings(mogrify_info,*image);
2662 flags=ParseGeometry(argv[i+1],&geometry_info);
2663 if ((flags & SigmaValue) == 0)
2664 geometry_info.sigma=1.0;
2665 mogrify_image=ShadeImage(*image,(*option == '-') ? MagickTrue :
2666 MagickFalse,geometry_info.rho,geometry_info.sigma,exception);
2667 break;
2668 }
2669 if (LocaleCompare("shadow",option+1) == 0)
2670 {
2671 /*
2672 Shadow image.
2673 */
2674 (void) SyncImageSettings(mogrify_info,*image);
2675 flags=ParseGeometry(argv[i+1],&geometry_info);
2676 if ((flags & SigmaValue) == 0)
2677 geometry_info.sigma=1.0;
2678 if ((flags & XiValue) == 0)
2679 geometry_info.xi=4.0;
2680 if ((flags & PsiValue) == 0)
2681 geometry_info.psi=4.0;
2682 mogrify_image=ShadowImage(*image,geometry_info.rho,
2683 geometry_info.sigma,(ssize_t) ceil(geometry_info.xi-0.5),(ssize_t)
2684 ceil(geometry_info.psi-0.5),exception);
2685 break;
2686 }
2687 if (LocaleCompare("sharpen",option+1) == 0)
2688 {
2689 /*
2690 Sharpen image.
2691 */
2692 (void) SyncImageSettings(mogrify_info,*image);
2693 flags=ParseGeometry(argv[i+1],&geometry_info);
2694 if ((flags & SigmaValue) == 0)
2695 geometry_info.sigma=1.0;
cristyf4ad9df2011-07-08 16:49:03 +00002696 mogrify_image=SharpenImage(*image,geometry_info.rho,
anthonydf8ebac2011-04-27 09:03:19 +00002697 geometry_info.sigma,exception);
2698 break;
2699 }
2700 if (LocaleCompare("shave",option+1) == 0)
2701 {
2702 /*
2703 Shave the image edges.
2704 */
2705 (void) SyncImageSettings(mogrify_info,*image);
2706 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2707 mogrify_image=ShaveImage(*image,&geometry,exception);
2708 break;
2709 }
2710 if (LocaleCompare("shear",option+1) == 0)
2711 {
2712 /*
2713 Shear image.
2714 */
2715 (void) SyncImageSettings(mogrify_info,*image);
2716 flags=ParseGeometry(argv[i+1],&geometry_info);
2717 if ((flags & SigmaValue) == 0)
2718 geometry_info.sigma=geometry_info.rho;
2719 mogrify_image=ShearImage(*image,geometry_info.rho,
2720 geometry_info.sigma,exception);
2721 break;
2722 }
2723 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
2724 {
2725 /*
2726 Sigmoidal non-linearity contrast control.
2727 */
2728 (void) SyncImageSettings(mogrify_info,*image);
2729 flags=ParseGeometry(argv[i+1],&geometry_info);
2730 if ((flags & SigmaValue) == 0)
2731 geometry_info.sigma=(double) QuantumRange/2.0;
2732 if ((flags & PercentValue) != 0)
2733 geometry_info.sigma=(double) QuantumRange*geometry_info.sigma/
2734 100.0;
cristy9ee60942011-07-06 14:54:38 +00002735 (void) SigmoidalContrastImage(*image,(*option == '-') ?
2736 MagickTrue : MagickFalse,geometry_info.rho,geometry_info.sigma);
anthonydf8ebac2011-04-27 09:03:19 +00002737 InheritException(exception,&(*image)->exception);
2738 break;
2739 }
2740 if (LocaleCompare("sketch",option+1) == 0)
2741 {
2742 /*
2743 Sketch image.
2744 */
2745 (void) SyncImageSettings(mogrify_info,*image);
2746 flags=ParseGeometry(argv[i+1],&geometry_info);
2747 if ((flags & SigmaValue) == 0)
2748 geometry_info.sigma=1.0;
2749 mogrify_image=SketchImage(*image,geometry_info.rho,
2750 geometry_info.sigma,geometry_info.xi,exception);
2751 break;
2752 }
2753 if (LocaleCompare("solarize",option+1) == 0)
2754 {
2755 double
2756 threshold;
2757
2758 (void) SyncImageSettings(mogrify_info,*image);
2759 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
2760 (void) SolarizeImage(*image,threshold);
2761 InheritException(exception,&(*image)->exception);
2762 break;
2763 }
2764 if (LocaleCompare("sparse-color",option+1) == 0)
2765 {
2766 SparseColorMethod
2767 method;
2768
2769 char
2770 *arguments;
2771
2772 /*
2773 Sparse Color Interpolated Gradient
2774 */
2775 (void) SyncImageSettings(mogrify_info,*image);
2776 method=(SparseColorMethod) ParseCommandOption(
2777 MagickSparseColorOptions,MagickFalse,argv[i+1]);
2778 arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
2779 InheritException(exception,&(*image)->exception);
2780 if (arguments == (char *) NULL)
2781 break;
2782 mogrify_image=SparseColorOption(*image,channel,method,arguments,
2783 option[0] == '+' ? MagickTrue : MagickFalse,exception);
2784 arguments=DestroyString(arguments);
2785 break;
2786 }
2787 if (LocaleCompare("splice",option+1) == 0)
2788 {
2789 /*
2790 Splice a solid color into the image.
2791 */
2792 (void) SyncImageSettings(mogrify_info,*image);
2793 (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
2794 mogrify_image=SpliceImage(*image,&geometry,exception);
2795 break;
2796 }
2797 if (LocaleCompare("spread",option+1) == 0)
2798 {
2799 /*
2800 Spread an image.
2801 */
2802 (void) SyncImageSettings(mogrify_info,*image);
2803 (void) ParseGeometry(argv[i+1],&geometry_info);
2804 mogrify_image=SpreadImage(*image,geometry_info.rho,exception);
2805 break;
2806 }
2807 if (LocaleCompare("statistic",option+1) == 0)
2808 {
2809 StatisticType
2810 type;
2811
2812 (void) SyncImageSettings(mogrify_info,*image);
2813 type=(StatisticType) ParseCommandOption(MagickStatisticOptions,
2814 MagickFalse,argv[i+1]);
2815 (void) ParseGeometry(argv[i+2],&geometry_info);
cristyf4ad9df2011-07-08 16:49:03 +00002816 mogrify_image=StatisticImage(*image,type,(size_t) geometry_info.rho,
2817 (size_t) geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002818 break;
2819 }
2820 if (LocaleCompare("stretch",option+1) == 0)
2821 {
2822 if (*option == '+')
2823 {
2824 draw_info->stretch=UndefinedStretch;
2825 break;
2826 }
2827 draw_info->stretch=(StretchType) ParseCommandOption(
2828 MagickStretchOptions,MagickFalse,argv[i+1]);
2829 break;
2830 }
2831 if (LocaleCompare("strip",option+1) == 0)
2832 {
2833 /*
2834 Strip image of profiles and comments.
2835 */
2836 (void) SyncImageSettings(mogrify_info,*image);
2837 (void) StripImage(*image);
2838 InheritException(exception,&(*image)->exception);
2839 break;
2840 }
2841 if (LocaleCompare("stroke",option+1) == 0)
2842 {
2843 ExceptionInfo
2844 *sans;
2845
2846 if (*option == '+')
2847 {
2848 (void) QueryColorDatabase("none",&draw_info->stroke,exception);
2849 if (draw_info->stroke_pattern != (Image *) NULL)
2850 draw_info->stroke_pattern=DestroyImage(
2851 draw_info->stroke_pattern);
2852 break;
2853 }
2854 sans=AcquireExceptionInfo();
2855 status=QueryColorDatabase(argv[i+1],&draw_info->stroke,sans);
2856 sans=DestroyExceptionInfo(sans);
2857 if (status == MagickFalse)
2858 draw_info->stroke_pattern=GetImageCache(mogrify_info,argv[i+1],
2859 exception);
2860 break;
2861 }
2862 if (LocaleCompare("strokewidth",option+1) == 0)
2863 {
cristyc1acd842011-05-19 23:05:47 +00002864 draw_info->stroke_width=InterpretLocaleValue(argv[i+1],
2865 (char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00002866 break;
2867 }
2868 if (LocaleCompare("style",option+1) == 0)
2869 {
2870 if (*option == '+')
2871 {
2872 draw_info->style=UndefinedStyle;
2873 break;
2874 }
2875 draw_info->style=(StyleType) ParseCommandOption(MagickStyleOptions,
2876 MagickFalse,argv[i+1]);
2877 break;
2878 }
2879 if (LocaleCompare("swirl",option+1) == 0)
2880 {
2881 /*
2882 Swirl image.
2883 */
2884 (void) SyncImageSettings(mogrify_info,*image);
2885 (void) ParseGeometry(argv[i+1],&geometry_info);
2886 mogrify_image=SwirlImage(*image,geometry_info.rho,exception);
2887 break;
2888 }
2889 break;
2890 }
2891 case 't':
2892 {
2893 if (LocaleCompare("threshold",option+1) == 0)
2894 {
2895 double
2896 threshold;
2897
2898 /*
2899 Threshold image.
2900 */
2901 (void) SyncImageSettings(mogrify_info,*image);
2902 if (*option == '+')
anthony247a86d2011-05-03 13:18:18 +00002903 threshold=(double) QuantumRange/2;
anthonydf8ebac2011-04-27 09:03:19 +00002904 else
2905 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
cristyf4ad9df2011-07-08 16:49:03 +00002906 (void) BilevelImage(*image,threshold);
anthonydf8ebac2011-04-27 09:03:19 +00002907 InheritException(exception,&(*image)->exception);
2908 break;
2909 }
2910 if (LocaleCompare("thumbnail",option+1) == 0)
2911 {
2912 /*
2913 Thumbnail image.
2914 */
2915 (void) SyncImageSettings(mogrify_info,*image);
2916 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2917 mogrify_image=ThumbnailImage(*image,geometry.width,geometry.height,
2918 exception);
2919 break;
2920 }
2921 if (LocaleCompare("tile",option+1) == 0)
2922 {
2923 if (*option == '+')
2924 {
2925 if (draw_info->fill_pattern != (Image *) NULL)
2926 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
2927 break;
2928 }
2929 draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1],
2930 exception);
2931 break;
2932 }
2933 if (LocaleCompare("tint",option+1) == 0)
2934 {
2935 /*
2936 Tint the image.
2937 */
2938 (void) SyncImageSettings(mogrify_info,*image);
2939 mogrify_image=TintImage(*image,argv[i+1],draw_info->fill,exception);
2940 break;
2941 }
2942 if (LocaleCompare("transform",option+1) == 0)
2943 {
2944 /*
2945 Affine transform image.
2946 */
2947 (void) SyncImageSettings(mogrify_info,*image);
2948 mogrify_image=AffineTransformImage(*image,&draw_info->affine,
2949 exception);
2950 break;
2951 }
2952 if (LocaleCompare("transparent",option+1) == 0)
2953 {
cristy4c08aed2011-07-01 19:47:50 +00002954 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00002955 target;
2956
2957 (void) SyncImageSettings(mogrify_info,*image);
2958 (void) QueryMagickColor(argv[i+1],&target,exception);
2959 (void) TransparentPaintImage(*image,&target,(Quantum)
cristy4c08aed2011-07-01 19:47:50 +00002960 TransparentAlpha,*option == '-' ? MagickFalse : MagickTrue);
anthonydf8ebac2011-04-27 09:03:19 +00002961 InheritException(exception,&(*image)->exception);
2962 break;
2963 }
2964 if (LocaleCompare("transpose",option+1) == 0)
2965 {
2966 /*
2967 Transpose image scanlines.
2968 */
2969 (void) SyncImageSettings(mogrify_info,*image);
2970 mogrify_image=TransposeImage(*image,exception);
2971 break;
2972 }
2973 if (LocaleCompare("transverse",option+1) == 0)
2974 {
2975 /*
2976 Transverse image scanlines.
2977 */
2978 (void) SyncImageSettings(mogrify_info,*image);
2979 mogrify_image=TransverseImage(*image,exception);
2980 break;
2981 }
2982 if (LocaleCompare("treedepth",option+1) == 0)
2983 {
2984 quantize_info->tree_depth=StringToUnsignedLong(argv[i+1]);
2985 break;
2986 }
2987 if (LocaleCompare("trim",option+1) == 0)
2988 {
2989 /*
2990 Trim image.
2991 */
2992 (void) SyncImageSettings(mogrify_info,*image);
2993 mogrify_image=TrimImage(*image,exception);
2994 break;
2995 }
2996 if (LocaleCompare("type",option+1) == 0)
2997 {
2998 ImageType
2999 type;
3000
3001 (void) SyncImageSettings(mogrify_info,*image);
3002 if (*option == '+')
3003 type=UndefinedType;
3004 else
3005 type=(ImageType) ParseCommandOption(MagickTypeOptions,MagickFalse,
3006 argv[i+1]);
3007 (*image)->type=UndefinedType;
3008 (void) SetImageType(*image,type);
3009 InheritException(exception,&(*image)->exception);
3010 break;
3011 }
3012 break;
3013 }
3014 case 'u':
3015 {
3016 if (LocaleCompare("undercolor",option+1) == 0)
3017 {
3018 (void) QueryColorDatabase(argv[i+1],&draw_info->undercolor,
3019 exception);
3020 break;
3021 }
3022 if (LocaleCompare("unique",option+1) == 0)
3023 {
3024 if (*option == '+')
3025 {
3026 (void) DeleteImageArtifact(*image,"identify:unique-colors");
3027 break;
3028 }
3029 (void) SetImageArtifact(*image,"identify:unique-colors","true");
3030 (void) SetImageArtifact(*image,"verbose","true");
3031 break;
3032 }
3033 if (LocaleCompare("unique-colors",option+1) == 0)
3034 {
3035 /*
3036 Unique image colors.
3037 */
3038 (void) SyncImageSettings(mogrify_info,*image);
3039 mogrify_image=UniqueImageColors(*image,exception);
3040 break;
3041 }
3042 if (LocaleCompare("unsharp",option+1) == 0)
3043 {
3044 /*
3045 Unsharp mask image.
3046 */
3047 (void) SyncImageSettings(mogrify_info,*image);
3048 flags=ParseGeometry(argv[i+1],&geometry_info);
3049 if ((flags & SigmaValue) == 0)
3050 geometry_info.sigma=1.0;
3051 if ((flags & XiValue) == 0)
3052 geometry_info.xi=1.0;
3053 if ((flags & PsiValue) == 0)
3054 geometry_info.psi=0.05;
cristyf4ad9df2011-07-08 16:49:03 +00003055 mogrify_image=UnsharpMaskImage(*image,geometry_info.rho,
3056 geometry_info.sigma,geometry_info.xi,geometry_info.psi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003057 break;
3058 }
3059 break;
3060 }
3061 case 'v':
3062 {
3063 if (LocaleCompare("verbose",option+1) == 0)
3064 {
3065 (void) SetImageArtifact(*image,option+1,
3066 *option == '+' ? "false" : "true");
3067 break;
3068 }
3069 if (LocaleCompare("vignette",option+1) == 0)
3070 {
3071 /*
3072 Vignette image.
3073 */
3074 (void) SyncImageSettings(mogrify_info,*image);
3075 flags=ParseGeometry(argv[i+1],&geometry_info);
3076 if ((flags & SigmaValue) == 0)
3077 geometry_info.sigma=1.0;
3078 if ((flags & XiValue) == 0)
3079 geometry_info.xi=0.1*(*image)->columns;
3080 if ((flags & PsiValue) == 0)
3081 geometry_info.psi=0.1*(*image)->rows;
3082 mogrify_image=VignetteImage(*image,geometry_info.rho,
3083 geometry_info.sigma,(ssize_t) ceil(geometry_info.xi-0.5),(ssize_t)
3084 ceil(geometry_info.psi-0.5),exception);
3085 break;
3086 }
3087 if (LocaleCompare("virtual-pixel",option+1) == 0)
3088 {
3089 if (*option == '+')
3090 {
3091 (void) SetImageVirtualPixelMethod(*image,
3092 UndefinedVirtualPixelMethod);
3093 break;
3094 }
3095 (void) SetImageVirtualPixelMethod(*image,(VirtualPixelMethod)
3096 ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
3097 argv[i+1]));
3098 break;
3099 }
3100 break;
3101 }
3102 case 'w':
3103 {
3104 if (LocaleCompare("wave",option+1) == 0)
3105 {
3106 /*
3107 Wave image.
3108 */
3109 (void) SyncImageSettings(mogrify_info,*image);
3110 flags=ParseGeometry(argv[i+1],&geometry_info);
3111 if ((flags & SigmaValue) == 0)
3112 geometry_info.sigma=1.0;
3113 mogrify_image=WaveImage(*image,geometry_info.rho,
3114 geometry_info.sigma,exception);
3115 break;
3116 }
3117 if (LocaleCompare("weight",option+1) == 0)
3118 {
3119 draw_info->weight=StringToUnsignedLong(argv[i+1]);
3120 if (LocaleCompare(argv[i+1],"all") == 0)
3121 draw_info->weight=0;
3122 if (LocaleCompare(argv[i+1],"bold") == 0)
3123 draw_info->weight=700;
3124 if (LocaleCompare(argv[i+1],"bolder") == 0)
3125 if (draw_info->weight <= 800)
3126 draw_info->weight+=100;
3127 if (LocaleCompare(argv[i+1],"lighter") == 0)
3128 if (draw_info->weight >= 100)
3129 draw_info->weight-=100;
3130 if (LocaleCompare(argv[i+1],"normal") == 0)
3131 draw_info->weight=400;
3132 break;
3133 }
3134 if (LocaleCompare("white-threshold",option+1) == 0)
3135 {
3136 /*
3137 White threshold image.
3138 */
3139 (void) SyncImageSettings(mogrify_info,*image);
cristyf4ad9df2011-07-08 16:49:03 +00003140 (void) WhiteThresholdImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00003141 InheritException(exception,&(*image)->exception);
3142 break;
3143 }
3144 break;
3145 }
3146 default:
3147 break;
3148 }
3149 /*
3150 Replace current image with any image that was generated
3151 */
3152 if (mogrify_image != (Image *) NULL)
3153 ReplaceImageInListReturnLast(image,mogrify_image);
cristy3ed852e2009-09-05 21:47:34 +00003154 i+=count;
3155 }
3156 if (region_image != (Image *) NULL)
3157 {
anthonydf8ebac2011-04-27 09:03:19 +00003158 /*
3159 Composite transformed region onto image.
3160 */
cristy6b3da3a2010-06-20 02:21:46 +00003161 (void) SyncImageSettings(mogrify_info,*image);
anthonya129f702011-04-14 01:08:48 +00003162 (void) CompositeImage(region_image,region_image->matte !=
cristyf4ad9df2011-07-08 16:49:03 +00003163 MagickFalse ? CopyCompositeOp : OverCompositeOp,*image,
3164 region_geometry.x,region_geometry.y);
cristy3ed852e2009-09-05 21:47:34 +00003165 InheritException(exception,&region_image->exception);
3166 *image=DestroyImage(*image);
3167 *image=region_image;
anthonye9c27192011-03-27 08:07:06 +00003168 region_image = (Image *) NULL;
cristy3ed852e2009-09-05 21:47:34 +00003169 }
3170 /*
3171 Free resources.
3172 */
anthonydf8ebac2011-04-27 09:03:19 +00003173 quantize_info=DestroyQuantizeInfo(quantize_info);
3174 draw_info=DestroyDrawInfo(draw_info);
cristy6b3da3a2010-06-20 02:21:46 +00003175 mogrify_info=DestroyImageInfo(mogrify_info);
cristy4c08aed2011-07-01 19:47:50 +00003176 status=(MagickStatusType) ((*image)->exception.severity ==
cristy5f09d852011-05-29 01:39:29 +00003177 UndefinedException ? 1 : 0);
cristy72988482011-03-29 16:34:38 +00003178 return(status == 0 ? MagickFalse : MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00003179}
3180
3181/*
3182%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3183% %
3184% %
3185% %
cristy5063d812010-10-19 16:28:10 +00003186+ 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 +00003187% %
3188% %
3189% %
3190%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3191%
3192% MogrifyImageCommand() transforms an image or a sequence of images. These
3193% transforms include image scaling, image rotation, color reduction, and
3194% others. The transmogrified image overwrites the original image.
3195%
3196% The format of the MogrifyImageCommand method is:
3197%
3198% MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,int argc,
3199% const char **argv,char **metadata,ExceptionInfo *exception)
3200%
3201% A description of each parameter follows:
3202%
3203% o image_info: the image info.
3204%
3205% o argc: the number of elements in the argument vector.
3206%
3207% o argv: A text array containing the command line arguments.
3208%
3209% o metadata: any metadata is returned here.
3210%
3211% o exception: return any errors or warnings in this structure.
3212%
3213*/
3214
3215static MagickBooleanType MogrifyUsage(void)
3216{
3217 static const char
3218 *miscellaneous[]=
3219 {
3220 "-debug events display copious debugging information",
3221 "-help print program options",
3222 "-list type print a list of supported option arguments",
3223 "-log format format of debugging information",
3224 "-version print version information",
3225 (char *) NULL
3226 },
3227 *operators[]=
3228 {
3229 "-adaptive-blur geometry",
3230 " adaptively blur pixels; decrease effect near edges",
3231 "-adaptive-resize geometry",
3232 " adaptively resize image using 'mesh' interpolation",
3233 "-adaptive-sharpen geometry",
3234 " adaptively sharpen pixels; increase effect near edges",
3235 "-alpha option on, activate, off, deactivate, set, opaque, copy",
3236 " transparent, extract, background, or shape",
3237 "-annotate geometry text",
3238 " annotate the image with text",
3239 "-auto-gamma automagically adjust gamma level of image",
3240 "-auto-level automagically adjust color levels of image",
3241 "-auto-orient automagically orient (rotate) image",
3242 "-bench iterations measure performance",
3243 "-black-threshold value",
3244 " force all pixels below the threshold into black",
3245 "-blue-shift simulate a scene at nighttime in the moonlight",
3246 "-blur geometry reduce image noise and reduce detail levels",
3247 "-border geometry surround image with a border of color",
3248 "-bordercolor color border color",
cristya28d6b82010-01-11 20:03:47 +00003249 "-brightness-contrast geometry",
3250 " improve brightness / contrast of the image",
cristy3ed852e2009-09-05 21:47:34 +00003251 "-cdl filename color correct with a color decision list",
3252 "-charcoal radius simulate a charcoal drawing",
3253 "-chop geometry remove pixels from the image interior",
cristyecb0c6d2009-09-25 16:50:09 +00003254 "-clamp restrict pixel range from 0 to the quantum depth",
cristycee97112010-05-28 00:44:52 +00003255 "-clip clip along the first path from the 8BIM profile",
cristy3ed852e2009-09-05 21:47:34 +00003256 "-clip-mask filename associate a clip mask with the image",
cristycee97112010-05-28 00:44:52 +00003257 "-clip-path id clip along a named path from the 8BIM profile",
cristy3ed852e2009-09-05 21:47:34 +00003258 "-colorize value colorize the image with the fill color",
cristye6365592010-04-02 17:31:23 +00003259 "-color-matrix matrix apply color correction to the image",
cristy3ed852e2009-09-05 21:47:34 +00003260 "-contrast enhance or reduce the image contrast",
3261 "-contrast-stretch geometry",
3262 " improve contrast by `stretching' the intensity range",
3263 "-convolve coefficients",
3264 " apply a convolution kernel to the image",
3265 "-cycle amount cycle the image colormap",
3266 "-decipher filename convert cipher pixels to plain pixels",
3267 "-deskew threshold straighten an image",
3268 "-despeckle reduce the speckles within an image",
3269 "-distort method args",
3270 " distort images according to given method ad args",
3271 "-draw string annotate the image with a graphic primitive",
3272 "-edge radius apply a filter to detect edges in the image",
3273 "-encipher filename convert plain pixels to cipher pixels",
3274 "-emboss radius emboss an image",
3275 "-enhance apply a digital filter to enhance a noisy image",
3276 "-equalize perform histogram equalization to an image",
3277 "-evaluate operator value",
cristyd18ae7c2010-03-07 17:39:52 +00003278 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003279 "-extent geometry set the image size",
3280 "-extract geometry extract area from image",
3281 "-fft implements the discrete Fourier transform (DFT)",
3282 "-flip flip image vertically",
3283 "-floodfill geometry color",
3284 " floodfill the image with color",
3285 "-flop flop image horizontally",
3286 "-frame geometry surround image with an ornamental border",
cristyc2b730e2009-11-24 14:32:09 +00003287 "-function name parameters",
cristy3ed852e2009-09-05 21:47:34 +00003288 " apply function over image values",
3289 "-gamma value level of gamma correction",
3290 "-gaussian-blur geometry",
3291 " reduce image noise and reduce detail levels",
cristy901f09d2009-10-16 22:56:10 +00003292 "-geometry geometry preferred size or location of the image",
cristy3ed852e2009-09-05 21:47:34 +00003293 "-identify identify the format and characteristics of the image",
3294 "-ift implements the inverse discrete Fourier transform (DFT)",
3295 "-implode amount implode image pixels about the center",
3296 "-lat geometry local adaptive thresholding",
3297 "-layers method optimize, merge, or compare image layers",
3298 "-level value adjust the level of image contrast",
3299 "-level-colors color,color",
cristyee0f8d72009-09-19 00:58:29 +00003300 " level image with the given colors",
cristy3ed852e2009-09-05 21:47:34 +00003301 "-linear-stretch geometry",
3302 " improve contrast by `stretching with saturation'",
3303 "-liquid-rescale geometry",
3304 " rescale image with seam-carving",
cristy3c741502011-04-01 23:21:16 +00003305 "-median geometry apply a median filter to the image",
glennrp30d2dc62011-06-25 03:17:16 +00003306 "-mode geometry make each pixel the 'predominant color' of the neighborhood",
cristy3ed852e2009-09-05 21:47:34 +00003307 "-modulate value vary the brightness, saturation, and hue",
3308 "-monochrome transform image to black and white",
cristy7c1b9fd2010-02-02 14:36:00 +00003309 "-morphology method kernel",
anthony29188a82010-01-22 10:12:34 +00003310 " apply a morphology method to the image",
cristy3ed852e2009-09-05 21:47:34 +00003311 "-motion-blur geometry",
3312 " simulate motion blur",
3313 "-negate replace every pixel with its complementary color ",
cristy3c741502011-04-01 23:21:16 +00003314 "-noise geometry add or reduce noise in an image",
cristy3ed852e2009-09-05 21:47:34 +00003315 "-normalize transform image to span the full range of colors",
3316 "-opaque color change this color to the fill color",
3317 "-ordered-dither NxN",
3318 " add a noise pattern to the image with specific",
3319 " amplitudes",
3320 "-paint radius simulate an oil painting",
3321 "-polaroid angle simulate a Polaroid picture",
3322 "-posterize levels reduce the image to a limited number of color levels",
cristy3ed852e2009-09-05 21:47:34 +00003323 "-profile filename add, delete, or apply an image profile",
3324 "-quantize colorspace reduce colors in this colorspace",
3325 "-radial-blur angle radial blur the image",
3326 "-raise value lighten/darken image edges to create a 3-D effect",
3327 "-random-threshold low,high",
3328 " random threshold the image",
cristy3ed852e2009-09-05 21:47:34 +00003329 "-region geometry apply options to a portion of the image",
3330 "-render render vector graphics",
3331 "-repage geometry size and location of an image canvas",
3332 "-resample geometry change the resolution of an image",
3333 "-resize geometry resize the image",
3334 "-roll geometry roll an image vertically or horizontally",
3335 "-rotate degrees apply Paeth rotation to the image",
3336 "-sample geometry scale image with pixel sampling",
3337 "-scale geometry scale the image",
3338 "-segment values segment an image",
3339 "-selective-blur geometry",
3340 " selectively blur pixels within a contrast threshold",
3341 "-sepia-tone threshold",
3342 " simulate a sepia-toned photo",
3343 "-set property value set an image property",
3344 "-shade degrees shade the image using a distant light source",
3345 "-shadow geometry simulate an image shadow",
3346 "-sharpen geometry sharpen the image",
3347 "-shave geometry shave pixels from the image edges",
cristycee97112010-05-28 00:44:52 +00003348 "-shear geometry slide one edge of the image along the X or Y axis",
cristy3ed852e2009-09-05 21:47:34 +00003349 "-sigmoidal-contrast geometry",
3350 " increase the contrast without saturating highlights or shadows",
3351 "-sketch geometry simulate a pencil sketch",
3352 "-solarize threshold negate all pixels above the threshold level",
3353 "-sparse-color method args",
3354 " fill in a image based on a few color points",
3355 "-splice geometry splice the background color into the image",
3356 "-spread radius displace image pixels by a random amount",
cristy0834d642011-03-18 18:26:08 +00003357 "-statistic type radius",
3358 " replace each pixel with corresponding statistic from the neighborhood",
cristy3ed852e2009-09-05 21:47:34 +00003359 "-strip strip image of all profiles and comments",
3360 "-swirl degrees swirl image pixels about the center",
3361 "-threshold value threshold the image",
3362 "-thumbnail geometry create a thumbnail of the image",
3363 "-tile filename tile image when filling a graphic primitive",
3364 "-tint value tint the image with the fill color",
3365 "-transform affine transform image",
3366 "-transparent color make this color transparent within the image",
3367 "-transpose flip image vertically and rotate 90 degrees",
3368 "-transverse flop image horizontally and rotate 270 degrees",
3369 "-trim trim image edges",
3370 "-type type image type",
3371 "-unique-colors discard all but one of any pixel color",
3372 "-unsharp geometry sharpen the image",
3373 "-vignette geometry soften the edges of the image in vignette style",
cristycee97112010-05-28 00:44:52 +00003374 "-wave geometry alter an image along a sine wave",
cristy3ed852e2009-09-05 21:47:34 +00003375 "-white-threshold value",
3376 " force all pixels above the threshold into white",
3377 (char *) NULL
3378 },
3379 *sequence_operators[]=
3380 {
cristy4285d782011-02-09 20:12:28 +00003381 "-append append an image sequence",
cristy3ed852e2009-09-05 21:47:34 +00003382 "-clut apply a color lookup table to the image",
3383 "-coalesce merge a sequence of images",
3384 "-combine combine a sequence of images",
3385 "-composite composite image",
3386 "-crop geometry cut out a rectangular region of the image",
3387 "-deconstruct break down an image sequence into constituent parts",
cristyd18ae7c2010-03-07 17:39:52 +00003388 "-evaluate-sequence operator",
3389 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003390 "-flatten flatten a sequence of images",
3391 "-fx expression apply mathematical expression to an image channel(s)",
3392 "-hald-clut apply a Hald color lookup table to the image",
3393 "-morph value morph an image sequence",
3394 "-mosaic create a mosaic from an image sequence",
cristy36b94822010-05-20 12:48:16 +00003395 "-print string interpret string and print to console",
cristy3ed852e2009-09-05 21:47:34 +00003396 "-process arguments process the image with a custom image filter",
cristy3ed852e2009-09-05 21:47:34 +00003397 "-separate separate an image channel into a grayscale image",
cristy4285d782011-02-09 20:12:28 +00003398 "-smush geometry smush an image sequence together",
cristy3ed852e2009-09-05 21:47:34 +00003399 "-write filename write images to this file",
3400 (char *) NULL
3401 },
3402 *settings[]=
3403 {
3404 "-adjoin join images into a single multi-image file",
3405 "-affine matrix affine transform matrix",
3406 "-alpha option activate, deactivate, reset, or set the alpha channel",
3407 "-antialias remove pixel-aliasing",
3408 "-authenticate password",
3409 " decipher image with this password",
3410 "-attenuate value lessen (or intensify) when adding noise to an image",
3411 "-background color background color",
3412 "-bias value add bias when convolving an image",
3413 "-black-point-compensation",
3414 " use black point compensation",
3415 "-blue-primary point chromaticity blue primary point",
3416 "-bordercolor color border color",
3417 "-caption string assign a caption to an image",
3418 "-channel type apply option to select image channels",
3419 "-colors value preferred number of colors in the image",
3420 "-colorspace type alternate image colorspace",
3421 "-comment string annotate image with comment",
3422 "-compose operator set image composite operator",
3423 "-compress type type of pixel compression when writing the image",
3424 "-define format:option",
3425 " define one or more image format options",
3426 "-delay value display the next image after pausing",
3427 "-density geometry horizontal and vertical density of the image",
3428 "-depth value image depth",
cristyc9b12952010-03-28 01:12:28 +00003429 "-direction type render text right-to-left or left-to-right",
cristy3ed852e2009-09-05 21:47:34 +00003430 "-display server get image or font from this X server",
3431 "-dispose method layer disposal method",
3432 "-dither method apply error diffusion to image",
3433 "-encoding type text encoding type",
3434 "-endian type endianness (MSB or LSB) of the image",
3435 "-family name render text with this font family",
3436 "-fill color color to use when filling a graphic primitive",
3437 "-filter type use this filter when resizing an image",
3438 "-font name render text with this font",
3439 "-format \"string\" output formatted image characteristics",
3440 "-fuzz distance colors within this distance are considered equal",
3441 "-gravity type horizontal and vertical text placement",
3442 "-green-primary point chromaticity green primary point",
3443 "-intent type type of rendering intent when managing the image color",
3444 "-interlace type type of image interlacing scheme",
cristyb32b90a2009-09-07 21:45:48 +00003445 "-interline-spacing value",
3446 " set the space between two text lines",
cristy3ed852e2009-09-05 21:47:34 +00003447 "-interpolate method pixel color interpolation method",
3448 "-interword-spacing value",
3449 " set the space between two words",
3450 "-kerning value set the space between two letters",
3451 "-label string assign a label to an image",
3452 "-limit type value pixel cache resource limit",
3453 "-loop iterations add Netscape loop extension to your GIF animation",
3454 "-mask filename associate a mask with the image",
3455 "-mattecolor color frame color",
3456 "-monitor monitor progress",
3457 "-orient type image orientation",
3458 "-page geometry size and location of an image canvas (setting)",
3459 "-ping efficiently determine image attributes",
3460 "-pointsize value font point size",
cristy7c1b9fd2010-02-02 14:36:00 +00003461 "-precision value maximum number of significant digits to print",
cristy3ed852e2009-09-05 21:47:34 +00003462 "-preview type image preview type",
3463 "-quality value JPEG/MIFF/PNG compression level",
3464 "-quiet suppress all warning messages",
3465 "-red-primary point chromaticity red primary point",
3466 "-regard-warnings pay attention to warning messages",
3467 "-remap filename transform image colors to match this set of colors",
3468 "-respect-parentheses settings remain in effect until parenthesis boundary",
3469 "-sampling-factor geometry",
3470 " horizontal and vertical sampling factor",
3471 "-scene value image scene number",
3472 "-seed value seed a new sequence of pseudo-random numbers",
3473 "-size geometry width and height of image",
3474 "-stretch type render text with this font stretch",
3475 "-stroke color graphic primitive stroke color",
3476 "-strokewidth value graphic primitive stroke width",
3477 "-style type render text with this font style",
cristyd9a29192010-10-16 16:49:53 +00003478 "-synchronize synchronize image to storage device",
3479 "-taint declare the image as modified",
cristy3ed852e2009-09-05 21:47:34 +00003480 "-texture filename name of texture to tile onto the image background",
3481 "-tile-offset geometry",
3482 " tile offset",
3483 "-treedepth value color tree depth",
3484 "-transparent-color color",
3485 " transparent color",
3486 "-undercolor color annotation bounding box color",
3487 "-units type the units of image resolution",
3488 "-verbose print detailed information about the image",
3489 "-view FlashPix viewing transforms",
3490 "-virtual-pixel method",
3491 " virtual pixel access method",
3492 "-weight type render text with this font weight",
3493 "-white-point point chromaticity white point",
3494 (char *) NULL
3495 },
3496 *stack_operators[]=
3497 {
anthonyb69c4b32011-03-23 04:37:44 +00003498 "-delete indexes delete the image from the image sequence",
3499 "-duplicate count,indexes",
cristyecb10ff2011-03-22 13:14:03 +00003500 " duplicate an image one or more times",
cristy3ed852e2009-09-05 21:47:34 +00003501 "-insert index insert last image into the image sequence",
anthony9bd15492011-03-23 02:11:13 +00003502 "-reverse reverse image sequence",
cristy3ed852e2009-09-05 21:47:34 +00003503 "-swap indexes swap two images in the image sequence",
3504 (char *) NULL
3505 };
3506
3507 const char
3508 **p;
3509
cristybb503372010-05-27 20:51:26 +00003510 (void) printf("Version: %s\n",GetMagickVersion((size_t *) NULL));
cristy610b2e22009-10-22 14:59:43 +00003511 (void) printf("Copyright: %s\n",GetMagickCopyright());
3512 (void) printf("Features: %s\n\n",GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00003513 (void) printf("Usage: %s [options ...] file [ [options ...] file ...]\n",
3514 GetClientName());
3515 (void) printf("\nImage Settings:\n");
3516 for (p=settings; *p != (char *) NULL; p++)
3517 (void) printf(" %s\n",*p);
3518 (void) printf("\nImage Operators:\n");
3519 for (p=operators; *p != (char *) NULL; p++)
3520 (void) printf(" %s\n",*p);
3521 (void) printf("\nImage Sequence Operators:\n");
3522 for (p=sequence_operators; *p != (char *) NULL; p++)
3523 (void) printf(" %s\n",*p);
3524 (void) printf("\nImage Stack Operators:\n");
3525 for (p=stack_operators; *p != (char *) NULL; p++)
3526 (void) printf(" %s\n",*p);
3527 (void) printf("\nMiscellaneous Options:\n");
3528 for (p=miscellaneous; *p != (char *) NULL; p++)
3529 (void) printf(" %s\n",*p);
3530 (void) printf(
3531 "\nBy default, the image format of `file' is determined by its magic\n");
3532 (void) printf(
3533 "number. To specify a particular image format, precede the filename\n");
3534 (void) printf(
3535 "with an image format name and a colon (i.e. ps:image) or specify the\n");
3536 (void) printf(
3537 "image type as the filename suffix (i.e. image.ps). Specify 'file' as\n");
3538 (void) printf("'-' for standard input or output.\n");
3539 return(MagickFalse);
3540}
3541
3542WandExport MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,
3543 int argc,char **argv,char **wand_unused(metadata),ExceptionInfo *exception)
3544{
3545#define DestroyMogrify() \
3546{ \
3547 if (format != (char *) NULL) \
3548 format=DestroyString(format); \
3549 if (path != (char *) NULL) \
3550 path=DestroyString(path); \
3551 DestroyImageStack(); \
cristybb503372010-05-27 20:51:26 +00003552 for (i=0; i < (ssize_t) argc; i++) \
cristy3ed852e2009-09-05 21:47:34 +00003553 argv[i]=DestroyString(argv[i]); \
3554 argv=(char **) RelinquishMagickMemory(argv); \
3555}
3556#define ThrowMogrifyException(asperity,tag,option) \
3557{ \
3558 (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag,"`%s'", \
3559 option); \
3560 DestroyMogrify(); \
3561 return(MagickFalse); \
3562}
3563#define ThrowMogrifyInvalidArgumentException(option,argument) \
3564{ \
3565 (void) ThrowMagickException(exception,GetMagickModule(),OptionError, \
3566 "InvalidArgument","`%s': %s",argument,option); \
3567 DestroyMogrify(); \
3568 return(MagickFalse); \
3569}
3570
3571 char
3572 *format,
3573 *option,
3574 *path;
3575
3576 Image
3577 *image;
3578
3579 ImageStack
3580 image_stack[MaxImageStackDepth+1];
3581
cristy3ed852e2009-09-05 21:47:34 +00003582 MagickBooleanType
3583 global_colormap;
3584
3585 MagickBooleanType
3586 fire,
cristyebbcfea2011-02-25 02:43:54 +00003587 pend,
3588 respect_parenthesis;
cristy3ed852e2009-09-05 21:47:34 +00003589
3590 MagickStatusType
3591 status;
3592
cristyebbcfea2011-02-25 02:43:54 +00003593 register ssize_t
3594 i;
3595
3596 ssize_t
3597 j,
3598 k;
3599
cristy3ed852e2009-09-05 21:47:34 +00003600 /*
3601 Set defaults.
3602 */
3603 assert(image_info != (ImageInfo *) NULL);
3604 assert(image_info->signature == MagickSignature);
3605 if (image_info->debug != MagickFalse)
3606 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3607 assert(exception != (ExceptionInfo *) NULL);
3608 if (argc == 2)
3609 {
3610 option=argv[1];
3611 if ((LocaleCompare("version",option+1) == 0) ||
3612 (LocaleCompare("-version",option+1) == 0))
3613 {
cristyb51dff52011-05-19 16:55:47 +00003614 (void) FormatLocaleFile(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +00003615 GetMagickVersion((size_t *) NULL));
cristy1e604812011-05-19 18:07:50 +00003616 (void) FormatLocaleFile(stdout,"Copyright: %s\n",
3617 GetMagickCopyright());
3618 (void) FormatLocaleFile(stdout,"Features: %s\n\n",
3619 GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00003620 return(MagickFalse);
3621 }
3622 }
3623 if (argc < 2)
cristy13e61a12010-02-04 20:19:00 +00003624 return(MogrifyUsage());
cristy3ed852e2009-09-05 21:47:34 +00003625 format=(char *) NULL;
3626 path=(char *) NULL;
3627 global_colormap=MagickFalse;
3628 k=0;
3629 j=1;
3630 NewImageStack();
3631 option=(char *) NULL;
3632 pend=MagickFalse;
cristyebbcfea2011-02-25 02:43:54 +00003633 respect_parenthesis=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00003634 status=MagickTrue;
3635 /*
3636 Parse command line.
3637 */
3638 ReadCommandlLine(argc,&argv);
3639 status=ExpandFilenames(&argc,&argv);
3640 if (status == MagickFalse)
3641 ThrowMogrifyException(ResourceLimitError,"MemoryAllocationFailed",
3642 GetExceptionMessage(errno));
cristybb503372010-05-27 20:51:26 +00003643 for (i=1; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00003644 {
3645 option=argv[i];
3646 if (LocaleCompare(option,"(") == 0)
3647 {
3648 FireImageStack(MagickFalse,MagickTrue,pend);
3649 if (k == MaxImageStackDepth)
3650 ThrowMogrifyException(OptionError,"ParenthesisNestedTooDeeply",
3651 option);
3652 PushImageStack();
3653 continue;
3654 }
3655 if (LocaleCompare(option,")") == 0)
3656 {
3657 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
3658 if (k == 0)
3659 ThrowMogrifyException(OptionError,"UnableToParseExpression",option);
3660 PopImageStack();
3661 continue;
3662 }
cristy042ee782011-04-22 18:48:30 +00003663 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00003664 {
3665 char
3666 backup_filename[MaxTextExtent],
3667 *filename;
3668
3669 Image
3670 *images;
3671
3672 /*
3673 Option is a file name: begin by reading image from specified file.
3674 */
3675 FireImageStack(MagickFalse,MagickFalse,pend);
3676 filename=argv[i];
cristycee97112010-05-28 00:44:52 +00003677 if ((LocaleCompare(filename,"--") == 0) && (i < (ssize_t) (argc-1)))
cristy3ed852e2009-09-05 21:47:34 +00003678 filename=argv[++i];
3679 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
3680 images=ReadImages(image_info,exception);
3681 status&=(images != (Image *) NULL) &&
3682 (exception->severity < ErrorException);
3683 if (images == (Image *) NULL)
3684 continue;
cristydaa76602010-06-30 13:05:11 +00003685 if (format != (char *) NULL)
3686 (void) CopyMagickString(images->filename,images->magick_filename,
3687 MaxTextExtent);
cristy3ed852e2009-09-05 21:47:34 +00003688 if (path != (char *) NULL)
3689 {
3690 GetPathComponent(option,TailPath,filename);
cristyb51dff52011-05-19 16:55:47 +00003691 (void) FormatLocaleString(images->filename,MaxTextExtent,"%s%c%s",
cristy3ed852e2009-09-05 21:47:34 +00003692 path,*DirectorySeparator,filename);
3693 }
3694 if (format != (char *) NULL)
cristydaa76602010-06-30 13:05:11 +00003695 AppendImageFormat(format,images->filename);
cristy3ed852e2009-09-05 21:47:34 +00003696 AppendImageStack(images);
3697 FinalizeImageSettings(image_info,image,MagickFalse);
3698 if (global_colormap != MagickFalse)
3699 {
3700 QuantizeInfo
3701 *quantize_info;
3702
3703 quantize_info=AcquireQuantizeInfo(image_info);
3704 (void) RemapImages(quantize_info,images,(Image *) NULL);
3705 quantize_info=DestroyQuantizeInfo(quantize_info);
3706 }
3707 *backup_filename='\0';
3708 if ((LocaleCompare(image->filename,"-") != 0) &&
3709 (IsPathWritable(image->filename) != MagickFalse))
3710 {
cristybb503372010-05-27 20:51:26 +00003711 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003712 i;
3713
3714 /*
3715 Rename image file as backup.
3716 */
3717 (void) CopyMagickString(backup_filename,image->filename,
3718 MaxTextExtent);
3719 for (i=0; i < 6; i++)
3720 {
3721 (void) ConcatenateMagickString(backup_filename,"~",MaxTextExtent);
3722 if (IsPathAccessible(backup_filename) == MagickFalse)
3723 break;
3724 }
3725 if ((IsPathAccessible(backup_filename) != MagickFalse) ||
3726 (rename(image->filename,backup_filename) != 0))
3727 *backup_filename='\0';
3728 }
3729 /*
3730 Write transmogrified image to disk.
3731 */
3732 image_info->synchronize=MagickTrue;
3733 status&=WriteImages(image_info,image,image->filename,exception);
3734 if ((status == MagickFalse) && (*backup_filename != '\0'))
3735 (void) remove(backup_filename);
3736 RemoveAllImageStack();
3737 continue;
3738 }
3739 pend=image != (Image *) NULL ? MagickTrue : MagickFalse;
3740 switch (*(option+1))
3741 {
3742 case 'a':
3743 {
3744 if (LocaleCompare("adaptive-blur",option+1) == 0)
3745 {
3746 i++;
cristybb503372010-05-27 20:51:26 +00003747 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003748 ThrowMogrifyException(OptionError,"MissingArgument",option);
3749 if (IsGeometry(argv[i]) == MagickFalse)
3750 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3751 break;
3752 }
3753 if (LocaleCompare("adaptive-resize",option+1) == 0)
3754 {
3755 i++;
cristybb503372010-05-27 20:51:26 +00003756 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003757 ThrowMogrifyException(OptionError,"MissingArgument",option);
3758 if (IsGeometry(argv[i]) == MagickFalse)
3759 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3760 break;
3761 }
3762 if (LocaleCompare("adaptive-sharpen",option+1) == 0)
3763 {
3764 i++;
cristybb503372010-05-27 20:51:26 +00003765 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003766 ThrowMogrifyException(OptionError,"MissingArgument",option);
3767 if (IsGeometry(argv[i]) == MagickFalse)
3768 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3769 break;
3770 }
3771 if (LocaleCompare("affine",option+1) == 0)
3772 {
3773 if (*option == '+')
3774 break;
3775 i++;
cristybb503372010-05-27 20:51:26 +00003776 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003777 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy3ed852e2009-09-05 21:47:34 +00003778 break;
3779 }
3780 if (LocaleCompare("alpha",option+1) == 0)
3781 {
cristybb503372010-05-27 20:51:26 +00003782 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003783 type;
3784
3785 if (*option == '+')
3786 break;
3787 i++;
cristybb503372010-05-27 20:51:26 +00003788 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003789 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00003790 type=ParseCommandOption(MagickAlphaOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00003791 if (type < 0)
3792 ThrowMogrifyException(OptionError,"UnrecognizedAlphaChannelType",
3793 argv[i]);
3794 break;
3795 }
3796 if (LocaleCompare("annotate",option+1) == 0)
3797 {
3798 if (*option == '+')
3799 break;
3800 i++;
cristybb503372010-05-27 20:51:26 +00003801 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003802 ThrowMogrifyException(OptionError,"MissingArgument",option);
3803 if (IsGeometry(argv[i]) == MagickFalse)
3804 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristybb503372010-05-27 20:51:26 +00003805 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003806 ThrowMogrifyException(OptionError,"MissingArgument",option);
3807 i++;
3808 break;
3809 }
3810 if (LocaleCompare("antialias",option+1) == 0)
3811 break;
3812 if (LocaleCompare("append",option+1) == 0)
3813 break;
3814 if (LocaleCompare("attenuate",option+1) == 0)
3815 {
3816 if (*option == '+')
3817 break;
3818 i++;
cristybb503372010-05-27 20:51:26 +00003819 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003820 ThrowMogrifyException(OptionError,"MissingArgument",option);
3821 if (IsGeometry(argv[i]) == MagickFalse)
3822 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3823 break;
3824 }
3825 if (LocaleCompare("authenticate",option+1) == 0)
3826 {
3827 if (*option == '+')
3828 break;
3829 i++;
cristybb503372010-05-27 20:51:26 +00003830 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003831 ThrowMogrifyException(OptionError,"MissingArgument",option);
3832 break;
3833 }
3834 if (LocaleCompare("auto-gamma",option+1) == 0)
3835 break;
3836 if (LocaleCompare("auto-level",option+1) == 0)
3837 break;
3838 if (LocaleCompare("auto-orient",option+1) == 0)
3839 break;
3840 if (LocaleCompare("average",option+1) == 0)
3841 break;
3842 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
3843 }
3844 case 'b':
3845 {
3846 if (LocaleCompare("background",option+1) == 0)
3847 {
3848 if (*option == '+')
3849 break;
3850 i++;
cristybb503372010-05-27 20:51:26 +00003851 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003852 ThrowMogrifyException(OptionError,"MissingArgument",option);
3853 break;
3854 }
3855 if (LocaleCompare("bias",option+1) == 0)
3856 {
3857 if (*option == '+')
3858 break;
3859 i++;
cristybb503372010-05-27 20:51:26 +00003860 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003861 ThrowMogrifyException(OptionError,"MissingArgument",option);
3862 if (IsGeometry(argv[i]) == MagickFalse)
3863 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3864 break;
3865 }
3866 if (LocaleCompare("black-point-compensation",option+1) == 0)
3867 break;
3868 if (LocaleCompare("black-threshold",option+1) == 0)
3869 {
3870 if (*option == '+')
3871 break;
3872 i++;
cristybb503372010-05-27 20:51:26 +00003873 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003874 ThrowMogrifyException(OptionError,"MissingArgument",option);
3875 if (IsGeometry(argv[i]) == MagickFalse)
3876 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3877 break;
3878 }
3879 if (LocaleCompare("blue-primary",option+1) == 0)
3880 {
3881 if (*option == '+')
3882 break;
3883 i++;
cristybb503372010-05-27 20:51:26 +00003884 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003885 ThrowMogrifyException(OptionError,"MissingArgument",option);
3886 if (IsGeometry(argv[i]) == MagickFalse)
3887 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3888 break;
3889 }
3890 if (LocaleCompare("blue-shift",option+1) == 0)
3891 {
3892 i++;
cristybb503372010-05-27 20:51:26 +00003893 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003894 ThrowMogrifyException(OptionError,"MissingArgument",option);
3895 if (IsGeometry(argv[i]) == MagickFalse)
3896 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3897 break;
3898 }
3899 if (LocaleCompare("blur",option+1) == 0)
3900 {
3901 i++;
cristybb503372010-05-27 20:51:26 +00003902 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003903 ThrowMogrifyException(OptionError,"MissingArgument",option);
3904 if (IsGeometry(argv[i]) == MagickFalse)
3905 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3906 break;
3907 }
3908 if (LocaleCompare("border",option+1) == 0)
3909 {
3910 if (*option == '+')
3911 break;
3912 i++;
cristybb503372010-05-27 20:51:26 +00003913 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003914 ThrowMogrifyException(OptionError,"MissingArgument",option);
3915 if (IsGeometry(argv[i]) == MagickFalse)
3916 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3917 break;
3918 }
3919 if (LocaleCompare("bordercolor",option+1) == 0)
3920 {
3921 if (*option == '+')
3922 break;
3923 i++;
cristybb503372010-05-27 20:51:26 +00003924 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003925 ThrowMogrifyException(OptionError,"MissingArgument",option);
3926 break;
3927 }
3928 if (LocaleCompare("box",option+1) == 0)
3929 {
3930 if (*option == '+')
3931 break;
3932 i++;
cristybb503372010-05-27 20:51:26 +00003933 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003934 ThrowMogrifyException(OptionError,"MissingArgument",option);
3935 break;
3936 }
cristya28d6b82010-01-11 20:03:47 +00003937 if (LocaleCompare("brightness-contrast",option+1) == 0)
3938 {
3939 i++;
cristybb503372010-05-27 20:51:26 +00003940 if (i == (ssize_t) argc)
cristya28d6b82010-01-11 20:03:47 +00003941 ThrowMogrifyException(OptionError,"MissingArgument",option);
3942 if (IsGeometry(argv[i]) == MagickFalse)
3943 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3944 break;
3945 }
cristy3ed852e2009-09-05 21:47:34 +00003946 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
3947 }
3948 case 'c':
3949 {
3950 if (LocaleCompare("cache",option+1) == 0)
3951 {
3952 if (*option == '+')
3953 break;
3954 i++;
cristybb503372010-05-27 20:51:26 +00003955 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003956 ThrowMogrifyException(OptionError,"MissingArgument",option);
3957 if (IsGeometry(argv[i]) == MagickFalse)
3958 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3959 break;
3960 }
3961 if (LocaleCompare("caption",option+1) == 0)
3962 {
3963 if (*option == '+')
3964 break;
3965 i++;
cristybb503372010-05-27 20:51:26 +00003966 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003967 ThrowMogrifyException(OptionError,"MissingArgument",option);
3968 break;
3969 }
3970 if (LocaleCompare("channel",option+1) == 0)
3971 {
cristybb503372010-05-27 20:51:26 +00003972 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003973 channel;
3974
3975 if (*option == '+')
3976 break;
3977 i++;
cristybb503372010-05-27 20:51:26 +00003978 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003979 ThrowMogrifyException(OptionError,"MissingArgument",option);
3980 channel=ParseChannelOption(argv[i]);
3981 if (channel < 0)
3982 ThrowMogrifyException(OptionError,"UnrecognizedChannelType",
3983 argv[i]);
3984 break;
3985 }
3986 if (LocaleCompare("cdl",option+1) == 0)
3987 {
3988 if (*option == '+')
3989 break;
3990 i++;
cristybb503372010-05-27 20:51:26 +00003991 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003992 ThrowMogrifyException(OptionError,"MissingArgument",option);
3993 break;
3994 }
3995 if (LocaleCompare("charcoal",option+1) == 0)
3996 {
3997 if (*option == '+')
3998 break;
3999 i++;
cristybb503372010-05-27 20:51:26 +00004000 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004001 ThrowMogrifyException(OptionError,"MissingArgument",option);
4002 if (IsGeometry(argv[i]) == MagickFalse)
4003 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4004 break;
4005 }
4006 if (LocaleCompare("chop",option+1) == 0)
4007 {
4008 if (*option == '+')
4009 break;
4010 i++;
cristybb503372010-05-27 20:51:26 +00004011 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004012 ThrowMogrifyException(OptionError,"MissingArgument",option);
4013 if (IsGeometry(argv[i]) == MagickFalse)
4014 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4015 break;
4016 }
cristy1eb45dd2009-09-25 16:38:06 +00004017 if (LocaleCompare("clamp",option+1) == 0)
4018 break;
4019 if (LocaleCompare("clip",option+1) == 0)
4020 break;
cristy3ed852e2009-09-05 21:47:34 +00004021 if (LocaleCompare("clip-mask",option+1) == 0)
4022 {
4023 if (*option == '+')
4024 break;
4025 i++;
cristybb503372010-05-27 20:51:26 +00004026 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004027 ThrowMogrifyException(OptionError,"MissingArgument",option);
4028 break;
4029 }
4030 if (LocaleCompare("clut",option+1) == 0)
4031 break;
4032 if (LocaleCompare("coalesce",option+1) == 0)
4033 break;
4034 if (LocaleCompare("colorize",option+1) == 0)
4035 {
4036 if (*option == '+')
4037 break;
4038 i++;
cristybb503372010-05-27 20:51:26 +00004039 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004040 ThrowMogrifyException(OptionError,"MissingArgument",option);
4041 if (IsGeometry(argv[i]) == MagickFalse)
4042 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4043 break;
4044 }
cristye6365592010-04-02 17:31:23 +00004045 if (LocaleCompare("color-matrix",option+1) == 0)
4046 {
cristyb6bd4ad2010-08-08 01:12:27 +00004047 KernelInfo
4048 *kernel_info;
4049
cristye6365592010-04-02 17:31:23 +00004050 if (*option == '+')
4051 break;
4052 i++;
cristybb503372010-05-27 20:51:26 +00004053 if (i == (ssize_t) (argc-1))
cristye6365592010-04-02 17:31:23 +00004054 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00004055 kernel_info=AcquireKernelInfo(argv[i]);
4056 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00004057 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00004058 kernel_info=DestroyKernelInfo(kernel_info);
cristye6365592010-04-02 17:31:23 +00004059 break;
4060 }
cristy3ed852e2009-09-05 21:47:34 +00004061 if (LocaleCompare("colors",option+1) == 0)
4062 {
4063 if (*option == '+')
4064 break;
4065 i++;
cristybb503372010-05-27 20:51:26 +00004066 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004067 ThrowMogrifyException(OptionError,"MissingArgument",option);
4068 if (IsGeometry(argv[i]) == MagickFalse)
4069 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4070 break;
4071 }
4072 if (LocaleCompare("colorspace",option+1) == 0)
4073 {
cristybb503372010-05-27 20:51:26 +00004074 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004075 colorspace;
4076
4077 if (*option == '+')
4078 break;
4079 i++;
cristybb503372010-05-27 20:51:26 +00004080 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004081 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004082 colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004083 argv[i]);
4084 if (colorspace < 0)
4085 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
4086 argv[i]);
4087 break;
4088 }
4089 if (LocaleCompare("combine",option+1) == 0)
4090 break;
4091 if (LocaleCompare("comment",option+1) == 0)
4092 {
4093 if (*option == '+')
4094 break;
4095 i++;
cristybb503372010-05-27 20:51:26 +00004096 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004097 ThrowMogrifyException(OptionError,"MissingArgument",option);
4098 break;
4099 }
4100 if (LocaleCompare("composite",option+1) == 0)
4101 break;
4102 if (LocaleCompare("compress",option+1) == 0)
4103 {
cristybb503372010-05-27 20:51:26 +00004104 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004105 compress;
4106
4107 if (*option == '+')
4108 break;
4109 i++;
cristybb503372010-05-27 20:51:26 +00004110 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004111 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004112 compress=ParseCommandOption(MagickCompressOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004113 argv[i]);
4114 if (compress < 0)
4115 ThrowMogrifyException(OptionError,"UnrecognizedImageCompression",
4116 argv[i]);
4117 break;
4118 }
cristy22879752009-10-25 23:55:40 +00004119 if (LocaleCompare("concurrent",option+1) == 0)
4120 break;
cristy3ed852e2009-09-05 21:47:34 +00004121 if (LocaleCompare("contrast",option+1) == 0)
4122 break;
4123 if (LocaleCompare("contrast-stretch",option+1) == 0)
4124 {
4125 i++;
cristybb503372010-05-27 20:51:26 +00004126 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004127 ThrowMogrifyException(OptionError,"MissingArgument",option);
4128 if (IsGeometry(argv[i]) == MagickFalse)
4129 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4130 break;
4131 }
4132 if (LocaleCompare("convolve",option+1) == 0)
4133 {
cristyb6bd4ad2010-08-08 01:12:27 +00004134 KernelInfo
4135 *kernel_info;
4136
cristy3ed852e2009-09-05 21:47:34 +00004137 if (*option == '+')
4138 break;
4139 i++;
cristybb503372010-05-27 20:51:26 +00004140 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004141 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00004142 kernel_info=AcquireKernelInfo(argv[i]);
4143 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00004144 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00004145 kernel_info=DestroyKernelInfo(kernel_info);
cristy3ed852e2009-09-05 21:47:34 +00004146 break;
4147 }
4148 if (LocaleCompare("crop",option+1) == 0)
4149 {
4150 if (*option == '+')
4151 break;
4152 i++;
cristybb503372010-05-27 20:51:26 +00004153 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004154 ThrowMogrifyException(OptionError,"MissingArgument",option);
4155 if (IsGeometry(argv[i]) == MagickFalse)
4156 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4157 break;
4158 }
4159 if (LocaleCompare("cycle",option+1) == 0)
4160 {
4161 if (*option == '+')
4162 break;
4163 i++;
cristybb503372010-05-27 20:51:26 +00004164 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004165 ThrowMogrifyException(OptionError,"MissingArgument",option);
4166 if (IsGeometry(argv[i]) == MagickFalse)
4167 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4168 break;
4169 }
4170 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4171 }
4172 case 'd':
4173 {
4174 if (LocaleCompare("decipher",option+1) == 0)
4175 {
4176 if (*option == '+')
4177 break;
4178 i++;
cristybb503372010-05-27 20:51:26 +00004179 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004180 ThrowMogrifyException(OptionError,"MissingArgument",option);
4181 break;
4182 }
4183 if (LocaleCompare("deconstruct",option+1) == 0)
4184 break;
4185 if (LocaleCompare("debug",option+1) == 0)
4186 {
cristybb503372010-05-27 20:51:26 +00004187 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004188 event;
4189
4190 if (*option == '+')
4191 break;
4192 i++;
cristybb503372010-05-27 20:51:26 +00004193 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004194 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004195 event=ParseCommandOption(MagickLogEventOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004196 if (event < 0)
4197 ThrowMogrifyException(OptionError,"UnrecognizedEventType",
4198 argv[i]);
4199 (void) SetLogEventMask(argv[i]);
4200 break;
4201 }
4202 if (LocaleCompare("define",option+1) == 0)
4203 {
4204 i++;
cristybb503372010-05-27 20:51:26 +00004205 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004206 ThrowMogrifyException(OptionError,"MissingArgument",option);
4207 if (*option == '+')
4208 {
4209 const char
4210 *define;
4211
4212 define=GetImageOption(image_info,argv[i]);
4213 if (define == (const char *) NULL)
4214 ThrowMogrifyException(OptionError,"NoSuchOption",argv[i]);
4215 break;
4216 }
4217 break;
4218 }
4219 if (LocaleCompare("delay",option+1) == 0)
4220 {
4221 if (*option == '+')
4222 break;
4223 i++;
cristybb503372010-05-27 20:51:26 +00004224 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004225 ThrowMogrifyException(OptionError,"MissingArgument",option);
4226 if (IsGeometry(argv[i]) == MagickFalse)
4227 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4228 break;
4229 }
cristyecb10ff2011-03-22 13:14:03 +00004230 if (LocaleCompare("delete",option+1) == 0)
4231 {
4232 if (*option == '+')
4233 break;
4234 i++;
4235 if (i == (ssize_t) (argc-1))
4236 ThrowMogrifyException(OptionError,"MissingArgument",option);
4237 if (IsGeometry(argv[i]) == MagickFalse)
4238 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4239 break;
4240 }
cristy3ed852e2009-09-05 21:47:34 +00004241 if (LocaleCompare("density",option+1) == 0)
4242 {
4243 if (*option == '+')
4244 break;
4245 i++;
cristybb503372010-05-27 20:51:26 +00004246 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004247 ThrowMogrifyException(OptionError,"MissingArgument",option);
4248 if (IsGeometry(argv[i]) == MagickFalse)
4249 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4250 break;
4251 }
4252 if (LocaleCompare("depth",option+1) == 0)
4253 {
4254 if (*option == '+')
4255 break;
4256 i++;
cristybb503372010-05-27 20:51:26 +00004257 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004258 ThrowMogrifyException(OptionError,"MissingArgument",option);
4259 if (IsGeometry(argv[i]) == MagickFalse)
4260 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4261 break;
4262 }
4263 if (LocaleCompare("deskew",option+1) == 0)
4264 {
4265 if (*option == '+')
4266 break;
4267 i++;
cristybb503372010-05-27 20:51:26 +00004268 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004269 ThrowMogrifyException(OptionError,"MissingArgument",option);
4270 if (IsGeometry(argv[i]) == MagickFalse)
4271 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4272 break;
4273 }
4274 if (LocaleCompare("despeckle",option+1) == 0)
4275 break;
4276 if (LocaleCompare("dft",option+1) == 0)
4277 break;
cristyc9b12952010-03-28 01:12:28 +00004278 if (LocaleCompare("direction",option+1) == 0)
4279 {
cristybb503372010-05-27 20:51:26 +00004280 ssize_t
cristyc9b12952010-03-28 01:12:28 +00004281 direction;
4282
4283 if (*option == '+')
4284 break;
4285 i++;
cristybb503372010-05-27 20:51:26 +00004286 if (i == (ssize_t) argc)
cristyc9b12952010-03-28 01:12:28 +00004287 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004288 direction=ParseCommandOption(MagickDirectionOptions,MagickFalse,
cristyc9b12952010-03-28 01:12:28 +00004289 argv[i]);
4290 if (direction < 0)
4291 ThrowMogrifyException(OptionError,"UnrecognizedDirectionType",
4292 argv[i]);
4293 break;
4294 }
cristy3ed852e2009-09-05 21:47:34 +00004295 if (LocaleCompare("display",option+1) == 0)
4296 {
4297 if (*option == '+')
4298 break;
4299 i++;
cristybb503372010-05-27 20:51:26 +00004300 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004301 ThrowMogrifyException(OptionError,"MissingArgument",option);
4302 break;
4303 }
4304 if (LocaleCompare("dispose",option+1) == 0)
4305 {
cristybb503372010-05-27 20:51:26 +00004306 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004307 dispose;
4308
4309 if (*option == '+')
4310 break;
4311 i++;
cristybb503372010-05-27 20:51:26 +00004312 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004313 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004314 dispose=ParseCommandOption(MagickDisposeOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004315 if (dispose < 0)
4316 ThrowMogrifyException(OptionError,"UnrecognizedDisposeMethod",
4317 argv[i]);
4318 break;
4319 }
4320 if (LocaleCompare("distort",option+1) == 0)
4321 {
cristybb503372010-05-27 20:51:26 +00004322 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004323 op;
4324
4325 i++;
cristybb503372010-05-27 20:51:26 +00004326 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004327 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004328 op=ParseCommandOption(MagickDistortOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004329 if (op < 0)
4330 ThrowMogrifyException(OptionError,"UnrecognizedDistortMethod",
4331 argv[i]);
4332 i++;
cristybb503372010-05-27 20:51:26 +00004333 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004334 ThrowMogrifyException(OptionError,"MissingArgument",option);
4335 break;
4336 }
4337 if (LocaleCompare("dither",option+1) == 0)
4338 {
cristybb503372010-05-27 20:51:26 +00004339 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004340 method;
4341
4342 if (*option == '+')
4343 break;
4344 i++;
cristybb503372010-05-27 20:51:26 +00004345 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004346 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004347 method=ParseCommandOption(MagickDitherOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004348 if (method < 0)
4349 ThrowMogrifyException(OptionError,"UnrecognizedDitherMethod",
4350 argv[i]);
4351 break;
4352 }
4353 if (LocaleCompare("draw",option+1) == 0)
4354 {
4355 if (*option == '+')
4356 break;
4357 i++;
cristybb503372010-05-27 20:51:26 +00004358 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004359 ThrowMogrifyException(OptionError,"MissingArgument",option);
4360 break;
4361 }
cristyecb10ff2011-03-22 13:14:03 +00004362 if (LocaleCompare("duplicate",option+1) == 0)
4363 {
4364 if (*option == '+')
4365 break;
4366 i++;
4367 if (i == (ssize_t) (argc-1))
4368 ThrowMogrifyException(OptionError,"MissingArgument",option);
4369 if (IsGeometry(argv[i]) == MagickFalse)
4370 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4371 break;
4372 }
cristy22879752009-10-25 23:55:40 +00004373 if (LocaleCompare("duration",option+1) == 0)
4374 {
4375 if (*option == '+')
4376 break;
4377 i++;
cristybb503372010-05-27 20:51:26 +00004378 if (i == (ssize_t) (argc-1))
cristy22879752009-10-25 23:55:40 +00004379 ThrowMogrifyException(OptionError,"MissingArgument",option);
4380 if (IsGeometry(argv[i]) == MagickFalse)
4381 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4382 break;
4383 }
cristy3ed852e2009-09-05 21:47:34 +00004384 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4385 }
4386 case 'e':
4387 {
4388 if (LocaleCompare("edge",option+1) == 0)
4389 {
4390 if (*option == '+')
4391 break;
4392 i++;
cristybb503372010-05-27 20:51:26 +00004393 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004394 ThrowMogrifyException(OptionError,"MissingArgument",option);
4395 if (IsGeometry(argv[i]) == MagickFalse)
4396 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4397 break;
4398 }
4399 if (LocaleCompare("emboss",option+1) == 0)
4400 {
4401 if (*option == '+')
4402 break;
4403 i++;
cristybb503372010-05-27 20:51:26 +00004404 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004405 ThrowMogrifyException(OptionError,"MissingArgument",option);
4406 if (IsGeometry(argv[i]) == MagickFalse)
4407 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4408 break;
4409 }
4410 if (LocaleCompare("encipher",option+1) == 0)
4411 {
4412 if (*option == '+')
4413 break;
4414 i++;
cristybb503372010-05-27 20:51:26 +00004415 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004416 ThrowMogrifyException(OptionError,"MissingArgument",option);
4417 break;
4418 }
4419 if (LocaleCompare("encoding",option+1) == 0)
4420 {
4421 if (*option == '+')
4422 break;
4423 i++;
cristybb503372010-05-27 20:51:26 +00004424 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004425 ThrowMogrifyException(OptionError,"MissingArgument",option);
4426 break;
4427 }
4428 if (LocaleCompare("endian",option+1) == 0)
4429 {
cristybb503372010-05-27 20:51:26 +00004430 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004431 endian;
4432
4433 if (*option == '+')
4434 break;
4435 i++;
cristybb503372010-05-27 20:51:26 +00004436 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004437 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004438 endian=ParseCommandOption(MagickEndianOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004439 if (endian < 0)
4440 ThrowMogrifyException(OptionError,"UnrecognizedEndianType",
4441 argv[i]);
4442 break;
4443 }
4444 if (LocaleCompare("enhance",option+1) == 0)
4445 break;
4446 if (LocaleCompare("equalize",option+1) == 0)
4447 break;
4448 if (LocaleCompare("evaluate",option+1) == 0)
4449 {
cristybb503372010-05-27 20:51:26 +00004450 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004451 op;
4452
4453 if (*option == '+')
4454 break;
4455 i++;
cristybb503372010-05-27 20:51:26 +00004456 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004457 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004458 op=ParseCommandOption(MagickEvaluateOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004459 if (op < 0)
4460 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4461 argv[i]);
4462 i++;
cristybb503372010-05-27 20:51:26 +00004463 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004464 ThrowMogrifyException(OptionError,"MissingArgument",option);
4465 if (IsGeometry(argv[i]) == MagickFalse)
4466 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4467 break;
4468 }
cristyd18ae7c2010-03-07 17:39:52 +00004469 if (LocaleCompare("evaluate-sequence",option+1) == 0)
4470 {
cristybb503372010-05-27 20:51:26 +00004471 ssize_t
cristyd18ae7c2010-03-07 17:39:52 +00004472 op;
4473
4474 if (*option == '+')
4475 break;
4476 i++;
cristybb503372010-05-27 20:51:26 +00004477 if (i == (ssize_t) argc)
cristyd18ae7c2010-03-07 17:39:52 +00004478 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004479 op=ParseCommandOption(MagickEvaluateOptions,MagickFalse,argv[i]);
cristyd18ae7c2010-03-07 17:39:52 +00004480 if (op < 0)
4481 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4482 argv[i]);
4483 break;
4484 }
cristy3ed852e2009-09-05 21:47:34 +00004485 if (LocaleCompare("extent",option+1) == 0)
4486 {
4487 if (*option == '+')
4488 break;
4489 i++;
cristybb503372010-05-27 20:51:26 +00004490 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004491 ThrowMogrifyException(OptionError,"MissingArgument",option);
4492 if (IsGeometry(argv[i]) == MagickFalse)
4493 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4494 break;
4495 }
4496 if (LocaleCompare("extract",option+1) == 0)
4497 {
4498 if (*option == '+')
4499 break;
4500 i++;
cristybb503372010-05-27 20:51:26 +00004501 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004502 ThrowMogrifyException(OptionError,"MissingArgument",option);
4503 if (IsGeometry(argv[i]) == MagickFalse)
4504 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4505 break;
4506 }
4507 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4508 }
4509 case 'f':
4510 {
4511 if (LocaleCompare("family",option+1) == 0)
4512 {
4513 if (*option == '+')
4514 break;
4515 i++;
cristybb503372010-05-27 20:51:26 +00004516 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004517 ThrowMogrifyException(OptionError,"MissingArgument",option);
4518 break;
4519 }
4520 if (LocaleCompare("fill",option+1) == 0)
4521 {
4522 if (*option == '+')
4523 break;
4524 i++;
cristybb503372010-05-27 20:51:26 +00004525 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004526 ThrowMogrifyException(OptionError,"MissingArgument",option);
4527 break;
4528 }
4529 if (LocaleCompare("filter",option+1) == 0)
4530 {
cristybb503372010-05-27 20:51:26 +00004531 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004532 filter;
4533
4534 if (*option == '+')
4535 break;
4536 i++;
cristybb503372010-05-27 20:51:26 +00004537 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004538 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004539 filter=ParseCommandOption(MagickFilterOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004540 if (filter < 0)
4541 ThrowMogrifyException(OptionError,"UnrecognizedImageFilter",
4542 argv[i]);
4543 break;
4544 }
4545 if (LocaleCompare("flatten",option+1) == 0)
4546 break;
4547 if (LocaleCompare("flip",option+1) == 0)
4548 break;
4549 if (LocaleCompare("flop",option+1) == 0)
4550 break;
4551 if (LocaleCompare("floodfill",option+1) == 0)
4552 {
4553 if (*option == '+')
4554 break;
4555 i++;
cristybb503372010-05-27 20:51:26 +00004556 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004557 ThrowMogrifyException(OptionError,"MissingArgument",option);
4558 if (IsGeometry(argv[i]) == MagickFalse)
4559 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4560 i++;
cristybb503372010-05-27 20:51:26 +00004561 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004562 ThrowMogrifyException(OptionError,"MissingArgument",option);
4563 break;
4564 }
4565 if (LocaleCompare("font",option+1) == 0)
4566 {
4567 if (*option == '+')
4568 break;
4569 i++;
cristybb503372010-05-27 20:51:26 +00004570 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004571 ThrowMogrifyException(OptionError,"MissingArgument",option);
4572 break;
4573 }
4574 if (LocaleCompare("format",option+1) == 0)
4575 {
4576 (void) CopyMagickString(argv[i]+1,"sans",MaxTextExtent);
4577 (void) CloneString(&format,(char *) NULL);
4578 if (*option == '+')
4579 break;
4580 i++;
cristybb503372010-05-27 20:51:26 +00004581 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004582 ThrowMogrifyException(OptionError,"MissingArgument",option);
4583 (void) CloneString(&format,argv[i]);
4584 (void) CopyMagickString(image_info->filename,format,MaxTextExtent);
4585 (void) ConcatenateMagickString(image_info->filename,":",
4586 MaxTextExtent);
cristyd965a422010-03-03 17:47:35 +00004587 (void) SetImageInfo(image_info,0,exception);
cristy3ed852e2009-09-05 21:47:34 +00004588 if (*image_info->magick == '\0')
4589 ThrowMogrifyException(OptionError,"UnrecognizedImageFormat",
4590 format);
4591 break;
4592 }
4593 if (LocaleCompare("frame",option+1) == 0)
4594 {
4595 if (*option == '+')
4596 break;
4597 i++;
cristybb503372010-05-27 20:51:26 +00004598 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004599 ThrowMogrifyException(OptionError,"MissingArgument",option);
4600 if (IsGeometry(argv[i]) == MagickFalse)
4601 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4602 break;
4603 }
4604 if (LocaleCompare("function",option+1) == 0)
4605 {
cristybb503372010-05-27 20:51:26 +00004606 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004607 op;
4608
4609 if (*option == '+')
4610 break;
4611 i++;
cristybb503372010-05-27 20:51:26 +00004612 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004613 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004614 op=ParseCommandOption(MagickFunctionOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004615 if (op < 0)
4616 ThrowMogrifyException(OptionError,"UnrecognizedFunction",argv[i]);
4617 i++;
cristybb503372010-05-27 20:51:26 +00004618 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004619 ThrowMogrifyException(OptionError,"MissingArgument",option);
4620 break;
4621 }
4622 if (LocaleCompare("fuzz",option+1) == 0)
4623 {
4624 if (*option == '+')
4625 break;
4626 i++;
cristybb503372010-05-27 20:51:26 +00004627 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004628 ThrowMogrifyException(OptionError,"MissingArgument",option);
4629 if (IsGeometry(argv[i]) == MagickFalse)
4630 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4631 break;
4632 }
4633 if (LocaleCompare("fx",option+1) == 0)
4634 {
4635 if (*option == '+')
4636 break;
4637 i++;
cristybb503372010-05-27 20:51:26 +00004638 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004639 ThrowMogrifyException(OptionError,"MissingArgument",option);
4640 break;
4641 }
4642 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4643 }
4644 case 'g':
4645 {
4646 if (LocaleCompare("gamma",option+1) == 0)
4647 {
4648 i++;
cristybb503372010-05-27 20:51:26 +00004649 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004650 ThrowMogrifyException(OptionError,"MissingArgument",option);
4651 if (IsGeometry(argv[i]) == MagickFalse)
4652 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4653 break;
4654 }
4655 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
4656 (LocaleCompare("gaussian",option+1) == 0))
4657 {
4658 i++;
cristybb503372010-05-27 20:51:26 +00004659 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004660 ThrowMogrifyException(OptionError,"MissingArgument",option);
4661 if (IsGeometry(argv[i]) == MagickFalse)
4662 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4663 break;
4664 }
4665 if (LocaleCompare("geometry",option+1) == 0)
4666 {
4667 if (*option == '+')
4668 break;
4669 i++;
cristybb503372010-05-27 20:51:26 +00004670 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004671 ThrowMogrifyException(OptionError,"MissingArgument",option);
4672 if (IsGeometry(argv[i]) == MagickFalse)
4673 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4674 break;
4675 }
4676 if (LocaleCompare("gravity",option+1) == 0)
4677 {
cristybb503372010-05-27 20:51:26 +00004678 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004679 gravity;
4680
4681 if (*option == '+')
4682 break;
4683 i++;
cristybb503372010-05-27 20:51:26 +00004684 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004685 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004686 gravity=ParseCommandOption(MagickGravityOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004687 if (gravity < 0)
4688 ThrowMogrifyException(OptionError,"UnrecognizedGravityType",
4689 argv[i]);
4690 break;
4691 }
4692 if (LocaleCompare("green-primary",option+1) == 0)
4693 {
4694 if (*option == '+')
4695 break;
4696 i++;
cristybb503372010-05-27 20:51:26 +00004697 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004698 ThrowMogrifyException(OptionError,"MissingArgument",option);
4699 if (IsGeometry(argv[i]) == MagickFalse)
4700 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4701 break;
4702 }
4703 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4704 }
4705 case 'h':
4706 {
4707 if (LocaleCompare("hald-clut",option+1) == 0)
4708 break;
4709 if ((LocaleCompare("help",option+1) == 0) ||
4710 (LocaleCompare("-help",option+1) == 0))
4711 return(MogrifyUsage());
4712 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4713 }
4714 case 'i':
4715 {
4716 if (LocaleCompare("identify",option+1) == 0)
4717 break;
4718 if (LocaleCompare("idft",option+1) == 0)
4719 break;
4720 if (LocaleCompare("implode",option+1) == 0)
4721 {
4722 if (*option == '+')
4723 break;
4724 i++;
cristybb503372010-05-27 20:51:26 +00004725 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004726 ThrowMogrifyException(OptionError,"MissingArgument",option);
4727 if (IsGeometry(argv[i]) == MagickFalse)
4728 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4729 break;
4730 }
4731 if (LocaleCompare("intent",option+1) == 0)
4732 {
cristybb503372010-05-27 20:51:26 +00004733 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004734 intent;
4735
4736 if (*option == '+')
4737 break;
4738 i++;
cristybb503372010-05-27 20:51:26 +00004739 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004740 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004741 intent=ParseCommandOption(MagickIntentOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004742 if (intent < 0)
4743 ThrowMogrifyException(OptionError,"UnrecognizedIntentType",
4744 argv[i]);
4745 break;
4746 }
4747 if (LocaleCompare("interlace",option+1) == 0)
4748 {
cristybb503372010-05-27 20:51:26 +00004749 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004750 interlace;
4751
4752 if (*option == '+')
4753 break;
4754 i++;
cristybb503372010-05-27 20:51:26 +00004755 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004756 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004757 interlace=ParseCommandOption(MagickInterlaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004758 argv[i]);
4759 if (interlace < 0)
4760 ThrowMogrifyException(OptionError,"UnrecognizedInterlaceType",
4761 argv[i]);
4762 break;
4763 }
cristyb32b90a2009-09-07 21:45:48 +00004764 if (LocaleCompare("interline-spacing",option+1) == 0)
4765 {
4766 if (*option == '+')
4767 break;
4768 i++;
cristybb503372010-05-27 20:51:26 +00004769 if (i == (ssize_t) (argc-1))
cristyb32b90a2009-09-07 21:45:48 +00004770 ThrowMogrifyException(OptionError,"MissingArgument",option);
4771 if (IsGeometry(argv[i]) == MagickFalse)
4772 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4773 break;
4774 }
cristy3ed852e2009-09-05 21:47:34 +00004775 if (LocaleCompare("interpolate",option+1) == 0)
4776 {
cristybb503372010-05-27 20:51:26 +00004777 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004778 interpolate;
4779
4780 if (*option == '+')
4781 break;
4782 i++;
cristybb503372010-05-27 20:51:26 +00004783 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004784 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004785 interpolate=ParseCommandOption(MagickInterpolateOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004786 argv[i]);
4787 if (interpolate < 0)
4788 ThrowMogrifyException(OptionError,"UnrecognizedInterpolateMethod",
4789 argv[i]);
4790 break;
4791 }
4792 if (LocaleCompare("interword-spacing",option+1) == 0)
4793 {
4794 if (*option == '+')
4795 break;
4796 i++;
cristybb503372010-05-27 20:51:26 +00004797 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004798 ThrowMogrifyException(OptionError,"MissingArgument",option);
4799 if (IsGeometry(argv[i]) == MagickFalse)
4800 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4801 break;
4802 }
4803 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4804 }
4805 case 'k':
4806 {
4807 if (LocaleCompare("kerning",option+1) == 0)
4808 {
4809 if (*option == '+')
4810 break;
4811 i++;
cristybb503372010-05-27 20:51:26 +00004812 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004813 ThrowMogrifyException(OptionError,"MissingArgument",option);
4814 if (IsGeometry(argv[i]) == MagickFalse)
4815 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4816 break;
4817 }
4818 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4819 }
4820 case 'l':
4821 {
4822 if (LocaleCompare("label",option+1) == 0)
4823 {
4824 if (*option == '+')
4825 break;
4826 i++;
cristybb503372010-05-27 20:51:26 +00004827 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004828 ThrowMogrifyException(OptionError,"MissingArgument",option);
4829 break;
4830 }
4831 if (LocaleCompare("lat",option+1) == 0)
4832 {
4833 if (*option == '+')
4834 break;
4835 i++;
cristybb503372010-05-27 20:51:26 +00004836 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004837 ThrowMogrifyException(OptionError,"MissingArgument",option);
4838 if (IsGeometry(argv[i]) == MagickFalse)
4839 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4840 }
4841 if (LocaleCompare("layers",option+1) == 0)
4842 {
cristybb503372010-05-27 20:51:26 +00004843 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004844 type;
4845
4846 if (*option == '+')
4847 break;
4848 i++;
cristybb503372010-05-27 20:51:26 +00004849 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004850 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004851 type=ParseCommandOption(MagickLayerOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004852 if (type < 0)
4853 ThrowMogrifyException(OptionError,"UnrecognizedLayerMethod",
4854 argv[i]);
4855 break;
4856 }
4857 if (LocaleCompare("level",option+1) == 0)
4858 {
4859 i++;
cristybb503372010-05-27 20:51:26 +00004860 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004861 ThrowMogrifyException(OptionError,"MissingArgument",option);
4862 if (IsGeometry(argv[i]) == MagickFalse)
4863 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4864 break;
4865 }
4866 if (LocaleCompare("level-colors",option+1) == 0)
4867 {
4868 i++;
cristybb503372010-05-27 20:51:26 +00004869 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004870 ThrowMogrifyException(OptionError,"MissingArgument",option);
4871 break;
4872 }
4873 if (LocaleCompare("linewidth",option+1) == 0)
4874 {
4875 if (*option == '+')
4876 break;
4877 i++;
cristybb503372010-05-27 20:51:26 +00004878 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004879 ThrowMogrifyException(OptionError,"MissingArgument",option);
4880 if (IsGeometry(argv[i]) == MagickFalse)
4881 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4882 break;
4883 }
4884 if (LocaleCompare("limit",option+1) == 0)
4885 {
4886 char
4887 *p;
4888
4889 double
4890 value;
4891
cristybb503372010-05-27 20:51:26 +00004892 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004893 resource;
4894
4895 if (*option == '+')
4896 break;
4897 i++;
cristybb503372010-05-27 20:51:26 +00004898 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004899 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004900 resource=ParseCommandOption(MagickResourceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004901 argv[i]);
4902 if (resource < 0)
4903 ThrowMogrifyException(OptionError,"UnrecognizedResourceType",
4904 argv[i]);
4905 i++;
cristybb503372010-05-27 20:51:26 +00004906 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004907 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyc1acd842011-05-19 23:05:47 +00004908 value=InterpretLocaleValue(argv[i],&p);
cristyda16f162011-02-19 23:52:17 +00004909 (void) value;
cristy3ed852e2009-09-05 21:47:34 +00004910 if ((p == argv[i]) && (LocaleCompare("unlimited",argv[i]) != 0))
4911 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4912 break;
4913 }
4914 if (LocaleCompare("liquid-rescale",option+1) == 0)
4915 {
4916 i++;
cristybb503372010-05-27 20:51:26 +00004917 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004918 ThrowMogrifyException(OptionError,"MissingArgument",option);
4919 if (IsGeometry(argv[i]) == MagickFalse)
4920 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4921 break;
4922 }
4923 if (LocaleCompare("list",option+1) == 0)
4924 {
cristybb503372010-05-27 20:51:26 +00004925 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004926 list;
4927
4928 if (*option == '+')
4929 break;
4930 i++;
cristybb503372010-05-27 20:51:26 +00004931 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004932 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004933 list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004934 if (list < 0)
4935 ThrowMogrifyException(OptionError,"UnrecognizedListType",argv[i]);
cristyaeb2cbc2010-05-07 13:28:58 +00004936 status=MogrifyImageInfo(image_info,(int) (i-j+1),(const char **)
cristy3ed852e2009-09-05 21:47:34 +00004937 argv+j,exception);
cristyaeb2cbc2010-05-07 13:28:58 +00004938 return(status != 0 ? MagickFalse : MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00004939 }
4940 if (LocaleCompare("log",option+1) == 0)
4941 {
4942 if (*option == '+')
4943 break;
4944 i++;
cristybb503372010-05-27 20:51:26 +00004945 if ((i == (ssize_t) argc) ||
cristy3ed852e2009-09-05 21:47:34 +00004946 (strchr(argv[i],'%') == (char *) NULL))
4947 ThrowMogrifyException(OptionError,"MissingArgument",option);
4948 break;
4949 }
4950 if (LocaleCompare("loop",option+1) == 0)
4951 {
4952 if (*option == '+')
4953 break;
4954 i++;
cristybb503372010-05-27 20:51:26 +00004955 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004956 ThrowMogrifyException(OptionError,"MissingArgument",option);
4957 if (IsGeometry(argv[i]) == MagickFalse)
4958 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4959 break;
4960 }
4961 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4962 }
4963 case 'm':
4964 {
4965 if (LocaleCompare("map",option+1) == 0)
4966 {
4967 global_colormap=(*option == '+') ? MagickTrue : MagickFalse;
4968 if (*option == '+')
4969 break;
4970 i++;
cristybb503372010-05-27 20:51:26 +00004971 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004972 ThrowMogrifyException(OptionError,"MissingArgument",option);
4973 break;
4974 }
4975 if (LocaleCompare("mask",option+1) == 0)
4976 {
4977 if (*option == '+')
4978 break;
4979 i++;
cristybb503372010-05-27 20:51:26 +00004980 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004981 ThrowMogrifyException(OptionError,"MissingArgument",option);
4982 break;
4983 }
4984 if (LocaleCompare("matte",option+1) == 0)
4985 break;
4986 if (LocaleCompare("mattecolor",option+1) == 0)
4987 {
4988 if (*option == '+')
4989 break;
4990 i++;
cristybb503372010-05-27 20:51:26 +00004991 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004992 ThrowMogrifyException(OptionError,"MissingArgument",option);
4993 break;
4994 }
cristyf40785b2010-03-06 02:27:27 +00004995 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00004996 break;
cristyf40785b2010-03-06 02:27:27 +00004997 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00004998 break;
cristy3ed852e2009-09-05 21:47:34 +00004999 if (LocaleCompare("modulate",option+1) == 0)
5000 {
5001 if (*option == '+')
5002 break;
5003 i++;
cristybb503372010-05-27 20:51:26 +00005004 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005005 ThrowMogrifyException(OptionError,"MissingArgument",option);
5006 if (IsGeometry(argv[i]) == MagickFalse)
5007 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5008 break;
5009 }
5010 if (LocaleCompare("median",option+1) == 0)
5011 {
5012 if (*option == '+')
5013 break;
5014 i++;
cristybb503372010-05-27 20:51:26 +00005015 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005016 ThrowMogrifyException(OptionError,"MissingArgument",option);
5017 if (IsGeometry(argv[i]) == MagickFalse)
5018 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5019 break;
5020 }
cristy69ec32d2011-02-27 23:57:09 +00005021 if (LocaleCompare("mode",option+1) == 0)
5022 {
5023 if (*option == '+')
5024 break;
5025 i++;
5026 if (i == (ssize_t) argc)
5027 ThrowMogrifyException(OptionError,"MissingArgument",option);
5028 if (IsGeometry(argv[i]) == MagickFalse)
5029 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5030 break;
5031 }
cristy3ed852e2009-09-05 21:47:34 +00005032 if (LocaleCompare("monitor",option+1) == 0)
5033 break;
5034 if (LocaleCompare("monochrome",option+1) == 0)
5035 break;
5036 if (LocaleCompare("morph",option+1) == 0)
5037 {
5038 if (*option == '+')
5039 break;
5040 i++;
cristybb503372010-05-27 20:51:26 +00005041 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005042 ThrowMogrifyException(OptionError,"MissingArgument",option);
5043 if (IsGeometry(argv[i]) == MagickFalse)
5044 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5045 break;
5046 }
anthony29188a82010-01-22 10:12:34 +00005047 if (LocaleCompare("morphology",option+1) == 0)
5048 {
anthony29188a82010-01-22 10:12:34 +00005049 char
5050 token[MaxTextExtent];
5051
cristyb6bd4ad2010-08-08 01:12:27 +00005052 KernelInfo
5053 *kernel_info;
5054
5055 ssize_t
5056 op;
5057
anthony29188a82010-01-22 10:12:34 +00005058 i++;
cristybb503372010-05-27 20:51:26 +00005059 if (i == (ssize_t) argc)
anthony29188a82010-01-22 10:12:34 +00005060 ThrowMogrifyException(OptionError,"MissingArgument",option);
5061 GetMagickToken(argv[i],NULL,token);
cristy042ee782011-04-22 18:48:30 +00005062 op=ParseCommandOption(MagickMorphologyOptions,MagickFalse,token);
anthony29188a82010-01-22 10:12:34 +00005063 if (op < 0)
5064 ThrowMogrifyException(OptionError,"UnrecognizedMorphologyMethod",
cristyf0c78232010-03-15 12:53:40 +00005065 token);
anthony29188a82010-01-22 10:12:34 +00005066 i++;
cristybb503372010-05-27 20:51:26 +00005067 if (i == (ssize_t) (argc-1))
anthony29188a82010-01-22 10:12:34 +00005068 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00005069 kernel_info=AcquireKernelInfo(argv[i]);
5070 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00005071 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00005072 kernel_info=DestroyKernelInfo(kernel_info);
anthony29188a82010-01-22 10:12:34 +00005073 break;
5074 }
cristy3ed852e2009-09-05 21:47:34 +00005075 if (LocaleCompare("mosaic",option+1) == 0)
5076 break;
5077 if (LocaleCompare("motion-blur",option+1) == 0)
5078 {
5079 if (*option == '+')
5080 break;
5081 i++;
cristybb503372010-05-27 20:51:26 +00005082 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005083 ThrowMogrifyException(OptionError,"MissingArgument",option);
5084 if (IsGeometry(argv[i]) == MagickFalse)
5085 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5086 break;
5087 }
5088 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5089 }
5090 case 'n':
5091 {
5092 if (LocaleCompare("negate",option+1) == 0)
5093 break;
5094 if (LocaleCompare("noise",option+1) == 0)
5095 {
5096 i++;
cristybb503372010-05-27 20:51:26 +00005097 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005098 ThrowMogrifyException(OptionError,"MissingArgument",option);
5099 if (*option == '+')
5100 {
cristybb503372010-05-27 20:51:26 +00005101 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005102 noise;
5103
cristy042ee782011-04-22 18:48:30 +00005104 noise=ParseCommandOption(MagickNoiseOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005105 if (noise < 0)
5106 ThrowMogrifyException(OptionError,"UnrecognizedNoiseType",
5107 argv[i]);
5108 break;
5109 }
5110 if (IsGeometry(argv[i]) == MagickFalse)
5111 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5112 break;
5113 }
5114 if (LocaleCompare("noop",option+1) == 0)
5115 break;
5116 if (LocaleCompare("normalize",option+1) == 0)
5117 break;
5118 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5119 }
5120 case 'o':
5121 {
5122 if (LocaleCompare("opaque",option+1) == 0)
5123 {
cristy3ed852e2009-09-05 21:47:34 +00005124 i++;
cristybb503372010-05-27 20:51:26 +00005125 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005126 ThrowMogrifyException(OptionError,"MissingArgument",option);
5127 break;
5128 }
5129 if (LocaleCompare("ordered-dither",option+1) == 0)
5130 {
5131 if (*option == '+')
5132 break;
5133 i++;
cristybb503372010-05-27 20:51:26 +00005134 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005135 ThrowMogrifyException(OptionError,"MissingArgument",option);
5136 break;
5137 }
5138 if (LocaleCompare("orient",option+1) == 0)
5139 {
cristybb503372010-05-27 20:51:26 +00005140 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005141 orientation;
5142
5143 orientation=UndefinedOrientation;
5144 if (*option == '+')
5145 break;
5146 i++;
cristybb503372010-05-27 20:51:26 +00005147 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005148 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005149 orientation=ParseCommandOption(MagickOrientationOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005150 argv[i]);
5151 if (orientation < 0)
5152 ThrowMogrifyException(OptionError,"UnrecognizedImageOrientation",
5153 argv[i]);
5154 break;
5155 }
5156 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5157 }
5158 case 'p':
5159 {
5160 if (LocaleCompare("page",option+1) == 0)
5161 {
5162 if (*option == '+')
5163 break;
5164 i++;
cristybb503372010-05-27 20:51:26 +00005165 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005166 ThrowMogrifyException(OptionError,"MissingArgument",option);
5167 break;
5168 }
5169 if (LocaleCompare("paint",option+1) == 0)
5170 {
5171 if (*option == '+')
5172 break;
5173 i++;
cristybb503372010-05-27 20:51:26 +00005174 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005175 ThrowMogrifyException(OptionError,"MissingArgument",option);
5176 if (IsGeometry(argv[i]) == MagickFalse)
5177 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5178 break;
5179 }
5180 if (LocaleCompare("path",option+1) == 0)
5181 {
5182 (void) CloneString(&path,(char *) NULL);
5183 if (*option == '+')
5184 break;
5185 i++;
cristybb503372010-05-27 20:51:26 +00005186 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005187 ThrowMogrifyException(OptionError,"MissingArgument",option);
5188 (void) CloneString(&path,argv[i]);
5189 break;
5190 }
5191 if (LocaleCompare("pointsize",option+1) == 0)
5192 {
5193 if (*option == '+')
5194 break;
5195 i++;
cristybb503372010-05-27 20:51:26 +00005196 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005197 ThrowMogrifyException(OptionError,"MissingArgument",option);
5198 if (IsGeometry(argv[i]) == MagickFalse)
5199 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5200 break;
5201 }
5202 if (LocaleCompare("polaroid",option+1) == 0)
5203 {
5204 if (*option == '+')
5205 break;
5206 i++;
cristybb503372010-05-27 20:51:26 +00005207 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005208 ThrowMogrifyException(OptionError,"MissingArgument",option);
5209 if (IsGeometry(argv[i]) == MagickFalse)
5210 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5211 break;
5212 }
5213 if (LocaleCompare("posterize",option+1) == 0)
5214 {
5215 if (*option == '+')
5216 break;
5217 i++;
cristybb503372010-05-27 20:51:26 +00005218 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005219 ThrowMogrifyException(OptionError,"MissingArgument",option);
5220 if (IsGeometry(argv[i]) == MagickFalse)
5221 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5222 break;
5223 }
cristye7f51092010-01-17 00:39:37 +00005224 if (LocaleCompare("precision",option+1) == 0)
5225 {
5226 if (*option == '+')
5227 break;
5228 i++;
cristybb503372010-05-27 20:51:26 +00005229 if (i == (ssize_t) argc)
cristye7f51092010-01-17 00:39:37 +00005230 ThrowMogrifyException(OptionError,"MissingArgument",option);
5231 if (IsGeometry(argv[i]) == MagickFalse)
5232 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5233 break;
5234 }
cristy3ed852e2009-09-05 21:47:34 +00005235 if (LocaleCompare("print",option+1) == 0)
5236 {
5237 if (*option == '+')
5238 break;
5239 i++;
cristybb503372010-05-27 20:51:26 +00005240 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005241 ThrowMogrifyException(OptionError,"MissingArgument",option);
5242 break;
5243 }
5244 if (LocaleCompare("process",option+1) == 0)
5245 {
5246 if (*option == '+')
5247 break;
5248 i++;
cristybb503372010-05-27 20:51:26 +00005249 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005250 ThrowMogrifyException(OptionError,"MissingArgument",option);
5251 break;
5252 }
5253 if (LocaleCompare("profile",option+1) == 0)
5254 {
5255 i++;
cristybb503372010-05-27 20:51:26 +00005256 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005257 ThrowMogrifyException(OptionError,"MissingArgument",option);
5258 break;
5259 }
5260 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5261 }
5262 case 'q':
5263 {
5264 if (LocaleCompare("quality",option+1) == 0)
5265 {
5266 if (*option == '+')
5267 break;
5268 i++;
cristybb503372010-05-27 20:51:26 +00005269 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005270 ThrowMogrifyException(OptionError,"MissingArgument",option);
5271 if (IsGeometry(argv[i]) == MagickFalse)
5272 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5273 break;
5274 }
5275 if (LocaleCompare("quantize",option+1) == 0)
5276 {
cristybb503372010-05-27 20:51:26 +00005277 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005278 colorspace;
5279
5280 if (*option == '+')
5281 break;
5282 i++;
cristybb503372010-05-27 20:51:26 +00005283 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005284 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005285 colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005286 argv[i]);
5287 if (colorspace < 0)
5288 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
5289 argv[i]);
5290 break;
5291 }
5292 if (LocaleCompare("quiet",option+1) == 0)
5293 break;
5294 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5295 }
5296 case 'r':
5297 {
5298 if (LocaleCompare("radial-blur",option+1) == 0)
5299 {
5300 i++;
cristybb503372010-05-27 20:51:26 +00005301 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005302 ThrowMogrifyException(OptionError,"MissingArgument",option);
5303 if (IsGeometry(argv[i]) == MagickFalse)
5304 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5305 break;
5306 }
5307 if (LocaleCompare("raise",option+1) == 0)
5308 {
5309 i++;
cristybb503372010-05-27 20:51:26 +00005310 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005311 ThrowMogrifyException(OptionError,"MissingArgument",option);
5312 if (IsGeometry(argv[i]) == MagickFalse)
5313 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5314 break;
5315 }
5316 if (LocaleCompare("random-threshold",option+1) == 0)
5317 {
5318 if (*option == '+')
5319 break;
5320 i++;
cristybb503372010-05-27 20:51:26 +00005321 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005322 ThrowMogrifyException(OptionError,"MissingArgument",option);
5323 if (IsGeometry(argv[i]) == MagickFalse)
5324 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5325 break;
5326 }
cristye6365592010-04-02 17:31:23 +00005327 if (LocaleCompare("recolor",option+1) == 0)
5328 {
5329 if (*option == '+')
5330 break;
5331 i++;
cristybb503372010-05-27 20:51:26 +00005332 if (i == (ssize_t) (argc-1))
cristye6365592010-04-02 17:31:23 +00005333 ThrowMogrifyException(OptionError,"MissingArgument",option);
5334 if (IsGeometry(argv[i]) == MagickFalse)
5335 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5336 break;
5337 }
cristy3ed852e2009-09-05 21:47:34 +00005338 if (LocaleCompare("red-primary",option+1) == 0)
5339 {
5340 if (*option == '+')
5341 break;
5342 i++;
cristybb503372010-05-27 20:51:26 +00005343 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005344 ThrowMogrifyException(OptionError,"MissingArgument",option);
5345 if (IsGeometry(argv[i]) == MagickFalse)
5346 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5347 }
cristy9f2083a2010-04-22 19:48:05 +00005348 if (LocaleCompare("regard-warnings",option+1) == 0)
5349 break;
cristy3ed852e2009-09-05 21:47:34 +00005350 if (LocaleCompare("region",option+1) == 0)
5351 {
5352 if (*option == '+')
5353 break;
5354 i++;
cristybb503372010-05-27 20:51:26 +00005355 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005356 ThrowMogrifyException(OptionError,"MissingArgument",option);
5357 if (IsGeometry(argv[i]) == MagickFalse)
5358 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5359 break;
5360 }
cristyf0c78232010-03-15 12:53:40 +00005361 if (LocaleCompare("remap",option+1) == 0)
5362 {
5363 if (*option == '+')
5364 break;
5365 i++;
cristybb503372010-05-27 20:51:26 +00005366 if (i == (ssize_t) (argc-1))
cristyf0c78232010-03-15 12:53:40 +00005367 ThrowMogrifyException(OptionError,"MissingArgument",option);
5368 break;
5369 }
cristy3ed852e2009-09-05 21:47:34 +00005370 if (LocaleCompare("render",option+1) == 0)
5371 break;
5372 if (LocaleCompare("repage",option+1) == 0)
5373 {
5374 if (*option == '+')
5375 break;
5376 i++;
cristybb503372010-05-27 20:51:26 +00005377 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005378 ThrowMogrifyException(OptionError,"MissingArgument",option);
5379 if (IsGeometry(argv[i]) == MagickFalse)
5380 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5381 break;
5382 }
5383 if (LocaleCompare("resample",option+1) == 0)
5384 {
5385 if (*option == '+')
5386 break;
5387 i++;
cristybb503372010-05-27 20:51:26 +00005388 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005389 ThrowMogrifyException(OptionError,"MissingArgument",option);
5390 if (IsGeometry(argv[i]) == MagickFalse)
5391 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5392 break;
5393 }
5394 if (LocaleCompare("resize",option+1) == 0)
5395 {
5396 if (*option == '+')
5397 break;
5398 i++;
cristybb503372010-05-27 20:51:26 +00005399 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005400 ThrowMogrifyException(OptionError,"MissingArgument",option);
5401 if (IsGeometry(argv[i]) == MagickFalse)
5402 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5403 break;
5404 }
cristyebbcfea2011-02-25 02:43:54 +00005405 if (LocaleNCompare("respect-parentheses",option+1,17) == 0)
5406 {
5407 respect_parenthesis=(*option == '-') ? MagickTrue : MagickFalse;
5408 break;
5409 }
cristy3ed852e2009-09-05 21:47:34 +00005410 if (LocaleCompare("reverse",option+1) == 0)
5411 break;
5412 if (LocaleCompare("roll",option+1) == 0)
5413 {
5414 if (*option == '+')
5415 break;
5416 i++;
cristybb503372010-05-27 20:51:26 +00005417 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005418 ThrowMogrifyException(OptionError,"MissingArgument",option);
5419 if (IsGeometry(argv[i]) == MagickFalse)
5420 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5421 break;
5422 }
5423 if (LocaleCompare("rotate",option+1) == 0)
5424 {
5425 i++;
cristybb503372010-05-27 20:51:26 +00005426 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005427 ThrowMogrifyException(OptionError,"MissingArgument",option);
5428 if (IsGeometry(argv[i]) == MagickFalse)
5429 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5430 break;
5431 }
5432 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5433 }
5434 case 's':
5435 {
5436 if (LocaleCompare("sample",option+1) == 0)
5437 {
5438 if (*option == '+')
5439 break;
5440 i++;
cristybb503372010-05-27 20:51:26 +00005441 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005442 ThrowMogrifyException(OptionError,"MissingArgument",option);
5443 if (IsGeometry(argv[i]) == MagickFalse)
5444 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5445 break;
5446 }
5447 if (LocaleCompare("sampling-factor",option+1) == 0)
5448 {
5449 if (*option == '+')
5450 break;
5451 i++;
cristybb503372010-05-27 20:51:26 +00005452 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005453 ThrowMogrifyException(OptionError,"MissingArgument",option);
5454 if (IsGeometry(argv[i]) == MagickFalse)
5455 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5456 break;
5457 }
5458 if (LocaleCompare("scale",option+1) == 0)
5459 {
5460 if (*option == '+')
5461 break;
5462 i++;
cristybb503372010-05-27 20:51:26 +00005463 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005464 ThrowMogrifyException(OptionError,"MissingArgument",option);
5465 if (IsGeometry(argv[i]) == MagickFalse)
5466 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5467 break;
5468 }
5469 if (LocaleCompare("scene",option+1) == 0)
5470 {
5471 if (*option == '+')
5472 break;
5473 i++;
cristybb503372010-05-27 20:51:26 +00005474 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005475 ThrowMogrifyException(OptionError,"MissingArgument",option);
5476 if (IsGeometry(argv[i]) == MagickFalse)
5477 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5478 break;
5479 }
5480 if (LocaleCompare("seed",option+1) == 0)
5481 {
5482 if (*option == '+')
5483 break;
5484 i++;
cristybb503372010-05-27 20:51:26 +00005485 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005486 ThrowMogrifyException(OptionError,"MissingArgument",option);
5487 if (IsGeometry(argv[i]) == MagickFalse)
5488 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5489 break;
5490 }
5491 if (LocaleCompare("segment",option+1) == 0)
5492 {
5493 if (*option == '+')
5494 break;
5495 i++;
cristybb503372010-05-27 20:51:26 +00005496 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005497 ThrowMogrifyException(OptionError,"MissingArgument",option);
5498 if (IsGeometry(argv[i]) == MagickFalse)
5499 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5500 break;
5501 }
5502 if (LocaleCompare("selective-blur",option+1) == 0)
5503 {
5504 i++;
cristybb503372010-05-27 20:51:26 +00005505 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005506 ThrowMogrifyException(OptionError,"MissingArgument",option);
5507 if (IsGeometry(argv[i]) == MagickFalse)
5508 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5509 break;
5510 }
5511 if (LocaleCompare("separate",option+1) == 0)
5512 break;
5513 if (LocaleCompare("sepia-tone",option+1) == 0)
5514 {
5515 if (*option == '+')
5516 break;
5517 i++;
cristybb503372010-05-27 20:51:26 +00005518 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005519 ThrowMogrifyException(OptionError,"MissingArgument",option);
5520 if (IsGeometry(argv[i]) == MagickFalse)
5521 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5522 break;
5523 }
5524 if (LocaleCompare("set",option+1) == 0)
5525 {
5526 i++;
cristybb503372010-05-27 20:51:26 +00005527 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005528 ThrowMogrifyException(OptionError,"MissingArgument",option);
5529 if (*option == '+')
5530 break;
5531 i++;
cristybb503372010-05-27 20:51:26 +00005532 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005533 ThrowMogrifyException(OptionError,"MissingArgument",option);
5534 break;
5535 }
5536 if (LocaleCompare("shade",option+1) == 0)
5537 {
5538 i++;
cristybb503372010-05-27 20:51:26 +00005539 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005540 ThrowMogrifyException(OptionError,"MissingArgument",option);
5541 if (IsGeometry(argv[i]) == MagickFalse)
5542 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5543 break;
5544 }
5545 if (LocaleCompare("shadow",option+1) == 0)
5546 {
5547 if (*option == '+')
5548 break;
5549 i++;
cristybb503372010-05-27 20:51:26 +00005550 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005551 ThrowMogrifyException(OptionError,"MissingArgument",option);
5552 if (IsGeometry(argv[i]) == MagickFalse)
5553 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5554 break;
5555 }
5556 if (LocaleCompare("sharpen",option+1) == 0)
5557 {
5558 i++;
cristybb503372010-05-27 20:51:26 +00005559 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005560 ThrowMogrifyException(OptionError,"MissingArgument",option);
5561 if (IsGeometry(argv[i]) == MagickFalse)
5562 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5563 break;
5564 }
5565 if (LocaleCompare("shave",option+1) == 0)
5566 {
5567 if (*option == '+')
5568 break;
5569 i++;
cristybb503372010-05-27 20:51:26 +00005570 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005571 ThrowMogrifyException(OptionError,"MissingArgument",option);
5572 if (IsGeometry(argv[i]) == MagickFalse)
5573 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5574 break;
5575 }
5576 if (LocaleCompare("shear",option+1) == 0)
5577 {
5578 i++;
cristybb503372010-05-27 20:51:26 +00005579 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005580 ThrowMogrifyException(OptionError,"MissingArgument",option);
5581 if (IsGeometry(argv[i]) == MagickFalse)
5582 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5583 break;
5584 }
5585 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
5586 {
5587 i++;
cristybb503372010-05-27 20:51:26 +00005588 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005589 ThrowMogrifyException(OptionError,"MissingArgument",option);
5590 if (IsGeometry(argv[i]) == MagickFalse)
5591 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5592 break;
5593 }
5594 if (LocaleCompare("size",option+1) == 0)
5595 {
5596 if (*option == '+')
5597 break;
5598 i++;
cristybb503372010-05-27 20:51:26 +00005599 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005600 ThrowMogrifyException(OptionError,"MissingArgument",option);
5601 if (IsGeometry(argv[i]) == MagickFalse)
5602 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5603 break;
5604 }
5605 if (LocaleCompare("sketch",option+1) == 0)
5606 {
5607 if (*option == '+')
5608 break;
5609 i++;
cristybb503372010-05-27 20:51:26 +00005610 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005611 ThrowMogrifyException(OptionError,"MissingArgument",option);
5612 if (IsGeometry(argv[i]) == MagickFalse)
5613 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5614 break;
5615 }
cristy4285d782011-02-09 20:12:28 +00005616 if (LocaleCompare("smush",option+1) == 0)
5617 {
cristy4285d782011-02-09 20:12:28 +00005618 i++;
5619 if (i == (ssize_t) argc)
5620 ThrowMogrifyException(OptionError,"MissingArgument",option);
5621 if (IsGeometry(argv[i]) == MagickFalse)
5622 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristy4285d782011-02-09 20:12:28 +00005623 i++;
5624 break;
5625 }
cristy3ed852e2009-09-05 21:47:34 +00005626 if (LocaleCompare("solarize",option+1) == 0)
5627 {
5628 if (*option == '+')
5629 break;
5630 i++;
cristybb503372010-05-27 20:51:26 +00005631 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005632 ThrowMogrifyException(OptionError,"MissingArgument",option);
5633 if (IsGeometry(argv[i]) == MagickFalse)
5634 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5635 break;
5636 }
5637 if (LocaleCompare("sparse-color",option+1) == 0)
5638 {
cristybb503372010-05-27 20:51:26 +00005639 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005640 op;
5641
5642 i++;
cristybb503372010-05-27 20:51:26 +00005643 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005644 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005645 op=ParseCommandOption(MagickSparseColorOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005646 if (op < 0)
5647 ThrowMogrifyException(OptionError,"UnrecognizedSparseColorMethod",
5648 argv[i]);
5649 i++;
cristybb503372010-05-27 20:51:26 +00005650 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005651 ThrowMogrifyException(OptionError,"MissingArgument",option);
5652 break;
5653 }
5654 if (LocaleCompare("spread",option+1) == 0)
5655 {
5656 if (*option == '+')
5657 break;
5658 i++;
cristybb503372010-05-27 20:51:26 +00005659 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005660 ThrowMogrifyException(OptionError,"MissingArgument",option);
5661 if (IsGeometry(argv[i]) == MagickFalse)
5662 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5663 break;
5664 }
cristy0834d642011-03-18 18:26:08 +00005665 if (LocaleCompare("statistic",option+1) == 0)
5666 {
5667 ssize_t
5668 op;
5669
5670 if (*option == '+')
5671 break;
5672 i++;
5673 if (i == (ssize_t) argc)
5674 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005675 op=ParseCommandOption(MagickStatisticOptions,MagickFalse,argv[i]);
cristy0834d642011-03-18 18:26:08 +00005676 if (op < 0)
5677 ThrowMogrifyException(OptionError,"UnrecognizedStatisticType",
5678 argv[i]);
5679 i++;
5680 if (i == (ssize_t) (argc-1))
5681 ThrowMogrifyException(OptionError,"MissingArgument",option);
5682 if (IsGeometry(argv[i]) == MagickFalse)
5683 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5684 break;
5685 }
cristy3ed852e2009-09-05 21:47:34 +00005686 if (LocaleCompare("stretch",option+1) == 0)
5687 {
cristybb503372010-05-27 20:51:26 +00005688 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005689 stretch;
5690
5691 if (*option == '+')
5692 break;
5693 i++;
cristybb503372010-05-27 20:51:26 +00005694 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005695 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005696 stretch=ParseCommandOption(MagickStretchOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005697 if (stretch < 0)
5698 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
5699 argv[i]);
5700 break;
5701 }
5702 if (LocaleCompare("strip",option+1) == 0)
5703 break;
5704 if (LocaleCompare("stroke",option+1) == 0)
5705 {
5706 if (*option == '+')
5707 break;
5708 i++;
cristybb503372010-05-27 20:51:26 +00005709 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005710 ThrowMogrifyException(OptionError,"MissingArgument",option);
5711 break;
5712 }
5713 if (LocaleCompare("strokewidth",option+1) == 0)
5714 {
5715 if (*option == '+')
5716 break;
5717 i++;
cristybb503372010-05-27 20:51:26 +00005718 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005719 ThrowMogrifyException(OptionError,"MissingArgument",option);
5720 if (IsGeometry(argv[i]) == MagickFalse)
5721 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5722 break;
5723 }
5724 if (LocaleCompare("style",option+1) == 0)
5725 {
cristybb503372010-05-27 20:51:26 +00005726 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005727 style;
5728
5729 if (*option == '+')
5730 break;
5731 i++;
cristybb503372010-05-27 20:51:26 +00005732 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005733 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005734 style=ParseCommandOption(MagickStyleOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005735 if (style < 0)
5736 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
5737 argv[i]);
5738 break;
5739 }
cristyecb10ff2011-03-22 13:14:03 +00005740 if (LocaleCompare("swap",option+1) == 0)
5741 {
5742 if (*option == '+')
5743 break;
5744 i++;
5745 if (i == (ssize_t) (argc-1))
5746 ThrowMogrifyException(OptionError,"MissingArgument",option);
5747 if (IsGeometry(argv[i]) == MagickFalse)
5748 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5749 break;
5750 }
cristy3ed852e2009-09-05 21:47:34 +00005751 if (LocaleCompare("swirl",option+1) == 0)
5752 {
5753 if (*option == '+')
5754 break;
5755 i++;
cristybb503372010-05-27 20:51:26 +00005756 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005757 ThrowMogrifyException(OptionError,"MissingArgument",option);
5758 if (IsGeometry(argv[i]) == MagickFalse)
5759 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5760 break;
5761 }
cristyd9a29192010-10-16 16:49:53 +00005762 if (LocaleCompare("synchronize",option+1) == 0)
5763 break;
cristy3ed852e2009-09-05 21:47:34 +00005764 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5765 }
5766 case 't':
5767 {
5768 if (LocaleCompare("taint",option+1) == 0)
5769 break;
5770 if (LocaleCompare("texture",option+1) == 0)
5771 {
5772 if (*option == '+')
5773 break;
5774 i++;
cristybb503372010-05-27 20:51:26 +00005775 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005776 ThrowMogrifyException(OptionError,"MissingArgument",option);
5777 break;
5778 }
5779 if (LocaleCompare("tile",option+1) == 0)
5780 {
5781 if (*option == '+')
5782 break;
5783 i++;
cristybb503372010-05-27 20:51:26 +00005784 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005785 ThrowMogrifyException(OptionError,"MissingArgument",option);
5786 break;
5787 }
5788 if (LocaleCompare("tile-offset",option+1) == 0)
5789 {
5790 if (*option == '+')
5791 break;
5792 i++;
cristybb503372010-05-27 20:51:26 +00005793 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005794 ThrowMogrifyException(OptionError,"MissingArgument",option);
5795 if (IsGeometry(argv[i]) == MagickFalse)
5796 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5797 break;
5798 }
5799 if (LocaleCompare("tint",option+1) == 0)
5800 {
5801 if (*option == '+')
5802 break;
5803 i++;
cristybb503372010-05-27 20:51:26 +00005804 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005805 ThrowMogrifyException(OptionError,"MissingArgument",option);
5806 if (IsGeometry(argv[i]) == MagickFalse)
5807 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5808 break;
5809 }
5810 if (LocaleCompare("transform",option+1) == 0)
5811 break;
5812 if (LocaleCompare("transpose",option+1) == 0)
5813 break;
5814 if (LocaleCompare("transverse",option+1) == 0)
5815 break;
5816 if (LocaleCompare("threshold",option+1) == 0)
5817 {
5818 if (*option == '+')
5819 break;
5820 i++;
cristybb503372010-05-27 20:51:26 +00005821 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005822 ThrowMogrifyException(OptionError,"MissingArgument",option);
5823 if (IsGeometry(argv[i]) == MagickFalse)
5824 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5825 break;
5826 }
5827 if (LocaleCompare("thumbnail",option+1) == 0)
5828 {
5829 if (*option == '+')
5830 break;
5831 i++;
cristybb503372010-05-27 20:51:26 +00005832 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005833 ThrowMogrifyException(OptionError,"MissingArgument",option);
5834 if (IsGeometry(argv[i]) == MagickFalse)
5835 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5836 break;
5837 }
5838 if (LocaleCompare("transparent",option+1) == 0)
5839 {
5840 i++;
cristybb503372010-05-27 20:51:26 +00005841 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005842 ThrowMogrifyException(OptionError,"MissingArgument",option);
5843 break;
5844 }
5845 if (LocaleCompare("transparent-color",option+1) == 0)
5846 {
5847 if (*option == '+')
5848 break;
5849 i++;
cristybb503372010-05-27 20:51:26 +00005850 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005851 ThrowMogrifyException(OptionError,"MissingArgument",option);
5852 break;
5853 }
5854 if (LocaleCompare("treedepth",option+1) == 0)
5855 {
5856 if (*option == '+')
5857 break;
5858 i++;
cristybb503372010-05-27 20:51:26 +00005859 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005860 ThrowMogrifyException(OptionError,"MissingArgument",option);
5861 if (IsGeometry(argv[i]) == MagickFalse)
5862 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5863 break;
5864 }
5865 if (LocaleCompare("trim",option+1) == 0)
5866 break;
5867 if (LocaleCompare("type",option+1) == 0)
5868 {
cristybb503372010-05-27 20:51:26 +00005869 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005870 type;
5871
5872 if (*option == '+')
5873 break;
5874 i++;
cristybb503372010-05-27 20:51:26 +00005875 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005876 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005877 type=ParseCommandOption(MagickTypeOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005878 if (type < 0)
5879 ThrowMogrifyException(OptionError,"UnrecognizedImageType",
5880 argv[i]);
5881 break;
5882 }
5883 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5884 }
5885 case 'u':
5886 {
5887 if (LocaleCompare("undercolor",option+1) == 0)
5888 {
5889 if (*option == '+')
5890 break;
5891 i++;
cristybb503372010-05-27 20:51:26 +00005892 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005893 ThrowMogrifyException(OptionError,"MissingArgument",option);
5894 break;
5895 }
5896 if (LocaleCompare("unique-colors",option+1) == 0)
5897 break;
5898 if (LocaleCompare("units",option+1) == 0)
5899 {
cristybb503372010-05-27 20:51:26 +00005900 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005901 units;
5902
5903 if (*option == '+')
5904 break;
5905 i++;
cristybb503372010-05-27 20:51:26 +00005906 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005907 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005908 units=ParseCommandOption(MagickResolutionOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005909 argv[i]);
5910 if (units < 0)
5911 ThrowMogrifyException(OptionError,"UnrecognizedUnitsType",
5912 argv[i]);
5913 break;
5914 }
5915 if (LocaleCompare("unsharp",option+1) == 0)
5916 {
5917 i++;
cristybb503372010-05-27 20:51:26 +00005918 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005919 ThrowMogrifyException(OptionError,"MissingArgument",option);
5920 if (IsGeometry(argv[i]) == MagickFalse)
5921 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5922 break;
5923 }
5924 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5925 }
5926 case 'v':
5927 {
5928 if (LocaleCompare("verbose",option+1) == 0)
5929 {
5930 image_info->verbose=(*option == '-') ? MagickTrue : MagickFalse;
5931 break;
5932 }
5933 if ((LocaleCompare("version",option+1) == 0) ||
5934 (LocaleCompare("-version",option+1) == 0))
5935 {
cristyb51dff52011-05-19 16:55:47 +00005936 (void) FormatLocaleFile(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +00005937 GetMagickVersion((size_t *) NULL));
cristy1e604812011-05-19 18:07:50 +00005938 (void) FormatLocaleFile(stdout,"Copyright: %s\n",
5939 GetMagickCopyright());
5940 (void) FormatLocaleFile(stdout,"Features: %s\n\n",
5941 GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00005942 break;
5943 }
5944 if (LocaleCompare("view",option+1) == 0)
5945 {
5946 if (*option == '+')
5947 break;
5948 i++;
cristybb503372010-05-27 20:51:26 +00005949 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005950 ThrowMogrifyException(OptionError,"MissingArgument",option);
5951 break;
5952 }
5953 if (LocaleCompare("vignette",option+1) == 0)
5954 {
5955 if (*option == '+')
5956 break;
5957 i++;
cristybb503372010-05-27 20:51:26 +00005958 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005959 ThrowMogrifyException(OptionError,"MissingArgument",option);
5960 if (IsGeometry(argv[i]) == MagickFalse)
5961 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5962 break;
5963 }
5964 if (LocaleCompare("virtual-pixel",option+1) == 0)
5965 {
cristybb503372010-05-27 20:51:26 +00005966 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005967 method;
5968
5969 if (*option == '+')
5970 break;
5971 i++;
cristybb503372010-05-27 20:51:26 +00005972 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005973 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005974 method=ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005975 argv[i]);
5976 if (method < 0)
5977 ThrowMogrifyException(OptionError,
5978 "UnrecognizedVirtualPixelMethod",argv[i]);
5979 break;
5980 }
5981 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5982 }
5983 case 'w':
5984 {
5985 if (LocaleCompare("wave",option+1) == 0)
5986 {
5987 i++;
cristybb503372010-05-27 20:51:26 +00005988 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005989 ThrowMogrifyException(OptionError,"MissingArgument",option);
5990 if (IsGeometry(argv[i]) == MagickFalse)
5991 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5992 break;
5993 }
5994 if (LocaleCompare("weight",option+1) == 0)
5995 {
5996 if (*option == '+')
5997 break;
5998 i++;
cristybb503372010-05-27 20:51:26 +00005999 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006000 ThrowMogrifyException(OptionError,"MissingArgument",option);
6001 break;
6002 }
6003 if (LocaleCompare("white-point",option+1) == 0)
6004 {
6005 if (*option == '+')
6006 break;
6007 i++;
cristybb503372010-05-27 20:51:26 +00006008 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006009 ThrowMogrifyException(OptionError,"MissingArgument",option);
6010 if (IsGeometry(argv[i]) == MagickFalse)
6011 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6012 break;
6013 }
6014 if (LocaleCompare("white-threshold",option+1) == 0)
6015 {
6016 if (*option == '+')
6017 break;
6018 i++;
cristybb503372010-05-27 20:51:26 +00006019 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006020 ThrowMogrifyException(OptionError,"MissingArgument",option);
6021 if (IsGeometry(argv[i]) == MagickFalse)
6022 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6023 break;
6024 }
6025 if (LocaleCompare("write",option+1) == 0)
6026 {
6027 i++;
cristybb503372010-05-27 20:51:26 +00006028 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006029 ThrowMogrifyException(OptionError,"MissingArgument",option);
6030 break;
6031 }
6032 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6033 }
6034 case '?':
6035 break;
6036 default:
6037 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6038 }
cristy042ee782011-04-22 18:48:30 +00006039 fire=(GetCommandOptionFlags(MagickCommandOptions,MagickFalse,option) &
6040 FireOptionFlag) == 0 ? MagickFalse : MagickTrue;
cristy3ed852e2009-09-05 21:47:34 +00006041 if (fire != MagickFalse)
6042 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
6043 }
6044 if (k != 0)
6045 ThrowMogrifyException(OptionError,"UnbalancedParenthesis",argv[i]);
cristycee97112010-05-28 00:44:52 +00006046 if (i != (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006047 ThrowMogrifyException(OptionError,"MissingAnImageFilename",argv[i]);
6048 DestroyMogrify();
6049 return(status != 0 ? MagickTrue : MagickFalse);
6050}
6051
6052/*
6053%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6054% %
6055% %
6056% %
6057+ M o g r i f y I m a g e I n f o %
6058% %
6059% %
6060% %
6061%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6062%
6063% MogrifyImageInfo() applies image processing settings to the image as
6064% prescribed by command line options.
6065%
6066% The format of the MogrifyImageInfo method is:
6067%
6068% MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,const int argc,
6069% const char **argv,ExceptionInfo *exception)
6070%
6071% A description of each parameter follows:
6072%
6073% o image_info: the image info..
6074%
6075% o argc: Specifies a pointer to an integer describing the number of
6076% elements in the argument vector.
6077%
6078% o argv: Specifies a pointer to a text array containing the command line
6079% arguments.
6080%
6081% o exception: return any errors or warnings in this structure.
6082%
6083*/
6084WandExport MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,
6085 const int argc,const char **argv,ExceptionInfo *exception)
6086{
6087 const char
6088 *option;
6089
6090 GeometryInfo
6091 geometry_info;
6092
cristybb503372010-05-27 20:51:26 +00006093 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006094 count;
6095
cristybb503372010-05-27 20:51:26 +00006096 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006097 i;
6098
6099 /*
6100 Initialize method variables.
6101 */
6102 assert(image_info != (ImageInfo *) NULL);
6103 assert(image_info->signature == MagickSignature);
6104 if (image_info->debug != MagickFalse)
6105 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
6106 image_info->filename);
6107 if (argc < 0)
6108 return(MagickTrue);
6109 /*
6110 Set the image settings.
6111 */
cristybb503372010-05-27 20:51:26 +00006112 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00006113 {
6114 option=argv[i];
cristy042ee782011-04-22 18:48:30 +00006115 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00006116 continue;
cristy042ee782011-04-22 18:48:30 +00006117 count=ParseCommandOption(MagickCommandOptions,MagickFalse,option);
anthonyce2716b2011-04-22 09:51:34 +00006118 count=MagickMax(count,0L);
cristycee97112010-05-28 00:44:52 +00006119 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006120 break;
6121 switch (*(option+1))
6122 {
6123 case 'a':
6124 {
6125 if (LocaleCompare("adjoin",option+1) == 0)
6126 {
6127 image_info->adjoin=(*option == '-') ? MagickTrue : MagickFalse;
6128 break;
6129 }
6130 if (LocaleCompare("antialias",option+1) == 0)
6131 {
6132 image_info->antialias=(*option == '-') ? MagickTrue : MagickFalse;
6133 break;
6134 }
6135 if (LocaleCompare("attenuate",option+1) == 0)
6136 {
6137 if (*option == '+')
6138 {
6139 (void) DeleteImageOption(image_info,option+1);
6140 break;
6141 }
6142 (void) SetImageOption(image_info,option+1,argv[i+1]);
6143 break;
6144 }
6145 if (LocaleCompare("authenticate",option+1) == 0)
6146 {
6147 if (*option == '+')
6148 (void) CloneString(&image_info->authenticate,(char *) NULL);
6149 else
6150 (void) CloneString(&image_info->authenticate,argv[i+1]);
6151 break;
6152 }
6153 break;
6154 }
6155 case 'b':
6156 {
6157 if (LocaleCompare("background",option+1) == 0)
6158 {
6159 if (*option == '+')
6160 {
6161 (void) DeleteImageOption(image_info,option+1);
6162 (void) QueryColorDatabase(BackgroundColor,
6163 &image_info->background_color,exception);
6164 break;
6165 }
6166 (void) SetImageOption(image_info,option+1,argv[i+1]);
6167 (void) QueryColorDatabase(argv[i+1],&image_info->background_color,
6168 exception);
6169 break;
6170 }
6171 if (LocaleCompare("bias",option+1) == 0)
6172 {
6173 if (*option == '+')
6174 {
6175 (void) SetImageOption(image_info,option+1,"0.0");
6176 break;
6177 }
6178 (void) SetImageOption(image_info,option+1,argv[i+1]);
6179 break;
6180 }
6181 if (LocaleCompare("black-point-compensation",option+1) == 0)
6182 {
6183 if (*option == '+')
6184 {
6185 (void) SetImageOption(image_info,option+1,"false");
6186 break;
6187 }
6188 (void) SetImageOption(image_info,option+1,"true");
6189 break;
6190 }
6191 if (LocaleCompare("blue-primary",option+1) == 0)
6192 {
6193 if (*option == '+')
6194 {
6195 (void) SetImageOption(image_info,option+1,"0.0");
6196 break;
6197 }
6198 (void) SetImageOption(image_info,option+1,argv[i+1]);
6199 break;
6200 }
6201 if (LocaleCompare("bordercolor",option+1) == 0)
6202 {
6203 if (*option == '+')
6204 {
6205 (void) DeleteImageOption(image_info,option+1);
6206 (void) QueryColorDatabase(BorderColor,&image_info->border_color,
6207 exception);
6208 break;
6209 }
6210 (void) QueryColorDatabase(argv[i+1],&image_info->border_color,
6211 exception);
6212 (void) SetImageOption(image_info,option+1,argv[i+1]);
6213 break;
6214 }
6215 if (LocaleCompare("box",option+1) == 0)
6216 {
6217 if (*option == '+')
6218 {
6219 (void) SetImageOption(image_info,"undercolor","none");
6220 break;
6221 }
6222 (void) SetImageOption(image_info,"undercolor",argv[i+1]);
6223 break;
6224 }
6225 break;
6226 }
6227 case 'c':
6228 {
6229 if (LocaleCompare("cache",option+1) == 0)
6230 {
6231 MagickSizeType
6232 limit;
6233
6234 limit=MagickResourceInfinity;
6235 if (LocaleCompare("unlimited",argv[i+1]) != 0)
cristyf2f27272009-12-17 14:48:46 +00006236 limit=(MagickSizeType) SiPrefixToDouble(argv[i+1],100.0);
cristy3ed852e2009-09-05 21:47:34 +00006237 (void) SetMagickResourceLimit(MemoryResource,limit);
6238 (void) SetMagickResourceLimit(MapResource,2*limit);
6239 break;
6240 }
6241 if (LocaleCompare("caption",option+1) == 0)
6242 {
6243 if (*option == '+')
6244 {
6245 (void) DeleteImageOption(image_info,option+1);
6246 break;
6247 }
6248 (void) SetImageOption(image_info,option+1,argv[i+1]);
6249 break;
6250 }
6251 if (LocaleCompare("channel",option+1) == 0)
6252 {
6253 if (*option == '+')
6254 {
6255 image_info->channel=DefaultChannels;
6256 break;
6257 }
6258 image_info->channel=(ChannelType) ParseChannelOption(argv[i+1]);
6259 break;
6260 }
6261 if (LocaleCompare("colors",option+1) == 0)
6262 {
cristye27293e2009-12-18 02:53:20 +00006263 image_info->colors=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006264 break;
6265 }
6266 if (LocaleCompare("colorspace",option+1) == 0)
6267 {
6268 if (*option == '+')
6269 {
6270 image_info->colorspace=UndefinedColorspace;
6271 (void) SetImageOption(image_info,option+1,"undefined");
6272 break;
6273 }
cristy042ee782011-04-22 18:48:30 +00006274 image_info->colorspace=(ColorspaceType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006275 MagickColorspaceOptions,MagickFalse,argv[i+1]);
6276 (void) SetImageOption(image_info,option+1,argv[i+1]);
6277 break;
6278 }
cristy3ed852e2009-09-05 21:47:34 +00006279 if (LocaleCompare("comment",option+1) == 0)
6280 {
6281 if (*option == '+')
6282 {
6283 (void) DeleteImageOption(image_info,option+1);
6284 break;
6285 }
6286 (void) SetImageOption(image_info,option+1,argv[i+1]);
6287 break;
6288 }
6289 if (LocaleCompare("compose",option+1) == 0)
6290 {
6291 if (*option == '+')
6292 {
6293 (void) SetImageOption(image_info,option+1,"undefined");
6294 break;
6295 }
6296 (void) SetImageOption(image_info,option+1,argv[i+1]);
6297 break;
6298 }
6299 if (LocaleCompare("compress",option+1) == 0)
6300 {
6301 if (*option == '+')
6302 {
6303 image_info->compression=UndefinedCompression;
6304 (void) SetImageOption(image_info,option+1,"undefined");
6305 break;
6306 }
cristy042ee782011-04-22 18:48:30 +00006307 image_info->compression=(CompressionType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006308 MagickCompressOptions,MagickFalse,argv[i+1]);
6309 (void) SetImageOption(image_info,option+1,argv[i+1]);
6310 break;
6311 }
6312 break;
6313 }
6314 case 'd':
6315 {
6316 if (LocaleCompare("debug",option+1) == 0)
6317 {
6318 if (*option == '+')
6319 (void) SetLogEventMask("none");
6320 else
6321 (void) SetLogEventMask(argv[i+1]);
6322 image_info->debug=IsEventLogging();
6323 break;
6324 }
6325 if (LocaleCompare("define",option+1) == 0)
6326 {
6327 if (*option == '+')
6328 {
6329 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6330 (void) DeleteImageRegistry(argv[i+1]+9);
6331 else
6332 (void) DeleteImageOption(image_info,argv[i+1]);
6333 break;
6334 }
6335 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6336 {
6337 (void) DefineImageRegistry(StringRegistryType,argv[i+1]+9,
6338 exception);
6339 break;
6340 }
6341 (void) DefineImageOption(image_info,argv[i+1]);
6342 break;
6343 }
6344 if (LocaleCompare("delay",option+1) == 0)
6345 {
6346 if (*option == '+')
6347 {
6348 (void) SetImageOption(image_info,option+1,"0");
6349 break;
6350 }
6351 (void) SetImageOption(image_info,option+1,argv[i+1]);
6352 break;
6353 }
6354 if (LocaleCompare("density",option+1) == 0)
6355 {
6356 /*
6357 Set image density.
6358 */
6359 if (*option == '+')
6360 {
6361 if (image_info->density != (char *) NULL)
6362 image_info->density=DestroyString(image_info->density);
6363 (void) SetImageOption(image_info,option+1,"72");
6364 break;
6365 }
6366 (void) CloneString(&image_info->density,argv[i+1]);
6367 (void) SetImageOption(image_info,option+1,argv[i+1]);
6368 break;
6369 }
6370 if (LocaleCompare("depth",option+1) == 0)
6371 {
6372 if (*option == '+')
6373 {
6374 image_info->depth=MAGICKCORE_QUANTUM_DEPTH;
6375 break;
6376 }
cristye27293e2009-12-18 02:53:20 +00006377 image_info->depth=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006378 break;
6379 }
cristyc9b12952010-03-28 01:12:28 +00006380 if (LocaleCompare("direction",option+1) == 0)
6381 {
6382 if (*option == '+')
6383 {
6384 (void) SetImageOption(image_info,option+1,"undefined");
6385 break;
6386 }
6387 (void) SetImageOption(image_info,option+1,argv[i+1]);
6388 break;
6389 }
cristy3ed852e2009-09-05 21:47:34 +00006390 if (LocaleCompare("display",option+1) == 0)
6391 {
6392 if (*option == '+')
6393 {
6394 if (image_info->server_name != (char *) NULL)
6395 image_info->server_name=DestroyString(
6396 image_info->server_name);
6397 break;
6398 }
6399 (void) CloneString(&image_info->server_name,argv[i+1]);
6400 break;
6401 }
6402 if (LocaleCompare("dispose",option+1) == 0)
6403 {
6404 if (*option == '+')
6405 {
6406 (void) SetImageOption(image_info,option+1,"undefined");
6407 break;
6408 }
6409 (void) SetImageOption(image_info,option+1,argv[i+1]);
6410 break;
6411 }
6412 if (LocaleCompare("dither",option+1) == 0)
6413 {
6414 if (*option == '+')
6415 {
6416 image_info->dither=MagickFalse;
cristyd5acfd12010-06-15 00:11:38 +00006417 (void) SetImageOption(image_info,option+1,"none");
cristy3ed852e2009-09-05 21:47:34 +00006418 break;
6419 }
6420 (void) SetImageOption(image_info,option+1,argv[i+1]);
6421 image_info->dither=MagickTrue;
6422 break;
6423 }
6424 break;
6425 }
6426 case 'e':
6427 {
6428 if (LocaleCompare("encoding",option+1) == 0)
6429 {
6430 if (*option == '+')
6431 {
6432 (void) SetImageOption(image_info,option+1,"undefined");
6433 break;
6434 }
6435 (void) SetImageOption(image_info,option+1,argv[i+1]);
6436 break;
6437 }
6438 if (LocaleCompare("endian",option+1) == 0)
6439 {
6440 if (*option == '+')
6441 {
6442 image_info->endian=UndefinedEndian;
6443 (void) SetImageOption(image_info,option+1,"undefined");
6444 break;
6445 }
cristy042ee782011-04-22 18:48:30 +00006446 image_info->endian=(EndianType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006447 MagickEndianOptions,MagickFalse,argv[i+1]);
6448 (void) SetImageOption(image_info,option+1,argv[i+1]);
6449 break;
6450 }
6451 if (LocaleCompare("extract",option+1) == 0)
6452 {
6453 /*
6454 Set image extract geometry.
6455 */
6456 if (*option == '+')
6457 {
6458 if (image_info->extract != (char *) NULL)
6459 image_info->extract=DestroyString(image_info->extract);
6460 break;
6461 }
6462 (void) CloneString(&image_info->extract,argv[i+1]);
6463 break;
6464 }
6465 break;
6466 }
6467 case 'f':
6468 {
6469 if (LocaleCompare("fill",option+1) == 0)
6470 {
6471 if (*option == '+')
6472 {
6473 (void) SetImageOption(image_info,option+1,"none");
6474 break;
6475 }
6476 (void) SetImageOption(image_info,option+1,argv[i+1]);
6477 break;
6478 }
6479 if (LocaleCompare("filter",option+1) == 0)
6480 {
6481 if (*option == '+')
6482 {
6483 (void) SetImageOption(image_info,option+1,"undefined");
6484 break;
6485 }
6486 (void) SetImageOption(image_info,option+1,argv[i+1]);
6487 break;
6488 }
6489 if (LocaleCompare("font",option+1) == 0)
6490 {
6491 if (*option == '+')
6492 {
6493 if (image_info->font != (char *) NULL)
6494 image_info->font=DestroyString(image_info->font);
6495 break;
6496 }
6497 (void) CloneString(&image_info->font,argv[i+1]);
6498 break;
6499 }
6500 if (LocaleCompare("format",option+1) == 0)
6501 {
6502 register const char
6503 *q;
6504
6505 for (q=strchr(argv[i+1],'%'); q != (char *) NULL; q=strchr(q+1,'%'))
cristy9ed85672011-03-02 00:19:13 +00006506 if (strchr("Agkrz@[#",*(q+1)) != (char *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00006507 image_info->ping=MagickFalse;
6508 (void) SetImageOption(image_info,option+1,argv[i+1]);
6509 break;
6510 }
6511 if (LocaleCompare("fuzz",option+1) == 0)
6512 {
6513 if (*option == '+')
6514 {
6515 image_info->fuzz=0.0;
6516 (void) SetImageOption(image_info,option+1,"0");
6517 break;
6518 }
cristyf2f27272009-12-17 14:48:46 +00006519 image_info->fuzz=SiPrefixToDouble(argv[i+1],(double) QuantumRange+
cristy3ed852e2009-09-05 21:47:34 +00006520 1.0);
6521 (void) SetImageOption(image_info,option+1,argv[i+1]);
6522 break;
6523 }
6524 break;
6525 }
6526 case 'g':
6527 {
6528 if (LocaleCompare("gravity",option+1) == 0)
6529 {
6530 if (*option == '+')
6531 {
6532 (void) SetImageOption(image_info,option+1,"undefined");
6533 break;
6534 }
6535 (void) SetImageOption(image_info,option+1,argv[i+1]);
6536 break;
6537 }
6538 if (LocaleCompare("green-primary",option+1) == 0)
6539 {
6540 if (*option == '+')
6541 {
6542 (void) SetImageOption(image_info,option+1,"0.0");
6543 break;
6544 }
6545 (void) SetImageOption(image_info,option+1,argv[i+1]);
6546 break;
6547 }
6548 break;
6549 }
6550 case 'i':
6551 {
6552 if (LocaleCompare("intent",option+1) == 0)
6553 {
6554 if (*option == '+')
6555 {
6556 (void) SetImageOption(image_info,option+1,"undefined");
6557 break;
6558 }
6559 (void) SetImageOption(image_info,option+1,argv[i+1]);
6560 break;
6561 }
6562 if (LocaleCompare("interlace",option+1) == 0)
6563 {
6564 if (*option == '+')
6565 {
6566 image_info->interlace=UndefinedInterlace;
6567 (void) SetImageOption(image_info,option+1,"undefined");
6568 break;
6569 }
cristy042ee782011-04-22 18:48:30 +00006570 image_info->interlace=(InterlaceType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006571 MagickInterlaceOptions,MagickFalse,argv[i+1]);
6572 (void) SetImageOption(image_info,option+1,argv[i+1]);
6573 break;
6574 }
cristyb32b90a2009-09-07 21:45:48 +00006575 if (LocaleCompare("interline-spacing",option+1) == 0)
6576 {
6577 if (*option == '+')
6578 {
6579 (void) SetImageOption(image_info,option+1,"undefined");
6580 break;
6581 }
6582 (void) SetImageOption(image_info,option+1,argv[i+1]);
6583 break;
6584 }
cristy3ed852e2009-09-05 21:47:34 +00006585 if (LocaleCompare("interpolate",option+1) == 0)
6586 {
6587 if (*option == '+')
6588 {
6589 (void) SetImageOption(image_info,option+1,"undefined");
6590 break;
6591 }
6592 (void) SetImageOption(image_info,option+1,argv[i+1]);
6593 break;
6594 }
6595 if (LocaleCompare("interword-spacing",option+1) == 0)
6596 {
6597 if (*option == '+')
6598 {
6599 (void) SetImageOption(image_info,option+1,"undefined");
6600 break;
6601 }
6602 (void) SetImageOption(image_info,option+1,argv[i+1]);
6603 break;
6604 }
6605 break;
6606 }
6607 case 'k':
6608 {
6609 if (LocaleCompare("kerning",option+1) == 0)
6610 {
6611 if (*option == '+')
6612 {
6613 (void) SetImageOption(image_info,option+1,"undefined");
6614 break;
6615 }
6616 (void) SetImageOption(image_info,option+1,argv[i+1]);
6617 break;
6618 }
6619 break;
6620 }
6621 case 'l':
6622 {
6623 if (LocaleCompare("label",option+1) == 0)
6624 {
6625 if (*option == '+')
6626 {
6627 (void) DeleteImageOption(image_info,option+1);
6628 break;
6629 }
6630 (void) SetImageOption(image_info,option+1,argv[i+1]);
6631 break;
6632 }
6633 if (LocaleCompare("limit",option+1) == 0)
6634 {
6635 MagickSizeType
6636 limit;
6637
6638 ResourceType
6639 type;
6640
6641 if (*option == '+')
6642 break;
cristy042ee782011-04-22 18:48:30 +00006643 type=(ResourceType) ParseCommandOption(MagickResourceOptions,
cristy3ed852e2009-09-05 21:47:34 +00006644 MagickFalse,argv[i+1]);
6645 limit=MagickResourceInfinity;
6646 if (LocaleCompare("unlimited",argv[i+2]) != 0)
cristyf2f27272009-12-17 14:48:46 +00006647 limit=(MagickSizeType) SiPrefixToDouble(argv[i+2],100.0);
cristy3ed852e2009-09-05 21:47:34 +00006648 (void) SetMagickResourceLimit(type,limit);
6649 break;
6650 }
6651 if (LocaleCompare("list",option+1) == 0)
6652 {
cristybb503372010-05-27 20:51:26 +00006653 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006654 list;
6655
6656 /*
6657 Display configuration list.
6658 */
cristy042ee782011-04-22 18:48:30 +00006659 list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006660 switch (list)
6661 {
6662 case MagickCoderOptions:
6663 {
6664 (void) ListCoderInfo((FILE *) NULL,exception);
6665 break;
6666 }
6667 case MagickColorOptions:
6668 {
6669 (void) ListColorInfo((FILE *) NULL,exception);
6670 break;
6671 }
6672 case MagickConfigureOptions:
6673 {
6674 (void) ListConfigureInfo((FILE *) NULL,exception);
6675 break;
6676 }
6677 case MagickDelegateOptions:
6678 {
6679 (void) ListDelegateInfo((FILE *) NULL,exception);
6680 break;
6681 }
6682 case MagickFontOptions:
6683 {
6684 (void) ListTypeInfo((FILE *) NULL,exception);
6685 break;
6686 }
6687 case MagickFormatOptions:
6688 {
6689 (void) ListMagickInfo((FILE *) NULL,exception);
6690 break;
6691 }
6692 case MagickLocaleOptions:
6693 {
6694 (void) ListLocaleInfo((FILE *) NULL,exception);
6695 break;
6696 }
6697 case MagickLogOptions:
6698 {
6699 (void) ListLogInfo((FILE *) NULL,exception);
6700 break;
6701 }
6702 case MagickMagicOptions:
6703 {
6704 (void) ListMagicInfo((FILE *) NULL,exception);
6705 break;
6706 }
6707 case MagickMimeOptions:
6708 {
6709 (void) ListMimeInfo((FILE *) NULL,exception);
6710 break;
6711 }
6712 case MagickModuleOptions:
6713 {
6714 (void) ListModuleInfo((FILE *) NULL,exception);
6715 break;
6716 }
6717 case MagickPolicyOptions:
6718 {
6719 (void) ListPolicyInfo((FILE *) NULL,exception);
6720 break;
6721 }
6722 case MagickResourceOptions:
6723 {
6724 (void) ListMagickResourceInfo((FILE *) NULL,exception);
6725 break;
6726 }
6727 case MagickThresholdOptions:
6728 {
6729 (void) ListThresholdMaps((FILE *) NULL,exception);
6730 break;
6731 }
6732 default:
6733 {
cristy042ee782011-04-22 18:48:30 +00006734 (void) ListCommandOptions((FILE *) NULL,(CommandOption) list,
cristy3ed852e2009-09-05 21:47:34 +00006735 exception);
6736 break;
6737 }
6738 }
cristyaeb2cbc2010-05-07 13:28:58 +00006739 break;
cristy3ed852e2009-09-05 21:47:34 +00006740 }
6741 if (LocaleCompare("log",option+1) == 0)
6742 {
6743 if (*option == '+')
6744 break;
6745 (void) SetLogFormat(argv[i+1]);
6746 break;
6747 }
6748 if (LocaleCompare("loop",option+1) == 0)
6749 {
6750 if (*option == '+')
6751 {
6752 (void) SetImageOption(image_info,option+1,"0");
6753 break;
6754 }
6755 (void) SetImageOption(image_info,option+1,argv[i+1]);
6756 break;
6757 }
6758 break;
6759 }
6760 case 'm':
6761 {
6762 if (LocaleCompare("matte",option+1) == 0)
6763 {
6764 if (*option == '+')
6765 {
6766 (void) SetImageOption(image_info,option+1,"false");
6767 break;
6768 }
6769 (void) SetImageOption(image_info,option+1,"true");
6770 break;
6771 }
6772 if (LocaleCompare("mattecolor",option+1) == 0)
6773 {
6774 if (*option == '+')
6775 {
6776 (void) SetImageOption(image_info,option+1,argv[i+1]);
6777 (void) QueryColorDatabase(MatteColor,&image_info->matte_color,
6778 exception);
6779 break;
6780 }
6781 (void) SetImageOption(image_info,option+1,argv[i+1]);
6782 (void) QueryColorDatabase(argv[i+1],&image_info->matte_color,
6783 exception);
6784 break;
6785 }
6786 if (LocaleCompare("monitor",option+1) == 0)
6787 {
6788 (void) SetImageInfoProgressMonitor(image_info,MonitorProgress,
6789 (void *) NULL);
6790 break;
6791 }
6792 if (LocaleCompare("monochrome",option+1) == 0)
6793 {
6794 image_info->monochrome=(*option == '-') ? MagickTrue : MagickFalse;
6795 break;
6796 }
6797 break;
6798 }
6799 case 'o':
6800 {
6801 if (LocaleCompare("orient",option+1) == 0)
6802 {
6803 if (*option == '+')
6804 {
6805 image_info->orientation=UndefinedOrientation;
6806 (void) SetImageOption(image_info,option+1,"undefined");
6807 break;
6808 }
cristy042ee782011-04-22 18:48:30 +00006809 image_info->orientation=(OrientationType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006810 MagickOrientationOptions,MagickFalse,argv[i+1]);
cristyc6e214d2010-08-08 00:31:08 +00006811 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006812 break;
6813 }
6814 }
6815 case 'p':
6816 {
6817 if (LocaleCompare("page",option+1) == 0)
6818 {
6819 char
6820 *canonical_page,
6821 page[MaxTextExtent];
6822
6823 const char
6824 *image_option;
6825
6826 MagickStatusType
6827 flags;
6828
6829 RectangleInfo
6830 geometry;
6831
6832 if (*option == '+')
6833 {
6834 (void) DeleteImageOption(image_info,option+1);
6835 (void) CloneString(&image_info->page,(char *) NULL);
6836 break;
6837 }
6838 (void) ResetMagickMemory(&geometry,0,sizeof(geometry));
6839 image_option=GetImageOption(image_info,"page");
6840 if (image_option != (const char *) NULL)
6841 flags=ParseAbsoluteGeometry(image_option,&geometry);
6842 canonical_page=GetPageGeometry(argv[i+1]);
6843 flags=ParseAbsoluteGeometry(canonical_page,&geometry);
6844 canonical_page=DestroyString(canonical_page);
cristyb51dff52011-05-19 16:55:47 +00006845 (void) FormatLocaleString(page,MaxTextExtent,"%lux%lu",
cristyf2faecf2010-05-28 19:19:36 +00006846 (unsigned long) geometry.width,(unsigned long) geometry.height);
cristy3ed852e2009-09-05 21:47:34 +00006847 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
cristyb51dff52011-05-19 16:55:47 +00006848 (void) FormatLocaleString(page,MaxTextExtent,"%lux%lu%+ld%+ld",
cristyf2faecf2010-05-28 19:19:36 +00006849 (unsigned long) geometry.width,(unsigned long) geometry.height,
6850 (long) geometry.x,(long) geometry.y);
cristy3ed852e2009-09-05 21:47:34 +00006851 (void) SetImageOption(image_info,option+1,page);
6852 (void) CloneString(&image_info->page,page);
6853 break;
6854 }
6855 if (LocaleCompare("pen",option+1) == 0)
6856 {
6857 if (*option == '+')
6858 {
6859 (void) SetImageOption(image_info,option+1,"none");
6860 break;
6861 }
6862 (void) SetImageOption(image_info,option+1,argv[i+1]);
6863 break;
6864 }
6865 if (LocaleCompare("ping",option+1) == 0)
6866 {
6867 image_info->ping=(*option == '-') ? MagickTrue : MagickFalse;
6868 break;
6869 }
6870 if (LocaleCompare("pointsize",option+1) == 0)
6871 {
6872 if (*option == '+')
6873 geometry_info.rho=0.0;
6874 else
6875 (void) ParseGeometry(argv[i+1],&geometry_info);
6876 image_info->pointsize=geometry_info.rho;
6877 break;
6878 }
cristye7f51092010-01-17 00:39:37 +00006879 if (LocaleCompare("precision",option+1) == 0)
6880 {
cristybf2766a2010-01-17 03:33:23 +00006881 (void) SetMagickPrecision(StringToInteger(argv[i+1]));
cristye7f51092010-01-17 00:39:37 +00006882 break;
6883 }
cristy3ed852e2009-09-05 21:47:34 +00006884 if (LocaleCompare("preview",option+1) == 0)
6885 {
6886 /*
6887 Preview image.
6888 */
6889 if (*option == '+')
6890 {
6891 image_info->preview_type=UndefinedPreview;
6892 break;
6893 }
cristy042ee782011-04-22 18:48:30 +00006894 image_info->preview_type=(PreviewType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006895 MagickPreviewOptions,MagickFalse,argv[i+1]);
6896 break;
6897 }
6898 break;
6899 }
6900 case 'q':
6901 {
6902 if (LocaleCompare("quality",option+1) == 0)
6903 {
6904 /*
6905 Set image compression quality.
6906 */
6907 if (*option == '+')
6908 {
6909 image_info->quality=UndefinedCompressionQuality;
6910 (void) SetImageOption(image_info,option+1,"0");
6911 break;
6912 }
cristye27293e2009-12-18 02:53:20 +00006913 image_info->quality=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006914 (void) SetImageOption(image_info,option+1,argv[i+1]);
6915 break;
6916 }
6917 if (LocaleCompare("quiet",option+1) == 0)
6918 {
6919 static WarningHandler
6920 warning_handler = (WarningHandler) NULL;
6921
6922 if (*option == '+')
6923 {
6924 /*
6925 Restore error or warning messages.
6926 */
6927 warning_handler=SetWarningHandler(warning_handler);
6928 break;
6929 }
6930 /*
6931 Suppress error or warning messages.
6932 */
6933 warning_handler=SetWarningHandler((WarningHandler) NULL);
6934 break;
6935 }
6936 break;
6937 }
6938 case 'r':
6939 {
6940 if (LocaleCompare("red-primary",option+1) == 0)
6941 {
6942 if (*option == '+')
6943 {
6944 (void) SetImageOption(image_info,option+1,"0.0");
6945 break;
6946 }
6947 (void) SetImageOption(image_info,option+1,argv[i+1]);
6948 break;
6949 }
6950 break;
6951 }
6952 case 's':
6953 {
6954 if (LocaleCompare("sampling-factor",option+1) == 0)
6955 {
6956 /*
6957 Set image sampling factor.
6958 */
6959 if (*option == '+')
6960 {
6961 if (image_info->sampling_factor != (char *) NULL)
6962 image_info->sampling_factor=DestroyString(
6963 image_info->sampling_factor);
6964 break;
6965 }
6966 (void) CloneString(&image_info->sampling_factor,argv[i+1]);
6967 break;
6968 }
6969 if (LocaleCompare("scene",option+1) == 0)
6970 {
6971 /*
6972 Set image scene.
6973 */
6974 if (*option == '+')
6975 {
6976 image_info->scene=0;
6977 (void) SetImageOption(image_info,option+1,"0");
6978 break;
6979 }
cristye27293e2009-12-18 02:53:20 +00006980 image_info->scene=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006981 (void) SetImageOption(image_info,option+1,argv[i+1]);
6982 break;
6983 }
6984 if (LocaleCompare("seed",option+1) == 0)
6985 {
cristybb503372010-05-27 20:51:26 +00006986 size_t
cristy3ed852e2009-09-05 21:47:34 +00006987 seed;
6988
6989 if (*option == '+')
6990 {
cristybb503372010-05-27 20:51:26 +00006991 seed=(size_t) time((time_t *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00006992 SeedPseudoRandomGenerator(seed);
6993 break;
6994 }
cristye27293e2009-12-18 02:53:20 +00006995 seed=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006996 SeedPseudoRandomGenerator(seed);
6997 break;
6998 }
6999 if (LocaleCompare("size",option+1) == 0)
7000 {
7001 if (*option == '+')
7002 {
7003 if (image_info->size != (char *) NULL)
7004 image_info->size=DestroyString(image_info->size);
7005 break;
7006 }
7007 (void) CloneString(&image_info->size,argv[i+1]);
7008 break;
7009 }
7010 if (LocaleCompare("stroke",option+1) == 0)
7011 {
7012 if (*option == '+')
7013 {
7014 (void) SetImageOption(image_info,option+1,"none");
7015 break;
7016 }
7017 (void) SetImageOption(image_info,option+1,argv[i+1]);
7018 break;
7019 }
7020 if (LocaleCompare("strokewidth",option+1) == 0)
7021 {
7022 if (*option == '+')
7023 {
7024 (void) SetImageOption(image_info,option+1,"0");
7025 break;
7026 }
7027 (void) SetImageOption(image_info,option+1,argv[i+1]);
7028 break;
7029 }
cristyd9a29192010-10-16 16:49:53 +00007030 if (LocaleCompare("synchronize",option+1) == 0)
7031 {
7032 if (*option == '+')
7033 {
7034 image_info->synchronize=MagickFalse;
7035 break;
7036 }
7037 image_info->synchronize=MagickTrue;
7038 break;
7039 }
cristy3ed852e2009-09-05 21:47:34 +00007040 break;
7041 }
7042 case 't':
7043 {
7044 if (LocaleCompare("taint",option+1) == 0)
7045 {
7046 if (*option == '+')
7047 {
7048 (void) SetImageOption(image_info,option+1,"false");
7049 break;
7050 }
7051 (void) SetImageOption(image_info,option+1,"true");
7052 break;
7053 }
7054 if (LocaleCompare("texture",option+1) == 0)
7055 {
7056 if (*option == '+')
7057 {
7058 if (image_info->texture != (char *) NULL)
7059 image_info->texture=DestroyString(image_info->texture);
7060 break;
7061 }
7062 (void) CloneString(&image_info->texture,argv[i+1]);
7063 break;
7064 }
7065 if (LocaleCompare("tile-offset",option+1) == 0)
7066 {
7067 if (*option == '+')
7068 {
7069 (void) SetImageOption(image_info,option+1,"0");
7070 break;
7071 }
7072 (void) SetImageOption(image_info,option+1,argv[i+1]);
7073 break;
7074 }
7075 if (LocaleCompare("transparent-color",option+1) == 0)
7076 {
7077 if (*option == '+')
7078 {
7079 (void) QueryColorDatabase("none",&image_info->transparent_color, exception);
7080 (void) SetImageOption(image_info,option+1,"none");
7081 break;
7082 }
7083 (void) QueryColorDatabase(argv[i+1],&image_info->transparent_color,
7084 exception);
7085 (void) SetImageOption(image_info,option+1,argv[i+1]);
7086 break;
7087 }
7088 if (LocaleCompare("type",option+1) == 0)
7089 {
7090 if (*option == '+')
7091 {
cristy5f1c1ff2010-12-23 21:38:06 +00007092 image_info->type=UndefinedType;
cristy3ed852e2009-09-05 21:47:34 +00007093 (void) SetImageOption(image_info,option+1,"undefined");
7094 break;
7095 }
cristy042ee782011-04-22 18:48:30 +00007096 image_info->type=(ImageType) ParseCommandOption(MagickTypeOptions,
cristy3ed852e2009-09-05 21:47:34 +00007097 MagickFalse,argv[i+1]);
7098 (void) SetImageOption(image_info,option+1,argv[i+1]);
7099 break;
7100 }
7101 break;
7102 }
7103 case 'u':
7104 {
7105 if (LocaleCompare("undercolor",option+1) == 0)
7106 {
7107 if (*option == '+')
7108 {
7109 (void) DeleteImageOption(image_info,option+1);
7110 break;
7111 }
7112 (void) SetImageOption(image_info,option+1,argv[i+1]);
7113 break;
7114 }
7115 if (LocaleCompare("units",option+1) == 0)
7116 {
7117 if (*option == '+')
7118 {
7119 image_info->units=UndefinedResolution;
7120 (void) SetImageOption(image_info,option+1,"undefined");
7121 break;
7122 }
cristy042ee782011-04-22 18:48:30 +00007123 image_info->units=(ResolutionType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007124 MagickResolutionOptions,MagickFalse,argv[i+1]);
7125 (void) SetImageOption(image_info,option+1,argv[i+1]);
7126 break;
7127 }
7128 break;
7129 }
7130 case 'v':
7131 {
7132 if (LocaleCompare("verbose",option+1) == 0)
7133 {
7134 if (*option == '+')
7135 {
7136 image_info->verbose=MagickFalse;
7137 break;
7138 }
7139 image_info->verbose=MagickTrue;
7140 image_info->ping=MagickFalse;
7141 break;
7142 }
7143 if (LocaleCompare("view",option+1) == 0)
7144 {
7145 if (*option == '+')
7146 {
7147 if (image_info->view != (char *) NULL)
7148 image_info->view=DestroyString(image_info->view);
7149 break;
7150 }
7151 (void) CloneString(&image_info->view,argv[i+1]);
7152 break;
7153 }
7154 if (LocaleCompare("virtual-pixel",option+1) == 0)
7155 {
7156 if (*option == '+')
7157 {
7158 image_info->virtual_pixel_method=UndefinedVirtualPixelMethod;
7159 (void) SetImageOption(image_info,option+1,"undefined");
7160 break;
7161 }
7162 image_info->virtual_pixel_method=(VirtualPixelMethod)
cristy042ee782011-04-22 18:48:30 +00007163 ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00007164 argv[i+1]);
7165 (void) SetImageOption(image_info,option+1,argv[i+1]);
7166 break;
7167 }
7168 break;
7169 }
7170 case 'w':
7171 {
7172 if (LocaleCompare("white-point",option+1) == 0)
7173 {
7174 if (*option == '+')
7175 {
7176 (void) SetImageOption(image_info,option+1,"0.0");
7177 break;
7178 }
7179 (void) SetImageOption(image_info,option+1,argv[i+1]);
7180 break;
7181 }
7182 break;
7183 }
7184 default:
7185 break;
7186 }
7187 i+=count;
7188 }
7189 return(MagickTrue);
7190}
7191
7192/*
7193%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7194% %
7195% %
7196% %
7197+ M o g r i f y I m a g e L i s t %
7198% %
7199% %
7200% %
7201%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7202%
7203% MogrifyImageList() applies any command line options that might affect the
7204% entire image list (e.g. -append, -coalesce, etc.).
7205%
7206% The format of the MogrifyImage method is:
7207%
7208% MagickBooleanType MogrifyImageList(ImageInfo *image_info,const int argc,
7209% const char **argv,Image **images,ExceptionInfo *exception)
7210%
7211% A description of each parameter follows:
7212%
7213% o image_info: the image info..
7214%
7215% o argc: Specifies a pointer to an integer describing the number of
7216% elements in the argument vector.
7217%
7218% o argv: Specifies a pointer to a text array containing the command line
7219% arguments.
7220%
anthonye9c27192011-03-27 08:07:06 +00007221% o images: pointer to pointer of the first image in image list.
cristy3ed852e2009-09-05 21:47:34 +00007222%
7223% o exception: return any errors or warnings in this structure.
7224%
7225*/
7226WandExport MagickBooleanType MogrifyImageList(ImageInfo *image_info,
7227 const int argc,const char **argv,Image **images,ExceptionInfo *exception)
7228{
cristy3ed852e2009-09-05 21:47:34 +00007229 const char
7230 *option;
7231
cristy6b3da3a2010-06-20 02:21:46 +00007232 ImageInfo
7233 *mogrify_info;
cristy3ed852e2009-09-05 21:47:34 +00007234
7235 MagickStatusType
7236 status;
7237
7238 QuantizeInfo
7239 *quantize_info;
7240
cristybb503372010-05-27 20:51:26 +00007241 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00007242 i;
7243
cristy6b3da3a2010-06-20 02:21:46 +00007244 ssize_t
7245 count,
7246 index;
7247
cristy3ed852e2009-09-05 21:47:34 +00007248 /*
7249 Apply options to the image list.
7250 */
7251 assert(image_info != (ImageInfo *) NULL);
7252 assert(image_info->signature == MagickSignature);
7253 assert(images != (Image **) NULL);
anthonye9c27192011-03-27 08:07:06 +00007254 assert((*images)->previous == (Image *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00007255 assert((*images)->signature == MagickSignature);
7256 if ((*images)->debug != MagickFalse)
7257 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
7258 (*images)->filename);
7259 if ((argc <= 0) || (*argv == (char *) NULL))
7260 return(MagickTrue);
cristy6b3da3a2010-06-20 02:21:46 +00007261 mogrify_info=CloneImageInfo(image_info);
7262 quantize_info=AcquireQuantizeInfo(mogrify_info);
cristy3ed852e2009-09-05 21:47:34 +00007263 status=MagickTrue;
cristybb503372010-05-27 20:51:26 +00007264 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00007265 {
cristy74fe8f12009-10-03 19:09:01 +00007266 if (*images == (Image *) NULL)
7267 break;
cristy3ed852e2009-09-05 21:47:34 +00007268 option=argv[i];
cristy042ee782011-04-22 18:48:30 +00007269 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00007270 continue;
cristy042ee782011-04-22 18:48:30 +00007271 count=ParseCommandOption(MagickCommandOptions,MagickFalse,option);
anthonyce2716b2011-04-22 09:51:34 +00007272 count=MagickMax(count,0L);
cristycee97112010-05-28 00:44:52 +00007273 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00007274 break;
cristy6b3da3a2010-06-20 02:21:46 +00007275 status=MogrifyImageInfo(mogrify_info,(int) count+1,argv+i,exception);
cristy3ed852e2009-09-05 21:47:34 +00007276 switch (*(option+1))
7277 {
7278 case 'a':
7279 {
7280 if (LocaleCompare("affinity",option+1) == 0)
7281 {
cristy6b3da3a2010-06-20 02:21:46 +00007282 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007283 if (*option == '+')
7284 {
7285 (void) RemapImages(quantize_info,*images,(Image *) NULL);
7286 InheritException(exception,&(*images)->exception);
7287 break;
7288 }
7289 i++;
7290 break;
7291 }
7292 if (LocaleCompare("append",option+1) == 0)
7293 {
7294 Image
7295 *append_image;
7296
cristy6b3da3a2010-06-20 02:21:46 +00007297 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007298 append_image=AppendImages(*images,*option == '-' ? MagickTrue :
7299 MagickFalse,exception);
7300 if (append_image == (Image *) NULL)
7301 {
7302 status=MagickFalse;
7303 break;
7304 }
7305 *images=DestroyImageList(*images);
7306 *images=append_image;
7307 break;
7308 }
7309 if (LocaleCompare("average",option+1) == 0)
7310 {
7311 Image
7312 *average_image;
7313
cristyd18ae7c2010-03-07 17:39:52 +00007314 /*
7315 Average an image sequence (deprecated).
7316 */
cristy6b3da3a2010-06-20 02:21:46 +00007317 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007318 average_image=EvaluateImages(*images,MeanEvaluateOperator,
7319 exception);
cristy3ed852e2009-09-05 21:47:34 +00007320 if (average_image == (Image *) NULL)
7321 {
7322 status=MagickFalse;
7323 break;
7324 }
7325 *images=DestroyImageList(*images);
7326 *images=average_image;
7327 break;
7328 }
7329 break;
7330 }
7331 case 'c':
7332 {
7333 if (LocaleCompare("channel",option+1) == 0)
7334 {
cristyf4ad9df2011-07-08 16:49:03 +00007335 ChannelType
7336 channel;
7337
cristy3ed852e2009-09-05 21:47:34 +00007338 if (*option == '+')
7339 {
7340 channel=DefaultChannels;
7341 break;
7342 }
7343 channel=(ChannelType) ParseChannelOption(argv[i+1]);
cristyf4ad9df2011-07-08 16:49:03 +00007344 SetPixelComponentMap(*images,channel);
cristy3ed852e2009-09-05 21:47:34 +00007345 break;
7346 }
7347 if (LocaleCompare("clut",option+1) == 0)
7348 {
7349 Image
7350 *clut_image,
7351 *image;
7352
cristy6b3da3a2010-06-20 02:21:46 +00007353 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007354 image=RemoveFirstImageFromList(images);
7355 clut_image=RemoveFirstImageFromList(images);
7356 if (clut_image == (Image *) NULL)
7357 {
7358 status=MagickFalse;
7359 break;
7360 }
cristyf89cb1d2011-07-07 01:24:37 +00007361 (void) ClutImage(image,clut_image);
cristy3ed852e2009-09-05 21:47:34 +00007362 clut_image=DestroyImage(clut_image);
7363 InheritException(exception,&image->exception);
7364 *images=DestroyImageList(*images);
7365 *images=image;
7366 break;
7367 }
7368 if (LocaleCompare("coalesce",option+1) == 0)
7369 {
7370 Image
7371 *coalesce_image;
7372
cristy6b3da3a2010-06-20 02:21:46 +00007373 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007374 coalesce_image=CoalesceImages(*images,exception);
7375 if (coalesce_image == (Image *) NULL)
7376 {
7377 status=MagickFalse;
7378 break;
7379 }
7380 *images=DestroyImageList(*images);
7381 *images=coalesce_image;
7382 break;
7383 }
7384 if (LocaleCompare("combine",option+1) == 0)
7385 {
7386 Image
7387 *combine_image;
7388
cristy6b3da3a2010-06-20 02:21:46 +00007389 (void) SyncImagesSettings(mogrify_info,*images);
cristy3139dc22011-07-08 00:11:42 +00007390 combine_image=CombineImages(*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007391 if (combine_image == (Image *) NULL)
7392 {
7393 status=MagickFalse;
7394 break;
7395 }
7396 *images=DestroyImageList(*images);
7397 *images=combine_image;
7398 break;
7399 }
7400 if (LocaleCompare("composite",option+1) == 0)
7401 {
7402 Image
7403 *mask_image,
7404 *composite_image,
7405 *image;
7406
7407 RectangleInfo
7408 geometry;
7409
cristy6b3da3a2010-06-20 02:21:46 +00007410 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007411 image=RemoveFirstImageFromList(images);
7412 composite_image=RemoveFirstImageFromList(images);
7413 if (composite_image == (Image *) NULL)
7414 {
7415 status=MagickFalse;
7416 break;
7417 }
7418 (void) TransformImage(&composite_image,(char *) NULL,
7419 composite_image->geometry);
7420 SetGeometry(composite_image,&geometry);
7421 (void) ParseAbsoluteGeometry(composite_image->geometry,&geometry);
7422 GravityAdjustGeometry(image->columns,image->rows,image->gravity,
7423 &geometry);
7424 mask_image=RemoveFirstImageFromList(images);
7425 if (mask_image != (Image *) NULL)
7426 {
7427 if ((image->compose == DisplaceCompositeOp) ||
7428 (image->compose == DistortCompositeOp))
7429 {
7430 /*
7431 Merge Y displacement into X displacement image.
7432 */
7433 (void) CompositeImage(composite_image,CopyGreenCompositeOp,
7434 mask_image,0,0);
7435 mask_image=DestroyImage(mask_image);
7436 }
7437 else
7438 {
7439 /*
7440 Set a blending mask for the composition.
7441 */
anthonya129f702011-04-14 01:08:48 +00007442 /* POSIBLE ERROR; what if image->mask already set */
cristy3ed852e2009-09-05 21:47:34 +00007443 image->mask=mask_image;
7444 (void) NegateImage(image->mask,MagickFalse);
7445 }
7446 }
cristyf4ad9df2011-07-08 16:49:03 +00007447 (void) CompositeImage(image,image->compose,composite_image,
7448 geometry.x,geometry.y);
anthonya129f702011-04-14 01:08:48 +00007449 if (mask_image != (Image *) NULL)
7450 mask_image=image->mask=DestroyImage(image->mask);
cristy3ed852e2009-09-05 21:47:34 +00007451 composite_image=DestroyImage(composite_image);
7452 InheritException(exception,&image->exception);
7453 *images=DestroyImageList(*images);
7454 *images=image;
7455 break;
7456 }
anthony9f4f0342011-03-28 11:47:22 +00007457#if 0
7458This has been merged completely into MogrifyImage()
cristy3ed852e2009-09-05 21:47:34 +00007459 if (LocaleCompare("crop",option+1) == 0)
7460 {
7461 MagickStatusType
7462 flags;
7463
7464 RectangleInfo
7465 geometry;
7466
anthonye9c27192011-03-27 08:07:06 +00007467 /*
anthony9f4f0342011-03-28 11:47:22 +00007468 Crop Image.
anthonye9c27192011-03-27 08:07:06 +00007469 */
cristy6b3da3a2010-06-20 02:21:46 +00007470 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007471 flags=ParseGravityGeometry(*images,argv[i+1],&geometry,exception);
7472 if (((geometry.width == 0) && (geometry.height == 0)) ||
7473 ((flags & XValue) != 0) || ((flags & YValue) != 0))
7474 break;
7475 (void) TransformImages(images,argv[i+1],(char *) NULL);
7476 InheritException(exception,&(*images)->exception);
7477 break;
7478 }
anthony9f4f0342011-03-28 11:47:22 +00007479#endif
cristy3ed852e2009-09-05 21:47:34 +00007480 break;
7481 }
7482 case 'd':
7483 {
7484 if (LocaleCompare("deconstruct",option+1) == 0)
7485 {
7486 Image
7487 *deconstruct_image;
7488
cristy6b3da3a2010-06-20 02:21:46 +00007489 (void) SyncImagesSettings(mogrify_info,*images);
cristy8a9106f2011-07-05 14:39:26 +00007490 deconstruct_image=CompareImagesLayers(*images,CompareAnyLayer,
cristy4c08aed2011-07-01 19:47:50 +00007491 exception);
cristy3ed852e2009-09-05 21:47:34 +00007492 if (deconstruct_image == (Image *) NULL)
7493 {
7494 status=MagickFalse;
7495 break;
7496 }
7497 *images=DestroyImageList(*images);
7498 *images=deconstruct_image;
7499 break;
7500 }
7501 if (LocaleCompare("delete",option+1) == 0)
7502 {
7503 if (*option == '+')
7504 DeleteImages(images,"-1",exception);
7505 else
7506 DeleteImages(images,argv[i+1],exception);
7507 break;
7508 }
7509 if (LocaleCompare("dither",option+1) == 0)
7510 {
7511 if (*option == '+')
7512 {
7513 quantize_info->dither=MagickFalse;
7514 break;
7515 }
7516 quantize_info->dither=MagickTrue;
cristy042ee782011-04-22 18:48:30 +00007517 quantize_info->dither_method=(DitherMethod) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007518 MagickDitherOptions,MagickFalse,argv[i+1]);
7519 break;
7520 }
cristyecb10ff2011-03-22 13:14:03 +00007521 if (LocaleCompare("duplicate",option+1) == 0)
7522 {
cristy72988482011-03-29 16:34:38 +00007523 Image
7524 *duplicate_images;
cristybf95deb2011-03-23 00:25:36 +00007525
anthony2b6bcae2011-03-23 13:05:34 +00007526 if (*option == '+')
cristy72988482011-03-29 16:34:38 +00007527 duplicate_images=DuplicateImages(*images,1,"-1",exception);
7528 else
7529 {
7530 const char
7531 *p;
7532
anthony2b6bcae2011-03-23 13:05:34 +00007533 size_t
7534 number_duplicates;
anthony9bd15492011-03-23 02:11:13 +00007535
anthony2b6bcae2011-03-23 13:05:34 +00007536 number_duplicates=(size_t) StringToLong(argv[i+1]);
cristy72988482011-03-29 16:34:38 +00007537 p=strchr(argv[i+1],',');
7538 if (p == (const char *) NULL)
7539 duplicate_images=DuplicateImages(*images,number_duplicates,
7540 "-1",exception);
anthony2b6bcae2011-03-23 13:05:34 +00007541 else
cristy72988482011-03-29 16:34:38 +00007542 duplicate_images=DuplicateImages(*images,number_duplicates,p,
7543 exception);
anthony2b6bcae2011-03-23 13:05:34 +00007544 }
7545 AppendImageToList(images, duplicate_images);
7546 (void) SyncImagesSettings(mogrify_info,*images);
cristyecb10ff2011-03-22 13:14:03 +00007547 break;
7548 }
cristy3ed852e2009-09-05 21:47:34 +00007549 break;
7550 }
cristyd18ae7c2010-03-07 17:39:52 +00007551 case 'e':
7552 {
7553 if (LocaleCompare("evaluate-sequence",option+1) == 0)
7554 {
7555 Image
7556 *evaluate_image;
7557
7558 MagickEvaluateOperator
7559 op;
7560
cristy6b3da3a2010-06-20 02:21:46 +00007561 (void) SyncImageSettings(mogrify_info,*images);
cristy042ee782011-04-22 18:48:30 +00007562 op=(MagickEvaluateOperator) ParseCommandOption(MagickEvaluateOptions,
cristyd18ae7c2010-03-07 17:39:52 +00007563 MagickFalse,argv[i+1]);
7564 evaluate_image=EvaluateImages(*images,op,exception);
7565 if (evaluate_image == (Image *) NULL)
7566 {
7567 status=MagickFalse;
7568 break;
7569 }
7570 *images=DestroyImageList(*images);
7571 *images=evaluate_image;
7572 break;
7573 }
7574 break;
7575 }
cristy3ed852e2009-09-05 21:47:34 +00007576 case 'f':
7577 {
cristyf0a247f2009-10-04 00:20:03 +00007578 if (LocaleCompare("fft",option+1) == 0)
7579 {
7580 Image
7581 *fourier_image;
7582
7583 /*
7584 Implements the discrete Fourier transform (DFT).
7585 */
cristy6b3da3a2010-06-20 02:21:46 +00007586 (void) SyncImageSettings(mogrify_info,*images);
cristyf0a247f2009-10-04 00:20:03 +00007587 fourier_image=ForwardFourierTransformImage(*images,*option == '-' ?
7588 MagickTrue : MagickFalse,exception);
7589 if (fourier_image == (Image *) NULL)
7590 break;
7591 *images=DestroyImage(*images);
7592 *images=fourier_image;
7593 break;
7594 }
cristy3ed852e2009-09-05 21:47:34 +00007595 if (LocaleCompare("flatten",option+1) == 0)
7596 {
7597 Image
7598 *flatten_image;
7599
cristy6b3da3a2010-06-20 02:21:46 +00007600 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007601 flatten_image=MergeImageLayers(*images,FlattenLayer,exception);
7602 if (flatten_image == (Image *) NULL)
7603 break;
7604 *images=DestroyImageList(*images);
7605 *images=flatten_image;
7606 break;
7607 }
7608 if (LocaleCompare("fx",option+1) == 0)
7609 {
7610 Image
7611 *fx_image;
7612
cristy6b3da3a2010-06-20 02:21:46 +00007613 (void) SyncImagesSettings(mogrify_info,*images);
cristy490408a2011-07-07 14:42:05 +00007614 fx_image=FxImage(*images,argv[i+1],exception);
cristy3ed852e2009-09-05 21:47:34 +00007615 if (fx_image == (Image *) NULL)
7616 {
7617 status=MagickFalse;
7618 break;
7619 }
7620 *images=DestroyImageList(*images);
7621 *images=fx_image;
7622 break;
7623 }
7624 break;
7625 }
7626 case 'h':
7627 {
7628 if (LocaleCompare("hald-clut",option+1) == 0)
7629 {
7630 Image
7631 *hald_image,
7632 *image;
7633
cristy6b3da3a2010-06-20 02:21:46 +00007634 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007635 image=RemoveFirstImageFromList(images);
7636 hald_image=RemoveFirstImageFromList(images);
7637 if (hald_image == (Image *) NULL)
7638 {
7639 status=MagickFalse;
7640 break;
7641 }
cristyf89cb1d2011-07-07 01:24:37 +00007642 (void) HaldClutImage(image,hald_image);
cristy3ed852e2009-09-05 21:47:34 +00007643 hald_image=DestroyImage(hald_image);
7644 InheritException(exception,&image->exception);
cristy0aff6ea2009-11-14 01:40:53 +00007645 if (*images != (Image *) NULL)
7646 *images=DestroyImageList(*images);
cristy3ed852e2009-09-05 21:47:34 +00007647 *images=image;
7648 break;
7649 }
7650 break;
7651 }
7652 case 'i':
7653 {
7654 if (LocaleCompare("ift",option+1) == 0)
7655 {
7656 Image
cristy8587f882009-11-13 20:28:49 +00007657 *fourier_image,
7658 *magnitude_image,
7659 *phase_image;
cristy3ed852e2009-09-05 21:47:34 +00007660
7661 /*
7662 Implements the inverse fourier discrete Fourier transform (DFT).
7663 */
cristy6b3da3a2010-06-20 02:21:46 +00007664 (void) SyncImagesSettings(mogrify_info,*images);
cristy8587f882009-11-13 20:28:49 +00007665 magnitude_image=RemoveFirstImageFromList(images);
7666 phase_image=RemoveFirstImageFromList(images);
7667 if (phase_image == (Image *) NULL)
7668 {
7669 status=MagickFalse;
7670 break;
7671 }
7672 fourier_image=InverseFourierTransformImage(magnitude_image,
7673 phase_image,*option == '-' ? MagickTrue : MagickFalse,exception);
cristy3ed852e2009-09-05 21:47:34 +00007674 if (fourier_image == (Image *) NULL)
7675 break;
cristy0aff6ea2009-11-14 01:40:53 +00007676 if (*images != (Image *) NULL)
7677 *images=DestroyImage(*images);
cristy3ed852e2009-09-05 21:47:34 +00007678 *images=fourier_image;
7679 break;
7680 }
7681 if (LocaleCompare("insert",option+1) == 0)
7682 {
7683 Image
7684 *p,
7685 *q;
7686
7687 index=0;
7688 if (*option != '+')
cristy32c2aea2010-12-01 01:00:50 +00007689 index=(ssize_t) StringToLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007690 p=RemoveLastImageFromList(images);
7691 if (p == (Image *) NULL)
7692 {
7693 (void) ThrowMagickException(exception,GetMagickModule(),
7694 OptionError,"NoSuchImage","`%s'",argv[i+1]);
7695 status=MagickFalse;
7696 break;
7697 }
7698 q=p;
7699 if (index == 0)
7700 PrependImageToList(images,q);
7701 else
cristybb503372010-05-27 20:51:26 +00007702 if (index == (ssize_t) GetImageListLength(*images))
cristy3ed852e2009-09-05 21:47:34 +00007703 AppendImageToList(images,q);
7704 else
7705 {
7706 q=GetImageFromList(*images,index-1);
7707 if (q == (Image *) NULL)
7708 {
7709 (void) ThrowMagickException(exception,GetMagickModule(),
7710 OptionError,"NoSuchImage","`%s'",argv[i+1]);
7711 status=MagickFalse;
7712 break;
7713 }
7714 InsertImageInList(&q,p);
7715 }
7716 *images=GetFirstImageInList(q);
7717 break;
7718 }
7719 break;
7720 }
7721 case 'l':
7722 {
7723 if (LocaleCompare("layers",option+1) == 0)
7724 {
7725 Image
7726 *layers;
7727
7728 ImageLayerMethod
7729 method;
7730
cristy6b3da3a2010-06-20 02:21:46 +00007731 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007732 layers=(Image *) NULL;
cristy042ee782011-04-22 18:48:30 +00007733 method=(ImageLayerMethod) ParseCommandOption(MagickLayerOptions,
cristy3ed852e2009-09-05 21:47:34 +00007734 MagickFalse,argv[i+1]);
7735 switch (method)
7736 {
7737 case CoalesceLayer:
7738 {
7739 layers=CoalesceImages(*images,exception);
7740 break;
7741 }
7742 case CompareAnyLayer:
7743 case CompareClearLayer:
7744 case CompareOverlayLayer:
7745 default:
7746 {
cristy8a9106f2011-07-05 14:39:26 +00007747 layers=CompareImagesLayers(*images,method,exception);
cristy3ed852e2009-09-05 21:47:34 +00007748 break;
7749 }
7750 case MergeLayer:
7751 case FlattenLayer:
7752 case MosaicLayer:
7753 case TrimBoundsLayer:
7754 {
7755 layers=MergeImageLayers(*images,method,exception);
7756 break;
7757 }
7758 case DisposeLayer:
7759 {
7760 layers=DisposeImages(*images,exception);
7761 break;
7762 }
7763 case OptimizeImageLayer:
7764 {
7765 layers=OptimizeImageLayers(*images,exception);
7766 break;
7767 }
7768 case OptimizePlusLayer:
7769 {
7770 layers=OptimizePlusImageLayers(*images,exception);
7771 break;
7772 }
7773 case OptimizeTransLayer:
7774 {
7775 OptimizeImageTransparency(*images,exception);
7776 break;
7777 }
7778 case RemoveDupsLayer:
7779 {
7780 RemoveDuplicateLayers(images,exception);
7781 break;
7782 }
7783 case RemoveZeroLayer:
7784 {
7785 RemoveZeroDelayLayers(images,exception);
7786 break;
7787 }
7788 case OptimizeLayer:
7789 {
7790 /*
7791 General Purpose, GIF Animation Optimizer.
7792 */
7793 layers=CoalesceImages(*images,exception);
7794 if (layers == (Image *) NULL)
7795 {
7796 status=MagickFalse;
7797 break;
7798 }
7799 InheritException(exception,&layers->exception);
7800 *images=DestroyImageList(*images);
7801 *images=layers;
7802 layers=OptimizeImageLayers(*images,exception);
7803 if (layers == (Image *) NULL)
7804 {
7805 status=MagickFalse;
7806 break;
7807 }
7808 InheritException(exception,&layers->exception);
7809 *images=DestroyImageList(*images);
7810 *images=layers;
7811 layers=(Image *) NULL;
7812 OptimizeImageTransparency(*images,exception);
7813 InheritException(exception,&(*images)->exception);
7814 (void) RemapImages(quantize_info,*images,(Image *) NULL);
7815 break;
7816 }
7817 case CompositeLayer:
7818 {
7819 CompositeOperator
7820 compose;
7821
7822 Image
7823 *source;
7824
7825 RectangleInfo
7826 geometry;
7827
7828 /*
7829 Split image sequence at the first 'NULL:' image.
7830 */
7831 source=(*images);
7832 while (source != (Image *) NULL)
7833 {
7834 source=GetNextImageInList(source);
7835 if ((source != (Image *) NULL) &&
7836 (LocaleCompare(source->magick,"NULL") == 0))
7837 break;
7838 }
7839 if (source != (Image *) NULL)
7840 {
7841 if ((GetPreviousImageInList(source) == (Image *) NULL) ||
7842 (GetNextImageInList(source) == (Image *) NULL))
7843 source=(Image *) NULL;
7844 else
7845 {
7846 /*
7847 Separate the two lists, junk the null: image.
7848 */
7849 source=SplitImageList(source->previous);
7850 DeleteImageFromList(&source);
7851 }
7852 }
7853 if (source == (Image *) NULL)
7854 {
7855 (void) ThrowMagickException(exception,GetMagickModule(),
7856 OptionError,"MissingNullSeparator","layers Composite");
7857 status=MagickFalse;
7858 break;
7859 }
7860 /*
7861 Adjust offset with gravity and virtual canvas.
7862 */
7863 SetGeometry(*images,&geometry);
7864 (void) ParseAbsoluteGeometry((*images)->geometry,&geometry);
7865 geometry.width=source->page.width != 0 ?
7866 source->page.width : source->columns;
7867 geometry.height=source->page.height != 0 ?
7868 source->page.height : source->rows;
7869 GravityAdjustGeometry((*images)->page.width != 0 ?
7870 (*images)->page.width : (*images)->columns,
7871 (*images)->page.height != 0 ? (*images)->page.height :
7872 (*images)->rows,(*images)->gravity,&geometry);
7873 compose=OverCompositeOp;
cristy6b3da3a2010-06-20 02:21:46 +00007874 option=GetImageOption(mogrify_info,"compose");
cristy3ed852e2009-09-05 21:47:34 +00007875 if (option != (const char *) NULL)
cristy042ee782011-04-22 18:48:30 +00007876 compose=(CompositeOperator) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007877 MagickComposeOptions,MagickFalse,option);
7878 CompositeLayers(*images,compose,source,geometry.x,geometry.y,
7879 exception);
7880 source=DestroyImageList(source);
7881 break;
7882 }
7883 }
7884 if (layers == (Image *) NULL)
7885 break;
7886 InheritException(exception,&layers->exception);
7887 *images=DestroyImageList(*images);
7888 *images=layers;
7889 break;
7890 }
7891 break;
7892 }
7893 case 'm':
7894 {
7895 if (LocaleCompare("map",option+1) == 0)
7896 {
cristy6b3da3a2010-06-20 02:21:46 +00007897 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007898 if (*option == '+')
7899 {
7900 (void) RemapImages(quantize_info,*images,(Image *) NULL);
7901 InheritException(exception,&(*images)->exception);
7902 break;
7903 }
7904 i++;
7905 break;
7906 }
cristyf40785b2010-03-06 02:27:27 +00007907 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00007908 {
7909 Image
cristyf40785b2010-03-06 02:27:27 +00007910 *maximum_image;
cristy1c274c92010-03-06 02:06:45 +00007911
cristyd18ae7c2010-03-07 17:39:52 +00007912 /*
7913 Maximum image sequence (deprecated).
7914 */
cristy6b3da3a2010-06-20 02:21:46 +00007915 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007916 maximum_image=EvaluateImages(*images,MaxEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00007917 if (maximum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00007918 {
7919 status=MagickFalse;
7920 break;
7921 }
7922 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00007923 *images=maximum_image;
cristy1c274c92010-03-06 02:06:45 +00007924 break;
7925 }
cristyf40785b2010-03-06 02:27:27 +00007926 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00007927 {
7928 Image
cristyf40785b2010-03-06 02:27:27 +00007929 *minimum_image;
cristy1c274c92010-03-06 02:06:45 +00007930
cristyd18ae7c2010-03-07 17:39:52 +00007931 /*
7932 Minimum image sequence (deprecated).
7933 */
cristy6b3da3a2010-06-20 02:21:46 +00007934 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007935 minimum_image=EvaluateImages(*images,MinEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00007936 if (minimum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00007937 {
7938 status=MagickFalse;
7939 break;
7940 }
7941 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00007942 *images=minimum_image;
cristy1c274c92010-03-06 02:06:45 +00007943 break;
7944 }
cristy3ed852e2009-09-05 21:47:34 +00007945 if (LocaleCompare("morph",option+1) == 0)
7946 {
7947 Image
7948 *morph_image;
7949
cristy6b3da3a2010-06-20 02:21:46 +00007950 (void) SyncImagesSettings(mogrify_info,*images);
cristye27293e2009-12-18 02:53:20 +00007951 morph_image=MorphImages(*images,StringToUnsignedLong(argv[i+1]),
cristy3ed852e2009-09-05 21:47:34 +00007952 exception);
7953 if (morph_image == (Image *) NULL)
7954 {
7955 status=MagickFalse;
7956 break;
7957 }
7958 *images=DestroyImageList(*images);
7959 *images=morph_image;
7960 break;
7961 }
7962 if (LocaleCompare("mosaic",option+1) == 0)
7963 {
7964 Image
7965 *mosaic_image;
7966
cristy6b3da3a2010-06-20 02:21:46 +00007967 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007968 mosaic_image=MergeImageLayers(*images,MosaicLayer,exception);
7969 if (mosaic_image == (Image *) NULL)
7970 {
7971 status=MagickFalse;
7972 break;
7973 }
7974 *images=DestroyImageList(*images);
7975 *images=mosaic_image;
7976 break;
7977 }
7978 break;
7979 }
7980 case 'p':
7981 {
7982 if (LocaleCompare("print",option+1) == 0)
7983 {
7984 char
7985 *string;
7986
cristy6b3da3a2010-06-20 02:21:46 +00007987 (void) SyncImagesSettings(mogrify_info,*images);
7988 string=InterpretImageProperties(mogrify_info,*images,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007989 if (string == (char *) NULL)
7990 break;
7991 InheritException(exception,&(*images)->exception);
cristyb51dff52011-05-19 16:55:47 +00007992 (void) FormatLocaleFile(stdout,"%s",string);
cristy3ed852e2009-09-05 21:47:34 +00007993 string=DestroyString(string);
7994 }
7995 if (LocaleCompare("process",option+1) == 0)
7996 {
7997 char
7998 **arguments;
7999
8000 int
8001 j,
8002 number_arguments;
8003
cristy6b3da3a2010-06-20 02:21:46 +00008004 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00008005 arguments=StringToArgv(argv[i+1],&number_arguments);
8006 if (arguments == (char **) NULL)
8007 break;
8008 if ((argc > 1) && (strchr(arguments[1],'=') != (char *) NULL))
8009 {
8010 char
8011 breaker,
8012 quote,
8013 *token;
8014
8015 const char
8016 *arguments;
8017
8018 int
8019 next,
8020 status;
8021
8022 size_t
8023 length;
8024
8025 TokenInfo
8026 *token_info;
8027
8028 /*
8029 Support old style syntax, filter="-option arg".
8030 */
8031 length=strlen(argv[i+1]);
8032 token=(char *) NULL;
cristy37e0b382011-06-07 13:31:21 +00008033 if (~length >= (MaxTextExtent-1))
cristy3ed852e2009-09-05 21:47:34 +00008034 token=(char *) AcquireQuantumMemory(length+MaxTextExtent,
8035 sizeof(*token));
8036 if (token == (char *) NULL)
8037 break;
8038 next=0;
8039 arguments=argv[i+1];
8040 token_info=AcquireTokenInfo();
8041 status=Tokenizer(token_info,0,token,length,arguments,"","=",
8042 "\"",'\0',&breaker,&next,&quote);
8043 token_info=DestroyTokenInfo(token_info);
8044 if (status == 0)
8045 {
8046 const char
8047 *argv;
8048
8049 argv=(&(arguments[next]));
8050 (void) InvokeDynamicImageFilter(token,&(*images),1,&argv,
8051 exception);
8052 }
8053 token=DestroyString(token);
8054 break;
8055 }
cristy91c0da22010-05-02 01:44:07 +00008056 (void) SubstituteString(&arguments[1],"-","");
cristy3ed852e2009-09-05 21:47:34 +00008057 (void) InvokeDynamicImageFilter(arguments[1],&(*images),
8058 number_arguments-2,(const char **) arguments+2,exception);
8059 for (j=0; j < number_arguments; j++)
8060 arguments[j]=DestroyString(arguments[j]);
8061 arguments=(char **) RelinquishMagickMemory(arguments);
8062 break;
8063 }
8064 break;
8065 }
8066 case 'r':
8067 {
8068 if (LocaleCompare("reverse",option+1) == 0)
8069 {
8070 ReverseImageList(images);
8071 InheritException(exception,&(*images)->exception);
8072 break;
8073 }
8074 break;
8075 }
8076 case 's':
8077 {
cristy4285d782011-02-09 20:12:28 +00008078 if (LocaleCompare("smush",option+1) == 0)
8079 {
8080 Image
8081 *smush_image;
8082
8083 ssize_t
8084 offset;
8085
8086 (void) SyncImagesSettings(mogrify_info,*images);
8087 offset=(ssize_t) StringToLong(argv[i+1]);
8088 smush_image=SmushImages(*images,*option == '-' ? MagickTrue :
8089 MagickFalse,offset,exception);
8090 if (smush_image == (Image *) NULL)
8091 {
8092 status=MagickFalse;
8093 break;
8094 }
8095 *images=DestroyImageList(*images);
8096 *images=smush_image;
8097 break;
8098 }
cristy3ed852e2009-09-05 21:47:34 +00008099 if (LocaleCompare("swap",option+1) == 0)
8100 {
8101 Image
8102 *p,
8103 *q,
8104 *swap;
8105
cristybb503372010-05-27 20:51:26 +00008106 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00008107 swap_index;
8108
8109 index=(-1);
8110 swap_index=(-2);
8111 if (*option != '+')
8112 {
8113 GeometryInfo
8114 geometry_info;
8115
8116 MagickStatusType
8117 flags;
8118
8119 swap_index=(-1);
8120 flags=ParseGeometry(argv[i+1],&geometry_info);
cristybb503372010-05-27 20:51:26 +00008121 index=(ssize_t) geometry_info.rho;
cristy3ed852e2009-09-05 21:47:34 +00008122 if ((flags & SigmaValue) != 0)
cristybb503372010-05-27 20:51:26 +00008123 swap_index=(ssize_t) geometry_info.sigma;
cristy3ed852e2009-09-05 21:47:34 +00008124 }
8125 p=GetImageFromList(*images,index);
8126 q=GetImageFromList(*images,swap_index);
8127 if ((p == (Image *) NULL) || (q == (Image *) NULL))
8128 {
8129 (void) ThrowMagickException(exception,GetMagickModule(),
8130 OptionError,"NoSuchImage","`%s'",(*images)->filename);
8131 status=MagickFalse;
8132 break;
8133 }
8134 if (p == q)
8135 break;
8136 swap=CloneImage(p,0,0,MagickTrue,exception);
8137 ReplaceImageInList(&p,CloneImage(q,0,0,MagickTrue,exception));
8138 ReplaceImageInList(&q,swap);
8139 *images=GetFirstImageInList(q);
8140 break;
8141 }
8142 break;
8143 }
8144 case 'w':
8145 {
8146 if (LocaleCompare("write",option+1) == 0)
8147 {
cristy071dd7b2010-04-09 13:04:54 +00008148 char
cristy06609ee2010-03-17 20:21:27 +00008149 key[MaxTextExtent];
8150
cristy3ed852e2009-09-05 21:47:34 +00008151 Image
8152 *write_images;
8153
8154 ImageInfo
8155 *write_info;
8156
cristy6b3da3a2010-06-20 02:21:46 +00008157 (void) SyncImagesSettings(mogrify_info,*images);
cristyb51dff52011-05-19 16:55:47 +00008158 (void) FormatLocaleString(key,MaxTextExtent,"cache:%s",argv[i+1]);
cristy06609ee2010-03-17 20:21:27 +00008159 (void) DeleteImageRegistry(key);
cristy3ed852e2009-09-05 21:47:34 +00008160 write_images=(*images);
8161 if (*option == '+')
8162 write_images=CloneImageList(*images,exception);
cristy6b3da3a2010-06-20 02:21:46 +00008163 write_info=CloneImageInfo(mogrify_info);
cristy3ed852e2009-09-05 21:47:34 +00008164 status&=WriteImages(write_info,write_images,argv[i+1],exception);
8165 write_info=DestroyImageInfo(write_info);
8166 if (*option == '+')
8167 write_images=DestroyImageList(write_images);
8168 break;
8169 }
8170 break;
8171 }
8172 default:
8173 break;
8174 }
8175 i+=count;
8176 }
8177 quantize_info=DestroyQuantizeInfo(quantize_info);
cristy6b3da3a2010-06-20 02:21:46 +00008178 mogrify_info=DestroyImageInfo(mogrify_info);
8179 status&=MogrifyImageInfo(image_info,argc,argv,exception);
cristy3ed852e2009-09-05 21:47:34 +00008180 return(status != 0 ? MagickTrue : MagickFalse);
8181}
8182
8183/*
8184%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8185% %
8186% %
8187% %
8188+ M o g r i f y I m a g e s %
8189% %
8190% %
8191% %
8192%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8193%
8194% MogrifyImages() applies image processing options to a sequence of images as
8195% prescribed by command line options.
8196%
8197% The format of the MogrifyImage method is:
8198%
8199% MagickBooleanType MogrifyImages(ImageInfo *image_info,
8200% const MagickBooleanType post,const int argc,const char **argv,
8201% Image **images,Exceptioninfo *exception)
8202%
8203% A description of each parameter follows:
8204%
8205% o image_info: the image info..
8206%
8207% o post: If true, post process image list operators otherwise pre-process.
8208%
8209% o argc: Specifies a pointer to an integer describing the number of
8210% elements in the argument vector.
8211%
8212% o argv: Specifies a pointer to a text array containing the command line
8213% arguments.
8214%
anthonye9c27192011-03-27 08:07:06 +00008215% o images: pointer to a pointer of the first image in image list.
cristy3ed852e2009-09-05 21:47:34 +00008216%
8217% o exception: return any errors or warnings in this structure.
8218%
8219*/
8220WandExport MagickBooleanType MogrifyImages(ImageInfo *image_info,
8221 const MagickBooleanType post,const int argc,const char **argv,
8222 Image **images,ExceptionInfo *exception)
8223{
8224#define MogrifyImageTag "Mogrify/Image"
8225
anthonye9c27192011-03-27 08:07:06 +00008226 MagickStatusType
8227 status;
cristy3ed852e2009-09-05 21:47:34 +00008228
cristy0e9f9c12010-02-11 03:00:47 +00008229 MagickBooleanType
8230 proceed;
8231
anthonye9c27192011-03-27 08:07:06 +00008232 size_t
8233 n;
cristy3ed852e2009-09-05 21:47:34 +00008234
cristybb503372010-05-27 20:51:26 +00008235 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00008236 i;
8237
cristy3ed852e2009-09-05 21:47:34 +00008238 assert(image_info != (ImageInfo *) NULL);
8239 assert(image_info->signature == MagickSignature);
8240 if (images == (Image **) NULL)
8241 return(MogrifyImage(image_info,argc,argv,images,exception));
anthonye9c27192011-03-27 08:07:06 +00008242 assert((*images)->previous == (Image *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00008243 assert((*images)->signature == MagickSignature);
8244 if ((*images)->debug != MagickFalse)
8245 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
8246 (*images)->filename);
8247 if ((argc <= 0) || (*argv == (char *) NULL))
8248 return(MagickTrue);
8249 (void) SetImageInfoProgressMonitor(image_info,(MagickProgressMonitor) NULL,
8250 (void *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00008251 status=0;
anthonye9c27192011-03-27 08:07:06 +00008252
anthonyce2716b2011-04-22 09:51:34 +00008253#if 0
cristy1e604812011-05-19 18:07:50 +00008254 (void) FormatLocaleFile(stderr, "mogrify start %s %d (%s)\n",argv[0],argc,
8255 post?"post":"pre");
anthonyce2716b2011-04-22 09:51:34 +00008256#endif
8257
anthonye9c27192011-03-27 08:07:06 +00008258 /*
8259 Pre-process multi-image sequence operators
8260 */
cristy3ed852e2009-09-05 21:47:34 +00008261 if (post == MagickFalse)
8262 status&=MogrifyImageList(image_info,argc,argv,images,exception);
anthonye9c27192011-03-27 08:07:06 +00008263 /*
8264 For each image, process simple single image operators
8265 */
8266 i=0;
8267 n=GetImageListLength(*images);
8268 for (;;)
cristy3ed852e2009-09-05 21:47:34 +00008269 {
anthonyce2716b2011-04-22 09:51:34 +00008270#if 0
cristy1e604812011-05-19 18:07:50 +00008271 (void) FormatLocaleFile(stderr,"mogrify %ld of %ld\n",(long)
8272 GetImageIndexInList(*images),(long)GetImageListLength(*images));
anthonyce2716b2011-04-22 09:51:34 +00008273#endif
anthonye9c27192011-03-27 08:07:06 +00008274 status&=MogrifyImage(image_info,argc,argv,images,exception);
8275 proceed=SetImageProgress(*images,MogrifyImageTag,(MagickOffsetType) i, n);
cristy0e9f9c12010-02-11 03:00:47 +00008276 if (proceed == MagickFalse)
8277 break;
anthonye9c27192011-03-27 08:07:06 +00008278 if ( (*images)->next == (Image *) NULL )
8279 break;
8280 *images=(*images)->next;
8281 i++;
cristy3ed852e2009-09-05 21:47:34 +00008282 }
anthonye9c27192011-03-27 08:07:06 +00008283 assert( *images != (Image *) NULL );
anthonyce2716b2011-04-22 09:51:34 +00008284#if 0
cristy1e604812011-05-19 18:07:50 +00008285 (void) FormatLocaleFile(stderr,"mogrify end %ld of %ld\n",(long)
8286 GetImageIndexInList(*images),(long)GetImageListLength(*images));
anthonyce2716b2011-04-22 09:51:34 +00008287#endif
anthonye9c27192011-03-27 08:07:06 +00008288
8289 /*
8290 Post-process, multi-image sequence operators
8291 */
8292 *images=GetFirstImageInList(*images);
cristy3ed852e2009-09-05 21:47:34 +00008293 if (post != MagickFalse)
anthonye9c27192011-03-27 08:07:06 +00008294 status&=MogrifyImageList(image_info,argc,argv,images,exception);
cristy3ed852e2009-09-05 21:47:34 +00008295 return(status != 0 ? MagickTrue : MagickFalse);
8296}