blob: 687ad173e96ec9eaf4b96e4d3fe7f1e3b1bcdd92 [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 %
cristyde984cd2013-12-01 14:49:27 +000016% Cristy %
cristy3ed852e2009-09-05 21:47:34 +000017% March 2000 %
18% %
19% %
Cristy7ce65e72015-12-12 18:03:16 -050020% Copyright 1999-2016 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"
cristy190229a2014-01-14 21:03:47 +000049#include "MagickWand/magick-wand-private.h"
cristyd79e2362013-01-06 23:01:40 +000050#include "MagickWand/mogrify-private.h"
cristye80f9cb2013-01-09 01:09:31 +000051#include "MagickCore/image-private.h"
cristy4c08aed2011-07-01 19:47:50 +000052#include "MagickCore/monitor-private.h"
cristy4c08aed2011-07-01 19:47:50 +000053#include "MagickCore/string-private.h"
cristy0740a982011-10-13 15:01:01 +000054#include "MagickCore/thread-private.h"
cristy18c6c272011-09-23 14:40:37 +000055#include "MagickCore/utility-private.h"
cristy03e83172012-03-25 22:41:06 +000056
cristy3ed852e2009-09-05 21:47:34 +000057/*
cristyee2da8b2013-01-09 01:21:16 +000058 Constant declaration.
cristy154fa9d2011-08-05 14:25:15 +000059*/
cristy3a557c02011-08-06 19:48:02 +000060static const char
cristy638895a2011-08-06 23:19:14 +000061 MogrifyBackgroundColor[] = "#ffffff", /* white */
62 MogrifyBorderColor[] = "#dfdfdf", /* gray */
63 MogrifyMatteColor[] = "#bdbdbd"; /* gray */
cristy154fa9d2011-08-05 14:25:15 +000064
65/*
cristy3ed852e2009-09-05 21:47:34 +000066 Define declarations.
67*/
68#define UndefinedCompressionQuality 0UL
69
70/*
cristy3ed852e2009-09-05 21:47:34 +000071%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
72% %
73% %
74% %
cristy5063d812010-10-19 16:28:10 +000075% 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 +000076% %
77% %
78% %
79%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
80%
81% MagickCommandGenesis() applies image processing options to an image as
82% prescribed by command line options.
83%
anthonya322a832013-04-27 06:28:03 +000084% It wiil look for special options like "-debug", "-bench", and
85% "-distribute-cache" that needs to be applied even before the main
86% processing begins, and may completely overrule normal command processing.
87% Such 'Genesis' Options can only be given on the CLI, (not in a script)
88% and are typically ignored (as they have been handled) if seen later.
89%
cristy3980b0d2009-10-25 14:37:13 +000090% The format of the MagickCommandGenesis method is:
91%
92% MagickBooleanType MagickCommandGenesis(ImageInfo *image_info,
cristy5063d812010-10-19 16:28:10 +000093% MagickCommand command,int argc,char **argv,char **metadata,
94% ExceptionInfo *exception)
cristy3980b0d2009-10-25 14:37:13 +000095%
96% A description of each parameter follows:
97%
98% o image_info: the image info.
99%
cristy5063d812010-10-19 16:28:10 +0000100% o command: Choose from ConvertImageCommand, IdentifyImageCommand,
cristy8a9106f2011-07-05 14:39:26 +0000101% MogrifyImageCommand, CompositeImageCommand, CompareImagesCommand,
cristy5063d812010-10-19 16:28:10 +0000102% ConjureImageCommand, StreamImageCommand, ImportImageCommand,
103% DisplayImageCommand, or AnimateImageCommand.
cristy3980b0d2009-10-25 14:37:13 +0000104%
105% o argc: Specifies a pointer to an integer describing the number of
106% elements in the argument vector.
107%
108% o argv: Specifies a pointer to a text array containing the command line
109% arguments.
110%
cristy5063d812010-10-19 16:28:10 +0000111% o metadata: any metadata is returned here.
cristy3980b0d2009-10-25 14:37:13 +0000112%
113% o exception: return any errors or warnings in this structure.
114%
115*/
116WandExport MagickBooleanType MagickCommandGenesis(ImageInfo *image_info,
117 MagickCommand command,int argc,char **argv,char **metadata,
118 ExceptionInfo *exception)
119{
120 char
121 *option;
122
123 double
124 duration,
cristy8ea926d2011-12-09 12:25:04 +0000125 serial;
cristy3980b0d2009-10-25 14:37:13 +0000126
cristy3980b0d2009-10-25 14:37:13 +0000127 MagickBooleanType
128 concurrent,
129 regard_warnings,
130 status;
131
cristybb503372010-05-27 20:51:26 +0000132 register ssize_t
cristy3980b0d2009-10-25 14:37:13 +0000133 i;
134
cristybb503372010-05-27 20:51:26 +0000135 size_t
cristyc2e3aeb2011-12-09 11:09:38 +0000136 iterations,
cristyc2e3aeb2011-12-09 11:09:38 +0000137 number_threads;
cristy3980b0d2009-10-25 14:37:13 +0000138
cristy118fc662012-02-11 00:02:25 +0000139 ssize_t
140 n;
141
cristyd0a94fa2010-03-12 14:18:11 +0000142 (void) setlocale(LC_ALL,"");
143 (void) setlocale(LC_NUMERIC,"C");
cristy3980b0d2009-10-25 14:37:13 +0000144 concurrent=MagickFalse;
145 duration=(-1.0);
146 iterations=1;
cristy8744d432014-06-27 12:04:01 +0000147 status=MagickTrue;
cristy3980b0d2009-10-25 14:37:13 +0000148 regard_warnings=MagickFalse;
cristybb503372010-05-27 20:51:26 +0000149 for (i=1; i < (ssize_t) (argc-1); i++)
cristy3980b0d2009-10-25 14:37:13 +0000150 {
151 option=argv[i];
152 if ((strlen(option) == 1) || ((*option != '-') && (*option != '+')))
153 continue;
anthony8226e722012-04-05 14:25:46 +0000154 if (LocaleCompare("-bench",option) == 0)
cristye27293e2009-12-18 02:53:20 +0000155 iterations=StringToUnsignedLong(argv[++i]);
anthony8226e722012-04-05 14:25:46 +0000156 if (LocaleCompare("-concurrent",option) == 0)
cristy3980b0d2009-10-25 14:37:13 +0000157 concurrent=MagickTrue;
anthony8226e722012-04-05 14:25:46 +0000158 if (LocaleCompare("-debug",option) == 0)
cristy3980b0d2009-10-25 14:37:13 +0000159 (void) SetLogEventMask(argv[++i]);
cristy93053632013-01-06 23:55:19 +0000160 if (LocaleCompare("-distribute-cache",option) == 0)
cristy8f7950e2013-01-07 14:58:48 +0000161 {
cristyb9120722013-01-20 17:20:50 +0000162 DistributePixelCacheServer(StringToInteger(argv[++i]),exception);
cristy8f7950e2013-01-07 14:58:48 +0000163 exit(0);
164 }
anthony8226e722012-04-05 14:25:46 +0000165 if (LocaleCompare("-duration",option) == 0)
cristydbdd0e32011-11-04 23:29:40 +0000166 duration=StringToDouble(argv[++i],(char **) NULL);
anthony8226e722012-04-05 14:25:46 +0000167 if (LocaleCompare("-regard-warnings",option) == 0)
cristy3980b0d2009-10-25 14:37:13 +0000168 regard_warnings=MagickTrue;
169 }
cristy8ea926d2011-12-09 12:25:04 +0000170 if (iterations == 1)
171 {
172 status=command(image_info,argc,argv,metadata,exception);
173 if (exception->severity != UndefinedException)
174 {
175 if ((exception->severity > ErrorException) ||
176 (regard_warnings != MagickFalse))
cristy8744d432014-06-27 12:04:01 +0000177 status=MagickFalse;
cristy8ea926d2011-12-09 12:25:04 +0000178 CatchException(exception);
179 }
cristyadda7c12014-05-27 00:06:06 +0000180 if ((metadata != (char **) NULL) && (*metadata != (char *) NULL))
181 {
182 (void) fputs(*metadata,stdout);
183 *metadata=DestroyString(*metadata);
184 }
cristy220c4d52013-11-27 19:31:32 +0000185 return(status);
cristy8ea926d2011-12-09 12:25:04 +0000186 }
cristyfeeb98d2012-05-09 16:32:12 +0000187 number_threads=GetOpenMPMaximumThreads();
cristy8ea926d2011-12-09 12:25:04 +0000188 serial=0.0;
cristy118fc662012-02-11 00:02:25 +0000189 for (n=1; n <= (ssize_t) number_threads; n++)
cristyc2e3aeb2011-12-09 11:09:38 +0000190 {
191 double
cristy8ea926d2011-12-09 12:25:04 +0000192 e,
193 parallel,
cristyc2e3aeb2011-12-09 11:09:38 +0000194 user_time;
195
196 TimerInfo
197 *timer;
198
cristy00f87232012-05-09 13:12:34 +0000199 (void) SetMagickResourceLimit(ThreadResource,(MagickSizeType) n);
cristyc2e3aeb2011-12-09 11:09:38 +0000200 timer=AcquireTimerInfo();
201 if (concurrent == MagickFalse)
cristy3980b0d2009-10-25 14:37:13 +0000202 {
cristyc2e3aeb2011-12-09 11:09:38 +0000203 for (i=0; i < (ssize_t) iterations; i++)
cristyceae09d2009-10-28 17:18:47 +0000204 {
cristy8744d432014-06-27 12:04:01 +0000205 if (status == MagickFalse)
cristyc2e3aeb2011-12-09 11:09:38 +0000206 continue;
207 if (duration > 0)
208 {
209 if (GetElapsedTime(timer) > duration)
210 continue;
211 (void) ContinueTimer(timer);
212 }
213 status=command(image_info,argc,argv,metadata,exception);
cristyceae09d2009-10-28 17:18:47 +0000214 if (exception->severity != UndefinedException)
215 {
216 if ((exception->severity > ErrorException) ||
217 (regard_warnings != MagickFalse))
cristy8744d432014-06-27 12:04:01 +0000218 status=MagickFalse;
cristyceae09d2009-10-28 17:18:47 +0000219 CatchException(exception);
220 }
221 if ((metadata != (char **) NULL) && (*metadata != (char *) NULL))
222 {
223 (void) fputs(*metadata,stdout);
cristyceae09d2009-10-28 17:18:47 +0000224 *metadata=DestroyString(*metadata);
225 }
226 }
227 }
cristyc2e3aeb2011-12-09 11:09:38 +0000228 else
229 {
230 SetOpenMPNested(1);
231#if defined(MAGICKCORE_OPENMP_SUPPORT)
232 # pragma omp parallel for shared(status)
233#endif
234 for (i=0; i < (ssize_t) iterations; i++)
235 {
cristy8744d432014-06-27 12:04:01 +0000236 if (status == MagickFalse)
cristyc2e3aeb2011-12-09 11:09:38 +0000237 continue;
238 if (duration > 0)
239 {
240 if (GetElapsedTime(timer) > duration)
241 continue;
242 (void) ContinueTimer(timer);
243 }
244 status=command(image_info,argc,argv,metadata,exception);
245#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy63b49292014-06-27 11:40:52 +0000246 # pragma omp critical (MagickCore_MagickCommandGenesis)
cristyc2e3aeb2011-12-09 11:09:38 +0000247#endif
248 {
249 if (exception->severity != UndefinedException)
250 {
251 if ((exception->severity > ErrorException) ||
252 (regard_warnings != MagickFalse))
cristy8744d432014-06-27 12:04:01 +0000253 status=MagickFalse;
cristyc2e3aeb2011-12-09 11:09:38 +0000254 CatchException(exception);
255 }
256 if ((metadata != (char **) NULL) && (*metadata != (char *) NULL))
257 {
258 (void) fputs(*metadata,stdout);
cristyc2e3aeb2011-12-09 11:09:38 +0000259 *metadata=DestroyString(*metadata);
260 }
261 }
262 }
263 }
cristyc2e3aeb2011-12-09 11:09:38 +0000264 user_time=GetUserTime(timer);
cristy8ea926d2011-12-09 12:25:04 +0000265 parallel=GetElapsedTime(timer);
266 e=1.0;
267 if (n == 1)
268 serial=parallel;
269 else
270 e=((1.0/(1.0/((serial/(serial+parallel))+(1.0-(serial/(serial+parallel)))/
271 (double) n)))-(1.0/(double) n))/(1.0-1.0/(double) n);
cristyc2e3aeb2011-12-09 11:09:38 +0000272 (void) FormatLocaleFile(stderr,
cristy91ce84d2011-12-09 23:02:25 +0000273 "Performance[%.20g]: %.20gi %0.3fips %0.3fe %0.3fu %lu:%02lu.%03lu\n",
cristyebd71f42013-09-13 22:35:48 +0000274 (double) n,(double) iterations,(double) iterations/parallel,e,user_time,
275 (unsigned long) (parallel/60.0),(unsigned long) floor(fmod(parallel,
276 60.0)),(unsigned long) (1000.0*(parallel-floor(parallel))+0.5));
cristyc2e3aeb2011-12-09 11:09:38 +0000277 timer=DestroyTimerInfo(timer);
278 }
cristy220c4d52013-11-27 19:31:32 +0000279 return(status);
cristy3980b0d2009-10-25 14:37:13 +0000280}
281
282/*
283%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
284% %
285% %
286% %
cristy3ed852e2009-09-05 21:47:34 +0000287+ M o g r i f y I m a g e %
288% %
289% %
290% %
291%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
292%
anthonye9c27192011-03-27 08:07:06 +0000293% MogrifyImage() applies simple single image processing options to a single
anthonydf8ebac2011-04-27 09:03:19 +0000294% image that may be part of a large list, but also handles any 'region'
295% image handling.
anthonye9c27192011-03-27 08:07:06 +0000296%
297% The image in the list may be modified in three different ways...
298%
299% * directly modified (EG: -negate, -gamma, -level, -annotate, -draw),
300% * replaced by a new image (EG: -spread, -resize, -rotate, -morphology)
301% * replace by a list of images (only the -separate option!)
302%
303% In each case the result is returned into the list, and a pointer to the
304% modified image (last image added if replaced by a list of images) is
305% returned.
306%
307% ASIDE: The -crop is present but restricted to non-tile single image crops
308%
309% This means if all the images are being processed (such as by
310% MogrifyImages(), next image to be processed will be as per the pointer
311% (*image)->next. Also the image list may grow as a result of some specific
312% operations but as images are never merged or deleted, it will never shrink
313% in length. Typically the list will remain the same length.
314%
315% WARNING: As the image pointed to may be replaced, the first image in the
316% list may also change. GetFirstImageInList() should be used by caller if
317% they wish return the Image pointer to the first image in list.
318%
cristy3ed852e2009-09-05 21:47:34 +0000319%
320% The format of the MogrifyImage method is:
321%
322% MagickBooleanType MogrifyImage(ImageInfo *image_info,const int argc,
323% const char **argv,Image **image)
324%
325% A description of each parameter follows:
326%
327% o image_info: the image info..
328%
329% o argc: Specifies a pointer to an integer describing the number of
330% elements in the argument vector.
331%
332% o argv: Specifies a pointer to a text array containing the command line
333% arguments.
334%
335% o image: the image.
336%
337% o exception: return any errors or warnings in this structure.
338%
339*/
340
anthonydf8ebac2011-04-27 09:03:19 +0000341static inline Image *GetImageCache(const ImageInfo *image_info,const char *path,
342 ExceptionInfo *exception)
343{
344 char
cristy151b66d2015-04-15 10:50:31 +0000345 key[MagickPathExtent];
anthonydf8ebac2011-04-27 09:03:19 +0000346
347 ExceptionInfo
348 *sans_exception;
349
350 Image
351 *image;
352
353 ImageInfo
354 *read_info;
355
cristyfcd785b2011-11-08 01:48:33 +0000356 /*
anthony32d85bf2012-02-15 14:54:59 +0000357 Read an image into a image cache (for repeated usage) if not already in
358 cache. Then return the image that is in the cache.
cristyfcd785b2011-11-08 01:48:33 +0000359 */
cristy151b66d2015-04-15 10:50:31 +0000360 (void) FormatLocaleString(key,MagickPathExtent,"cache:%s",path);
anthonydf8ebac2011-04-27 09:03:19 +0000361 sans_exception=AcquireExceptionInfo();
362 image=(Image *) GetImageRegistry(ImageRegistryType,key,sans_exception);
363 sans_exception=DestroyExceptionInfo(sans_exception);
364 if (image != (Image *) NULL)
365 return(image);
366 read_info=CloneImageInfo(image_info);
cristy151b66d2015-04-15 10:50:31 +0000367 (void) CopyMagickString(read_info->filename,path,MagickPathExtent);
anthonydf8ebac2011-04-27 09:03:19 +0000368 image=ReadImage(read_info,exception);
369 read_info=DestroyImageInfo(read_info);
370 if (image != (Image *) NULL)
371 (void) SetImageRegistry(ImageRegistryType,key,image,exception);
372 return(image);
373}
374
cristyba3c5702012-06-27 13:30:13 +0000375static inline MagickBooleanType IsPathWritable(const char *path)
cristy3ed852e2009-09-05 21:47:34 +0000376{
377 if (IsPathAccessible(path) == MagickFalse)
378 return(MagickFalse);
cristy18c6c272011-09-23 14:40:37 +0000379 if (access_utf8(path,W_OK) != 0)
cristy3ed852e2009-09-05 21:47:34 +0000380 return(MagickFalse);
381 return(MagickTrue);
382}
383
anthonydf8ebac2011-04-27 09:03:19 +0000384static MagickBooleanType MonitorProgress(const char *text,
385 const MagickOffsetType offset,const MagickSizeType extent,
386 void *wand_unused(client_data))
387{
388 char
cristy151b66d2015-04-15 10:50:31 +0000389 message[MagickPathExtent],
390 tag[MagickPathExtent];
anthonydf8ebac2011-04-27 09:03:19 +0000391
392 const char
393 *locale_message;
394
395 register char
396 *p;
397
Cristy5da20072015-09-02 10:06:14 -0400398 if ((extent <= 1) || (offset < 0) || (offset >= (MagickOffsetType) extent))
399 return(MagickTrue);
400 if ((offset != (MagickOffsetType) (extent-1)) && ((offset % 50) != 0))
anthonydf8ebac2011-04-27 09:03:19 +0000401 return(MagickTrue);
cristy151b66d2015-04-15 10:50:31 +0000402 (void) CopyMagickMemory(tag,text,MagickPathExtent);
anthonydf8ebac2011-04-27 09:03:19 +0000403 p=strrchr(tag,'/');
404 if (p != (char *) NULL)
405 *p='\0';
cristy151b66d2015-04-15 10:50:31 +0000406 (void) FormatLocaleString(message,MagickPathExtent,"Monitor/%s",tag);
anthonydf8ebac2011-04-27 09:03:19 +0000407 locale_message=GetLocaleMessage(message);
408 if (locale_message == message)
409 locale_message=tag;
410 if (p == (char *) NULL)
cristy1e604812011-05-19 18:07:50 +0000411 (void) FormatLocaleFile(stderr,"%s: %ld of %lu, %02ld%% complete\r",
412 locale_message,(long) offset,(unsigned long) extent,(long)
413 (100L*offset/(extent-1)));
anthonydf8ebac2011-04-27 09:03:19 +0000414 else
cristyb51dff52011-05-19 16:55:47 +0000415 (void) FormatLocaleFile(stderr,"%s[%s]: %ld of %lu, %02ld%% complete\r",
anthonydf8ebac2011-04-27 09:03:19 +0000416 locale_message,p+1,(long) offset,(unsigned long) extent,(long)
417 (100L*offset/(extent-1)));
418 if (offset == (MagickOffsetType) (extent-1))
cristyb51dff52011-05-19 16:55:47 +0000419 (void) FormatLocaleFile(stderr,"\n");
anthonydf8ebac2011-04-27 09:03:19 +0000420 (void) fflush(stderr);
421 return(MagickTrue);
422}
423
cristy3884f692011-07-08 18:00:18 +0000424static Image *SparseColorOption(const Image *image,
anthonydf8ebac2011-04-27 09:03:19 +0000425 const SparseColorMethod method,const char *arguments,
426 const MagickBooleanType color_from_image,ExceptionInfo *exception)
427{
anthonydf8ebac2011-04-27 09:03:19 +0000428 char
cristy151b66d2015-04-15 10:50:31 +0000429 token[MagickPathExtent];
anthonydf8ebac2011-04-27 09:03:19 +0000430
431 const char
432 *p;
433
434 double
435 *sparse_arguments;
436
anthonydf8ebac2011-04-27 09:03:19 +0000437 Image
438 *sparse_image;
439
cristy4c08aed2011-07-01 19:47:50 +0000440 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +0000441 color;
442
443 MagickBooleanType
444 error;
445
cristy5f09d852011-05-29 01:39:29 +0000446 register size_t
447 x;
448
449 size_t
450 number_arguments,
451 number_colors;
452
cristyf4425a72011-11-08 01:52:04 +0000453 /*
454 SparseColorOption() parses the complex -sparse-color argument into an an
455 array of floating point values then calls SparseColorImage(). Argument is
456 a complex mix of floating-point pixel coodinates, and color specifications
457 (or direct floating point numbers). The number of floats needed to
458 represent a color varies depending on the current channel setting.
459 */
anthonydf8ebac2011-04-27 09:03:19 +0000460 assert(image != (Image *) NULL);
cristye1c94d92015-06-28 12:16:33 +0000461 assert(image->signature == MagickCoreSignature);
anthonydf8ebac2011-04-27 09:03:19 +0000462 if (image->debug != MagickFalse)
463 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
464 assert(exception != (ExceptionInfo *) NULL);
cristye1c94d92015-06-28 12:16:33 +0000465 assert(exception->signature == MagickCoreSignature);
anthonydf8ebac2011-04-27 09:03:19 +0000466 /*
467 Limit channels according to image - and add up number of color channel.
468 */
anthonydf8ebac2011-04-27 09:03:19 +0000469 number_colors=0;
cristyed231572011-07-14 02:18:59 +0000470 if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000471 number_colors++;
cristyed231572011-07-14 02:18:59 +0000472 if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000473 number_colors++;
cristyed231572011-07-14 02:18:59 +0000474 if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000475 number_colors++;
cristyed231572011-07-14 02:18:59 +0000476 if (((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000477 (image->colorspace == CMYKColorspace))
anthonydf8ebac2011-04-27 09:03:19 +0000478 number_colors++;
cristyed231572011-07-14 02:18:59 +0000479 if (((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0) &&
cristy7d6d3d82014-11-09 17:00:16 +0000480 (image->alpha_trait != UndefinedPixelTrait))
anthonydf8ebac2011-04-27 09:03:19 +0000481 number_colors++;
482
483 /*
484 Read string, to determine number of arguments needed,
485 */
486 p=arguments;
487 x=0;
488 while( *p != '\0' )
489 {
490 GetMagickToken(p,&p,token);
491 if ( token[0] == ',' ) continue;
492 if ( isalpha((int) token[0]) || token[0] == '#' ) {
493 if ( color_from_image ) {
494 (void) ThrowMagickException(exception,GetMagickModule(),
anthonye5b39652012-04-21 05:37:29 +0000495 OptionError, "InvalidArgument", "'%s': %s", "sparse-color",
anthonydf8ebac2011-04-27 09:03:19 +0000496 "Color arg given, when colors are coming from image");
cristyf432c632014-12-07 15:11:28 +0000497 return( (Image *) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000498 }
499 x += number_colors; /* color argument */
500 }
501 else {
502 x++; /* floating point argument */
503 }
504 }
505 error=MagickTrue;
506 if ( color_from_image ) {
507 /* just the control points are being given */
508 error = ( x % 2 != 0 ) ? MagickTrue : MagickFalse;
509 number_arguments=(x/2)*(2+number_colors);
510 }
511 else {
512 /* control points and color values */
513 error = ( x % (2+number_colors) != 0 ) ? MagickTrue : MagickFalse;
514 number_arguments=x;
515 }
516 if ( error ) {
517 (void) ThrowMagickException(exception,GetMagickModule(),
anthonye5b39652012-04-21 05:37:29 +0000518 OptionError, "InvalidArgument", "'%s': %s", "sparse-color",
anthonydf8ebac2011-04-27 09:03:19 +0000519 "Invalid number of Arguments");
cristyf432c632014-12-07 15:11:28 +0000520 return( (Image *) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000521 }
522
523 /* Allocate and fill in the floating point arguments */
524 sparse_arguments=(double *) AcquireQuantumMemory(number_arguments,
525 sizeof(*sparse_arguments));
526 if (sparse_arguments == (double *) NULL) {
527 (void) ThrowMagickException(exception,GetMagickModule(),ResourceLimitError,
528 "MemoryAllocationFailed","%s","SparseColorOption");
cristyf432c632014-12-07 15:11:28 +0000529 return( (Image *) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000530 }
531 (void) ResetMagickMemory(sparse_arguments,0,number_arguments*
532 sizeof(*sparse_arguments));
533 p=arguments;
534 x=0;
535 while( *p != '\0' && x < number_arguments ) {
536 /* X coordinate */
537 token[0]=','; while ( token[0] == ',' ) GetMagickToken(p,&p,token);
538 if ( token[0] == '\0' ) break;
539 if ( isalpha((int) token[0]) || token[0] == '#' ) {
540 (void) ThrowMagickException(exception,GetMagickModule(),
anthonye5b39652012-04-21 05:37:29 +0000541 OptionError, "InvalidArgument", "'%s': %s", "sparse-color",
anthonydf8ebac2011-04-27 09:03:19 +0000542 "Color found, instead of X-coord");
543 error = MagickTrue;
544 break;
545 }
cristydbdd0e32011-11-04 23:29:40 +0000546 sparse_arguments[x++]=StringToDouble(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000547 /* Y coordinate */
548 token[0]=','; while ( token[0] == ',' ) GetMagickToken(p,&p,token);
549 if ( token[0] == '\0' ) break;
550 if ( isalpha((int) token[0]) || token[0] == '#' ) {
551 (void) ThrowMagickException(exception,GetMagickModule(),
anthonye5b39652012-04-21 05:37:29 +0000552 OptionError, "InvalidArgument", "'%s': %s", "sparse-color",
anthonydf8ebac2011-04-27 09:03:19 +0000553 "Color found, instead of Y-coord");
554 error = MagickTrue;
555 break;
556 }
cristydbdd0e32011-11-04 23:29:40 +0000557 sparse_arguments[x++]=StringToDouble(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000558 /* color values for this control point */
559#if 0
560 if ( (color_from_image ) {
561 /* get color from image */
562 /* HOW??? */
563 }
564 else
565#endif
566 {
567 /* color name or function given in string argument */
568 token[0]=','; while ( token[0] == ',' ) GetMagickToken(p,&p,token);
569 if ( token[0] == '\0' ) break;
570 if ( isalpha((int) token[0]) || token[0] == '#' ) {
571 /* Color string given */
cristy269c9412011-10-13 23:41:15 +0000572 (void) QueryColorCompliance(token,AllCompliance,&color,exception);
cristyed231572011-07-14 02:18:59 +0000573 if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000574 sparse_arguments[x++] = QuantumScale*color.red;
cristyed231572011-07-14 02:18:59 +0000575 if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000576 sparse_arguments[x++] = QuantumScale*color.green;
cristyed231572011-07-14 02:18:59 +0000577 if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000578 sparse_arguments[x++] = QuantumScale*color.blue;
cristyed231572011-07-14 02:18:59 +0000579 if (((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000580 (image->colorspace == CMYKColorspace))
cristy4c08aed2011-07-01 19:47:50 +0000581 sparse_arguments[x++] = QuantumScale*color.black;
cristyed231572011-07-14 02:18:59 +0000582 if (((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0) &&
cristy7d6d3d82014-11-09 17:00:16 +0000583 (image->alpha_trait != UndefinedPixelTrait))
cristy4c08aed2011-07-01 19:47:50 +0000584 sparse_arguments[x++] = QuantumScale*color.alpha;
anthonydf8ebac2011-04-27 09:03:19 +0000585 }
586 else {
587 /* Colors given as a set of floating point values - experimental */
588 /* NB: token contains the first floating point value to use! */
cristyed231572011-07-14 02:18:59 +0000589 if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
cristy3884f692011-07-08 18:00:18 +0000590 {
anthonydf8ebac2011-04-27 09:03:19 +0000591 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
592 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
593 break;
cristydbdd0e32011-11-04 23:29:40 +0000594 sparse_arguments[x++]=StringToDouble(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000595 token[0] = ','; /* used this token - get another */
596 }
cristyed231572011-07-14 02:18:59 +0000597 if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
cristy3884f692011-07-08 18:00:18 +0000598 {
anthonydf8ebac2011-04-27 09:03:19 +0000599 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
600 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
601 break;
cristydbdd0e32011-11-04 23:29:40 +0000602 sparse_arguments[x++]=StringToDouble(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000603 token[0] = ','; /* used this token - get another */
604 }
cristyed231572011-07-14 02:18:59 +0000605 if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
cristy3884f692011-07-08 18:00:18 +0000606 {
anthonydf8ebac2011-04-27 09:03:19 +0000607 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
608 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
609 break;
cristydbdd0e32011-11-04 23:29:40 +0000610 sparse_arguments[x++]=StringToDouble(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000611 token[0] = ','; /* used this token - get another */
612 }
cristyed231572011-07-14 02:18:59 +0000613 if (((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000614 (image->colorspace == CMYKColorspace))
615 {
anthonydf8ebac2011-04-27 09:03:19 +0000616 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
617 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
618 break;
cristydbdd0e32011-11-04 23:29:40 +0000619 sparse_arguments[x++]=StringToDouble(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000620 token[0] = ','; /* used this token - get another */
621 }
cristyed231572011-07-14 02:18:59 +0000622 if (((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0) &&
cristy7d6d3d82014-11-09 17:00:16 +0000623 (image->alpha_trait != UndefinedPixelTrait))
cristy3884f692011-07-08 18:00:18 +0000624 {
anthonydf8ebac2011-04-27 09:03:19 +0000625 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
626 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
627 break;
cristydbdd0e32011-11-04 23:29:40 +0000628 sparse_arguments[x++]=StringToDouble(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000629 token[0] = ','; /* used this token - get another */
630 }
631 }
632 }
633 }
634 if ( number_arguments != x && !error ) {
635 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
anthonye5b39652012-04-21 05:37:29 +0000636 "InvalidArgument","'%s': %s","sparse-color","Argument Parsing Error");
anthonydf8ebac2011-04-27 09:03:19 +0000637 sparse_arguments=(double *) RelinquishMagickMemory(sparse_arguments);
cristyf432c632014-12-07 15:11:28 +0000638 return( (Image *) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000639 }
640 if ( error )
cristyf432c632014-12-07 15:11:28 +0000641 return( (Image *) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000642
643 /* Call the Interpolation function with the parsed arguments */
cristy3884f692011-07-08 18:00:18 +0000644 sparse_image=SparseColorImage(image,method,number_arguments,sparse_arguments,
645 exception);
anthonydf8ebac2011-04-27 09:03:19 +0000646 sparse_arguments=(double *) RelinquishMagickMemory(sparse_arguments);
647 return( sparse_image );
648}
649
cristy3ed852e2009-09-05 21:47:34 +0000650WandExport MagickBooleanType MogrifyImage(ImageInfo *image_info,const int argc,
651 const char **argv,Image **image,ExceptionInfo *exception)
652{
cristy633f0c62011-09-15 13:27:36 +0000653 CompositeOperator
654 compose;
655
anthonydf8ebac2011-04-27 09:03:19 +0000656 const char
657 *format,
658 *option;
659
cristy9ed1f812011-10-08 02:00:08 +0000660 double
661 attenuate;
662
anthonydf8ebac2011-04-27 09:03:19 +0000663 DrawInfo
664 *draw_info;
665
666 GeometryInfo
667 geometry_info;
668
cristy3ed852e2009-09-05 21:47:34 +0000669 Image
670 *region_image;
671
anthonydf8ebac2011-04-27 09:03:19 +0000672 ImageInfo
673 *mogrify_info;
674
cristyebbcfea2011-02-25 02:43:54 +0000675 MagickStatusType
cristy3ed852e2009-09-05 21:47:34 +0000676 status;
677
cristy4c08aed2011-07-01 19:47:50 +0000678 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +0000679 fill;
cristy3ed852e2009-09-05 21:47:34 +0000680
anthonydf8ebac2011-04-27 09:03:19 +0000681 MagickStatusType
682 flags;
683
cristy28474bf2011-09-11 23:32:52 +0000684 PixelInterpolateMethod
685 interpolate_method;
686
anthonydf8ebac2011-04-27 09:03:19 +0000687 QuantizeInfo
688 *quantize_info;
689
690 RectangleInfo
691 geometry,
692 region_geometry;
anthony56ad4222011-04-25 11:04:27 +0000693
cristybb503372010-05-27 20:51:26 +0000694 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000695 i;
696
697 /*
698 Initialize method variables.
699 */
700 assert(image_info != (const ImageInfo *) NULL);
cristye1c94d92015-06-28 12:16:33 +0000701 assert(image_info->signature == MagickCoreSignature);
cristy3ed852e2009-09-05 21:47:34 +0000702 assert(image != (Image **) NULL);
cristye1c94d92015-06-28 12:16:33 +0000703 assert((*image)->signature == MagickCoreSignature);
cristy3ed852e2009-09-05 21:47:34 +0000704 if ((*image)->debug != MagickFalse)
705 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",(*image)->filename);
706 if (argc < 0)
707 return(MagickTrue);
cristy6b3da3a2010-06-20 02:21:46 +0000708 mogrify_info=CloneImageInfo(image_info);
anthonydf8ebac2011-04-27 09:03:19 +0000709 draw_info=CloneDrawInfo(mogrify_info,(DrawInfo *) NULL);
710 quantize_info=AcquireQuantizeInfo(mogrify_info);
711 SetGeometryInfo(&geometry_info);
cristy4c08aed2011-07-01 19:47:50 +0000712 GetPixelInfo(*image,&fill);
cristy9d8c8ce2011-10-25 16:13:52 +0000713 fill=(*image)->background_color;
cristy9ed1f812011-10-08 02:00:08 +0000714 attenuate=1.0;
cristy633f0c62011-09-15 13:27:36 +0000715 compose=(*image)->compose;
cristy28474bf2011-09-11 23:32:52 +0000716 interpolate_method=UndefinedInterpolatePixel;
anthonydf8ebac2011-04-27 09:03:19 +0000717 format=GetImageOption(mogrify_info,"format");
cristy3ed852e2009-09-05 21:47:34 +0000718 SetGeometry(*image,&region_geometry);
719 region_image=NewImageList();
720 /*
721 Transmogrify the image.
722 */
cristybb503372010-05-27 20:51:26 +0000723 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +0000724 {
anthonydf8ebac2011-04-27 09:03:19 +0000725 Image
726 *mogrify_image;
727
anthonye9c27192011-03-27 08:07:06 +0000728 ssize_t
729 count;
730
anthonydf8ebac2011-04-27 09:03:19 +0000731 option=argv[i];
732 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +0000733 continue;
anthonydf8ebac2011-04-27 09:03:19 +0000734 count=MagickMax(ParseCommandOption(MagickCommandOptions,MagickFalse,option),
735 0L);
cristycee97112010-05-28 00:44:52 +0000736 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +0000737 break;
cristy6b3da3a2010-06-20 02:21:46 +0000738 status=MogrifyImageInfo(mogrify_info,(int) count+1,argv+i,exception);
cristyf432c632014-12-07 15:11:28 +0000739 mogrify_image=(Image *) NULL;
anthonydf8ebac2011-04-27 09:03:19 +0000740 switch (*(option+1))
741 {
742 case 'a':
cristy3ed852e2009-09-05 21:47:34 +0000743 {
anthonydf8ebac2011-04-27 09:03:19 +0000744 if (LocaleCompare("adaptive-blur",option+1) == 0)
cristy3ed852e2009-09-05 21:47:34 +0000745 {
anthonydf8ebac2011-04-27 09:03:19 +0000746 /*
747 Adaptive blur image.
748 */
cristy6fccee12011-10-20 18:43:18 +0000749 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000750 flags=ParseGeometry(argv[i+1],&geometry_info);
751 if ((flags & SigmaValue) == 0)
752 geometry_info.sigma=1.0;
cristyf4ad9df2011-07-08 16:49:03 +0000753 mogrify_image=AdaptiveBlurImage(*image,geometry_info.rho,
cristyaa2c16c2012-03-25 22:21:35 +0000754 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000755 break;
cristy3ed852e2009-09-05 21:47:34 +0000756 }
anthonydf8ebac2011-04-27 09:03:19 +0000757 if (LocaleCompare("adaptive-resize",option+1) == 0)
758 {
759 /*
760 Adaptive resize image.
761 */
cristy6fccee12011-10-20 18:43:18 +0000762 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000763 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
764 mogrify_image=AdaptiveResizeImage(*image,geometry.width,
anthonyfd706f92012-01-19 04:22:02 +0000765 geometry.height,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000766 break;
767 }
768 if (LocaleCompare("adaptive-sharpen",option+1) == 0)
769 {
770 /*
771 Adaptive sharpen image.
772 */
cristy6fccee12011-10-20 18:43:18 +0000773 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000774 flags=ParseGeometry(argv[i+1],&geometry_info);
775 if ((flags & SigmaValue) == 0)
776 geometry_info.sigma=1.0;
cristyf4ad9df2011-07-08 16:49:03 +0000777 mogrify_image=AdaptiveSharpenImage(*image,geometry_info.rho,
cristyaa2c16c2012-03-25 22:21:35 +0000778 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000779 break;
780 }
781 if (LocaleCompare("affine",option+1) == 0)
782 {
783 /*
784 Affine matrix.
785 */
786 if (*option == '+')
787 {
788 GetAffineMatrix(&draw_info->affine);
789 break;
790 }
791 (void) ParseAffineGeometry(argv[i+1],&draw_info->affine,exception);
792 break;
793 }
794 if (LocaleCompare("alpha",option+1) == 0)
795 {
cristyb15b06c2012-08-28 11:36:48 +0000796 AlphaChannelOption
anthonydf8ebac2011-04-27 09:03:19 +0000797 alpha_type;
cristy3ed852e2009-09-05 21:47:34 +0000798
cristy6fccee12011-10-20 18:43:18 +0000799 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy8cdfb342012-11-11 21:44:36 +0000800 alpha_type=(AlphaChannelOption) ParseCommandOption(
801 MagickAlphaChannelOptions,MagickFalse,argv[i+1]);
cristy63240882011-08-05 19:05:27 +0000802 (void) SetImageAlphaChannel(*image,alpha_type,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000803 break;
804 }
805 if (LocaleCompare("annotate",option+1) == 0)
806 {
807 char
808 *text,
dirkb4979cb2015-11-22 10:01:27 +0100809 geometry_str[MagickPathExtent];
anthonydf8ebac2011-04-27 09:03:19 +0000810
811 /*
812 Annotate image.
813 */
cristy6fccee12011-10-20 18:43:18 +0000814 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000815 SetGeometryInfo(&geometry_info);
816 flags=ParseGeometry(argv[i+1],&geometry_info);
817 if ((flags & SigmaValue) == 0)
818 geometry_info.sigma=geometry_info.rho;
cristy018f07f2011-09-04 21:15:19 +0000819 text=InterpretImageProperties(mogrify_info,*image,argv[i+2],
820 exception);
anthonydf8ebac2011-04-27 09:03:19 +0000821 if (text == (char *) NULL)
822 break;
823 (void) CloneString(&draw_info->text,text);
824 text=DestroyString(text);
dirkb4979cb2015-11-22 10:01:27 +0100825 (void) FormatLocaleString(geometry_str,MagickPathExtent,"%+f%+f",
anthonydf8ebac2011-04-27 09:03:19 +0000826 geometry_info.xi,geometry_info.psi);
dirkb4979cb2015-11-22 10:01:27 +0100827 (void) CloneString(&draw_info->geometry,geometry_str);
anthonydf8ebac2011-04-27 09:03:19 +0000828 draw_info->affine.sx=cos(DegreesToRadians(
829 fmod(geometry_info.rho,360.0)));
830 draw_info->affine.rx=sin(DegreesToRadians(
831 fmod(geometry_info.rho,360.0)));
832 draw_info->affine.ry=(-sin(DegreesToRadians(
833 fmod(geometry_info.sigma,360.0))));
834 draw_info->affine.sy=cos(DegreesToRadians(
835 fmod(geometry_info.sigma,360.0)));
cristy5cbc0162011-08-29 00:36:28 +0000836 (void) AnnotateImage(*image,draw_info,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000837 break;
838 }
839 if (LocaleCompare("antialias",option+1) == 0)
840 {
841 draw_info->stroke_antialias=(*option == '-') ? MagickTrue :
842 MagickFalse;
843 draw_info->text_antialias=(*option == '-') ? MagickTrue :
844 MagickFalse;
845 break;
846 }
cristy9ed1f812011-10-08 02:00:08 +0000847 if (LocaleCompare("attenuate",option+1) == 0)
848 {
849 if (*option == '+')
850 {
851 attenuate=1.0;
852 break;
853 }
cristydbdd0e32011-11-04 23:29:40 +0000854 attenuate=StringToDouble(argv[i+1],(char **) NULL);
cristy9ed1f812011-10-08 02:00:08 +0000855 break;
856 }
anthonydf8ebac2011-04-27 09:03:19 +0000857 if (LocaleCompare("auto-gamma",option+1) == 0)
858 {
859 /*
860 Auto Adjust Gamma of image based on its mean
861 */
cristy6fccee12011-10-20 18:43:18 +0000862 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy95111202011-08-09 19:41:42 +0000863 (void) AutoGammaImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000864 break;
865 }
866 if (LocaleCompare("auto-level",option+1) == 0)
867 {
868 /*
869 Perfectly Normalize (max/min stretch) the image
870 */
cristy6fccee12011-10-20 18:43:18 +0000871 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy95111202011-08-09 19:41:42 +0000872 (void) AutoLevelImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000873 break;
874 }
875 if (LocaleCompare("auto-orient",option+1) == 0)
876 {
cristy6fccee12011-10-20 18:43:18 +0000877 (void) SyncImageSettings(mogrify_info,*image,exception);
cristyfa5f6c72013-01-01 14:37:35 +0000878 mogrify_image=AutoOrientImage(*image,(*image)->orientation,
879 exception);
anthonydf8ebac2011-04-27 09:03:19 +0000880 break;
881 }
882 break;
883 }
884 case 'b':
885 {
886 if (LocaleCompare("black-threshold",option+1) == 0)
887 {
888 /*
889 Black threshold image.
890 */
cristy6fccee12011-10-20 18:43:18 +0000891 (void) SyncImageSettings(mogrify_info,*image,exception);
cristyf4ad9df2011-07-08 16:49:03 +0000892 (void) BlackThresholdImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +0000893 break;
894 }
895 if (LocaleCompare("blue-shift",option+1) == 0)
896 {
897 /*
898 Blue shift image.
899 */
cristy6fccee12011-10-20 18:43:18 +0000900 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000901 geometry_info.rho=1.5;
902 if (*option == '-')
903 flags=ParseGeometry(argv[i+1],&geometry_info);
904 mogrify_image=BlueShiftImage(*image,geometry_info.rho,exception);
905 break;
906 }
907 if (LocaleCompare("blur",option+1) == 0)
908 {
909 /*
910 Gaussian blur image.
911 */
cristy6fccee12011-10-20 18:43:18 +0000912 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000913 flags=ParseGeometry(argv[i+1],&geometry_info);
914 if ((flags & SigmaValue) == 0)
915 geometry_info.sigma=1.0;
cristy05c0c9a2011-09-05 23:16:13 +0000916 if ((flags & XiValue) == 0)
917 geometry_info.xi=0.0;
cristyf4ad9df2011-07-08 16:49:03 +0000918 mogrify_image=BlurImage(*image,geometry_info.rho,
cristyaa2c16c2012-03-25 22:21:35 +0000919 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000920 break;
921 }
922 if (LocaleCompare("border",option+1) == 0)
923 {
924 /*
925 Surround image with a border of solid color.
926 */
cristy6fccee12011-10-20 18:43:18 +0000927 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000928 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
cristy633f0c62011-09-15 13:27:36 +0000929 mogrify_image=BorderImage(*image,&geometry,compose,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000930 break;
931 }
932 if (LocaleCompare("bordercolor",option+1) == 0)
933 {
934 if (*option == '+')
935 {
cristy9950d572011-10-01 18:22:35 +0000936 (void) QueryColorCompliance(MogrifyBorderColor,AllCompliance,
cristy05c0c9a2011-09-05 23:16:13 +0000937 &draw_info->border_color,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000938 break;
939 }
cristy9950d572011-10-01 18:22:35 +0000940 (void) QueryColorCompliance(argv[i+1],AllCompliance,
941 &draw_info->border_color,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000942 break;
943 }
944 if (LocaleCompare("box",option+1) == 0)
945 {
cristy9950d572011-10-01 18:22:35 +0000946 (void) QueryColorCompliance(argv[i+1],AllCompliance,
947 &draw_info->undercolor,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000948 break;
949 }
950 if (LocaleCompare("brightness-contrast",option+1) == 0)
951 {
952 double
953 brightness,
954 contrast;
955
anthonydf8ebac2011-04-27 09:03:19 +0000956 /*
957 Brightness / contrast image.
958 */
cristy6fccee12011-10-20 18:43:18 +0000959 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000960 flags=ParseGeometry(argv[i+1],&geometry_info);
961 brightness=geometry_info.rho;
962 contrast=0.0;
963 if ((flags & SigmaValue) != 0)
964 contrast=geometry_info.sigma;
cristy444eda62011-08-10 02:07:46 +0000965 (void) BrightnessContrastImage(*image,brightness,contrast,
966 exception);
anthonydf8ebac2011-04-27 09:03:19 +0000967 break;
968 }
969 break;
970 }
971 case 'c':
972 {
cristy4ceadb82014-03-29 15:30:43 +0000973 if (LocaleCompare("canny",option+1) == 0)
974 {
975 /*
976 Detect edges in the image.
977 */
978 (void) SyncImageSettings(mogrify_info,*image,exception);
979 flags=ParseGeometry(argv[i+1],&geometry_info);
980 if ((flags & SigmaValue) == 0)
981 geometry_info.sigma=1.0;
982 if ((flags & XiValue) == 0)
cristy3bf50d82014-04-10 18:26:23 +0000983 geometry_info.xi=0.10;
cristy4ceadb82014-03-29 15:30:43 +0000984 if ((flags & PsiValue) == 0)
cristy3bf50d82014-04-10 18:26:23 +0000985 geometry_info.psi=0.30;
cristyd47682e2014-03-29 21:58:22 +0000986 if ((flags & PercentValue) != 0)
987 {
cristy41814f22014-04-09 20:53:11 +0000988 geometry_info.xi/=100.0;
989 geometry_info.psi/=100.0;
cristyd47682e2014-03-29 21:58:22 +0000990 }
cristy4ceadb82014-03-29 15:30:43 +0000991 mogrify_image=CannyEdgeImage(*image,geometry_info.rho,
992 geometry_info.sigma,geometry_info.xi,geometry_info.psi,exception);
993 break;
994 }
anthonydf8ebac2011-04-27 09:03:19 +0000995 if (LocaleCompare("cdl",option+1) == 0)
996 {
997 char
998 *color_correction_collection;
999
1000 /*
1001 Color correct with a color decision list.
1002 */
cristy6fccee12011-10-20 18:43:18 +00001003 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy3a5987c2013-11-07 14:18:46 +00001004 color_correction_collection=FileToString(argv[i+1],~0UL,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001005 if (color_correction_collection == (char *) NULL)
1006 break;
cristy1bfa9f02011-08-11 02:35:43 +00001007 (void) ColorDecisionListImage(*image,color_correction_collection,
1008 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001009 break;
1010 }
cristy17ada022014-11-07 22:12:23 +00001011 if (LocaleCompare("channel",option+1) == 0)
1012 {
1013 ChannelType
1014 channel;
1015
1016 (void) SyncImageSettings(mogrify_info,*image,exception);
1017 if (*option == '+')
1018 {
cristybcd59342015-06-07 14:07:19 +00001019 (void) SetPixelChannelMask(*image,DefaultChannels);
cristy17ada022014-11-07 22:12:23 +00001020 break;
1021 }
1022 channel=(ChannelType) ParseChannelOption(argv[i+1]);
cristybcd59342015-06-07 14:07:19 +00001023 (void) SetPixelChannelMask(*image,channel);
cristy17ada022014-11-07 22:12:23 +00001024 break;
1025 }
anthonydf8ebac2011-04-27 09:03:19 +00001026 if (LocaleCompare("charcoal",option+1) == 0)
1027 {
1028 /*
1029 Charcoal image.
1030 */
cristy6fccee12011-10-20 18:43:18 +00001031 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001032 flags=ParseGeometry(argv[i+1],&geometry_info);
1033 if ((flags & SigmaValue) == 0)
1034 geometry_info.sigma=1.0;
cristy05c0c9a2011-09-05 23:16:13 +00001035 if ((flags & XiValue) == 0)
1036 geometry_info.xi=1.0;
anthonydf8ebac2011-04-27 09:03:19 +00001037 mogrify_image=CharcoalImage(*image,geometry_info.rho,
cristyaa2c16c2012-03-25 22:21:35 +00001038 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001039 break;
1040 }
1041 if (LocaleCompare("chop",option+1) == 0)
1042 {
1043 /*
1044 Chop the image.
1045 */
cristy6fccee12011-10-20 18:43:18 +00001046 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001047 (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1048 mogrify_image=ChopImage(*image,&geometry,exception);
1049 break;
1050 }
anthonydf8ebac2011-04-27 09:03:19 +00001051 if (LocaleCompare("clip",option+1) == 0)
1052 {
cristy6fccee12011-10-20 18:43:18 +00001053 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001054 if (*option == '+')
1055 {
cristyacd0d4c2015-07-25 16:12:33 +00001056 (void) SetImageMask(*image,ReadPixelMask,(Image *) NULL,
1057 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001058 break;
1059 }
cristy018f07f2011-09-04 21:15:19 +00001060 (void) ClipImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001061 break;
1062 }
1063 if (LocaleCompare("clip-mask",option+1) == 0)
1064 {
1065 CacheView
1066 *mask_view;
1067
1068 Image
1069 *mask_image;
1070
cristy4c08aed2011-07-01 19:47:50 +00001071 register Quantum
dirk05d2ff72015-11-18 23:13:43 +01001072 *magick_restrict q;
anthonydf8ebac2011-04-27 09:03:19 +00001073
1074 register ssize_t
1075 x;
1076
1077 ssize_t
1078 y;
1079
cristy6fccee12011-10-20 18:43:18 +00001080 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001081 if (*option == '+')
1082 {
1083 /*
1084 Remove a mask.
1085 */
cristyacd0d4c2015-07-25 16:12:33 +00001086 (void) SetImageMask(*image,ReadPixelMask,(Image *) NULL,
1087 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001088 break;
1089 }
1090 /*
1091 Set the image mask.
1092 FUTURE: This Should Be a SetImageAlphaChannel() call, Or two.
1093 */
1094 mask_image=GetImageCache(mogrify_info,argv[i+1],exception);
1095 if (mask_image == (Image *) NULL)
1096 break;
cristy574cc262011-08-05 01:23:58 +00001097 if (SetImageStorageClass(mask_image,DirectClass,exception) == MagickFalse)
anthonydf8ebac2011-04-27 09:03:19 +00001098 return(MagickFalse);
cristy46ff2672012-12-14 15:32:26 +00001099 mask_view=AcquireAuthenticCacheView(mask_image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001100 for (y=0; y < (ssize_t) mask_image->rows; y++)
1101 {
1102 q=GetCacheViewAuthenticPixels(mask_view,0,y,mask_image->columns,1,
1103 exception);
cristyacd2ed22011-08-30 01:44:23 +00001104 if (q == (Quantum *) NULL)
anthonydf8ebac2011-04-27 09:03:19 +00001105 break;
1106 for (x=0; x < (ssize_t) mask_image->columns; x++)
1107 {
cristy7d6d3d82014-11-09 17:00:16 +00001108 if (mask_image->alpha_trait == UndefinedPixelTrait)
cristy52b632a2014-11-08 00:31:34 +00001109 SetPixelAlpha(mask_image,(Quantum)
1110 GetPixelIntensity(mask_image,q),q);
cristy4c08aed2011-07-01 19:47:50 +00001111 SetPixelRed(mask_image,GetPixelAlpha(mask_image,q),q);
1112 SetPixelGreen(mask_image,GetPixelAlpha(mask_image,q),q);
1113 SetPixelBlue(mask_image,GetPixelAlpha(mask_image,q),q);
cristyed231572011-07-14 02:18:59 +00001114 q+=GetPixelChannels(mask_image);
anthonydf8ebac2011-04-27 09:03:19 +00001115 }
1116 if (SyncCacheViewAuthenticPixels(mask_view,exception) == MagickFalse)
1117 break;
1118 }
1119 mask_view=DestroyCacheView(mask_view);
cristy8a46d822012-08-28 23:32:39 +00001120 mask_image->alpha_trait=BlendPixelTrait;
cristyacd0d4c2015-07-25 16:12:33 +00001121 (void) SetImageMask(*image,ReadPixelMask,mask_image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001122 break;
1123 }
1124 if (LocaleCompare("clip-path",option+1) == 0)
1125 {
cristy6fccee12011-10-20 18:43:18 +00001126 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001127 (void) ClipImagePath(*image,argv[i+1],*option == '-' ? MagickTrue :
cristy018f07f2011-09-04 21:15:19 +00001128 MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001129 break;
1130 }
1131 if (LocaleCompare("colorize",option+1) == 0)
1132 {
1133 /*
1134 Colorize the image.
1135 */
cristy6fccee12011-10-20 18:43:18 +00001136 (void) SyncImageSettings(mogrify_info,*image,exception);
cristyc7e6ff62011-10-03 13:46:11 +00001137 mogrify_image=ColorizeImage(*image,argv[i+1],&fill,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001138 break;
1139 }
1140 if (LocaleCompare("color-matrix",option+1) == 0)
1141 {
1142 KernelInfo
1143 *kernel;
1144
cristy6fccee12011-10-20 18:43:18 +00001145 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy2c57b742014-10-31 00:40:34 +00001146 kernel=AcquireKernelInfo(argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00001147 if (kernel == (KernelInfo *) NULL)
1148 break;
anthonyfd706f92012-01-19 04:22:02 +00001149 /* FUTURE: check on size of the matrix */
anthonydf8ebac2011-04-27 09:03:19 +00001150 mogrify_image=ColorMatrixImage(*image,kernel,exception);
1151 kernel=DestroyKernelInfo(kernel);
1152 break;
1153 }
1154 if (LocaleCompare("colors",option+1) == 0)
1155 {
1156 /*
1157 Reduce the number of colors in the image.
1158 */
cristy6fccee12011-10-20 18:43:18 +00001159 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001160 quantize_info->number_colors=StringToUnsignedLong(argv[i+1]);
1161 if (quantize_info->number_colors == 0)
1162 break;
1163 if (((*image)->storage_class == DirectClass) ||
1164 (*image)->colors > quantize_info->number_colors)
cristy018f07f2011-09-04 21:15:19 +00001165 (void) QuantizeImage(quantize_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001166 else
cristy018f07f2011-09-04 21:15:19 +00001167 (void) CompressImageColormap(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001168 break;
1169 }
1170 if (LocaleCompare("colorspace",option+1) == 0)
1171 {
1172 ColorspaceType
1173 colorspace;
1174
cristy6fccee12011-10-20 18:43:18 +00001175 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001176 if (*option == '+')
1177 {
cristyc511e882012-04-16 21:11:14 +00001178 (void) TransformImageColorspace(*image,sRGBColorspace,
1179 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001180 break;
1181 }
1182 colorspace=(ColorspaceType) ParseCommandOption(
1183 MagickColorspaceOptions,MagickFalse,argv[i+1]);
cristye941a752011-10-15 01:52:48 +00001184 (void) TransformImageColorspace(*image,colorspace,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001185 break;
1186 }
cristy633f0c62011-09-15 13:27:36 +00001187 if (LocaleCompare("compose",option+1) == 0)
1188 {
cristy6fccee12011-10-20 18:43:18 +00001189 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy633f0c62011-09-15 13:27:36 +00001190 compose=(CompositeOperator) ParseCommandOption(MagickComposeOptions,
1191 MagickFalse,argv[i+1]);
1192 break;
1193 }
dirk7182bd12016-01-01 13:10:03 +01001194 if (LocaleCompare("connected-components",option+1) == 0)
cristy6e0b3bc2014-10-19 17:51:42 +00001195 {
1196 (void) SyncImageSettings(mogrify_info,*image,exception);
Cristy62e13982015-12-30 09:26:00 -05001197 mogrify_image=ConnectedComponentsImage(*image,(size_t)
Cristy2ca0e9a2016-01-01 08:36:14 -05001198 StringToInteger(argv[i+1]),(CCObjectInfo **) NULL,exception);
cristy6e0b3bc2014-10-19 17:51:42 +00001199 break;
1200 }
anthonydf8ebac2011-04-27 09:03:19 +00001201 if (LocaleCompare("contrast",option+1) == 0)
1202 {
cristy6fccee12011-10-20 18:43:18 +00001203 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001204 (void) ContrastImage(*image,(*option == '-') ? MagickTrue :
cristye23ec9d2011-08-16 18:15:40 +00001205 MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001206 break;
1207 }
1208 if (LocaleCompare("contrast-stretch",option+1) == 0)
1209 {
1210 double
1211 black_point,
1212 white_point;
1213
anthonydf8ebac2011-04-27 09:03:19 +00001214 /*
1215 Contrast stretch image.
1216 */
cristy6fccee12011-10-20 18:43:18 +00001217 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001218 flags=ParseGeometry(argv[i+1],&geometry_info);
1219 black_point=geometry_info.rho;
1220 white_point=(flags & SigmaValue) != 0 ? geometry_info.sigma :
1221 black_point;
1222 if ((flags & PercentValue) != 0)
1223 {
1224 black_point*=(double) (*image)->columns*(*image)->rows/100.0;
1225 white_point*=(double) (*image)->columns*(*image)->rows/100.0;
1226 }
cristya19f1d72012-08-07 18:24:38 +00001227 white_point=(double) (*image)->columns*(*image)->rows-
anthonydf8ebac2011-04-27 09:03:19 +00001228 white_point;
cristye23ec9d2011-08-16 18:15:40 +00001229 (void) ContrastStretchImage(*image,black_point,white_point,
1230 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001231 break;
1232 }
1233 if (LocaleCompare("convolve",option+1) == 0)
1234 {
cristy77923262015-02-23 21:57:13 +00001235 double
1236 gamma;
1237
anthonydf8ebac2011-04-27 09:03:19 +00001238 KernelInfo
cristy41cbe682011-07-15 19:12:37 +00001239 *kernel_info;
cristy77923262015-02-23 21:57:13 +00001240
1241 register ssize_t
1242 j;
anthonydf8ebac2011-04-27 09:03:19 +00001243
cristy5fb03252015-02-23 22:04:31 +00001244 size_t
1245 extent;
1246
cristy6fccee12011-10-20 18:43:18 +00001247 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy2c57b742014-10-31 00:40:34 +00001248 kernel_info=AcquireKernelInfo(argv[i+1],exception);
cristy41cbe682011-07-15 19:12:37 +00001249 if (kernel_info == (KernelInfo *) NULL)
anthonydf8ebac2011-04-27 09:03:19 +00001250 break;
cristy5fb03252015-02-23 22:04:31 +00001251 extent=kernel_info->width*kernel_info->height;
cristy77923262015-02-23 21:57:13 +00001252 gamma=0.0;
cristy5fb03252015-02-23 22:04:31 +00001253 for (j=0; j < (ssize_t) extent; j++)
cristy77923262015-02-23 21:57:13 +00001254 gamma+=kernel_info->values[j];
1255 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
cristy5fb03252015-02-23 22:04:31 +00001256 for (j=0; j < (ssize_t) extent; j++)
cristy77923262015-02-23 21:57:13 +00001257 kernel_info->values[j]*=gamma;
cristya12d8ba2012-04-29 16:33:41 +00001258 mogrify_image=MorphologyImage(*image,CorrelateMorphology,1,
1259 kernel_info,exception);
cristy41cbe682011-07-15 19:12:37 +00001260 kernel_info=DestroyKernelInfo(kernel_info);
anthonydf8ebac2011-04-27 09:03:19 +00001261 break;
1262 }
1263 if (LocaleCompare("crop",option+1) == 0)
1264 {
1265 /*
1266 Crop a image to a smaller size
1267 */
cristy6fccee12011-10-20 18:43:18 +00001268 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001269 mogrify_image=CropImageToTiles(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00001270 break;
1271 }
1272 if (LocaleCompare("cycle",option+1) == 0)
1273 {
1274 /*
1275 Cycle an image colormap.
1276 */
cristy6fccee12011-10-20 18:43:18 +00001277 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy018f07f2011-09-04 21:15:19 +00001278 (void) CycleColormapImage(*image,(ssize_t) StringToLong(argv[i+1]),
1279 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001280 break;
1281 }
1282 break;
1283 }
1284 case 'd':
1285 {
1286 if (LocaleCompare("decipher",option+1) == 0)
1287 {
1288 StringInfo
1289 *passkey;
1290
1291 /*
1292 Decipher pixels.
1293 */
cristy6fccee12011-10-20 18:43:18 +00001294 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy3a5987c2013-11-07 14:18:46 +00001295 passkey=FileToStringInfo(argv[i+1],~0UL,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001296 if (passkey != (StringInfo *) NULL)
1297 {
1298 (void) PasskeyDecipherImage(*image,passkey,exception);
1299 passkey=DestroyStringInfo(passkey);
1300 }
1301 break;
1302 }
1303 if (LocaleCompare("density",option+1) == 0)
1304 {
1305 /*
1306 Set image density.
1307 */
1308 (void) CloneString(&draw_info->density,argv[i+1]);
1309 break;
1310 }
1311 if (LocaleCompare("depth",option+1) == 0)
1312 {
cristy6fccee12011-10-20 18:43:18 +00001313 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001314 if (*option == '+')
1315 {
cristy8a11cb12011-10-19 23:53:34 +00001316 (void) SetImageDepth(*image,MAGICKCORE_QUANTUM_DEPTH,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001317 break;
1318 }
cristy8a11cb12011-10-19 23:53:34 +00001319 (void) SetImageDepth(*image,StringToUnsignedLong(argv[i+1]),
1320 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001321 break;
1322 }
1323 if (LocaleCompare("deskew",option+1) == 0)
1324 {
1325 double
1326 threshold;
1327
1328 /*
1329 Straighten the image.
1330 */
cristy6fccee12011-10-20 18:43:18 +00001331 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001332 if (*option == '+')
1333 threshold=40.0*QuantumRange/100.0;
1334 else
cristy9b34e302011-11-05 02:15:45 +00001335 threshold=StringToDoubleInterval(argv[i+1],(double) QuantumRange+
1336 1.0);
anthonydf8ebac2011-04-27 09:03:19 +00001337 mogrify_image=DeskewImage(*image,threshold,exception);
1338 break;
1339 }
1340 if (LocaleCompare("despeckle",option+1) == 0)
1341 {
1342 /*
1343 Reduce the speckles within an image.
1344 */
cristy6fccee12011-10-20 18:43:18 +00001345 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001346 mogrify_image=DespeckleImage(*image,exception);
1347 break;
1348 }
1349 if (LocaleCompare("display",option+1) == 0)
1350 {
1351 (void) CloneString(&draw_info->server_name,argv[i+1]);
1352 break;
1353 }
1354 if (LocaleCompare("distort",option+1) == 0)
1355 {
1356 char
1357 *args,
cristy151b66d2015-04-15 10:50:31 +00001358 token[MagickPathExtent];
anthonydf8ebac2011-04-27 09:03:19 +00001359
1360 const char
1361 *p;
1362
1363 DistortImageMethod
1364 method;
1365
1366 double
1367 *arguments;
1368
1369 register ssize_t
1370 x;
1371
1372 size_t
1373 number_arguments;
1374
1375 /*
1376 Distort image.
1377 */
cristy6fccee12011-10-20 18:43:18 +00001378 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001379 method=(DistortImageMethod) ParseCommandOption(MagickDistortOptions,
1380 MagickFalse,argv[i+1]);
cristy56835872011-11-06 01:19:13 +00001381 if (method == ResizeDistortion)
anthonydf8ebac2011-04-27 09:03:19 +00001382 {
anthonydf8ebac2011-04-27 09:03:19 +00001383 double
1384 resize_args[2];
cristy56835872011-11-06 01:19:13 +00001385
1386 /*
1387 Special Case - Argument is actually a resize geometry!
1388 Convert that to an appropriate distortion argument array.
1389 */
anthonydf8ebac2011-04-27 09:03:19 +00001390 (void) ParseRegionGeometry(*image,argv[i+2],&geometry,
cristy56835872011-11-06 01:19:13 +00001391 exception);
1392 resize_args[0]=(double) geometry.width;
1393 resize_args[1]=(double) geometry.height;
anthonydf8ebac2011-04-27 09:03:19 +00001394 mogrify_image=DistortImage(*image,method,(size_t)2,
cristy56835872011-11-06 01:19:13 +00001395 resize_args,MagickTrue,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001396 break;
1397 }
cristy018f07f2011-09-04 21:15:19 +00001398 args=InterpretImageProperties(mogrify_info,*image,argv[i+2],
1399 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001400 if (args == (char *) NULL)
1401 break;
1402 p=(char *) args;
1403 for (x=0; *p != '\0'; x++)
1404 {
1405 GetMagickToken(p,&p,token);
1406 if (*token == ',')
1407 GetMagickToken(p,&p,token);
1408 }
1409 number_arguments=(size_t) x;
1410 arguments=(double *) AcquireQuantumMemory(number_arguments,
1411 sizeof(*arguments));
1412 if (arguments == (double *) NULL)
1413 ThrowWandFatalException(ResourceLimitFatalError,
1414 "MemoryAllocationFailed",(*image)->filename);
1415 (void) ResetMagickMemory(arguments,0,number_arguments*
1416 sizeof(*arguments));
1417 p=(char *) args;
1418 for (x=0; (x < (ssize_t) number_arguments) && (*p != '\0'); x++)
1419 {
1420 GetMagickToken(p,&p,token);
1421 if (*token == ',')
1422 GetMagickToken(p,&p,token);
cristydbdd0e32011-11-04 23:29:40 +00001423 arguments[x]=StringToDouble(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001424 }
1425 args=DestroyString(args);
1426 mogrify_image=DistortImage(*image,method,number_arguments,arguments,
1427 (*option == '+') ? MagickTrue : MagickFalse,exception);
1428 arguments=(double *) RelinquishMagickMemory(arguments);
1429 break;
1430 }
1431 if (LocaleCompare("dither",option+1) == 0)
1432 {
1433 if (*option == '+')
1434 {
cristycbda6112012-05-27 20:57:16 +00001435 quantize_info->dither_method=NoDitherMethod;
anthonydf8ebac2011-04-27 09:03:19 +00001436 break;
1437 }
anthonydf8ebac2011-04-27 09:03:19 +00001438 quantize_info->dither_method=(DitherMethod) ParseCommandOption(
1439 MagickDitherOptions,MagickFalse,argv[i+1]);
anthonydf8ebac2011-04-27 09:03:19 +00001440 break;
1441 }
1442 if (LocaleCompare("draw",option+1) == 0)
1443 {
1444 /*
1445 Draw image.
1446 */
cristy6fccee12011-10-20 18:43:18 +00001447 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001448 (void) CloneString(&draw_info->primitive,argv[i+1]);
cristy018f07f2011-09-04 21:15:19 +00001449 (void) DrawImage(*image,draw_info,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001450 break;
1451 }
1452 break;
1453 }
1454 case 'e':
1455 {
1456 if (LocaleCompare("edge",option+1) == 0)
1457 {
1458 /*
1459 Enhance edges in the image.
1460 */
cristy6fccee12011-10-20 18:43:18 +00001461 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001462 flags=ParseGeometry(argv[i+1],&geometry_info);
cristy9dc4c512013-03-24 01:38:00 +00001463 mogrify_image=EdgeImage(*image,geometry_info.rho,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001464 break;
1465 }
1466 if (LocaleCompare("emboss",option+1) == 0)
1467 {
1468 /*
cristyd89705a2012-01-20 02:52:24 +00001469 Emboss image.
anthonydf8ebac2011-04-27 09:03:19 +00001470 */
cristy6fccee12011-10-20 18:43:18 +00001471 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001472 flags=ParseGeometry(argv[i+1],&geometry_info);
1473 if ((flags & SigmaValue) == 0)
1474 geometry_info.sigma=1.0;
1475 mogrify_image=EmbossImage(*image,geometry_info.rho,
1476 geometry_info.sigma,exception);
1477 break;
1478 }
1479 if (LocaleCompare("encipher",option+1) == 0)
1480 {
1481 StringInfo
1482 *passkey;
1483
1484 /*
1485 Encipher pixels.
1486 */
cristy6fccee12011-10-20 18:43:18 +00001487 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy3a5987c2013-11-07 14:18:46 +00001488 passkey=FileToStringInfo(argv[i+1],~0UL,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001489 if (passkey != (StringInfo *) NULL)
1490 {
1491 (void) PasskeyEncipherImage(*image,passkey,exception);
1492 passkey=DestroyStringInfo(passkey);
1493 }
1494 break;
1495 }
1496 if (LocaleCompare("encoding",option+1) == 0)
1497 {
1498 (void) CloneString(&draw_info->encoding,argv[i+1]);
1499 break;
1500 }
1501 if (LocaleCompare("enhance",option+1) == 0)
1502 {
1503 /*
1504 Enhance image.
1505 */
cristy6fccee12011-10-20 18:43:18 +00001506 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001507 mogrify_image=EnhanceImage(*image,exception);
1508 break;
1509 }
1510 if (LocaleCompare("equalize",option+1) == 0)
1511 {
1512 /*
1513 Equalize image.
1514 */
cristy6fccee12011-10-20 18:43:18 +00001515 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy6d8c3d72011-08-22 01:20:01 +00001516 (void) EqualizeImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001517 break;
1518 }
1519 if (LocaleCompare("evaluate",option+1) == 0)
1520 {
1521 double
1522 constant;
1523
1524 MagickEvaluateOperator
1525 op;
1526
cristy6fccee12011-10-20 18:43:18 +00001527 (void) SyncImageSettings(mogrify_info,*image,exception);
cristyd42d9952011-07-08 14:21:50 +00001528 op=(MagickEvaluateOperator) ParseCommandOption(
1529 MagickEvaluateOptions,MagickFalse,argv[i+1]);
cristy9b34e302011-11-05 02:15:45 +00001530 constant=StringToDoubleInterval(argv[i+2],(double) QuantumRange+
1531 1.0);
cristyd42d9952011-07-08 14:21:50 +00001532 (void) EvaluateImage(*image,op,constant,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001533 break;
1534 }
1535 if (LocaleCompare("extent",option+1) == 0)
1536 {
1537 /*
1538 Set the image extent.
1539 */
cristy6fccee12011-10-20 18:43:18 +00001540 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001541 flags=ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1542 if (geometry.width == 0)
1543 geometry.width=(*image)->columns;
1544 if (geometry.height == 0)
1545 geometry.height=(*image)->rows;
1546 mogrify_image=ExtentImage(*image,&geometry,exception);
1547 break;
1548 }
1549 break;
1550 }
1551 case 'f':
1552 {
1553 if (LocaleCompare("family",option+1) == 0)
1554 {
1555 if (*option == '+')
1556 {
1557 if (draw_info->family != (char *) NULL)
1558 draw_info->family=DestroyString(draw_info->family);
1559 break;
1560 }
1561 (void) CloneString(&draw_info->family,argv[i+1]);
1562 break;
1563 }
1564 if (LocaleCompare("features",option+1) == 0)
1565 {
1566 if (*option == '+')
1567 {
1568 (void) DeleteImageArtifact(*image,"identify:features");
1569 break;
1570 }
cristy47c09d12014-01-19 15:18:47 +00001571 (void) SetImageArtifact(*image,"vdentify:features",argv[i+1]);
1572 (void) SetImageArtifact(*image,"verbose","true");
anthonydf8ebac2011-04-27 09:03:19 +00001573 break;
1574 }
1575 if (LocaleCompare("fill",option+1) == 0)
1576 {
1577 ExceptionInfo
1578 *sans;
1579
anthonyfd706f92012-01-19 04:22:02 +00001580 PixelInfo
1581 color;
1582
cristy4c08aed2011-07-01 19:47:50 +00001583 GetPixelInfo(*image,&fill);
anthonydf8ebac2011-04-27 09:03:19 +00001584 if (*option == '+')
1585 {
cristy269c9412011-10-13 23:41:15 +00001586 (void) QueryColorCompliance("none",AllCompliance,&fill,
cristy9950d572011-10-01 18:22:35 +00001587 exception);
anthonyfd706f92012-01-19 04:22:02 +00001588 draw_info->fill=fill;
anthonydf8ebac2011-04-27 09:03:19 +00001589 if (draw_info->fill_pattern != (Image *) NULL)
1590 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
1591 break;
1592 }
1593 sans=AcquireExceptionInfo();
anthonyfd706f92012-01-19 04:22:02 +00001594 status=QueryColorCompliance(argv[i+1],AllCompliance,&color,sans);
anthonydf8ebac2011-04-27 09:03:19 +00001595 sans=DestroyExceptionInfo(sans);
1596 if (status == MagickFalse)
1597 draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1],
1598 exception);
anthonyfd706f92012-01-19 04:22:02 +00001599 else
1600 draw_info->fill=fill=color;
anthonydf8ebac2011-04-27 09:03:19 +00001601 break;
1602 }
1603 if (LocaleCompare("flip",option+1) == 0)
1604 {
1605 /*
1606 Flip image scanlines.
1607 */
cristy6fccee12011-10-20 18:43:18 +00001608 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001609 mogrify_image=FlipImage(*image,exception);
1610 break;
1611 }
anthonydf8ebac2011-04-27 09:03:19 +00001612 if (LocaleCompare("floodfill",option+1) == 0)
1613 {
cristy4c08aed2011-07-01 19:47:50 +00001614 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00001615 target;
1616
1617 /*
1618 Floodfill image.
1619 */
cristy6fccee12011-10-20 18:43:18 +00001620 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001621 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
cristy269c9412011-10-13 23:41:15 +00001622 (void) QueryColorCompliance(argv[i+2],AllCompliance,&target,
cristy9950d572011-10-01 18:22:35 +00001623 exception);
cristyd42d9952011-07-08 14:21:50 +00001624 (void) FloodfillPaintImage(*image,draw_info,&target,geometry.x,
cristy189e84c2011-08-27 18:08:53 +00001625 geometry.y,*option == '-' ? MagickFalse : MagickTrue,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001626 break;
1627 }
anthony3d2f4862011-05-01 13:48:16 +00001628 if (LocaleCompare("flop",option+1) == 0)
1629 {
1630 /*
1631 Flop image scanlines.
1632 */
cristy6fccee12011-10-20 18:43:18 +00001633 (void) SyncImageSettings(mogrify_info,*image,exception);
anthony3d2f4862011-05-01 13:48:16 +00001634 mogrify_image=FlopImage(*image,exception);
1635 break;
1636 }
anthonydf8ebac2011-04-27 09:03:19 +00001637 if (LocaleCompare("font",option+1) == 0)
1638 {
1639 if (*option == '+')
1640 {
1641 if (draw_info->font != (char *) NULL)
1642 draw_info->font=DestroyString(draw_info->font);
1643 break;
1644 }
1645 (void) CloneString(&draw_info->font,argv[i+1]);
1646 break;
1647 }
1648 if (LocaleCompare("format",option+1) == 0)
1649 {
1650 format=argv[i+1];
1651 break;
1652 }
1653 if (LocaleCompare("frame",option+1) == 0)
1654 {
1655 FrameInfo
1656 frame_info;
1657
1658 /*
1659 Surround image with an ornamental border.
1660 */
cristy6fccee12011-10-20 18:43:18 +00001661 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001662 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
1663 frame_info.width=geometry.width;
1664 frame_info.height=geometry.height;
anthonydf8ebac2011-04-27 09:03:19 +00001665 frame_info.outer_bevel=geometry.x;
1666 frame_info.inner_bevel=geometry.y;
1667 frame_info.x=(ssize_t) frame_info.width;
1668 frame_info.y=(ssize_t) frame_info.height;
1669 frame_info.width=(*image)->columns+2*frame_info.width;
1670 frame_info.height=(*image)->rows+2*frame_info.height;
cristy633f0c62011-09-15 13:27:36 +00001671 mogrify_image=FrameImage(*image,&frame_info,compose,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001672 break;
1673 }
1674 if (LocaleCompare("function",option+1) == 0)
1675 {
1676 char
1677 *arguments,
cristy151b66d2015-04-15 10:50:31 +00001678 token[MagickPathExtent];
anthonydf8ebac2011-04-27 09:03:19 +00001679
1680 const char
1681 *p;
1682
1683 double
1684 *parameters;
1685
1686 MagickFunction
1687 function;
1688
1689 register ssize_t
1690 x;
1691
1692 size_t
1693 number_parameters;
1694
1695 /*
1696 Function Modify Image Values
1697 */
cristy6fccee12011-10-20 18:43:18 +00001698 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001699 function=(MagickFunction) ParseCommandOption(MagickFunctionOptions,
1700 MagickFalse,argv[i+1]);
cristy018f07f2011-09-04 21:15:19 +00001701 arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2],
1702 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001703 if (arguments == (char *) NULL)
1704 break;
1705 p=(char *) arguments;
1706 for (x=0; *p != '\0'; x++)
1707 {
1708 GetMagickToken(p,&p,token);
1709 if (*token == ',')
1710 GetMagickToken(p,&p,token);
1711 }
1712 number_parameters=(size_t) x;
1713 parameters=(double *) AcquireQuantumMemory(number_parameters,
1714 sizeof(*parameters));
1715 if (parameters == (double *) NULL)
1716 ThrowWandFatalException(ResourceLimitFatalError,
1717 "MemoryAllocationFailed",(*image)->filename);
1718 (void) ResetMagickMemory(parameters,0,number_parameters*
1719 sizeof(*parameters));
1720 p=(char *) arguments;
1721 for (x=0; (x < (ssize_t) number_parameters) && (*p != '\0'); x++)
1722 {
1723 GetMagickToken(p,&p,token);
1724 if (*token == ',')
1725 GetMagickToken(p,&p,token);
cristydbdd0e32011-11-04 23:29:40 +00001726 parameters[x]=StringToDouble(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001727 }
1728 arguments=DestroyString(arguments);
cristyd42d9952011-07-08 14:21:50 +00001729 (void) FunctionImage(*image,function,number_parameters,parameters,
1730 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001731 parameters=(double *) RelinquishMagickMemory(parameters);
1732 break;
1733 }
1734 break;
1735 }
1736 case 'g':
1737 {
1738 if (LocaleCompare("gamma",option+1) == 0)
1739 {
1740 /*
1741 Gamma image.
1742 */
cristy6fccee12011-10-20 18:43:18 +00001743 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001744 if (*option == '+')
cristydbdd0e32011-11-04 23:29:40 +00001745 (*image)->gamma=StringToDouble(argv[i+1],(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001746 else
cristy473db352015-02-10 23:10:18 +00001747 (void) GammaImage(*image,StringToDouble(argv[i+1],(char **) NULL),
1748 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001749 break;
1750 }
1751 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
1752 (LocaleCompare("gaussian",option+1) == 0))
1753 {
1754 /*
1755 Gaussian blur image.
1756 */
cristy6fccee12011-10-20 18:43:18 +00001757 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001758 flags=ParseGeometry(argv[i+1],&geometry_info);
1759 if ((flags & SigmaValue) == 0)
1760 geometry_info.sigma=1.0;
cristyf4ad9df2011-07-08 16:49:03 +00001761 mogrify_image=GaussianBlurImage(*image,geometry_info.rho,
cristyd89705a2012-01-20 02:52:24 +00001762 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001763 break;
1764 }
1765 if (LocaleCompare("geometry",option+1) == 0)
1766 {
1767 /*
1768 Record Image offset, Resize last image.
1769 */
cristy6fccee12011-10-20 18:43:18 +00001770 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001771 if (*option == '+')
1772 {
1773 if ((*image)->geometry != (char *) NULL)
1774 (*image)->geometry=DestroyString((*image)->geometry);
1775 break;
1776 }
1777 flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
1778 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
1779 (void) CloneString(&(*image)->geometry,argv[i+1]);
1780 else
1781 mogrify_image=ResizeImage(*image,geometry.width,geometry.height,
cristyaa2c16c2012-03-25 22:21:35 +00001782 (*image)->filter,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001783 break;
1784 }
1785 if (LocaleCompare("gravity",option+1) == 0)
1786 {
1787 if (*option == '+')
1788 {
1789 draw_info->gravity=UndefinedGravity;
1790 break;
1791 }
1792 draw_info->gravity=(GravityType) ParseCommandOption(
1793 MagickGravityOptions,MagickFalse,argv[i+1]);
1794 break;
1795 }
cristye0b9b8f2013-03-28 12:39:39 +00001796 if (LocaleCompare("grayscale",option+1) == 0)
1797 {
cristyab943592013-03-29 16:47:23 +00001798 PixelIntensityMethod
1799 method;
1800
cristye0b9b8f2013-03-28 12:39:39 +00001801 (void) SyncImageSettings(mogrify_info,*image,exception);
cristyab943592013-03-29 16:47:23 +00001802 method=(PixelIntensityMethod) ParseCommandOption(
cristye0b9b8f2013-03-28 12:39:39 +00001803 MagickPixelIntensityOptions,MagickFalse,argv[i+1]);
cristyab943592013-03-29 16:47:23 +00001804 (void) GrayscaleImage(*image,method,exception);
cristye0b9b8f2013-03-28 12:39:39 +00001805 break;
1806 }
anthonydf8ebac2011-04-27 09:03:19 +00001807 break;
1808 }
1809 case 'h':
1810 {
1811 if (LocaleCompare("highlight-color",option+1) == 0)
1812 {
1813 (void) SetImageArtifact(*image,option+1,argv[i+1]);
1814 break;
1815 }
cristy4e215022014-04-19 18:02:35 +00001816 if (LocaleCompare("hough-lines",option+1) == 0)
1817 {
1818 /*
1819 Detect edges in the image.
1820 */
1821 (void) SyncImageSettings(mogrify_info,*image,exception);
1822 flags=ParseGeometry(argv[i+1],&geometry_info);
1823 if ((flags & SigmaValue) == 0)
1824 geometry_info.sigma=geometry_info.rho;
cristy20f90422014-04-27 13:34:21 +00001825 if ((flags & XiValue) == 0)
1826 geometry_info.xi=40;
cristy2fc10e52014-04-26 14:13:53 +00001827 mogrify_image=HoughLineImage(*image,(size_t) geometry_info.rho,
cristy4e215022014-04-19 18:02:35 +00001828 (size_t) geometry_info.sigma,(size_t) geometry_info.xi,exception);
1829 break;
1830 }
anthonydf8ebac2011-04-27 09:03:19 +00001831 break;
1832 }
1833 case 'i':
1834 {
1835 if (LocaleCompare("identify",option+1) == 0)
1836 {
1837 char
1838 *text;
1839
cristy6fccee12011-10-20 18:43:18 +00001840 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001841 if (format == (char *) NULL)
1842 {
cristya4037272011-08-28 15:11:39 +00001843 (void) IdentifyImage(*image,stdout,mogrify_info->verbose,
1844 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001845 break;
1846 }
cristy018f07f2011-09-04 21:15:19 +00001847 text=InterpretImageProperties(mogrify_info,*image,format,
1848 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001849 if (text == (char *) NULL)
1850 break;
1851 (void) fputs(text,stdout);
anthonydf8ebac2011-04-27 09:03:19 +00001852 text=DestroyString(text);
1853 break;
1854 }
1855 if (LocaleCompare("implode",option+1) == 0)
1856 {
1857 /*
1858 Implode image.
1859 */
cristy6fccee12011-10-20 18:43:18 +00001860 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001861 (void) ParseGeometry(argv[i+1],&geometry_info);
cristy76f512e2011-09-12 01:26:56 +00001862 mogrify_image=ImplodeImage(*image,geometry_info.rho,
1863 interpolate_method,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001864 break;
1865 }
1866 if (LocaleCompare("interline-spacing",option+1) == 0)
1867 {
1868 if (*option == '+')
1869 (void) ParseGeometry("0",&geometry_info);
1870 else
1871 (void) ParseGeometry(argv[i+1],&geometry_info);
1872 draw_info->interline_spacing=geometry_info.rho;
1873 break;
1874 }
cristy28474bf2011-09-11 23:32:52 +00001875 if (LocaleCompare("interpolate",option+1) == 0)
1876 {
1877 interpolate_method=(PixelInterpolateMethod) ParseCommandOption(
1878 MagickInterpolateOptions,MagickFalse,argv[i+1]);
1879 break;
1880 }
anthonydf8ebac2011-04-27 09:03:19 +00001881 if (LocaleCompare("interword-spacing",option+1) == 0)
1882 {
1883 if (*option == '+')
1884 (void) ParseGeometry("0",&geometry_info);
1885 else
1886 (void) ParseGeometry(argv[i+1],&geometry_info);
1887 draw_info->interword_spacing=geometry_info.rho;
1888 break;
1889 }
anthonyfd706f92012-01-19 04:22:02 +00001890 if (LocaleCompare("interpolative-resize",option+1) == 0)
1891 {
1892 /*
1893 Interpolative resize image.
1894 */
1895 (void) SyncImageSettings(mogrify_info,*image,exception);
1896 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
1897 mogrify_image=InterpolativeResizeImage(*image,geometry.width,
1898 geometry.height,interpolate_method,exception);
1899 break;
1900 }
anthonydf8ebac2011-04-27 09:03:19 +00001901 break;
1902 }
1903 case 'k':
1904 {
1905 if (LocaleCompare("kerning",option+1) == 0)
1906 {
1907 if (*option == '+')
1908 (void) ParseGeometry("0",&geometry_info);
1909 else
1910 (void) ParseGeometry(argv[i+1],&geometry_info);
1911 draw_info->kerning=geometry_info.rho;
1912 break;
1913 }
cristy3b207f82014-09-27 14:21:20 +00001914 if (LocaleCompare("kuwahara",option+1) == 0)
1915 {
1916 /*
1917 Edge preserving blur.
1918 */
1919 (void) SyncImageSettings(mogrify_info,*image,exception);
1920 flags=ParseGeometry(argv[i+1],&geometry_info);
1921 if ((flags & SigmaValue) == 0)
cristy25ea9362014-10-04 01:12:09 +00001922 geometry_info.sigma=geometry_info.rho-0.5;
cristy3b207f82014-09-27 14:21:20 +00001923 mogrify_image=KuwaharaImage(*image,geometry_info.rho,
1924 geometry_info.sigma,exception);
1925 break;
1926 }
anthonydf8ebac2011-04-27 09:03:19 +00001927 break;
1928 }
1929 case 'l':
1930 {
1931 if (LocaleCompare("lat",option+1) == 0)
1932 {
1933 /*
1934 Local adaptive threshold image.
1935 */
cristy6fccee12011-10-20 18:43:18 +00001936 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001937 flags=ParseGeometry(argv[i+1],&geometry_info);
1938 if ((flags & PercentValue) != 0)
1939 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
1940 mogrify_image=AdaptiveThresholdImage(*image,(size_t)
cristyde5cc632011-07-18 14:47:00 +00001941 geometry_info.rho,(size_t) geometry_info.sigma,(double)
anthonydf8ebac2011-04-27 09:03:19 +00001942 geometry_info.xi,exception);
1943 break;
1944 }
1945 if (LocaleCompare("level",option+1) == 0)
1946 {
cristya19f1d72012-08-07 18:24:38 +00001947 double
anthonydf8ebac2011-04-27 09:03:19 +00001948 black_point,
1949 gamma,
1950 white_point;
1951
anthonydf8ebac2011-04-27 09:03:19 +00001952 /*
1953 Parse levels.
1954 */
cristy6fccee12011-10-20 18:43:18 +00001955 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001956 flags=ParseGeometry(argv[i+1],&geometry_info);
1957 black_point=geometry_info.rho;
cristya19f1d72012-08-07 18:24:38 +00001958 white_point=(double) QuantumRange;
anthonydf8ebac2011-04-27 09:03:19 +00001959 if ((flags & SigmaValue) != 0)
1960 white_point=geometry_info.sigma;
1961 gamma=1.0;
1962 if ((flags & XiValue) != 0)
1963 gamma=geometry_info.xi;
1964 if ((flags & PercentValue) != 0)
1965 {
cristya19f1d72012-08-07 18:24:38 +00001966 black_point*=(double) (QuantumRange/100.0);
1967 white_point*=(double) (QuantumRange/100.0);
anthonydf8ebac2011-04-27 09:03:19 +00001968 }
1969 if ((flags & SigmaValue) == 0)
cristya19f1d72012-08-07 18:24:38 +00001970 white_point=(double) QuantumRange-black_point;
anthonydf8ebac2011-04-27 09:03:19 +00001971 if ((*option == '+') || ((flags & AspectValue) != 0))
cristy7c0a0a42011-08-23 17:57:25 +00001972 (void) LevelizeImage(*image,black_point,white_point,gamma,
1973 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001974 else
cristy01e9afd2011-08-10 17:38:41 +00001975 (void) LevelImage(*image,black_point,white_point,gamma,
1976 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001977 break;
1978 }
1979 if (LocaleCompare("level-colors",option+1) == 0)
1980 {
1981 char
cristy151b66d2015-04-15 10:50:31 +00001982 token[MagickPathExtent];
anthonydf8ebac2011-04-27 09:03:19 +00001983
1984 const char
1985 *p;
1986
cristy4c08aed2011-07-01 19:47:50 +00001987 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00001988 black_point,
1989 white_point;
1990
1991 p=(const char *) argv[i+1];
1992 GetMagickToken(p,&p,token); /* get black point color */
1993 if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
cristy269c9412011-10-13 23:41:15 +00001994 (void) QueryColorCompliance(token,AllCompliance,
cristy9950d572011-10-01 18:22:35 +00001995 &black_point,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001996 else
cristy269c9412011-10-13 23:41:15 +00001997 (void) QueryColorCompliance("#000000",AllCompliance,
cristy9950d572011-10-01 18:22:35 +00001998 &black_point,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001999 if (isalpha((int) token[0]) || (token[0] == '#'))
2000 GetMagickToken(p,&p,token);
2001 if (*token == '\0')
2002 white_point=black_point; /* set everything to that color */
2003 else
2004 {
2005 if ((isalpha((int) *token) == 0) && ((*token == '#') == 0))
2006 GetMagickToken(p,&p,token); /* Get white point color. */
2007 if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
cristy269c9412011-10-13 23:41:15 +00002008 (void) QueryColorCompliance(token,AllCompliance,
cristy9950d572011-10-01 18:22:35 +00002009 &white_point,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002010 else
cristy269c9412011-10-13 23:41:15 +00002011 (void) QueryColorCompliance("#ffffff",AllCompliance,
cristy9950d572011-10-01 18:22:35 +00002012 &white_point,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002013 }
cristy490408a2011-07-07 14:42:05 +00002014 (void) LevelImageColors(*image,&black_point,&white_point,
cristy7c0a0a42011-08-23 17:57:25 +00002015 *option == '+' ? MagickTrue : MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002016 break;
2017 }
2018 if (LocaleCompare("linear-stretch",option+1) == 0)
2019 {
2020 double
2021 black_point,
2022 white_point;
2023
cristy6fccee12011-10-20 18:43:18 +00002024 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002025 flags=ParseGeometry(argv[i+1],&geometry_info);
2026 black_point=geometry_info.rho;
cristya19f1d72012-08-07 18:24:38 +00002027 white_point=(double) (*image)->columns*(*image)->rows;
anthonydf8ebac2011-04-27 09:03:19 +00002028 if ((flags & SigmaValue) != 0)
2029 white_point=geometry_info.sigma;
2030 if ((flags & PercentValue) != 0)
2031 {
2032 black_point*=(double) (*image)->columns*(*image)->rows/100.0;
2033 white_point*=(double) (*image)->columns*(*image)->rows/100.0;
2034 }
2035 if ((flags & SigmaValue) == 0)
cristya19f1d72012-08-07 18:24:38 +00002036 white_point=(double) (*image)->columns*(*image)->rows-
anthonydf8ebac2011-04-27 09:03:19 +00002037 black_point;
cristy33bd5152011-08-24 01:42:24 +00002038 (void) LinearStretchImage(*image,black_point,white_point,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002039 break;
2040 }
anthonydf8ebac2011-04-27 09:03:19 +00002041 if (LocaleCompare("liquid-rescale",option+1) == 0)
2042 {
2043 /*
2044 Liquid rescale image.
2045 */
cristy6fccee12011-10-20 18:43:18 +00002046 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002047 flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2048 if ((flags & XValue) == 0)
2049 geometry.x=1;
2050 if ((flags & YValue) == 0)
2051 geometry.y=0;
2052 mogrify_image=LiquidRescaleImage(*image,geometry.width,
2053 geometry.height,1.0*geometry.x,1.0*geometry.y,exception);
2054 break;
2055 }
dirk3505d872015-11-01 23:30:09 +01002056 if (LocaleCompare("local-contrast",option+1) == 0)
2057 {
dirk3505d872015-11-01 23:30:09 +01002058 (void) SyncImageSettings(mogrify_info,*image,exception);
2059 flags=ParseGeometry(argv[i+1],&geometry_info);
dirk394f2112015-11-03 21:27:00 +01002060 if ((flags & RhoValue) == 0)
2061 geometry_info.rho=10;
dirk3505d872015-11-01 23:30:09 +01002062 if ((flags & SigmaValue) == 0)
dirk394f2112015-11-03 21:27:00 +01002063 geometry_info.sigma=12.5;
2064 if (((flags & RhoValue) == 0) || ((flags & PercentValue) != 0))
2065 geometry_info.rho*=MagickMax((*image)->columns,(*image)->rows)/
2066 100.0;
dirk3505d872015-11-01 23:30:09 +01002067 mogrify_image=LocalContrastImage(*image,geometry_info.rho,
2068 geometry_info.sigma,exception);
2069 break;
2070 }
anthonydf8ebac2011-04-27 09:03:19 +00002071 if (LocaleCompare("lowlight-color",option+1) == 0)
2072 {
2073 (void) SetImageArtifact(*image,option+1,argv[i+1]);
2074 break;
2075 }
2076 break;
2077 }
2078 case 'm':
2079 {
cristy7220ee42013-04-14 01:30:34 +00002080 if (LocaleCompare("magnify",option+1) == 0)
2081 {
2082 /*
2083 Double image size.
2084 */
2085 (void) SyncImageSettings(mogrify_info,*image,exception);
2086 mogrify_image=MagnifyImage(*image,exception);
2087 break;
2088 }
anthonydf8ebac2011-04-27 09:03:19 +00002089 if (LocaleCompare("map",option+1) == 0)
cristy3ed852e2009-09-05 21:47:34 +00002090 {
cristy3ed852e2009-09-05 21:47:34 +00002091 Image
anthonydf8ebac2011-04-27 09:03:19 +00002092 *remap_image;
cristy3ed852e2009-09-05 21:47:34 +00002093
anthonydf8ebac2011-04-27 09:03:19 +00002094 /*
2095 Transform image colors to match this set of colors.
2096 */
cristy6fccee12011-10-20 18:43:18 +00002097 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002098 if (*option == '+')
2099 break;
2100 remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
2101 if (remap_image == (Image *) NULL)
2102 break;
cristy018f07f2011-09-04 21:15:19 +00002103 (void) RemapImage(quantize_info,*image,remap_image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002104 remap_image=DestroyImage(remap_image);
2105 break;
2106 }
2107 if (LocaleCompare("mask",option+1) == 0)
2108 {
2109 Image
2110 *mask;
2111
cristy6fccee12011-10-20 18:43:18 +00002112 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002113 if (*option == '+')
2114 {
2115 /*
2116 Remove a mask.
2117 */
cristyacd0d4c2015-07-25 16:12:33 +00002118 (void) SetImageMask(*image,ReadPixelMask,(Image *) NULL,
2119 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002120 break;
2121 }
2122 /*
2123 Set the image mask.
2124 */
2125 mask=GetImageCache(mogrify_info,argv[i+1],exception);
2126 if (mask == (Image *) NULL)
2127 break;
cristyacd0d4c2015-07-25 16:12:33 +00002128 (void) SetImageMask(*image,ReadPixelMask,mask,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002129 mask=DestroyImage(mask);
anthonydf8ebac2011-04-27 09:03:19 +00002130 break;
2131 }
cristy52ad9e92013-02-08 23:23:29 +00002132 if (LocaleCompare("matte",option+1) == 0)
2133 {
2134 (void) SetImageAlphaChannel(*image,(*option == '-') ?
2135 SetAlphaChannel : DeactivateAlphaChannel,exception);
2136 break;
2137 }
cristy2fc10e52014-04-26 14:13:53 +00002138 if (LocaleCompare("mean-shift",option+1) == 0)
2139 {
2140 /*
2141 Detect edges in the image.
2142 */
2143 (void) SyncImageSettings(mogrify_info,*image,exception);
2144 flags=ParseGeometry(argv[i+1],&geometry_info);
2145 if ((flags & SigmaValue) == 0)
2146 geometry_info.sigma=geometry_info.rho;
cristy2fc10e52014-04-26 14:13:53 +00002147 if ((flags & XiValue) == 0)
cristy1309fc32014-04-26 18:48:37 +00002148 geometry_info.xi=0.10*QuantumRange;
2149 if ((flags & PercentValue) != 0)
2150 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
cristy2fc10e52014-04-26 14:13:53 +00002151 mogrify_image=MeanShiftImage(*image,(size_t) geometry_info.rho,
cristy1309fc32014-04-26 18:48:37 +00002152 (size_t) geometry_info.sigma,geometry_info.xi,exception);
cristy2fc10e52014-04-26 14:13:53 +00002153 break;
2154 }
cristy52ad9e92013-02-08 23:23:29 +00002155 if (LocaleCompare("median",option+1) == 0)
2156 {
2157 /*
2158 Median filter image.
2159 */
2160 (void) SyncImageSettings(mogrify_info,*image,exception);
2161 flags=ParseGeometry(argv[i+1],&geometry_info);
2162 if ((flags & SigmaValue) == 0)
2163 geometry_info.sigma=geometry_info.rho;
2164 mogrify_image=StatisticImage(*image,MedianStatistic,(size_t)
2165 geometry_info.rho,(size_t) geometry_info.sigma,exception);
2166 break;
2167 }
2168 if (LocaleCompare("mode",option+1) == 0)
2169 {
2170 /*
2171 Mode image.
2172 */
2173 (void) SyncImageSettings(mogrify_info,*image,exception);
2174 flags=ParseGeometry(argv[i+1],&geometry_info);
2175 if ((flags & SigmaValue) == 0)
2176 geometry_info.sigma=geometry_info.rho;
2177 mogrify_image=StatisticImage(*image,ModeStatistic,(size_t)
2178 geometry_info.rho,(size_t) geometry_info.sigma,exception);
2179 break;
2180 }
anthonydf8ebac2011-04-27 09:03:19 +00002181 if (LocaleCompare("modulate",option+1) == 0)
2182 {
cristy6fccee12011-10-20 18:43:18 +00002183 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy33bd5152011-08-24 01:42:24 +00002184 (void) ModulateImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00002185 break;
2186 }
cristybd4a3c22014-01-07 15:09:37 +00002187 if (LocaleCompare("moments",option+1) == 0)
2188 {
2189 if (*option == '+')
2190 {
2191 (void) DeleteImageArtifact(*image,"identify:moments");
2192 break;
2193 }
2194 (void) SetImageArtifact(*image,"identify:moments",argv[i+1]);
cristy47c09d12014-01-19 15:18:47 +00002195 (void) SetImageArtifact(*image,"verbose","true");
cristybd4a3c22014-01-07 15:09:37 +00002196 break;
2197 }
anthonydf8ebac2011-04-27 09:03:19 +00002198 if (LocaleCompare("monitor",option+1) == 0)
2199 {
2200 if (*option == '+')
2201 {
2202 (void) SetImageProgressMonitor(*image,
2203 (MagickProgressMonitor) NULL,(void *) NULL);
2204 break;
2205 }
2206 (void) SetImageProgressMonitor(*image,MonitorProgress,
2207 (void *) NULL);
2208 break;
2209 }
2210 if (LocaleCompare("monochrome",option+1) == 0)
2211 {
cristy6fccee12011-10-20 18:43:18 +00002212 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy018f07f2011-09-04 21:15:19 +00002213 (void) SetImageType(*image,BilevelType,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002214 break;
2215 }
2216 if (LocaleCompare("morphology",option+1) == 0)
2217 {
2218 char
cristy151b66d2015-04-15 10:50:31 +00002219 token[MagickPathExtent];
anthonydf8ebac2011-04-27 09:03:19 +00002220
2221 const char
2222 *p;
2223
2224 KernelInfo
2225 *kernel;
2226
2227 MorphologyMethod
2228 method;
2229
2230 ssize_t
2231 iterations;
2232
2233 /*
2234 Morphological Image Operation
2235 */
cristy6fccee12011-10-20 18:43:18 +00002236 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002237 p=argv[i+1];
2238 GetMagickToken(p,&p,token);
cristy28474bf2011-09-11 23:32:52 +00002239 method=(MorphologyMethod) ParseCommandOption(
2240 MagickMorphologyOptions,MagickFalse,token);
anthonydf8ebac2011-04-27 09:03:19 +00002241 iterations=1L;
2242 GetMagickToken(p,&p,token);
2243 if ((*p == ':') || (*p == ','))
2244 GetMagickToken(p,&p,token);
2245 if ((*p != '\0'))
2246 iterations=(ssize_t) StringToLong(p);
cristy2c57b742014-10-31 00:40:34 +00002247 kernel=AcquireKernelInfo(argv[i+2],exception);
anthonydf8ebac2011-04-27 09:03:19 +00002248 if (kernel == (KernelInfo *) NULL)
2249 {
2250 (void) ThrowMagickException(exception,GetMagickModule(),
2251 OptionError,"UnabletoParseKernel","morphology");
2252 status=MagickFalse;
2253 break;
2254 }
cristyf4ad9df2011-07-08 16:49:03 +00002255 mogrify_image=MorphologyImage(*image,method,iterations,kernel,
2256 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002257 kernel=DestroyKernelInfo(kernel);
2258 break;
2259 }
2260 if (LocaleCompare("motion-blur",option+1) == 0)
2261 {
2262 /*
2263 Motion blur image.
2264 */
cristy6fccee12011-10-20 18:43:18 +00002265 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002266 flags=ParseGeometry(argv[i+1],&geometry_info);
2267 if ((flags & SigmaValue) == 0)
2268 geometry_info.sigma=1.0;
cristyf4ad9df2011-07-08 16:49:03 +00002269 mogrify_image=MotionBlurImage(*image,geometry_info.rho,
cristyaa2c16c2012-03-25 22:21:35 +00002270 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002271 break;
2272 }
2273 break;
2274 }
2275 case 'n':
2276 {
2277 if (LocaleCompare("negate",option+1) == 0)
2278 {
cristy6fccee12011-10-20 18:43:18 +00002279 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy50fbc382011-07-07 02:19:17 +00002280 (void) NegateImage(*image,*option == '+' ? MagickTrue :
cristyb3e7c6c2011-07-24 01:43:55 +00002281 MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002282 break;
2283 }
2284 if (LocaleCompare("noise",option+1) == 0)
2285 {
cristy6fccee12011-10-20 18:43:18 +00002286 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002287 if (*option == '-')
2288 {
cristyf36cbcb2011-09-07 13:28:22 +00002289 flags=ParseGeometry(argv[i+1],&geometry_info);
2290 if ((flags & SigmaValue) == 0)
2291 geometry_info.sigma=geometry_info.rho;
cristyf4ad9df2011-07-08 16:49:03 +00002292 mogrify_image=StatisticImage(*image,NonpeakStatistic,(size_t)
cristyf36cbcb2011-09-07 13:28:22 +00002293 geometry_info.rho,(size_t) geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002294 }
2295 else
2296 {
2297 NoiseType
2298 noise;
2299
2300 noise=(NoiseType) ParseCommandOption(MagickNoiseOptions,
2301 MagickFalse,argv[i+1]);
cristy9ed1f812011-10-08 02:00:08 +00002302 mogrify_image=AddNoiseImage(*image,noise,attenuate,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002303 }
2304 break;
2305 }
2306 if (LocaleCompare("normalize",option+1) == 0)
2307 {
cristy6fccee12011-10-20 18:43:18 +00002308 (void) SyncImageSettings(mogrify_info,*image,exception);
cristye23ec9d2011-08-16 18:15:40 +00002309 (void) NormalizeImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002310 break;
2311 }
2312 break;
2313 }
2314 case 'o':
2315 {
2316 if (LocaleCompare("opaque",option+1) == 0)
2317 {
cristy4c08aed2011-07-01 19:47:50 +00002318 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00002319 target;
2320
cristy6fccee12011-10-20 18:43:18 +00002321 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy269c9412011-10-13 23:41:15 +00002322 (void) QueryColorCompliance(argv[i+1],AllCompliance,&target,
cristy9950d572011-10-01 18:22:35 +00002323 exception);
cristyd42d9952011-07-08 14:21:50 +00002324 (void) OpaquePaintImage(*image,&target,&fill,*option == '-' ?
cristy189e84c2011-08-27 18:08:53 +00002325 MagickFalse : MagickTrue,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002326 break;
2327 }
2328 if (LocaleCompare("ordered-dither",option+1) == 0)
2329 {
cristy6fccee12011-10-20 18:43:18 +00002330 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy13020672011-07-08 02:33:26 +00002331 (void) OrderedPosterizeImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00002332 break;
2333 }
2334 break;
2335 }
2336 case 'p':
2337 {
2338 if (LocaleCompare("paint",option+1) == 0)
2339 {
cristy6fccee12011-10-20 18:43:18 +00002340 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002341 (void) ParseGeometry(argv[i+1],&geometry_info);
cristy14973ba2011-08-27 23:48:07 +00002342 mogrify_image=OilPaintImage(*image,geometry_info.rho,
2343 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002344 break;
2345 }
cristy17ada022014-11-07 22:12:23 +00002346 if (LocaleCompare("perceptible",option+1) == 0)
2347 {
2348 /*
2349 Perceptible image.
2350 */
2351 (void) SyncImageSettings(mogrify_info,*image,exception);
2352 (void) PerceptibleImage(*image,StringToDouble(argv[i+1],
2353 (char **) NULL),exception);
2354 break;
2355 }
anthonydf8ebac2011-04-27 09:03:19 +00002356 if (LocaleCompare("pointsize",option+1) == 0)
2357 {
2358 if (*option == '+')
2359 (void) ParseGeometry("12",&geometry_info);
2360 else
2361 (void) ParseGeometry(argv[i+1],&geometry_info);
2362 draw_info->pointsize=geometry_info.rho;
2363 break;
2364 }
2365 if (LocaleCompare("polaroid",option+1) == 0)
2366 {
cristye9e3d382011-12-14 01:50:13 +00002367 const char
2368 *caption;
2369
anthonydf8ebac2011-04-27 09:03:19 +00002370 double
2371 angle;
2372
2373 RandomInfo
2374 *random_info;
2375
2376 /*
2377 Simulate a Polaroid picture.
2378 */
cristy6fccee12011-10-20 18:43:18 +00002379 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002380 random_info=AcquireRandomInfo();
2381 angle=22.5*(GetPseudoRandomValue(random_info)-0.5);
2382 random_info=DestroyRandomInfo(random_info);
2383 if (*option == '-')
2384 {
2385 SetGeometryInfo(&geometry_info);
2386 flags=ParseGeometry(argv[i+1],&geometry_info);
2387 angle=geometry_info.rho;
2388 }
cristye9e3d382011-12-14 01:50:13 +00002389 caption=GetImageProperty(*image,"caption",exception);
2390 mogrify_image=PolaroidImage(*image,draw_info,caption,angle,
cristy28474bf2011-09-11 23:32:52 +00002391 interpolate_method,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002392 break;
2393 }
2394 if (LocaleCompare("posterize",option+1) == 0)
2395 {
2396 /*
2397 Posterize image.
2398 */
cristy6fccee12011-10-20 18:43:18 +00002399 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002400 (void) PosterizeImage(*image,StringToUnsignedLong(argv[i+1]),
cristycbda6112012-05-27 20:57:16 +00002401 quantize_info->dither_method,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002402 break;
2403 }
2404 if (LocaleCompare("preview",option+1) == 0)
2405 {
2406 PreviewType
2407 preview_type;
2408
2409 /*
2410 Preview image.
2411 */
cristy6fccee12011-10-20 18:43:18 +00002412 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002413 if (*option == '+')
2414 preview_type=UndefinedPreview;
2415 else
cristy28474bf2011-09-11 23:32:52 +00002416 preview_type=(PreviewType) ParseCommandOption(
2417 MagickPreviewOptions,MagickFalse,argv[i+1]);
anthonydf8ebac2011-04-27 09:03:19 +00002418 mogrify_image=PreviewImage(*image,preview_type,exception);
2419 break;
2420 }
2421 if (LocaleCompare("profile",option+1) == 0)
2422 {
2423 const char
2424 *name;
2425
2426 const StringInfo
2427 *profile;
2428
2429 Image
2430 *profile_image;
2431
2432 ImageInfo
2433 *profile_info;
2434
cristy6fccee12011-10-20 18:43:18 +00002435 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002436 if (*option == '+')
2437 {
2438 /*
2439 Remove a profile from the image.
2440 */
2441 (void) ProfileImage(*image,argv[i+1],(const unsigned char *)
cristy092d71c2011-10-14 18:01:29 +00002442 NULL,0,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002443 break;
2444 }
2445 /*
2446 Associate a profile with the image.
2447 */
2448 profile_info=CloneImageInfo(mogrify_info);
2449 profile=GetImageProfile(*image,"iptc");
2450 if (profile != (StringInfo *) NULL)
2451 profile_info->profile=(void *) CloneStringInfo(profile);
2452 profile_image=GetImageCache(profile_info,argv[i+1],exception);
2453 profile_info=DestroyImageInfo(profile_info);
2454 if (profile_image == (Image *) NULL)
2455 {
2456 StringInfo
dirkb4979cb2015-11-22 10:01:27 +01002457 *file_data;
anthonydf8ebac2011-04-27 09:03:19 +00002458
2459 profile_info=CloneImageInfo(mogrify_info);
2460 (void) CopyMagickString(profile_info->filename,argv[i+1],
cristy151b66d2015-04-15 10:50:31 +00002461 MagickPathExtent);
dirkb4979cb2015-11-22 10:01:27 +01002462 file_data=FileToStringInfo(profile_info->filename,~0UL,
2463 exception);
2464 if (file_data != (StringInfo *) NULL)
anthonydf8ebac2011-04-27 09:03:19 +00002465 {
2466 (void) ProfileImage(*image,profile_info->magick,
dirkb4979cb2015-11-22 10:01:27 +01002467 GetStringInfoDatum(file_data),
2468 GetStringInfoLength(file_data),exception);
2469 file_data=DestroyStringInfo(file_data);
anthonydf8ebac2011-04-27 09:03:19 +00002470 }
2471 profile_info=DestroyImageInfo(profile_info);
2472 break;
2473 }
2474 ResetImageProfileIterator(profile_image);
2475 name=GetNextImageProfile(profile_image);
2476 while (name != (const char *) NULL)
2477 {
2478 profile=GetImageProfile(profile_image,name);
2479 if (profile != (StringInfo *) NULL)
2480 (void) ProfileImage(*image,name,GetStringInfoDatum(profile),
cristy3fac9ec2011-11-17 18:04:39 +00002481 (size_t) GetStringInfoLength(profile),exception);
anthonydf8ebac2011-04-27 09:03:19 +00002482 name=GetNextImageProfile(profile_image);
2483 }
2484 profile_image=DestroyImage(profile_image);
2485 break;
2486 }
2487 break;
2488 }
2489 case 'q':
2490 {
2491 if (LocaleCompare("quantize",option+1) == 0)
2492 {
2493 if (*option == '+')
2494 {
2495 quantize_info->colorspace=UndefinedColorspace;
2496 break;
2497 }
2498 quantize_info->colorspace=(ColorspaceType) ParseCommandOption(
2499 MagickColorspaceOptions,MagickFalse,argv[i+1]);
2500 break;
2501 }
2502 break;
2503 }
2504 case 'r':
2505 {
dirk6d612cf2014-03-13 21:17:23 +00002506 if (LocaleCompare("rotational-blur",option+1) == 0)
anthonydf8ebac2011-04-27 09:03:19 +00002507 {
2508 /*
dirk6d612cf2014-03-13 21:17:23 +00002509 Rotational blur image.
anthonydf8ebac2011-04-27 09:03:19 +00002510 */
cristy6fccee12011-10-20 18:43:18 +00002511 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy6435bd92011-09-10 02:10:07 +00002512 flags=ParseGeometry(argv[i+1],&geometry_info);
dirk6d612cf2014-03-13 21:17:23 +00002513 mogrify_image=RotationalBlurImage(*image,geometry_info.rho,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002514 break;
2515 }
2516 if (LocaleCompare("raise",option+1) == 0)
2517 {
2518 /*
2519 Surround image with a raise of solid color.
2520 */
2521 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002522 (void) RaiseImage(*image,&geometry,*option == '-' ? MagickTrue :
cristy6170ac32011-08-28 14:15:37 +00002523 MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002524 break;
2525 }
2526 if (LocaleCompare("random-threshold",option+1) == 0)
2527 {
2528 /*
2529 Threshold image.
2530 */
cristy6fccee12011-10-20 18:43:18 +00002531 (void) SyncImageSettings(mogrify_info,*image,exception);
cristyf4ad9df2011-07-08 16:49:03 +00002532 (void) RandomThresholdImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00002533 break;
2534 }
cristy327030c2015-07-25 18:05:50 +00002535 if (LocaleCompare("read-mask",option+1) == 0)
2536 {
2537 Image
2538 *mask;
2539
2540 (void) SyncImageSettings(mogrify_info,*image,exception);
2541 if (*option == '+')
2542 {
2543 /*
2544 Remove a mask.
2545 */
2546 (void) SetImageMask(*image,ReadPixelMask,(Image *) NULL,
2547 exception);
2548 break;
2549 }
2550 /*
2551 Set the image mask.
2552 */
2553 mask=GetImageCache(mogrify_info,argv[i+1],exception);
2554 if (mask == (Image *) NULL)
2555 break;
2556 (void) SetImageMask(*image,ReadPixelMask,mask,exception);
2557 mask=DestroyImage(mask);
2558 break;
2559 }
anthonydf8ebac2011-04-27 09:03:19 +00002560 if (LocaleCompare("region",option+1) == 0)
2561 {
cristy6fccee12011-10-20 18:43:18 +00002562 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002563 if (region_image != (Image *) NULL)
2564 {
2565 /*
2566 Composite region.
2567 */
cristy8a46d822012-08-28 23:32:39 +00002568 (void) CompositeImage(region_image,*image,
cristy7d6d3d82014-11-09 17:00:16 +00002569 region_image->alpha_trait != UndefinedPixelTrait ?
cristy8a46d822012-08-28 23:32:39 +00002570 CopyCompositeOp : OverCompositeOp,MagickTrue,
cristye941a752011-10-15 01:52:48 +00002571 region_geometry.x,region_geometry.y,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002572 *image=DestroyImage(*image);
2573 *image=region_image;
2574 region_image = (Image *) NULL;
2575 }
2576 if (*option == '+')
2577 break;
2578 /*
2579 Apply transformations to a selected region of the image.
2580 */
cristy3ed852e2009-09-05 21:47:34 +00002581 (void) ParseGravityGeometry(*image,argv[i+1],&region_geometry,
2582 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002583 mogrify_image=CropImage(*image,&region_geometry,exception);
2584 if (mogrify_image == (Image *) NULL)
2585 break;
2586 region_image=(*image);
2587 *image=mogrify_image;
2588 mogrify_image=(Image *) NULL;
2589 break;
cristy3ed852e2009-09-05 21:47:34 +00002590 }
anthonydf8ebac2011-04-27 09:03:19 +00002591 if (LocaleCompare("render",option+1) == 0)
2592 {
cristy6fccee12011-10-20 18:43:18 +00002593 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002594 draw_info->render=(*option == '+') ? MagickTrue : MagickFalse;
2595 break;
2596 }
2597 if (LocaleCompare("remap",option+1) == 0)
2598 {
2599 Image
2600 *remap_image;
cristy3ed852e2009-09-05 21:47:34 +00002601
anthonydf8ebac2011-04-27 09:03:19 +00002602 /*
2603 Transform image colors to match this set of colors.
2604 */
cristy6fccee12011-10-20 18:43:18 +00002605 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002606 if (*option == '+')
2607 break;
2608 remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
2609 if (remap_image == (Image *) NULL)
2610 break;
cristy018f07f2011-09-04 21:15:19 +00002611 (void) RemapImage(quantize_info,*image,remap_image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002612 remap_image=DestroyImage(remap_image);
2613 break;
2614 }
2615 if (LocaleCompare("repage",option+1) == 0)
2616 {
2617 if (*option == '+')
2618 {
2619 (void) ParseAbsoluteGeometry("0x0+0+0",&(*image)->page);
2620 break;
2621 }
2622 (void) ResetImagePage(*image,argv[i+1]);
anthonydf8ebac2011-04-27 09:03:19 +00002623 break;
2624 }
2625 if (LocaleCompare("resample",option+1) == 0)
2626 {
2627 /*
2628 Resample image.
2629 */
cristy6fccee12011-10-20 18:43:18 +00002630 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002631 flags=ParseGeometry(argv[i+1],&geometry_info);
2632 if ((flags & SigmaValue) == 0)
2633 geometry_info.sigma=geometry_info.rho;
2634 mogrify_image=ResampleImage(*image,geometry_info.rho,
cristyaa2c16c2012-03-25 22:21:35 +00002635 geometry_info.sigma,(*image)->filter,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002636 break;
2637 }
2638 if (LocaleCompare("resize",option+1) == 0)
2639 {
2640 /*
2641 Resize image.
2642 */
cristy6fccee12011-10-20 18:43:18 +00002643 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002644 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2645 mogrify_image=ResizeImage(*image,geometry.width,geometry.height,
cristyaa2c16c2012-03-25 22:21:35 +00002646 (*image)->filter,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002647 break;
2648 }
2649 if (LocaleCompare("roll",option+1) == 0)
2650 {
2651 /*
2652 Roll image.
2653 */
cristy6fccee12011-10-20 18:43:18 +00002654 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002655 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2656 mogrify_image=RollImage(*image,geometry.x,geometry.y,exception);
2657 break;
2658 }
2659 if (LocaleCompare("rotate",option+1) == 0)
2660 {
2661 char
dirkb4979cb2015-11-22 10:01:27 +01002662 *rotation;
anthonydf8ebac2011-04-27 09:03:19 +00002663
2664 /*
2665 Check for conditional image rotation.
2666 */
cristy6fccee12011-10-20 18:43:18 +00002667 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002668 if (strchr(argv[i+1],'>') != (char *) NULL)
2669 if ((*image)->columns <= (*image)->rows)
2670 break;
2671 if (strchr(argv[i+1],'<') != (char *) NULL)
2672 if ((*image)->columns >= (*image)->rows)
2673 break;
2674 /*
2675 Rotate image.
2676 */
dirkb4979cb2015-11-22 10:01:27 +01002677 rotation=ConstantString(argv[i+1]);
2678 (void) SubstituteString(&rotation,">","");
2679 (void) SubstituteString(&rotation,"<","");
2680 (void) ParseGeometry(rotation,&geometry_info);
2681 rotation=DestroyString(rotation);
anthonydf8ebac2011-04-27 09:03:19 +00002682 mogrify_image=RotateImage(*image,geometry_info.rho,exception);
2683 break;
2684 }
2685 break;
2686 }
2687 case 's':
2688 {
2689 if (LocaleCompare("sample",option+1) == 0)
2690 {
2691 /*
2692 Sample image with pixel replication.
2693 */
cristy6fccee12011-10-20 18:43:18 +00002694 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002695 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2696 mogrify_image=SampleImage(*image,geometry.width,geometry.height,
2697 exception);
2698 break;
2699 }
2700 if (LocaleCompare("scale",option+1) == 0)
2701 {
2702 /*
2703 Resize image.
2704 */
cristy6fccee12011-10-20 18:43:18 +00002705 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002706 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2707 mogrify_image=ScaleImage(*image,geometry.width,geometry.height,
2708 exception);
2709 break;
2710 }
2711 if (LocaleCompare("selective-blur",option+1) == 0)
2712 {
2713 /*
2714 Selectively blur pixels within a contrast threshold.
2715 */
cristy6fccee12011-10-20 18:43:18 +00002716 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002717 flags=ParseGeometry(argv[i+1],&geometry_info);
2718 if ((flags & PercentValue) != 0)
2719 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
cristyf4ad9df2011-07-08 16:49:03 +00002720 mogrify_image=SelectiveBlurImage(*image,geometry_info.rho,
cristyaa2c16c2012-03-25 22:21:35 +00002721 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002722 break;
2723 }
2724 if (LocaleCompare("separate",option+1) == 0)
2725 {
2726 /*
2727 Break channels into separate images.
anthonydf8ebac2011-04-27 09:03:19 +00002728 */
cristy6fccee12011-10-20 18:43:18 +00002729 (void) SyncImageSettings(mogrify_info,*image,exception);
cristydfdb19e2012-03-21 22:22:24 +00002730 mogrify_image=SeparateImages(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002731 break;
2732 }
2733 if (LocaleCompare("sepia-tone",option+1) == 0)
2734 {
2735 double
2736 threshold;
2737
2738 /*
2739 Sepia-tone image.
2740 */
cristy6fccee12011-10-20 18:43:18 +00002741 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy9b34e302011-11-05 02:15:45 +00002742 threshold=StringToDoubleInterval(argv[i+1],(double) QuantumRange+
2743 1.0);
anthonydf8ebac2011-04-27 09:03:19 +00002744 mogrify_image=SepiaToneImage(*image,threshold,exception);
2745 break;
2746 }
2747 if (LocaleCompare("segment",option+1) == 0)
2748 {
2749 /*
2750 Segment image.
2751 */
cristy6fccee12011-10-20 18:43:18 +00002752 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002753 flags=ParseGeometry(argv[i+1],&geometry_info);
2754 if ((flags & SigmaValue) == 0)
2755 geometry_info.sigma=1.0;
2756 (void) SegmentImage(*image,(*image)->colorspace,
cristy018f07f2011-09-04 21:15:19 +00002757 mogrify_info->verbose,geometry_info.rho,geometry_info.sigma,
2758 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002759 break;
2760 }
2761 if (LocaleCompare("set",option+1) == 0)
2762 {
2763 char
2764 *value;
2765
2766 /*
2767 Set image option.
2768 */
2769 if (*option == '+')
2770 {
2771 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2772 (void) DeleteImageRegistry(argv[i+1]+9);
2773 else
2774 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
2775 {
2776 (void) DeleteImageOption(mogrify_info,argv[i+1]+7);
2777 (void) DeleteImageArtifact(*image,argv[i+1]+7);
2778 }
2779 else
2780 (void) DeleteImageProperty(*image,argv[i+1]);
2781 break;
2782 }
cristy018f07f2011-09-04 21:15:19 +00002783 value=InterpretImageProperties(mogrify_info,*image,argv[i+2],
2784 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002785 if (value == (char *) NULL)
2786 break;
2787 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2788 (void) SetImageRegistry(StringRegistryType,argv[i+1]+9,value,
2789 exception);
2790 else
2791 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
2792 {
2793 (void) SetImageOption(image_info,argv[i+1]+7,value);
2794 (void) SetImageOption(mogrify_info,argv[i+1]+7,value);
2795 (void) SetImageArtifact(*image,argv[i+1]+7,value);
2796 }
2797 else
cristyd15e6592011-10-15 00:13:06 +00002798 (void) SetImageProperty(*image,argv[i+1],value,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002799 value=DestroyString(value);
2800 break;
2801 }
2802 if (LocaleCompare("shade",option+1) == 0)
2803 {
2804 /*
2805 Shade image.
2806 */
cristy6fccee12011-10-20 18:43:18 +00002807 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002808 flags=ParseGeometry(argv[i+1],&geometry_info);
2809 if ((flags & SigmaValue) == 0)
2810 geometry_info.sigma=1.0;
2811 mogrify_image=ShadeImage(*image,(*option == '-') ? MagickTrue :
2812 MagickFalse,geometry_info.rho,geometry_info.sigma,exception);
2813 break;
2814 }
2815 if (LocaleCompare("shadow",option+1) == 0)
2816 {
2817 /*
2818 Shadow image.
2819 */
cristy6fccee12011-10-20 18:43:18 +00002820 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002821 flags=ParseGeometry(argv[i+1],&geometry_info);
2822 if ((flags & SigmaValue) == 0)
2823 geometry_info.sigma=1.0;
2824 if ((flags & XiValue) == 0)
2825 geometry_info.xi=4.0;
2826 if ((flags & PsiValue) == 0)
2827 geometry_info.psi=4.0;
2828 mogrify_image=ShadowImage(*image,geometry_info.rho,
cristyaa2c16c2012-03-25 22:21:35 +00002829 geometry_info.sigma,(ssize_t) ceil(geometry_info.xi-0.5),
2830 (ssize_t) ceil(geometry_info.psi-0.5),exception);
anthonydf8ebac2011-04-27 09:03:19 +00002831 break;
2832 }
2833 if (LocaleCompare("sharpen",option+1) == 0)
2834 {
2835 /*
2836 Sharpen image.
2837 */
cristy6fccee12011-10-20 18:43:18 +00002838 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002839 flags=ParseGeometry(argv[i+1],&geometry_info);
2840 if ((flags & SigmaValue) == 0)
2841 geometry_info.sigma=1.0;
cristy05c0c9a2011-09-05 23:16:13 +00002842 if ((flags & XiValue) == 0)
2843 geometry_info.xi=0.0;
cristyf4ad9df2011-07-08 16:49:03 +00002844 mogrify_image=SharpenImage(*image,geometry_info.rho,
cristyaa2c16c2012-03-25 22:21:35 +00002845 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002846 break;
2847 }
2848 if (LocaleCompare("shave",option+1) == 0)
2849 {
2850 /*
2851 Shave the image edges.
2852 */
cristy6fccee12011-10-20 18:43:18 +00002853 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002854 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2855 mogrify_image=ShaveImage(*image,&geometry,exception);
2856 break;
2857 }
2858 if (LocaleCompare("shear",option+1) == 0)
2859 {
2860 /*
2861 Shear image.
2862 */
cristy6fccee12011-10-20 18:43:18 +00002863 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002864 flags=ParseGeometry(argv[i+1],&geometry_info);
2865 if ((flags & SigmaValue) == 0)
2866 geometry_info.sigma=geometry_info.rho;
2867 mogrify_image=ShearImage(*image,geometry_info.rho,
2868 geometry_info.sigma,exception);
2869 break;
2870 }
2871 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
2872 {
2873 /*
2874 Sigmoidal non-linearity contrast control.
2875 */
cristy6fccee12011-10-20 18:43:18 +00002876 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002877 flags=ParseGeometry(argv[i+1],&geometry_info);
2878 if ((flags & SigmaValue) == 0)
2879 geometry_info.sigma=(double) QuantumRange/2.0;
2880 if ((flags & PercentValue) != 0)
2881 geometry_info.sigma=(double) QuantumRange*geometry_info.sigma/
2882 100.0;
cristy9ee60942011-07-06 14:54:38 +00002883 (void) SigmoidalContrastImage(*image,(*option == '-') ?
cristy33bd5152011-08-24 01:42:24 +00002884 MagickTrue : MagickFalse,geometry_info.rho,geometry_info.sigma,
2885 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002886 break;
2887 }
2888 if (LocaleCompare("sketch",option+1) == 0)
2889 {
2890 /*
2891 Sketch image.
2892 */
cristy6fccee12011-10-20 18:43:18 +00002893 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002894 flags=ParseGeometry(argv[i+1],&geometry_info);
2895 if ((flags & SigmaValue) == 0)
2896 geometry_info.sigma=1.0;
2897 mogrify_image=SketchImage(*image,geometry_info.rho,
cristyaa2c16c2012-03-25 22:21:35 +00002898 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002899 break;
2900 }
2901 if (LocaleCompare("solarize",option+1) == 0)
2902 {
2903 double
2904 threshold;
2905
cristy6fccee12011-10-20 18:43:18 +00002906 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy9b34e302011-11-05 02:15:45 +00002907 threshold=StringToDoubleInterval(argv[i+1],(double) QuantumRange+
2908 1.0);
cristy5cbc0162011-08-29 00:36:28 +00002909 (void) SolarizeImage(*image,threshold,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002910 break;
2911 }
2912 if (LocaleCompare("sparse-color",option+1) == 0)
2913 {
2914 SparseColorMethod
2915 method;
2916
2917 char
2918 *arguments;
2919
2920 /*
2921 Sparse Color Interpolated Gradient
2922 */
cristy6fccee12011-10-20 18:43:18 +00002923 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002924 method=(SparseColorMethod) ParseCommandOption(
2925 MagickSparseColorOptions,MagickFalse,argv[i+1]);
cristy018f07f2011-09-04 21:15:19 +00002926 arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2],
2927 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002928 if (arguments == (char *) NULL)
2929 break;
cristy3884f692011-07-08 18:00:18 +00002930 mogrify_image=SparseColorOption(*image,method,arguments,
anthonydf8ebac2011-04-27 09:03:19 +00002931 option[0] == '+' ? MagickTrue : MagickFalse,exception);
2932 arguments=DestroyString(arguments);
2933 break;
2934 }
2935 if (LocaleCompare("splice",option+1) == 0)
2936 {
2937 /*
2938 Splice a solid color into the image.
2939 */
cristy6fccee12011-10-20 18:43:18 +00002940 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002941 (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
2942 mogrify_image=SpliceImage(*image,&geometry,exception);
2943 break;
2944 }
2945 if (LocaleCompare("spread",option+1) == 0)
2946 {
2947 /*
2948 Spread an image.
2949 */
cristy6fccee12011-10-20 18:43:18 +00002950 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002951 (void) ParseGeometry(argv[i+1],&geometry_info);
Cristye3319c12015-08-24 07:11:48 -04002952 mogrify_image=SpreadImage(*image,interpolate_method,
2953 geometry_info.rho,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002954 break;
2955 }
2956 if (LocaleCompare("statistic",option+1) == 0)
2957 {
2958 StatisticType
2959 type;
2960
cristy6fccee12011-10-20 18:43:18 +00002961 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002962 type=(StatisticType) ParseCommandOption(MagickStatisticOptions,
2963 MagickFalse,argv[i+1]);
2964 (void) ParseGeometry(argv[i+2],&geometry_info);
cristyf4ad9df2011-07-08 16:49:03 +00002965 mogrify_image=StatisticImage(*image,type,(size_t) geometry_info.rho,
2966 (size_t) geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002967 break;
2968 }
2969 if (LocaleCompare("stretch",option+1) == 0)
2970 {
2971 if (*option == '+')
2972 {
2973 draw_info->stretch=UndefinedStretch;
2974 break;
2975 }
2976 draw_info->stretch=(StretchType) ParseCommandOption(
2977 MagickStretchOptions,MagickFalse,argv[i+1]);
2978 break;
2979 }
2980 if (LocaleCompare("strip",option+1) == 0)
2981 {
2982 /*
2983 Strip image of profiles and comments.
2984 */
cristy6fccee12011-10-20 18:43:18 +00002985 (void) SyncImageSettings(mogrify_info,*image,exception);
cristye941a752011-10-15 01:52:48 +00002986 (void) StripImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002987 break;
2988 }
2989 if (LocaleCompare("stroke",option+1) == 0)
2990 {
2991 ExceptionInfo
2992 *sans;
2993
anthonyfd706f92012-01-19 04:22:02 +00002994 PixelInfo
2995 color;
2996
anthonydf8ebac2011-04-27 09:03:19 +00002997 if (*option == '+')
2998 {
cristy9950d572011-10-01 18:22:35 +00002999 (void) QueryColorCompliance("none",AllCompliance,
3000 &draw_info->stroke,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003001 if (draw_info->stroke_pattern != (Image *) NULL)
3002 draw_info->stroke_pattern=DestroyImage(
3003 draw_info->stroke_pattern);
3004 break;
3005 }
3006 sans=AcquireExceptionInfo();
anthonyfd706f92012-01-19 04:22:02 +00003007 status=QueryColorCompliance(argv[i+1],AllCompliance,&color,sans);
anthonydf8ebac2011-04-27 09:03:19 +00003008 sans=DestroyExceptionInfo(sans);
3009 if (status == MagickFalse)
3010 draw_info->stroke_pattern=GetImageCache(mogrify_info,argv[i+1],
3011 exception);
anthonyfd706f92012-01-19 04:22:02 +00003012 else
3013 draw_info->stroke=color;
anthonydf8ebac2011-04-27 09:03:19 +00003014 break;
3015 }
3016 if (LocaleCompare("strokewidth",option+1) == 0)
3017 {
cristy9b34e302011-11-05 02:15:45 +00003018 draw_info->stroke_width=StringToDouble(argv[i+1],(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00003019 break;
3020 }
3021 if (LocaleCompare("style",option+1) == 0)
3022 {
3023 if (*option == '+')
3024 {
3025 draw_info->style=UndefinedStyle;
3026 break;
3027 }
3028 draw_info->style=(StyleType) ParseCommandOption(MagickStyleOptions,
3029 MagickFalse,argv[i+1]);
3030 break;
3031 }
3032 if (LocaleCompare("swirl",option+1) == 0)
3033 {
3034 /*
3035 Swirl image.
3036 */
cristy6fccee12011-10-20 18:43:18 +00003037 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003038 (void) ParseGeometry(argv[i+1],&geometry_info);
cristy76f512e2011-09-12 01:26:56 +00003039 mogrify_image=SwirlImage(*image,geometry_info.rho,
3040 interpolate_method,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003041 break;
3042 }
3043 break;
3044 }
3045 case 't':
3046 {
3047 if (LocaleCompare("threshold",option+1) == 0)
3048 {
3049 double
3050 threshold;
3051
3052 /*
3053 Threshold image.
3054 */
cristy6fccee12011-10-20 18:43:18 +00003055 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003056 if (*option == '+')
anthony247a86d2011-05-03 13:18:18 +00003057 threshold=(double) QuantumRange/2;
anthonydf8ebac2011-04-27 09:03:19 +00003058 else
cristy9b34e302011-11-05 02:15:45 +00003059 threshold=StringToDoubleInterval(argv[i+1],(double) QuantumRange+
3060 1.0);
cristye941a752011-10-15 01:52:48 +00003061 (void) BilevelImage(*image,threshold,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003062 break;
3063 }
3064 if (LocaleCompare("thumbnail",option+1) == 0)
3065 {
3066 /*
3067 Thumbnail image.
3068 */
cristy6fccee12011-10-20 18:43:18 +00003069 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003070 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
3071 mogrify_image=ThumbnailImage(*image,geometry.width,geometry.height,
3072 exception);
3073 break;
3074 }
3075 if (LocaleCompare("tile",option+1) == 0)
3076 {
3077 if (*option == '+')
3078 {
3079 if (draw_info->fill_pattern != (Image *) NULL)
3080 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
3081 break;
3082 }
3083 draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1],
3084 exception);
3085 break;
3086 }
3087 if (LocaleCompare("tint",option+1) == 0)
3088 {
3089 /*
3090 Tint the image.
3091 */
cristy6fccee12011-10-20 18:43:18 +00003092 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy28474bf2011-09-11 23:32:52 +00003093 mogrify_image=TintImage(*image,argv[i+1],&fill,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003094 break;
3095 }
3096 if (LocaleCompare("transform",option+1) == 0)
3097 {
3098 /*
3099 Affine transform image.
3100 */
cristy6fccee12011-10-20 18:43:18 +00003101 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003102 mogrify_image=AffineTransformImage(*image,&draw_info->affine,
3103 exception);
3104 break;
3105 }
3106 if (LocaleCompare("transparent",option+1) == 0)
3107 {
cristy4c08aed2011-07-01 19:47:50 +00003108 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00003109 target;
3110
cristy6fccee12011-10-20 18:43:18 +00003111 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy269c9412011-10-13 23:41:15 +00003112 (void) QueryColorCompliance(argv[i+1],AllCompliance,&target,
cristy9950d572011-10-01 18:22:35 +00003113 exception);
anthonydf8ebac2011-04-27 09:03:19 +00003114 (void) TransparentPaintImage(*image,&target,(Quantum)
cristy189e84c2011-08-27 18:08:53 +00003115 TransparentAlpha,*option == '-' ? MagickFalse : MagickTrue,
cristy82d7af52011-10-16 16:26:41 +00003116 exception);
anthonydf8ebac2011-04-27 09:03:19 +00003117 break;
3118 }
3119 if (LocaleCompare("transpose",option+1) == 0)
3120 {
3121 /*
3122 Transpose image scanlines.
3123 */
cristy6fccee12011-10-20 18:43:18 +00003124 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003125 mogrify_image=TransposeImage(*image,exception);
3126 break;
3127 }
3128 if (LocaleCompare("transverse",option+1) == 0)
3129 {
3130 /*
3131 Transverse image scanlines.
3132 */
cristy6fccee12011-10-20 18:43:18 +00003133 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003134 mogrify_image=TransverseImage(*image,exception);
3135 break;
3136 }
3137 if (LocaleCompare("treedepth",option+1) == 0)
3138 {
3139 quantize_info->tree_depth=StringToUnsignedLong(argv[i+1]);
3140 break;
3141 }
3142 if (LocaleCompare("trim",option+1) == 0)
3143 {
3144 /*
3145 Trim image.
3146 */
cristy6fccee12011-10-20 18:43:18 +00003147 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003148 mogrify_image=TrimImage(*image,exception);
3149 break;
3150 }
3151 if (LocaleCompare("type",option+1) == 0)
3152 {
3153 ImageType
3154 type;
3155
cristy6fccee12011-10-20 18:43:18 +00003156 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003157 if (*option == '+')
3158 type=UndefinedType;
3159 else
3160 type=(ImageType) ParseCommandOption(MagickTypeOptions,MagickFalse,
3161 argv[i+1]);
3162 (*image)->type=UndefinedType;
cristy018f07f2011-09-04 21:15:19 +00003163 (void) SetImageType(*image,type,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003164 break;
3165 }
3166 break;
3167 }
3168 case 'u':
3169 {
3170 if (LocaleCompare("undercolor",option+1) == 0)
3171 {
cristy9950d572011-10-01 18:22:35 +00003172 (void) QueryColorCompliance(argv[i+1],AllCompliance,
3173 &draw_info->undercolor,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003174 break;
3175 }
3176 if (LocaleCompare("unique",option+1) == 0)
3177 {
3178 if (*option == '+')
3179 {
3180 (void) DeleteImageArtifact(*image,"identify:unique-colors");
3181 break;
3182 }
3183 (void) SetImageArtifact(*image,"identify:unique-colors","true");
3184 (void) SetImageArtifact(*image,"verbose","true");
3185 break;
3186 }
3187 if (LocaleCompare("unique-colors",option+1) == 0)
3188 {
3189 /*
3190 Unique image colors.
3191 */
cristy6fccee12011-10-20 18:43:18 +00003192 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003193 mogrify_image=UniqueImageColors(*image,exception);
3194 break;
3195 }
3196 if (LocaleCompare("unsharp",option+1) == 0)
3197 {
3198 /*
3199 Unsharp mask image.
3200 */
cristy6fccee12011-10-20 18:43:18 +00003201 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003202 flags=ParseGeometry(argv[i+1],&geometry_info);
3203 if ((flags & SigmaValue) == 0)
3204 geometry_info.sigma=1.0;
3205 if ((flags & XiValue) == 0)
3206 geometry_info.xi=1.0;
3207 if ((flags & PsiValue) == 0)
3208 geometry_info.psi=0.05;
cristyf4ad9df2011-07-08 16:49:03 +00003209 mogrify_image=UnsharpMaskImage(*image,geometry_info.rho,
cristy3afd4012013-03-25 11:30:44 +00003210 geometry_info.sigma,geometry_info.xi,geometry_info.psi,
3211 exception);
anthonydf8ebac2011-04-27 09:03:19 +00003212 break;
3213 }
3214 break;
3215 }
3216 case 'v':
3217 {
3218 if (LocaleCompare("verbose",option+1) == 0)
3219 {
3220 (void) SetImageArtifact(*image,option+1,
3221 *option == '+' ? "false" : "true");
3222 break;
3223 }
3224 if (LocaleCompare("vignette",option+1) == 0)
3225 {
3226 /*
3227 Vignette image.
3228 */
cristy6fccee12011-10-20 18:43:18 +00003229 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003230 flags=ParseGeometry(argv[i+1],&geometry_info);
3231 if ((flags & SigmaValue) == 0)
3232 geometry_info.sigma=1.0;
3233 if ((flags & XiValue) == 0)
3234 geometry_info.xi=0.1*(*image)->columns;
3235 if ((flags & PsiValue) == 0)
3236 geometry_info.psi=0.1*(*image)->rows;
cristy8e2392e2013-11-11 17:58:38 +00003237 if ((flags & PercentValue) != 0)
3238 {
cristy531c9602013-11-11 19:16:05 +00003239 geometry_info.xi*=(double) (*image)->columns/100.0;
3240 geometry_info.psi*=(double) (*image)->rows/100.0;
cristy8e2392e2013-11-11 17:58:38 +00003241 }
anthonydf8ebac2011-04-27 09:03:19 +00003242 mogrify_image=VignetteImage(*image,geometry_info.rho,
cristyaa2c16c2012-03-25 22:21:35 +00003243 geometry_info.sigma,(ssize_t) ceil(geometry_info.xi-0.5),
3244 (ssize_t) ceil(geometry_info.psi-0.5),exception);
anthonydf8ebac2011-04-27 09:03:19 +00003245 break;
3246 }
3247 if (LocaleCompare("virtual-pixel",option+1) == 0)
3248 {
3249 if (*option == '+')
3250 {
3251 (void) SetImageVirtualPixelMethod(*image,
cristy387430f2012-02-07 13:09:46 +00003252 UndefinedVirtualPixelMethod,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003253 break;
3254 }
3255 (void) SetImageVirtualPixelMethod(*image,(VirtualPixelMethod)
3256 ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
cristy387430f2012-02-07 13:09:46 +00003257 argv[i+1]),exception);
anthonydf8ebac2011-04-27 09:03:19 +00003258 break;
3259 }
3260 break;
3261 }
3262 case 'w':
3263 {
3264 if (LocaleCompare("wave",option+1) == 0)
3265 {
3266 /*
3267 Wave image.
3268 */
cristy6fccee12011-10-20 18:43:18 +00003269 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003270 flags=ParseGeometry(argv[i+1],&geometry_info);
3271 if ((flags & SigmaValue) == 0)
3272 geometry_info.sigma=1.0;
3273 mogrify_image=WaveImage(*image,geometry_info.rho,
cristy28474bf2011-09-11 23:32:52 +00003274 geometry_info.sigma,interpolate_method,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003275 break;
3276 }
3277 if (LocaleCompare("weight",option+1) == 0)
3278 {
dirk5acf7022015-07-30 18:37:03 +00003279 ssize_t
3280 weight;
3281
3282 weight=ParseCommandOption(MagickWeightOptions,MagickFalse,
3283 argv[i+1]);
3284 if (weight == -1)
3285 weight=StringToUnsignedLong(argv[i+1]);
3286 draw_info->weight=(size_t) weight;
anthonydf8ebac2011-04-27 09:03:19 +00003287 break;
3288 }
3289 if (LocaleCompare("white-threshold",option+1) == 0)
3290 {
3291 /*
3292 White threshold image.
3293 */
cristy6fccee12011-10-20 18:43:18 +00003294 (void) SyncImageSettings(mogrify_info,*image,exception);
cristyf4ad9df2011-07-08 16:49:03 +00003295 (void) WhiteThresholdImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00003296 break;
3297 }
cristy327030c2015-07-25 18:05:50 +00003298 if (LocaleCompare("write-mask",option+1) == 0)
3299 {
3300 Image
3301 *mask;
3302
3303 (void) SyncImageSettings(mogrify_info,*image,exception);
3304 if (*option == '+')
3305 {
3306 /*
3307 Remove a mask.
3308 */
3309 (void) SetImageMask(*image,WritePixelMask,(Image *) NULL,
3310 exception);
3311 break;
3312 }
3313 /*
3314 Set the image mask.
3315 */
3316 mask=GetImageCache(mogrify_info,argv[i+1],exception);
3317 if (mask == (Image *) NULL)
3318 break;
3319 (void) SetImageMask(*image,WritePixelMask,mask,exception);
3320 mask=DestroyImage(mask);
3321 break;
3322 }
anthonydf8ebac2011-04-27 09:03:19 +00003323 break;
3324 }
3325 default:
3326 break;
3327 }
3328 /*
3329 Replace current image with any image that was generated
3330 */
3331 if (mogrify_image != (Image *) NULL)
3332 ReplaceImageInListReturnLast(image,mogrify_image);
cristy3ed852e2009-09-05 21:47:34 +00003333 i+=count;
3334 }
3335 if (region_image != (Image *) NULL)
3336 {
anthonydf8ebac2011-04-27 09:03:19 +00003337 /*
3338 Composite transformed region onto image.
3339 */
cristy6fccee12011-10-20 18:43:18 +00003340 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy8a46d822012-08-28 23:32:39 +00003341 (void) CompositeImage(region_image,*image,
cristy7d6d3d82014-11-09 17:00:16 +00003342 region_image->alpha_trait != UndefinedPixelTrait ? CopyCompositeOp :
cristy8a46d822012-08-28 23:32:39 +00003343 OverCompositeOp,MagickTrue,region_geometry.x,region_geometry.y,
3344 exception);
cristy3ed852e2009-09-05 21:47:34 +00003345 *image=DestroyImage(*image);
3346 *image=region_image;
anthonye9c27192011-03-27 08:07:06 +00003347 region_image = (Image *) NULL;
cristy3ed852e2009-09-05 21:47:34 +00003348 }
3349 /*
3350 Free resources.
3351 */
anthonydf8ebac2011-04-27 09:03:19 +00003352 quantize_info=DestroyQuantizeInfo(quantize_info);
3353 draw_info=DestroyDrawInfo(draw_info);
cristy6b3da3a2010-06-20 02:21:46 +00003354 mogrify_info=DestroyImageInfo(mogrify_info);
cristy39374372014-10-19 22:28:54 +00003355 status=(MagickStatusType) (exception->severity < ErrorException ? 1 : 0);
cristy72988482011-03-29 16:34:38 +00003356 return(status == 0 ? MagickFalse : MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00003357}
3358
3359/*
3360%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3361% %
3362% %
3363% %
cristy5063d812010-10-19 16:28:10 +00003364+ 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 +00003365% %
3366% %
3367% %
3368%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3369%
3370% MogrifyImageCommand() transforms an image or a sequence of images. These
3371% transforms include image scaling, image rotation, color reduction, and
3372% others. The transmogrified image overwrites the original image.
3373%
3374% The format of the MogrifyImageCommand method is:
3375%
3376% MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,int argc,
3377% const char **argv,char **metadata,ExceptionInfo *exception)
3378%
3379% A description of each parameter follows:
3380%
3381% o image_info: the image info.
3382%
3383% o argc: the number of elements in the argument vector.
3384%
3385% o argv: A text array containing the command line arguments.
3386%
3387% o metadata: any metadata is returned here.
3388%
3389% o exception: return any errors or warnings in this structure.
3390%
3391*/
3392
3393static MagickBooleanType MogrifyUsage(void)
3394{
3395 static const char
cristy87c02f42012-02-24 00:19:10 +00003396 *channel_operators[]=
3397 {
cristy5f257b22012-03-07 00:27:29 +00003398 "-channel-fx expression",
cristyd04e7bf2012-03-03 19:19:12 +00003399 " exchange, extract, or transfer one or more image channels",
cristydfdb19e2012-03-21 22:22:24 +00003400 "-separate separate an image channel into a grayscale image",
cristy87c02f42012-02-24 00:19:10 +00003401 (char *) NULL
3402 },
cristy3ed852e2009-09-05 21:47:34 +00003403 *miscellaneous[]=
3404 {
3405 "-debug events display copious debugging information",
cristy93053632013-01-06 23:55:19 +00003406 "-distribute-cache port",
cristyd79e2362013-01-06 23:01:40 +00003407 " distributed pixel cache spanning one or more servers",
cristy3ed852e2009-09-05 21:47:34 +00003408 "-help print program options",
3409 "-list type print a list of supported option arguments",
3410 "-log format format of debugging information",
3411 "-version print version information",
3412 (char *) NULL
3413 },
3414 *operators[]=
3415 {
3416 "-adaptive-blur geometry",
3417 " adaptively blur pixels; decrease effect near edges",
3418 "-adaptive-resize geometry",
3419 " adaptively resize image using 'mesh' interpolation",
3420 "-adaptive-sharpen geometry",
3421 " adaptively sharpen pixels; increase effect near edges",
3422 "-alpha option on, activate, off, deactivate, set, opaque, copy",
3423 " transparent, extract, background, or shape",
3424 "-annotate geometry text",
3425 " annotate the image with text",
3426 "-auto-gamma automagically adjust gamma level of image",
3427 "-auto-level automagically adjust color levels of image",
3428 "-auto-orient automagically orient (rotate) image",
3429 "-bench iterations measure performance",
3430 "-black-threshold value",
3431 " force all pixels below the threshold into black",
3432 "-blue-shift simulate a scene at nighttime in the moonlight",
3433 "-blur geometry reduce image noise and reduce detail levels",
3434 "-border geometry surround image with a border of color",
3435 "-bordercolor color border color",
cristya28d6b82010-01-11 20:03:47 +00003436 "-brightness-contrast geometry",
3437 " improve brightness / contrast of the image",
cristy4ceadb82014-03-29 15:30:43 +00003438 "-canny geometry detect edges in the image",
cristy3ed852e2009-09-05 21:47:34 +00003439 "-cdl filename color correct with a color decision list",
cristy17ada022014-11-07 22:12:23 +00003440 "-channel mask set the image channel mask",
cristy05c0c9a2011-09-05 23:16:13 +00003441 "-charcoal geometry simulate a charcoal drawing",
cristy3ed852e2009-09-05 21:47:34 +00003442 "-chop geometry remove pixels from the image interior",
cristy1df20892012-11-04 01:06:40 +00003443 "-clamp keep pixel values in range (0-QuantumRange)",
cristycee97112010-05-28 00:44:52 +00003444 "-clip clip along the first path from the 8BIM profile",
cristy3ed852e2009-09-05 21:47:34 +00003445 "-clip-mask filename associate a clip mask with the image",
cristycee97112010-05-28 00:44:52 +00003446 "-clip-path id clip along a named path from the 8BIM profile",
cristy3ed852e2009-09-05 21:47:34 +00003447 "-colorize value colorize the image with the fill color",
cristye6365592010-04-02 17:31:23 +00003448 "-color-matrix matrix apply color correction to the image",
cristybb93b802014-10-25 13:32:45 +00003449 "-connected-components connectivity",
3450 " connected-components uniquely labeled",
cristy3ed852e2009-09-05 21:47:34 +00003451 "-contrast enhance or reduce the image contrast",
3452 "-contrast-stretch geometry",
anthonye5b39652012-04-21 05:37:29 +00003453 " improve contrast by 'stretching' the intensity range",
cristy3ed852e2009-09-05 21:47:34 +00003454 "-convolve coefficients",
3455 " apply a convolution kernel to the image",
3456 "-cycle amount cycle the image colormap",
3457 "-decipher filename convert cipher pixels to plain pixels",
3458 "-deskew threshold straighten an image",
3459 "-despeckle reduce the speckles within an image",
3460 "-distort method args",
3461 " distort images according to given method ad args",
3462 "-draw string annotate the image with a graphic primitive",
3463 "-edge radius apply a filter to detect edges in the image",
3464 "-encipher filename convert plain pixels to cipher pixels",
3465 "-emboss radius emboss an image",
3466 "-enhance apply a digital filter to enhance a noisy image",
3467 "-equalize perform histogram equalization to an image",
3468 "-evaluate operator value",
cristyd18ae7c2010-03-07 17:39:52 +00003469 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003470 "-extent geometry set the image size",
3471 "-extract geometry extract area from image",
3472 "-fft implements the discrete Fourier transform (DFT)",
3473 "-flip flip image vertically",
3474 "-floodfill geometry color",
3475 " floodfill the image with color",
3476 "-flop flop image horizontally",
3477 "-frame geometry surround image with an ornamental border",
cristyc2b730e2009-11-24 14:32:09 +00003478 "-function name parameters",
cristy3ed852e2009-09-05 21:47:34 +00003479 " apply function over image values",
3480 "-gamma value level of gamma correction",
3481 "-gaussian-blur geometry",
3482 " reduce image noise and reduce detail levels",
cristy901f09d2009-10-16 22:56:10 +00003483 "-geometry geometry preferred size or location of the image",
cristybc008152013-03-28 16:52:59 +00003484 "-grayscale method convert image to grayscale",
cristy2fc10e52014-04-26 14:13:53 +00003485 "-hough-lines geometry",
3486 " identify lines in the image",
cristy3ed852e2009-09-05 21:47:34 +00003487 "-identify identify the format and characteristics of the image",
3488 "-ift implements the inverse discrete Fourier transform (DFT)",
3489 "-implode amount implode image pixels about the center",
anthonyfd706f92012-01-19 04:22:02 +00003490 "-interpolative-resize geometry",
3491 " resize image using interpolation",
cristyd1bc64d2014-09-30 09:52:12 +00003492 "-kuwahara geometry edge preserving noise reduction filter",
cristy3ed852e2009-09-05 21:47:34 +00003493 "-lat geometry local adaptive thresholding",
cristy3ed852e2009-09-05 21:47:34 +00003494 "-level value adjust the level of image contrast",
3495 "-level-colors color,color",
cristyee0f8d72009-09-19 00:58:29 +00003496 " level image with the given colors",
cristy3ed852e2009-09-05 21:47:34 +00003497 "-linear-stretch geometry",
anthonye5b39652012-04-21 05:37:29 +00003498 " improve contrast by 'stretching with saturation'",
cristy3ed852e2009-09-05 21:47:34 +00003499 "-liquid-rescale geometry",
3500 " rescale image with seam-carving",
dirk3505d872015-11-01 23:30:09 +01003501 "-local-contrast geometry",
3502 " enhance local contrast",
cristye9252c22013-07-30 15:43:21 +00003503 "-magnify double the size of the image with pixel art scaling",
cristy2fc10e52014-04-26 14:13:53 +00003504 "-mean-shift geometry delineate arbitrarily shaped clusters in the image",
cristy52ad9e92013-02-08 23:23:29 +00003505 "-median geometry apply a median filter to the image",
cristyb4671fc2012-11-04 15:02:10 +00003506 "-mode geometry make each pixel the 'predominant color' of the",
3507 " neighborhood",
cristy3ed852e2009-09-05 21:47:34 +00003508 "-modulate value vary the brightness, saturation, and hue",
3509 "-monochrome transform image to black and white",
cristy7c1b9fd2010-02-02 14:36:00 +00003510 "-morphology method kernel",
anthony29188a82010-01-22 10:12:34 +00003511 " apply a morphology method to the image",
cristy3ed852e2009-09-05 21:47:34 +00003512 "-motion-blur geometry",
3513 " simulate motion blur",
3514 "-negate replace every pixel with its complementary color ",
cristy3c741502011-04-01 23:21:16 +00003515 "-noise geometry add or reduce noise in an image",
cristy3ed852e2009-09-05 21:47:34 +00003516 "-normalize transform image to span the full range of colors",
3517 "-opaque color change this color to the fill color",
3518 "-ordered-dither NxN",
3519 " add a noise pattern to the image with specific",
3520 " amplitudes",
3521 "-paint radius simulate an oil painting",
cristy3d629e22012-11-04 01:32:13 +00003522 "-perceptible epsilon",
cristyb4671fc2012-11-04 15:02:10 +00003523 " pixel value less than |epsilon| become epsilon or",
3524 " -epsilon",
cristy3ed852e2009-09-05 21:47:34 +00003525 "-polaroid angle simulate a Polaroid picture",
3526 "-posterize levels reduce the image to a limited number of color levels",
cristy3ed852e2009-09-05 21:47:34 +00003527 "-profile filename add, delete, or apply an image profile",
3528 "-quantize colorspace reduce colors in this colorspace",
cristy3ed852e2009-09-05 21:47:34 +00003529 "-raise value lighten/darken image edges to create a 3-D effect",
3530 "-random-threshold low,high",
3531 " random threshold the image",
cristy3ed852e2009-09-05 21:47:34 +00003532 "-region geometry apply options to a portion of the image",
3533 "-render render vector graphics",
3534 "-repage geometry size and location of an image canvas",
3535 "-resample geometry change the resolution of an image",
3536 "-resize geometry resize the image",
3537 "-roll geometry roll an image vertically or horizontally",
3538 "-rotate degrees apply Paeth rotation to the image",
dirk6d612cf2014-03-13 21:17:23 +00003539 "-rotational-blur angle",
3540 " rotational blur the image",
cristy3ed852e2009-09-05 21:47:34 +00003541 "-sample geometry scale image with pixel sampling",
3542 "-scale geometry scale the image",
3543 "-segment values segment an image",
3544 "-selective-blur geometry",
3545 " selectively blur pixels within a contrast threshold",
3546 "-sepia-tone threshold",
3547 " simulate a sepia-toned photo",
3548 "-set property value set an image property",
3549 "-shade degrees shade the image using a distant light source",
3550 "-shadow geometry simulate an image shadow",
3551 "-sharpen geometry sharpen the image",
3552 "-shave geometry shave pixels from the image edges",
cristycee97112010-05-28 00:44:52 +00003553 "-shear geometry slide one edge of the image along the X or Y axis",
cristy3ed852e2009-09-05 21:47:34 +00003554 "-sigmoidal-contrast geometry",
cristyb4671fc2012-11-04 15:02:10 +00003555 " increase the contrast without saturating highlights or",
3556 " shadows",
cristy3ed852e2009-09-05 21:47:34 +00003557 "-sketch geometry simulate a pencil sketch",
3558 "-solarize threshold negate all pixels above the threshold level",
3559 "-sparse-color method args",
3560 " fill in a image based on a few color points",
3561 "-splice geometry splice the background color into the image",
3562 "-spread radius displace image pixels by a random amount",
cristy0834d642011-03-18 18:26:08 +00003563 "-statistic type radius",
3564 " replace each pixel with corresponding statistic from the neighborhood",
cristy3ed852e2009-09-05 21:47:34 +00003565 "-strip strip image of all profiles and comments",
3566 "-swirl degrees swirl image pixels about the center",
3567 "-threshold value threshold the image",
3568 "-thumbnail geometry create a thumbnail of the image",
3569 "-tile filename tile image when filling a graphic primitive",
3570 "-tint value tint the image with the fill color",
3571 "-transform affine transform image",
3572 "-transparent color make this color transparent within the image",
3573 "-transpose flip image vertically and rotate 90 degrees",
3574 "-transverse flop image horizontally and rotate 270 degrees",
3575 "-trim trim image edges",
3576 "-type type image type",
3577 "-unique-colors discard all but one of any pixel color",
3578 "-unsharp geometry sharpen the image",
3579 "-vignette geometry soften the edges of the image in vignette style",
cristycee97112010-05-28 00:44:52 +00003580 "-wave geometry alter an image along a sine wave",
cristy3ed852e2009-09-05 21:47:34 +00003581 "-white-threshold value",
3582 " force all pixels above the threshold into white",
3583 (char *) NULL
3584 },
3585 *sequence_operators[]=
3586 {
cristye9252c22013-07-30 15:43:21 +00003587 "-affinity filename transform image colors to match this set of colors",
cristy4285d782011-02-09 20:12:28 +00003588 "-append append an image sequence",
cristy3ed852e2009-09-05 21:47:34 +00003589 "-clut apply a color lookup table to the image",
3590 "-coalesce merge a sequence of images",
3591 "-combine combine a sequence of images",
cristyb92495a2013-08-20 00:10:59 +00003592 "-compare mathematically and visually annotate the difference between an image and its reconstruction",
cristy790190d2013-10-04 00:51:51 +00003593 "-complex operator perform complex mathematics on an image sequence",
cristy3ed852e2009-09-05 21:47:34 +00003594 "-composite composite image",
cristy3476df82015-06-22 18:43:46 +00003595 "-copy geometry offset",
3596 " copy pixels from one area of an image to another",
cristy3ed852e2009-09-05 21:47:34 +00003597 "-crop geometry cut out a rectangular region of the image",
3598 "-deconstruct break down an image sequence into constituent parts",
cristyd18ae7c2010-03-07 17:39:52 +00003599 "-evaluate-sequence operator",
3600 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003601 "-flatten flatten a sequence of images",
3602 "-fx expression apply mathematical expression to an image channel(s)",
3603 "-hald-clut apply a Hald color lookup table to the image",
cristye0b9b8f2013-03-28 12:39:39 +00003604 "-layers method optimize, merge, or compare image layers",
cristy3ed852e2009-09-05 21:47:34 +00003605 "-morph value morph an image sequence",
3606 "-mosaic create a mosaic from an image sequence",
cristy8cdfb342012-11-11 21:44:36 +00003607 "-poly terms build a polynomial from the image sequence and the corresponding",
cristydbc2da92012-11-12 13:16:07 +00003608 " terms (coefficients and degree pairs).",
cristy36b94822010-05-20 12:48:16 +00003609 "-print string interpret string and print to console",
cristy3ed852e2009-09-05 21:47:34 +00003610 "-process arguments process the image with a custom image filter",
cristy4285d782011-02-09 20:12:28 +00003611 "-smush geometry smush an image sequence together",
cristy3ed852e2009-09-05 21:47:34 +00003612 "-write filename write images to this file",
3613 (char *) NULL
3614 },
3615 *settings[]=
3616 {
3617 "-adjoin join images into a single multi-image file",
3618 "-affine matrix affine transform matrix",
3619 "-alpha option activate, deactivate, reset, or set the alpha channel",
3620 "-antialias remove pixel-aliasing",
3621 "-authenticate password",
3622 " decipher image with this password",
3623 "-attenuate value lessen (or intensify) when adding noise to an image",
3624 "-background color background color",
3625 "-bias value add bias when convolving an image",
3626 "-black-point-compensation",
3627 " use black point compensation",
3628 "-blue-primary point chromaticity blue primary point",
3629 "-bordercolor color border color",
3630 "-caption string assign a caption to an image",
cristy3ed852e2009-09-05 21:47:34 +00003631 "-colors value preferred number of colors in the image",
3632 "-colorspace type alternate image colorspace",
3633 "-comment string annotate image with comment",
3634 "-compose operator set image composite operator",
3635 "-compress type type of pixel compression when writing the image",
anthonyfd706f92012-01-19 04:22:02 +00003636 "-define format:option=value",
cristy3ed852e2009-09-05 21:47:34 +00003637 " define one or more image format options",
3638 "-delay value display the next image after pausing",
3639 "-density geometry horizontal and vertical density of the image",
3640 "-depth value image depth",
cristyc9b12952010-03-28 01:12:28 +00003641 "-direction type render text right-to-left or left-to-right",
cristy3ed852e2009-09-05 21:47:34 +00003642 "-display server get image or font from this X server",
3643 "-dispose method layer disposal method",
3644 "-dither method apply error diffusion to image",
3645 "-encoding type text encoding type",
3646 "-endian type endianness (MSB or LSB) of the image",
3647 "-family name render text with this font family",
cristy14154222012-06-15 23:21:49 +00003648 "-features distance analyze image features (e.g. contrast, correlation)",
cristy3ed852e2009-09-05 21:47:34 +00003649 "-fill color color to use when filling a graphic primitive",
3650 "-filter type use this filter when resizing an image",
3651 "-font name render text with this font",
anthonyfd706f92012-01-19 04:22:02 +00003652 "-format \"string\" output formatted image characteristics",
cristy3ed852e2009-09-05 21:47:34 +00003653 "-fuzz distance colors within this distance are considered equal",
3654 "-gravity type horizontal and vertical text placement",
3655 "-green-primary point chromaticity green primary point",
cristy70e9f682013-03-12 22:31:22 +00003656 "-intensity method method to generate an intensity value from a pixel",
cristy3ed852e2009-09-05 21:47:34 +00003657 "-intent type type of rendering intent when managing the image color",
3658 "-interlace type type of image interlacing scheme",
cristyb32b90a2009-09-07 21:45:48 +00003659 "-interline-spacing value",
3660 " set the space between two text lines",
cristy3ed852e2009-09-05 21:47:34 +00003661 "-interpolate method pixel color interpolation method",
3662 "-interword-spacing value",
3663 " set the space between two words",
3664 "-kerning value set the space between two letters",
3665 "-label string assign a label to an image",
3666 "-limit type value pixel cache resource limit",
3667 "-loop iterations add Netscape loop extension to your GIF animation",
cristye9252c22013-07-30 15:43:21 +00003668 "-matte store matte channel if the image has one",
cristy3ed852e2009-09-05 21:47:34 +00003669 "-mattecolor color frame color",
3670 "-monitor monitor progress",
3671 "-orient type image orientation",
3672 "-page geometry size and location of an image canvas (setting)",
cristye9252c22013-07-30 15:43:21 +00003673 "-path path write images to this path on disk",
cristy3ed852e2009-09-05 21:47:34 +00003674 "-ping efficiently determine image attributes",
3675 "-pointsize value font point size",
cristy7c1b9fd2010-02-02 14:36:00 +00003676 "-precision value maximum number of significant digits to print",
cristy3ed852e2009-09-05 21:47:34 +00003677 "-preview type image preview type",
3678 "-quality value JPEG/MIFF/PNG compression level",
3679 "-quiet suppress all warning messages",
cristy327030c2015-07-25 18:05:50 +00003680 "-read-mask filename associate a read mask with the image",
cristy3ed852e2009-09-05 21:47:34 +00003681 "-red-primary point chromaticity red primary point",
3682 "-regard-warnings pay attention to warning messages",
3683 "-remap filename transform image colors to match this set of colors",
3684 "-respect-parentheses settings remain in effect until parenthesis boundary",
3685 "-sampling-factor geometry",
3686 " horizontal and vertical sampling factor",
3687 "-scene value image scene number",
3688 "-seed value seed a new sequence of pseudo-random numbers",
3689 "-size geometry width and height of image",
3690 "-stretch type render text with this font stretch",
3691 "-stroke color graphic primitive stroke color",
3692 "-strokewidth value graphic primitive stroke width",
3693 "-style type render text with this font style",
cristyd9a29192010-10-16 16:49:53 +00003694 "-synchronize synchronize image to storage device",
3695 "-taint declare the image as modified",
cristy3ed852e2009-09-05 21:47:34 +00003696 "-texture filename name of texture to tile onto the image background",
3697 "-tile-offset geometry",
3698 " tile offset",
3699 "-treedepth value color tree depth",
3700 "-transparent-color color",
3701 " transparent color",
3702 "-undercolor color annotation bounding box color",
3703 "-units type the units of image resolution",
3704 "-verbose print detailed information about the image",
3705 "-view FlashPix viewing transforms",
3706 "-virtual-pixel method",
3707 " virtual pixel access method",
3708 "-weight type render text with this font weight",
3709 "-white-point point chromaticity white point",
cristy327030c2015-07-25 18:05:50 +00003710 "-write-mask filename associate a write mask with the image",
cristy3ed852e2009-09-05 21:47:34 +00003711 (char *) NULL
3712 },
3713 *stack_operators[]=
3714 {
anthonyb69c4b32011-03-23 04:37:44 +00003715 "-delete indexes delete the image from the image sequence",
3716 "-duplicate count,indexes",
cristyecb10ff2011-03-22 13:14:03 +00003717 " duplicate an image one or more times",
cristy3ed852e2009-09-05 21:47:34 +00003718 "-insert index insert last image into the image sequence",
anthony9bd15492011-03-23 02:11:13 +00003719 "-reverse reverse image sequence",
cristy3ed852e2009-09-05 21:47:34 +00003720 "-swap indexes swap two images in the image sequence",
3721 (char *) NULL
3722 };
3723
3724 const char
3725 **p;
3726
cristy4f7a6132012-12-23 00:35:19 +00003727 ListMagickVersion(stdout);
cristy3ed852e2009-09-05 21:47:34 +00003728 (void) printf("Usage: %s [options ...] file [ [options ...] file ...]\n",
3729 GetClientName());
3730 (void) printf("\nImage Settings:\n");
3731 for (p=settings; *p != (char *) NULL; p++)
3732 (void) printf(" %s\n",*p);
3733 (void) printf("\nImage Operators:\n");
3734 for (p=operators; *p != (char *) NULL; p++)
3735 (void) printf(" %s\n",*p);
cristy87c02f42012-02-24 00:19:10 +00003736 (void) printf("\nImage Channel Operators:\n");
3737 for (p=channel_operators; *p != (char *) NULL; p++)
3738 (void) printf(" %s\n",*p);
cristy3ed852e2009-09-05 21:47:34 +00003739 (void) printf("\nImage Sequence Operators:\n");
3740 for (p=sequence_operators; *p != (char *) NULL; p++)
3741 (void) printf(" %s\n",*p);
3742 (void) printf("\nImage Stack Operators:\n");
3743 for (p=stack_operators; *p != (char *) NULL; p++)
3744 (void) printf(" %s\n",*p);
3745 (void) printf("\nMiscellaneous Options:\n");
3746 for (p=miscellaneous; *p != (char *) NULL; p++)
3747 (void) printf(" %s\n",*p);
3748 (void) printf(
anthonyfd706f92012-01-19 04:22:02 +00003749 "\nBy default, the image format of 'file' is determined by its magic\n");
cristy3ed852e2009-09-05 21:47:34 +00003750 (void) printf(
3751 "number. To specify a particular image format, precede the filename\n");
3752 (void) printf(
3753 "with an image format name and a colon (i.e. ps:image) or specify the\n");
3754 (void) printf(
3755 "image type as the filename suffix (i.e. image.ps). Specify 'file' as\n");
3756 (void) printf("'-' for standard input or output.\n");
3757 return(MagickFalse);
3758}
3759
3760WandExport MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,
3761 int argc,char **argv,char **wand_unused(metadata),ExceptionInfo *exception)
3762{
3763#define DestroyMogrify() \
3764{ \
3765 if (format != (char *) NULL) \
3766 format=DestroyString(format); \
3767 if (path != (char *) NULL) \
3768 path=DestroyString(path); \
3769 DestroyImageStack(); \
cristybb503372010-05-27 20:51:26 +00003770 for (i=0; i < (ssize_t) argc; i++) \
cristy3ed852e2009-09-05 21:47:34 +00003771 argv[i]=DestroyString(argv[i]); \
3772 argv=(char **) RelinquishMagickMemory(argv); \
3773}
3774#define ThrowMogrifyException(asperity,tag,option) \
3775{ \
cristyefe601c2013-01-05 17:51:12 +00003776 (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag,"`%s'", \
cristy3ed852e2009-09-05 21:47:34 +00003777 option); \
3778 DestroyMogrify(); \
3779 return(MagickFalse); \
3780}
3781#define ThrowMogrifyInvalidArgumentException(option,argument) \
3782{ \
3783 (void) ThrowMagickException(exception,GetMagickModule(),OptionError, \
anthonye5b39652012-04-21 05:37:29 +00003784 "InvalidArgument","'%s': %s",argument,option); \
cristy3ed852e2009-09-05 21:47:34 +00003785 DestroyMogrify(); \
3786 return(MagickFalse); \
3787}
3788
3789 char
3790 *format,
3791 *option,
3792 *path;
3793
3794 Image
3795 *image;
3796
3797 ImageStack
3798 image_stack[MaxImageStackDepth+1];
3799
cristy3ed852e2009-09-05 21:47:34 +00003800 MagickBooleanType
3801 global_colormap;
3802
3803 MagickBooleanType
3804 fire,
cristyebbcfea2011-02-25 02:43:54 +00003805 pend,
3806 respect_parenthesis;
cristy3ed852e2009-09-05 21:47:34 +00003807
3808 MagickStatusType
3809 status;
3810
cristyebbcfea2011-02-25 02:43:54 +00003811 register ssize_t
3812 i;
3813
3814 ssize_t
3815 j,
3816 k;
3817
cristy3ed852e2009-09-05 21:47:34 +00003818 /*
3819 Set defaults.
3820 */
3821 assert(image_info != (ImageInfo *) NULL);
cristye1c94d92015-06-28 12:16:33 +00003822 assert(image_info->signature == MagickCoreSignature);
cristy3ed852e2009-09-05 21:47:34 +00003823 if (image_info->debug != MagickFalse)
3824 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3825 assert(exception != (ExceptionInfo *) NULL);
3826 if (argc == 2)
3827 {
3828 option=argv[1];
3829 if ((LocaleCompare("version",option+1) == 0) ||
3830 (LocaleCompare("-version",option+1) == 0))
3831 {
cristy4f7a6132012-12-23 00:35:19 +00003832 ListMagickVersion(stdout);
cristy3ed852e2009-09-05 21:47:34 +00003833 return(MagickFalse);
3834 }
3835 }
3836 if (argc < 2)
cristy13e61a12010-02-04 20:19:00 +00003837 return(MogrifyUsage());
cristy3ed852e2009-09-05 21:47:34 +00003838 format=(char *) NULL;
3839 path=(char *) NULL;
3840 global_colormap=MagickFalse;
3841 k=0;
3842 j=1;
3843 NewImageStack();
3844 option=(char *) NULL;
3845 pend=MagickFalse;
cristyebbcfea2011-02-25 02:43:54 +00003846 respect_parenthesis=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00003847 status=MagickTrue;
3848 /*
3849 Parse command line.
3850 */
3851 ReadCommandlLine(argc,&argv);
3852 status=ExpandFilenames(&argc,&argv);
3853 if (status == MagickFalse)
3854 ThrowMogrifyException(ResourceLimitError,"MemoryAllocationFailed",
3855 GetExceptionMessage(errno));
cristybb503372010-05-27 20:51:26 +00003856 for (i=1; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00003857 {
3858 option=argv[i];
3859 if (LocaleCompare(option,"(") == 0)
3860 {
3861 FireImageStack(MagickFalse,MagickTrue,pend);
3862 if (k == MaxImageStackDepth)
3863 ThrowMogrifyException(OptionError,"ParenthesisNestedTooDeeply",
3864 option);
3865 PushImageStack();
3866 continue;
3867 }
3868 if (LocaleCompare(option,")") == 0)
3869 {
3870 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
3871 if (k == 0)
3872 ThrowMogrifyException(OptionError,"UnableToParseExpression",option);
3873 PopImageStack();
3874 continue;
3875 }
cristy042ee782011-04-22 18:48:30 +00003876 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00003877 {
3878 char
cristy151b66d2015-04-15 10:50:31 +00003879 backup_filename[MagickPathExtent],
cristy3ed852e2009-09-05 21:47:34 +00003880 *filename;
3881
3882 Image
3883 *images;
3884
3885 /*
3886 Option is a file name: begin by reading image from specified file.
3887 */
3888 FireImageStack(MagickFalse,MagickFalse,pend);
3889 filename=argv[i];
cristycee97112010-05-28 00:44:52 +00003890 if ((LocaleCompare(filename,"--") == 0) && (i < (ssize_t) (argc-1)))
cristy3ed852e2009-09-05 21:47:34 +00003891 filename=argv[++i];
cristy1b58f252012-03-01 01:41:41 +00003892 images=ReadImages(image_info,filename,exception);
cristy3ed852e2009-09-05 21:47:34 +00003893 status&=(images != (Image *) NULL) &&
3894 (exception->severity < ErrorException);
3895 if (images == (Image *) NULL)
3896 continue;
cristydaa76602010-06-30 13:05:11 +00003897 if (format != (char *) NULL)
3898 (void) CopyMagickString(images->filename,images->magick_filename,
cristy151b66d2015-04-15 10:50:31 +00003899 MagickPathExtent);
cristy3ed852e2009-09-05 21:47:34 +00003900 if (path != (char *) NULL)
3901 {
3902 GetPathComponent(option,TailPath,filename);
cristy151b66d2015-04-15 10:50:31 +00003903 (void) FormatLocaleString(images->filename,MagickPathExtent,"%s%c%s",
cristy3ed852e2009-09-05 21:47:34 +00003904 path,*DirectorySeparator,filename);
3905 }
3906 if (format != (char *) NULL)
cristydaa76602010-06-30 13:05:11 +00003907 AppendImageFormat(format,images->filename);
cristy3ed852e2009-09-05 21:47:34 +00003908 AppendImageStack(images);
3909 FinalizeImageSettings(image_info,image,MagickFalse);
3910 if (global_colormap != MagickFalse)
3911 {
3912 QuantizeInfo
3913 *quantize_info;
3914
3915 quantize_info=AcquireQuantizeInfo(image_info);
cristy018f07f2011-09-04 21:15:19 +00003916 (void) RemapImages(quantize_info,images,(Image *) NULL,exception);
cristy3ed852e2009-09-05 21:47:34 +00003917 quantize_info=DestroyQuantizeInfo(quantize_info);
3918 }
3919 *backup_filename='\0';
3920 if ((LocaleCompare(image->filename,"-") != 0) &&
3921 (IsPathWritable(image->filename) != MagickFalse))
3922 {
cristy3ed852e2009-09-05 21:47:34 +00003923 /*
3924 Rename image file as backup.
3925 */
3926 (void) CopyMagickString(backup_filename,image->filename,
cristy151b66d2015-04-15 10:50:31 +00003927 MagickPathExtent);
dirkb4979cb2015-11-22 10:01:27 +01003928 for (j=0; j < 6; j++)
cristy3ed852e2009-09-05 21:47:34 +00003929 {
cristy151b66d2015-04-15 10:50:31 +00003930 (void) ConcatenateMagickString(backup_filename,"~",MagickPathExtent);
cristy3ed852e2009-09-05 21:47:34 +00003931 if (IsPathAccessible(backup_filename) == MagickFalse)
3932 break;
3933 }
3934 if ((IsPathAccessible(backup_filename) != MagickFalse) ||
cristy320684d2011-09-23 14:55:47 +00003935 (rename_utf8(image->filename,backup_filename) != 0))
cristy3ed852e2009-09-05 21:47:34 +00003936 *backup_filename='\0';
3937 }
3938 /*
3939 Write transmogrified image to disk.
3940 */
3941 image_info->synchronize=MagickTrue;
3942 status&=WriteImages(image_info,image,image->filename,exception);
cristy74aae342014-07-19 21:16:28 +00003943 if ((status != MagickFalse) && (*backup_filename != '\0'))
cristy18c6c272011-09-23 14:40:37 +00003944 (void) remove_utf8(backup_filename);
cristy3ed852e2009-09-05 21:47:34 +00003945 RemoveAllImageStack();
3946 continue;
3947 }
3948 pend=image != (Image *) NULL ? MagickTrue : MagickFalse;
3949 switch (*(option+1))
3950 {
3951 case 'a':
3952 {
3953 if (LocaleCompare("adaptive-blur",option+1) == 0)
3954 {
3955 i++;
cristybb503372010-05-27 20:51:26 +00003956 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003957 ThrowMogrifyException(OptionError,"MissingArgument",option);
3958 if (IsGeometry(argv[i]) == MagickFalse)
3959 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3960 break;
3961 }
3962 if (LocaleCompare("adaptive-resize",option+1) == 0)
3963 {
3964 i++;
cristybb503372010-05-27 20:51:26 +00003965 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003966 ThrowMogrifyException(OptionError,"MissingArgument",option);
3967 if (IsGeometry(argv[i]) == MagickFalse)
3968 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3969 break;
3970 }
3971 if (LocaleCompare("adaptive-sharpen",option+1) == 0)
3972 {
3973 i++;
cristybb503372010-05-27 20:51:26 +00003974 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003975 ThrowMogrifyException(OptionError,"MissingArgument",option);
3976 if (IsGeometry(argv[i]) == MagickFalse)
3977 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3978 break;
3979 }
3980 if (LocaleCompare("affine",option+1) == 0)
3981 {
3982 if (*option == '+')
3983 break;
3984 i++;
cristybb503372010-05-27 20:51:26 +00003985 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003986 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy3ed852e2009-09-05 21:47:34 +00003987 break;
3988 }
3989 if (LocaleCompare("alpha",option+1) == 0)
3990 {
cristybb503372010-05-27 20:51:26 +00003991 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003992 type;
3993
3994 if (*option == '+')
3995 break;
3996 i++;
cristybb503372010-05-27 20:51:26 +00003997 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003998 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy288a3532012-08-28 00:19:44 +00003999 type=ParseCommandOption(MagickAlphaChannelOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004000 if (type < 0)
cristyb15b06c2012-08-28 11:36:48 +00004001 ThrowMogrifyException(OptionError,"UnrecognizedAlphaChannelOption",
cristy3ed852e2009-09-05 21:47:34 +00004002 argv[i]);
4003 break;
4004 }
4005 if (LocaleCompare("annotate",option+1) == 0)
4006 {
4007 if (*option == '+')
4008 break;
4009 i++;
cristybb503372010-05-27 20:51:26 +00004010 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004011 ThrowMogrifyException(OptionError,"MissingArgument",option);
4012 if (IsGeometry(argv[i]) == MagickFalse)
4013 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristybb503372010-05-27 20:51:26 +00004014 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004015 ThrowMogrifyException(OptionError,"MissingArgument",option);
4016 i++;
4017 break;
4018 }
4019 if (LocaleCompare("antialias",option+1) == 0)
4020 break;
4021 if (LocaleCompare("append",option+1) == 0)
4022 break;
4023 if (LocaleCompare("attenuate",option+1) == 0)
4024 {
4025 if (*option == '+')
4026 break;
4027 i++;
cristye81f5522014-05-07 01:25:59 +00004028 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004029 ThrowMogrifyException(OptionError,"MissingArgument",option);
4030 if (IsGeometry(argv[i]) == MagickFalse)
4031 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4032 break;
4033 }
4034 if (LocaleCompare("authenticate",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 break;
4042 }
4043 if (LocaleCompare("auto-gamma",option+1) == 0)
4044 break;
4045 if (LocaleCompare("auto-level",option+1) == 0)
4046 break;
4047 if (LocaleCompare("auto-orient",option+1) == 0)
4048 break;
cristy52ad9e92013-02-08 23:23:29 +00004049 if (LocaleCompare("average",option+1) == 0)
4050 break;
cristy3ed852e2009-09-05 21:47:34 +00004051 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4052 }
4053 case 'b':
4054 {
4055 if (LocaleCompare("background",option+1) == 0)
4056 {
4057 if (*option == '+')
4058 break;
4059 i++;
cristybb503372010-05-27 20:51:26 +00004060 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004061 ThrowMogrifyException(OptionError,"MissingArgument",option);
4062 break;
4063 }
4064 if (LocaleCompare("bias",option+1) == 0)
4065 {
4066 if (*option == '+')
4067 break;
4068 i++;
cristye81f5522014-05-07 01:25:59 +00004069 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004070 ThrowMogrifyException(OptionError,"MissingArgument",option);
4071 if (IsGeometry(argv[i]) == MagickFalse)
4072 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4073 break;
4074 }
4075 if (LocaleCompare("black-point-compensation",option+1) == 0)
4076 break;
4077 if (LocaleCompare("black-threshold",option+1) == 0)
4078 {
4079 if (*option == '+')
4080 break;
4081 i++;
cristybb503372010-05-27 20:51:26 +00004082 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004083 ThrowMogrifyException(OptionError,"MissingArgument",option);
4084 if (IsGeometry(argv[i]) == MagickFalse)
4085 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4086 break;
4087 }
4088 if (LocaleCompare("blue-primary",option+1) == 0)
4089 {
4090 if (*option == '+')
4091 break;
4092 i++;
cristybb503372010-05-27 20:51:26 +00004093 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004094 ThrowMogrifyException(OptionError,"MissingArgument",option);
4095 if (IsGeometry(argv[i]) == MagickFalse)
4096 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4097 break;
4098 }
4099 if (LocaleCompare("blue-shift",option+1) == 0)
4100 {
4101 i++;
cristybb503372010-05-27 20:51:26 +00004102 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004103 ThrowMogrifyException(OptionError,"MissingArgument",option);
4104 if (IsGeometry(argv[i]) == MagickFalse)
4105 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4106 break;
4107 }
4108 if (LocaleCompare("blur",option+1) == 0)
4109 {
4110 i++;
cristybb503372010-05-27 20:51:26 +00004111 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004112 ThrowMogrifyException(OptionError,"MissingArgument",option);
4113 if (IsGeometry(argv[i]) == MagickFalse)
4114 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4115 break;
4116 }
4117 if (LocaleCompare("border",option+1) == 0)
4118 {
4119 if (*option == '+')
4120 break;
4121 i++;
cristybb503372010-05-27 20:51:26 +00004122 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004123 ThrowMogrifyException(OptionError,"MissingArgument",option);
4124 if (IsGeometry(argv[i]) == MagickFalse)
4125 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4126 break;
4127 }
4128 if (LocaleCompare("bordercolor",option+1) == 0)
4129 {
4130 if (*option == '+')
4131 break;
4132 i++;
cristybb503372010-05-27 20:51:26 +00004133 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004134 ThrowMogrifyException(OptionError,"MissingArgument",option);
4135 break;
4136 }
4137 if (LocaleCompare("box",option+1) == 0)
4138 {
4139 if (*option == '+')
4140 break;
4141 i++;
cristybb503372010-05-27 20:51:26 +00004142 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004143 ThrowMogrifyException(OptionError,"MissingArgument",option);
4144 break;
4145 }
cristya28d6b82010-01-11 20:03:47 +00004146 if (LocaleCompare("brightness-contrast",option+1) == 0)
4147 {
4148 i++;
cristybb503372010-05-27 20:51:26 +00004149 if (i == (ssize_t) argc)
cristya28d6b82010-01-11 20:03:47 +00004150 ThrowMogrifyException(OptionError,"MissingArgument",option);
4151 if (IsGeometry(argv[i]) == MagickFalse)
4152 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4153 break;
4154 }
cristy3ed852e2009-09-05 21:47:34 +00004155 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4156 }
4157 case 'c':
4158 {
4159 if (LocaleCompare("cache",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 }
cristy4ceadb82014-03-29 15:30:43 +00004170 if (LocaleCompare("canny",option+1) == 0)
4171 {
4172 if (*option == '+')
4173 break;
4174 i++;
4175 if (i == (ssize_t) argc)
4176 ThrowMogrifyException(OptionError,"MissingArgument",option);
4177 if (IsGeometry(argv[i]) == MagickFalse)
4178 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4179 break;
4180 }
cristy3ed852e2009-09-05 21:47:34 +00004181 if (LocaleCompare("caption",option+1) == 0)
4182 {
4183 if (*option == '+')
4184 break;
4185 i++;
cristybb503372010-05-27 20:51:26 +00004186 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004187 ThrowMogrifyException(OptionError,"MissingArgument",option);
4188 break;
4189 }
4190 if (LocaleCompare("channel",option+1) == 0)
4191 {
cristybb503372010-05-27 20:51:26 +00004192 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004193 channel;
4194
4195 if (*option == '+')
4196 break;
4197 i++;
cristye81f5522014-05-07 01:25:59 +00004198 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004199 ThrowMogrifyException(OptionError,"MissingArgument",option);
4200 channel=ParseChannelOption(argv[i]);
4201 if (channel < 0)
4202 ThrowMogrifyException(OptionError,"UnrecognizedChannelType",
4203 argv[i]);
4204 break;
4205 }
cristy5f257b22012-03-07 00:27:29 +00004206 if (LocaleCompare("channel-fx",option+1) == 0)
cristy87c02f42012-02-24 00:19:10 +00004207 {
4208 ssize_t
4209 channel;
4210
4211 if (*option == '+')
4212 break;
4213 i++;
cristye81f5522014-05-07 01:25:59 +00004214 if (i == (ssize_t) argc)
cristy87c02f42012-02-24 00:19:10 +00004215 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy953c4bd2012-02-24 01:04:04 +00004216 channel=ParsePixelChannelOption(argv[i]);
cristy87c02f42012-02-24 00:19:10 +00004217 if (channel < 0)
4218 ThrowMogrifyException(OptionError,"UnrecognizedChannelType",
4219 argv[i]);
4220 break;
4221 }
cristy3ed852e2009-09-05 21:47:34 +00004222 if (LocaleCompare("cdl",option+1) == 0)
4223 {
4224 if (*option == '+')
4225 break;
4226 i++;
cristye81f5522014-05-07 01:25:59 +00004227 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004228 ThrowMogrifyException(OptionError,"MissingArgument",option);
4229 break;
4230 }
4231 if (LocaleCompare("charcoal",option+1) == 0)
4232 {
4233 if (*option == '+')
4234 break;
4235 i++;
cristybb503372010-05-27 20:51:26 +00004236 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004237 ThrowMogrifyException(OptionError,"MissingArgument",option);
4238 if (IsGeometry(argv[i]) == MagickFalse)
4239 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4240 break;
4241 }
4242 if (LocaleCompare("chop",option+1) == 0)
4243 {
4244 if (*option == '+')
4245 break;
4246 i++;
cristybb503372010-05-27 20:51:26 +00004247 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004248 ThrowMogrifyException(OptionError,"MissingArgument",option);
4249 if (IsGeometry(argv[i]) == MagickFalse)
4250 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4251 break;
4252 }
cristy1eb45dd2009-09-25 16:38:06 +00004253 if (LocaleCompare("clamp",option+1) == 0)
4254 break;
4255 if (LocaleCompare("clip",option+1) == 0)
4256 break;
cristy3ed852e2009-09-05 21:47:34 +00004257 if (LocaleCompare("clip-mask",option+1) == 0)
4258 {
4259 if (*option == '+')
4260 break;
4261 i++;
cristybb503372010-05-27 20:51:26 +00004262 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004263 ThrowMogrifyException(OptionError,"MissingArgument",option);
4264 break;
4265 }
4266 if (LocaleCompare("clut",option+1) == 0)
4267 break;
4268 if (LocaleCompare("coalesce",option+1) == 0)
4269 break;
4270 if (LocaleCompare("colorize",option+1) == 0)
4271 {
4272 if (*option == '+')
4273 break;
4274 i++;
cristybb503372010-05-27 20:51:26 +00004275 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004276 ThrowMogrifyException(OptionError,"MissingArgument",option);
4277 if (IsGeometry(argv[i]) == MagickFalse)
4278 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4279 break;
4280 }
cristye6365592010-04-02 17:31:23 +00004281 if (LocaleCompare("color-matrix",option+1) == 0)
4282 {
cristyb6bd4ad2010-08-08 01:12:27 +00004283 KernelInfo
4284 *kernel_info;
4285
cristye6365592010-04-02 17:31:23 +00004286 if (*option == '+')
4287 break;
4288 i++;
cristye81f5522014-05-07 01:25:59 +00004289 if (i == (ssize_t) argc)
cristye6365592010-04-02 17:31:23 +00004290 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy2c57b742014-10-31 00:40:34 +00004291 kernel_info=AcquireKernelInfo(argv[i],exception);
cristyb6bd4ad2010-08-08 01:12:27 +00004292 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00004293 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00004294 kernel_info=DestroyKernelInfo(kernel_info);
cristye6365592010-04-02 17:31:23 +00004295 break;
4296 }
cristy3ed852e2009-09-05 21:47:34 +00004297 if (LocaleCompare("colors",option+1) == 0)
4298 {
4299 if (*option == '+')
4300 break;
4301 i++;
cristybb503372010-05-27 20:51:26 +00004302 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004303 ThrowMogrifyException(OptionError,"MissingArgument",option);
4304 if (IsGeometry(argv[i]) == MagickFalse)
4305 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4306 break;
4307 }
4308 if (LocaleCompare("colorspace",option+1) == 0)
4309 {
cristybb503372010-05-27 20:51:26 +00004310 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004311 colorspace;
4312
4313 if (*option == '+')
4314 break;
4315 i++;
cristybb503372010-05-27 20:51:26 +00004316 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004317 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004318 colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004319 argv[i]);
4320 if (colorspace < 0)
4321 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
4322 argv[i]);
4323 break;
4324 }
4325 if (LocaleCompare("combine",option+1) == 0)
cristy46f354c2012-07-04 13:31:29 +00004326 {
4327 ssize_t
4328 colorspace;
4329
4330 if (*option == '+')
4331 break;
4332 i++;
4333 if (i == (ssize_t) argc)
4334 ThrowMogrifyException(OptionError,"MissingArgument",option);
4335 colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
4336 argv[i]);
4337 if (colorspace < 0)
4338 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
4339 argv[i]);
4340 break;
4341 }
cristyb92495a2013-08-20 00:10:59 +00004342 if (LocaleCompare("compare",option+1) == 0)
4343 break;
cristy3ed852e2009-09-05 21:47:34 +00004344 if (LocaleCompare("comment",option+1) == 0)
4345 {
4346 if (*option == '+')
4347 break;
4348 i++;
cristybb503372010-05-27 20:51:26 +00004349 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004350 ThrowMogrifyException(OptionError,"MissingArgument",option);
4351 break;
4352 }
4353 if (LocaleCompare("composite",option+1) == 0)
4354 break;
4355 if (LocaleCompare("compress",option+1) == 0)
4356 {
cristybb503372010-05-27 20:51:26 +00004357 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004358 compress;
4359
4360 if (*option == '+')
4361 break;
4362 i++;
cristybb503372010-05-27 20:51:26 +00004363 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004364 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004365 compress=ParseCommandOption(MagickCompressOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004366 argv[i]);
4367 if (compress < 0)
4368 ThrowMogrifyException(OptionError,"UnrecognizedImageCompression",
4369 argv[i]);
4370 break;
4371 }
cristy22879752009-10-25 23:55:40 +00004372 if (LocaleCompare("concurrent",option+1) == 0)
4373 break;
cristy6e0b3bc2014-10-19 17:51:42 +00004374 if (LocaleCompare("connected-components",option+1) == 0)
4375 {
4376 i++;
4377 if (i == (ssize_t) argc)
4378 ThrowMogrifyException(OptionError,"MissingArgument",option);
4379 if (IsGeometry(argv[i]) == MagickFalse)
4380 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4381 break;
4382 }
cristy3ed852e2009-09-05 21:47:34 +00004383 if (LocaleCompare("contrast",option+1) == 0)
4384 break;
4385 if (LocaleCompare("contrast-stretch",option+1) == 0)
4386 {
4387 i++;
cristybb503372010-05-27 20:51:26 +00004388 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004389 ThrowMogrifyException(OptionError,"MissingArgument",option);
4390 if (IsGeometry(argv[i]) == MagickFalse)
4391 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4392 break;
4393 }
4394 if (LocaleCompare("convolve",option+1) == 0)
4395 {
cristyb6bd4ad2010-08-08 01:12:27 +00004396 KernelInfo
4397 *kernel_info;
4398
cristy3ed852e2009-09-05 21:47:34 +00004399 if (*option == '+')
4400 break;
4401 i++;
cristybb503372010-05-27 20:51:26 +00004402 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004403 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy2c57b742014-10-31 00:40:34 +00004404 kernel_info=AcquireKernelInfo(argv[i],exception);
cristyb6bd4ad2010-08-08 01:12:27 +00004405 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00004406 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00004407 kernel_info=DestroyKernelInfo(kernel_info);
cristy3ed852e2009-09-05 21:47:34 +00004408 break;
4409 }
cristy3476df82015-06-22 18:43:46 +00004410 if (LocaleCompare("copy",option+1) == 0)
4411 {
4412 if (*option == '+')
4413 break;
4414 i++;
4415 if (i == (ssize_t) argc)
4416 ThrowMogrifyException(OptionError,"MissingArgument",option);
4417 if (IsGeometry(argv[i]) == MagickFalse)
4418 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4419 i++;
4420 if (i == (ssize_t) argc)
4421 ThrowMogrifyException(OptionError,"MissingArgument",option);
4422 if (IsGeometry(argv[i]) == MagickFalse)
4423 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristy3476df82015-06-22 18:43:46 +00004424 break;
4425 }
cristy3ed852e2009-09-05 21:47:34 +00004426 if (LocaleCompare("crop",option+1) == 0)
4427 {
4428 if (*option == '+')
4429 break;
4430 i++;
cristybb503372010-05-27 20:51:26 +00004431 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004432 ThrowMogrifyException(OptionError,"MissingArgument",option);
4433 if (IsGeometry(argv[i]) == MagickFalse)
4434 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4435 break;
4436 }
4437 if (LocaleCompare("cycle",option+1) == 0)
4438 {
4439 if (*option == '+')
4440 break;
4441 i++;
cristybb503372010-05-27 20:51:26 +00004442 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004443 ThrowMogrifyException(OptionError,"MissingArgument",option);
4444 if (IsGeometry(argv[i]) == MagickFalse)
4445 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4446 break;
4447 }
4448 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4449 }
4450 case 'd':
4451 {
4452 if (LocaleCompare("decipher",option+1) == 0)
4453 {
4454 if (*option == '+')
4455 break;
4456 i++;
cristye81f5522014-05-07 01:25:59 +00004457 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004458 ThrowMogrifyException(OptionError,"MissingArgument",option);
4459 break;
4460 }
4461 if (LocaleCompare("deconstruct",option+1) == 0)
4462 break;
4463 if (LocaleCompare("debug",option+1) == 0)
4464 {
cristybb503372010-05-27 20:51:26 +00004465 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004466 event;
4467
4468 if (*option == '+')
4469 break;
4470 i++;
cristybb503372010-05-27 20:51:26 +00004471 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004472 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004473 event=ParseCommandOption(MagickLogEventOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004474 if (event < 0)
4475 ThrowMogrifyException(OptionError,"UnrecognizedEventType",
4476 argv[i]);
4477 (void) SetLogEventMask(argv[i]);
4478 break;
4479 }
4480 if (LocaleCompare("define",option+1) == 0)
4481 {
4482 i++;
cristybb503372010-05-27 20:51:26 +00004483 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004484 ThrowMogrifyException(OptionError,"MissingArgument",option);
4485 if (*option == '+')
4486 {
4487 const char
4488 *define;
4489
4490 define=GetImageOption(image_info,argv[i]);
4491 if (define == (const char *) NULL)
4492 ThrowMogrifyException(OptionError,"NoSuchOption",argv[i]);
4493 break;
4494 }
4495 break;
4496 }
4497 if (LocaleCompare("delay",option+1) == 0)
4498 {
4499 if (*option == '+')
4500 break;
4501 i++;
cristybb503372010-05-27 20:51:26 +00004502 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004503 ThrowMogrifyException(OptionError,"MissingArgument",option);
4504 if (IsGeometry(argv[i]) == MagickFalse)
4505 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4506 break;
4507 }
cristyecb10ff2011-03-22 13:14:03 +00004508 if (LocaleCompare("delete",option+1) == 0)
4509 {
4510 if (*option == '+')
4511 break;
4512 i++;
cristye81f5522014-05-07 01:25:59 +00004513 if (i == (ssize_t) argc)
cristyecb10ff2011-03-22 13:14:03 +00004514 ThrowMogrifyException(OptionError,"MissingArgument",option);
4515 if (IsGeometry(argv[i]) == MagickFalse)
4516 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4517 break;
4518 }
cristy3ed852e2009-09-05 21:47:34 +00004519 if (LocaleCompare("density",option+1) == 0)
4520 {
4521 if (*option == '+')
4522 break;
4523 i++;
cristybb503372010-05-27 20:51:26 +00004524 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004525 ThrowMogrifyException(OptionError,"MissingArgument",option);
4526 if (IsGeometry(argv[i]) == MagickFalse)
4527 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4528 break;
4529 }
4530 if (LocaleCompare("depth",option+1) == 0)
4531 {
4532 if (*option == '+')
4533 break;
4534 i++;
cristybb503372010-05-27 20:51:26 +00004535 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004536 ThrowMogrifyException(OptionError,"MissingArgument",option);
4537 if (IsGeometry(argv[i]) == MagickFalse)
4538 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4539 break;
4540 }
4541 if (LocaleCompare("deskew",option+1) == 0)
4542 {
4543 if (*option == '+')
4544 break;
4545 i++;
cristybb503372010-05-27 20:51:26 +00004546 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004547 ThrowMogrifyException(OptionError,"MissingArgument",option);
4548 if (IsGeometry(argv[i]) == MagickFalse)
4549 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4550 break;
4551 }
4552 if (LocaleCompare("despeckle",option+1) == 0)
4553 break;
4554 if (LocaleCompare("dft",option+1) == 0)
4555 break;
cristyc9b12952010-03-28 01:12:28 +00004556 if (LocaleCompare("direction",option+1) == 0)
4557 {
cristybb503372010-05-27 20:51:26 +00004558 ssize_t
cristyc9b12952010-03-28 01:12:28 +00004559 direction;
4560
4561 if (*option == '+')
4562 break;
4563 i++;
cristybb503372010-05-27 20:51:26 +00004564 if (i == (ssize_t) argc)
cristyc9b12952010-03-28 01:12:28 +00004565 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004566 direction=ParseCommandOption(MagickDirectionOptions,MagickFalse,
cristyc9b12952010-03-28 01:12:28 +00004567 argv[i]);
4568 if (direction < 0)
4569 ThrowMogrifyException(OptionError,"UnrecognizedDirectionType",
4570 argv[i]);
4571 break;
4572 }
cristy3ed852e2009-09-05 21:47:34 +00004573 if (LocaleCompare("display",option+1) == 0)
4574 {
4575 if (*option == '+')
4576 break;
4577 i++;
cristybb503372010-05-27 20:51:26 +00004578 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004579 ThrowMogrifyException(OptionError,"MissingArgument",option);
4580 break;
4581 }
4582 if (LocaleCompare("dispose",option+1) == 0)
4583 {
cristybb503372010-05-27 20:51:26 +00004584 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004585 dispose;
4586
4587 if (*option == '+')
4588 break;
4589 i++;
cristybb503372010-05-27 20:51:26 +00004590 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004591 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004592 dispose=ParseCommandOption(MagickDisposeOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004593 if (dispose < 0)
4594 ThrowMogrifyException(OptionError,"UnrecognizedDisposeMethod",
4595 argv[i]);
4596 break;
4597 }
4598 if (LocaleCompare("distort",option+1) == 0)
4599 {
cristybb503372010-05-27 20:51:26 +00004600 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004601 op;
4602
4603 i++;
cristybb503372010-05-27 20:51:26 +00004604 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004605 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004606 op=ParseCommandOption(MagickDistortOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004607 if (op < 0)
4608 ThrowMogrifyException(OptionError,"UnrecognizedDistortMethod",
4609 argv[i]);
4610 i++;
cristye81f5522014-05-07 01:25:59 +00004611 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004612 ThrowMogrifyException(OptionError,"MissingArgument",option);
4613 break;
4614 }
4615 if (LocaleCompare("dither",option+1) == 0)
4616 {
cristybb503372010-05-27 20:51:26 +00004617 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004618 method;
4619
4620 if (*option == '+')
4621 break;
4622 i++;
cristybb503372010-05-27 20:51:26 +00004623 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004624 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004625 method=ParseCommandOption(MagickDitherOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004626 if (method < 0)
4627 ThrowMogrifyException(OptionError,"UnrecognizedDitherMethod",
4628 argv[i]);
4629 break;
4630 }
4631 if (LocaleCompare("draw",option+1) == 0)
4632 {
4633 if (*option == '+')
4634 break;
4635 i++;
cristybb503372010-05-27 20:51:26 +00004636 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004637 ThrowMogrifyException(OptionError,"MissingArgument",option);
4638 break;
4639 }
cristyecb10ff2011-03-22 13:14:03 +00004640 if (LocaleCompare("duplicate",option+1) == 0)
4641 {
4642 if (*option == '+')
4643 break;
4644 i++;
cristye81f5522014-05-07 01:25:59 +00004645 if (i == (ssize_t) argc)
cristyecb10ff2011-03-22 13:14:03 +00004646 ThrowMogrifyException(OptionError,"MissingArgument",option);
4647 if (IsGeometry(argv[i]) == MagickFalse)
4648 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4649 break;
4650 }
cristy22879752009-10-25 23:55:40 +00004651 if (LocaleCompare("duration",option+1) == 0)
4652 {
4653 if (*option == '+')
4654 break;
4655 i++;
cristye81f5522014-05-07 01:25:59 +00004656 if (i == (ssize_t) argc)
cristy22879752009-10-25 23:55:40 +00004657 ThrowMogrifyException(OptionError,"MissingArgument",option);
4658 if (IsGeometry(argv[i]) == MagickFalse)
4659 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4660 break;
4661 }
cristy3ed852e2009-09-05 21:47:34 +00004662 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4663 }
4664 case 'e':
4665 {
4666 if (LocaleCompare("edge",option+1) == 0)
4667 {
4668 if (*option == '+')
4669 break;
4670 i++;
cristybb503372010-05-27 20:51:26 +00004671 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004672 ThrowMogrifyException(OptionError,"MissingArgument",option);
4673 if (IsGeometry(argv[i]) == MagickFalse)
4674 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4675 break;
4676 }
4677 if (LocaleCompare("emboss",option+1) == 0)
4678 {
4679 if (*option == '+')
4680 break;
4681 i++;
cristybb503372010-05-27 20:51:26 +00004682 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004683 ThrowMogrifyException(OptionError,"MissingArgument",option);
4684 if (IsGeometry(argv[i]) == MagickFalse)
4685 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4686 break;
4687 }
4688 if (LocaleCompare("encipher",option+1) == 0)
4689 {
4690 if (*option == '+')
4691 break;
4692 i++;
cristybb503372010-05-27 20:51:26 +00004693 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004694 ThrowMogrifyException(OptionError,"MissingArgument",option);
4695 break;
4696 }
4697 if (LocaleCompare("encoding",option+1) == 0)
4698 {
4699 if (*option == '+')
4700 break;
4701 i++;
cristybb503372010-05-27 20:51:26 +00004702 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004703 ThrowMogrifyException(OptionError,"MissingArgument",option);
4704 break;
4705 }
4706 if (LocaleCompare("endian",option+1) == 0)
4707 {
cristybb503372010-05-27 20:51:26 +00004708 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004709 endian;
4710
4711 if (*option == '+')
4712 break;
4713 i++;
cristybb503372010-05-27 20:51:26 +00004714 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004715 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004716 endian=ParseCommandOption(MagickEndianOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004717 if (endian < 0)
4718 ThrowMogrifyException(OptionError,"UnrecognizedEndianType",
4719 argv[i]);
4720 break;
4721 }
4722 if (LocaleCompare("enhance",option+1) == 0)
4723 break;
4724 if (LocaleCompare("equalize",option+1) == 0)
4725 break;
4726 if (LocaleCompare("evaluate",option+1) == 0)
4727 {
cristybb503372010-05-27 20:51:26 +00004728 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004729 op;
4730
4731 if (*option == '+')
4732 break;
4733 i++;
cristybb503372010-05-27 20:51:26 +00004734 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004735 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004736 op=ParseCommandOption(MagickEvaluateOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004737 if (op < 0)
4738 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4739 argv[i]);
4740 i++;
cristye81f5522014-05-07 01:25:59 +00004741 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004742 ThrowMogrifyException(OptionError,"MissingArgument",option);
4743 if (IsGeometry(argv[i]) == MagickFalse)
4744 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4745 break;
4746 }
cristyd18ae7c2010-03-07 17:39:52 +00004747 if (LocaleCompare("evaluate-sequence",option+1) == 0)
4748 {
cristybb503372010-05-27 20:51:26 +00004749 ssize_t
cristyd18ae7c2010-03-07 17:39:52 +00004750 op;
4751
4752 if (*option == '+')
4753 break;
4754 i++;
cristybb503372010-05-27 20:51:26 +00004755 if (i == (ssize_t) argc)
cristyd18ae7c2010-03-07 17:39:52 +00004756 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004757 op=ParseCommandOption(MagickEvaluateOptions,MagickFalse,argv[i]);
cristyd18ae7c2010-03-07 17:39:52 +00004758 if (op < 0)
4759 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4760 argv[i]);
4761 break;
4762 }
cristy3ed852e2009-09-05 21:47:34 +00004763 if (LocaleCompare("extent",option+1) == 0)
4764 {
4765 if (*option == '+')
4766 break;
4767 i++;
cristybb503372010-05-27 20:51:26 +00004768 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004769 ThrowMogrifyException(OptionError,"MissingArgument",option);
4770 if (IsGeometry(argv[i]) == MagickFalse)
4771 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4772 break;
4773 }
4774 if (LocaleCompare("extract",option+1) == 0)
4775 {
4776 if (*option == '+')
4777 break;
4778 i++;
cristybb503372010-05-27 20:51:26 +00004779 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004780 ThrowMogrifyException(OptionError,"MissingArgument",option);
4781 if (IsGeometry(argv[i]) == MagickFalse)
4782 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4783 break;
4784 }
4785 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4786 }
4787 case 'f':
4788 {
4789 if (LocaleCompare("family",option+1) == 0)
4790 {
4791 if (*option == '+')
4792 break;
4793 i++;
cristye81f5522014-05-07 01:25:59 +00004794 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004795 ThrowMogrifyException(OptionError,"MissingArgument",option);
4796 break;
4797 }
cristy14154222012-06-15 23:21:49 +00004798 if (LocaleCompare("features",option+1) == 0)
4799 {
4800 if (*option == '+')
4801 break;
4802 i++;
cristye81f5522014-05-07 01:25:59 +00004803 if (i == (ssize_t) argc)
cristy14154222012-06-15 23:21:49 +00004804 ThrowMogrifyException(OptionError,"MissingArgument",option);
4805 if (IsGeometry(argv[i]) == MagickFalse)
4806 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4807 break;
4808 }
cristy3ed852e2009-09-05 21:47:34 +00004809 if (LocaleCompare("fill",option+1) == 0)
4810 {
4811 if (*option == '+')
4812 break;
4813 i++;
cristybb503372010-05-27 20:51:26 +00004814 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004815 ThrowMogrifyException(OptionError,"MissingArgument",option);
4816 break;
4817 }
4818 if (LocaleCompare("filter",option+1) == 0)
4819 {
cristybb503372010-05-27 20:51:26 +00004820 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004821 filter;
4822
4823 if (*option == '+')
4824 break;
4825 i++;
cristybb503372010-05-27 20:51:26 +00004826 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004827 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004828 filter=ParseCommandOption(MagickFilterOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004829 if (filter < 0)
4830 ThrowMogrifyException(OptionError,"UnrecognizedImageFilter",
4831 argv[i]);
4832 break;
4833 }
4834 if (LocaleCompare("flatten",option+1) == 0)
4835 break;
4836 if (LocaleCompare("flip",option+1) == 0)
4837 break;
4838 if (LocaleCompare("flop",option+1) == 0)
4839 break;
4840 if (LocaleCompare("floodfill",option+1) == 0)
4841 {
4842 if (*option == '+')
4843 break;
4844 i++;
cristybb503372010-05-27 20:51:26 +00004845 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004846 ThrowMogrifyException(OptionError,"MissingArgument",option);
4847 if (IsGeometry(argv[i]) == MagickFalse)
4848 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4849 i++;
cristybb503372010-05-27 20:51:26 +00004850 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004851 ThrowMogrifyException(OptionError,"MissingArgument",option);
4852 break;
4853 }
4854 if (LocaleCompare("font",option+1) == 0)
4855 {
4856 if (*option == '+')
4857 break;
4858 i++;
cristybb503372010-05-27 20:51:26 +00004859 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004860 ThrowMogrifyException(OptionError,"MissingArgument",option);
4861 break;
4862 }
4863 if (LocaleCompare("format",option+1) == 0)
4864 {
cristy151b66d2015-04-15 10:50:31 +00004865 (void) CopyMagickString(argv[i]+1,"sans",MagickPathExtent);
cristy3ed852e2009-09-05 21:47:34 +00004866 (void) CloneString(&format,(char *) NULL);
4867 if (*option == '+')
4868 break;
4869 i++;
cristybb503372010-05-27 20:51:26 +00004870 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004871 ThrowMogrifyException(OptionError,"MissingArgument",option);
4872 (void) CloneString(&format,argv[i]);
cristy151b66d2015-04-15 10:50:31 +00004873 (void) CopyMagickString(image_info->filename,format,MagickPathExtent);
cristy3ed852e2009-09-05 21:47:34 +00004874 (void) ConcatenateMagickString(image_info->filename,":",
cristy151b66d2015-04-15 10:50:31 +00004875 MagickPathExtent);
cristyd965a422010-03-03 17:47:35 +00004876 (void) SetImageInfo(image_info,0,exception);
cristy3ed852e2009-09-05 21:47:34 +00004877 if (*image_info->magick == '\0')
4878 ThrowMogrifyException(OptionError,"UnrecognizedImageFormat",
4879 format);
4880 break;
4881 }
4882 if (LocaleCompare("frame",option+1) == 0)
4883 {
4884 if (*option == '+')
4885 break;
4886 i++;
cristybb503372010-05-27 20:51:26 +00004887 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004888 ThrowMogrifyException(OptionError,"MissingArgument",option);
4889 if (IsGeometry(argv[i]) == MagickFalse)
4890 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4891 break;
4892 }
4893 if (LocaleCompare("function",option+1) == 0)
4894 {
cristybb503372010-05-27 20:51:26 +00004895 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004896 op;
4897
4898 if (*option == '+')
4899 break;
4900 i++;
cristybb503372010-05-27 20:51:26 +00004901 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004902 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004903 op=ParseCommandOption(MagickFunctionOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004904 if (op < 0)
4905 ThrowMogrifyException(OptionError,"UnrecognizedFunction",argv[i]);
4906 i++;
cristye81f5522014-05-07 01:25:59 +00004907 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004908 ThrowMogrifyException(OptionError,"MissingArgument",option);
4909 break;
4910 }
4911 if (LocaleCompare("fuzz",option+1) == 0)
4912 {
4913 if (*option == '+')
4914 break;
4915 i++;
cristybb503372010-05-27 20:51:26 +00004916 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004917 ThrowMogrifyException(OptionError,"MissingArgument",option);
4918 if (IsGeometry(argv[i]) == MagickFalse)
4919 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4920 break;
4921 }
4922 if (LocaleCompare("fx",option+1) == 0)
4923 {
4924 if (*option == '+')
4925 break;
4926 i++;
cristye81f5522014-05-07 01:25:59 +00004927 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004928 ThrowMogrifyException(OptionError,"MissingArgument",option);
4929 break;
4930 }
4931 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4932 }
4933 case 'g':
4934 {
4935 if (LocaleCompare("gamma",option+1) == 0)
4936 {
4937 i++;
cristybb503372010-05-27 20:51:26 +00004938 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004939 ThrowMogrifyException(OptionError,"MissingArgument",option);
4940 if (IsGeometry(argv[i]) == MagickFalse)
4941 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4942 break;
4943 }
4944 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
4945 (LocaleCompare("gaussian",option+1) == 0))
4946 {
4947 i++;
cristybb503372010-05-27 20:51:26 +00004948 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004949 ThrowMogrifyException(OptionError,"MissingArgument",option);
4950 if (IsGeometry(argv[i]) == MagickFalse)
4951 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4952 break;
4953 }
4954 if (LocaleCompare("geometry",option+1) == 0)
4955 {
4956 if (*option == '+')
4957 break;
4958 i++;
cristybb503372010-05-27 20:51:26 +00004959 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004960 ThrowMogrifyException(OptionError,"MissingArgument",option);
4961 if (IsGeometry(argv[i]) == MagickFalse)
4962 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4963 break;
4964 }
4965 if (LocaleCompare("gravity",option+1) == 0)
4966 {
cristybb503372010-05-27 20:51:26 +00004967 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004968 gravity;
4969
4970 if (*option == '+')
4971 break;
4972 i++;
cristybb503372010-05-27 20:51:26 +00004973 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004974 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristye0b9b8f2013-03-28 12:39:39 +00004975 gravity=ParseCommandOption(MagickGravityOptions,MagickFalse,
4976 argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004977 if (gravity < 0)
4978 ThrowMogrifyException(OptionError,"UnrecognizedGravityType",
4979 argv[i]);
4980 break;
4981 }
cristye0b9b8f2013-03-28 12:39:39 +00004982 if (LocaleCompare("grayscale",option+1) == 0)
4983 {
4984 ssize_t
cristybc008152013-03-28 16:52:59 +00004985 method;
cristye0b9b8f2013-03-28 12:39:39 +00004986
4987 if (*option == '+')
4988 break;
4989 i++;
cristye81f5522014-05-07 01:25:59 +00004990 if (i == (ssize_t) argc)
cristye0b9b8f2013-03-28 12:39:39 +00004991 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristybc008152013-03-28 16:52:59 +00004992 method=ParseCommandOption(MagickPixelIntensityOptions,MagickFalse,
cristye0b9b8f2013-03-28 12:39:39 +00004993 argv[i]);
cristybc008152013-03-28 16:52:59 +00004994 if (method < 0)
cristye0b9b8f2013-03-28 12:39:39 +00004995 ThrowMogrifyException(OptionError,"UnrecognizedIntensityMethod",
4996 argv[i]);
4997 break;
4998 }
cristy3ed852e2009-09-05 21:47:34 +00004999 if (LocaleCompare("green-primary",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 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5011 }
5012 case 'h':
5013 {
5014 if (LocaleCompare("hald-clut",option+1) == 0)
5015 break;
5016 if ((LocaleCompare("help",option+1) == 0) ||
5017 (LocaleCompare("-help",option+1) == 0))
5018 return(MogrifyUsage());
cristy2fc10e52014-04-26 14:13:53 +00005019 if (LocaleCompare("hough-lines",option+1) == 0)
5020 {
5021 if (*option == '+')
5022 break;
5023 i++;
5024 if (i == (ssize_t) argc)
5025 ThrowMogrifyException(OptionError,"MissingArgument",option);
5026 if (IsGeometry(argv[i]) == MagickFalse)
5027 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5028 break;
5029 }
cristy3ed852e2009-09-05 21:47:34 +00005030 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5031 }
5032 case 'i':
5033 {
5034 if (LocaleCompare("identify",option+1) == 0)
5035 break;
5036 if (LocaleCompare("idft",option+1) == 0)
5037 break;
5038 if (LocaleCompare("implode",option+1) == 0)
5039 {
5040 if (*option == '+')
5041 break;
5042 i++;
cristybb503372010-05-27 20:51:26 +00005043 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005044 ThrowMogrifyException(OptionError,"MissingArgument",option);
5045 if (IsGeometry(argv[i]) == MagickFalse)
5046 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5047 break;
5048 }
cristy70e9f682013-03-12 22:31:22 +00005049 if (LocaleCompare("intensity",option+1) == 0)
5050 {
5051 ssize_t
5052 intensity;
5053
5054 if (*option == '+')
5055 break;
5056 i++;
cristye81f5522014-05-07 01:25:59 +00005057 if (i == (ssize_t) argc)
cristy70e9f682013-03-12 22:31:22 +00005058 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristye0b9b8f2013-03-28 12:39:39 +00005059 intensity=ParseCommandOption(MagickPixelIntensityOptions,
5060 MagickFalse,argv[i]);
cristy70e9f682013-03-12 22:31:22 +00005061 if (intensity < 0)
cristye0b9b8f2013-03-28 12:39:39 +00005062 ThrowMogrifyException(OptionError,
5063 "UnrecognizedPixelIntensityMethod",argv[i]);
cristy70e9f682013-03-12 22:31:22 +00005064 break;
5065 }
cristy3ed852e2009-09-05 21:47:34 +00005066 if (LocaleCompare("intent",option+1) == 0)
5067 {
cristybb503372010-05-27 20:51:26 +00005068 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005069 intent;
5070
5071 if (*option == '+')
5072 break;
5073 i++;
cristye81f5522014-05-07 01:25:59 +00005074 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005075 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005076 intent=ParseCommandOption(MagickIntentOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005077 if (intent < 0)
5078 ThrowMogrifyException(OptionError,"UnrecognizedIntentType",
5079 argv[i]);
5080 break;
5081 }
5082 if (LocaleCompare("interlace",option+1) == 0)
5083 {
cristybb503372010-05-27 20:51:26 +00005084 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005085 interlace;
5086
5087 if (*option == '+')
5088 break;
5089 i++;
cristybb503372010-05-27 20:51:26 +00005090 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005091 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005092 interlace=ParseCommandOption(MagickInterlaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005093 argv[i]);
5094 if (interlace < 0)
5095 ThrowMogrifyException(OptionError,"UnrecognizedInterlaceType",
5096 argv[i]);
5097 break;
5098 }
cristyb32b90a2009-09-07 21:45:48 +00005099 if (LocaleCompare("interline-spacing",option+1) == 0)
5100 {
5101 if (*option == '+')
5102 break;
5103 i++;
cristye81f5522014-05-07 01:25:59 +00005104 if (i == (ssize_t) argc)
cristyb32b90a2009-09-07 21:45:48 +00005105 ThrowMogrifyException(OptionError,"MissingArgument",option);
5106 if (IsGeometry(argv[i]) == MagickFalse)
5107 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5108 break;
5109 }
cristy3ed852e2009-09-05 21:47:34 +00005110 if (LocaleCompare("interpolate",option+1) == 0)
5111 {
cristybb503372010-05-27 20:51:26 +00005112 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005113 interpolate;
5114
5115 if (*option == '+')
5116 break;
5117 i++;
cristybb503372010-05-27 20:51:26 +00005118 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005119 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005120 interpolate=ParseCommandOption(MagickInterpolateOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005121 argv[i]);
5122 if (interpolate < 0)
5123 ThrowMogrifyException(OptionError,"UnrecognizedInterpolateMethod",
5124 argv[i]);
5125 break;
5126 }
5127 if (LocaleCompare("interword-spacing",option+1) == 0)
5128 {
5129 if (*option == '+')
5130 break;
5131 i++;
cristye81f5522014-05-07 01:25:59 +00005132 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005133 ThrowMogrifyException(OptionError,"MissingArgument",option);
5134 if (IsGeometry(argv[i]) == MagickFalse)
5135 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5136 break;
5137 }
5138 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5139 }
5140 case 'k':
5141 {
5142 if (LocaleCompare("kerning",option+1) == 0)
5143 {
5144 if (*option == '+')
5145 break;
5146 i++;
cristye81f5522014-05-07 01:25:59 +00005147 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005148 ThrowMogrifyException(OptionError,"MissingArgument",option);
5149 if (IsGeometry(argv[i]) == MagickFalse)
5150 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5151 break;
5152 }
cristy3b207f82014-09-27 14:21:20 +00005153 if (LocaleCompare("kuwahara",option+1) == 0)
5154 {
5155 i++;
5156 if (i == (ssize_t) argc)
5157 ThrowMogrifyException(OptionError,"MissingArgument",option);
5158 if (IsGeometry(argv[i]) == MagickFalse)
5159 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5160 break;
5161 }
cristy3ed852e2009-09-05 21:47:34 +00005162 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5163 }
5164 case 'l':
5165 {
5166 if (LocaleCompare("label",option+1) == 0)
5167 {
5168 if (*option == '+')
5169 break;
5170 i++;
cristybb503372010-05-27 20:51:26 +00005171 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005172 ThrowMogrifyException(OptionError,"MissingArgument",option);
5173 break;
5174 }
5175 if (LocaleCompare("lat",option+1) == 0)
5176 {
5177 if (*option == '+')
5178 break;
5179 i++;
cristybb503372010-05-27 20:51:26 +00005180 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005181 ThrowMogrifyException(OptionError,"MissingArgument",option);
5182 if (IsGeometry(argv[i]) == MagickFalse)
5183 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5184 }
5185 if (LocaleCompare("layers",option+1) == 0)
5186 {
cristybb503372010-05-27 20:51:26 +00005187 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005188 type;
5189
5190 if (*option == '+')
5191 break;
5192 i++;
cristye81f5522014-05-07 01:25:59 +00005193 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005194 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005195 type=ParseCommandOption(MagickLayerOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005196 if (type < 0)
5197 ThrowMogrifyException(OptionError,"UnrecognizedLayerMethod",
5198 argv[i]);
5199 break;
5200 }
5201 if (LocaleCompare("level",option+1) == 0)
5202 {
5203 i++;
cristybb503372010-05-27 20:51:26 +00005204 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005205 ThrowMogrifyException(OptionError,"MissingArgument",option);
5206 if (IsGeometry(argv[i]) == MagickFalse)
5207 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5208 break;
5209 }
5210 if (LocaleCompare("level-colors",option+1) == 0)
5211 {
5212 i++;
cristybb503372010-05-27 20:51:26 +00005213 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005214 ThrowMogrifyException(OptionError,"MissingArgument",option);
5215 break;
5216 }
cristy3ed852e2009-09-05 21:47:34 +00005217 if (LocaleCompare("limit",option+1) == 0)
5218 {
5219 char
5220 *p;
5221
5222 double
5223 value;
5224
cristybb503372010-05-27 20:51:26 +00005225 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005226 resource;
5227
5228 if (*option == '+')
5229 break;
5230 i++;
cristybb503372010-05-27 20:51:26 +00005231 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005232 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005233 resource=ParseCommandOption(MagickResourceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005234 argv[i]);
5235 if (resource < 0)
5236 ThrowMogrifyException(OptionError,"UnrecognizedResourceType",
5237 argv[i]);
5238 i++;
cristybb503372010-05-27 20:51:26 +00005239 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005240 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristydbdd0e32011-11-04 23:29:40 +00005241 value=StringToDouble(argv[i],&p);
cristyda16f162011-02-19 23:52:17 +00005242 (void) value;
cristy3ed852e2009-09-05 21:47:34 +00005243 if ((p == argv[i]) && (LocaleCompare("unlimited",argv[i]) != 0))
5244 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5245 break;
5246 }
5247 if (LocaleCompare("liquid-rescale",option+1) == 0)
5248 {
5249 i++;
cristybb503372010-05-27 20:51:26 +00005250 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005251 ThrowMogrifyException(OptionError,"MissingArgument",option);
5252 if (IsGeometry(argv[i]) == MagickFalse)
5253 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5254 break;
5255 }
5256 if (LocaleCompare("list",option+1) == 0)
5257 {
cristybb503372010-05-27 20:51:26 +00005258 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005259 list;
5260
5261 if (*option == '+')
5262 break;
5263 i++;
cristybb503372010-05-27 20:51:26 +00005264 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005265 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005266 list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005267 if (list < 0)
5268 ThrowMogrifyException(OptionError,"UnrecognizedListType",argv[i]);
cristyaeb2cbc2010-05-07 13:28:58 +00005269 status=MogrifyImageInfo(image_info,(int) (i-j+1),(const char **)
cristy3ed852e2009-09-05 21:47:34 +00005270 argv+j,exception);
cristy32ce2392014-09-24 19:08:53 +00005271 return(status == 0 ? MagickTrue : MagickFalse);
cristy3ed852e2009-09-05 21:47:34 +00005272 }
5273 if (LocaleCompare("log",option+1) == 0)
5274 {
5275 if (*option == '+')
5276 break;
5277 i++;
cristybb503372010-05-27 20:51:26 +00005278 if ((i == (ssize_t) argc) ||
cristy3ed852e2009-09-05 21:47:34 +00005279 (strchr(argv[i],'%') == (char *) NULL))
5280 ThrowMogrifyException(OptionError,"MissingArgument",option);
5281 break;
5282 }
5283 if (LocaleCompare("loop",option+1) == 0)
5284 {
5285 if (*option == '+')
5286 break;
5287 i++;
cristybb503372010-05-27 20:51:26 +00005288 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005289 ThrowMogrifyException(OptionError,"MissingArgument",option);
5290 if (IsGeometry(argv[i]) == MagickFalse)
5291 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5292 break;
5293 }
5294 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5295 }
5296 case 'm':
5297 {
5298 if (LocaleCompare("map",option+1) == 0)
5299 {
5300 global_colormap=(*option == '+') ? MagickTrue : MagickFalse;
5301 if (*option == '+')
5302 break;
5303 i++;
cristybb503372010-05-27 20:51:26 +00005304 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005305 ThrowMogrifyException(OptionError,"MissingArgument",option);
5306 break;
5307 }
5308 if (LocaleCompare("mask",option+1) == 0)
5309 {
5310 if (*option == '+')
5311 break;
5312 i++;
cristybb503372010-05-27 20:51:26 +00005313 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005314 ThrowMogrifyException(OptionError,"MissingArgument",option);
5315 break;
5316 }
cristy52ad9e92013-02-08 23:23:29 +00005317 if (LocaleCompare("matte",option+1) == 0)
5318 break;
cristy3ed852e2009-09-05 21:47:34 +00005319 if (LocaleCompare("mattecolor",option+1) == 0)
5320 {
5321 if (*option == '+')
5322 break;
5323 i++;
cristybb503372010-05-27 20:51:26 +00005324 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005325 ThrowMogrifyException(OptionError,"MissingArgument",option);
5326 break;
5327 }
cristy52ad9e92013-02-08 23:23:29 +00005328 if (LocaleCompare("maximum",option+1) == 0)
5329 break;
cristy2fc10e52014-04-26 14:13:53 +00005330 if (LocaleCompare("mean-shift",option+1) == 0)
5331 {
5332 if (*option == '+')
5333 break;
5334 i++;
5335 if (i == (ssize_t) argc)
5336 ThrowMogrifyException(OptionError,"MissingArgument",option);
5337 if (IsGeometry(argv[i]) == MagickFalse)
5338 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5339 break;
5340 }
5341 if (LocaleCompare("median",option+1) == 0)
5342 {
5343 if (*option == '+')
5344 break;
5345 i++;
5346 if (i == (ssize_t) argc)
5347 ThrowMogrifyException(OptionError,"MissingArgument",option);
5348 if (IsGeometry(argv[i]) == MagickFalse)
5349 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5350 break;
5351 }
cristyb92495a2013-08-20 00:10:59 +00005352 if (LocaleCompare("metric",option+1) == 0)
5353 {
5354 ssize_t
5355 type;
5356
5357 if (*option == '+')
5358 break;
5359 i++;
5360 if (i == (ssize_t) argc)
5361 ThrowMogrifyException(OptionError,"MissingArgument",option);
5362 type=ParseCommandOption(MagickMetricOptions,MagickTrue,argv[i]);
5363 if (type < 0)
5364 ThrowMogrifyException(OptionError,"UnrecognizedMetricType",
5365 argv[i]);
5366 break;
5367 }
cristy52ad9e92013-02-08 23:23:29 +00005368 if (LocaleCompare("minimum",option+1) == 0)
5369 break;
cristy3ed852e2009-09-05 21:47:34 +00005370 if (LocaleCompare("modulate",option+1) == 0)
5371 {
5372 if (*option == '+')
5373 break;
5374 i++;
cristybb503372010-05-27 20:51:26 +00005375 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005376 ThrowMogrifyException(OptionError,"MissingArgument",option);
5377 if (IsGeometry(argv[i]) == MagickFalse)
5378 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5379 break;
5380 }
cristy52ad9e92013-02-08 23:23:29 +00005381 if (LocaleCompare("mode",option+1) == 0)
5382 {
5383 if (*option == '+')
5384 break;
5385 i++;
5386 if (i == (ssize_t) argc)
5387 ThrowMogrifyException(OptionError,"MissingArgument",option);
5388 if (IsGeometry(argv[i]) == MagickFalse)
5389 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5390 break;
5391 }
cristy3ed852e2009-09-05 21:47:34 +00005392 if (LocaleCompare("monitor",option+1) == 0)
5393 break;
5394 if (LocaleCompare("monochrome",option+1) == 0)
5395 break;
5396 if (LocaleCompare("morph",option+1) == 0)
5397 {
5398 if (*option == '+')
5399 break;
5400 i++;
cristye81f5522014-05-07 01:25:59 +00005401 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005402 ThrowMogrifyException(OptionError,"MissingArgument",option);
5403 if (IsGeometry(argv[i]) == MagickFalse)
5404 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5405 break;
5406 }
anthony29188a82010-01-22 10:12:34 +00005407 if (LocaleCompare("morphology",option+1) == 0)
5408 {
anthony29188a82010-01-22 10:12:34 +00005409 char
cristy151b66d2015-04-15 10:50:31 +00005410 token[MagickPathExtent];
anthony29188a82010-01-22 10:12:34 +00005411
cristyb6bd4ad2010-08-08 01:12:27 +00005412 KernelInfo
5413 *kernel_info;
5414
5415 ssize_t
5416 op;
5417
anthony29188a82010-01-22 10:12:34 +00005418 i++;
cristybb503372010-05-27 20:51:26 +00005419 if (i == (ssize_t) argc)
anthony29188a82010-01-22 10:12:34 +00005420 ThrowMogrifyException(OptionError,"MissingArgument",option);
5421 GetMagickToken(argv[i],NULL,token);
cristy042ee782011-04-22 18:48:30 +00005422 op=ParseCommandOption(MagickMorphologyOptions,MagickFalse,token);
anthony29188a82010-01-22 10:12:34 +00005423 if (op < 0)
5424 ThrowMogrifyException(OptionError,"UnrecognizedMorphologyMethod",
cristyf0c78232010-03-15 12:53:40 +00005425 token);
anthony29188a82010-01-22 10:12:34 +00005426 i++;
cristye81f5522014-05-07 01:25:59 +00005427 if (i == (ssize_t) argc)
anthony29188a82010-01-22 10:12:34 +00005428 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy2c57b742014-10-31 00:40:34 +00005429 kernel_info=AcquireKernelInfo(argv[i],exception);
cristyb6bd4ad2010-08-08 01:12:27 +00005430 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00005431 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00005432 kernel_info=DestroyKernelInfo(kernel_info);
anthony29188a82010-01-22 10:12:34 +00005433 break;
5434 }
cristy3ed852e2009-09-05 21:47:34 +00005435 if (LocaleCompare("mosaic",option+1) == 0)
5436 break;
5437 if (LocaleCompare("motion-blur",option+1) == 0)
5438 {
5439 if (*option == '+')
5440 break;
5441 i++;
cristybb503372010-05-27 20:51:26 +00005442 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005443 ThrowMogrifyException(OptionError,"MissingArgument",option);
5444 if (IsGeometry(argv[i]) == MagickFalse)
5445 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5446 break;
5447 }
5448 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5449 }
5450 case 'n':
5451 {
5452 if (LocaleCompare("negate",option+1) == 0)
5453 break;
5454 if (LocaleCompare("noise",option+1) == 0)
5455 {
5456 i++;
cristybb503372010-05-27 20:51:26 +00005457 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005458 ThrowMogrifyException(OptionError,"MissingArgument",option);
5459 if (*option == '+')
5460 {
cristybb503372010-05-27 20:51:26 +00005461 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005462 noise;
5463
cristy042ee782011-04-22 18:48:30 +00005464 noise=ParseCommandOption(MagickNoiseOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005465 if (noise < 0)
5466 ThrowMogrifyException(OptionError,"UnrecognizedNoiseType",
5467 argv[i]);
5468 break;
5469 }
5470 if (IsGeometry(argv[i]) == MagickFalse)
5471 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5472 break;
5473 }
5474 if (LocaleCompare("noop",option+1) == 0)
5475 break;
5476 if (LocaleCompare("normalize",option+1) == 0)
5477 break;
5478 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5479 }
5480 case 'o':
5481 {
5482 if (LocaleCompare("opaque",option+1) == 0)
5483 {
cristy3ed852e2009-09-05 21:47:34 +00005484 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 break;
5488 }
5489 if (LocaleCompare("ordered-dither",option+1) == 0)
5490 {
5491 if (*option == '+')
5492 break;
5493 i++;
cristybb503372010-05-27 20:51:26 +00005494 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005495 ThrowMogrifyException(OptionError,"MissingArgument",option);
5496 break;
5497 }
5498 if (LocaleCompare("orient",option+1) == 0)
5499 {
cristybb503372010-05-27 20:51:26 +00005500 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005501 orientation;
5502
5503 orientation=UndefinedOrientation;
5504 if (*option == '+')
5505 break;
5506 i++;
cristye81f5522014-05-07 01:25:59 +00005507 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005508 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005509 orientation=ParseCommandOption(MagickOrientationOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005510 argv[i]);
5511 if (orientation < 0)
5512 ThrowMogrifyException(OptionError,"UnrecognizedImageOrientation",
5513 argv[i]);
5514 break;
5515 }
5516 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5517 }
5518 case 'p':
5519 {
5520 if (LocaleCompare("page",option+1) == 0)
5521 {
5522 if (*option == '+')
5523 break;
5524 i++;
cristybb503372010-05-27 20:51:26 +00005525 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005526 ThrowMogrifyException(OptionError,"MissingArgument",option);
5527 break;
5528 }
5529 if (LocaleCompare("paint",option+1) == 0)
5530 {
5531 if (*option == '+')
5532 break;
5533 i++;
cristybb503372010-05-27 20:51:26 +00005534 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005535 ThrowMogrifyException(OptionError,"MissingArgument",option);
5536 if (IsGeometry(argv[i]) == MagickFalse)
5537 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5538 break;
5539 }
5540 if (LocaleCompare("path",option+1) == 0)
5541 {
5542 (void) CloneString(&path,(char *) NULL);
5543 if (*option == '+')
5544 break;
5545 i++;
cristybb503372010-05-27 20:51:26 +00005546 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005547 ThrowMogrifyException(OptionError,"MissingArgument",option);
5548 (void) CloneString(&path,argv[i]);
5549 break;
5550 }
cristyab2b40a2012-11-04 01:43:29 +00005551 if (LocaleCompare("perceptible",option+1) == 0)
5552 {
5553 if (*option == '+')
5554 break;
5555 i++;
5556 if (i == (ssize_t) argc)
5557 ThrowMogrifyException(OptionError,"MissingArgument",option);
5558 if (IsGeometry(argv[i]) == MagickFalse)
5559 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5560 break;
5561 }
cristy3ed852e2009-09-05 21:47:34 +00005562 if (LocaleCompare("pointsize",option+1) == 0)
5563 {
5564 if (*option == '+')
5565 break;
5566 i++;
cristybb503372010-05-27 20:51:26 +00005567 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005568 ThrowMogrifyException(OptionError,"MissingArgument",option);
5569 if (IsGeometry(argv[i]) == MagickFalse)
5570 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5571 break;
5572 }
5573 if (LocaleCompare("polaroid",option+1) == 0)
5574 {
5575 if (*option == '+')
5576 break;
5577 i++;
cristybb503372010-05-27 20:51:26 +00005578 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005579 ThrowMogrifyException(OptionError,"MissingArgument",option);
5580 if (IsGeometry(argv[i]) == MagickFalse)
5581 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5582 break;
5583 }
cristy8cdfb342012-11-11 21:44:36 +00005584 if (LocaleCompare("poly",option+1) == 0)
5585 {
5586 if (*option == '+')
5587 break;
5588 i++;
5589 if (i == (ssize_t) argc)
5590 ThrowMogrifyException(OptionError,"MissingArgument",option);
5591 if (IsGeometry(argv[i]) == MagickFalse)
5592 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5593 break;
5594 }
cristy3ed852e2009-09-05 21:47:34 +00005595 if (LocaleCompare("posterize",option+1) == 0)
5596 {
5597 if (*option == '+')
5598 break;
5599 i++;
cristybb503372010-05-27 20:51:26 +00005600 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005601 ThrowMogrifyException(OptionError,"MissingArgument",option);
5602 if (IsGeometry(argv[i]) == MagickFalse)
5603 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5604 break;
5605 }
cristye7f51092010-01-17 00:39:37 +00005606 if (LocaleCompare("precision",option+1) == 0)
5607 {
5608 if (*option == '+')
5609 break;
5610 i++;
cristybb503372010-05-27 20:51:26 +00005611 if (i == (ssize_t) argc)
cristye7f51092010-01-17 00:39:37 +00005612 ThrowMogrifyException(OptionError,"MissingArgument",option);
5613 if (IsGeometry(argv[i]) == MagickFalse)
5614 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5615 break;
5616 }
cristy3ed852e2009-09-05 21:47:34 +00005617 if (LocaleCompare("print",option+1) == 0)
5618 {
5619 if (*option == '+')
5620 break;
5621 i++;
cristybb503372010-05-27 20:51:26 +00005622 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005623 ThrowMogrifyException(OptionError,"MissingArgument",option);
5624 break;
5625 }
5626 if (LocaleCompare("process",option+1) == 0)
5627 {
5628 if (*option == '+')
5629 break;
5630 i++;
cristye81f5522014-05-07 01:25:59 +00005631 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005632 ThrowMogrifyException(OptionError,"MissingArgument",option);
5633 break;
5634 }
5635 if (LocaleCompare("profile",option+1) == 0)
5636 {
5637 i++;
cristybb503372010-05-27 20:51:26 +00005638 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005639 ThrowMogrifyException(OptionError,"MissingArgument",option);
5640 break;
5641 }
5642 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5643 }
5644 case 'q':
5645 {
5646 if (LocaleCompare("quality",option+1) == 0)
5647 {
5648 if (*option == '+')
5649 break;
5650 i++;
cristybb503372010-05-27 20:51:26 +00005651 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005652 ThrowMogrifyException(OptionError,"MissingArgument",option);
5653 if (IsGeometry(argv[i]) == MagickFalse)
5654 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5655 break;
5656 }
5657 if (LocaleCompare("quantize",option+1) == 0)
5658 {
cristybb503372010-05-27 20:51:26 +00005659 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005660 colorspace;
5661
5662 if (*option == '+')
5663 break;
5664 i++;
cristye81f5522014-05-07 01:25:59 +00005665 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005666 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005667 colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005668 argv[i]);
5669 if (colorspace < 0)
5670 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
5671 argv[i]);
5672 break;
5673 }
5674 if (LocaleCompare("quiet",option+1) == 0)
5675 break;
5676 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5677 }
5678 case 'r':
5679 {
dirk6d612cf2014-03-13 21:17:23 +00005680 if (LocaleCompare("rotational-blur",option+1) == 0)
cristy3ed852e2009-09-05 21:47:34 +00005681 {
5682 i++;
cristybb503372010-05-27 20:51:26 +00005683 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005684 ThrowMogrifyException(OptionError,"MissingArgument",option);
5685 if (IsGeometry(argv[i]) == MagickFalse)
5686 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5687 break;
5688 }
5689 if (LocaleCompare("raise",option+1) == 0)
5690 {
5691 i++;
cristybb503372010-05-27 20:51:26 +00005692 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005693 ThrowMogrifyException(OptionError,"MissingArgument",option);
5694 if (IsGeometry(argv[i]) == MagickFalse)
5695 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5696 break;
5697 }
5698 if (LocaleCompare("random-threshold",option+1) == 0)
5699 {
5700 if (*option == '+')
5701 break;
5702 i++;
cristybb503372010-05-27 20:51:26 +00005703 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005704 ThrowMogrifyException(OptionError,"MissingArgument",option);
5705 if (IsGeometry(argv[i]) == MagickFalse)
5706 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5707 break;
5708 }
cristy327030c2015-07-25 18:05:50 +00005709 if (LocaleCompare("read-mask",option+1) == 0)
5710 {
5711 if (*option == '+')
5712 break;
5713 i++;
5714 if (i == (ssize_t) argc)
5715 ThrowMogrifyException(OptionError,"MissingArgument",option);
5716 break;
5717 }
cristy3ed852e2009-09-05 21:47:34 +00005718 if (LocaleCompare("red-primary",option+1) == 0)
5719 {
5720 if (*option == '+')
5721 break;
5722 i++;
cristybb503372010-05-27 20:51:26 +00005723 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005724 ThrowMogrifyException(OptionError,"MissingArgument",option);
5725 if (IsGeometry(argv[i]) == MagickFalse)
5726 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5727 }
cristy9f2083a2010-04-22 19:48:05 +00005728 if (LocaleCompare("regard-warnings",option+1) == 0)
5729 break;
cristy3ed852e2009-09-05 21:47:34 +00005730 if (LocaleCompare("region",option+1) == 0)
5731 {
5732 if (*option == '+')
5733 break;
5734 i++;
cristybb503372010-05-27 20:51:26 +00005735 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005736 ThrowMogrifyException(OptionError,"MissingArgument",option);
5737 if (IsGeometry(argv[i]) == MagickFalse)
5738 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5739 break;
5740 }
cristyf0c78232010-03-15 12:53:40 +00005741 if (LocaleCompare("remap",option+1) == 0)
5742 {
5743 if (*option == '+')
5744 break;
5745 i++;
cristye81f5522014-05-07 01:25:59 +00005746 if (i == (ssize_t) argc)
cristyf0c78232010-03-15 12:53:40 +00005747 ThrowMogrifyException(OptionError,"MissingArgument",option);
5748 break;
5749 }
cristy3ed852e2009-09-05 21:47:34 +00005750 if (LocaleCompare("render",option+1) == 0)
5751 break;
5752 if (LocaleCompare("repage",option+1) == 0)
5753 {
5754 if (*option == '+')
5755 break;
5756 i++;
cristybb503372010-05-27 20:51:26 +00005757 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005758 ThrowMogrifyException(OptionError,"MissingArgument",option);
5759 if (IsGeometry(argv[i]) == MagickFalse)
5760 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5761 break;
5762 }
5763 if (LocaleCompare("resample",option+1) == 0)
5764 {
5765 if (*option == '+')
5766 break;
5767 i++;
cristybb503372010-05-27 20:51:26 +00005768 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005769 ThrowMogrifyException(OptionError,"MissingArgument",option);
5770 if (IsGeometry(argv[i]) == MagickFalse)
5771 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5772 break;
5773 }
5774 if (LocaleCompare("resize",option+1) == 0)
5775 {
5776 if (*option == '+')
5777 break;
5778 i++;
cristybb503372010-05-27 20:51:26 +00005779 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005780 ThrowMogrifyException(OptionError,"MissingArgument",option);
5781 if (IsGeometry(argv[i]) == MagickFalse)
5782 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5783 break;
5784 }
cristyebbcfea2011-02-25 02:43:54 +00005785 if (LocaleNCompare("respect-parentheses",option+1,17) == 0)
5786 {
5787 respect_parenthesis=(*option == '-') ? MagickTrue : MagickFalse;
5788 break;
5789 }
cristy3ed852e2009-09-05 21:47:34 +00005790 if (LocaleCompare("reverse",option+1) == 0)
5791 break;
5792 if (LocaleCompare("roll",option+1) == 0)
5793 {
5794 if (*option == '+')
5795 break;
5796 i++;
cristybb503372010-05-27 20:51:26 +00005797 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005798 ThrowMogrifyException(OptionError,"MissingArgument",option);
5799 if (IsGeometry(argv[i]) == MagickFalse)
5800 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5801 break;
5802 }
5803 if (LocaleCompare("rotate",option+1) == 0)
5804 {
5805 i++;
cristybb503372010-05-27 20:51:26 +00005806 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005807 ThrowMogrifyException(OptionError,"MissingArgument",option);
5808 if (IsGeometry(argv[i]) == MagickFalse)
5809 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5810 break;
5811 }
5812 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5813 }
5814 case 's':
5815 {
5816 if (LocaleCompare("sample",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("sampling-factor",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("scale",option+1) == 0)
5839 {
5840 if (*option == '+')
5841 break;
5842 i++;
cristybb503372010-05-27 20:51:26 +00005843 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005844 ThrowMogrifyException(OptionError,"MissingArgument",option);
5845 if (IsGeometry(argv[i]) == MagickFalse)
5846 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5847 break;
5848 }
5849 if (LocaleCompare("scene",option+1) == 0)
5850 {
5851 if (*option == '+')
5852 break;
5853 i++;
cristybb503372010-05-27 20:51:26 +00005854 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005855 ThrowMogrifyException(OptionError,"MissingArgument",option);
5856 if (IsGeometry(argv[i]) == MagickFalse)
5857 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5858 break;
5859 }
5860 if (LocaleCompare("seed",option+1) == 0)
5861 {
5862 if (*option == '+')
5863 break;
5864 i++;
cristybb503372010-05-27 20:51:26 +00005865 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005866 ThrowMogrifyException(OptionError,"MissingArgument",option);
5867 if (IsGeometry(argv[i]) == MagickFalse)
5868 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5869 break;
5870 }
5871 if (LocaleCompare("segment",option+1) == 0)
5872 {
5873 if (*option == '+')
5874 break;
5875 i++;
cristybb503372010-05-27 20:51:26 +00005876 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005877 ThrowMogrifyException(OptionError,"MissingArgument",option);
5878 if (IsGeometry(argv[i]) == MagickFalse)
5879 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5880 break;
5881 }
5882 if (LocaleCompare("selective-blur",option+1) == 0)
5883 {
5884 i++;
cristybb503372010-05-27 20:51:26 +00005885 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005886 ThrowMogrifyException(OptionError,"MissingArgument",option);
5887 if (IsGeometry(argv[i]) == MagickFalse)
5888 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5889 break;
5890 }
5891 if (LocaleCompare("separate",option+1) == 0)
5892 break;
5893 if (LocaleCompare("sepia-tone",option+1) == 0)
5894 {
5895 if (*option == '+')
5896 break;
5897 i++;
cristybb503372010-05-27 20:51:26 +00005898 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005899 ThrowMogrifyException(OptionError,"MissingArgument",option);
5900 if (IsGeometry(argv[i]) == MagickFalse)
5901 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5902 break;
5903 }
5904 if (LocaleCompare("set",option+1) == 0)
5905 {
5906 i++;
cristybb503372010-05-27 20:51:26 +00005907 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005908 ThrowMogrifyException(OptionError,"MissingArgument",option);
5909 if (*option == '+')
5910 break;
5911 i++;
cristybb503372010-05-27 20:51:26 +00005912 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005913 ThrowMogrifyException(OptionError,"MissingArgument",option);
5914 break;
5915 }
5916 if (LocaleCompare("shade",option+1) == 0)
5917 {
5918 i++;
cristybb503372010-05-27 20:51:26 +00005919 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005920 ThrowMogrifyException(OptionError,"MissingArgument",option);
5921 if (IsGeometry(argv[i]) == MagickFalse)
5922 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5923 break;
5924 }
5925 if (LocaleCompare("shadow",option+1) == 0)
5926 {
5927 if (*option == '+')
5928 break;
5929 i++;
cristybb503372010-05-27 20:51:26 +00005930 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005931 ThrowMogrifyException(OptionError,"MissingArgument",option);
5932 if (IsGeometry(argv[i]) == MagickFalse)
5933 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5934 break;
5935 }
5936 if (LocaleCompare("sharpen",option+1) == 0)
5937 {
5938 i++;
cristybb503372010-05-27 20:51:26 +00005939 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005940 ThrowMogrifyException(OptionError,"MissingArgument",option);
5941 if (IsGeometry(argv[i]) == MagickFalse)
5942 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5943 break;
5944 }
5945 if (LocaleCompare("shave",option+1) == 0)
5946 {
5947 if (*option == '+')
5948 break;
5949 i++;
cristybb503372010-05-27 20:51:26 +00005950 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005951 ThrowMogrifyException(OptionError,"MissingArgument",option);
5952 if (IsGeometry(argv[i]) == MagickFalse)
5953 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5954 break;
5955 }
5956 if (LocaleCompare("shear",option+1) == 0)
5957 {
5958 i++;
cristybb503372010-05-27 20:51:26 +00005959 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005960 ThrowMogrifyException(OptionError,"MissingArgument",option);
5961 if (IsGeometry(argv[i]) == MagickFalse)
5962 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5963 break;
5964 }
5965 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
5966 {
5967 i++;
cristye81f5522014-05-07 01:25:59 +00005968 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005969 ThrowMogrifyException(OptionError,"MissingArgument",option);
5970 if (IsGeometry(argv[i]) == MagickFalse)
5971 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5972 break;
5973 }
5974 if (LocaleCompare("size",option+1) == 0)
5975 {
5976 if (*option == '+')
5977 break;
5978 i++;
cristybb503372010-05-27 20:51:26 +00005979 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005980 ThrowMogrifyException(OptionError,"MissingArgument",option);
5981 if (IsGeometry(argv[i]) == MagickFalse)
5982 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5983 break;
5984 }
5985 if (LocaleCompare("sketch",option+1) == 0)
5986 {
5987 if (*option == '+')
5988 break;
5989 i++;
cristybb503372010-05-27 20:51:26 +00005990 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005991 ThrowMogrifyException(OptionError,"MissingArgument",option);
5992 if (IsGeometry(argv[i]) == MagickFalse)
5993 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5994 break;
5995 }
cristy4285d782011-02-09 20:12:28 +00005996 if (LocaleCompare("smush",option+1) == 0)
5997 {
cristy4285d782011-02-09 20:12:28 +00005998 i++;
5999 if (i == (ssize_t) argc)
6000 ThrowMogrifyException(OptionError,"MissingArgument",option);
6001 if (IsGeometry(argv[i]) == MagickFalse)
6002 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristy4285d782011-02-09 20:12:28 +00006003 i++;
6004 break;
6005 }
cristy3ed852e2009-09-05 21:47:34 +00006006 if (LocaleCompare("solarize",option+1) == 0)
6007 {
6008 if (*option == '+')
6009 break;
6010 i++;
cristybb503372010-05-27 20:51:26 +00006011 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006012 ThrowMogrifyException(OptionError,"MissingArgument",option);
6013 if (IsGeometry(argv[i]) == MagickFalse)
6014 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6015 break;
6016 }
6017 if (LocaleCompare("sparse-color",option+1) == 0)
6018 {
cristybb503372010-05-27 20:51:26 +00006019 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006020 op;
6021
6022 i++;
cristybb503372010-05-27 20:51:26 +00006023 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006024 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00006025 op=ParseCommandOption(MagickSparseColorOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00006026 if (op < 0)
6027 ThrowMogrifyException(OptionError,"UnrecognizedSparseColorMethod",
6028 argv[i]);
6029 i++;
cristye81f5522014-05-07 01:25:59 +00006030 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006031 ThrowMogrifyException(OptionError,"MissingArgument",option);
6032 break;
6033 }
cristy3b993fd2013-09-04 11:43:13 +00006034 if (LocaleCompare("splice",option+1) == 0)
6035 {
6036 if (*option == '+')
6037 break;
6038 i++;
6039 if (i == (ssize_t) argc)
6040 ThrowMogrifyException(OptionError,"MissingArgument",option);
6041 if (IsGeometry(argv[i]) == MagickFalse)
6042 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6043 break;
6044 }
cristy3ed852e2009-09-05 21:47:34 +00006045 if (LocaleCompare("spread",option+1) == 0)
6046 {
6047 if (*option == '+')
6048 break;
6049 i++;
cristybb503372010-05-27 20:51:26 +00006050 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006051 ThrowMogrifyException(OptionError,"MissingArgument",option);
6052 if (IsGeometry(argv[i]) == MagickFalse)
6053 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6054 break;
6055 }
cristy0834d642011-03-18 18:26:08 +00006056 if (LocaleCompare("statistic",option+1) == 0)
6057 {
6058 ssize_t
6059 op;
6060
6061 if (*option == '+')
6062 break;
6063 i++;
6064 if (i == (ssize_t) argc)
6065 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00006066 op=ParseCommandOption(MagickStatisticOptions,MagickFalse,argv[i]);
cristy0834d642011-03-18 18:26:08 +00006067 if (op < 0)
6068 ThrowMogrifyException(OptionError,"UnrecognizedStatisticType",
6069 argv[i]);
6070 i++;
cristye81f5522014-05-07 01:25:59 +00006071 if (i == (ssize_t) argc)
cristy0834d642011-03-18 18:26:08 +00006072 ThrowMogrifyException(OptionError,"MissingArgument",option);
6073 if (IsGeometry(argv[i]) == MagickFalse)
6074 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6075 break;
6076 }
cristy3ed852e2009-09-05 21:47:34 +00006077 if (LocaleCompare("stretch",option+1) == 0)
6078 {
cristybb503372010-05-27 20:51:26 +00006079 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006080 stretch;
6081
6082 if (*option == '+')
6083 break;
6084 i++;
cristye81f5522014-05-07 01:25:59 +00006085 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006086 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00006087 stretch=ParseCommandOption(MagickStretchOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00006088 if (stretch < 0)
6089 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
6090 argv[i]);
6091 break;
6092 }
6093 if (LocaleCompare("strip",option+1) == 0)
6094 break;
6095 if (LocaleCompare("stroke",option+1) == 0)
6096 {
6097 if (*option == '+')
6098 break;
6099 i++;
cristybb503372010-05-27 20:51:26 +00006100 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006101 ThrowMogrifyException(OptionError,"MissingArgument",option);
6102 break;
6103 }
6104 if (LocaleCompare("strokewidth",option+1) == 0)
6105 {
6106 if (*option == '+')
6107 break;
6108 i++;
cristybb503372010-05-27 20:51:26 +00006109 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006110 ThrowMogrifyException(OptionError,"MissingArgument",option);
6111 if (IsGeometry(argv[i]) == MagickFalse)
6112 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6113 break;
6114 }
6115 if (LocaleCompare("style",option+1) == 0)
6116 {
cristybb503372010-05-27 20:51:26 +00006117 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006118 style;
6119
6120 if (*option == '+')
6121 break;
6122 i++;
cristye81f5522014-05-07 01:25:59 +00006123 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006124 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00006125 style=ParseCommandOption(MagickStyleOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00006126 if (style < 0)
6127 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
6128 argv[i]);
6129 break;
6130 }
cristyecb10ff2011-03-22 13:14:03 +00006131 if (LocaleCompare("swap",option+1) == 0)
6132 {
6133 if (*option == '+')
6134 break;
6135 i++;
cristye81f5522014-05-07 01:25:59 +00006136 if (i == (ssize_t) argc)
cristyecb10ff2011-03-22 13:14:03 +00006137 ThrowMogrifyException(OptionError,"MissingArgument",option);
6138 if (IsGeometry(argv[i]) == MagickFalse)
6139 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6140 break;
6141 }
cristy3ed852e2009-09-05 21:47:34 +00006142 if (LocaleCompare("swirl",option+1) == 0)
6143 {
6144 if (*option == '+')
6145 break;
6146 i++;
cristybb503372010-05-27 20:51:26 +00006147 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006148 ThrowMogrifyException(OptionError,"MissingArgument",option);
6149 if (IsGeometry(argv[i]) == MagickFalse)
6150 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6151 break;
6152 }
cristyd9a29192010-10-16 16:49:53 +00006153 if (LocaleCompare("synchronize",option+1) == 0)
6154 break;
cristy3ed852e2009-09-05 21:47:34 +00006155 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6156 }
6157 case 't':
6158 {
6159 if (LocaleCompare("taint",option+1) == 0)
6160 break;
6161 if (LocaleCompare("texture",option+1) == 0)
6162 {
6163 if (*option == '+')
6164 break;
6165 i++;
cristybb503372010-05-27 20:51:26 +00006166 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006167 ThrowMogrifyException(OptionError,"MissingArgument",option);
6168 break;
6169 }
6170 if (LocaleCompare("tile",option+1) == 0)
6171 {
6172 if (*option == '+')
6173 break;
6174 i++;
cristye81f5522014-05-07 01:25:59 +00006175 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006176 ThrowMogrifyException(OptionError,"MissingArgument",option);
6177 break;
6178 }
6179 if (LocaleCompare("tile-offset",option+1) == 0)
6180 {
6181 if (*option == '+')
6182 break;
6183 i++;
cristybb503372010-05-27 20:51:26 +00006184 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006185 ThrowMogrifyException(OptionError,"MissingArgument",option);
6186 if (IsGeometry(argv[i]) == MagickFalse)
6187 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6188 break;
6189 }
6190 if (LocaleCompare("tint",option+1) == 0)
6191 {
6192 if (*option == '+')
6193 break;
6194 i++;
cristye81f5522014-05-07 01:25:59 +00006195 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006196 ThrowMogrifyException(OptionError,"MissingArgument",option);
6197 if (IsGeometry(argv[i]) == MagickFalse)
6198 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6199 break;
6200 }
6201 if (LocaleCompare("transform",option+1) == 0)
6202 break;
6203 if (LocaleCompare("transpose",option+1) == 0)
6204 break;
6205 if (LocaleCompare("transverse",option+1) == 0)
6206 break;
6207 if (LocaleCompare("threshold",option+1) == 0)
6208 {
6209 if (*option == '+')
6210 break;
6211 i++;
cristybb503372010-05-27 20:51:26 +00006212 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006213 ThrowMogrifyException(OptionError,"MissingArgument",option);
6214 if (IsGeometry(argv[i]) == MagickFalse)
6215 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6216 break;
6217 }
6218 if (LocaleCompare("thumbnail",option+1) == 0)
6219 {
6220 if (*option == '+')
6221 break;
6222 i++;
cristybb503372010-05-27 20:51:26 +00006223 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006224 ThrowMogrifyException(OptionError,"MissingArgument",option);
6225 if (IsGeometry(argv[i]) == MagickFalse)
6226 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6227 break;
6228 }
6229 if (LocaleCompare("transparent",option+1) == 0)
6230 {
6231 i++;
cristybb503372010-05-27 20:51:26 +00006232 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006233 ThrowMogrifyException(OptionError,"MissingArgument",option);
6234 break;
6235 }
6236 if (LocaleCompare("transparent-color",option+1) == 0)
6237 {
6238 if (*option == '+')
6239 break;
6240 i++;
cristye81f5522014-05-07 01:25:59 +00006241 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006242 ThrowMogrifyException(OptionError,"MissingArgument",option);
6243 break;
6244 }
6245 if (LocaleCompare("treedepth",option+1) == 0)
6246 {
6247 if (*option == '+')
6248 break;
6249 i++;
cristybb503372010-05-27 20:51:26 +00006250 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006251 ThrowMogrifyException(OptionError,"MissingArgument",option);
6252 if (IsGeometry(argv[i]) == MagickFalse)
6253 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6254 break;
6255 }
6256 if (LocaleCompare("trim",option+1) == 0)
6257 break;
6258 if (LocaleCompare("type",option+1) == 0)
6259 {
cristybb503372010-05-27 20:51:26 +00006260 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006261 type;
6262
6263 if (*option == '+')
6264 break;
6265 i++;
cristybb503372010-05-27 20:51:26 +00006266 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006267 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00006268 type=ParseCommandOption(MagickTypeOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00006269 if (type < 0)
6270 ThrowMogrifyException(OptionError,"UnrecognizedImageType",
6271 argv[i]);
6272 break;
6273 }
6274 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6275 }
6276 case 'u':
6277 {
6278 if (LocaleCompare("undercolor",option+1) == 0)
6279 {
6280 if (*option == '+')
6281 break;
6282 i++;
cristybb503372010-05-27 20:51:26 +00006283 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006284 ThrowMogrifyException(OptionError,"MissingArgument",option);
6285 break;
6286 }
6287 if (LocaleCompare("unique-colors",option+1) == 0)
6288 break;
6289 if (LocaleCompare("units",option+1) == 0)
6290 {
cristybb503372010-05-27 20:51:26 +00006291 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006292 units;
6293
6294 if (*option == '+')
6295 break;
6296 i++;
cristybb503372010-05-27 20:51:26 +00006297 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006298 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00006299 units=ParseCommandOption(MagickResolutionOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00006300 argv[i]);
6301 if (units < 0)
6302 ThrowMogrifyException(OptionError,"UnrecognizedUnitsType",
6303 argv[i]);
6304 break;
6305 }
6306 if (LocaleCompare("unsharp",option+1) == 0)
6307 {
6308 i++;
cristybb503372010-05-27 20:51:26 +00006309 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006310 ThrowMogrifyException(OptionError,"MissingArgument",option);
6311 if (IsGeometry(argv[i]) == MagickFalse)
6312 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6313 break;
6314 }
6315 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6316 }
6317 case 'v':
6318 {
6319 if (LocaleCompare("verbose",option+1) == 0)
6320 {
6321 image_info->verbose=(*option == '-') ? MagickTrue : MagickFalse;
6322 break;
6323 }
6324 if ((LocaleCompare("version",option+1) == 0) ||
6325 (LocaleCompare("-version",option+1) == 0))
6326 {
cristy4f7a6132012-12-23 00:35:19 +00006327 ListMagickVersion(stdout);
cristy3ed852e2009-09-05 21:47:34 +00006328 break;
6329 }
6330 if (LocaleCompare("view",option+1) == 0)
6331 {
6332 if (*option == '+')
6333 break;
6334 i++;
cristybb503372010-05-27 20:51:26 +00006335 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006336 ThrowMogrifyException(OptionError,"MissingArgument",option);
6337 break;
6338 }
6339 if (LocaleCompare("vignette",option+1) == 0)
6340 {
6341 if (*option == '+')
6342 break;
6343 i++;
cristybb503372010-05-27 20:51:26 +00006344 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006345 ThrowMogrifyException(OptionError,"MissingArgument",option);
6346 if (IsGeometry(argv[i]) == MagickFalse)
6347 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6348 break;
6349 }
6350 if (LocaleCompare("virtual-pixel",option+1) == 0)
6351 {
cristybb503372010-05-27 20:51:26 +00006352 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006353 method;
6354
6355 if (*option == '+')
6356 break;
6357 i++;
cristybb503372010-05-27 20:51:26 +00006358 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006359 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00006360 method=ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00006361 argv[i]);
6362 if (method < 0)
6363 ThrowMogrifyException(OptionError,
6364 "UnrecognizedVirtualPixelMethod",argv[i]);
6365 break;
6366 }
6367 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6368 }
6369 case 'w':
6370 {
6371 if (LocaleCompare("wave",option+1) == 0)
6372 {
6373 i++;
cristybb503372010-05-27 20:51:26 +00006374 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006375 ThrowMogrifyException(OptionError,"MissingArgument",option);
6376 if (IsGeometry(argv[i]) == MagickFalse)
6377 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6378 break;
6379 }
6380 if (LocaleCompare("weight",option+1) == 0)
6381 {
6382 if (*option == '+')
6383 break;
6384 i++;
cristye81f5522014-05-07 01:25:59 +00006385 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006386 ThrowMogrifyException(OptionError,"MissingArgument",option);
6387 break;
6388 }
6389 if (LocaleCompare("white-point",option+1) == 0)
6390 {
6391 if (*option == '+')
6392 break;
6393 i++;
cristybb503372010-05-27 20:51:26 +00006394 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006395 ThrowMogrifyException(OptionError,"MissingArgument",option);
6396 if (IsGeometry(argv[i]) == MagickFalse)
6397 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6398 break;
6399 }
6400 if (LocaleCompare("white-threshold",option+1) == 0)
6401 {
6402 if (*option == '+')
6403 break;
6404 i++;
cristybb503372010-05-27 20:51:26 +00006405 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006406 ThrowMogrifyException(OptionError,"MissingArgument",option);
6407 if (IsGeometry(argv[i]) == MagickFalse)
6408 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6409 break;
6410 }
6411 if (LocaleCompare("write",option+1) == 0)
6412 {
6413 i++;
cristye81f5522014-05-07 01:25:59 +00006414 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006415 ThrowMogrifyException(OptionError,"MissingArgument",option);
6416 break;
6417 }
cristy327030c2015-07-25 18:05:50 +00006418 if (LocaleCompare("write-mask",option+1) == 0)
6419 {
6420 if (*option == '+')
6421 break;
6422 i++;
6423 if (i == (ssize_t) argc)
6424 ThrowMogrifyException(OptionError,"MissingArgument",option);
6425 break;
6426 }
cristy3ed852e2009-09-05 21:47:34 +00006427 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6428 }
6429 case '?':
6430 break;
6431 default:
6432 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6433 }
cristy042ee782011-04-22 18:48:30 +00006434 fire=(GetCommandOptionFlags(MagickCommandOptions,MagickFalse,option) &
6435 FireOptionFlag) == 0 ? MagickFalse : MagickTrue;
cristy3ed852e2009-09-05 21:47:34 +00006436 if (fire != MagickFalse)
6437 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
6438 }
6439 if (k != 0)
6440 ThrowMogrifyException(OptionError,"UnbalancedParenthesis",argv[i]);
cristycee97112010-05-28 00:44:52 +00006441 if (i != (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006442 ThrowMogrifyException(OptionError,"MissingAnImageFilename",argv[i]);
6443 DestroyMogrify();
6444 return(status != 0 ? MagickTrue : MagickFalse);
6445}
6446
6447/*
6448%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6449% %
6450% %
6451% %
6452+ M o g r i f y I m a g e I n f o %
6453% %
6454% %
6455% %
6456%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6457%
6458% MogrifyImageInfo() applies image processing settings to the image as
6459% prescribed by command line options.
6460%
6461% The format of the MogrifyImageInfo method is:
6462%
6463% MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,const int argc,
6464% const char **argv,ExceptionInfo *exception)
6465%
6466% A description of each parameter follows:
6467%
6468% o image_info: the image info..
6469%
6470% o argc: Specifies a pointer to an integer describing the number of
6471% elements in the argument vector.
6472%
6473% o argv: Specifies a pointer to a text array containing the command line
6474% arguments.
6475%
6476% o exception: return any errors or warnings in this structure.
6477%
6478*/
6479WandExport MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,
6480 const int argc,const char **argv,ExceptionInfo *exception)
6481{
6482 const char
6483 *option;
6484
6485 GeometryInfo
6486 geometry_info;
6487
cristybb503372010-05-27 20:51:26 +00006488 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006489 count;
6490
cristybb503372010-05-27 20:51:26 +00006491 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006492 i;
6493
6494 /*
6495 Initialize method variables.
6496 */
6497 assert(image_info != (ImageInfo *) NULL);
cristye1c94d92015-06-28 12:16:33 +00006498 assert(image_info->signature == MagickCoreSignature);
cristy3ed852e2009-09-05 21:47:34 +00006499 if (image_info->debug != MagickFalse)
6500 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
6501 image_info->filename);
6502 if (argc < 0)
6503 return(MagickTrue);
6504 /*
6505 Set the image settings.
6506 */
cristybb503372010-05-27 20:51:26 +00006507 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00006508 {
6509 option=argv[i];
cristy042ee782011-04-22 18:48:30 +00006510 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00006511 continue;
cristy042ee782011-04-22 18:48:30 +00006512 count=ParseCommandOption(MagickCommandOptions,MagickFalse,option);
anthonyce2716b2011-04-22 09:51:34 +00006513 count=MagickMax(count,0L);
cristycee97112010-05-28 00:44:52 +00006514 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006515 break;
6516 switch (*(option+1))
6517 {
6518 case 'a':
6519 {
6520 if (LocaleCompare("adjoin",option+1) == 0)
6521 {
6522 image_info->adjoin=(*option == '-') ? MagickTrue : MagickFalse;
6523 break;
6524 }
6525 if (LocaleCompare("antialias",option+1) == 0)
6526 {
6527 image_info->antialias=(*option == '-') ? MagickTrue : MagickFalse;
6528 break;
6529 }
cristy3ed852e2009-09-05 21:47:34 +00006530 if (LocaleCompare("authenticate",option+1) == 0)
6531 {
6532 if (*option == '+')
anthony1afdc7a2011-10-05 11:54:28 +00006533 (void) DeleteImageOption(image_info,option+1);
cristy3ed852e2009-09-05 21:47:34 +00006534 else
anthony1afdc7a2011-10-05 11:54:28 +00006535 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006536 break;
6537 }
6538 break;
6539 }
6540 case 'b':
6541 {
6542 if (LocaleCompare("background",option+1) == 0)
6543 {
6544 if (*option == '+')
6545 {
6546 (void) DeleteImageOption(image_info,option+1);
cristy9950d572011-10-01 18:22:35 +00006547 (void) QueryColorCompliance(MogrifyBackgroundColor,
6548 AllCompliance,&image_info->background_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006549 break;
6550 }
6551 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy9950d572011-10-01 18:22:35 +00006552 (void) QueryColorCompliance(argv[i+1],AllCompliance,
6553 &image_info->background_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006554 break;
6555 }
6556 if (LocaleCompare("bias",option+1) == 0)
6557 {
6558 if (*option == '+')
6559 {
6560 (void) SetImageOption(image_info,option+1,"0.0");
6561 break;
6562 }
6563 (void) SetImageOption(image_info,option+1,argv[i+1]);
6564 break;
6565 }
6566 if (LocaleCompare("black-point-compensation",option+1) == 0)
6567 {
6568 if (*option == '+')
6569 {
6570 (void) SetImageOption(image_info,option+1,"false");
6571 break;
6572 }
6573 (void) SetImageOption(image_info,option+1,"true");
6574 break;
6575 }
6576 if (LocaleCompare("blue-primary",option+1) == 0)
6577 {
6578 if (*option == '+')
6579 {
6580 (void) SetImageOption(image_info,option+1,"0.0");
6581 break;
6582 }
6583 (void) SetImageOption(image_info,option+1,argv[i+1]);
6584 break;
6585 }
6586 if (LocaleCompare("bordercolor",option+1) == 0)
6587 {
6588 if (*option == '+')
6589 {
6590 (void) DeleteImageOption(image_info,option+1);
cristy9950d572011-10-01 18:22:35 +00006591 (void) QueryColorCompliance(MogrifyBorderColor,AllCompliance,
cristy638895a2011-08-06 23:19:14 +00006592 &image_info->border_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006593 break;
6594 }
cristy9950d572011-10-01 18:22:35 +00006595 (void) QueryColorCompliance(argv[i+1],AllCompliance,
6596 &image_info->border_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006597 (void) SetImageOption(image_info,option+1,argv[i+1]);
6598 break;
6599 }
6600 if (LocaleCompare("box",option+1) == 0)
6601 {
6602 if (*option == '+')
6603 {
6604 (void) SetImageOption(image_info,"undercolor","none");
6605 break;
6606 }
6607 (void) SetImageOption(image_info,"undercolor",argv[i+1]);
6608 break;
6609 }
6610 break;
6611 }
6612 case 'c':
6613 {
6614 if (LocaleCompare("cache",option+1) == 0)
6615 {
6616 MagickSizeType
6617 limit;
6618
6619 limit=MagickResourceInfinity;
6620 if (LocaleCompare("unlimited",argv[i+1]) != 0)
cristy9b34e302011-11-05 02:15:45 +00006621 limit=(MagickSizeType) SiPrefixToDoubleInterval(argv[i+1],
6622 100.0);
cristy3ed852e2009-09-05 21:47:34 +00006623 (void) SetMagickResourceLimit(MemoryResource,limit);
6624 (void) SetMagickResourceLimit(MapResource,2*limit);
6625 break;
6626 }
6627 if (LocaleCompare("caption",option+1) == 0)
6628 {
6629 if (*option == '+')
6630 {
6631 (void) DeleteImageOption(image_info,option+1);
6632 break;
6633 }
6634 (void) SetImageOption(image_info,option+1,argv[i+1]);
6635 break;
6636 }
cristy3ed852e2009-09-05 21:47:34 +00006637 if (LocaleCompare("colorspace",option+1) == 0)
6638 {
6639 if (*option == '+')
6640 {
6641 image_info->colorspace=UndefinedColorspace;
6642 (void) SetImageOption(image_info,option+1,"undefined");
6643 break;
6644 }
cristy042ee782011-04-22 18:48:30 +00006645 image_info->colorspace=(ColorspaceType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006646 MagickColorspaceOptions,MagickFalse,argv[i+1]);
6647 (void) SetImageOption(image_info,option+1,argv[i+1]);
6648 break;
6649 }
cristy3ed852e2009-09-05 21:47:34 +00006650 if (LocaleCompare("comment",option+1) == 0)
6651 {
6652 if (*option == '+')
6653 {
6654 (void) DeleteImageOption(image_info,option+1);
6655 break;
6656 }
6657 (void) SetImageOption(image_info,option+1,argv[i+1]);
6658 break;
6659 }
6660 if (LocaleCompare("compose",option+1) == 0)
6661 {
6662 if (*option == '+')
6663 {
6664 (void) SetImageOption(image_info,option+1,"undefined");
6665 break;
6666 }
6667 (void) SetImageOption(image_info,option+1,argv[i+1]);
6668 break;
6669 }
6670 if (LocaleCompare("compress",option+1) == 0)
6671 {
6672 if (*option == '+')
6673 {
6674 image_info->compression=UndefinedCompression;
6675 (void) SetImageOption(image_info,option+1,"undefined");
6676 break;
6677 }
cristy042ee782011-04-22 18:48:30 +00006678 image_info->compression=(CompressionType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006679 MagickCompressOptions,MagickFalse,argv[i+1]);
6680 (void) SetImageOption(image_info,option+1,argv[i+1]);
6681 break;
6682 }
6683 break;
6684 }
6685 case 'd':
6686 {
6687 if (LocaleCompare("debug",option+1) == 0)
6688 {
6689 if (*option == '+')
6690 (void) SetLogEventMask("none");
6691 else
6692 (void) SetLogEventMask(argv[i+1]);
6693 image_info->debug=IsEventLogging();
6694 break;
6695 }
6696 if (LocaleCompare("define",option+1) == 0)
6697 {
6698 if (*option == '+')
6699 {
6700 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6701 (void) DeleteImageRegistry(argv[i+1]+9);
6702 else
6703 (void) DeleteImageOption(image_info,argv[i+1]);
6704 break;
6705 }
6706 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6707 {
6708 (void) DefineImageRegistry(StringRegistryType,argv[i+1]+9,
6709 exception);
6710 break;
6711 }
6712 (void) DefineImageOption(image_info,argv[i+1]);
6713 break;
6714 }
6715 if (LocaleCompare("delay",option+1) == 0)
6716 {
6717 if (*option == '+')
6718 {
6719 (void) SetImageOption(image_info,option+1,"0");
6720 break;
6721 }
6722 (void) SetImageOption(image_info,option+1,argv[i+1]);
6723 break;
6724 }
6725 if (LocaleCompare("density",option+1) == 0)
6726 {
6727 /*
6728 Set image density.
6729 */
6730 if (*option == '+')
6731 {
6732 if (image_info->density != (char *) NULL)
6733 image_info->density=DestroyString(image_info->density);
6734 (void) SetImageOption(image_info,option+1,"72");
6735 break;
6736 }
6737 (void) CloneString(&image_info->density,argv[i+1]);
6738 (void) SetImageOption(image_info,option+1,argv[i+1]);
6739 break;
6740 }
6741 if (LocaleCompare("depth",option+1) == 0)
6742 {
6743 if (*option == '+')
6744 {
6745 image_info->depth=MAGICKCORE_QUANTUM_DEPTH;
6746 break;
6747 }
cristye27293e2009-12-18 02:53:20 +00006748 image_info->depth=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006749 break;
6750 }
cristyc9b12952010-03-28 01:12:28 +00006751 if (LocaleCompare("direction",option+1) == 0)
6752 {
6753 if (*option == '+')
6754 {
6755 (void) SetImageOption(image_info,option+1,"undefined");
6756 break;
6757 }
6758 (void) SetImageOption(image_info,option+1,argv[i+1]);
6759 break;
6760 }
cristy3ed852e2009-09-05 21:47:34 +00006761 if (LocaleCompare("display",option+1) == 0)
6762 {
6763 if (*option == '+')
6764 {
6765 if (image_info->server_name != (char *) NULL)
6766 image_info->server_name=DestroyString(
6767 image_info->server_name);
6768 break;
6769 }
6770 (void) CloneString(&image_info->server_name,argv[i+1]);
6771 break;
6772 }
6773 if (LocaleCompare("dispose",option+1) == 0)
6774 {
6775 if (*option == '+')
6776 {
6777 (void) SetImageOption(image_info,option+1,"undefined");
6778 break;
6779 }
6780 (void) SetImageOption(image_info,option+1,argv[i+1]);
6781 break;
6782 }
6783 if (LocaleCompare("dither",option+1) == 0)
6784 {
6785 if (*option == '+')
6786 {
6787 image_info->dither=MagickFalse;
cristyd5acfd12010-06-15 00:11:38 +00006788 (void) SetImageOption(image_info,option+1,"none");
cristy3ed852e2009-09-05 21:47:34 +00006789 break;
6790 }
6791 (void) SetImageOption(image_info,option+1,argv[i+1]);
6792 image_info->dither=MagickTrue;
6793 break;
6794 }
6795 break;
6796 }
6797 case 'e':
6798 {
6799 if (LocaleCompare("encoding",option+1) == 0)
6800 {
6801 if (*option == '+')
6802 {
6803 (void) SetImageOption(image_info,option+1,"undefined");
6804 break;
6805 }
6806 (void) SetImageOption(image_info,option+1,argv[i+1]);
6807 break;
6808 }
6809 if (LocaleCompare("endian",option+1) == 0)
6810 {
6811 if (*option == '+')
6812 {
6813 image_info->endian=UndefinedEndian;
6814 (void) SetImageOption(image_info,option+1,"undefined");
6815 break;
6816 }
cristy042ee782011-04-22 18:48:30 +00006817 image_info->endian=(EndianType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006818 MagickEndianOptions,MagickFalse,argv[i+1]);
6819 (void) SetImageOption(image_info,option+1,argv[i+1]);
6820 break;
6821 }
6822 if (LocaleCompare("extract",option+1) == 0)
6823 {
6824 /*
6825 Set image extract geometry.
6826 */
6827 if (*option == '+')
6828 {
6829 if (image_info->extract != (char *) NULL)
6830 image_info->extract=DestroyString(image_info->extract);
6831 break;
6832 }
6833 (void) CloneString(&image_info->extract,argv[i+1]);
6834 break;
6835 }
6836 break;
6837 }
6838 case 'f':
6839 {
dirk6409f342015-08-01 08:06:56 +00006840 if (LocaleCompare("family",option+1) == 0)
6841 {
6842 if (*option != '+')
6843 (void) SetImageOption(image_info,option+1,argv[i+1]);
6844 break;
6845 }
cristy3ed852e2009-09-05 21:47:34 +00006846 if (LocaleCompare("fill",option+1) == 0)
6847 {
6848 if (*option == '+')
6849 {
6850 (void) SetImageOption(image_info,option+1,"none");
6851 break;
6852 }
6853 (void) SetImageOption(image_info,option+1,argv[i+1]);
6854 break;
6855 }
6856 if (LocaleCompare("filter",option+1) == 0)
6857 {
6858 if (*option == '+')
6859 {
6860 (void) SetImageOption(image_info,option+1,"undefined");
6861 break;
6862 }
6863 (void) SetImageOption(image_info,option+1,argv[i+1]);
6864 break;
6865 }
6866 if (LocaleCompare("font",option+1) == 0)
6867 {
6868 if (*option == '+')
6869 {
6870 if (image_info->font != (char *) NULL)
6871 image_info->font=DestroyString(image_info->font);
6872 break;
6873 }
6874 (void) CloneString(&image_info->font,argv[i+1]);
6875 break;
6876 }
6877 if (LocaleCompare("format",option+1) == 0)
6878 {
6879 register const char
6880 *q;
6881
6882 for (q=strchr(argv[i+1],'%'); q != (char *) NULL; q=strchr(q+1,'%'))
cristy9ed85672011-03-02 00:19:13 +00006883 if (strchr("Agkrz@[#",*(q+1)) != (char *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00006884 image_info->ping=MagickFalse;
6885 (void) SetImageOption(image_info,option+1,argv[i+1]);
6886 break;
6887 }
6888 if (LocaleCompare("fuzz",option+1) == 0)
6889 {
6890 if (*option == '+')
6891 {
6892 image_info->fuzz=0.0;
6893 (void) SetImageOption(image_info,option+1,"0");
6894 break;
6895 }
cristydbdd0e32011-11-04 23:29:40 +00006896 image_info->fuzz=StringToDoubleInterval(argv[i+1],(double)
6897 QuantumRange+1.0);
cristy3ed852e2009-09-05 21:47:34 +00006898 (void) SetImageOption(image_info,option+1,argv[i+1]);
6899 break;
6900 }
6901 break;
6902 }
6903 case 'g':
6904 {
6905 if (LocaleCompare("gravity",option+1) == 0)
6906 {
6907 if (*option == '+')
6908 {
6909 (void) SetImageOption(image_info,option+1,"undefined");
6910 break;
6911 }
6912 (void) SetImageOption(image_info,option+1,argv[i+1]);
6913 break;
6914 }
6915 if (LocaleCompare("green-primary",option+1) == 0)
6916 {
6917 if (*option == '+')
6918 {
6919 (void) SetImageOption(image_info,option+1,"0.0");
6920 break;
6921 }
6922 (void) SetImageOption(image_info,option+1,argv[i+1]);
6923 break;
6924 }
6925 break;
6926 }
6927 case 'i':
6928 {
cristy70e9f682013-03-12 22:31:22 +00006929 if (LocaleCompare("intensity",option+1) == 0)
6930 {
6931 if (*option == '+')
6932 {
6933 (void) SetImageOption(image_info,option+1,"undefined");
6934 break;
6935 }
6936 (void) SetImageOption(image_info,option+1,argv[i+1]);
6937 break;
6938 }
cristy3ed852e2009-09-05 21:47:34 +00006939 if (LocaleCompare("intent",option+1) == 0)
6940 {
6941 if (*option == '+')
6942 {
6943 (void) SetImageOption(image_info,option+1,"undefined");
6944 break;
6945 }
6946 (void) SetImageOption(image_info,option+1,argv[i+1]);
6947 break;
6948 }
6949 if (LocaleCompare("interlace",option+1) == 0)
6950 {
6951 if (*option == '+')
6952 {
6953 image_info->interlace=UndefinedInterlace;
6954 (void) SetImageOption(image_info,option+1,"undefined");
6955 break;
6956 }
cristy042ee782011-04-22 18:48:30 +00006957 image_info->interlace=(InterlaceType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006958 MagickInterlaceOptions,MagickFalse,argv[i+1]);
6959 (void) SetImageOption(image_info,option+1,argv[i+1]);
6960 break;
6961 }
cristyb32b90a2009-09-07 21:45:48 +00006962 if (LocaleCompare("interline-spacing",option+1) == 0)
6963 {
6964 if (*option == '+')
6965 {
6966 (void) SetImageOption(image_info,option+1,"undefined");
6967 break;
6968 }
6969 (void) SetImageOption(image_info,option+1,argv[i+1]);
6970 break;
6971 }
cristy3ed852e2009-09-05 21:47:34 +00006972 if (LocaleCompare("interpolate",option+1) == 0)
6973 {
6974 if (*option == '+')
6975 {
6976 (void) SetImageOption(image_info,option+1,"undefined");
6977 break;
6978 }
6979 (void) SetImageOption(image_info,option+1,argv[i+1]);
6980 break;
6981 }
6982 if (LocaleCompare("interword-spacing",option+1) == 0)
6983 {
6984 if (*option == '+')
6985 {
6986 (void) SetImageOption(image_info,option+1,"undefined");
6987 break;
6988 }
6989 (void) SetImageOption(image_info,option+1,argv[i+1]);
6990 break;
6991 }
6992 break;
6993 }
6994 case 'k':
6995 {
6996 if (LocaleCompare("kerning",option+1) == 0)
6997 {
6998 if (*option == '+')
6999 {
7000 (void) SetImageOption(image_info,option+1,"undefined");
7001 break;
7002 }
7003 (void) SetImageOption(image_info,option+1,argv[i+1]);
7004 break;
7005 }
7006 break;
7007 }
7008 case 'l':
7009 {
7010 if (LocaleCompare("label",option+1) == 0)
7011 {
7012 if (*option == '+')
7013 {
7014 (void) DeleteImageOption(image_info,option+1);
7015 break;
7016 }
7017 (void) SetImageOption(image_info,option+1,argv[i+1]);
7018 break;
7019 }
7020 if (LocaleCompare("limit",option+1) == 0)
7021 {
7022 MagickSizeType
7023 limit;
7024
7025 ResourceType
7026 type;
7027
7028 if (*option == '+')
7029 break;
cristy042ee782011-04-22 18:48:30 +00007030 type=(ResourceType) ParseCommandOption(MagickResourceOptions,
cristy3ed852e2009-09-05 21:47:34 +00007031 MagickFalse,argv[i+1]);
7032 limit=MagickResourceInfinity;
7033 if (LocaleCompare("unlimited",argv[i+2]) != 0)
cristyc0627342011-11-18 21:15:24 +00007034 limit=(MagickSizeType) SiPrefixToDoubleInterval(argv[i+2],100.0);
cristy3ed852e2009-09-05 21:47:34 +00007035 (void) SetMagickResourceLimit(type,limit);
7036 break;
7037 }
7038 if (LocaleCompare("list",option+1) == 0)
7039 {
cristybb503372010-05-27 20:51:26 +00007040 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00007041 list;
7042
7043 /*
7044 Display configuration list.
7045 */
cristy042ee782011-04-22 18:48:30 +00007046 list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007047 switch (list)
7048 {
7049 case MagickCoderOptions:
7050 {
7051 (void) ListCoderInfo((FILE *) NULL,exception);
7052 break;
7053 }
7054 case MagickColorOptions:
7055 {
7056 (void) ListColorInfo((FILE *) NULL,exception);
7057 break;
7058 }
7059 case MagickConfigureOptions:
7060 {
7061 (void) ListConfigureInfo((FILE *) NULL,exception);
7062 break;
7063 }
7064 case MagickDelegateOptions:
7065 {
7066 (void) ListDelegateInfo((FILE *) NULL,exception);
7067 break;
7068 }
7069 case MagickFontOptions:
7070 {
7071 (void) ListTypeInfo((FILE *) NULL,exception);
7072 break;
7073 }
7074 case MagickFormatOptions:
7075 {
7076 (void) ListMagickInfo((FILE *) NULL,exception);
7077 break;
7078 }
7079 case MagickLocaleOptions:
7080 {
7081 (void) ListLocaleInfo((FILE *) NULL,exception);
7082 break;
7083 }
7084 case MagickLogOptions:
7085 {
7086 (void) ListLogInfo((FILE *) NULL,exception);
7087 break;
7088 }
7089 case MagickMagicOptions:
7090 {
7091 (void) ListMagicInfo((FILE *) NULL,exception);
7092 break;
7093 }
7094 case MagickMimeOptions:
7095 {
7096 (void) ListMimeInfo((FILE *) NULL,exception);
7097 break;
7098 }
7099 case MagickModuleOptions:
7100 {
7101 (void) ListModuleInfo((FILE *) NULL,exception);
7102 break;
7103 }
7104 case MagickPolicyOptions:
7105 {
7106 (void) ListPolicyInfo((FILE *) NULL,exception);
7107 break;
7108 }
7109 case MagickResourceOptions:
7110 {
7111 (void) ListMagickResourceInfo((FILE *) NULL,exception);
7112 break;
7113 }
7114 case MagickThresholdOptions:
7115 {
7116 (void) ListThresholdMaps((FILE *) NULL,exception);
7117 break;
7118 }
7119 default:
7120 {
cristy042ee782011-04-22 18:48:30 +00007121 (void) ListCommandOptions((FILE *) NULL,(CommandOption) list,
cristy3ed852e2009-09-05 21:47:34 +00007122 exception);
7123 break;
7124 }
7125 }
cristyaeb2cbc2010-05-07 13:28:58 +00007126 break;
cristy3ed852e2009-09-05 21:47:34 +00007127 }
7128 if (LocaleCompare("log",option+1) == 0)
7129 {
7130 if (*option == '+')
7131 break;
7132 (void) SetLogFormat(argv[i+1]);
7133 break;
7134 }
7135 if (LocaleCompare("loop",option+1) == 0)
7136 {
7137 if (*option == '+')
7138 {
7139 (void) SetImageOption(image_info,option+1,"0");
7140 break;
7141 }
7142 (void) SetImageOption(image_info,option+1,argv[i+1]);
7143 break;
7144 }
7145 break;
7146 }
7147 case 'm':
7148 {
cristy52ad9e92013-02-08 23:23:29 +00007149 if (LocaleCompare("matte",option+1) == 0)
7150 {
7151 if (*option == '+')
7152 {
7153 (void) SetImageOption(image_info,option+1,"false");
7154 break;
7155 }
7156 (void) SetImageOption(image_info,option+1,"true");
7157 break;
7158 }
cristy3ed852e2009-09-05 21:47:34 +00007159 if (LocaleCompare("mattecolor",option+1) == 0)
7160 {
7161 if (*option == '+')
7162 {
7163 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy9950d572011-10-01 18:22:35 +00007164 (void) QueryColorCompliance(MogrifyMatteColor,AllCompliance,
cristy638895a2011-08-06 23:19:14 +00007165 &image_info->matte_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00007166 break;
7167 }
7168 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy9950d572011-10-01 18:22:35 +00007169 (void) QueryColorCompliance(argv[i+1],AllCompliance,
7170 &image_info->matte_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00007171 break;
7172 }
cristyf4185122013-08-20 00:58:56 +00007173 if (LocaleCompare("metric",option+1) == 0)
7174 {
7175 if (*option == '+')
7176 (void) DeleteImageOption(image_info,option+1);
7177 else
7178 (void) SetImageOption(image_info,option+1,argv[i+1]);
7179 break;
7180 }
cristy3ed852e2009-09-05 21:47:34 +00007181 if (LocaleCompare("monitor",option+1) == 0)
7182 {
7183 (void) SetImageInfoProgressMonitor(image_info,MonitorProgress,
7184 (void *) NULL);
7185 break;
7186 }
7187 if (LocaleCompare("monochrome",option+1) == 0)
7188 {
7189 image_info->monochrome=(*option == '-') ? MagickTrue : MagickFalse;
7190 break;
7191 }
7192 break;
7193 }
7194 case 'o':
7195 {
7196 if (LocaleCompare("orient",option+1) == 0)
7197 {
7198 if (*option == '+')
7199 {
7200 image_info->orientation=UndefinedOrientation;
7201 (void) SetImageOption(image_info,option+1,"undefined");
7202 break;
7203 }
cristy042ee782011-04-22 18:48:30 +00007204 image_info->orientation=(OrientationType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007205 MagickOrientationOptions,MagickFalse,argv[i+1]);
cristyc6e214d2010-08-08 00:31:08 +00007206 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007207 break;
7208 }
7209 }
7210 case 'p':
7211 {
7212 if (LocaleCompare("page",option+1) == 0)
7213 {
7214 char
7215 *canonical_page,
cristy151b66d2015-04-15 10:50:31 +00007216 page[MagickPathExtent];
cristy3ed852e2009-09-05 21:47:34 +00007217
7218 const char
7219 *image_option;
7220
7221 MagickStatusType
7222 flags;
7223
7224 RectangleInfo
7225 geometry;
7226
7227 if (*option == '+')
7228 {
7229 (void) DeleteImageOption(image_info,option+1);
7230 (void) CloneString(&image_info->page,(char *) NULL);
7231 break;
7232 }
7233 (void) ResetMagickMemory(&geometry,0,sizeof(geometry));
7234 image_option=GetImageOption(image_info,"page");
7235 if (image_option != (const char *) NULL)
7236 flags=ParseAbsoluteGeometry(image_option,&geometry);
7237 canonical_page=GetPageGeometry(argv[i+1]);
7238 flags=ParseAbsoluteGeometry(canonical_page,&geometry);
7239 canonical_page=DestroyString(canonical_page);
cristy151b66d2015-04-15 10:50:31 +00007240 (void) FormatLocaleString(page,MagickPathExtent,"%lux%lu",
cristyf2faecf2010-05-28 19:19:36 +00007241 (unsigned long) geometry.width,(unsigned long) geometry.height);
cristy3ed852e2009-09-05 21:47:34 +00007242 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
cristy151b66d2015-04-15 10:50:31 +00007243 (void) FormatLocaleString(page,MagickPathExtent,"%lux%lu%+ld%+ld",
cristyf2faecf2010-05-28 19:19:36 +00007244 (unsigned long) geometry.width,(unsigned long) geometry.height,
7245 (long) geometry.x,(long) geometry.y);
cristy3ed852e2009-09-05 21:47:34 +00007246 (void) SetImageOption(image_info,option+1,page);
7247 (void) CloneString(&image_info->page,page);
7248 break;
7249 }
cristy3ed852e2009-09-05 21:47:34 +00007250 if (LocaleCompare("ping",option+1) == 0)
7251 {
7252 image_info->ping=(*option == '-') ? MagickTrue : MagickFalse;
7253 break;
7254 }
7255 if (LocaleCompare("pointsize",option+1) == 0)
7256 {
7257 if (*option == '+')
7258 geometry_info.rho=0.0;
7259 else
7260 (void) ParseGeometry(argv[i+1],&geometry_info);
7261 image_info->pointsize=geometry_info.rho;
7262 break;
7263 }
cristye7f51092010-01-17 00:39:37 +00007264 if (LocaleCompare("precision",option+1) == 0)
7265 {
cristybf2766a2010-01-17 03:33:23 +00007266 (void) SetMagickPrecision(StringToInteger(argv[i+1]));
cristye7f51092010-01-17 00:39:37 +00007267 break;
7268 }
cristy3ed852e2009-09-05 21:47:34 +00007269 if (LocaleCompare("preview",option+1) == 0)
7270 {
7271 /*
7272 Preview image.
7273 */
7274 if (*option == '+')
7275 {
7276 image_info->preview_type=UndefinedPreview;
7277 break;
7278 }
cristy042ee782011-04-22 18:48:30 +00007279 image_info->preview_type=(PreviewType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007280 MagickPreviewOptions,MagickFalse,argv[i+1]);
7281 break;
7282 }
7283 break;
7284 }
7285 case 'q':
7286 {
7287 if (LocaleCompare("quality",option+1) == 0)
7288 {
7289 /*
7290 Set image compression quality.
7291 */
7292 if (*option == '+')
7293 {
7294 image_info->quality=UndefinedCompressionQuality;
7295 (void) SetImageOption(image_info,option+1,"0");
7296 break;
7297 }
cristye27293e2009-12-18 02:53:20 +00007298 image_info->quality=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007299 (void) SetImageOption(image_info,option+1,argv[i+1]);
7300 break;
7301 }
7302 if (LocaleCompare("quiet",option+1) == 0)
7303 {
7304 static WarningHandler
7305 warning_handler = (WarningHandler) NULL;
7306
7307 if (*option == '+')
7308 {
7309 /*
7310 Restore error or warning messages.
7311 */
7312 warning_handler=SetWarningHandler(warning_handler);
7313 break;
7314 }
7315 /*
7316 Suppress error or warning messages.
7317 */
7318 warning_handler=SetWarningHandler((WarningHandler) NULL);
7319 break;
7320 }
7321 break;
7322 }
7323 case 'r':
7324 {
7325 if (LocaleCompare("red-primary",option+1) == 0)
7326 {
7327 if (*option == '+')
7328 {
7329 (void) SetImageOption(image_info,option+1,"0.0");
7330 break;
7331 }
7332 (void) SetImageOption(image_info,option+1,argv[i+1]);
7333 break;
7334 }
7335 break;
7336 }
7337 case 's':
7338 {
7339 if (LocaleCompare("sampling-factor",option+1) == 0)
7340 {
7341 /*
7342 Set image sampling factor.
7343 */
7344 if (*option == '+')
7345 {
7346 if (image_info->sampling_factor != (char *) NULL)
7347 image_info->sampling_factor=DestroyString(
7348 image_info->sampling_factor);
7349 break;
7350 }
7351 (void) CloneString(&image_info->sampling_factor,argv[i+1]);
7352 break;
7353 }
7354 if (LocaleCompare("scene",option+1) == 0)
7355 {
7356 /*
7357 Set image scene.
7358 */
7359 if (*option == '+')
7360 {
7361 image_info->scene=0;
7362 (void) SetImageOption(image_info,option+1,"0");
7363 break;
7364 }
cristye27293e2009-12-18 02:53:20 +00007365 image_info->scene=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007366 (void) SetImageOption(image_info,option+1,argv[i+1]);
7367 break;
7368 }
7369 if (LocaleCompare("seed",option+1) == 0)
7370 {
cristy0e274112014-03-25 14:09:19 +00007371 unsigned long
cristy3ed852e2009-09-05 21:47:34 +00007372 seed;
7373
7374 if (*option == '+')
7375 {
cristy0e274112014-03-25 14:09:19 +00007376 seed=(unsigned long) time((time_t *) NULL);
cristyd7761bb2012-04-14 01:42:05 +00007377 SetRandomSecretKey(seed);
cristy3ed852e2009-09-05 21:47:34 +00007378 break;
7379 }
cristye27293e2009-12-18 02:53:20 +00007380 seed=StringToUnsignedLong(argv[i+1]);
cristyd7761bb2012-04-14 01:42:05 +00007381 SetRandomSecretKey(seed);
cristy3ed852e2009-09-05 21:47:34 +00007382 break;
7383 }
7384 if (LocaleCompare("size",option+1) == 0)
7385 {
7386 if (*option == '+')
7387 {
7388 if (image_info->size != (char *) NULL)
7389 image_info->size=DestroyString(image_info->size);
7390 break;
7391 }
7392 (void) CloneString(&image_info->size,argv[i+1]);
7393 break;
7394 }
7395 if (LocaleCompare("stroke",option+1) == 0)
7396 {
7397 if (*option == '+')
7398 {
7399 (void) SetImageOption(image_info,option+1,"none");
7400 break;
7401 }
7402 (void) SetImageOption(image_info,option+1,argv[i+1]);
7403 break;
7404 }
7405 if (LocaleCompare("strokewidth",option+1) == 0)
7406 {
7407 if (*option == '+')
dirk5acf7022015-07-30 18:37:03 +00007408 (void) SetImageOption(image_info,option+1,"0");
7409 else
7410 (void) SetImageOption(image_info,option+1,argv[i+1]);
7411 break;
7412 }
7413 if (LocaleCompare("style",option+1) == 0)
7414 {
7415 if (*option == '+')
cristy3ed852e2009-09-05 21:47:34 +00007416 {
dirk5acf7022015-07-30 18:37:03 +00007417 (void) SetImageOption(image_info,option+1,"none");
cristy3ed852e2009-09-05 21:47:34 +00007418 break;
7419 }
7420 (void) SetImageOption(image_info,option+1,argv[i+1]);
7421 break;
7422 }
cristyd9a29192010-10-16 16:49:53 +00007423 if (LocaleCompare("synchronize",option+1) == 0)
7424 {
7425 if (*option == '+')
7426 {
7427 image_info->synchronize=MagickFalse;
7428 break;
7429 }
7430 image_info->synchronize=MagickTrue;
7431 break;
7432 }
cristy3ed852e2009-09-05 21:47:34 +00007433 break;
7434 }
7435 case 't':
7436 {
7437 if (LocaleCompare("taint",option+1) == 0)
7438 {
7439 if (*option == '+')
7440 {
7441 (void) SetImageOption(image_info,option+1,"false");
7442 break;
7443 }
7444 (void) SetImageOption(image_info,option+1,"true");
7445 break;
7446 }
7447 if (LocaleCompare("texture",option+1) == 0)
7448 {
7449 if (*option == '+')
7450 {
7451 if (image_info->texture != (char *) NULL)
7452 image_info->texture=DestroyString(image_info->texture);
7453 break;
7454 }
7455 (void) CloneString(&image_info->texture,argv[i+1]);
7456 break;
7457 }
7458 if (LocaleCompare("tile-offset",option+1) == 0)
7459 {
7460 if (*option == '+')
anthonyfd706f92012-01-19 04:22:02 +00007461 (void) SetImageOption(image_info,option+1,"0");
7462 else
7463 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007464 break;
7465 }
7466 if (LocaleCompare("transparent-color",option+1) == 0)
7467 {
7468 if (*option == '+')
7469 {
cristy9950d572011-10-01 18:22:35 +00007470 (void) QueryColorCompliance("none",AllCompliance,
7471 &image_info->transparent_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00007472 (void) SetImageOption(image_info,option+1,"none");
7473 break;
7474 }
cristy9950d572011-10-01 18:22:35 +00007475 (void) QueryColorCompliance(argv[i+1],AllCompliance,
7476 &image_info->transparent_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00007477 (void) SetImageOption(image_info,option+1,argv[i+1]);
7478 break;
7479 }
7480 if (LocaleCompare("type",option+1) == 0)
7481 {
7482 if (*option == '+')
7483 {
cristy5f1c1ff2010-12-23 21:38:06 +00007484 image_info->type=UndefinedType;
cristy3ed852e2009-09-05 21:47:34 +00007485 (void) SetImageOption(image_info,option+1,"undefined");
7486 break;
7487 }
cristy042ee782011-04-22 18:48:30 +00007488 image_info->type=(ImageType) ParseCommandOption(MagickTypeOptions,
cristy3ed852e2009-09-05 21:47:34 +00007489 MagickFalse,argv[i+1]);
7490 (void) SetImageOption(image_info,option+1,argv[i+1]);
7491 break;
7492 }
7493 break;
7494 }
7495 case 'u':
7496 {
7497 if (LocaleCompare("undercolor",option+1) == 0)
7498 {
7499 if (*option == '+')
anthonyfd706f92012-01-19 04:22:02 +00007500 (void) DeleteImageOption(image_info,option+1);
7501 else
7502 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007503 break;
7504 }
7505 if (LocaleCompare("units",option+1) == 0)
7506 {
7507 if (*option == '+')
7508 {
7509 image_info->units=UndefinedResolution;
7510 (void) SetImageOption(image_info,option+1,"undefined");
7511 break;
7512 }
cristy042ee782011-04-22 18:48:30 +00007513 image_info->units=(ResolutionType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007514 MagickResolutionOptions,MagickFalse,argv[i+1]);
7515 (void) SetImageOption(image_info,option+1,argv[i+1]);
7516 break;
7517 }
7518 break;
7519 }
7520 case 'v':
7521 {
7522 if (LocaleCompare("verbose",option+1) == 0)
7523 {
7524 if (*option == '+')
7525 {
7526 image_info->verbose=MagickFalse;
7527 break;
7528 }
7529 image_info->verbose=MagickTrue;
7530 image_info->ping=MagickFalse;
7531 break;
7532 }
7533 if (LocaleCompare("view",option+1) == 0)
7534 {
7535 if (*option == '+')
7536 {
7537 if (image_info->view != (char *) NULL)
7538 image_info->view=DestroyString(image_info->view);
7539 break;
7540 }
7541 (void) CloneString(&image_info->view,argv[i+1]);
7542 break;
7543 }
7544 if (LocaleCompare("virtual-pixel",option+1) == 0)
7545 {
7546 if (*option == '+')
anthonyfd706f92012-01-19 04:22:02 +00007547 (void) SetImageOption(image_info,option+1,"undefined");
7548 else
7549 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007550 break;
7551 }
7552 break;
7553 }
7554 case 'w':
7555 {
dirk5acf7022015-07-30 18:37:03 +00007556 if (LocaleCompare("weight",option+1) == 0)
7557 {
7558 if (*option == '+')
7559 (void) SetImageOption(image_info,option+1,"0");
7560 else
7561 (void) SetImageOption(image_info,option+1,argv[i+1]);
7562 break;
7563 }
cristy3ed852e2009-09-05 21:47:34 +00007564 if (LocaleCompare("white-point",option+1) == 0)
7565 {
7566 if (*option == '+')
anthonyfd706f92012-01-19 04:22:02 +00007567 (void) SetImageOption(image_info,option+1,"0.0");
7568 else
7569 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007570 break;
7571 }
7572 break;
7573 }
7574 default:
7575 break;
7576 }
7577 i+=count;
7578 }
7579 return(MagickTrue);
7580}
7581
7582/*
7583%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7584% %
7585% %
7586% %
7587+ M o g r i f y I m a g e L i s t %
7588% %
7589% %
7590% %
7591%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7592%
7593% MogrifyImageList() applies any command line options that might affect the
7594% entire image list (e.g. -append, -coalesce, etc.).
7595%
7596% The format of the MogrifyImage method is:
7597%
7598% MagickBooleanType MogrifyImageList(ImageInfo *image_info,const int argc,
7599% const char **argv,Image **images,ExceptionInfo *exception)
7600%
7601% A description of each parameter follows:
7602%
7603% o image_info: the image info..
7604%
7605% o argc: Specifies a pointer to an integer describing the number of
7606% elements in the argument vector.
7607%
7608% o argv: Specifies a pointer to a text array containing the command line
7609% arguments.
7610%
anthonye9c27192011-03-27 08:07:06 +00007611% o images: pointer to pointer of the first image in image list.
cristy3ed852e2009-09-05 21:47:34 +00007612%
7613% o exception: return any errors or warnings in this structure.
7614%
7615*/
7616WandExport MagickBooleanType MogrifyImageList(ImageInfo *image_info,
7617 const int argc,const char **argv,Image **images,ExceptionInfo *exception)
7618{
cristy3ed852e2009-09-05 21:47:34 +00007619 const char
7620 *option;
7621
cristy6b3da3a2010-06-20 02:21:46 +00007622 ImageInfo
7623 *mogrify_info;
cristy3ed852e2009-09-05 21:47:34 +00007624
7625 MagickStatusType
7626 status;
7627
cristy28474bf2011-09-11 23:32:52 +00007628 PixelInterpolateMethod
7629 interpolate_method;
7630
cristy3ed852e2009-09-05 21:47:34 +00007631 QuantizeInfo
7632 *quantize_info;
7633
cristybb503372010-05-27 20:51:26 +00007634 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00007635 i;
7636
cristy6b3da3a2010-06-20 02:21:46 +00007637 ssize_t
7638 count,
7639 index;
7640
cristy3ed852e2009-09-05 21:47:34 +00007641 /*
7642 Apply options to the image list.
7643 */
7644 assert(image_info != (ImageInfo *) NULL);
cristye1c94d92015-06-28 12:16:33 +00007645 assert(image_info->signature == MagickCoreSignature);
cristy3ed852e2009-09-05 21:47:34 +00007646 assert(images != (Image **) NULL);
anthonye9c27192011-03-27 08:07:06 +00007647 assert((*images)->previous == (Image *) NULL);
cristye1c94d92015-06-28 12:16:33 +00007648 assert((*images)->signature == MagickCoreSignature);
cristy3ed852e2009-09-05 21:47:34 +00007649 if ((*images)->debug != MagickFalse)
7650 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
7651 (*images)->filename);
7652 if ((argc <= 0) || (*argv == (char *) NULL))
7653 return(MagickTrue);
cristy28474bf2011-09-11 23:32:52 +00007654 interpolate_method=UndefinedInterpolatePixel;
cristy6b3da3a2010-06-20 02:21:46 +00007655 mogrify_info=CloneImageInfo(image_info);
7656 quantize_info=AcquireQuantizeInfo(mogrify_info);
cristy3ed852e2009-09-05 21:47:34 +00007657 status=MagickTrue;
cristybb503372010-05-27 20:51:26 +00007658 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00007659 {
cristy74fe8f12009-10-03 19:09:01 +00007660 if (*images == (Image *) NULL)
7661 break;
cristy3ed852e2009-09-05 21:47:34 +00007662 option=argv[i];
cristy042ee782011-04-22 18:48:30 +00007663 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00007664 continue;
cristy042ee782011-04-22 18:48:30 +00007665 count=ParseCommandOption(MagickCommandOptions,MagickFalse,option);
anthonyce2716b2011-04-22 09:51:34 +00007666 count=MagickMax(count,0L);
cristycee97112010-05-28 00:44:52 +00007667 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00007668 break;
cristy6b3da3a2010-06-20 02:21:46 +00007669 status=MogrifyImageInfo(mogrify_info,(int) count+1,argv+i,exception);
cristy3ed852e2009-09-05 21:47:34 +00007670 switch (*(option+1))
7671 {
7672 case 'a':
7673 {
7674 if (LocaleCompare("affinity",option+1) == 0)
7675 {
cristy6fccee12011-10-20 18:43:18 +00007676 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007677 if (*option == '+')
7678 {
cristy018f07f2011-09-04 21:15:19 +00007679 (void) RemapImages(quantize_info,*images,(Image *) NULL,
7680 exception);
cristy3ed852e2009-09-05 21:47:34 +00007681 break;
7682 }
7683 i++;
7684 break;
7685 }
7686 if (LocaleCompare("append",option+1) == 0)
7687 {
7688 Image
7689 *append_image;
7690
cristy6fccee12011-10-20 18:43:18 +00007691 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007692 append_image=AppendImages(*images,*option == '-' ? MagickTrue :
7693 MagickFalse,exception);
7694 if (append_image == (Image *) NULL)
7695 {
7696 status=MagickFalse;
7697 break;
7698 }
7699 *images=DestroyImageList(*images);
7700 *images=append_image;
7701 break;
7702 }
cristy52ad9e92013-02-08 23:23:29 +00007703 if (LocaleCompare("average",option+1) == 0)
7704 {
7705 Image
7706 *average_image;
7707
7708 /*
7709 Average an image sequence (deprecated).
7710 */
7711 (void) SyncImagesSettings(mogrify_info,*images,exception);
7712 average_image=EvaluateImages(*images,MeanEvaluateOperator,
7713 exception);
7714 if (average_image == (Image *) NULL)
7715 {
7716 status=MagickFalse;
7717 break;
7718 }
7719 *images=DestroyImageList(*images);
7720 *images=average_image;
7721 break;
7722 }
cristy3ed852e2009-09-05 21:47:34 +00007723 break;
7724 }
7725 case 'c':
7726 {
cristy5f257b22012-03-07 00:27:29 +00007727 if (LocaleCompare("channel-fx",option+1) == 0)
cristy87c02f42012-02-24 00:19:10 +00007728 {
cristyd04e7bf2012-03-03 19:19:12 +00007729 Image
7730 *channel_image;
7731
7732 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy5f257b22012-03-07 00:27:29 +00007733 channel_image=ChannelFxImage(*images,argv[i+1],exception);
cristyd04e7bf2012-03-03 19:19:12 +00007734 if (channel_image == (Image *) NULL)
7735 {
7736 status=MagickFalse;
7737 break;
7738 }
7739 *images=DestroyImageList(*images);
7740 *images=channel_image;
cristy87c02f42012-02-24 00:19:10 +00007741 break;
7742 }
cristy3ed852e2009-09-05 21:47:34 +00007743 if (LocaleCompare("clut",option+1) == 0)
7744 {
7745 Image
7746 *clut_image,
7747 *image;
7748
cristy6fccee12011-10-20 18:43:18 +00007749 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007750 image=RemoveFirstImageFromList(images);
7751 clut_image=RemoveFirstImageFromList(images);
7752 if (clut_image == (Image *) NULL)
7753 {
7754 status=MagickFalse;
7755 break;
7756 }
cristy28474bf2011-09-11 23:32:52 +00007757 (void) ClutImage(image,clut_image,interpolate_method,exception);
cristy3ed852e2009-09-05 21:47:34 +00007758 clut_image=DestroyImage(clut_image);
cristy3ed852e2009-09-05 21:47:34 +00007759 *images=DestroyImageList(*images);
7760 *images=image;
7761 break;
7762 }
7763 if (LocaleCompare("coalesce",option+1) == 0)
7764 {
7765 Image
7766 *coalesce_image;
7767
cristy6fccee12011-10-20 18:43:18 +00007768 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007769 coalesce_image=CoalesceImages(*images,exception);
7770 if (coalesce_image == (Image *) NULL)
7771 {
7772 status=MagickFalse;
7773 break;
7774 }
7775 *images=DestroyImageList(*images);
7776 *images=coalesce_image;
7777 break;
7778 }
7779 if (LocaleCompare("combine",option+1) == 0)
7780 {
cristy46f354c2012-07-04 13:31:29 +00007781 ColorspaceType
7782 colorspace;
7783
cristy3ed852e2009-09-05 21:47:34 +00007784 Image
7785 *combine_image;
7786
cristy6fccee12011-10-20 18:43:18 +00007787 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy9a0e8ef2015-05-11 23:20:15 +00007788 colorspace=(*images)->colorspace;
7789 if (*option == '+')
cristyc4a7b842015-05-09 12:27:33 +00007790 colorspace=(ColorspaceType) ParseCommandOption(
7791 MagickColorspaceOptions,MagickFalse,argv[i+1]);
cristy46f354c2012-07-04 13:31:29 +00007792 combine_image=CombineImages(*images,colorspace,exception);
cristy3ed852e2009-09-05 21:47:34 +00007793 if (combine_image == (Image *) NULL)
7794 {
7795 status=MagickFalse;
7796 break;
7797 }
7798 *images=DestroyImageList(*images);
7799 *images=combine_image;
7800 break;
7801 }
cristyb92495a2013-08-20 00:10:59 +00007802 if (LocaleCompare("compare",option+1) == 0)
7803 {
7804 double
7805 distortion;
7806
7807 Image
7808 *difference_image,
7809 *image,
7810 *reconstruct_image;
7811
cristyf4185122013-08-20 00:58:56 +00007812 MetricType
7813 metric;
7814
cristyb92495a2013-08-20 00:10:59 +00007815 /*
7816 Mathematically and visually annotate the difference between an
7817 image and its reconstruction.
7818 */
7819 (void) SyncImagesSettings(mogrify_info,*images,exception);
7820 image=RemoveFirstImageFromList(images);
7821 reconstruct_image=RemoveFirstImageFromList(images);
7822 if (reconstruct_image == (Image *) NULL)
7823 {
7824 status=MagickFalse;
7825 break;
7826 }
cristy7718e802013-08-20 11:39:31 +00007827 metric=UndefinedErrorMetric;
cristyf4185122013-08-20 00:58:56 +00007828 option=GetImageOption(image_info,"metric");
7829 if (option != (const char *) NULL)
7830 metric=(MetricType) ParseCommandOption(MagickMetricOptions,
7831 MagickFalse,option);
cristyb92495a2013-08-20 00:10:59 +00007832 difference_image=CompareImages(image,reconstruct_image,metric,
7833 &distortion,exception);
7834 if (difference_image == (Image *) NULL)
7835 break;
7836 if (*images != (Image *) NULL)
7837 *images=DestroyImage(*images);
7838 *images=difference_image;
7839 break;
7840 }
cristy790190d2013-10-04 00:51:51 +00007841 if (LocaleCompare("complex",option+1) == 0)
7842 {
cristy790190d2013-10-04 00:51:51 +00007843 ComplexOperator
cristy6398ec72013-11-28 02:00:27 +00007844 op;
cristy790190d2013-10-04 00:51:51 +00007845
cristy34919ed2013-10-06 15:42:40 +00007846 Image
7847 *complex_images;
7848
cristy790190d2013-10-04 00:51:51 +00007849 (void) SyncImageSettings(mogrify_info,*images,exception);
cristy6398ec72013-11-28 02:00:27 +00007850 op=(ComplexOperator) ParseCommandOption(MagickComplexOptions,
cristy790190d2013-10-04 00:51:51 +00007851 MagickFalse,argv[i+1]);
cristy6398ec72013-11-28 02:00:27 +00007852 complex_images=ComplexImages(*images,op,exception);
cristy34919ed2013-10-06 15:42:40 +00007853 if (complex_images == (Image *) NULL)
cristy790190d2013-10-04 00:51:51 +00007854 {
7855 status=MagickFalse;
7856 break;
7857 }
7858 *images=DestroyImageList(*images);
cristy34919ed2013-10-06 15:42:40 +00007859 *images=complex_images;
cristy790190d2013-10-04 00:51:51 +00007860 break;
7861 }
cristy3ed852e2009-09-05 21:47:34 +00007862 if (LocaleCompare("composite",option+1) == 0)
7863 {
cristy542a95b2012-04-03 19:30:58 +00007864 const char
7865 *value;
7866
cristy3ed852e2009-09-05 21:47:34 +00007867 Image
7868 *mask_image,
7869 *composite_image,
7870 *image;
7871
cristyfeb3e962012-03-29 17:25:55 +00007872 MagickBooleanType
7873 clip_to_self;
7874
cristy3ed852e2009-09-05 21:47:34 +00007875 RectangleInfo
7876 geometry;
7877
cristy6fccee12011-10-20 18:43:18 +00007878 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy542a95b2012-04-03 19:30:58 +00007879 value=GetImageOption(mogrify_info,"compose:clip-to-self");
7880 if (value == (const char *) NULL)
7881 clip_to_self=MagickTrue;
7882 else
7883 clip_to_self=IsStringTrue(GetImageOption(mogrify_info,
7884 "compose:clip-to-self")); /* if this is true */
dirk9a846de2015-07-25 16:51:01 +00007885 if (clip_to_self == MagickFalse) /* or */
7886 clip_to_self=IsStringFalse(GetImageOption(mogrify_info,
7887 "compose:outside-overlay"));
cristy3ed852e2009-09-05 21:47:34 +00007888 image=RemoveFirstImageFromList(images);
7889 composite_image=RemoveFirstImageFromList(images);
7890 if (composite_image == (Image *) NULL)
7891 {
7892 status=MagickFalse;
7893 break;
7894 }
7895 (void) TransformImage(&composite_image,(char *) NULL,
cristye941a752011-10-15 01:52:48 +00007896 composite_image->geometry,exception);
cristy3ed852e2009-09-05 21:47:34 +00007897 SetGeometry(composite_image,&geometry);
7898 (void) ParseAbsoluteGeometry(composite_image->geometry,&geometry);
7899 GravityAdjustGeometry(image->columns,image->rows,image->gravity,
7900 &geometry);
7901 mask_image=RemoveFirstImageFromList(images);
cristy052d1f72015-01-04 21:10:37 +00007902 if (mask_image == (Image *) NULL)
7903 (void) CompositeImage(image,composite_image,image->compose,
7904 clip_to_self,geometry.x,geometry.y,exception);
7905 else
cristy3ed852e2009-09-05 21:47:34 +00007906 {
cristyfae52a22014-11-27 21:49:03 +00007907 if ((image->compose != DisplaceCompositeOp) &&
7908 (image->compose != DistortCompositeOp))
cristy052d1f72015-01-04 21:10:37 +00007909 {
7910 status&=CompositeImage(composite_image,mask_image,
7911 CopyGreenCompositeOp,MagickTrue,0,0,exception);
7912 (void) CompositeImage(image,composite_image,image->compose,
7913 clip_to_self,geometry.x,geometry.y,exception);
7914 }
7915 else
7916 {
7917 Image
7918 *clone_image;
7919
7920 clone_image=CloneImage(image,0,0,MagickTrue,exception);
7921 if (clone_image == (Image *) NULL)
7922 break;
7923 (void) CompositeImage(image,composite_image,image->compose,
7924 clip_to_self,geometry.x,geometry.y,exception);
7925 status&=CompositeImage(image,mask_image,
7926 CopyAlphaCompositeOp,MagickTrue,0,0,exception);
7927 status&=CompositeImage(clone_image,image,OverCompositeOp,
Cristy087a0592015-08-30 16:40:35 -04007928 clip_to_self,0,0,exception);
cristy052d1f72015-01-04 21:10:37 +00007929 image=DestroyImage(image);
7930 image=clone_image;
7931 }
cristyfe831852013-02-12 14:56:07 +00007932 mask_image=DestroyImage(mask_image);
cristy3ed852e2009-09-05 21:47:34 +00007933 }
cristy3ed852e2009-09-05 21:47:34 +00007934 composite_image=DestroyImage(composite_image);
cristy3ed852e2009-09-05 21:47:34 +00007935 *images=DestroyImageList(*images);
7936 *images=image;
7937 break;
7938 }
cristy8c4c1c42015-06-22 23:51:22 +00007939 if (LocaleCompare("copy",option+1) == 0)
7940 {
7941 Image
7942 *source_image;
7943
7944 OffsetInfo
7945 offset;
7946
7947 RectangleInfo
7948 geometry;
7949
7950 /*
7951 Copy image pixels.
7952 */
7953 (void) SyncImageSettings(mogrify_info,*images,exception);
7954 (void) ParsePageGeometry(*images,argv[i+2],&geometry,exception);
7955 offset.x=geometry.x;
7956 offset.y=geometry.y;
7957 source_image=(*images);
7958 if (source_image->next != (Image *) NULL)
7959 source_image=source_image->next;
7960 (void) ParsePageGeometry(source_image,argv[i+1],&geometry,
7961 exception);
7962 status=CopyImagePixels(*images,source_image,&geometry,&offset,
7963 exception);
7964 break;
7965 }
cristy3ed852e2009-09-05 21:47:34 +00007966 break;
7967 }
7968 case 'd':
7969 {
7970 if (LocaleCompare("deconstruct",option+1) == 0)
7971 {
7972 Image
7973 *deconstruct_image;
7974
cristy6fccee12011-10-20 18:43:18 +00007975 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy8a9106f2011-07-05 14:39:26 +00007976 deconstruct_image=CompareImagesLayers(*images,CompareAnyLayer,
cristy4c08aed2011-07-01 19:47:50 +00007977 exception);
cristy3ed852e2009-09-05 21:47:34 +00007978 if (deconstruct_image == (Image *) NULL)
7979 {
7980 status=MagickFalse;
7981 break;
7982 }
7983 *images=DestroyImageList(*images);
7984 *images=deconstruct_image;
7985 break;
7986 }
7987 if (LocaleCompare("delete",option+1) == 0)
7988 {
7989 if (*option == '+')
7990 DeleteImages(images,"-1",exception);
7991 else
7992 DeleteImages(images,argv[i+1],exception);
7993 break;
7994 }
7995 if (LocaleCompare("dither",option+1) == 0)
7996 {
7997 if (*option == '+')
7998 {
cristycbda6112012-05-27 20:57:16 +00007999 quantize_info->dither_method=NoDitherMethod;
cristy3ed852e2009-09-05 21:47:34 +00008000 break;
8001 }
cristy042ee782011-04-22 18:48:30 +00008002 quantize_info->dither_method=(DitherMethod) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00008003 MagickDitherOptions,MagickFalse,argv[i+1]);
8004 break;
8005 }
cristyecb10ff2011-03-22 13:14:03 +00008006 if (LocaleCompare("duplicate",option+1) == 0)
8007 {
cristy72988482011-03-29 16:34:38 +00008008 Image
8009 *duplicate_images;
cristybf95deb2011-03-23 00:25:36 +00008010
anthony2b6bcae2011-03-23 13:05:34 +00008011 if (*option == '+')
cristy72988482011-03-29 16:34:38 +00008012 duplicate_images=DuplicateImages(*images,1,"-1",exception);
8013 else
8014 {
8015 const char
8016 *p;
8017
anthony2b6bcae2011-03-23 13:05:34 +00008018 size_t
8019 number_duplicates;
anthony9bd15492011-03-23 02:11:13 +00008020
anthony2b6bcae2011-03-23 13:05:34 +00008021 number_duplicates=(size_t) StringToLong(argv[i+1]);
cristy72988482011-03-29 16:34:38 +00008022 p=strchr(argv[i+1],',');
8023 if (p == (const char *) NULL)
8024 duplicate_images=DuplicateImages(*images,number_duplicates,
8025 "-1",exception);
anthony2b6bcae2011-03-23 13:05:34 +00008026 else
cristy72988482011-03-29 16:34:38 +00008027 duplicate_images=DuplicateImages(*images,number_duplicates,p,
8028 exception);
anthony2b6bcae2011-03-23 13:05:34 +00008029 }
8030 AppendImageToList(images, duplicate_images);
cristy6fccee12011-10-20 18:43:18 +00008031 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristyecb10ff2011-03-22 13:14:03 +00008032 break;
8033 }
cristy3ed852e2009-09-05 21:47:34 +00008034 break;
8035 }
cristyd18ae7c2010-03-07 17:39:52 +00008036 case 'e':
8037 {
8038 if (LocaleCompare("evaluate-sequence",option+1) == 0)
8039 {
8040 Image
8041 *evaluate_image;
8042
8043 MagickEvaluateOperator
8044 op;
8045
cristy6fccee12011-10-20 18:43:18 +00008046 (void) SyncImageSettings(mogrify_info,*images,exception);
cristy28474bf2011-09-11 23:32:52 +00008047 op=(MagickEvaluateOperator) ParseCommandOption(
8048 MagickEvaluateOptions,MagickFalse,argv[i+1]);
cristyd18ae7c2010-03-07 17:39:52 +00008049 evaluate_image=EvaluateImages(*images,op,exception);
8050 if (evaluate_image == (Image *) NULL)
8051 {
8052 status=MagickFalse;
8053 break;
8054 }
8055 *images=DestroyImageList(*images);
8056 *images=evaluate_image;
8057 break;
8058 }
8059 break;
8060 }
cristy3ed852e2009-09-05 21:47:34 +00008061 case 'f':
8062 {
cristyf0a247f2009-10-04 00:20:03 +00008063 if (LocaleCompare("fft",option+1) == 0)
8064 {
8065 Image
8066 *fourier_image;
8067
8068 /*
8069 Implements the discrete Fourier transform (DFT).
8070 */
cristy6fccee12011-10-20 18:43:18 +00008071 (void) SyncImageSettings(mogrify_info,*images,exception);
cristyf0a247f2009-10-04 00:20:03 +00008072 fourier_image=ForwardFourierTransformImage(*images,*option == '-' ?
8073 MagickTrue : MagickFalse,exception);
8074 if (fourier_image == (Image *) NULL)
8075 break;
8076 *images=DestroyImage(*images);
8077 *images=fourier_image;
8078 break;
8079 }
cristy3ed852e2009-09-05 21:47:34 +00008080 if (LocaleCompare("flatten",option+1) == 0)
8081 {
8082 Image
8083 *flatten_image;
8084
cristy6fccee12011-10-20 18:43:18 +00008085 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00008086 flatten_image=MergeImageLayers(*images,FlattenLayer,exception);
8087 if (flatten_image == (Image *) NULL)
8088 break;
8089 *images=DestroyImageList(*images);
8090 *images=flatten_image;
8091 break;
8092 }
8093 if (LocaleCompare("fx",option+1) == 0)
8094 {
8095 Image
8096 *fx_image;
8097
cristy6fccee12011-10-20 18:43:18 +00008098 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy490408a2011-07-07 14:42:05 +00008099 fx_image=FxImage(*images,argv[i+1],exception);
cristy3ed852e2009-09-05 21:47:34 +00008100 if (fx_image == (Image *) NULL)
8101 {
8102 status=MagickFalse;
8103 break;
8104 }
8105 *images=DestroyImageList(*images);
8106 *images=fx_image;
8107 break;
8108 }
8109 break;
8110 }
8111 case 'h':
8112 {
8113 if (LocaleCompare("hald-clut",option+1) == 0)
8114 {
8115 Image
8116 *hald_image,
8117 *image;
8118
cristy6fccee12011-10-20 18:43:18 +00008119 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00008120 image=RemoveFirstImageFromList(images);
8121 hald_image=RemoveFirstImageFromList(images);
8122 if (hald_image == (Image *) NULL)
8123 {
8124 status=MagickFalse;
8125 break;
8126 }
cristy7c0a0a42011-08-23 17:57:25 +00008127 (void) HaldClutImage(image,hald_image,exception);
cristy3ed852e2009-09-05 21:47:34 +00008128 hald_image=DestroyImage(hald_image);
cristy0aff6ea2009-11-14 01:40:53 +00008129 if (*images != (Image *) NULL)
8130 *images=DestroyImageList(*images);
cristy3ed852e2009-09-05 21:47:34 +00008131 *images=image;
8132 break;
8133 }
8134 break;
8135 }
8136 case 'i':
8137 {
8138 if (LocaleCompare("ift",option+1) == 0)
8139 {
8140 Image
cristy8587f882009-11-13 20:28:49 +00008141 *fourier_image,
8142 *magnitude_image,
8143 *phase_image;
cristy3ed852e2009-09-05 21:47:34 +00008144
8145 /*
8146 Implements the inverse fourier discrete Fourier transform (DFT).
8147 */
cristy6fccee12011-10-20 18:43:18 +00008148 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy8587f882009-11-13 20:28:49 +00008149 magnitude_image=RemoveFirstImageFromList(images);
8150 phase_image=RemoveFirstImageFromList(images);
8151 if (phase_image == (Image *) NULL)
8152 {
8153 status=MagickFalse;
8154 break;
8155 }
8156 fourier_image=InverseFourierTransformImage(magnitude_image,
8157 phase_image,*option == '-' ? MagickTrue : MagickFalse,exception);
cristy3ed852e2009-09-05 21:47:34 +00008158 if (fourier_image == (Image *) NULL)
8159 break;
cristy0aff6ea2009-11-14 01:40:53 +00008160 if (*images != (Image *) NULL)
8161 *images=DestroyImage(*images);
cristy3ed852e2009-09-05 21:47:34 +00008162 *images=fourier_image;
8163 break;
8164 }
8165 if (LocaleCompare("insert",option+1) == 0)
8166 {
8167 Image
8168 *p,
8169 *q;
8170
8171 index=0;
8172 if (*option != '+')
cristy32c2aea2010-12-01 01:00:50 +00008173 index=(ssize_t) StringToLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00008174 p=RemoveLastImageFromList(images);
8175 if (p == (Image *) NULL)
8176 {
8177 (void) ThrowMagickException(exception,GetMagickModule(),
cristyefe601c2013-01-05 17:51:12 +00008178 OptionError,"NoSuchImage","`%s'",argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00008179 status=MagickFalse;
8180 break;
8181 }
8182 q=p;
8183 if (index == 0)
8184 PrependImageToList(images,q);
8185 else
cristybb503372010-05-27 20:51:26 +00008186 if (index == (ssize_t) GetImageListLength(*images))
cristy3ed852e2009-09-05 21:47:34 +00008187 AppendImageToList(images,q);
8188 else
8189 {
8190 q=GetImageFromList(*images,index-1);
8191 if (q == (Image *) NULL)
8192 {
8193 (void) ThrowMagickException(exception,GetMagickModule(),
cristyefe601c2013-01-05 17:51:12 +00008194 OptionError,"NoSuchImage","`%s'",argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00008195 status=MagickFalse;
8196 break;
8197 }
8198 InsertImageInList(&q,p);
8199 }
8200 *images=GetFirstImageInList(q);
8201 break;
8202 }
cristy28474bf2011-09-11 23:32:52 +00008203 if (LocaleCompare("interpolate",option+1) == 0)
8204 {
8205 interpolate_method=(PixelInterpolateMethod) ParseCommandOption(
8206 MagickInterpolateOptions,MagickFalse,argv[i+1]);
8207 break;
8208 }
cristy3ed852e2009-09-05 21:47:34 +00008209 break;
8210 }
8211 case 'l':
8212 {
8213 if (LocaleCompare("layers",option+1) == 0)
8214 {
8215 Image
8216 *layers;
8217
cristya0417062012-09-02 23:34:56 +00008218 LayerMethod
cristy3ed852e2009-09-05 21:47:34 +00008219 method;
8220
cristy6fccee12011-10-20 18:43:18 +00008221 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00008222 layers=(Image *) NULL;
cristya0417062012-09-02 23:34:56 +00008223 method=(LayerMethod) ParseCommandOption(MagickLayerOptions,
cristy3ed852e2009-09-05 21:47:34 +00008224 MagickFalse,argv[i+1]);
8225 switch (method)
8226 {
8227 case CoalesceLayer:
8228 {
8229 layers=CoalesceImages(*images,exception);
8230 break;
8231 }
8232 case CompareAnyLayer:
8233 case CompareClearLayer:
8234 case CompareOverlayLayer:
8235 default:
8236 {
cristy8a9106f2011-07-05 14:39:26 +00008237 layers=CompareImagesLayers(*images,method,exception);
cristy3ed852e2009-09-05 21:47:34 +00008238 break;
8239 }
8240 case MergeLayer:
8241 case FlattenLayer:
8242 case MosaicLayer:
8243 case TrimBoundsLayer:
8244 {
8245 layers=MergeImageLayers(*images,method,exception);
8246 break;
8247 }
8248 case DisposeLayer:
8249 {
8250 layers=DisposeImages(*images,exception);
8251 break;
8252 }
8253 case OptimizeImageLayer:
8254 {
8255 layers=OptimizeImageLayers(*images,exception);
8256 break;
8257 }
8258 case OptimizePlusLayer:
8259 {
8260 layers=OptimizePlusImageLayers(*images,exception);
8261 break;
8262 }
8263 case OptimizeTransLayer:
8264 {
8265 OptimizeImageTransparency(*images,exception);
8266 break;
8267 }
8268 case RemoveDupsLayer:
8269 {
8270 RemoveDuplicateLayers(images,exception);
8271 break;
8272 }
8273 case RemoveZeroLayer:
8274 {
8275 RemoveZeroDelayLayers(images,exception);
8276 break;
8277 }
8278 case OptimizeLayer:
8279 {
8280 /*
8281 General Purpose, GIF Animation Optimizer.
8282 */
8283 layers=CoalesceImages(*images,exception);
8284 if (layers == (Image *) NULL)
8285 {
8286 status=MagickFalse;
8287 break;
8288 }
cristy3ed852e2009-09-05 21:47:34 +00008289 *images=DestroyImageList(*images);
8290 *images=layers;
8291 layers=OptimizeImageLayers(*images,exception);
8292 if (layers == (Image *) NULL)
8293 {
8294 status=MagickFalse;
8295 break;
8296 }
cristy3ed852e2009-09-05 21:47:34 +00008297 *images=DestroyImageList(*images);
8298 *images=layers;
8299 layers=(Image *) NULL;
8300 OptimizeImageTransparency(*images,exception);
cristy018f07f2011-09-04 21:15:19 +00008301 (void) RemapImages(quantize_info,*images,(Image *) NULL,
8302 exception);
cristy3ed852e2009-09-05 21:47:34 +00008303 break;
8304 }
8305 case CompositeLayer:
8306 {
8307 CompositeOperator
8308 compose;
8309
8310 Image
8311 *source;
8312
8313 RectangleInfo
8314 geometry;
8315
8316 /*
8317 Split image sequence at the first 'NULL:' image.
8318 */
8319 source=(*images);
8320 while (source != (Image *) NULL)
8321 {
8322 source=GetNextImageInList(source);
8323 if ((source != (Image *) NULL) &&
8324 (LocaleCompare(source->magick,"NULL") == 0))
8325 break;
8326 }
8327 if (source != (Image *) NULL)
8328 {
8329 if ((GetPreviousImageInList(source) == (Image *) NULL) ||
8330 (GetNextImageInList(source) == (Image *) NULL))
8331 source=(Image *) NULL;
8332 else
8333 {
8334 /*
8335 Separate the two lists, junk the null: image.
8336 */
8337 source=SplitImageList(source->previous);
8338 DeleteImageFromList(&source);
8339 }
8340 }
8341 if (source == (Image *) NULL)
8342 {
8343 (void) ThrowMagickException(exception,GetMagickModule(),
8344 OptionError,"MissingNullSeparator","layers Composite");
8345 status=MagickFalse;
8346 break;
8347 }
8348 /*
8349 Adjust offset with gravity and virtual canvas.
8350 */
8351 SetGeometry(*images,&geometry);
8352 (void) ParseAbsoluteGeometry((*images)->geometry,&geometry);
8353 geometry.width=source->page.width != 0 ?
8354 source->page.width : source->columns;
8355 geometry.height=source->page.height != 0 ?
8356 source->page.height : source->rows;
8357 GravityAdjustGeometry((*images)->page.width != 0 ?
8358 (*images)->page.width : (*images)->columns,
8359 (*images)->page.height != 0 ? (*images)->page.height :
8360 (*images)->rows,(*images)->gravity,&geometry);
8361 compose=OverCompositeOp;
cristy6b3da3a2010-06-20 02:21:46 +00008362 option=GetImageOption(mogrify_info,"compose");
cristy3ed852e2009-09-05 21:47:34 +00008363 if (option != (const char *) NULL)
cristy042ee782011-04-22 18:48:30 +00008364 compose=(CompositeOperator) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00008365 MagickComposeOptions,MagickFalse,option);
8366 CompositeLayers(*images,compose,source,geometry.x,geometry.y,
8367 exception);
8368 source=DestroyImageList(source);
8369 break;
8370 }
8371 }
8372 if (layers == (Image *) NULL)
8373 break;
cristy3ed852e2009-09-05 21:47:34 +00008374 *images=DestroyImageList(*images);
8375 *images=layers;
8376 break;
8377 }
8378 break;
8379 }
8380 case 'm':
8381 {
8382 if (LocaleCompare("map",option+1) == 0)
8383 {
cristy6fccee12011-10-20 18:43:18 +00008384 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00008385 if (*option == '+')
8386 {
cristy018f07f2011-09-04 21:15:19 +00008387 (void) RemapImages(quantize_info,*images,(Image *) NULL,
8388 exception);
cristy3ed852e2009-09-05 21:47:34 +00008389 break;
8390 }
8391 i++;
8392 break;
8393 }
cristy52ad9e92013-02-08 23:23:29 +00008394 if (LocaleCompare("maximum",option+1) == 0)
8395 {
8396 Image
8397 *maximum_image;
8398
8399 /*
8400 Maximum image sequence (deprecated).
8401 */
8402 (void) SyncImagesSettings(mogrify_info,*images,exception);
8403 maximum_image=EvaluateImages(*images,MaxEvaluateOperator,exception);
8404 if (maximum_image == (Image *) NULL)
8405 {
8406 status=MagickFalse;
8407 break;
8408 }
8409 *images=DestroyImageList(*images);
8410 *images=maximum_image;
8411 break;
8412 }
8413 if (LocaleCompare("minimum",option+1) == 0)
8414 {
8415 Image
8416 *minimum_image;
8417
8418 /*
8419 Minimum image sequence (deprecated).
8420 */
8421 (void) SyncImagesSettings(mogrify_info,*images,exception);
8422 minimum_image=EvaluateImages(*images,MinEvaluateOperator,exception);
8423 if (minimum_image == (Image *) NULL)
8424 {
8425 status=MagickFalse;
8426 break;
8427 }
8428 *images=DestroyImageList(*images);
8429 *images=minimum_image;
8430 break;
8431 }
cristy3ed852e2009-09-05 21:47:34 +00008432 if (LocaleCompare("morph",option+1) == 0)
8433 {
8434 Image
8435 *morph_image;
8436
cristy6fccee12011-10-20 18:43:18 +00008437 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristye27293e2009-12-18 02:53:20 +00008438 morph_image=MorphImages(*images,StringToUnsignedLong(argv[i+1]),
cristy3ed852e2009-09-05 21:47:34 +00008439 exception);
8440 if (morph_image == (Image *) NULL)
8441 {
8442 status=MagickFalse;
8443 break;
8444 }
8445 *images=DestroyImageList(*images);
8446 *images=morph_image;
8447 break;
8448 }
8449 if (LocaleCompare("mosaic",option+1) == 0)
8450 {
8451 Image
8452 *mosaic_image;
8453
cristy6fccee12011-10-20 18:43:18 +00008454 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00008455 mosaic_image=MergeImageLayers(*images,MosaicLayer,exception);
8456 if (mosaic_image == (Image *) NULL)
8457 {
8458 status=MagickFalse;
8459 break;
8460 }
8461 *images=DestroyImageList(*images);
8462 *images=mosaic_image;
8463 break;
8464 }
8465 break;
8466 }
8467 case 'p':
8468 {
cristy02016cf2012-11-13 01:14:41 +00008469 if (LocaleCompare("poly",option+1) == 0)
8470 {
8471 char
8472 *args,
cristy151b66d2015-04-15 10:50:31 +00008473 token[MagickPathExtent];
cristy02016cf2012-11-13 01:14:41 +00008474
8475 const char
8476 *p;
8477
8478 double
8479 *arguments;
8480
8481 Image
8482 *polynomial_image;
8483
8484 register ssize_t
8485 x;
8486
8487 size_t
8488 number_arguments;
8489
8490 /*
8491 Polynomial image.
8492 */
8493 (void) SyncImageSettings(mogrify_info,*images,exception);
8494 args=InterpretImageProperties(mogrify_info,*images,argv[i+1],
8495 exception);
8496 if (args == (char *) NULL)
8497 break;
8498 p=(char *) args;
8499 for (x=0; *p != '\0'; x++)
8500 {
8501 GetMagickToken(p,&p,token);
8502 if (*token == ',')
8503 GetMagickToken(p,&p,token);
8504 }
8505 number_arguments=(size_t) x;
8506 arguments=(double *) AcquireQuantumMemory(number_arguments,
8507 sizeof(*arguments));
8508 if (arguments == (double *) NULL)
8509 ThrowWandFatalException(ResourceLimitFatalError,
8510 "MemoryAllocationFailed",(*images)->filename);
8511 (void) ResetMagickMemory(arguments,0,number_arguments*
8512 sizeof(*arguments));
8513 p=(char *) args;
8514 for (x=0; (x < (ssize_t) number_arguments) && (*p != '\0'); x++)
8515 {
8516 GetMagickToken(p,&p,token);
8517 if (*token == ',')
8518 GetMagickToken(p,&p,token);
8519 arguments[x]=StringToDouble(token,(char **) NULL);
8520 }
8521 args=DestroyString(args);
8522 polynomial_image=PolynomialImage(*images,number_arguments >> 1,
8523 arguments,exception);
8524 arguments=(double *) RelinquishMagickMemory(arguments);
8525 if (polynomial_image == (Image *) NULL)
8526 {
8527 status=MagickFalse;
8528 break;
8529 }
8530 *images=DestroyImageList(*images);
8531 *images=polynomial_image;
8532 }
cristy3ed852e2009-09-05 21:47:34 +00008533 if (LocaleCompare("print",option+1) == 0)
8534 {
8535 char
8536 *string;
8537
cristy6fccee12011-10-20 18:43:18 +00008538 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy018f07f2011-09-04 21:15:19 +00008539 string=InterpretImageProperties(mogrify_info,*images,argv[i+1],
8540 exception);
cristy3ed852e2009-09-05 21:47:34 +00008541 if (string == (char *) NULL)
8542 break;
cristyb51dff52011-05-19 16:55:47 +00008543 (void) FormatLocaleFile(stdout,"%s",string);
cristy3ed852e2009-09-05 21:47:34 +00008544 string=DestroyString(string);
8545 }
8546 if (LocaleCompare("process",option+1) == 0)
8547 {
8548 char
8549 **arguments;
8550
8551 int
8552 j,
8553 number_arguments;
8554
cristy6fccee12011-10-20 18:43:18 +00008555 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00008556 arguments=StringToArgv(argv[i+1],&number_arguments);
8557 if (arguments == (char **) NULL)
8558 break;
8559 if ((argc > 1) && (strchr(arguments[1],'=') != (char *) NULL))
8560 {
8561 char
8562 breaker,
8563 quote,
8564 *token;
8565
8566 const char
dirkb4979cb2015-11-22 10:01:27 +01008567 *argument;
cristy3ed852e2009-09-05 21:47:34 +00008568
8569 int
8570 next,
dirkb4979cb2015-11-22 10:01:27 +01008571 token_status;
cristy3ed852e2009-09-05 21:47:34 +00008572
8573 size_t
8574 length;
8575
8576 TokenInfo
8577 *token_info;
8578
8579 /*
8580 Support old style syntax, filter="-option arg".
8581 */
8582 length=strlen(argv[i+1]);
8583 token=(char *) NULL;
cristy151b66d2015-04-15 10:50:31 +00008584 if (~length >= (MagickPathExtent-1))
8585 token=(char *) AcquireQuantumMemory(length+MagickPathExtent,
cristy3ed852e2009-09-05 21:47:34 +00008586 sizeof(*token));
8587 if (token == (char *) NULL)
8588 break;
8589 next=0;
dirkb4979cb2015-11-22 10:01:27 +01008590 argument=argv[i+1];
cristy3ed852e2009-09-05 21:47:34 +00008591 token_info=AcquireTokenInfo();
dirkb4979cb2015-11-22 10:01:27 +01008592 token_status=Tokenizer(token_info,0,token,length,argument,"",
8593 "=","\"",'\0',&breaker,&next,&quote);
cristy3ed852e2009-09-05 21:47:34 +00008594 token_info=DestroyTokenInfo(token_info);
dirkb4979cb2015-11-22 10:01:27 +01008595 if (token_status == 0)
cristy3ed852e2009-09-05 21:47:34 +00008596 {
8597 const char
dirkb4979cb2015-11-22 10:01:27 +01008598 *arg;
cristy3ed852e2009-09-05 21:47:34 +00008599
dirkb4979cb2015-11-22 10:01:27 +01008600 arg=(&(argument[next]));
8601 (void) InvokeDynamicImageFilter(token,&(*images),1,&arg,
cristy3ed852e2009-09-05 21:47:34 +00008602 exception);
8603 }
8604 token=DestroyString(token);
8605 break;
8606 }
cristy91c0da22010-05-02 01:44:07 +00008607 (void) SubstituteString(&arguments[1],"-","");
cristy3ed852e2009-09-05 21:47:34 +00008608 (void) InvokeDynamicImageFilter(arguments[1],&(*images),
8609 number_arguments-2,(const char **) arguments+2,exception);
8610 for (j=0; j < number_arguments; j++)
8611 arguments[j]=DestroyString(arguments[j]);
8612 arguments=(char **) RelinquishMagickMemory(arguments);
8613 break;
8614 }
8615 break;
8616 }
8617 case 'r':
8618 {
8619 if (LocaleCompare("reverse",option+1) == 0)
8620 {
8621 ReverseImageList(images);
cristy3ed852e2009-09-05 21:47:34 +00008622 break;
8623 }
8624 break;
8625 }
8626 case 's':
8627 {
cristy4285d782011-02-09 20:12:28 +00008628 if (LocaleCompare("smush",option+1) == 0)
8629 {
8630 Image
8631 *smush_image;
8632
8633 ssize_t
8634 offset;
8635
cristy6fccee12011-10-20 18:43:18 +00008636 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy4285d782011-02-09 20:12:28 +00008637 offset=(ssize_t) StringToLong(argv[i+1]);
8638 smush_image=SmushImages(*images,*option == '-' ? MagickTrue :
8639 MagickFalse,offset,exception);
8640 if (smush_image == (Image *) NULL)
8641 {
8642 status=MagickFalse;
8643 break;
8644 }
8645 *images=DestroyImageList(*images);
8646 *images=smush_image;
8647 break;
8648 }
cristy3ed852e2009-09-05 21:47:34 +00008649 if (LocaleCompare("swap",option+1) == 0)
8650 {
8651 Image
8652 *p,
8653 *q,
8654 *swap;
8655
cristybb503372010-05-27 20:51:26 +00008656 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00008657 swap_index;
8658
8659 index=(-1);
8660 swap_index=(-2);
8661 if (*option != '+')
8662 {
8663 GeometryInfo
8664 geometry_info;
8665
8666 MagickStatusType
8667 flags;
8668
8669 swap_index=(-1);
8670 flags=ParseGeometry(argv[i+1],&geometry_info);
cristybb503372010-05-27 20:51:26 +00008671 index=(ssize_t) geometry_info.rho;
cristy3ed852e2009-09-05 21:47:34 +00008672 if ((flags & SigmaValue) != 0)
cristybb503372010-05-27 20:51:26 +00008673 swap_index=(ssize_t) geometry_info.sigma;
cristy3ed852e2009-09-05 21:47:34 +00008674 }
8675 p=GetImageFromList(*images,index);
8676 q=GetImageFromList(*images,swap_index);
8677 if ((p == (Image *) NULL) || (q == (Image *) NULL))
8678 {
8679 (void) ThrowMagickException(exception,GetMagickModule(),
cristyefe601c2013-01-05 17:51:12 +00008680 OptionError,"NoSuchImage","`%s'",(*images)->filename);
cristy3ed852e2009-09-05 21:47:34 +00008681 status=MagickFalse;
8682 break;
8683 }
8684 if (p == q)
8685 break;
8686 swap=CloneImage(p,0,0,MagickTrue,exception);
8687 ReplaceImageInList(&p,CloneImage(q,0,0,MagickTrue,exception));
8688 ReplaceImageInList(&q,swap);
8689 *images=GetFirstImageInList(q);
8690 break;
8691 }
8692 break;
8693 }
8694 case 'w':
8695 {
8696 if (LocaleCompare("write",option+1) == 0)
8697 {
cristy071dd7b2010-04-09 13:04:54 +00008698 char
cristy151b66d2015-04-15 10:50:31 +00008699 key[MagickPathExtent];
cristy06609ee2010-03-17 20:21:27 +00008700
cristy3ed852e2009-09-05 21:47:34 +00008701 Image
8702 *write_images;
8703
8704 ImageInfo
8705 *write_info;
8706
cristy6fccee12011-10-20 18:43:18 +00008707 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy151b66d2015-04-15 10:50:31 +00008708 (void) FormatLocaleString(key,MagickPathExtent,"cache:%s",argv[i+1]);
cristy06609ee2010-03-17 20:21:27 +00008709 (void) DeleteImageRegistry(key);
cristy3ed852e2009-09-05 21:47:34 +00008710 write_images=(*images);
8711 if (*option == '+')
8712 write_images=CloneImageList(*images,exception);
cristy6b3da3a2010-06-20 02:21:46 +00008713 write_info=CloneImageInfo(mogrify_info);
cristy3ed852e2009-09-05 21:47:34 +00008714 status&=WriteImages(write_info,write_images,argv[i+1],exception);
8715 write_info=DestroyImageInfo(write_info);
8716 if (*option == '+')
8717 write_images=DestroyImageList(write_images);
8718 break;
8719 }
8720 break;
8721 }
8722 default:
8723 break;
8724 }
8725 i+=count;
8726 }
8727 quantize_info=DestroyQuantizeInfo(quantize_info);
cristy6b3da3a2010-06-20 02:21:46 +00008728 mogrify_info=DestroyImageInfo(mogrify_info);
8729 status&=MogrifyImageInfo(image_info,argc,argv,exception);
cristy3ed852e2009-09-05 21:47:34 +00008730 return(status != 0 ? MagickTrue : MagickFalse);
8731}
8732
8733/*
8734%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8735% %
8736% %
8737% %
8738+ M o g r i f y I m a g e s %
8739% %
8740% %
8741% %
8742%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8743%
8744% MogrifyImages() applies image processing options to a sequence of images as
8745% prescribed by command line options.
8746%
8747% The format of the MogrifyImage method is:
8748%
8749% MagickBooleanType MogrifyImages(ImageInfo *image_info,
8750% const MagickBooleanType post,const int argc,const char **argv,
8751% Image **images,Exceptioninfo *exception)
8752%
8753% A description of each parameter follows:
8754%
8755% o image_info: the image info..
8756%
8757% o post: If true, post process image list operators otherwise pre-process.
8758%
8759% o argc: Specifies a pointer to an integer describing the number of
8760% elements in the argument vector.
8761%
8762% o argv: Specifies a pointer to a text array containing the command line
8763% arguments.
8764%
anthonye9c27192011-03-27 08:07:06 +00008765% o images: pointer to a pointer of the first image in image list.
cristy3ed852e2009-09-05 21:47:34 +00008766%
8767% o exception: return any errors or warnings in this structure.
8768%
8769*/
8770WandExport MagickBooleanType MogrifyImages(ImageInfo *image_info,
8771 const MagickBooleanType post,const int argc,const char **argv,
8772 Image **images,ExceptionInfo *exception)
8773{
8774#define MogrifyImageTag "Mogrify/Image"
8775
anthonye9c27192011-03-27 08:07:06 +00008776 MagickStatusType
8777 status;
cristy3ed852e2009-09-05 21:47:34 +00008778
cristy0e9f9c12010-02-11 03:00:47 +00008779 MagickBooleanType
8780 proceed;
8781
anthonye9c27192011-03-27 08:07:06 +00008782 size_t
8783 n;
cristy3ed852e2009-09-05 21:47:34 +00008784
cristybb503372010-05-27 20:51:26 +00008785 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00008786 i;
8787
cristy3ed852e2009-09-05 21:47:34 +00008788 assert(image_info != (ImageInfo *) NULL);
cristye1c94d92015-06-28 12:16:33 +00008789 assert(image_info->signature == MagickCoreSignature);
cristy3ed852e2009-09-05 21:47:34 +00008790 if (images == (Image **) NULL)
8791 return(MogrifyImage(image_info,argc,argv,images,exception));
anthonye9c27192011-03-27 08:07:06 +00008792 assert((*images)->previous == (Image *) NULL);
cristye1c94d92015-06-28 12:16:33 +00008793 assert((*images)->signature == MagickCoreSignature);
cristy3ed852e2009-09-05 21:47:34 +00008794 if ((*images)->debug != MagickFalse)
8795 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
8796 (*images)->filename);
8797 if ((argc <= 0) || (*argv == (char *) NULL))
8798 return(MagickTrue);
8799 (void) SetImageInfoProgressMonitor(image_info,(MagickProgressMonitor) NULL,
8800 (void *) NULL);
cristy35892192014-05-26 12:04:36 +00008801 status=MagickTrue;
anthonyce2716b2011-04-22 09:51:34 +00008802#if 0
cristy1e604812011-05-19 18:07:50 +00008803 (void) FormatLocaleFile(stderr, "mogrify start %s %d (%s)\n",argv[0],argc,
8804 post?"post":"pre");
anthonyce2716b2011-04-22 09:51:34 +00008805#endif
anthonye9c27192011-03-27 08:07:06 +00008806 /*
8807 Pre-process multi-image sequence operators
8808 */
cristy3ed852e2009-09-05 21:47:34 +00008809 if (post == MagickFalse)
8810 status&=MogrifyImageList(image_info,argc,argv,images,exception);
anthonye9c27192011-03-27 08:07:06 +00008811 /*
8812 For each image, process simple single image operators
8813 */
8814 i=0;
8815 n=GetImageListLength(*images);
cristy9f027d12011-09-21 01:17:17 +00008816 for ( ; ; )
cristy3ed852e2009-09-05 21:47:34 +00008817 {
anthonyce2716b2011-04-22 09:51:34 +00008818#if 0
cristy1e604812011-05-19 18:07:50 +00008819 (void) FormatLocaleFile(stderr,"mogrify %ld of %ld\n",(long)
8820 GetImageIndexInList(*images),(long)GetImageListLength(*images));
anthonyce2716b2011-04-22 09:51:34 +00008821#endif
anthonye9c27192011-03-27 08:07:06 +00008822 status&=MogrifyImage(image_info,argc,argv,images,exception);
8823 proceed=SetImageProgress(*images,MogrifyImageTag,(MagickOffsetType) i, n);
cristy0e9f9c12010-02-11 03:00:47 +00008824 if (proceed == MagickFalse)
8825 break;
anthonye9c27192011-03-27 08:07:06 +00008826 if ( (*images)->next == (Image *) NULL )
8827 break;
8828 *images=(*images)->next;
8829 i++;
cristy3ed852e2009-09-05 21:47:34 +00008830 }
anthonye9c27192011-03-27 08:07:06 +00008831 assert( *images != (Image *) NULL );
anthonyce2716b2011-04-22 09:51:34 +00008832#if 0
cristy1e604812011-05-19 18:07:50 +00008833 (void) FormatLocaleFile(stderr,"mogrify end %ld of %ld\n",(long)
8834 GetImageIndexInList(*images),(long)GetImageListLength(*images));
anthonyce2716b2011-04-22 09:51:34 +00008835#endif
anthonye9c27192011-03-27 08:07:06 +00008836 /*
8837 Post-process, multi-image sequence operators
8838 */
8839 *images=GetFirstImageInList(*images);
cristy3ed852e2009-09-05 21:47:34 +00008840 if (post != MagickFalse)
anthonye9c27192011-03-27 08:07:06 +00008841 status&=MogrifyImageList(image_info,argc,argv,images,exception);
cristy3ed852e2009-09-05 21:47:34 +00008842 return(status != 0 ? MagickTrue : MagickFalse);
8843}