blob: b35880c98605775497d2e951d78b37a7e91a9a71 [file] [log] [blame]
cristy3ed852e2009-09-05 21:47:34 +00001/*
2%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3% %
4% %
5% %
6% M M OOO GGGGG RRRR IIIII FFFFF Y Y %
7% MM MM O O G R R I F Y Y %
8% M M M O O G GGG RRRR I FFF Y %
9% M M O O G G R R I F Y %
10% M M OOO GGGG R R IIIII F Y %
11% %
12% %
13% MagickWand Module Methods %
14% %
15% Software Design %
16% John Cristy %
17% March 2000 %
18% %
19% %
cristy16af1cb2009-12-11 21:38:29 +000020% Copyright 1999-2010 ImageMagick Studio LLC, a non-profit organization %
cristy3ed852e2009-09-05 21:47:34 +000021% dedicated to making software imaging solutions freely available. %
22% %
23% You may not use this file except in compliance with the License. You may %
24% obtain a copy of the License at %
25% %
26% http://www.imagemagick.org/script/license.php %
27% %
28% Unless required by applicable law or agreed to in writing, software %
29% distributed under the License is distributed on an "AS IS" BASIS, %
30% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
31% See the License for the specific language governing permissions and %
32% limitations under the License. %
33% %
34%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35%
36% Use the mogrify program to resize an image, blur, crop, despeckle, dither,
37% draw on, flip, join, re-sample, and much more. This tool is similiar to
38% convert except that the original image file is overwritten (unless you
39% change the file suffix with the -format option) with any changes you
cristy6a917d92009-10-06 19:23:54 +000040% request.
cristy3ed852e2009-09-05 21:47:34 +000041%
42*/
43
44/*
45 Include declarations.
46*/
47#include "wand/studio.h"
48#include "wand/MagickWand.h"
49#include "wand/mogrify-private.h"
cristy0e9f9c12010-02-11 03:00:47 +000050#include "magick/monitor-private.h"
cristy3980b0d2009-10-25 14:37:13 +000051#include "magick/thread-private.h"
cristyf2f27272009-12-17 14:48:46 +000052#include "magick/string-private.h"
cristy3ed852e2009-09-05 21:47:34 +000053
54/*
55 Define declarations.
56*/
57#define UndefinedCompressionQuality 0UL
58
59/*
60 Constant declaration.
61*/
62static const char
cristy7138c592009-09-08 13:58:52 +000063 BackgroundColor[] = "#fff", /* white */
64 BorderColor[] = "#dfdfdf", /* gray */
65 MatteColor[] = "#bdbdbd"; /* gray */
cristy3ed852e2009-09-05 21:47:34 +000066
67/*
68%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
69% %
70% %
71% %
cristy3980b0d2009-10-25 14:37:13 +000072+ M a g i c k C o m m a n d G e n e s i s %
73% %
74% %
75% %
76%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
77%
78% MagickCommandGenesis() applies image processing options to an image as
79% prescribed by command line options.
80%
81% The format of the MagickCommandGenesis method is:
82%
83% MagickBooleanType MagickCommandGenesis(ImageInfo *image_info,
84% MagickCommand command,const int argc,const char **argv,Image **image)
85%
86% A description of each parameter follows:
87%
88% o image_info: the image info.
89%
90% o command: the magick command.
91%
92% o argc: Specifies a pointer to an integer describing the number of
93% elements in the argument vector.
94%
95% o argv: Specifies a pointer to a text array containing the command line
96% arguments.
97%
98% o image: the image.
99%
100% o exception: return any errors or warnings in this structure.
101%
102*/
103WandExport MagickBooleanType MagickCommandGenesis(ImageInfo *image_info,
104 MagickCommand command,int argc,char **argv,char **metadata,
105 ExceptionInfo *exception)
106{
107 char
108 *option;
109
110 double
111 duration,
112 elapsed_time,
113 user_time;
114
cristy3980b0d2009-10-25 14:37:13 +0000115 MagickBooleanType
116 concurrent,
117 regard_warnings,
118 status;
119
120 register long
121 i;
122
123 TimerInfo
124 *timer;
125
126 unsigned long
127 iterations;
128
129 concurrent=MagickFalse;
130 duration=(-1.0);
131 iterations=1;
cristy33557d72009-11-06 00:54:33 +0000132 status=MagickFalse;
cristy3980b0d2009-10-25 14:37:13 +0000133 regard_warnings=MagickFalse;
134 for (i=1; i < (long) (argc-1); i++)
135 {
136 option=argv[i];
137 if ((strlen(option) == 1) || ((*option != '-') && (*option != '+')))
138 continue;
139 if (LocaleCompare("bench",option+1) == 0)
cristye27293e2009-12-18 02:53:20 +0000140 iterations=StringToUnsignedLong(argv[++i]);
cristy3980b0d2009-10-25 14:37:13 +0000141 if (LocaleCompare("concurrent",option+1) == 0)
142 concurrent=MagickTrue;
143 if (LocaleCompare("debug",option+1) == 0)
144 (void) SetLogEventMask(argv[++i]);
145 if (LocaleCompare("duration",option+1) == 0)
cristyf2f27272009-12-17 14:48:46 +0000146 duration=StringToDouble(argv[++i]);
cristy3980b0d2009-10-25 14:37:13 +0000147 if (LocaleCompare("regard-warnings",option+1) == 0)
148 regard_warnings=MagickTrue;
149 }
150 timer=AcquireTimerInfo();
cristyceae09d2009-10-28 17:18:47 +0000151 if (concurrent == MagickFalse)
cristy3980b0d2009-10-25 14:37:13 +0000152 {
cristyceae09d2009-10-28 17:18:47 +0000153 for (i=0; i < (long) iterations; i++)
cristy3980b0d2009-10-25 14:37:13 +0000154 {
cristy33557d72009-11-06 00:54:33 +0000155 if (status != MagickFalse)
cristyceae09d2009-10-28 17:18:47 +0000156 continue;
157 if (duration > 0)
158 {
159 if (GetElapsedTime(timer) > duration)
160 continue;
161 (void) ContinueTimer(timer);
162 }
163 status=command(image_info,argc,argv,metadata,exception);
cristy3980b0d2009-10-25 14:37:13 +0000164 if (exception->severity != UndefinedException)
165 {
166 if ((exception->severity > ErrorException) ||
167 (regard_warnings != MagickFalse))
168 status=MagickTrue;
169 CatchException(exception);
170 }
cristy3d1a5512009-10-25 21:23:27 +0000171 if ((metadata != (char **) NULL) && (*metadata != (char *) NULL))
cristy3980b0d2009-10-25 14:37:13 +0000172 {
173 (void) fputs(*metadata,stdout);
174 (void) fputc('\n',stdout);
175 *metadata=DestroyString(*metadata);
176 }
177 }
178 }
cristyceae09d2009-10-28 17:18:47 +0000179 else
180 {
181 SetOpenMPNested(1);
cristyb5d5f722009-11-04 03:03:49 +0000182#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristyceae09d2009-10-28 17:18:47 +0000183 # pragma omp parallel for shared(status)
184#endif
185 for (i=0; i < (long) iterations; i++)
186 {
cristy33557d72009-11-06 00:54:33 +0000187 if (status != MagickFalse)
cristyceae09d2009-10-28 17:18:47 +0000188 continue;
189 if (duration > 0)
190 {
191 if (GetElapsedTime(timer) > duration)
192 continue;
193 (void) ContinueTimer(timer);
194 }
195 status=command(image_info,argc,argv,metadata,exception);
cristyb5d5f722009-11-04 03:03:49 +0000196#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristyceae09d2009-10-28 17:18:47 +0000197 # pragma omp critical (MagickCore_Launch_Command)
198#endif
199 {
200 if (exception->severity != UndefinedException)
201 {
202 if ((exception->severity > ErrorException) ||
203 (regard_warnings != MagickFalse))
204 status=MagickTrue;
205 CatchException(exception);
206 }
207 if ((metadata != (char **) NULL) && (*metadata != (char *) NULL))
208 {
209 (void) fputs(*metadata,stdout);
210 (void) fputc('\n',stdout);
211 *metadata=DestroyString(*metadata);
212 }
213 }
214 }
215 }
cristy3980b0d2009-10-25 14:37:13 +0000216 if (iterations > 1)
217 {
218 elapsed_time=GetElapsedTime(timer);
219 user_time=GetUserTime(timer);
cristy8cd5b312010-01-07 01:10:24 +0000220 (void) fprintf(stderr,
cristye7f51092010-01-17 00:39:37 +0000221 "Performance: %lui %gips %0.3fu %ld:%02ld.%03ld\n",
cristy3980b0d2009-10-25 14:37:13 +0000222 iterations,1.0*iterations/elapsed_time,user_time,(long)
223 (elapsed_time/60.0),(long) floor(fmod(elapsed_time,60.0)),
224 (long) (1000.0*(elapsed_time-floor(elapsed_time))));
225 }
226 timer=DestroyTimerInfo(timer);
cristy1f9e1ed2009-11-18 04:09:38 +0000227 return(status);
cristy3980b0d2009-10-25 14:37:13 +0000228}
229
230/*
231%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
232% %
233% %
234% %
cristy3ed852e2009-09-05 21:47:34 +0000235+ M o g r i f y I m a g e %
236% %
237% %
238% %
239%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
240%
241% MogrifyImage() applies image processing options to an image as prescribed
242% by command line options.
243%
244% The format of the MogrifyImage method is:
245%
246% MagickBooleanType MogrifyImage(ImageInfo *image_info,const int argc,
247% const char **argv,Image **image)
248%
249% A description of each parameter follows:
250%
251% o image_info: the image info..
252%
253% o argc: Specifies a pointer to an integer describing the number of
254% elements in the argument vector.
255%
256% o argv: Specifies a pointer to a text array containing the command line
257% arguments.
258%
259% o image: the image.
260%
261% o exception: return any errors or warnings in this structure.
262%
263*/
264
265static inline Image *GetImageCache(const ImageInfo *image_info,const char *path,
266 ExceptionInfo *exception)
267{
268 char
269 key[MaxTextExtent];
270
271 ExceptionInfo
272 *sans_exception;
273
274 Image
275 *image;
276
277 ImageInfo
278 *read_info;
279
280 (void) FormatMagickString(key,MaxTextExtent,"cache:%s",path);
281 sans_exception=AcquireExceptionInfo();
282 image=(Image *) GetImageRegistry(ImageRegistryType,key,sans_exception);
283 sans_exception=DestroyExceptionInfo(sans_exception);
284 if (image != (Image *) NULL)
285 return(image);
286 read_info=CloneImageInfo(image_info);
287 (void) CopyMagickString(read_info->filename,path,MaxTextExtent);
288 image=ReadImage(read_info,exception);
289 read_info=DestroyImageInfo(read_info);
290 if (image != (Image *) NULL)
291 (void) SetImageRegistry(ImageRegistryType,key,image,exception);
292 return(image);
293}
294
295static int IsPathDirectory(const char *path)
296{
297 MagickBooleanType
298 status;
299
300 struct stat
301 attributes;
302
303 if ((path == (const char *) NULL) || (*path == '\0'))
304 return(MagickFalse);
305 status=GetPathAttributes(path,&attributes);
306 if (status == MagickFalse)
307 return(-1);
308 if (S_ISDIR(attributes.st_mode) == 0)
309 return(0);
310 return(1);
311}
312
313static MagickBooleanType IsPathWritable(const char *path)
314{
315 if (IsPathAccessible(path) == MagickFalse)
316 return(MagickFalse);
317 if (access(path,W_OK) != 0)
318 return(MagickFalse);
319 return(MagickTrue);
320}
321
322static inline long MagickMax(const long x,const long y)
323{
324 if (x > y)
325 return(x);
326 return(y);
327}
328
329static MagickBooleanType MonitorProgress(const char *text,
cristyb32b90a2009-09-07 21:45:48 +0000330 const MagickOffsetType offset,const MagickSizeType extent,
cristy3ed852e2009-09-05 21:47:34 +0000331 void *wand_unused(client_data))
332{
333 char
334 message[MaxTextExtent],
335 tag[MaxTextExtent];
336
337 const char
338 *locale_message;
339
340 register char
341 *p;
342
cristyb32b90a2009-09-07 21:45:48 +0000343 if (extent < 2)
cristy3ed852e2009-09-05 21:47:34 +0000344 return(MagickTrue);
345 (void) CopyMagickMemory(tag,text,MaxTextExtent);
346 p=strrchr(tag,'/');
347 if (p != (char *) NULL)
348 *p='\0';
349 (void) FormatMagickString(message,MaxTextExtent,"Monitor/%s",tag);
350 locale_message=GetLocaleMessage(message);
351 if (locale_message == message)
352 locale_message=tag;
353 if (p == (char *) NULL)
cristyb32b90a2009-09-07 21:45:48 +0000354 (void) fprintf(stderr,"%s: %ld of %lu, %02ld%% complete\r",locale_message,
355 (long) offset,(unsigned long) extent,(long) (100L*offset/(extent-1)));
cristy3ed852e2009-09-05 21:47:34 +0000356 else
cristyb32b90a2009-09-07 21:45:48 +0000357 (void) fprintf(stderr,"%s[%s]: %ld of %lu, %02ld%% complete\r",
358 locale_message,p+1,(long) offset,(unsigned long) extent,(long)
359 (100L*offset/(extent-1)));
360 if (offset == (MagickOffsetType) (extent-1))
cristy3ed852e2009-09-05 21:47:34 +0000361 (void) fprintf(stderr,"\n");
362 (void) fflush(stderr);
363 return(MagickTrue);
364}
365
366static Image *SparseColorOption(const Image *image,const ChannelType channel,
367 const SparseColorMethod method,const char *arguments,
368 const MagickBooleanType color_from_image,ExceptionInfo *exception)
369{
370 ChannelType
371 channels;
372
373 char
374 token[MaxTextExtent];
375
376 const char
377 *p;
378
379 double
380 *sparse_arguments;
381
382 register unsigned long
383 x;
384
385 unsigned long
386 number_arguments;
387
388 unsigned long
389 number_colors;
390
391 Image
392 *sparse_image;
393
394 MagickPixelPacket
395 color;
396
397 MagickBooleanType
398 error;
399
400 assert(image != (Image *) NULL);
401 assert(image->signature == MagickSignature);
402 if (image->debug != MagickFalse)
403 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
404 assert(exception != (ExceptionInfo *) NULL);
405 assert(exception->signature == MagickSignature);
406 /*
407 Limit channels according to image - and add up number of color channel.
408 */
409 channels=channel;
410 if (image->colorspace != CMYKColorspace)
411 channels=(ChannelType) (channels & ~IndexChannel); /* no index channel */
412 if (image->matte == MagickFalse)
413 channels=(ChannelType) (channels & ~OpacityChannel); /* no alpha channel */
414 number_colors=0;
415 if ((channels & RedChannel) != 0)
416 number_colors++;
417 if ((channels & GreenChannel) != 0)
418 number_colors++;
419 if ((channels & BlueChannel) != 0)
420 number_colors++;
421 if ((channels & IndexChannel) != 0)
422 number_colors++;
423 if ((channels & OpacityChannel) != 0)
424 number_colors++;
425 /*
426 Read string, to determine number of arguments needed,
427 */
428 p=arguments;
429 x=0;
430 while( *p != '\0' )
431 {
432 GetMagickToken(p,&p,token);
433 if ( token[0] == ',' ) continue;
434 if ( isalpha((int) token[0]) || token[0] == '#' ) {
435 if ( color_from_image ) {
436 (void) ThrowMagickException(exception,GetMagickModule(),
437 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
438 "Color arg given, when colors are coming from image");
439 return( (Image *)NULL);
440 }
441 x += number_colors; /* color argument */
442 }
443 else {
444 x++; /* floating point argument */
445 }
446 }
447 error=MagickTrue;
448 if ( color_from_image ) {
449 /* just the control points are being given */
450 error = ( x % 2 != 0 ) ? MagickTrue : MagickFalse;
451 number_arguments=(x/2)*(2+number_colors);
452 }
453 else {
454 /* control points and color values */
455 error = ( x % (2+number_colors) != 0 ) ? MagickTrue : MagickFalse;
456 number_arguments=x;
457 }
458 if ( error ) {
459 (void) ThrowMagickException(exception,GetMagickModule(),
460 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
461 "Invalid number of Arguments");
462 return( (Image *)NULL);
463 }
464
465 /* Allocate and fill in the floating point arguments */
466 sparse_arguments=(double *) AcquireQuantumMemory(number_arguments,
467 sizeof(*sparse_arguments));
468 if (sparse_arguments == (double *) NULL) {
469 (void) ThrowMagickException(exception,GetMagickModule(),ResourceLimitError,
470 "MemoryAllocationFailed","%s","SparseColorOption");
471 return( (Image *)NULL);
472 }
473 (void) ResetMagickMemory(sparse_arguments,0,number_arguments*
474 sizeof(*sparse_arguments));
475 p=arguments;
476 x=0;
477 while( *p != '\0' && x < number_arguments ) {
478 /* X coordinate */
479 token[0]=','; while ( token[0] == ',' ) GetMagickToken(p,&p,token);
480 if ( token[0] == '\0' ) break;
481 if ( isalpha((int) token[0]) || token[0] == '#' ) {
482 (void) ThrowMagickException(exception,GetMagickModule(),
483 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
484 "Color found, instead of X-coord");
485 error = MagickTrue;
486 break;
487 }
cristyf2f27272009-12-17 14:48:46 +0000488 sparse_arguments[x++]=StringToDouble(token);
cristy3ed852e2009-09-05 21:47:34 +0000489 /* Y coordinate */
490 token[0]=','; while ( token[0] == ',' ) GetMagickToken(p,&p,token);
491 if ( token[0] == '\0' ) break;
492 if ( isalpha((int) token[0]) || token[0] == '#' ) {
493 (void) ThrowMagickException(exception,GetMagickModule(),
494 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
495 "Color found, instead of Y-coord");
496 error = MagickTrue;
497 break;
498 }
cristyf2f27272009-12-17 14:48:46 +0000499 sparse_arguments[x++]=StringToDouble(token);
cristy3ed852e2009-09-05 21:47:34 +0000500 /* color values for this control point */
501#if 0
502 if ( (color_from_image ) {
503 /* get color from image */
504 /* HOW??? */
505 }
506 else
507#endif
508 {
509 /* color name or function given in string argument */
510 token[0]=','; while ( token[0] == ',' ) GetMagickToken(p,&p,token);
511 if ( token[0] == '\0' ) break;
512 if ( isalpha((int) token[0]) || token[0] == '#' ) {
513 /* Color string given */
514 (void) QueryMagickColor(token,&color,exception);
515 if ( channels & RedChannel )
516 sparse_arguments[x++] = QuantumScale*color.red;
517 if ( channels & GreenChannel )
518 sparse_arguments[x++] = QuantumScale*color.green;
519 if ( channels & BlueChannel )
520 sparse_arguments[x++] = QuantumScale*color.blue;
521 if ( channels & IndexChannel )
522 sparse_arguments[x++] = QuantumScale*color.index;
523 if ( channels & OpacityChannel )
524 sparse_arguments[x++] = QuantumScale*color.opacity;
525 }
526 else {
527#if 0
528 /* the color name/function/value was not found - error */
529 break;
530#else
531 /* Colors given as a set of floating point values - experimental */
532 /* NB: token contains the first floating point value to use! */
533 if ( channels & RedChannel ) {
534 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
535 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
536 break;
cristy0f19e682009-12-17 14:55:51 +0000537 sparse_arguments[x++]=StringToDouble(token);
cristy3ed852e2009-09-05 21:47:34 +0000538 token[0] = ','; /* used this token - get another */
539 }
540 if ( channels & GreenChannel ) {
541 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
542 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
543 break;
cristy0f19e682009-12-17 14:55:51 +0000544 sparse_arguments[x++]=StringToDouble(token);
cristy3ed852e2009-09-05 21:47:34 +0000545 token[0] = ','; /* used this token - get another */
546 }
547 if ( channels & BlueChannel ) {
548 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
549 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
550 break;
cristy0f19e682009-12-17 14:55:51 +0000551 sparse_arguments[x++]=StringToDouble(token);
cristy3ed852e2009-09-05 21:47:34 +0000552 token[0] = ','; /* used this token - get another */
553 }
554 if ( channels & IndexChannel ) {
555 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
556 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
557 break;
cristy0f19e682009-12-17 14:55:51 +0000558 sparse_arguments[x++]=StringToDouble(token);
cristy3ed852e2009-09-05 21:47:34 +0000559 token[0] = ','; /* used this token - get another */
560 }
561 if ( channels & OpacityChannel ) {
562 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
563 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
564 break;
cristy0f19e682009-12-17 14:55:51 +0000565 sparse_arguments[x++]=StringToDouble(token);
cristy3ed852e2009-09-05 21:47:34 +0000566 token[0] = ','; /* used this token - get another */
567 }
568#endif
569 }
570 }
571 }
572 if ( number_arguments != x && !error ) {
573 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
574 "InvalidArgument","`%s': %s","sparse-color","Argument Parsing Error");
575 sparse_arguments=(double *) RelinquishMagickMemory(sparse_arguments);
576 return( (Image *)NULL);
577 }
578 if ( error )
579 return( (Image *)NULL);
580
581 /* Call the Interpolation function with the parsed arguments */
582 sparse_image=SparseColorImage(image,channels,method,number_arguments,
583 sparse_arguments,exception);
584 sparse_arguments=(double *) RelinquishMagickMemory(sparse_arguments);
585 return( sparse_image );
586}
587
588WandExport MagickBooleanType MogrifyImage(ImageInfo *image_info,const int argc,
589 const char **argv,Image **image,ExceptionInfo *exception)
590{
591 ChannelType
592 channel;
593
594 const char
595 *format,
596 *option;
597
598 DrawInfo
599 *draw_info;
600
601 GeometryInfo
602 geometry_info;
603
604 Image
605 *region_image;
606
607 long
608 count;
609
610 MagickBooleanType
611 status;
612
613 MagickPixelPacket
614 fill;
615
616 MagickStatusType
617 flags;
618
619 QuantizeInfo
620 *quantize_info;
621
622 RectangleInfo
623 geometry,
624 region_geometry;
625
626 register long
627 i;
628
629 /*
630 Initialize method variables.
631 */
632 assert(image_info != (const ImageInfo *) NULL);
633 assert(image_info->signature == MagickSignature);
634 assert(image != (Image **) NULL);
635 assert((*image)->signature == MagickSignature);
636 if ((*image)->debug != MagickFalse)
637 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",(*image)->filename);
638 if (argc < 0)
639 return(MagickTrue);
640 draw_info=CloneDrawInfo(image_info,(DrawInfo *) NULL);
641 quantize_info=AcquireQuantizeInfo(image_info);
642 SetGeometryInfo(&geometry_info);
643 GetMagickPixelPacket(*image,&fill);
644 SetMagickPixelPacket(*image,&(*image)->background_color,(IndexPacket *) NULL,
645 &fill);
646 channel=image_info->channel;
647 format=GetImageOption(image_info,"format");
648 SetGeometry(*image,&region_geometry);
649 region_image=NewImageList();
650 /*
651 Transmogrify the image.
652 */
653 for (i=0; i < (long) argc; i++)
654 {
655 option=argv[i];
656 if (IsMagickOption(option) == MagickFalse)
657 continue;
658 count=MagickMax(ParseMagickOption(MagickCommandOptions,MagickFalse,option),
659 0L);
660 if ((i+count) >= argc)
661 break;
662 status=MogrifyImageInfo(image_info,count+1,argv+i,exception);
663 switch (*(option+1))
664 {
665 case 'a':
666 {
667 if (LocaleCompare("adaptive-blur",option+1) == 0)
668 {
669 Image
670 *blur_image;
671
672 /*
673 Adaptive blur image.
674 */
675 (void) SyncImageSettings(image_info,*image);
676 flags=ParseGeometry(argv[i+1],&geometry_info);
677 if ((flags & SigmaValue) == 0)
678 geometry_info.sigma=1.0;
679 blur_image=AdaptiveBlurImageChannel(*image,channel,
680 geometry_info.rho,geometry_info.sigma,exception);
681 if (blur_image == (Image *) NULL)
682 break;
683 *image=DestroyImage(*image);
684 *image=blur_image;
685 break;
686 }
687 if (LocaleCompare("adaptive-resize",option+1) == 0)
688 {
689 Image
690 *resize_image;
691
692 /*
693 Adaptive resize image.
694 */
695 (void) SyncImageSettings(image_info,*image);
696 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
697 resize_image=AdaptiveResizeImage(*image,geometry.width,
698 geometry.height,exception);
699 if (resize_image == (Image *) NULL)
700 break;
701 *image=DestroyImage(*image);
702 *image=resize_image;
703 break;
704 }
705 if (LocaleCompare("adaptive-sharpen",option+1) == 0)
706 {
707 Image
708 *sharp_image;
709
710 /*
711 Adaptive sharpen image.
712 */
713 (void) SyncImageSettings(image_info,*image);
714 flags=ParseGeometry(argv[i+1],&geometry_info);
715 if ((flags & SigmaValue) == 0)
716 geometry_info.sigma=1.0;
717 sharp_image=AdaptiveSharpenImageChannel(*image,channel,
718 geometry_info.rho,geometry_info.sigma,exception);
719 if (sharp_image == (Image *) NULL)
720 break;
721 *image=DestroyImage(*image);
722 *image=sharp_image;
723 break;
724 }
725 if (LocaleCompare("affine",option+1) == 0)
726 {
727 /*
728 Affine matrix.
729 */
730 if (*option == '+')
731 {
732 GetAffineMatrix(&draw_info->affine);
733 break;
734 }
735 (void) ParseAffineGeometry(argv[i+1],&draw_info->affine,exception);
736 break;
737 }
738 if (LocaleCompare("alpha",option+1) == 0)
739 {
740 AlphaChannelType
741 alpha_type;
742
743 (void) SyncImageSettings(image_info,*image);
744 alpha_type=(AlphaChannelType) ParseMagickOption(MagickAlphaOptions,
745 MagickFalse,argv[i+1]);
746 (void) SetImageAlphaChannel(*image,alpha_type);
747 InheritException(exception,&(*image)->exception);
748 break;
749 }
750 if (LocaleCompare("annotate",option+1) == 0)
751 {
752 char
753 *text,
754 geometry[MaxTextExtent];
755
756 /*
757 Annotate image.
758 */
759 (void) SyncImageSettings(image_info,*image);
760 SetGeometryInfo(&geometry_info);
761 flags=ParseGeometry(argv[i+1],&geometry_info);
762 if ((flags & SigmaValue) == 0)
763 geometry_info.sigma=geometry_info.rho;
764 text=InterpretImageProperties(image_info,*image,argv[i+2]);
765 InheritException(exception,&(*image)->exception);
766 if (text == (char *) NULL)
767 break;
768 (void) CloneString(&draw_info->text,text);
769 text=DestroyString(text);
770 (void) FormatMagickString(geometry,MaxTextExtent,"%+f%+f",
771 geometry_info.xi,geometry_info.psi);
772 (void) CloneString(&draw_info->geometry,geometry);
773 draw_info->affine.sx=cos(DegreesToRadians(
774 fmod(geometry_info.rho,360.0)));
775 draw_info->affine.rx=sin(DegreesToRadians(
776 fmod(geometry_info.rho,360.0)));
777 draw_info->affine.ry=(-sin(DegreesToRadians(
778 fmod(geometry_info.sigma,360.0))));
779 draw_info->affine.sy=cos(DegreesToRadians(
780 fmod(geometry_info.sigma,360.0)));
781 (void) AnnotateImage(*image,draw_info);
782 InheritException(exception,&(*image)->exception);
783 break;
784 }
785 if (LocaleCompare("antialias",option+1) == 0)
786 {
787 draw_info->stroke_antialias=(*option == '-') ? MagickTrue :
788 MagickFalse;
789 draw_info->text_antialias=(*option == '-') ? MagickTrue :
790 MagickFalse;
791 break;
792 }
793 if (LocaleCompare("auto-gamma",option+1) == 0)
794 {
795 /*
796 Auto Adjust Gamma of image based on its mean
797 */
798 (void) SyncImageSettings(image_info,*image);
799 (void) AutoGammaImageChannel(*image,channel);
800 break;
801 }
802 if (LocaleCompare("auto-level",option+1) == 0)
803 {
804 /*
805 Perfectly Normalize (max/min stretch) the image
806 */
807 (void) SyncImageSettings(image_info,*image);
808 (void) AutoLevelImageChannel(*image,channel);
809 break;
810 }
811 if (LocaleCompare("auto-orient",option+1) == 0)
812 {
813 Image
814 *orient_image;
815
816 (void) SyncImageSettings(image_info,*image);
817 orient_image=NewImageList();
818 switch ((*image)->orientation)
819 {
820 case TopRightOrientation:
821 {
822 orient_image=FlopImage(*image,exception);
823 break;
824 }
825 case BottomRightOrientation:
826 {
827 orient_image=RotateImage(*image,180.0,exception);
828 break;
829 }
830 case BottomLeftOrientation:
831 {
832 orient_image=FlipImage(*image,exception);
833 break;
834 }
835 case LeftTopOrientation:
836 {
837 orient_image=TransposeImage(*image,exception);
838 break;
839 }
840 case RightTopOrientation:
841 {
842 orient_image=RotateImage(*image,90.0,exception);
843 break;
844 }
845 case RightBottomOrientation:
846 {
847 orient_image=TransverseImage(*image,exception);
848 break;
849 }
850 case LeftBottomOrientation:
851 {
852 orient_image=RotateImage(*image,270.0,exception);
853 break;
854 }
855 default:
856 break;
857 }
858 if (orient_image == (Image *) NULL)
859 break;
860 orient_image->orientation=TopLeftOrientation;
861 *image=DestroyImage(*image);
862 *image=orient_image;
863 break;
864 }
865 break;
866 }
867 case 'b':
868 {
869 if (LocaleCompare("black-threshold",option+1) == 0)
870 {
871 /*
872 Black threshold image.
873 */
874 (void) SyncImageSettings(image_info,*image);
875 (void) BlackThresholdImageChannel(*image,channel,argv[i+1],
876 exception);
877 InheritException(exception,&(*image)->exception);
878 break;
879 }
880 if (LocaleCompare("blue-shift",option+1) == 0)
881 {
882 Image
883 *shift_image;
884
885 /*
886 Blue shift image.
887 */
888 (void) SyncImageSettings(image_info,*image);
889 geometry_info.rho=1.5;
890 if (*option == '-')
891 flags=ParseGeometry(argv[i+1],&geometry_info);
892 shift_image=BlueShiftImage(*image,geometry_info.rho,exception);
893 if (shift_image == (Image *) NULL)
894 break;
895 *image=DestroyImage(*image);
896 *image=shift_image;
897 break;
898 }
899 if (LocaleCompare("blur",option+1) == 0)
900 {
901 Image
902 *blur_image;
903
904 /*
905 Gaussian blur image.
906 */
907 (void) SyncImageSettings(image_info,*image);
908 flags=ParseGeometry(argv[i+1],&geometry_info);
909 if ((flags & SigmaValue) == 0)
910 geometry_info.sigma=1.0;
911 blur_image=BlurImageChannel(*image,channel,geometry_info.rho,
912 geometry_info.sigma,exception);
913 if (blur_image == (Image *) NULL)
914 break;
915 *image=DestroyImage(*image);
916 *image=blur_image;
917 break;
918 }
919 if (LocaleCompare("border",option+1) == 0)
920 {
921 Image
922 *border_image;
923
924 /*
925 Surround image with a border of solid color.
926 */
927 (void) SyncImageSettings(image_info,*image);
928 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
929 if ((flags & SigmaValue) == 0)
930 geometry.height=geometry.width;
931 border_image=BorderImage(*image,&geometry,exception);
932 if (border_image == (Image *) NULL)
933 break;
934 *image=DestroyImage(*image);
935 *image=border_image;
936 break;
937 }
938 if (LocaleCompare("bordercolor",option+1) == 0)
939 {
940 if (*option == '+')
941 {
942 (void) QueryColorDatabase(BorderColor,&draw_info->border_color,
943 exception);
944 break;
945 }
946 (void) QueryColorDatabase(argv[i+1],&draw_info->border_color,
947 exception);
948 break;
949 }
950 if (LocaleCompare("box",option+1) == 0)
951 {
952 (void) QueryColorDatabase(argv[i+1],&draw_info->undercolor,
953 exception);
954 break;
955 }
cristya28d6b82010-01-11 20:03:47 +0000956 if (LocaleCompare("brightness-contrast",option+1) == 0)
957 {
958 double
959 brightness,
960 contrast;
961
962 GeometryInfo
963 geometry_info;
964
965 MagickStatusType
966 flags;
967
968 /*
969 Brightness / contrast image.
970 */
971 (void) SyncImageSettings(image_info,*image);
972 flags=ParseGeometry(argv[i+1],&geometry_info);
973 brightness=geometry_info.rho;
cristy81fbc8b2010-01-11 20:04:07 +0000974 contrast=0.0;
cristya28d6b82010-01-11 20:03:47 +0000975 if ((flags & SigmaValue) != 0)
976 contrast=geometry_info.sigma;
cristy02cc0f22010-01-12 00:02:32 +0000977 (void) BrightnessContrastImageChannel(*image,channel,brightness,
978 contrast);
cristya28d6b82010-01-11 20:03:47 +0000979 InheritException(exception,&(*image)->exception);
980 break;
981 }
cristy3ed852e2009-09-05 21:47:34 +0000982 break;
983 }
984 case 'c':
985 {
986 if (LocaleCompare("cdl",option+1) == 0)
987 {
988 char
989 *color_correction_collection;
990
991 /*
992 Color correct with a color decision list.
993 */
994 (void) SyncImageSettings(image_info,*image);
995 color_correction_collection=FileToString(argv[i+1],~0,exception);
996 if (color_correction_collection == (char *) NULL)
997 break;
998 (void) ColorDecisionListImage(*image,color_correction_collection);
999 InheritException(exception,&(*image)->exception);
1000 break;
1001 }
1002 if (LocaleCompare("channel",option+1) == 0)
1003 {
1004 if (*option == '+')
1005 {
1006 channel=DefaultChannels;
1007 break;
1008 }
1009 channel=(ChannelType) ParseChannelOption(argv[i+1]);
1010 break;
1011 }
1012 if (LocaleCompare("charcoal",option+1) == 0)
1013 {
1014 Image
1015 *charcoal_image;
1016
1017 /*
1018 Charcoal image.
1019 */
1020 (void) SyncImageSettings(image_info,*image);
1021 flags=ParseGeometry(argv[i+1],&geometry_info);
1022 if ((flags & SigmaValue) == 0)
1023 geometry_info.sigma=1.0;
1024 charcoal_image=CharcoalImage(*image,geometry_info.rho,
1025 geometry_info.sigma,exception);
1026 if (charcoal_image == (Image *) NULL)
1027 break;
1028 *image=DestroyImage(*image);
1029 *image=charcoal_image;
1030 break;
1031 }
1032 if (LocaleCompare("chop",option+1) == 0)
1033 {
1034 Image
1035 *chop_image;
1036
1037 /*
1038 Chop the image.
1039 */
1040 (void) SyncImageSettings(image_info,*image);
1041 (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1042 chop_image=ChopImage(*image,&geometry,exception);
1043 if (chop_image == (Image *) NULL)
1044 break;
1045 *image=DestroyImage(*image);
1046 *image=chop_image;
1047 break;
1048 }
cristy1eb45dd2009-09-25 16:38:06 +00001049 if (LocaleCompare("clamp",option+1) == 0)
1050 {
1051 /*
1052 Clamp image.
1053 */
1054 (void) SyncImageSettings(image_info,*image);
1055 (void) ClampImageChannel(*image,channel);
1056 InheritException(exception,&(*image)->exception);
1057 break;
1058 }
cristy3ed852e2009-09-05 21:47:34 +00001059 if (LocaleCompare("clip",option+1) == 0)
1060 {
1061 (void) SyncImageSettings(image_info,*image);
1062 if (*option == '+')
1063 {
1064 (void) SetImageClipMask(*image,(Image *) NULL);
1065 InheritException(exception,&(*image)->exception);
1066 break;
1067 }
1068 (void) ClipImage(*image);
1069 InheritException(exception,&(*image)->exception);
1070 break;
1071 }
1072 if (LocaleCompare("clip-mask",option+1) == 0)
1073 {
1074 Image
1075 *mask;
1076
1077 long
1078 y;
1079
1080 register long
1081 x;
1082
1083 register PixelPacket
cristyc47d1f82009-11-26 01:44:43 +00001084 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00001085
1086 (void) SyncImageSettings(image_info,*image);
1087 if (*option == '+')
1088 {
1089 /*
1090 Remove a mask.
1091 */
1092 (void) SetImageMask(*image,(Image *) NULL);
1093 InheritException(exception,&(*image)->exception);
1094 break;
1095 }
1096 /*
1097 Set the image mask.
1098 */
1099 mask=GetImageCache(image_info,argv[i+1],exception);
1100 if (mask == (Image *) NULL)
1101 break;
1102 for (y=0; y < (long) mask->rows; y++)
1103 {
1104 q=GetAuthenticPixels(mask,0,y,mask->columns,1,exception);
1105 if (q == (PixelPacket *) NULL)
1106 break;
1107 for (x=0; x < (long) mask->columns; x++)
1108 {
1109 if (mask->matte == MagickFalse)
1110 q->opacity=PixelIntensityToQuantum(q);
1111 q->red=q->opacity;
1112 q->green=q->opacity;
1113 q->blue=q->opacity;
1114 q++;
1115 }
1116 if (SyncAuthenticPixels(mask,exception) == MagickFalse)
1117 break;
1118 }
1119 if (SetImageStorageClass(mask,DirectClass) == MagickFalse)
1120 return(MagickFalse);
1121 mask->matte=MagickTrue;
1122 (void) SetImageClipMask(*image,mask);
1123 mask=DestroyImage(mask);
1124 InheritException(exception,&(*image)->exception);
1125 break;
1126 }
1127 if (LocaleCompare("clip-path",option+1) == 0)
1128 {
1129 (void) SyncImageSettings(image_info,*image);
1130 (void) ClipImagePath(*image,argv[i+1],*option == '-' ? MagickTrue :
1131 MagickFalse);
1132 InheritException(exception,&(*image)->exception);
1133 break;
1134 }
1135 if (LocaleCompare("colorize",option+1) == 0)
1136 {
1137 Image
1138 *colorize_image;
1139
1140 /*
1141 Colorize the image.
1142 */
1143 (void) SyncImageSettings(image_info,*image);
1144 colorize_image=ColorizeImage(*image,argv[i+1],draw_info->fill,
1145 exception);
1146 if (colorize_image == (Image *) NULL)
1147 break;
1148 *image=DestroyImage(*image);
1149 *image=colorize_image;
1150 break;
1151 }
1152 if (LocaleCompare("colors",option+1) == 0)
1153 {
1154 /*
1155 Reduce the number of colors in the image.
1156 */
1157 (void) SyncImageSettings(image_info,*image);
cristye27293e2009-12-18 02:53:20 +00001158 quantize_info->number_colors=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00001159 if (quantize_info->number_colors == 0)
1160 break;
1161 if (((*image)->storage_class == DirectClass) ||
1162 (*image)->colors > quantize_info->number_colors)
1163 (void) QuantizeImage(quantize_info,*image);
1164 else
1165 (void) CompressImageColormap(*image);
1166 InheritException(exception,&(*image)->exception);
1167 break;
1168 }
1169 if (LocaleCompare("colorspace",option+1) == 0)
1170 {
1171 ColorspaceType
1172 colorspace;
1173
1174 (void) SyncImageSettings(image_info,*image);
1175 if (*option == '+')
1176 {
1177 (void) TransformImageColorspace(*image,RGBColorspace);
1178 InheritException(exception,&(*image)->exception);
1179 break;
1180 }
1181 colorspace=(ColorspaceType) ParseMagickOption(
1182 MagickColorspaceOptions,MagickFalse,argv[i+1]);
1183 (void) TransformImageColorspace(*image,colorspace);
1184 InheritException(exception,&(*image)->exception);
1185 break;
1186 }
1187 if (LocaleCompare("contrast",option+1) == 0)
1188 {
1189 (void) SyncImageSettings(image_info,*image);
1190 (void) ContrastImage(*image,(*option == '-') ? MagickTrue :
1191 MagickFalse);
1192 InheritException(exception,&(*image)->exception);
1193 break;
1194 }
1195 if (LocaleCompare("contrast-stretch",option+1) == 0)
1196 {
1197 double
1198 black_point,
1199 white_point;
1200
cristy3ed852e2009-09-05 21:47:34 +00001201 MagickStatusType
1202 flags;
1203
1204 /*
1205 Contrast stretch image.
1206 */
1207 (void) SyncImageSettings(image_info,*image);
1208 flags=ParseGeometry(argv[i+1],&geometry_info);
1209 black_point=geometry_info.rho;
1210 white_point=(flags & SigmaValue) != 0 ? geometry_info.sigma :
1211 black_point;
1212 if ((flags & PercentValue) != 0)
1213 {
1214 black_point*=(double) (*image)->columns*(*image)->rows/100.0;
1215 white_point*=(double) (*image)->columns*(*image)->rows/100.0;
1216 }
1217 white_point=(MagickRealType) (*image)->columns*(*image)->rows-
1218 white_point;
1219 (void) ContrastStretchImageChannel(*image,channel,black_point,
1220 white_point);
1221 InheritException(exception,&(*image)->exception);
1222 break;
1223 }
1224 if (LocaleCompare("convolve",option+1) == 0)
1225 {
cristy36826ab2010-03-06 01:29:30 +00001226 double
1227 gamma;
1228
cristy3ed852e2009-09-05 21:47:34 +00001229 Image
1230 *convolve_image;
1231
cristy2be15382010-01-21 02:38:03 +00001232 KernelInfo
cristy56a9e512010-01-06 18:18:55 +00001233 *kernel;
cristy3ed852e2009-09-05 21:47:34 +00001234
cristy36826ab2010-03-06 01:29:30 +00001235 register long
1236 j;
1237
cristy2be15382010-01-21 02:38:03 +00001238 kernel=AcquireKernelInfo(argv[i+1]);
1239 if (kernel == (KernelInfo *) NULL)
cristy56a9e512010-01-06 18:18:55 +00001240 break;
cristy36826ab2010-03-06 01:29:30 +00001241 gamma=0.0;
1242 for (j=0; j < (long) (kernel->width*kernel->height); j++)
1243 gamma+=kernel->values[j];
1244 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
1245 for (j=0; j < (long) (kernel->width*kernel->width); j++)
1246 kernel->values[j]*=gamma;
cristy6771f1e2010-03-05 19:43:39 +00001247 convolve_image=FilterImageChannel(*image,channel,kernel,exception);
anthony83ba99b2010-01-24 08:48:15 +00001248 kernel=DestroyKernelInfo(kernel);
cristy3ed852e2009-09-05 21:47:34 +00001249 if (convolve_image == (Image *) NULL)
1250 break;
1251 *image=DestroyImage(*image);
1252 *image=convolve_image;
1253 break;
1254 }
1255 if (LocaleCompare("crop",option+1) == 0)
1256 {
1257 (void) SyncImageSettings(image_info,*image);
1258 flags=ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1259 if (((geometry.width != 0) || (geometry.height != 0)) &&
1260 ((flags & XValue) == 0) && ((flags & YValue) == 0))
1261 break;
1262 (void) TransformImage(image,argv[i+1],(char *) NULL);
1263 InheritException(exception,&(*image)->exception);
1264 break;
1265 }
1266 if (LocaleCompare("cycle",option+1) == 0)
1267 {
1268 /*
1269 Cycle an image colormap.
1270 */
1271 (void) SyncImageSettings(image_info,*image);
cristyf2f27272009-12-17 14:48:46 +00001272 (void) CycleColormapImage(*image,StringToLong(argv[i+1]));
cristy3ed852e2009-09-05 21:47:34 +00001273 InheritException(exception,&(*image)->exception);
1274 break;
1275 }
1276 break;
1277 }
1278 case 'd':
1279 {
1280 if (LocaleCompare("decipher",option+1) == 0)
1281 {
1282 StringInfo
1283 *passkey;
1284
1285 /*
1286 Decipher pixels.
1287 */
1288 (void) SyncImageSettings(image_info,*image);
1289 passkey=FileToStringInfo(argv[i+1],~0,exception);
1290 if (passkey != (StringInfo *) NULL)
1291 {
1292 (void) PasskeyDecipherImage(*image,passkey,exception);
1293 passkey=DestroyStringInfo(passkey);
1294 }
1295 break;
1296 }
1297 if (LocaleCompare("density",option+1) == 0)
1298 {
1299 /*
1300 Set image density.
1301 */
1302 (void) CloneString(&draw_info->density,argv[i+1]);
1303 break;
1304 }
1305 if (LocaleCompare("depth",option+1) == 0)
1306 {
1307 (void) SyncImageSettings(image_info,*image);
1308 if (*option == '+')
1309 {
1310 (void) SetImageDepth(*image,MAGICKCORE_QUANTUM_DEPTH);
1311 break;
1312 }
cristye27293e2009-12-18 02:53:20 +00001313 (void) SetImageDepth(*image,StringToUnsignedLong(argv[i+1]));
cristy3ed852e2009-09-05 21:47:34 +00001314 break;
1315 }
1316 if (LocaleCompare("deskew",option+1) == 0)
1317 {
1318 double
1319 threshold;
1320
1321 Image
1322 *deskew_image;
1323
1324 /*
1325 Straighten the image.
1326 */
1327 (void) SyncImageSettings(image_info,*image);
1328 if (*option == '+')
1329 threshold=40.0*QuantumRange/100.0;
1330 else
cristyf2f27272009-12-17 14:48:46 +00001331 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
cristy3ed852e2009-09-05 21:47:34 +00001332 deskew_image=DeskewImage(*image,threshold,exception);
1333 if (deskew_image == (Image *) NULL)
1334 break;
1335 *image=DestroyImage(*image);
1336 *image=deskew_image;
1337 break;
1338 }
1339 if (LocaleCompare("despeckle",option+1) == 0)
1340 {
1341 Image
1342 *despeckle_image;
1343
1344 /*
1345 Reduce the speckles within an image.
1346 */
1347 (void) SyncImageSettings(image_info,*image);
1348 despeckle_image=DespeckleImage(*image,exception);
1349 if (despeckle_image == (Image *) NULL)
1350 break;
1351 *image=DestroyImage(*image);
1352 *image=despeckle_image;
1353 break;
1354 }
1355 if (LocaleCompare("display",option+1) == 0)
1356 {
1357 (void) CloneString(&draw_info->server_name,argv[i+1]);
1358 break;
1359 }
cristy3ed852e2009-09-05 21:47:34 +00001360 if (LocaleCompare("distort",option+1) == 0)
1361 {
1362 char
1363 *args,
1364 token[MaxTextExtent];
1365
1366 const char
1367 *p;
1368
1369 DistortImageMethod
1370 method;
1371
1372 double
1373 *arguments;
1374
1375 Image
1376 *distort_image;
1377
1378 register long
1379 x;
1380
1381 unsigned long
1382 number_arguments;
1383
1384 /*
1385 Distort image.
1386 */
1387 (void) SyncImageSettings(image_info,*image);
1388 method=(DistortImageMethod) ParseMagickOption(MagickDistortOptions,
1389 MagickFalse,argv[i+1]);
1390 args=InterpretImageProperties(image_info,*image,argv[i+2]);
1391 InheritException(exception,&(*image)->exception);
1392 if (args == (char *) NULL)
1393 break;
1394 p=(char *) args;
1395 for (x=0; *p != '\0'; x++)
1396 {
1397 GetMagickToken(p,&p,token);
1398 if (*token == ',')
1399 GetMagickToken(p,&p,token);
1400 }
1401 number_arguments=(unsigned long) x;
1402 arguments=(double *) AcquireQuantumMemory(number_arguments,
1403 sizeof(*arguments));
1404 if (arguments == (double *) NULL)
1405 ThrowWandFatalException(ResourceLimitFatalError,
1406 "MemoryAllocationFailed",(*image)->filename);
1407 (void) ResetMagickMemory(arguments,0,number_arguments*
1408 sizeof(*arguments));
1409 p=(char *) args;
1410 for (x=0; (x < (long) number_arguments) && (*p != '\0'); x++)
1411 {
1412 GetMagickToken(p,&p,token);
1413 if (*token == ',')
1414 GetMagickToken(p,&p,token);
cristyf2f27272009-12-17 14:48:46 +00001415 arguments[x]=StringToDouble(token);
cristy3ed852e2009-09-05 21:47:34 +00001416 }
1417 args=DestroyString(args);
1418 distort_image=DistortImage(*image,method,number_arguments,arguments,
1419 (*option == '+') ? MagickTrue : MagickFalse,exception);
1420 arguments=(double *) RelinquishMagickMemory(arguments);
1421 if (distort_image == (Image *) NULL)
1422 break;
1423 *image=DestroyImage(*image);
1424 *image=distort_image;
1425 break;
1426 }
1427 if (LocaleCompare("dither",option+1) == 0)
1428 {
1429 if (*option == '+')
1430 {
1431 quantize_info->dither=MagickFalse;
1432 break;
1433 }
1434 quantize_info->dither=MagickTrue;
1435 quantize_info->dither_method=(DitherMethod) ParseMagickOption(
1436 MagickDitherOptions,MagickFalse,argv[i+1]);
1437 if (quantize_info->dither_method == NoDitherMethod)
1438 quantize_info->dither=MagickFalse;
1439 break;
1440 }
1441 if (LocaleCompare("draw",option+1) == 0)
1442 {
1443 /*
1444 Draw image.
1445 */
1446 (void) SyncImageSettings(image_info,*image);
1447 (void) CloneString(&draw_info->primitive,argv[i+1]);
1448 (void) DrawImage(*image,draw_info);
1449 InheritException(exception,&(*image)->exception);
1450 break;
1451 }
1452 break;
1453 }
1454 case 'e':
1455 {
1456 if (LocaleCompare("edge",option+1) == 0)
1457 {
1458 Image
1459 *edge_image;
1460
1461 /*
1462 Enhance edges in the image.
1463 */
1464 (void) SyncImageSettings(image_info,*image);
1465 flags=ParseGeometry(argv[i+1],&geometry_info);
1466 if ((flags & SigmaValue) == 0)
1467 geometry_info.sigma=1.0;
1468 edge_image=EdgeImage(*image,geometry_info.rho,exception);
1469 if (edge_image == (Image *) NULL)
1470 break;
1471 *image=DestroyImage(*image);
1472 *image=edge_image;
1473 break;
1474 }
1475 if (LocaleCompare("emboss",option+1) == 0)
1476 {
1477 Image
1478 *emboss_image;
1479
1480 /*
1481 Gaussian embossen image.
1482 */
1483 (void) SyncImageSettings(image_info,*image);
1484 flags=ParseGeometry(argv[i+1],&geometry_info);
1485 if ((flags & SigmaValue) == 0)
1486 geometry_info.sigma=1.0;
1487 emboss_image=EmbossImage(*image,geometry_info.rho,
1488 geometry_info.sigma,exception);
1489 if (emboss_image == (Image *) NULL)
1490 break;
1491 *image=DestroyImage(*image);
1492 *image=emboss_image;
1493 break;
1494 }
1495 if (LocaleCompare("encipher",option+1) == 0)
1496 {
1497 StringInfo
1498 *passkey;
1499
1500 /*
1501 Encipher pixels.
1502 */
1503 (void) SyncImageSettings(image_info,*image);
1504 passkey=FileToStringInfo(argv[i+1],~0,exception);
1505 if (passkey != (StringInfo *) NULL)
1506 {
1507 (void) PasskeyEncipherImage(*image,passkey,exception);
1508 passkey=DestroyStringInfo(passkey);
1509 }
1510 break;
1511 }
1512 if (LocaleCompare("encoding",option+1) == 0)
1513 {
1514 (void) CloneString(&draw_info->encoding,argv[i+1]);
1515 break;
1516 }
1517 if (LocaleCompare("enhance",option+1) == 0)
1518 {
1519 Image
1520 *enhance_image;
1521
1522 /*
1523 Enhance image.
1524 */
1525 (void) SyncImageSettings(image_info,*image);
1526 enhance_image=EnhanceImage(*image,exception);
1527 if (enhance_image == (Image *) NULL)
1528 break;
1529 *image=DestroyImage(*image);
1530 *image=enhance_image;
1531 break;
1532 }
1533 if (LocaleCompare("equalize",option+1) == 0)
1534 {
1535 /*
1536 Equalize image.
1537 */
1538 (void) SyncImageSettings(image_info,*image);
1539 (void) EqualizeImageChannel(*image,channel);
1540 InheritException(exception,&(*image)->exception);
1541 break;
1542 }
1543 if (LocaleCompare("evaluate",option+1) == 0)
1544 {
1545 double
1546 constant;
1547
1548 MagickEvaluateOperator
1549 op;
1550
1551 (void) SyncImageSettings(image_info,*image);
1552 op=(MagickEvaluateOperator) ParseMagickOption(MagickEvaluateOptions,
1553 MagickFalse,argv[i+1]);
cristyf2f27272009-12-17 14:48:46 +00001554 constant=SiPrefixToDouble(argv[i+2],QuantumRange);
cristy3ed852e2009-09-05 21:47:34 +00001555 (void) EvaluateImageChannel(*image,channel,op,constant,exception);
1556 break;
1557 }
1558 if (LocaleCompare("extent",option+1) == 0)
1559 {
1560 Image
1561 *extent_image;
1562
1563 /*
1564 Set the image extent.
1565 */
1566 (void) SyncImageSettings(image_info,*image);
1567 flags=ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
cristyf0bbfd92009-11-25 14:12:31 +00001568 if (geometry.width == 0)
cristy2ea9a4e2009-11-25 14:30:22 +00001569 geometry.width=(*image)->columns;
cristyf0bbfd92009-11-25 14:12:31 +00001570 if (geometry.height == 0)
cristy2ea9a4e2009-11-25 14:30:22 +00001571 geometry.height=(*image)->rows;
cristy3ed852e2009-09-05 21:47:34 +00001572 geometry.x=(-geometry.x);
1573 geometry.y=(-geometry.y);
1574 extent_image=ExtentImage(*image,&geometry,exception);
1575 if (extent_image == (Image *) NULL)
1576 break;
1577 *image=DestroyImage(*image);
1578 *image=extent_image;
1579 break;
1580 }
1581 break;
1582 }
1583 case 'f':
1584 {
1585 if (LocaleCompare("family",option+1) == 0)
1586 {
1587 if (*option == '+')
1588 {
1589 if (draw_info->family != (char *) NULL)
1590 draw_info->family=DestroyString(draw_info->family);
1591 break;
1592 }
1593 (void) CloneString(&draw_info->family,argv[i+1]);
1594 break;
1595 }
cristy0fe961c2010-01-30 03:09:54 +00001596 if (LocaleCompare("features",option+1) == 0)
1597 {
1598 if (*option == '+')
1599 {
1600 (void) DeleteImageArtifact(*image,"identify:features");
1601 break;
1602 }
1603 (void) SetImageArtifact(*image,"identify:features",argv[i+1]);
1604 break;
1605 }
cristy3ed852e2009-09-05 21:47:34 +00001606 if (LocaleCompare("fill",option+1) == 0)
1607 {
1608 ExceptionInfo
1609 *sans;
1610
1611 GetMagickPixelPacket(*image,&fill);
1612 if (*option == '+')
1613 {
1614 (void) QueryMagickColor("none",&fill,exception);
1615 (void) QueryColorDatabase("none",&draw_info->fill,exception);
1616 if (draw_info->fill_pattern != (Image *) NULL)
1617 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
1618 break;
1619 }
1620 sans=AcquireExceptionInfo();
1621 (void) QueryMagickColor(argv[i+1],&fill,sans);
1622 status=QueryColorDatabase(argv[i+1],&draw_info->fill,sans);
1623 sans=DestroyExceptionInfo(sans);
1624 if (status == MagickFalse)
1625 draw_info->fill_pattern=GetImageCache(image_info,argv[i+1],
1626 exception);
1627 break;
1628 }
1629 if (LocaleCompare("flip",option+1) == 0)
1630 {
1631 Image
1632 *flip_image;
1633
1634 /*
1635 Flip image scanlines.
1636 */
1637 (void) SyncImageSettings(image_info,*image);
1638 flip_image=FlipImage(*image,exception);
1639 if (flip_image == (Image *) NULL)
1640 break;
1641 *image=DestroyImage(*image);
1642 *image=flip_image;
1643 break;
1644 }
1645 if (LocaleCompare("flop",option+1) == 0)
1646 {
1647 Image
1648 *flop_image;
1649
1650 /*
1651 Flop image scanlines.
1652 */
1653 (void) SyncImageSettings(image_info,*image);
1654 flop_image=FlopImage(*image,exception);
1655 if (flop_image == (Image *) NULL)
1656 break;
1657 *image=DestroyImage(*image);
1658 *image=flop_image;
1659 break;
1660 }
1661 if (LocaleCompare("floodfill",option+1) == 0)
1662 {
1663 MagickPixelPacket
1664 target;
1665
1666 /*
1667 Floodfill image.
1668 */
1669 (void) SyncImageSettings(image_info,*image);
1670 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
1671 (void) QueryMagickColor(argv[i+2],&target,exception);
1672 (void) FloodfillPaintImage(*image,channel,draw_info,&target,
1673 geometry.x,geometry.y,*option == '-' ? MagickFalse : MagickTrue);
1674 InheritException(exception,&(*image)->exception);
1675 break;
1676 }
1677 if (LocaleCompare("font",option+1) == 0)
1678 {
1679 if (*option == '+')
1680 {
1681 if (draw_info->font != (char *) NULL)
1682 draw_info->font=DestroyString(draw_info->font);
1683 break;
1684 }
1685 (void) CloneString(&draw_info->font,argv[i+1]);
1686 break;
1687 }
1688 if (LocaleCompare("format",option+1) == 0)
1689 {
1690 format=argv[i+1];
1691 break;
1692 }
1693 if (LocaleCompare("frame",option+1) == 0)
1694 {
1695 FrameInfo
1696 frame_info;
1697
1698 Image
1699 *frame_image;
1700
1701 /*
1702 Surround image with an ornamental border.
1703 */
1704 (void) SyncImageSettings(image_info,*image);
1705 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
1706 frame_info.width=geometry.width;
1707 frame_info.height=geometry.height;
1708 if ((flags & HeightValue) == 0)
1709 frame_info.height=geometry.width;
1710 frame_info.outer_bevel=geometry.x;
1711 frame_info.inner_bevel=geometry.y;
1712 frame_info.x=(long) frame_info.width;
1713 frame_info.y=(long) frame_info.height;
1714 frame_info.width=(*image)->columns+2*frame_info.width;
1715 frame_info.height=(*image)->rows+2*frame_info.height;
1716 frame_image=FrameImage(*image,&frame_info,exception);
1717 if (frame_image == (Image *) NULL)
1718 break;
1719 *image=DestroyImage(*image);
1720 *image=frame_image;
1721 break;
1722 }
1723 if (LocaleCompare("function",option+1) == 0)
1724 {
1725 char
1726 *arguments,
1727 token[MaxTextExtent];
1728
1729 const char
1730 *p;
1731
1732 double
1733 *parameters;
1734
1735 MagickFunction
1736 function;
1737
1738 register long
1739 x;
1740
1741 unsigned long
1742 number_parameters;
1743
1744 /*
1745 Function Modify Image Values
1746 */
1747 (void) SyncImageSettings(image_info,*image);
1748 function=(MagickFunction) ParseMagickOption(MagickFunctionOptions,
1749 MagickFalse,argv[i+1]);
1750 arguments=InterpretImageProperties(image_info,*image,argv[i+2]);
1751 InheritException(exception,&(*image)->exception);
1752 if (arguments == (char *) NULL)
1753 break;
1754 p=(char *) arguments;
1755 for (x=0; *p != '\0'; x++)
1756 {
1757 GetMagickToken(p,&p,token);
1758 if (*token == ',')
1759 GetMagickToken(p,&p,token);
1760 }
1761 number_parameters=(unsigned long) x;
1762 parameters=(double *) AcquireQuantumMemory(number_parameters,
1763 sizeof(*parameters));
1764 if (parameters == (double *) NULL)
1765 ThrowWandFatalException(ResourceLimitFatalError,
1766 "MemoryAllocationFailed",(*image)->filename);
1767 (void) ResetMagickMemory(parameters,0,number_parameters*
1768 sizeof(*parameters));
1769 p=(char *) arguments;
1770 for (x=0; (x < (long) number_parameters) && (*p != '\0'); x++)
1771 {
1772 GetMagickToken(p,&p,token);
1773 if (*token == ',')
1774 GetMagickToken(p,&p,token);
cristyf2f27272009-12-17 14:48:46 +00001775 parameters[x]=StringToDouble(token);
cristy3ed852e2009-09-05 21:47:34 +00001776 }
1777 arguments=DestroyString(arguments);
1778 (void) FunctionImageChannel(*image,channel,function,
1779 number_parameters,parameters,exception);
1780 parameters=(double *) RelinquishMagickMemory(parameters);
1781 break;
1782 }
1783 break;
1784 }
1785 case 'g':
1786 {
1787 if (LocaleCompare("gamma",option+1) == 0)
1788 {
1789 /*
1790 Gamma image.
1791 */
1792 (void) SyncImageSettings(image_info,*image);
1793 if (*option == '+')
cristyf2f27272009-12-17 14:48:46 +00001794 (*image)->gamma=StringToDouble(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00001795 else
1796 {
1797 if (strchr(argv[i+1],',') != (char *) NULL)
1798 (void) GammaImage(*image,argv[i+1]);
1799 else
cristya5447be2010-01-11 00:20:51 +00001800 (void) GammaImageChannel(*image,channel,
1801 StringToDouble(argv[i+1]));
cristy3ed852e2009-09-05 21:47:34 +00001802 InheritException(exception,&(*image)->exception);
1803 }
1804 break;
1805 }
1806 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
1807 (LocaleCompare("gaussian",option+1) == 0))
1808 {
1809 Image
1810 *gaussian_image;
1811
1812 /*
1813 Gaussian blur image.
1814 */
1815 (void) SyncImageSettings(image_info,*image);
1816 flags=ParseGeometry(argv[i+1],&geometry_info);
1817 if ((flags & SigmaValue) == 0)
1818 geometry_info.sigma=1.0;
1819 gaussian_image=GaussianBlurImageChannel(*image,channel,
1820 geometry_info.rho,geometry_info.sigma,exception);
1821 if (gaussian_image == (Image *) NULL)
1822 break;
1823 *image=DestroyImage(*image);
1824 *image=gaussian_image;
1825 break;
1826 }
1827 if (LocaleCompare("geometry",option+1) == 0)
1828 {
1829 (void) SyncImageSettings(image_info,*image);
1830 if (*option == '+')
1831 {
1832 if ((*image)->geometry != (char *) NULL)
1833 (*image)->geometry=DestroyString((*image)->geometry);
1834 break;
1835 }
1836 flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
1837 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
1838 (void) CloneString(&(*image)->geometry,argv[i+1]);
1839 else
1840 {
1841 Image
1842 *zoom_image;
1843
1844 /*
1845 Resize image.
1846 */
1847 zoom_image=ZoomImage(*image,geometry.width,geometry.height,
1848 exception);
1849 if (zoom_image == (Image *) NULL)
1850 break;
1851 *image=DestroyImage(*image);
1852 *image=zoom_image;
1853 }
1854 break;
1855 }
1856 if (LocaleCompare("gravity",option+1) == 0)
1857 {
1858 if (*option == '+')
1859 {
1860 draw_info->gravity=UndefinedGravity;
1861 break;
1862 }
1863 draw_info->gravity=(GravityType) ParseMagickOption(
1864 MagickGravityOptions,MagickFalse,argv[i+1]);
1865 break;
1866 }
1867 break;
1868 }
1869 case 'h':
1870 {
1871 if (LocaleCompare("highlight-color",option+1) == 0)
1872 {
1873 (void) SetImageArtifact(*image,option+1,argv[i+1]);
1874 break;
1875 }
1876 break;
1877 }
1878 case 'i':
1879 {
1880 if (LocaleCompare("identify",option+1) == 0)
1881 {
1882 char
1883 *text;
1884
1885 (void) SyncImageSettings(image_info,*image);
1886 if (format == (char *) NULL)
1887 {
1888 (void) IdentifyImage(*image,stdout,image_info->verbose);
1889 InheritException(exception,&(*image)->exception);
1890 break;
1891 }
1892 text=InterpretImageProperties(image_info,*image,format);
1893 InheritException(exception,&(*image)->exception);
1894 if (text == (char *) NULL)
1895 break;
1896 (void) fputs(text,stdout);
1897 (void) fputc('\n',stdout);
1898 text=DestroyString(text);
1899 break;
1900 }
1901 if (LocaleCompare("implode",option+1) == 0)
1902 {
1903 Image
1904 *implode_image;
1905
1906 /*
1907 Implode image.
1908 */
1909 (void) SyncImageSettings(image_info,*image);
1910 (void) ParseGeometry(argv[i+1],&geometry_info);
1911 implode_image=ImplodeImage(*image,geometry_info.rho,exception);
1912 if (implode_image == (Image *) NULL)
1913 break;
1914 *image=DestroyImage(*image);
1915 *image=implode_image;
1916 break;
1917 }
cristyb32b90a2009-09-07 21:45:48 +00001918 if (LocaleCompare("interline-spacing",option+1) == 0)
1919 {
1920 if (*option == '+')
1921 (void) ParseGeometry("0",&geometry_info);
1922 else
1923 (void) ParseGeometry(argv[i+1],&geometry_info);
1924 draw_info->interline_spacing=geometry_info.rho;
1925 break;
1926 }
cristy3ed852e2009-09-05 21:47:34 +00001927 if (LocaleCompare("interword-spacing",option+1) == 0)
1928 {
1929 if (*option == '+')
1930 (void) ParseGeometry("0",&geometry_info);
1931 else
1932 (void) ParseGeometry(argv[i+1],&geometry_info);
1933 draw_info->interword_spacing=geometry_info.rho;
1934 break;
1935 }
1936 break;
1937 }
1938 case 'k':
1939 {
1940 if (LocaleCompare("kerning",option+1) == 0)
1941 {
1942 if (*option == '+')
1943 (void) ParseGeometry("0",&geometry_info);
1944 else
1945 (void) ParseGeometry(argv[i+1],&geometry_info);
1946 draw_info->kerning=geometry_info.rho;
1947 break;
1948 }
1949 break;
1950 }
1951 case 'l':
1952 {
1953 if (LocaleCompare("lat",option+1) == 0)
1954 {
1955 Image
1956 *threshold_image;
1957
1958 /*
1959 Local adaptive threshold image.
1960 */
1961 (void) SyncImageSettings(image_info,*image);
1962 flags=ParseGeometry(argv[i+1],&geometry_info);
1963 if ((flags & PercentValue) != 0)
1964 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
1965 threshold_image=AdaptiveThresholdImage(*image,(unsigned long)
1966 geometry_info.rho,(unsigned long) geometry_info.sigma,
1967 (long) geometry_info.xi,exception);
1968 if (threshold_image == (Image *) NULL)
1969 break;
1970 *image=DestroyImage(*image);
1971 *image=threshold_image;
1972 break;
1973 }
1974 if (LocaleCompare("level",option+1) == 0)
1975 {
cristy3ed852e2009-09-05 21:47:34 +00001976 MagickRealType
1977 black_point,
1978 gamma,
1979 white_point;
1980
1981 MagickStatusType
1982 flags;
1983
1984 /*
1985 Parse levels.
1986 */
1987 (void) SyncImageSettings(image_info,*image);
1988 flags=ParseGeometry(argv[i+1],&geometry_info);
1989 black_point=geometry_info.rho;
1990 white_point=(MagickRealType) QuantumRange;
1991 if ((flags & SigmaValue) != 0)
1992 white_point=geometry_info.sigma;
1993 gamma=1.0;
1994 if ((flags & XiValue) != 0)
1995 gamma=geometry_info.xi;
1996 if ((flags & PercentValue) != 0)
1997 {
1998 black_point*=(MagickRealType) (QuantumRange/100.0);
1999 white_point*=(MagickRealType) (QuantumRange/100.0);
2000 }
2001 if ((flags & SigmaValue) == 0)
2002 white_point=(MagickRealType) QuantumRange-black_point;
2003 if ((*option == '+') || ((flags & AspectValue) != 0))
2004 (void) LevelizeImageChannel(*image,channel,black_point,
2005 white_point,gamma);
2006 else
2007 (void) LevelImageChannel(*image,channel,black_point,white_point,
2008 gamma);
2009 InheritException(exception,&(*image)->exception);
2010 break;
2011 }
2012 if (LocaleCompare("level-colors",option+1) == 0)
2013 {
2014 char
2015 token[MaxTextExtent];
2016
2017 const char
2018 *p;
2019
2020 MagickPixelPacket
2021 black_point,
2022 white_point;
2023
2024 p=(const char *) argv[i+1];
2025 GetMagickToken(p,&p,token); /* get black point color */
cristyee0f8d72009-09-19 00:58:29 +00002026 if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
cristy3ed852e2009-09-05 21:47:34 +00002027 (void) QueryMagickColor(token,&black_point,exception);
2028 else
cristyee0f8d72009-09-19 00:58:29 +00002029 (void) QueryMagickColor("#000000",&black_point,exception);
cristy3ed852e2009-09-05 21:47:34 +00002030 if (isalpha((int) token[0]) || (token[0] == '#'))
2031 GetMagickToken(p,&p,token);
cristyee0f8d72009-09-19 00:58:29 +00002032 if (*token == '\0')
cristy3ed852e2009-09-05 21:47:34 +00002033 white_point=black_point; /* set everything to that color */
2034 else
2035 {
2036 /*
2037 Get white point color.
2038 */
cristyee0f8d72009-09-19 00:58:29 +00002039 if ((isalpha((int) *token) == 0) && ((*token == '#') == 0))
cristy3ed852e2009-09-05 21:47:34 +00002040 GetMagickToken(p,&p,token);
cristyee0f8d72009-09-19 00:58:29 +00002041 if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
cristy3ed852e2009-09-05 21:47:34 +00002042 (void) QueryMagickColor(token,&white_point,exception);
2043 else
cristyee0f8d72009-09-19 00:58:29 +00002044 (void) QueryMagickColor("#ffffff",&white_point,exception);
cristy3ed852e2009-09-05 21:47:34 +00002045 }
cristy74fe8f12009-10-03 19:09:01 +00002046 (void) LevelColorsImageChannel(*image,channel,&black_point,
2047 &white_point,*option == '+' ? MagickTrue : MagickFalse);
cristy3ed852e2009-09-05 21:47:34 +00002048 break;
2049 }
2050 if (LocaleCompare("linear-stretch",option+1) == 0)
2051 {
2052 double
2053 black_point,
2054 white_point;
2055
cristy3ed852e2009-09-05 21:47:34 +00002056 MagickStatusType
2057 flags;
2058
2059 (void) SyncImageSettings(image_info,*image);
2060 flags=ParseGeometry(argv[i+1],&geometry_info);
2061 black_point=geometry_info.rho;
2062 white_point=(MagickRealType) (*image)->columns*(*image)->rows;
2063 if ((flags & SigmaValue) != 0)
2064 white_point=geometry_info.sigma;
2065 if ((flags & PercentValue) != 0)
2066 {
2067 black_point*=(double) (*image)->columns*(*image)->rows/100.0;
2068 white_point*=(double) (*image)->columns*(*image)->rows/100.0;
2069 }
2070 if ((flags & SigmaValue) == 0)
2071 white_point=(MagickRealType) (*image)->columns*(*image)->rows-
2072 black_point;
2073 (void) LinearStretchImage(*image,black_point,white_point);
2074 InheritException(exception,&(*image)->exception);
2075 break;
2076 }
2077 if (LocaleCompare("linewidth",option+1) == 0)
2078 {
cristyf2f27272009-12-17 14:48:46 +00002079 draw_info->stroke_width=StringToDouble(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00002080 break;
2081 }
2082 if (LocaleCompare("liquid-rescale",option+1) == 0)
2083 {
2084 Image
2085 *resize_image;
2086
2087 /*
2088 Liquid rescale image.
2089 */
2090 (void) SyncImageSettings(image_info,*image);
2091 flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2092 if ((flags & XValue) == 0)
2093 geometry.x=1;
2094 if ((flags & YValue) == 0)
2095 geometry.y=0;
2096 resize_image=LiquidRescaleImage(*image,geometry.width,
2097 geometry.height,1.0*geometry.x,1.0*geometry.y,exception);
2098 if (resize_image == (Image *) NULL)
2099 break;
2100 *image=DestroyImage(*image);
2101 *image=resize_image;
2102 break;
2103 }
2104 if (LocaleCompare("lowlight-color",option+1) == 0)
2105 {
2106 (void) SetImageArtifact(*image,option+1,argv[i+1]);
2107 break;
2108 }
2109 break;
2110 }
2111 case 'm':
2112 {
2113 if (LocaleCompare("map",option+1) == 0)
2114 {
2115 Image
2116 *remap_image;
2117
2118 /*
2119 Transform image colors to match this set of colors.
2120 */
2121 (void) SyncImageSettings(image_info,*image);
2122 if (*option == '+')
2123 break;
2124 remap_image=GetImageCache(image_info,argv[i+1],exception);
2125 if (remap_image == (Image *) NULL)
2126 break;
2127 (void) RemapImage(quantize_info,*image,remap_image);
2128 InheritException(exception,&(*image)->exception);
2129 remap_image=DestroyImage(remap_image);
2130 break;
2131 }
2132 if (LocaleCompare("mask",option+1) == 0)
2133 {
2134 Image
2135 *mask;
2136
2137 (void) SyncImageSettings(image_info,*image);
2138 if (*option == '+')
2139 {
2140 /*
2141 Remove a mask.
2142 */
2143 (void) SetImageMask(*image,(Image *) NULL);
2144 InheritException(exception,&(*image)->exception);
2145 break;
2146 }
2147 /*
2148 Set the image mask.
2149 */
2150 mask=GetImageCache(image_info,argv[i+1],exception);
2151 if (mask == (Image *) NULL)
2152 break;
2153 (void) SetImageMask(*image,mask);
2154 mask=DestroyImage(mask);
2155 InheritException(exception,&(*image)->exception);
2156 break;
2157 }
2158 if (LocaleCompare("matte",option+1) == 0)
2159 {
2160 (void) SetImageAlphaChannel(*image,(*option == '-') ?
2161 SetAlphaChannel : DeactivateAlphaChannel );
2162 InheritException(exception,&(*image)->exception);
2163 break;
2164 }
2165 if (LocaleCompare("median",option+1) == 0)
2166 {
2167 Image
2168 *median_image;
2169
2170 /*
2171 Median filter image.
2172 */
2173 (void) SyncImageSettings(image_info,*image);
2174 (void) ParseGeometry(argv[i+1],&geometry_info);
2175 median_image=MedianFilterImage(*image,geometry_info.rho,exception);
2176 if (median_image == (Image *) NULL)
2177 break;
2178 *image=DestroyImage(*image);
2179 *image=median_image;
2180 break;
2181 }
2182 if (LocaleCompare("modulate",option+1) == 0)
2183 {
2184 (void) SyncImageSettings(image_info,*image);
2185 (void) ModulateImage(*image,argv[i+1]);
2186 InheritException(exception,&(*image)->exception);
2187 break;
2188 }
2189 if (LocaleCompare("monitor",option+1) == 0)
2190 {
2191 (void) SetImageProgressMonitor(*image,MonitorProgress,
2192 (void *) NULL);
2193 break;
2194 }
2195 if (LocaleCompare("monochrome",option+1) == 0)
2196 {
2197 (void) SyncImageSettings(image_info,*image);
2198 (void) SetImageType(*image,BilevelType);
2199 InheritException(exception,&(*image)->exception);
2200 break;
2201 }
anthony29188a82010-01-22 10:12:34 +00002202 if (LocaleCompare("morphology",option+1) == 0)
2203 {
2204 MorphologyMethod
2205 method;
2206
2207 KernelInfo
2208 *kernel;
2209
2210 char
2211 token[MaxTextExtent];
2212
2213 const char
2214 *p;
2215
cristyef656912010-03-05 19:54:59 +00002216 long
anthony29188a82010-01-22 10:12:34 +00002217 iterations;
2218
2219 Image
2220 *morphology_image;
2221 /*
2222 Morphological Image Operation
2223 */
2224 (void) SyncImageSettings(image_info,*image);
2225 p=argv[i+1];
2226 GetMagickToken(p,&p,token);
2227 method=(MorphologyMethod) ParseMagickOption(MagickMorphologyOptions,
2228 MagickFalse,token);
cristyef656912010-03-05 19:54:59 +00002229 iterations=1L;
anthony29188a82010-01-22 10:12:34 +00002230 GetMagickToken(p,&p,token);
cristyef656912010-03-05 19:54:59 +00002231 if ((*p == ':') || (*p == ','))
anthony29188a82010-01-22 10:12:34 +00002232 GetMagickToken(p,&p,token);
cristyef656912010-03-05 19:54:59 +00002233 if ((*p != '\0'))
2234 iterations=StringToLong(p);
anthony29188a82010-01-22 10:12:34 +00002235 kernel=AcquireKernelInfo(argv[i+2]);
2236 if (kernel == (KernelInfo *) NULL)
2237 ThrowWandFatalException(ResourceLimitFatalError,
2238 "MemoryAllocationFailed",(*image)->filename);
anthony930be612010-02-08 04:26:15 +00002239 if ( GetImageArtifact(*image,"showkernel") != (const char *) NULL)
2240 ShowKernelInfo(kernel); /* display the kernel to stderr */
anthony29188a82010-01-22 10:12:34 +00002241 morphology_image=MorphologyImageChannel(*image,channel,method,
cristy02d5b4f2010-02-01 01:08:27 +00002242 iterations,kernel,exception);
anthony83ba99b2010-01-24 08:48:15 +00002243 kernel=DestroyKernelInfo(kernel);
anthony29188a82010-01-22 10:12:34 +00002244 if (morphology_image == (Image *) NULL)
2245 break;
2246 *image=DestroyImage(*image);
2247 *image=morphology_image;
2248 break;
2249 }
cristy3ed852e2009-09-05 21:47:34 +00002250 if (LocaleCompare("motion-blur",option+1) == 0)
2251 {
2252 Image
2253 *blur_image;
2254
2255 /*
2256 Motion blur image.
2257 */
2258 (void) SyncImageSettings(image_info,*image);
2259 flags=ParseGeometry(argv[i+1],&geometry_info);
2260 if ((flags & SigmaValue) == 0)
2261 geometry_info.sigma=1.0;
2262 blur_image=MotionBlurImageChannel(*image,channel,geometry_info.rho,
2263 geometry_info.sigma,geometry_info.xi,exception);
2264 if (blur_image == (Image *) NULL)
2265 break;
2266 *image=DestroyImage(*image);
2267 *image=blur_image;
2268 break;
2269 }
2270 break;
2271 }
2272 case 'n':
2273 {
2274 if (LocaleCompare("negate",option+1) == 0)
2275 {
2276 (void) SyncImageSettings(image_info,*image);
2277 (void) NegateImageChannel(*image,channel,*option == '+' ?
2278 MagickTrue : MagickFalse);
2279 InheritException(exception,&(*image)->exception);
2280 break;
2281 }
2282 if (LocaleCompare("noise",option+1) == 0)
2283 {
2284 Image
2285 *noisy_image;
2286
2287 (void) SyncImageSettings(image_info,*image);
2288 if (*option == '-')
2289 {
2290 (void) ParseGeometry(argv[i+1],&geometry_info);
2291 noisy_image=ReduceNoiseImage(*image,geometry_info.rho,
2292 exception);
2293 }
2294 else
2295 {
2296 NoiseType
2297 noise;
2298
2299 noise=(NoiseType) ParseMagickOption(MagickNoiseOptions,
2300 MagickFalse,argv[i+1]);
2301 noisy_image=AddNoiseImageChannel(*image,channel,noise,
2302 exception);
2303 }
2304 if (noisy_image == (Image *) NULL)
2305 break;
2306 *image=DestroyImage(*image);
2307 *image=noisy_image;
2308 break;
2309 }
2310 if (LocaleCompare("normalize",option+1) == 0)
2311 {
2312 (void) SyncImageSettings(image_info,*image);
2313 (void) NormalizeImageChannel(*image,channel);
2314 InheritException(exception,&(*image)->exception);
2315 break;
2316 }
2317 break;
2318 }
2319 case 'o':
2320 {
2321 if (LocaleCompare("opaque",option+1) == 0)
2322 {
2323 MagickPixelPacket
2324 target;
2325
2326 (void) SyncImageSettings(image_info,*image);
2327 (void) QueryMagickColor(argv[i+1],&target,exception);
2328 (void) OpaquePaintImageChannel(*image,channel,&target,&fill,
2329 *option == '-' ? MagickFalse : MagickTrue);
2330 break;
2331 }
2332 if (LocaleCompare("ordered-dither",option+1) == 0)
2333 {
2334 (void) SyncImageSettings(image_info,*image);
2335 (void) OrderedPosterizeImageChannel(*image,channel,argv[i+1],
2336 exception);
2337 break;
2338 }
2339 break;
2340 }
2341 case 'p':
2342 {
2343 if (LocaleCompare("paint",option+1) == 0)
2344 {
2345 Image
2346 *paint_image;
2347
2348 /*
2349 Oil paint image.
2350 */
2351 (void) SyncImageSettings(image_info,*image);
2352 (void) ParseGeometry(argv[i+1],&geometry_info);
2353 paint_image=OilPaintImage(*image,geometry_info.rho,exception);
2354 if (paint_image == (Image *) NULL)
2355 break;
2356 *image=DestroyImage(*image);
2357 *image=paint_image;
2358 break;
2359 }
2360 if (LocaleCompare("pen",option+1) == 0)
2361 {
2362 if (*option == '+')
2363 {
2364 (void) QueryColorDatabase("none",&draw_info->fill,exception);
2365 break;
2366 }
2367 (void) QueryColorDatabase(argv[i+1],&draw_info->fill,exception);
2368 break;
2369 }
2370 if (LocaleCompare("pointsize",option+1) == 0)
2371 {
2372 if (*option == '+')
2373 (void) ParseGeometry("12",&geometry_info);
2374 else
2375 (void) ParseGeometry(argv[i+1],&geometry_info);
2376 draw_info->pointsize=geometry_info.rho;
2377 break;
2378 }
2379 if (LocaleCompare("polaroid",option+1) == 0)
2380 {
2381 double
2382 angle;
2383
2384 Image
2385 *polaroid_image;
2386
2387 RandomInfo
2388 *random_info;
2389
2390 /*
2391 Simulate a Polaroid picture.
2392 */
2393 (void) SyncImageSettings(image_info,*image);
2394 random_info=AcquireRandomInfo();
2395 angle=22.5*(GetPseudoRandomValue(random_info)-0.5);
2396 random_info=DestroyRandomInfo(random_info);
2397 if (*option == '-')
2398 {
2399 SetGeometryInfo(&geometry_info);
2400 flags=ParseGeometry(argv[i+1],&geometry_info);
2401 angle=geometry_info.rho;
2402 }
2403 polaroid_image=PolaroidImage(*image,draw_info,angle,exception);
2404 if (polaroid_image == (Image *) NULL)
2405 break;
2406 *image=DestroyImage(*image);
2407 *image=polaroid_image;
2408 break;
2409 }
2410 if (LocaleCompare("posterize",option+1) == 0)
2411 {
2412 /*
2413 Posterize image.
2414 */
2415 (void) SyncImageSettings(image_info,*image);
cristye27293e2009-12-18 02:53:20 +00002416 (void) PosterizeImage(*image,StringToUnsignedLong(argv[i+1]),
cristy3ed852e2009-09-05 21:47:34 +00002417 quantize_info->dither);
2418 InheritException(exception,&(*image)->exception);
2419 break;
2420 }
2421 if (LocaleCompare("preview",option+1) == 0)
2422 {
2423 Image
2424 *preview_image;
2425
2426 PreviewType
2427 preview_type;
2428
2429 /*
2430 Preview image.
2431 */
2432 (void) SyncImageSettings(image_info,*image);
2433 if (*option == '+')
2434 preview_type=UndefinedPreview;
2435 else
2436 preview_type=(PreviewType) ParseMagickOption(MagickPreviewOptions,
2437 MagickFalse,argv[i+1]);
2438 preview_image=PreviewImage(*image,preview_type,exception);
2439 if (preview_image == (Image *) NULL)
2440 break;
2441 *image=DestroyImage(*image);
2442 *image=preview_image;
2443 break;
2444 }
2445 if (LocaleCompare("profile",option+1) == 0)
2446 {
2447 const char
2448 *name;
2449
2450 const StringInfo
2451 *profile;
2452
2453 Image
2454 *profile_image;
2455
2456 ImageInfo
2457 *profile_info;
2458
2459 (void) SyncImageSettings(image_info,*image);
2460 if (*option == '+')
2461 {
2462 /*
2463 Remove a profile from the image.
2464 */
2465 (void) ProfileImage(*image,argv[i+1],(const unsigned char *)
2466 NULL,0,MagickTrue);
2467 InheritException(exception,&(*image)->exception);
2468 break;
2469 }
2470 /*
2471 Associate a profile with the image.
2472 */
2473 profile_info=CloneImageInfo(image_info);
2474 profile=GetImageProfile(*image,"iptc");
2475 if (profile != (StringInfo *) NULL)
2476 profile_info->profile=(void *) CloneStringInfo(profile);
2477 profile_image=GetImageCache(profile_info,argv[i+1],exception);
2478 profile_info=DestroyImageInfo(profile_info);
2479 if (profile_image == (Image *) NULL)
2480 {
2481 char
2482 name[MaxTextExtent],
2483 filename[MaxTextExtent];
2484
2485 register char
2486 *p;
2487
2488 StringInfo
2489 *profile;
2490
2491 (void) CopyMagickString(filename,argv[i+1],MaxTextExtent);
2492 (void) CopyMagickString(name,argv[i+1],MaxTextExtent);
2493 for (p=filename; *p != '\0'; p++)
2494 if ((*p == ':') && (IsPathDirectory(argv[i+1]) < 0) &&
2495 (IsPathAccessible(argv[i+1]) == MagickFalse))
2496 {
2497 register char
2498 *q;
2499
2500 /*
2501 Look for profile name (e.g. name:profile).
2502 */
2503 (void) CopyMagickString(name,filename,(size_t)
2504 (p-filename+1));
2505 for (q=filename; *q != '\0'; q++)
2506 *q=(*++p);
2507 break;
2508 }
2509 profile=FileToStringInfo(filename,~0UL,exception);
2510 if (profile != (StringInfo *) NULL)
2511 {
2512 (void) ProfileImage(*image,name,GetStringInfoDatum(profile),
2513 (unsigned long) GetStringInfoLength(profile),MagickFalse);
2514 profile=DestroyStringInfo(profile);
2515 }
2516 break;
2517 }
2518 ResetImageProfileIterator(profile_image);
2519 name=GetNextImageProfile(profile_image);
2520 while (name != (const char *) NULL)
2521 {
2522 profile=GetImageProfile(profile_image,name);
2523 if (profile != (StringInfo *) NULL)
2524 (void) ProfileImage(*image,name,GetStringInfoDatum(profile),
2525 (unsigned long) GetStringInfoLength(profile),MagickFalse);
2526 name=GetNextImageProfile(profile_image);
2527 }
2528 profile_image=DestroyImage(profile_image);
2529 break;
2530 }
2531 break;
2532 }
2533 case 'q':
2534 {
2535 if (LocaleCompare("quantize",option+1) == 0)
2536 {
2537 if (*option == '+')
2538 {
2539 quantize_info->colorspace=UndefinedColorspace;
2540 break;
2541 }
2542 quantize_info->colorspace=(ColorspaceType) ParseMagickOption(
2543 MagickColorspaceOptions,MagickFalse,argv[i+1]);
2544 break;
2545 }
2546 break;
2547 }
2548 case 'r':
2549 {
2550 if (LocaleCompare("radial-blur",option+1) == 0)
2551 {
2552 Image
2553 *blur_image;
2554
2555 /*
2556 Radial blur image.
2557 */
2558 (void) SyncImageSettings(image_info,*image);
cristya5447be2010-01-11 00:20:51 +00002559 blur_image=RadialBlurImageChannel(*image,channel,
2560 StringToDouble(argv[i+1]),exception);
cristy3ed852e2009-09-05 21:47:34 +00002561 if (blur_image == (Image *) NULL)
2562 break;
2563 *image=DestroyImage(*image);
2564 *image=blur_image;
2565 break;
2566 }
2567 if (LocaleCompare("raise",option+1) == 0)
2568 {
2569 /*
2570 Surround image with a raise of solid color.
2571 */
2572 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2573 if ((flags & SigmaValue) == 0)
2574 geometry.height=geometry.width;
2575 (void) RaiseImage(*image,&geometry,*option == '-' ? MagickTrue :
2576 MagickFalse);
2577 InheritException(exception,&(*image)->exception);
2578 break;
2579 }
2580 if (LocaleCompare("random-threshold",option+1) == 0)
2581 {
2582 /*
2583 Threshold image.
2584 */
2585 (void) SyncImageSettings(image_info,*image);
2586 (void) RandomThresholdImageChannel(*image,channel,argv[i+1],
2587 exception);
2588 break;
2589 }
2590 if (LocaleCompare("recolor",option+1) == 0)
2591 {
2592 char
2593 token[MaxTextExtent];
2594
2595 const char
2596 *p;
2597
2598 double
2599 *color_matrix;
2600
2601 Image
2602 *recolor_image;
2603
2604 register long
2605 x;
2606
2607 unsigned long
2608 order;
2609
2610 /*
2611 Transform color image.
2612 */
2613 (void) SyncImageSettings(image_info,*image);
2614 p=argv[i+1];
2615 for (x=0; *p != '\0'; x++)
2616 {
2617 GetMagickToken(p,&p,token);
2618 if (*token == ',')
2619 GetMagickToken(p,&p,token);
2620 }
2621 order=(unsigned long) sqrt((double) x+1.0);
2622 color_matrix=(double *) AcquireQuantumMemory(order,order*
2623 sizeof(*color_matrix));
2624 if (color_matrix == (double *) NULL)
2625 ThrowWandFatalException(ResourceLimitFatalError,
2626 "MemoryAllocationFailed",(*image)->filename);
2627 p=argv[i+1];
2628 for (x=0; (x < (long) (order*order)) && (*p != '\0'); x++)
2629 {
2630 GetMagickToken(p,&p,token);
2631 if (*token == ',')
2632 GetMagickToken(p,&p,token);
cristyf2f27272009-12-17 14:48:46 +00002633 color_matrix[x]=StringToDouble(token);
cristy3ed852e2009-09-05 21:47:34 +00002634 }
2635 for ( ; x < (long) (order*order); x++)
2636 color_matrix[x]=0.0;
2637 recolor_image=RecolorImage(*image,order,color_matrix,exception);
2638 color_matrix=(double *) RelinquishMagickMemory(color_matrix);
2639 if (recolor_image == (Image *) NULL)
2640 break;
2641 *image=DestroyImage(*image);
2642 *image=recolor_image;
2643 break;
2644 }
2645 if (LocaleCompare("region",option+1) == 0)
2646 {
2647 Image
2648 *crop_image;
2649
2650 (void) SyncImageSettings(image_info,*image);
2651 if (region_image != (Image *) NULL)
2652 {
2653 /*
2654 Composite region.
2655 */
2656 (void) CompositeImage(region_image,(*image)->matte !=
2657 MagickFalse ? OverCompositeOp : CopyCompositeOp,*image,
2658 region_geometry.x,region_geometry.y);
2659 InheritException(exception,&region_image->exception);
2660 *image=DestroyImage(*image);
2661 *image=region_image;
2662 }
2663 if (*option == '+')
2664 {
2665 if (region_image != (Image *) NULL)
2666 region_image=DestroyImage(region_image);
2667 break;
2668 }
2669 /*
2670 Apply transformations to a selected region of the image.
2671 */
2672 (void) ParseGravityGeometry(*image,argv[i+1],&region_geometry,
2673 exception);
2674 crop_image=CropImage(*image,&region_geometry,exception);
2675 if (crop_image == (Image *) NULL)
2676 break;
2677 region_image=(*image);
2678 *image=crop_image;
2679 break;
2680 }
2681 if (LocaleCompare("render",option+1) == 0)
2682 {
2683 (void) SyncImageSettings(image_info,*image);
2684 draw_info->render=(*option == '+') ? MagickTrue : MagickFalse;
2685 break;
2686 }
2687 if (LocaleCompare("remap",option+1) == 0)
2688 {
2689 Image
2690 *remap_image;
2691
2692 /*
2693 Transform image colors to match this set of colors.
2694 */
2695 (void) SyncImageSettings(image_info,*image);
2696 if (*option == '+')
2697 break;
2698 remap_image=GetImageCache(image_info,argv[i+1],exception);
2699 if (remap_image == (Image *) NULL)
2700 break;
2701 (void) RemapImage(quantize_info,*image,remap_image);
2702 InheritException(exception,&(*image)->exception);
2703 remap_image=DestroyImage(remap_image);
2704 break;
2705 }
2706 if (LocaleCompare("repage",option+1) == 0)
2707 {
2708 if (*option == '+')
2709 {
2710 (void) ParseAbsoluteGeometry("0x0+0+0",&(*image)->page);
2711 break;
2712 }
2713 (void) ResetImagePage(*image,argv[i+1]);
2714 InheritException(exception,&(*image)->exception);
2715 break;
2716 }
2717 if (LocaleCompare("resample",option+1) == 0)
2718 {
2719 Image
2720 *resample_image;
2721
2722 /*
2723 Resample image.
2724 */
2725 (void) SyncImageSettings(image_info,*image);
2726 flags=ParseGeometry(argv[i+1],&geometry_info);
2727 if ((flags & SigmaValue) == 0)
2728 geometry_info.sigma=geometry_info.rho;
2729 resample_image=ResampleImage(*image,geometry_info.rho,
2730 geometry_info.sigma,(*image)->filter,(*image)->blur,exception);
2731 if (resample_image == (Image *) NULL)
2732 break;
2733 *image=DestroyImage(*image);
2734 *image=resample_image;
2735 break;
2736 }
2737 if (LocaleCompare("resize",option+1) == 0)
2738 {
2739 Image
2740 *resize_image;
2741
2742 /*
2743 Resize image.
2744 */
2745 (void) SyncImageSettings(image_info,*image);
2746 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2747 resize_image=ResizeImage(*image,geometry.width,geometry.height,
2748 (*image)->filter,(*image)->blur,exception);
2749 if (resize_image == (Image *) NULL)
2750 break;
2751 *image=DestroyImage(*image);
2752 *image=resize_image;
2753 break;
2754 }
2755 if (LocaleNCompare("respect-parentheses",option+1,17) == 0)
2756 {
2757 respect_parenthesis=(*option == '-') ? MagickTrue : MagickFalse;
2758 break;
2759 }
2760 if (LocaleCompare("roll",option+1) == 0)
2761 {
2762 Image
2763 *roll_image;
2764
2765 /*
2766 Roll image.
2767 */
2768 (void) SyncImageSettings(image_info,*image);
2769 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2770 roll_image=RollImage(*image,geometry.x,geometry.y,exception);
2771 if (roll_image == (Image *) NULL)
2772 break;
2773 *image=DestroyImage(*image);
2774 *image=roll_image;
2775 break;
2776 }
2777 if (LocaleCompare("rotate",option+1) == 0)
2778 {
2779 char
2780 *geometry;
2781
2782 Image
2783 *rotate_image;
2784
2785 /*
2786 Check for conditional image rotation.
2787 */
2788 (void) SyncImageSettings(image_info,*image);
2789 if (strchr(argv[i+1],'>') != (char *) NULL)
2790 if ((*image)->columns <= (*image)->rows)
2791 break;
2792 if (strchr(argv[i+1],'<') != (char *) NULL)
2793 if ((*image)->columns >= (*image)->rows)
2794 break;
2795 /*
2796 Rotate image.
2797 */
2798 geometry=ConstantString(argv[i+1]);
2799 (void) SubstituteString(&geometry,">","");
2800 (void) SubstituteString(&geometry,"<","");
2801 (void) ParseGeometry(geometry,&geometry_info);
2802 geometry=DestroyString(geometry);
2803 rotate_image=RotateImage(*image,geometry_info.rho,exception);
2804 if (rotate_image == (Image *) NULL)
2805 break;
2806 *image=DestroyImage(*image);
2807 *image=rotate_image;
2808 break;
2809 }
2810 break;
2811 }
2812 case 's':
2813 {
2814 if (LocaleCompare("sample",option+1) == 0)
2815 {
2816 Image
2817 *sample_image;
2818
2819 /*
2820 Sample image with pixel replication.
2821 */
2822 (void) SyncImageSettings(image_info,*image);
2823 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2824 sample_image=SampleImage(*image,geometry.width,geometry.height,
2825 exception);
2826 if (sample_image == (Image *) NULL)
2827 break;
2828 *image=DestroyImage(*image);
2829 *image=sample_image;
2830 break;
2831 }
2832 if (LocaleCompare("scale",option+1) == 0)
2833 {
2834 Image
2835 *scale_image;
2836
2837 /*
2838 Resize image.
2839 */
2840 (void) SyncImageSettings(image_info,*image);
2841 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2842 scale_image=ScaleImage(*image,geometry.width,geometry.height,
2843 exception);
2844 if (scale_image == (Image *) NULL)
2845 break;
2846 *image=DestroyImage(*image);
2847 *image=scale_image;
2848 break;
2849 }
2850 if (LocaleCompare("selective-blur",option+1) == 0)
2851 {
2852 Image
2853 *blur_image;
2854
2855 /*
2856 Selectively blur pixels within a contrast threshold.
2857 */
2858 (void) SyncImageSettings(image_info,*image);
2859 flags=ParseGeometry(argv[i+1],&geometry_info);
2860 if ((flags & PercentValue) != 0)
2861 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
2862 blur_image=SelectiveBlurImageChannel(*image,channel,
2863 geometry_info.rho,geometry_info.sigma,geometry_info.xi,exception);
2864 if (blur_image == (Image *) NULL)
2865 break;
2866 *image=DestroyImage(*image);
2867 *image=blur_image;
2868 break;
2869 }
2870 if (LocaleCompare("separate",option+1) == 0)
2871 {
2872 Image
2873 *separate_images;
2874
2875 /*
2876 Break channels into separate images.
2877 */
2878 (void) SyncImageSettings(image_info,*image);
2879 separate_images=SeparateImages(*image,channel,exception);
2880 if (separate_images == (Image *) NULL)
2881 break;
2882 *image=DestroyImage(*image);
2883 *image=separate_images;
2884 break;
2885 }
2886 if (LocaleCompare("sepia-tone",option+1) == 0)
2887 {
2888 double
2889 threshold;
2890
2891 Image
2892 *sepia_image;
2893
2894 /*
2895 Sepia-tone image.
2896 */
2897 (void) SyncImageSettings(image_info,*image);
cristyf2f27272009-12-17 14:48:46 +00002898 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
cristy3ed852e2009-09-05 21:47:34 +00002899 sepia_image=SepiaToneImage(*image,threshold,exception);
2900 if (sepia_image == (Image *) NULL)
2901 break;
2902 *image=DestroyImage(*image);
2903 *image=sepia_image;
2904 break;
2905 }
2906 if (LocaleCompare("segment",option+1) == 0)
2907 {
2908 /*
2909 Segment image.
2910 */
2911 (void) SyncImageSettings(image_info,*image);
2912 flags=ParseGeometry(argv[i+1],&geometry_info);
2913 if ((flags & SigmaValue) == 0)
2914 geometry_info.sigma=1.0;
2915 (void) SegmentImage(*image,(*image)->colorspace,image_info->verbose,
2916 geometry_info.rho,geometry_info.sigma);
2917 InheritException(exception,&(*image)->exception);
2918 break;
2919 }
2920 if (LocaleCompare("set",option+1) == 0)
2921 {
2922 /*
2923 Set image option.
2924 */
2925 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2926 (void) DeleteImageRegistry(argv[i+1]+9);
2927 else
2928 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
2929 (void) DeleteImageOption(image_info,argv[i+1]+7);
2930 else
2931 (void) DeleteImageProperty(*image,argv[i+1]);
2932 if (*option == '-')
2933 {
2934 char
2935 *value;
2936
2937 value=InterpretImageProperties(image_info,*image,argv[i+2]);
2938 if (value != (char *) NULL)
2939 {
2940 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2941 (void) SetImageRegistry(StringRegistryType,argv[i+1]+9,
2942 value,exception);
2943 else
2944 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
2945 {
2946 (void) SetImageOption(image_info,argv[i+1]+7,value);
2947 (void) SetImageArtifact(*image,argv[i+1]+7,value);
2948 }
2949 else
2950 (void) SetImageProperty(*image,argv[i+1],value);
2951 value=DestroyString(value);
2952 }
2953 }
2954 break;
2955 }
2956 if (LocaleCompare("shade",option+1) == 0)
2957 {
2958 Image
2959 *shade_image;
2960
2961 /*
2962 Shade image.
2963 */
2964 (void) SyncImageSettings(image_info,*image);
2965 flags=ParseGeometry(argv[i+1],&geometry_info);
2966 if ((flags & SigmaValue) == 0)
2967 geometry_info.sigma=1.0;
2968 shade_image=ShadeImage(*image,(*option == '-') ? MagickTrue :
2969 MagickFalse,geometry_info.rho,geometry_info.sigma,exception);
2970 if (shade_image == (Image *) NULL)
2971 break;
2972 *image=DestroyImage(*image);
2973 *image=shade_image;
2974 break;
2975 }
2976 if (LocaleCompare("shadow",option+1) == 0)
2977 {
2978 Image
2979 *shadow_image;
2980
2981 /*
2982 Shadow image.
2983 */
2984 (void) SyncImageSettings(image_info,*image);
2985 flags=ParseGeometry(argv[i+1],&geometry_info);
2986 if ((flags & SigmaValue) == 0)
2987 geometry_info.sigma=1.0;
2988 if ((flags & XiValue) == 0)
2989 geometry_info.xi=4.0;
2990 if ((flags & PsiValue) == 0)
2991 geometry_info.psi=4.0;
2992 shadow_image=ShadowImage(*image,geometry_info.rho,
2993 geometry_info.sigma,(long) (geometry_info.xi+0.5),(long)
2994 (geometry_info.psi+0.5),exception);
2995 if (shadow_image == (Image *) NULL)
2996 break;
2997 *image=DestroyImage(*image);
2998 *image=shadow_image;
2999 break;
3000 }
3001 if (LocaleCompare("sharpen",option+1) == 0)
3002 {
3003 Image
3004 *sharp_image;
3005
3006 /*
3007 Sharpen image.
3008 */
3009 (void) SyncImageSettings(image_info,*image);
3010 flags=ParseGeometry(argv[i+1],&geometry_info);
3011 if ((flags & SigmaValue) == 0)
3012 geometry_info.sigma=1.0;
3013 sharp_image=SharpenImageChannel(*image,channel,geometry_info.rho,
3014 geometry_info.sigma,exception);
3015 if (sharp_image == (Image *) NULL)
3016 break;
3017 *image=DestroyImage(*image);
3018 *image=sharp_image;
3019 break;
3020 }
3021 if (LocaleCompare("shave",option+1) == 0)
3022 {
3023 Image
3024 *shave_image;
3025
3026 /*
3027 Shave the image edges.
3028 */
3029 (void) SyncImageSettings(image_info,*image);
3030 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
3031 shave_image=ShaveImage(*image,&geometry,exception);
3032 if (shave_image == (Image *) NULL)
3033 break;
3034 *image=DestroyImage(*image);
3035 *image=shave_image;
3036 break;
3037 }
3038 if (LocaleCompare("shear",option+1) == 0)
3039 {
3040 Image
3041 *shear_image;
3042
3043 /*
3044 Shear image.
3045 */
3046 (void) SyncImageSettings(image_info,*image);
3047 flags=ParseGeometry(argv[i+1],&geometry_info);
3048 if ((flags & SigmaValue) == 0)
3049 geometry_info.sigma=geometry_info.rho;
3050 shear_image=ShearImage(*image,geometry_info.rho,geometry_info.sigma,
3051 exception);
3052 if (shear_image == (Image *) NULL)
3053 break;
3054 *image=DestroyImage(*image);
3055 *image=shear_image;
3056 break;
3057 }
3058 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
3059 {
3060 /*
3061 Sigmoidal non-linearity contrast control.
3062 */
3063 (void) SyncImageSettings(image_info,*image);
3064 flags=ParseGeometry(argv[i+1],&geometry_info);
3065 if ((flags & SigmaValue) == 0)
3066 geometry_info.sigma=(double) QuantumRange/2.0;
3067 if ((flags & PercentValue) != 0)
3068 geometry_info.sigma=(double) QuantumRange*geometry_info.sigma/
3069 100.0;
3070 (void) SigmoidalContrastImageChannel(*image,channel,
3071 (*option == '-') ? MagickTrue : MagickFalse,geometry_info.rho,
3072 geometry_info.sigma);
3073 InheritException(exception,&(*image)->exception);
3074 break;
3075 }
3076 if (LocaleCompare("sketch",option+1) == 0)
3077 {
3078 Image
3079 *sketch_image;
3080
3081 /*
3082 Sketch image.
3083 */
3084 (void) SyncImageSettings(image_info,*image);
3085 flags=ParseGeometry(argv[i+1],&geometry_info);
3086 if ((flags & SigmaValue) == 0)
3087 geometry_info.sigma=1.0;
3088 sketch_image=SketchImage(*image,geometry_info.rho,
3089 geometry_info.sigma,geometry_info.xi,exception);
3090 if (sketch_image == (Image *) NULL)
3091 break;
3092 *image=DestroyImage(*image);
3093 *image=sketch_image;
3094 break;
3095 }
3096 if (LocaleCompare("solarize",option+1) == 0)
3097 {
3098 double
3099 threshold;
3100
3101 (void) SyncImageSettings(image_info,*image);
cristyf2f27272009-12-17 14:48:46 +00003102 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
cristy3ed852e2009-09-05 21:47:34 +00003103 (void) SolarizeImage(*image,threshold);
3104 InheritException(exception,&(*image)->exception);
3105 break;
3106 }
3107 if (LocaleCompare("sparse-color",option+1) == 0)
3108 {
3109 Image
3110 *sparse_image;
3111
3112 SparseColorMethod
3113 method;
3114
3115 char
3116 *arguments;
3117
3118 /*
3119 Sparse Color Interpolated Gradient
3120 */
3121 (void) SyncImageSettings(image_info,*image);
3122 method=(SparseColorMethod) ParseMagickOption(
3123 MagickSparseColorOptions,MagickFalse,argv[i+1]);
3124 arguments=InterpretImageProperties(image_info,*image,argv[i+2]);
3125 InheritException(exception,&(*image)->exception);
3126 if (arguments == (char *) NULL)
3127 break;
3128 sparse_image=SparseColorOption(*image,channel,method,arguments,
3129 option[0] == '+' ? MagickTrue : MagickFalse,exception);
3130 arguments=DestroyString(arguments);
3131 if (sparse_image == (Image *) NULL)
3132 break;
3133 *image=DestroyImage(*image);
3134 *image=sparse_image;
3135 break;
3136 }
3137 if (LocaleCompare("splice",option+1) == 0)
3138 {
3139 Image
3140 *splice_image;
3141
3142 /*
3143 Splice a solid color into the image.
3144 */
3145 (void) SyncImageSettings(image_info,*image);
3146 (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
3147 splice_image=SpliceImage(*image,&geometry,exception);
3148 if (splice_image == (Image *) NULL)
3149 break;
3150 *image=DestroyImage(*image);
3151 *image=splice_image;
3152 break;
3153 }
3154 if (LocaleCompare("spread",option+1) == 0)
3155 {
3156 Image
3157 *spread_image;
3158
3159 /*
3160 Spread an image.
3161 */
3162 (void) SyncImageSettings(image_info,*image);
3163 (void) ParseGeometry(argv[i+1],&geometry_info);
3164 spread_image=SpreadImage(*image,geometry_info.rho,exception);
3165 if (spread_image == (Image *) NULL)
3166 break;
3167 *image=DestroyImage(*image);
3168 *image=spread_image;
3169 break;
3170 }
3171 if (LocaleCompare("stretch",option+1) == 0)
3172 {
3173 if (*option == '+')
3174 {
3175 draw_info->stretch=UndefinedStretch;
3176 break;
3177 }
3178 draw_info->stretch=(StretchType) ParseMagickOption(
3179 MagickStretchOptions,MagickFalse,argv[i+1]);
3180 break;
3181 }
3182 if (LocaleCompare("strip",option+1) == 0)
3183 {
3184 /*
3185 Strip image of profiles and comments.
3186 */
3187 (void) SyncImageSettings(image_info,*image);
3188 (void) StripImage(*image);
3189 InheritException(exception,&(*image)->exception);
3190 break;
3191 }
3192 if (LocaleCompare("stroke",option+1) == 0)
3193 {
3194 ExceptionInfo
3195 *sans;
3196
3197 if (*option == '+')
3198 {
3199 (void) QueryColorDatabase("none",&draw_info->stroke,exception);
3200 if (draw_info->stroke_pattern != (Image *) NULL)
3201 draw_info->stroke_pattern=DestroyImage(
3202 draw_info->stroke_pattern);
3203 break;
3204 }
3205 sans=AcquireExceptionInfo();
3206 status=QueryColorDatabase(argv[i+1],&draw_info->stroke,sans);
3207 sans=DestroyExceptionInfo(sans);
3208 if (status == MagickFalse)
3209 draw_info->stroke_pattern=GetImageCache(image_info,argv[i+1],
3210 exception);
3211 break;
3212 }
3213 if (LocaleCompare("strokewidth",option+1) == 0)
3214 {
cristyf2f27272009-12-17 14:48:46 +00003215 draw_info->stroke_width=StringToDouble(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00003216 break;
3217 }
3218 if (LocaleCompare("style",option+1) == 0)
3219 {
3220 if (*option == '+')
3221 {
3222 draw_info->style=UndefinedStyle;
3223 break;
3224 }
3225 draw_info->style=(StyleType) ParseMagickOption(MagickStyleOptions,
3226 MagickFalse,argv[i+1]);
3227 break;
3228 }
3229 if (LocaleCompare("swirl",option+1) == 0)
3230 {
3231 Image
3232 *swirl_image;
3233
3234 /*
3235 Swirl image.
3236 */
3237 (void) SyncImageSettings(image_info,*image);
3238 (void) ParseGeometry(argv[i+1],&geometry_info);
3239 swirl_image=SwirlImage(*image,geometry_info.rho,exception);
3240 if (swirl_image == (Image *) NULL)
3241 break;
3242 *image=DestroyImage(*image);
3243 *image=swirl_image;
3244 break;
3245 }
3246 break;
3247 }
3248 case 't':
3249 {
3250 if (LocaleCompare("threshold",option+1) == 0)
3251 {
3252 double
3253 threshold;
3254
3255 /*
3256 Threshold image.
3257 */
3258 (void) SyncImageSettings(image_info,*image);
3259 if (*option == '+')
3260 threshold=(double) QuantumRange/2.5;
3261 else
cristyf2f27272009-12-17 14:48:46 +00003262 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
cristy3ed852e2009-09-05 21:47:34 +00003263 (void) BilevelImageChannel(*image,channel,threshold);
3264 InheritException(exception,&(*image)->exception);
3265 break;
3266 }
3267 if (LocaleCompare("thumbnail",option+1) == 0)
3268 {
3269 Image
3270 *thumbnail_image;
3271
3272 /*
3273 Thumbnail image.
3274 */
3275 (void) SyncImageSettings(image_info,*image);
3276 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
3277 thumbnail_image=ThumbnailImage(*image,geometry.width,
3278 geometry.height,exception);
3279 if (thumbnail_image == (Image *) NULL)
3280 break;
3281 *image=DestroyImage(*image);
3282 *image=thumbnail_image;
3283 break;
3284 }
3285 if (LocaleCompare("tile",option+1) == 0)
3286 {
3287 if (*option == '+')
3288 {
3289 if (draw_info->fill_pattern != (Image *) NULL)
3290 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
3291 break;
3292 }
3293 draw_info->fill_pattern=GetImageCache(image_info,argv[i+1],
3294 exception);
3295 break;
3296 }
3297 if (LocaleCompare("tint",option+1) == 0)
3298 {
3299 Image
3300 *tint_image;
3301
3302 /*
3303 Tint the image.
3304 */
3305 (void) SyncImageSettings(image_info,*image);
3306 tint_image=TintImage(*image,argv[i+1],draw_info->fill,exception);
3307 if (tint_image == (Image *) NULL)
3308 break;
3309 *image=DestroyImage(*image);
3310 *image=tint_image;
3311 break;
3312 }
3313 if (LocaleCompare("transform",option+1) == 0)
3314 {
3315 Image
3316 *transform_image;
3317
3318 /*
3319 Affine transform image.
3320 */
3321 (void) SyncImageSettings(image_info,*image);
3322 transform_image=AffineTransformImage(*image,&draw_info->affine,
3323 exception);
3324 if (transform_image == (Image *) NULL)
3325 break;
3326 *image=DestroyImage(*image);
3327 *image=transform_image;
3328 break;
3329 }
3330 if (LocaleCompare("transparent",option+1) == 0)
3331 {
3332 MagickPixelPacket
3333 target;
3334
3335 (void) SyncImageSettings(image_info,*image);
3336 (void) QueryMagickColor(argv[i+1],&target,exception);
3337 (void) TransparentPaintImage(*image,&target,(Quantum)
3338 TransparentOpacity,*option == '-' ? MagickFalse : MagickTrue);
3339 InheritException(exception,&(*image)->exception);
3340 break;
3341 }
3342 if (LocaleCompare("transpose",option+1) == 0)
3343 {
3344 Image
3345 *transpose_image;
3346
3347 /*
3348 Transpose image scanlines.
3349 */
3350 (void) SyncImageSettings(image_info,*image);
3351 transpose_image=TransposeImage(*image,exception);
3352 if (transpose_image == (Image *) NULL)
3353 break;
3354 *image=DestroyImage(*image);
3355 *image=transpose_image;
3356 break;
3357 }
3358 if (LocaleCompare("transverse",option+1) == 0)
3359 {
3360 Image
3361 *transverse_image;
3362
3363 /*
3364 Transverse image scanlines.
3365 */
3366 (void) SyncImageSettings(image_info,*image);
3367 transverse_image=TransverseImage(*image,exception);
3368 if (transverse_image == (Image *) NULL)
3369 break;
3370 *image=DestroyImage(*image);
3371 *image=transverse_image;
3372 break;
3373 }
3374 if (LocaleCompare("treedepth",option+1) == 0)
3375 {
cristye27293e2009-12-18 02:53:20 +00003376 quantize_info->tree_depth=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00003377 break;
3378 }
3379 if (LocaleCompare("trim",option+1) == 0)
3380 {
3381 Image
3382 *trim_image;
3383
3384 /*
3385 Trim image.
3386 */
3387 (void) SyncImageSettings(image_info,*image);
3388 trim_image=TrimImage(*image,exception);
3389 if (trim_image == (Image *) NULL)
3390 break;
3391 *image=DestroyImage(*image);
3392 *image=trim_image;
3393 break;
3394 }
3395 if (LocaleCompare("type",option+1) == 0)
3396 {
3397 ImageType
3398 type;
3399
3400 (void) SyncImageSettings(image_info,*image);
3401 if (*option == '+')
3402 type=UndefinedType;
3403 else
3404 type=(ImageType) ParseMagickOption(MagickTypeOptions,MagickFalse,
3405 argv[i+1]);
3406 (*image)->type=UndefinedType;
3407 (void) SetImageType(*image,type);
3408 InheritException(exception,&(*image)->exception);
3409 break;
3410 }
3411 break;
3412 }
3413 case 'u':
3414 {
3415 if (LocaleCompare("undercolor",option+1) == 0)
3416 {
3417 (void) QueryColorDatabase(argv[i+1],&draw_info->undercolor,
3418 exception);
3419 break;
3420 }
cristy045bd902010-01-30 18:56:24 +00003421 if (LocaleCompare("unique",option+1) == 0)
3422 {
3423 if (*option == '+')
3424 {
3425 (void) DeleteImageArtifact(*image,"identify:unique");
3426 break;
3427 }
3428 (void) SetImageArtifact(*image,"identify:unique","true");
3429 break;
3430 }
cristy3ed852e2009-09-05 21:47:34 +00003431 if (LocaleCompare("unique-colors",option+1) == 0)
3432 {
3433 Image
3434 *unique_image;
3435
3436 /*
3437 Unique image colors.
3438 */
3439 (void) SyncImageSettings(image_info,*image);
3440 unique_image=UniqueImageColors(*image,exception);
3441 if (unique_image == (Image *) NULL)
3442 break;
3443 *image=DestroyImage(*image);
3444 *image=unique_image;
3445 break;
3446 }
3447 if (LocaleCompare("unsharp",option+1) == 0)
3448 {
3449 Image
3450 *unsharp_image;
3451
3452 /*
3453 Unsharp mask image.
3454 */
3455 (void) SyncImageSettings(image_info,*image);
3456 flags=ParseGeometry(argv[i+1],&geometry_info);
3457 if ((flags & SigmaValue) == 0)
3458 geometry_info.sigma=1.0;
3459 if ((flags & XiValue) == 0)
3460 geometry_info.xi=1.0;
3461 if ((flags & PsiValue) == 0)
3462 geometry_info.psi=0.05;
3463 unsharp_image=UnsharpMaskImageChannel(*image,channel,
3464 geometry_info.rho,geometry_info.sigma,geometry_info.xi,
3465 geometry_info.psi,exception);
3466 if (unsharp_image == (Image *) NULL)
3467 break;
3468 *image=DestroyImage(*image);
3469 *image=unsharp_image;
3470 break;
3471 }
3472 break;
3473 }
3474 case 'v':
3475 {
3476 if (LocaleCompare("verbose",option+1) == 0)
3477 {
3478 (void) SetImageArtifact(*image,option+1,
3479 *option == '+' ? "false" : "true");
3480 break;
3481 }
3482 if (LocaleCompare("vignette",option+1) == 0)
3483 {
3484 Image
3485 *vignette_image;
3486
3487 /*
3488 Vignette image.
3489 */
3490 (void) SyncImageSettings(image_info,*image);
3491 flags=ParseGeometry(argv[i+1],&geometry_info);
3492 if ((flags & SigmaValue) == 0)
3493 geometry_info.sigma=1.0;
3494 if ((flags & XiValue) == 0)
3495 geometry_info.xi=0.1*(*image)->columns;
3496 if ((flags & PsiValue) == 0)
3497 geometry_info.psi=0.1*(*image)->rows;
3498 vignette_image=VignetteImage(*image,geometry_info.rho,
3499 geometry_info.sigma,(long) (geometry_info.xi+0.5),(long)
3500 (geometry_info.psi+0.5),exception);
3501 if (vignette_image == (Image *) NULL)
3502 break;
3503 *image=DestroyImage(*image);
3504 *image=vignette_image;
3505 break;
3506 }
3507 if (LocaleCompare("virtual-pixel",option+1) == 0)
3508 {
3509 if (*option == '+')
3510 {
3511 (void) SetImageVirtualPixelMethod(*image,
3512 UndefinedVirtualPixelMethod);
3513 break;
3514 }
3515 (void) SetImageVirtualPixelMethod(*image,(VirtualPixelMethod)
3516 ParseMagickOption(MagickVirtualPixelOptions,MagickFalse,
3517 argv[i+1]));
3518 break;
3519 }
3520 break;
3521 }
3522 case 'w':
3523 {
3524 if (LocaleCompare("wave",option+1) == 0)
3525 {
3526 Image
3527 *wave_image;
3528
3529 /*
3530 Wave image.
3531 */
3532 (void) SyncImageSettings(image_info,*image);
3533 flags=ParseGeometry(argv[i+1],&geometry_info);
3534 if ((flags & SigmaValue) == 0)
3535 geometry_info.sigma=1.0;
3536 wave_image=WaveImage(*image,geometry_info.rho,geometry_info.sigma,
3537 exception);
3538 if (wave_image == (Image *) NULL)
3539 break;
3540 *image=DestroyImage(*image);
3541 *image=wave_image;
3542 break;
3543 }
3544 if (LocaleCompare("weight",option+1) == 0)
3545 {
cristye27293e2009-12-18 02:53:20 +00003546 draw_info->weight=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00003547 if (LocaleCompare(argv[i+1],"all") == 0)
3548 draw_info->weight=0;
3549 if (LocaleCompare(argv[i+1],"bold") == 0)
3550 draw_info->weight=700;
3551 if (LocaleCompare(argv[i+1],"bolder") == 0)
3552 if (draw_info->weight <= 800)
3553 draw_info->weight+=100;
3554 if (LocaleCompare(argv[i+1],"lighter") == 0)
3555 if (draw_info->weight >= 100)
3556 draw_info->weight-=100;
3557 if (LocaleCompare(argv[i+1],"normal") == 0)
3558 draw_info->weight=400;
3559 break;
3560 }
3561 if (LocaleCompare("white-threshold",option+1) == 0)
3562 {
3563 /*
3564 White threshold image.
3565 */
3566 (void) SyncImageSettings(image_info,*image);
3567 (void) WhiteThresholdImageChannel(*image,channel,argv[i+1],
3568 exception);
3569 InheritException(exception,&(*image)->exception);
3570 break;
3571 }
3572 break;
3573 }
3574 default:
3575 break;
3576 }
3577 i+=count;
3578 }
3579 if (region_image != (Image *) NULL)
3580 {
3581 /*
3582 Composite transformed region onto image.
3583 */
3584 (void) SyncImageSettings(image_info,*image);
3585 (void) CompositeImage(region_image,(*image)->matte != MagickFalse ?
3586 OverCompositeOp : CopyCompositeOp,*image,region_geometry.x,
3587 region_geometry.y);
3588 InheritException(exception,&region_image->exception);
3589 *image=DestroyImage(*image);
3590 *image=region_image;
3591 }
3592 /*
3593 Free resources.
3594 */
3595 quantize_info=DestroyQuantizeInfo(quantize_info);
3596 draw_info=DestroyDrawInfo(draw_info);
3597 status=(*image)->exception.severity == UndefinedException ?
3598 MagickTrue : MagickFalse;
3599 return(status);
3600}
3601
3602/*
3603%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3604% %
3605% %
3606% %
3607% M o g r i f y I m a g e C o m m a n d %
3608% %
3609% %
3610% %
3611%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3612%
3613% MogrifyImageCommand() transforms an image or a sequence of images. These
3614% transforms include image scaling, image rotation, color reduction, and
3615% others. The transmogrified image overwrites the original image.
3616%
3617% The format of the MogrifyImageCommand method is:
3618%
3619% MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,int argc,
3620% const char **argv,char **metadata,ExceptionInfo *exception)
3621%
3622% A description of each parameter follows:
3623%
3624% o image_info: the image info.
3625%
3626% o argc: the number of elements in the argument vector.
3627%
3628% o argv: A text array containing the command line arguments.
3629%
3630% o metadata: any metadata is returned here.
3631%
3632% o exception: return any errors or warnings in this structure.
3633%
3634*/
3635
3636static MagickBooleanType MogrifyUsage(void)
3637{
3638 static const char
3639 *miscellaneous[]=
3640 {
3641 "-debug events display copious debugging information",
3642 "-help print program options",
3643 "-list type print a list of supported option arguments",
3644 "-log format format of debugging information",
3645 "-version print version information",
3646 (char *) NULL
3647 },
3648 *operators[]=
3649 {
3650 "-adaptive-blur geometry",
3651 " adaptively blur pixels; decrease effect near edges",
3652 "-adaptive-resize geometry",
3653 " adaptively resize image using 'mesh' interpolation",
3654 "-adaptive-sharpen geometry",
3655 " adaptively sharpen pixels; increase effect near edges",
3656 "-alpha option on, activate, off, deactivate, set, opaque, copy",
3657 " transparent, extract, background, or shape",
3658 "-annotate geometry text",
3659 " annotate the image with text",
3660 "-auto-gamma automagically adjust gamma level of image",
3661 "-auto-level automagically adjust color levels of image",
3662 "-auto-orient automagically orient (rotate) image",
3663 "-bench iterations measure performance",
3664 "-black-threshold value",
3665 " force all pixels below the threshold into black",
3666 "-blue-shift simulate a scene at nighttime in the moonlight",
3667 "-blur geometry reduce image noise and reduce detail levels",
3668 "-border geometry surround image with a border of color",
3669 "-bordercolor color border color",
cristya28d6b82010-01-11 20:03:47 +00003670 "-brightness-contrast geometry",
3671 " improve brightness / contrast of the image",
cristy3ed852e2009-09-05 21:47:34 +00003672 "-cdl filename color correct with a color decision list",
3673 "-charcoal radius simulate a charcoal drawing",
3674 "-chop geometry remove pixels from the image interior",
cristyecb0c6d2009-09-25 16:50:09 +00003675 "-clamp restrict pixel range from 0 to the quantum depth",
cristy3ed852e2009-09-05 21:47:34 +00003676 "-clip clip along the first path from the 8BIM profile",
3677 "-clip-mask filename associate a clip mask with the image",
3678 "-clip-path id clip along a named path from the 8BIM profile",
3679 "-colorize value colorize the image with the fill color",
3680 "-contrast enhance or reduce the image contrast",
3681 "-contrast-stretch geometry",
3682 " improve contrast by `stretching' the intensity range",
3683 "-convolve coefficients",
3684 " apply a convolution kernel to the image",
3685 "-cycle amount cycle the image colormap",
3686 "-decipher filename convert cipher pixels to plain pixels",
3687 "-deskew threshold straighten an image",
3688 "-despeckle reduce the speckles within an image",
3689 "-distort method args",
3690 " distort images according to given method ad args",
3691 "-draw string annotate the image with a graphic primitive",
3692 "-edge radius apply a filter to detect edges in the image",
3693 "-encipher filename convert plain pixels to cipher pixels",
3694 "-emboss radius emboss an image",
3695 "-enhance apply a digital filter to enhance a noisy image",
3696 "-equalize perform histogram equalization to an image",
3697 "-evaluate operator value",
3698 " evaluate an expression over image values",
3699 "-extent geometry set the image size",
3700 "-extract geometry extract area from image",
3701 "-fft implements the discrete Fourier transform (DFT)",
3702 "-flip flip image vertically",
3703 "-floodfill geometry color",
3704 " floodfill the image with color",
3705 "-flop flop image horizontally",
3706 "-frame geometry surround image with an ornamental border",
cristyc2b730e2009-11-24 14:32:09 +00003707 "-function name parameters",
cristy3ed852e2009-09-05 21:47:34 +00003708 " apply function over image values",
3709 "-gamma value level of gamma correction",
3710 "-gaussian-blur geometry",
3711 " reduce image noise and reduce detail levels",
cristy901f09d2009-10-16 22:56:10 +00003712 "-geometry geometry preferred size or location of the image",
cristy3ed852e2009-09-05 21:47:34 +00003713 "-identify identify the format and characteristics of the image",
3714 "-ift implements the inverse discrete Fourier transform (DFT)",
3715 "-implode amount implode image pixels about the center",
3716 "-lat geometry local adaptive thresholding",
3717 "-layers method optimize, merge, or compare image layers",
3718 "-level value adjust the level of image contrast",
3719 "-level-colors color,color",
cristyee0f8d72009-09-19 00:58:29 +00003720 " level image with the given colors",
cristy3ed852e2009-09-05 21:47:34 +00003721 "-linear-stretch geometry",
3722 " improve contrast by `stretching with saturation'",
3723 "-liquid-rescale geometry",
3724 " rescale image with seam-carving",
3725 "-median radius apply a median filter to the image",
3726 "-modulate value vary the brightness, saturation, and hue",
3727 "-monochrome transform image to black and white",
cristy7c1b9fd2010-02-02 14:36:00 +00003728 "-morphology method kernel",
anthony29188a82010-01-22 10:12:34 +00003729 " apply a morphology method to the image",
cristy3ed852e2009-09-05 21:47:34 +00003730 "-motion-blur geometry",
3731 " simulate motion blur",
3732 "-negate replace every pixel with its complementary color ",
3733 "-noise radius add or reduce noise in an image",
3734 "-normalize transform image to span the full range of colors",
3735 "-opaque color change this color to the fill color",
3736 "-ordered-dither NxN",
3737 " add a noise pattern to the image with specific",
3738 " amplitudes",
3739 "-paint radius simulate an oil painting",
3740 "-polaroid angle simulate a Polaroid picture",
3741 "-posterize levels reduce the image to a limited number of color levels",
3742 "-print string interpret string and print to console",
3743 "-profile filename add, delete, or apply an image profile",
3744 "-quantize colorspace reduce colors in this colorspace",
3745 "-radial-blur angle radial blur the image",
3746 "-raise value lighten/darken image edges to create a 3-D effect",
3747 "-random-threshold low,high",
3748 " random threshold the image",
3749 "-recolor matrix translate, scale, shear, or rotate image colors",
3750 "-region geometry apply options to a portion of the image",
3751 "-render render vector graphics",
3752 "-repage geometry size and location of an image canvas",
3753 "-resample geometry change the resolution of an image",
3754 "-resize geometry resize the image",
3755 "-roll geometry roll an image vertically or horizontally",
3756 "-rotate degrees apply Paeth rotation to the image",
3757 "-sample geometry scale image with pixel sampling",
3758 "-scale geometry scale the image",
3759 "-segment values segment an image",
3760 "-selective-blur geometry",
3761 " selectively blur pixels within a contrast threshold",
3762 "-sepia-tone threshold",
3763 " simulate a sepia-toned photo",
3764 "-set property value set an image property",
3765 "-shade degrees shade the image using a distant light source",
3766 "-shadow geometry simulate an image shadow",
3767 "-sharpen geometry sharpen the image",
3768 "-shave geometry shave pixels from the image edges",
3769 "-shear geometry slide one edge of the image along the X or Y axis",
3770 "-sigmoidal-contrast geometry",
3771 " increase the contrast without saturating highlights or shadows",
3772 "-sketch geometry simulate a pencil sketch",
3773 "-solarize threshold negate all pixels above the threshold level",
3774 "-sparse-color method args",
3775 " fill in a image based on a few color points",
3776 "-splice geometry splice the background color into the image",
3777 "-spread radius displace image pixels by a random amount",
3778 "-strip strip image of all profiles and comments",
3779 "-swirl degrees swirl image pixels about the center",
3780 "-threshold value threshold the image",
3781 "-thumbnail geometry create a thumbnail of the image",
3782 "-tile filename tile image when filling a graphic primitive",
3783 "-tint value tint the image with the fill color",
3784 "-transform affine transform image",
3785 "-transparent color make this color transparent within the image",
3786 "-transpose flip image vertically and rotate 90 degrees",
3787 "-transverse flop image horizontally and rotate 270 degrees",
3788 "-trim trim image edges",
3789 "-type type image type",
3790 "-unique-colors discard all but one of any pixel color",
3791 "-unsharp geometry sharpen the image",
3792 "-vignette geometry soften the edges of the image in vignette style",
3793 "-wave geometry alter an image along a sine wave",
3794 "-white-threshold value",
3795 " force all pixels above the threshold into white",
3796 (char *) NULL
3797 },
3798 *sequence_operators[]=
3799 {
3800 "-append append an image sequence",
3801 "-average average an image sequence",
3802 "-clut apply a color lookup table to the image",
3803 "-coalesce merge a sequence of images",
3804 "-combine combine a sequence of images",
3805 "-composite composite image",
3806 "-crop geometry cut out a rectangular region of the image",
3807 "-deconstruct break down an image sequence into constituent parts",
3808 "-flatten flatten a sequence of images",
3809 "-fx expression apply mathematical expression to an image channel(s)",
3810 "-hald-clut apply a Hald color lookup table to the image",
cristyf40785b2010-03-06 02:27:27 +00003811 "-maximum return the maximum intensity of an image sequence",
3812 "-minimum return the minimum intensity of an image sequence",
cristy3ed852e2009-09-05 21:47:34 +00003813 "-morph value morph an image sequence",
3814 "-mosaic create a mosaic from an image sequence",
3815 "-process arguments process the image with a custom image filter",
3816 "-reverse reverse image sequence",
3817 "-separate separate an image channel into a grayscale image",
3818 "-write filename write images to this file",
3819 (char *) NULL
3820 },
3821 *settings[]=
3822 {
3823 "-adjoin join images into a single multi-image file",
3824 "-affine matrix affine transform matrix",
3825 "-alpha option activate, deactivate, reset, or set the alpha channel",
3826 "-antialias remove pixel-aliasing",
3827 "-authenticate password",
3828 " decipher image with this password",
3829 "-attenuate value lessen (or intensify) when adding noise to an image",
3830 "-background color background color",
3831 "-bias value add bias when convolving an image",
3832 "-black-point-compensation",
3833 " use black point compensation",
3834 "-blue-primary point chromaticity blue primary point",
3835 "-bordercolor color border color",
3836 "-caption string assign a caption to an image",
3837 "-channel type apply option to select image channels",
3838 "-colors value preferred number of colors in the image",
3839 "-colorspace type alternate image colorspace",
3840 "-comment string annotate image with comment",
3841 "-compose operator set image composite operator",
3842 "-compress type type of pixel compression when writing the image",
3843 "-define format:option",
3844 " define one or more image format options",
3845 "-delay value display the next image after pausing",
3846 "-density geometry horizontal and vertical density of the image",
3847 "-depth value image depth",
3848 "-display server get image or font from this X server",
3849 "-dispose method layer disposal method",
3850 "-dither method apply error diffusion to image",
3851 "-encoding type text encoding type",
3852 "-endian type endianness (MSB or LSB) of the image",
3853 "-family name render text with this font family",
3854 "-fill color color to use when filling a graphic primitive",
3855 "-filter type use this filter when resizing an image",
3856 "-font name render text with this font",
3857 "-format \"string\" output formatted image characteristics",
3858 "-fuzz distance colors within this distance are considered equal",
3859 "-gravity type horizontal and vertical text placement",
3860 "-green-primary point chromaticity green primary point",
3861 "-intent type type of rendering intent when managing the image color",
3862 "-interlace type type of image interlacing scheme",
cristyb32b90a2009-09-07 21:45:48 +00003863 "-interline-spacing value",
3864 " set the space between two text lines",
cristy3ed852e2009-09-05 21:47:34 +00003865 "-interpolate method pixel color interpolation method",
3866 "-interword-spacing value",
3867 " set the space between two words",
3868 "-kerning value set the space between two letters",
3869 "-label string assign a label to an image",
3870 "-limit type value pixel cache resource limit",
3871 "-loop iterations add Netscape loop extension to your GIF animation",
3872 "-mask filename associate a mask with the image",
3873 "-mattecolor color frame color",
3874 "-monitor monitor progress",
3875 "-orient type image orientation",
3876 "-page geometry size and location of an image canvas (setting)",
3877 "-ping efficiently determine image attributes",
3878 "-pointsize value font point size",
cristy7c1b9fd2010-02-02 14:36:00 +00003879 "-precision value maximum number of significant digits to print",
cristy3ed852e2009-09-05 21:47:34 +00003880 "-preview type image preview type",
3881 "-quality value JPEG/MIFF/PNG compression level",
3882 "-quiet suppress all warning messages",
3883 "-red-primary point chromaticity red primary point",
3884 "-regard-warnings pay attention to warning messages",
3885 "-remap filename transform image colors to match this set of colors",
3886 "-respect-parentheses settings remain in effect until parenthesis boundary",
3887 "-sampling-factor geometry",
3888 " horizontal and vertical sampling factor",
3889 "-scene value image scene number",
3890 "-seed value seed a new sequence of pseudo-random numbers",
3891 "-size geometry width and height of image",
3892 "-stretch type render text with this font stretch",
3893 "-stroke color graphic primitive stroke color",
3894 "-strokewidth value graphic primitive stroke width",
3895 "-style type render text with this font style",
3896 "-taint image as ineligible for bi-modal delegate",
3897 "-texture filename name of texture to tile onto the image background",
3898 "-tile-offset geometry",
3899 " tile offset",
3900 "-treedepth value color tree depth",
3901 "-transparent-color color",
3902 " transparent color",
3903 "-undercolor color annotation bounding box color",
3904 "-units type the units of image resolution",
3905 "-verbose print detailed information about the image",
3906 "-view FlashPix viewing transforms",
3907 "-virtual-pixel method",
3908 " virtual pixel access method",
3909 "-weight type render text with this font weight",
3910 "-white-point point chromaticity white point",
3911 (char *) NULL
3912 },
3913 *stack_operators[]=
3914 {
3915 "-clone index clone an image",
3916 "-delete index delete the image from the image sequence",
3917 "-insert index insert last image into the image sequence",
3918 "-swap indexes swap two images in the image sequence",
3919 (char *) NULL
3920 };
3921
3922 const char
3923 **p;
3924
3925 (void) printf("Version: %s\n",GetMagickVersion((unsigned long *) NULL));
cristy610b2e22009-10-22 14:59:43 +00003926 (void) printf("Copyright: %s\n",GetMagickCopyright());
3927 (void) printf("Features: %s\n\n",GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00003928 (void) printf("Usage: %s [options ...] file [ [options ...] file ...]\n",
3929 GetClientName());
3930 (void) printf("\nImage Settings:\n");
3931 for (p=settings; *p != (char *) NULL; p++)
3932 (void) printf(" %s\n",*p);
3933 (void) printf("\nImage Operators:\n");
3934 for (p=operators; *p != (char *) NULL; p++)
3935 (void) printf(" %s\n",*p);
3936 (void) printf("\nImage Sequence Operators:\n");
3937 for (p=sequence_operators; *p != (char *) NULL; p++)
3938 (void) printf(" %s\n",*p);
3939 (void) printf("\nImage Stack Operators:\n");
3940 for (p=stack_operators; *p != (char *) NULL; p++)
3941 (void) printf(" %s\n",*p);
3942 (void) printf("\nMiscellaneous Options:\n");
3943 for (p=miscellaneous; *p != (char *) NULL; p++)
3944 (void) printf(" %s\n",*p);
3945 (void) printf(
3946 "\nBy default, the image format of `file' is determined by its magic\n");
3947 (void) printf(
3948 "number. To specify a particular image format, precede the filename\n");
3949 (void) printf(
3950 "with an image format name and a colon (i.e. ps:image) or specify the\n");
3951 (void) printf(
3952 "image type as the filename suffix (i.e. image.ps). Specify 'file' as\n");
3953 (void) printf("'-' for standard input or output.\n");
3954 return(MagickFalse);
3955}
3956
3957WandExport MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,
3958 int argc,char **argv,char **wand_unused(metadata),ExceptionInfo *exception)
3959{
3960#define DestroyMogrify() \
3961{ \
3962 if (format != (char *) NULL) \
3963 format=DestroyString(format); \
3964 if (path != (char *) NULL) \
3965 path=DestroyString(path); \
3966 DestroyImageStack(); \
3967 for (i=0; i < (long) argc; i++) \
3968 argv[i]=DestroyString(argv[i]); \
3969 argv=(char **) RelinquishMagickMemory(argv); \
3970}
3971#define ThrowMogrifyException(asperity,tag,option) \
3972{ \
3973 (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag,"`%s'", \
3974 option); \
3975 DestroyMogrify(); \
3976 return(MagickFalse); \
3977}
3978#define ThrowMogrifyInvalidArgumentException(option,argument) \
3979{ \
3980 (void) ThrowMagickException(exception,GetMagickModule(),OptionError, \
3981 "InvalidArgument","`%s': %s",argument,option); \
3982 DestroyMogrify(); \
3983 return(MagickFalse); \
3984}
3985
3986 char
3987 *format,
3988 *option,
3989 *path;
3990
3991 Image
3992 *image;
3993
3994 ImageStack
3995 image_stack[MaxImageStackDepth+1];
3996
3997 long
3998 j,
3999 k;
4000
4001 register long
4002 i;
4003
4004 MagickBooleanType
4005 global_colormap;
4006
4007 MagickBooleanType
4008 fire,
4009 pend;
4010
4011 MagickStatusType
4012 status;
4013
4014 /*
4015 Set defaults.
4016 */
4017 assert(image_info != (ImageInfo *) NULL);
4018 assert(image_info->signature == MagickSignature);
4019 if (image_info->debug != MagickFalse)
4020 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
4021 assert(exception != (ExceptionInfo *) NULL);
4022 if (argc == 2)
4023 {
4024 option=argv[1];
4025 if ((LocaleCompare("version",option+1) == 0) ||
4026 (LocaleCompare("-version",option+1) == 0))
4027 {
4028 (void) fprintf(stdout,"Version: %s\n",
4029 GetMagickVersion((unsigned long *) NULL));
cristy610b2e22009-10-22 14:59:43 +00004030 (void) fprintf(stdout,"Copyright: %s\n",GetMagickCopyright());
4031 (void) fprintf(stdout,"Features: %s\n\n",GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00004032 return(MagickFalse);
4033 }
4034 }
4035 if (argc < 2)
cristy13e61a12010-02-04 20:19:00 +00004036 return(MogrifyUsage());
cristy3ed852e2009-09-05 21:47:34 +00004037 format=(char *) NULL;
4038 path=(char *) NULL;
4039 global_colormap=MagickFalse;
4040 k=0;
4041 j=1;
4042 NewImageStack();
4043 option=(char *) NULL;
4044 pend=MagickFalse;
4045 status=MagickTrue;
4046 /*
4047 Parse command line.
4048 */
4049 ReadCommandlLine(argc,&argv);
4050 status=ExpandFilenames(&argc,&argv);
4051 if (status == MagickFalse)
4052 ThrowMogrifyException(ResourceLimitError,"MemoryAllocationFailed",
4053 GetExceptionMessage(errno));
4054 for (i=1; i < (long) argc; i++)
4055 {
4056 option=argv[i];
4057 if (LocaleCompare(option,"(") == 0)
4058 {
4059 FireImageStack(MagickFalse,MagickTrue,pend);
4060 if (k == MaxImageStackDepth)
4061 ThrowMogrifyException(OptionError,"ParenthesisNestedTooDeeply",
4062 option);
4063 PushImageStack();
4064 continue;
4065 }
4066 if (LocaleCompare(option,")") == 0)
4067 {
4068 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
4069 if (k == 0)
4070 ThrowMogrifyException(OptionError,"UnableToParseExpression",option);
4071 PopImageStack();
4072 continue;
4073 }
4074 if (IsMagickOption(option) == MagickFalse)
4075 {
4076 char
4077 backup_filename[MaxTextExtent],
4078 *filename;
4079
4080 Image
4081 *images;
4082
4083 /*
4084 Option is a file name: begin by reading image from specified file.
4085 */
4086 FireImageStack(MagickFalse,MagickFalse,pend);
4087 filename=argv[i];
4088 if ((LocaleCompare(filename,"--") == 0) && (i < (argc-1)))
4089 filename=argv[++i];
4090 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
4091 images=ReadImages(image_info,exception);
4092 status&=(images != (Image *) NULL) &&
4093 (exception->severity < ErrorException);
4094 if (images == (Image *) NULL)
4095 continue;
4096 if (path != (char *) NULL)
4097 {
4098 GetPathComponent(option,TailPath,filename);
4099 (void) FormatMagickString(images->filename,MaxTextExtent,"%s%c%s",
4100 path,*DirectorySeparator,filename);
4101 }
4102 if (format != (char *) NULL)
4103 AppendImageFormat(format,images->filename);
4104 AppendImageStack(images);
4105 FinalizeImageSettings(image_info,image,MagickFalse);
4106 if (global_colormap != MagickFalse)
4107 {
4108 QuantizeInfo
4109 *quantize_info;
4110
4111 quantize_info=AcquireQuantizeInfo(image_info);
4112 (void) RemapImages(quantize_info,images,(Image *) NULL);
4113 quantize_info=DestroyQuantizeInfo(quantize_info);
4114 }
4115 *backup_filename='\0';
4116 if ((LocaleCompare(image->filename,"-") != 0) &&
4117 (IsPathWritable(image->filename) != MagickFalse))
4118 {
4119 register long
4120 i;
4121
4122 /*
4123 Rename image file as backup.
4124 */
4125 (void) CopyMagickString(backup_filename,image->filename,
4126 MaxTextExtent);
4127 for (i=0; i < 6; i++)
4128 {
4129 (void) ConcatenateMagickString(backup_filename,"~",MaxTextExtent);
4130 if (IsPathAccessible(backup_filename) == MagickFalse)
4131 break;
4132 }
4133 if ((IsPathAccessible(backup_filename) != MagickFalse) ||
4134 (rename(image->filename,backup_filename) != 0))
4135 *backup_filename='\0';
4136 }
4137 /*
4138 Write transmogrified image to disk.
4139 */
4140 image_info->synchronize=MagickTrue;
4141 status&=WriteImages(image_info,image,image->filename,exception);
4142 if ((status == MagickFalse) && (*backup_filename != '\0'))
4143 (void) remove(backup_filename);
4144 RemoveAllImageStack();
4145 continue;
4146 }
4147 pend=image != (Image *) NULL ? MagickTrue : MagickFalse;
4148 switch (*(option+1))
4149 {
4150 case 'a':
4151 {
4152 if (LocaleCompare("adaptive-blur",option+1) == 0)
4153 {
4154 i++;
4155 if (i == (long) argc)
4156 ThrowMogrifyException(OptionError,"MissingArgument",option);
4157 if (IsGeometry(argv[i]) == MagickFalse)
4158 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4159 break;
4160 }
4161 if (LocaleCompare("adaptive-resize",option+1) == 0)
4162 {
4163 i++;
4164 if (i == (long) argc)
4165 ThrowMogrifyException(OptionError,"MissingArgument",option);
4166 if (IsGeometry(argv[i]) == MagickFalse)
4167 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4168 break;
4169 }
4170 if (LocaleCompare("adaptive-sharpen",option+1) == 0)
4171 {
4172 i++;
4173 if (i == (long) argc)
4174 ThrowMogrifyException(OptionError,"MissingArgument",option);
4175 if (IsGeometry(argv[i]) == MagickFalse)
4176 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4177 break;
4178 }
4179 if (LocaleCompare("affine",option+1) == 0)
4180 {
4181 if (*option == '+')
4182 break;
4183 i++;
4184 if (i == (long) argc)
4185 ThrowMogrifyException(OptionError,"MissingArgument",option);
4186 if (IsGeometry(argv[i]) == MagickFalse)
4187 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4188 break;
4189 }
4190 if (LocaleCompare("alpha",option+1) == 0)
4191 {
4192 long
4193 type;
4194
4195 if (*option == '+')
4196 break;
4197 i++;
4198 if (i == (long) argc)
4199 ThrowMogrifyException(OptionError,"MissingArgument",option);
4200 type=ParseMagickOption(MagickAlphaOptions,MagickFalse,argv[i]);
4201 if (type < 0)
4202 ThrowMogrifyException(OptionError,"UnrecognizedAlphaChannelType",
4203 argv[i]);
4204 break;
4205 }
4206 if (LocaleCompare("annotate",option+1) == 0)
4207 {
4208 if (*option == '+')
4209 break;
4210 i++;
4211 if (i == (long) argc)
4212 ThrowMogrifyException(OptionError,"MissingArgument",option);
4213 if (IsGeometry(argv[i]) == MagickFalse)
4214 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4215 if (i == (long) argc)
4216 ThrowMogrifyException(OptionError,"MissingArgument",option);
4217 i++;
4218 break;
4219 }
4220 if (LocaleCompare("antialias",option+1) == 0)
4221 break;
4222 if (LocaleCompare("append",option+1) == 0)
4223 break;
4224 if (LocaleCompare("attenuate",option+1) == 0)
4225 {
4226 if (*option == '+')
4227 break;
4228 i++;
4229 if (i == (long) (argc-1))
4230 ThrowMogrifyException(OptionError,"MissingArgument",option);
4231 if (IsGeometry(argv[i]) == MagickFalse)
4232 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4233 break;
4234 }
4235 if (LocaleCompare("authenticate",option+1) == 0)
4236 {
4237 if (*option == '+')
4238 break;
4239 i++;
4240 if (i == (long) argc)
4241 ThrowMogrifyException(OptionError,"MissingArgument",option);
4242 break;
4243 }
4244 if (LocaleCompare("auto-gamma",option+1) == 0)
4245 break;
4246 if (LocaleCompare("auto-level",option+1) == 0)
4247 break;
4248 if (LocaleCompare("auto-orient",option+1) == 0)
4249 break;
4250 if (LocaleCompare("average",option+1) == 0)
4251 break;
4252 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4253 }
4254 case 'b':
4255 {
4256 if (LocaleCompare("background",option+1) == 0)
4257 {
4258 if (*option == '+')
4259 break;
4260 i++;
4261 if (i == (long) argc)
4262 ThrowMogrifyException(OptionError,"MissingArgument",option);
4263 break;
4264 }
4265 if (LocaleCompare("bias",option+1) == 0)
4266 {
4267 if (*option == '+')
4268 break;
4269 i++;
4270 if (i == (long) (argc-1))
4271 ThrowMogrifyException(OptionError,"MissingArgument",option);
4272 if (IsGeometry(argv[i]) == MagickFalse)
4273 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4274 break;
4275 }
4276 if (LocaleCompare("black-point-compensation",option+1) == 0)
4277 break;
4278 if (LocaleCompare("black-threshold",option+1) == 0)
4279 {
4280 if (*option == '+')
4281 break;
4282 i++;
4283 if (i == (long) argc)
4284 ThrowMogrifyException(OptionError,"MissingArgument",option);
4285 if (IsGeometry(argv[i]) == MagickFalse)
4286 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4287 break;
4288 }
4289 if (LocaleCompare("blue-primary",option+1) == 0)
4290 {
4291 if (*option == '+')
4292 break;
4293 i++;
4294 if (i == (long) argc)
4295 ThrowMogrifyException(OptionError,"MissingArgument",option);
4296 if (IsGeometry(argv[i]) == MagickFalse)
4297 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4298 break;
4299 }
4300 if (LocaleCompare("blue-shift",option+1) == 0)
4301 {
4302 i++;
4303 if (i == (long) argc)
4304 ThrowMogrifyException(OptionError,"MissingArgument",option);
4305 if (IsGeometry(argv[i]) == MagickFalse)
4306 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4307 break;
4308 }
4309 if (LocaleCompare("blur",option+1) == 0)
4310 {
4311 i++;
4312 if (i == (long) argc)
4313 ThrowMogrifyException(OptionError,"MissingArgument",option);
4314 if (IsGeometry(argv[i]) == MagickFalse)
4315 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4316 break;
4317 }
4318 if (LocaleCompare("border",option+1) == 0)
4319 {
4320 if (*option == '+')
4321 break;
4322 i++;
4323 if (i == (long) argc)
4324 ThrowMogrifyException(OptionError,"MissingArgument",option);
4325 if (IsGeometry(argv[i]) == MagickFalse)
4326 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4327 break;
4328 }
4329 if (LocaleCompare("bordercolor",option+1) == 0)
4330 {
4331 if (*option == '+')
4332 break;
4333 i++;
4334 if (i == (long) argc)
4335 ThrowMogrifyException(OptionError,"MissingArgument",option);
4336 break;
4337 }
4338 if (LocaleCompare("box",option+1) == 0)
4339 {
4340 if (*option == '+')
4341 break;
4342 i++;
4343 if (i == (long) argc)
4344 ThrowMogrifyException(OptionError,"MissingArgument",option);
4345 break;
4346 }
cristya28d6b82010-01-11 20:03:47 +00004347 if (LocaleCompare("brightness-contrast",option+1) == 0)
4348 {
4349 i++;
4350 if (i == (long) argc)
4351 ThrowMogrifyException(OptionError,"MissingArgument",option);
4352 if (IsGeometry(argv[i]) == MagickFalse)
4353 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4354 break;
4355 }
cristy3ed852e2009-09-05 21:47:34 +00004356 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4357 }
4358 case 'c':
4359 {
4360 if (LocaleCompare("cache",option+1) == 0)
4361 {
4362 if (*option == '+')
4363 break;
4364 i++;
4365 if (i == (long) argc)
4366 ThrowMogrifyException(OptionError,"MissingArgument",option);
4367 if (IsGeometry(argv[i]) == MagickFalse)
4368 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4369 break;
4370 }
4371 if (LocaleCompare("caption",option+1) == 0)
4372 {
4373 if (*option == '+')
4374 break;
4375 i++;
4376 if (i == (long) argc)
4377 ThrowMogrifyException(OptionError,"MissingArgument",option);
4378 break;
4379 }
4380 if (LocaleCompare("channel",option+1) == 0)
4381 {
4382 long
4383 channel;
4384
4385 if (*option == '+')
4386 break;
4387 i++;
4388 if (i == (long) (argc-1))
4389 ThrowMogrifyException(OptionError,"MissingArgument",option);
4390 channel=ParseChannelOption(argv[i]);
4391 if (channel < 0)
4392 ThrowMogrifyException(OptionError,"UnrecognizedChannelType",
4393 argv[i]);
4394 break;
4395 }
4396 if (LocaleCompare("cdl",option+1) == 0)
4397 {
4398 if (*option == '+')
4399 break;
4400 i++;
4401 if (i == (long) (argc-1))
4402 ThrowMogrifyException(OptionError,"MissingArgument",option);
4403 break;
4404 }
4405 if (LocaleCompare("charcoal",option+1) == 0)
4406 {
4407 if (*option == '+')
4408 break;
4409 i++;
4410 if (i == (long) argc)
4411 ThrowMogrifyException(OptionError,"MissingArgument",option);
4412 if (IsGeometry(argv[i]) == MagickFalse)
4413 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4414 break;
4415 }
4416 if (LocaleCompare("chop",option+1) == 0)
4417 {
4418 if (*option == '+')
4419 break;
4420 i++;
4421 if (i == (long) argc)
4422 ThrowMogrifyException(OptionError,"MissingArgument",option);
4423 if (IsGeometry(argv[i]) == MagickFalse)
4424 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4425 break;
4426 }
cristy1eb45dd2009-09-25 16:38:06 +00004427 if (LocaleCompare("clamp",option+1) == 0)
4428 break;
4429 if (LocaleCompare("clip",option+1) == 0)
4430 break;
cristy3ed852e2009-09-05 21:47:34 +00004431 if (LocaleCompare("clip-mask",option+1) == 0)
4432 {
4433 if (*option == '+')
4434 break;
4435 i++;
4436 if (i == (long) argc)
4437 ThrowMogrifyException(OptionError,"MissingArgument",option);
4438 break;
4439 }
4440 if (LocaleCompare("clut",option+1) == 0)
4441 break;
4442 if (LocaleCompare("coalesce",option+1) == 0)
4443 break;
4444 if (LocaleCompare("colorize",option+1) == 0)
4445 {
4446 if (*option == '+')
4447 break;
4448 i++;
4449 if (i == (long) argc)
4450 ThrowMogrifyException(OptionError,"MissingArgument",option);
4451 if (IsGeometry(argv[i]) == MagickFalse)
4452 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4453 break;
4454 }
4455 if (LocaleCompare("colors",option+1) == 0)
4456 {
4457 if (*option == '+')
4458 break;
4459 i++;
4460 if (i == (long) argc)
4461 ThrowMogrifyException(OptionError,"MissingArgument",option);
4462 if (IsGeometry(argv[i]) == MagickFalse)
4463 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4464 break;
4465 }
4466 if (LocaleCompare("colorspace",option+1) == 0)
4467 {
4468 long
4469 colorspace;
4470
4471 if (*option == '+')
4472 break;
4473 i++;
4474 if (i == (long) argc)
4475 ThrowMogrifyException(OptionError,"MissingArgument",option);
4476 colorspace=ParseMagickOption(MagickColorspaceOptions,MagickFalse,
4477 argv[i]);
4478 if (colorspace < 0)
4479 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
4480 argv[i]);
4481 break;
4482 }
4483 if (LocaleCompare("combine",option+1) == 0)
4484 break;
4485 if (LocaleCompare("comment",option+1) == 0)
4486 {
4487 if (*option == '+')
4488 break;
4489 i++;
4490 if (i == (long) argc)
4491 ThrowMogrifyException(OptionError,"MissingArgument",option);
4492 break;
4493 }
4494 if (LocaleCompare("composite",option+1) == 0)
4495 break;
4496 if (LocaleCompare("compress",option+1) == 0)
4497 {
4498 long
4499 compress;
4500
4501 if (*option == '+')
4502 break;
4503 i++;
4504 if (i == (long) argc)
4505 ThrowMogrifyException(OptionError,"MissingArgument",option);
4506 compress=ParseMagickOption(MagickCompressOptions,MagickFalse,
4507 argv[i]);
4508 if (compress < 0)
4509 ThrowMogrifyException(OptionError,"UnrecognizedImageCompression",
4510 argv[i]);
4511 break;
4512 }
cristy22879752009-10-25 23:55:40 +00004513 if (LocaleCompare("concurrent",option+1) == 0)
4514 break;
cristy3ed852e2009-09-05 21:47:34 +00004515 if (LocaleCompare("contrast",option+1) == 0)
4516 break;
4517 if (LocaleCompare("contrast-stretch",option+1) == 0)
4518 {
4519 i++;
4520 if (i == (long) argc)
4521 ThrowMogrifyException(OptionError,"MissingArgument",option);
4522 if (IsGeometry(argv[i]) == MagickFalse)
4523 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4524 break;
4525 }
4526 if (LocaleCompare("convolve",option+1) == 0)
4527 {
anthony29188a82010-01-22 10:12:34 +00004528 char
4529 token[MaxTextExtent];
4530
cristy3ed852e2009-09-05 21:47:34 +00004531 if (*option == '+')
4532 break;
4533 i++;
4534 if (i == (long) argc)
4535 ThrowMogrifyException(OptionError,"MissingArgument",option);
anthony29188a82010-01-22 10:12:34 +00004536#if 1
cristy3ed852e2009-09-05 21:47:34 +00004537 if (IsGeometry(argv[i]) == MagickFalse)
4538 ThrowMogrifyInvalidArgumentException(option,argv[i]);
anthony29188a82010-01-22 10:12:34 +00004539#else
4540 /* Allow the use of built-in kernels like 'gaussian'
4541 * These may not work for kernels with 'nan' values, like 'diamond'
4542 */
4543 GetMagickToken(argv[i],NULL,token);
4544 if ( isalpha((int)token[0]) )
4545 {
4546 long
4547 op;
4548
4549 op=ParseMagickOption(MagickKernelOptions,MagickFalse,token);
4550 if (op < 0)
4551 ThrowMogrifyException(OptionError,"UnrecognizedKernelType",
4552 token);
4553 }
4554 /* geometry current returns invalid if 'nan' values are used */
4555 else if (IsGeometry(argv[i]) == MagickFalse)
4556 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4557#endif
cristy3ed852e2009-09-05 21:47:34 +00004558 break;
4559 }
4560 if (LocaleCompare("crop",option+1) == 0)
4561 {
4562 if (*option == '+')
4563 break;
4564 i++;
4565 if (i == (long) argc)
4566 ThrowMogrifyException(OptionError,"MissingArgument",option);
4567 if (IsGeometry(argv[i]) == MagickFalse)
4568 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4569 break;
4570 }
4571 if (LocaleCompare("cycle",option+1) == 0)
4572 {
4573 if (*option == '+')
4574 break;
4575 i++;
4576 if (i == (long) argc)
4577 ThrowMogrifyException(OptionError,"MissingArgument",option);
4578 if (IsGeometry(argv[i]) == MagickFalse)
4579 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4580 break;
4581 }
4582 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4583 }
4584 case 'd':
4585 {
4586 if (LocaleCompare("decipher",option+1) == 0)
4587 {
4588 if (*option == '+')
4589 break;
4590 i++;
4591 if (i == (long) (argc-1))
4592 ThrowMogrifyException(OptionError,"MissingArgument",option);
4593 break;
4594 }
4595 if (LocaleCompare("deconstruct",option+1) == 0)
4596 break;
4597 if (LocaleCompare("debug",option+1) == 0)
4598 {
4599 long
4600 event;
4601
4602 if (*option == '+')
4603 break;
4604 i++;
4605 if (i == (long) argc)
4606 ThrowMogrifyException(OptionError,"MissingArgument",option);
4607 event=ParseMagickOption(MagickLogEventOptions,MagickFalse,argv[i]);
4608 if (event < 0)
4609 ThrowMogrifyException(OptionError,"UnrecognizedEventType",
4610 argv[i]);
4611 (void) SetLogEventMask(argv[i]);
4612 break;
4613 }
4614 if (LocaleCompare("define",option+1) == 0)
4615 {
4616 i++;
4617 if (i == (long) argc)
4618 ThrowMogrifyException(OptionError,"MissingArgument",option);
4619 if (*option == '+')
4620 {
4621 const char
4622 *define;
4623
4624 define=GetImageOption(image_info,argv[i]);
4625 if (define == (const char *) NULL)
4626 ThrowMogrifyException(OptionError,"NoSuchOption",argv[i]);
4627 break;
4628 }
4629 break;
4630 }
4631 if (LocaleCompare("delay",option+1) == 0)
4632 {
4633 if (*option == '+')
4634 break;
4635 i++;
4636 if (i == (long) argc)
4637 ThrowMogrifyException(OptionError,"MissingArgument",option);
4638 if (IsGeometry(argv[i]) == MagickFalse)
4639 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4640 break;
4641 }
4642 if (LocaleCompare("density",option+1) == 0)
4643 {
4644 if (*option == '+')
4645 break;
4646 i++;
4647 if (i == (long) argc)
4648 ThrowMogrifyException(OptionError,"MissingArgument",option);
4649 if (IsGeometry(argv[i]) == MagickFalse)
4650 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4651 break;
4652 }
4653 if (LocaleCompare("depth",option+1) == 0)
4654 {
4655 if (*option == '+')
4656 break;
4657 i++;
4658 if (i == (long) argc)
4659 ThrowMogrifyException(OptionError,"MissingArgument",option);
4660 if (IsGeometry(argv[i]) == MagickFalse)
4661 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4662 break;
4663 }
4664 if (LocaleCompare("deskew",option+1) == 0)
4665 {
4666 if (*option == '+')
4667 break;
4668 i++;
4669 if (i == (long) argc)
4670 ThrowMogrifyException(OptionError,"MissingArgument",option);
4671 if (IsGeometry(argv[i]) == MagickFalse)
4672 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4673 break;
4674 }
4675 if (LocaleCompare("despeckle",option+1) == 0)
4676 break;
4677 if (LocaleCompare("dft",option+1) == 0)
4678 break;
4679 if (LocaleCompare("display",option+1) == 0)
4680 {
4681 if (*option == '+')
4682 break;
4683 i++;
4684 if (i == (long) argc)
4685 ThrowMogrifyException(OptionError,"MissingArgument",option);
4686 break;
4687 }
4688 if (LocaleCompare("dispose",option+1) == 0)
4689 {
4690 long
4691 dispose;
4692
4693 if (*option == '+')
4694 break;
4695 i++;
4696 if (i == (long) argc)
4697 ThrowMogrifyException(OptionError,"MissingArgument",option);
4698 dispose=ParseMagickOption(MagickDisposeOptions,MagickFalse,argv[i]);
4699 if (dispose < 0)
4700 ThrowMogrifyException(OptionError,"UnrecognizedDisposeMethod",
4701 argv[i]);
4702 break;
4703 }
4704 if (LocaleCompare("distort",option+1) == 0)
4705 {
4706 long
4707 op;
4708
4709 i++;
4710 if (i == (long) argc)
4711 ThrowMogrifyException(OptionError,"MissingArgument",option);
4712 op=ParseMagickOption(MagickDistortOptions,MagickFalse,argv[i]);
4713 if (op < 0)
4714 ThrowMogrifyException(OptionError,"UnrecognizedDistortMethod",
4715 argv[i]);
4716 i++;
4717 if (i == (long) (argc-1))
4718 ThrowMogrifyException(OptionError,"MissingArgument",option);
4719 break;
4720 }
4721 if (LocaleCompare("dither",option+1) == 0)
4722 {
4723 long
4724 method;
4725
4726 if (*option == '+')
4727 break;
4728 i++;
4729 if (i == (long) argc)
4730 ThrowMogrifyException(OptionError,"MissingArgument",option);
4731 method=ParseMagickOption(MagickDitherOptions,MagickFalse,argv[i]);
4732 if (method < 0)
4733 ThrowMogrifyException(OptionError,"UnrecognizedDitherMethod",
4734 argv[i]);
4735 break;
4736 }
4737 if (LocaleCompare("draw",option+1) == 0)
4738 {
4739 if (*option == '+')
4740 break;
4741 i++;
4742 if (i == (long) argc)
4743 ThrowMogrifyException(OptionError,"MissingArgument",option);
4744 break;
4745 }
cristy22879752009-10-25 23:55:40 +00004746 if (LocaleCompare("duration",option+1) == 0)
4747 {
4748 if (*option == '+')
4749 break;
4750 i++;
4751 if (i == (long) (argc-1))
4752 ThrowMogrifyException(OptionError,"MissingArgument",option);
4753 if (IsGeometry(argv[i]) == MagickFalse)
4754 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4755 break;
4756 }
cristy3ed852e2009-09-05 21:47:34 +00004757 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4758 }
4759 case 'e':
4760 {
4761 if (LocaleCompare("edge",option+1) == 0)
4762 {
4763 if (*option == '+')
4764 break;
4765 i++;
4766 if (i == (long) argc)
4767 ThrowMogrifyException(OptionError,"MissingArgument",option);
4768 if (IsGeometry(argv[i]) == MagickFalse)
4769 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4770 break;
4771 }
4772 if (LocaleCompare("emboss",option+1) == 0)
4773 {
4774 if (*option == '+')
4775 break;
4776 i++;
4777 if (i == (long) argc)
4778 ThrowMogrifyException(OptionError,"MissingArgument",option);
4779 if (IsGeometry(argv[i]) == MagickFalse)
4780 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4781 break;
4782 }
4783 if (LocaleCompare("encipher",option+1) == 0)
4784 {
4785 if (*option == '+')
4786 break;
4787 i++;
4788 if (i == (long) argc)
4789 ThrowMogrifyException(OptionError,"MissingArgument",option);
4790 break;
4791 }
4792 if (LocaleCompare("encoding",option+1) == 0)
4793 {
4794 if (*option == '+')
4795 break;
4796 i++;
4797 if (i == (long) argc)
4798 ThrowMogrifyException(OptionError,"MissingArgument",option);
4799 break;
4800 }
4801 if (LocaleCompare("endian",option+1) == 0)
4802 {
4803 long
4804 endian;
4805
4806 if (*option == '+')
4807 break;
4808 i++;
4809 if (i == (long) argc)
4810 ThrowMogrifyException(OptionError,"MissingArgument",option);
4811 endian=ParseMagickOption(MagickEndianOptions,MagickFalse,argv[i]);
4812 if (endian < 0)
4813 ThrowMogrifyException(OptionError,"UnrecognizedEndianType",
4814 argv[i]);
4815 break;
4816 }
4817 if (LocaleCompare("enhance",option+1) == 0)
4818 break;
4819 if (LocaleCompare("equalize",option+1) == 0)
4820 break;
4821 if (LocaleCompare("evaluate",option+1) == 0)
4822 {
4823 long
4824 op;
4825
4826 if (*option == '+')
4827 break;
4828 i++;
4829 if (i == (long) argc)
4830 ThrowMogrifyException(OptionError,"MissingArgument",option);
4831 op=ParseMagickOption(MagickEvaluateOptions,MagickFalse,argv[i]);
4832 if (op < 0)
4833 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4834 argv[i]);
4835 i++;
4836 if (i == (long) (argc-1))
4837 ThrowMogrifyException(OptionError,"MissingArgument",option);
4838 if (IsGeometry(argv[i]) == MagickFalse)
4839 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4840 break;
4841 }
4842 if (LocaleCompare("extent",option+1) == 0)
4843 {
4844 if (*option == '+')
4845 break;
4846 i++;
4847 if (i == (long) argc)
4848 ThrowMogrifyException(OptionError,"MissingArgument",option);
4849 if (IsGeometry(argv[i]) == MagickFalse)
4850 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4851 break;
4852 }
4853 if (LocaleCompare("extract",option+1) == 0)
4854 {
4855 if (*option == '+')
4856 break;
4857 i++;
4858 if (i == (long) argc)
4859 ThrowMogrifyException(OptionError,"MissingArgument",option);
4860 if (IsGeometry(argv[i]) == MagickFalse)
4861 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4862 break;
4863 }
4864 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4865 }
4866 case 'f':
4867 {
4868 if (LocaleCompare("family",option+1) == 0)
4869 {
4870 if (*option == '+')
4871 break;
4872 i++;
4873 if (i == (long) (argc-1))
4874 ThrowMogrifyException(OptionError,"MissingArgument",option);
4875 break;
4876 }
4877 if (LocaleCompare("fill",option+1) == 0)
4878 {
4879 if (*option == '+')
4880 break;
4881 i++;
4882 if (i == (long) argc)
4883 ThrowMogrifyException(OptionError,"MissingArgument",option);
4884 break;
4885 }
4886 if (LocaleCompare("filter",option+1) == 0)
4887 {
4888 long
4889 filter;
4890
4891 if (*option == '+')
4892 break;
4893 i++;
4894 if (i == (long) argc)
4895 ThrowMogrifyException(OptionError,"MissingArgument",option);
4896 filter=ParseMagickOption(MagickFilterOptions,MagickFalse,argv[i]);
4897 if (filter < 0)
4898 ThrowMogrifyException(OptionError,"UnrecognizedImageFilter",
4899 argv[i]);
4900 break;
4901 }
4902 if (LocaleCompare("flatten",option+1) == 0)
4903 break;
4904 if (LocaleCompare("flip",option+1) == 0)
4905 break;
4906 if (LocaleCompare("flop",option+1) == 0)
4907 break;
4908 if (LocaleCompare("floodfill",option+1) == 0)
4909 {
4910 if (*option == '+')
4911 break;
4912 i++;
4913 if (i == (long) argc)
4914 ThrowMogrifyException(OptionError,"MissingArgument",option);
4915 if (IsGeometry(argv[i]) == MagickFalse)
4916 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4917 i++;
4918 if (i == (long) argc)
4919 ThrowMogrifyException(OptionError,"MissingArgument",option);
4920 break;
4921 }
4922 if (LocaleCompare("font",option+1) == 0)
4923 {
4924 if (*option == '+')
4925 break;
4926 i++;
4927 if (i == (long) argc)
4928 ThrowMogrifyException(OptionError,"MissingArgument",option);
4929 break;
4930 }
4931 if (LocaleCompare("format",option+1) == 0)
4932 {
4933 (void) CopyMagickString(argv[i]+1,"sans",MaxTextExtent);
4934 (void) CloneString(&format,(char *) NULL);
4935 if (*option == '+')
4936 break;
4937 i++;
4938 if (i == (long) argc)
4939 ThrowMogrifyException(OptionError,"MissingArgument",option);
4940 (void) CloneString(&format,argv[i]);
4941 (void) CopyMagickString(image_info->filename,format,MaxTextExtent);
4942 (void) ConcatenateMagickString(image_info->filename,":",
4943 MaxTextExtent);
cristyd965a422010-03-03 17:47:35 +00004944 (void) SetImageInfo(image_info,0,exception);
cristy3ed852e2009-09-05 21:47:34 +00004945 if (*image_info->magick == '\0')
4946 ThrowMogrifyException(OptionError,"UnrecognizedImageFormat",
4947 format);
4948 break;
4949 }
4950 if (LocaleCompare("frame",option+1) == 0)
4951 {
4952 if (*option == '+')
4953 break;
4954 i++;
4955 if (i == (long) argc)
4956 ThrowMogrifyException(OptionError,"MissingArgument",option);
4957 if (IsGeometry(argv[i]) == MagickFalse)
4958 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4959 break;
4960 }
4961 if (LocaleCompare("function",option+1) == 0)
4962 {
4963 long
4964 op;
4965
4966 if (*option == '+')
4967 break;
4968 i++;
4969 if (i == (long) argc)
4970 ThrowMogrifyException(OptionError,"MissingArgument",option);
4971 op=ParseMagickOption(MagickFunctionOptions,MagickFalse,argv[i]);
4972 if (op < 0)
4973 ThrowMogrifyException(OptionError,"UnrecognizedFunction",argv[i]);
4974 i++;
4975 if (i == (long) (argc-1))
4976 ThrowMogrifyException(OptionError,"MissingArgument",option);
4977 break;
4978 }
4979 if (LocaleCompare("fuzz",option+1) == 0)
4980 {
4981 if (*option == '+')
4982 break;
4983 i++;
4984 if (i == (long) argc)
4985 ThrowMogrifyException(OptionError,"MissingArgument",option);
4986 if (IsGeometry(argv[i]) == MagickFalse)
4987 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4988 break;
4989 }
4990 if (LocaleCompare("fx",option+1) == 0)
4991 {
4992 if (*option == '+')
4993 break;
4994 i++;
4995 if (i == (long) (argc-1))
4996 ThrowMogrifyException(OptionError,"MissingArgument",option);
4997 break;
4998 }
4999 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5000 }
5001 case 'g':
5002 {
5003 if (LocaleCompare("gamma",option+1) == 0)
5004 {
5005 i++;
5006 if (i == (long) argc)
5007 ThrowMogrifyException(OptionError,"MissingArgument",option);
5008 if (IsGeometry(argv[i]) == MagickFalse)
5009 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5010 break;
5011 }
5012 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
5013 (LocaleCompare("gaussian",option+1) == 0))
5014 {
5015 i++;
5016 if (i == (long) argc)
5017 ThrowMogrifyException(OptionError,"MissingArgument",option);
5018 if (IsGeometry(argv[i]) == MagickFalse)
5019 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5020 break;
5021 }
5022 if (LocaleCompare("geometry",option+1) == 0)
5023 {
5024 if (*option == '+')
5025 break;
5026 i++;
5027 if (i == (long) argc)
5028 ThrowMogrifyException(OptionError,"MissingArgument",option);
5029 if (IsGeometry(argv[i]) == MagickFalse)
5030 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5031 break;
5032 }
5033 if (LocaleCompare("gravity",option+1) == 0)
5034 {
5035 long
5036 gravity;
5037
5038 if (*option == '+')
5039 break;
5040 i++;
5041 if (i == (long) argc)
5042 ThrowMogrifyException(OptionError,"MissingArgument",option);
5043 gravity=ParseMagickOption(MagickGravityOptions,MagickFalse,argv[i]);
5044 if (gravity < 0)
5045 ThrowMogrifyException(OptionError,"UnrecognizedGravityType",
5046 argv[i]);
5047 break;
5048 }
5049 if (LocaleCompare("green-primary",option+1) == 0)
5050 {
5051 if (*option == '+')
5052 break;
5053 i++;
5054 if (i == (long) argc)
5055 ThrowMogrifyException(OptionError,"MissingArgument",option);
5056 if (IsGeometry(argv[i]) == MagickFalse)
5057 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5058 break;
5059 }
5060 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5061 }
5062 case 'h':
5063 {
5064 if (LocaleCompare("hald-clut",option+1) == 0)
5065 break;
5066 if ((LocaleCompare("help",option+1) == 0) ||
5067 (LocaleCompare("-help",option+1) == 0))
5068 return(MogrifyUsage());
5069 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5070 }
5071 case 'i':
5072 {
5073 if (LocaleCompare("identify",option+1) == 0)
5074 break;
5075 if (LocaleCompare("idft",option+1) == 0)
5076 break;
5077 if (LocaleCompare("implode",option+1) == 0)
5078 {
5079 if (*option == '+')
5080 break;
5081 i++;
5082 if (i == (long) argc)
5083 ThrowMogrifyException(OptionError,"MissingArgument",option);
5084 if (IsGeometry(argv[i]) == MagickFalse)
5085 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5086 break;
5087 }
5088 if (LocaleCompare("intent",option+1) == 0)
5089 {
5090 long
5091 intent;
5092
5093 if (*option == '+')
5094 break;
5095 i++;
5096 if (i == (long) (argc-1))
5097 ThrowMogrifyException(OptionError,"MissingArgument",option);
5098 intent=ParseMagickOption(MagickIntentOptions,MagickFalse,argv[i]);
5099 if (intent < 0)
5100 ThrowMogrifyException(OptionError,"UnrecognizedIntentType",
5101 argv[i]);
5102 break;
5103 }
5104 if (LocaleCompare("interlace",option+1) == 0)
5105 {
5106 long
5107 interlace;
5108
5109 if (*option == '+')
5110 break;
5111 i++;
5112 if (i == (long) argc)
5113 ThrowMogrifyException(OptionError,"MissingArgument",option);
5114 interlace=ParseMagickOption(MagickInterlaceOptions,MagickFalse,
5115 argv[i]);
5116 if (interlace < 0)
5117 ThrowMogrifyException(OptionError,"UnrecognizedInterlaceType",
5118 argv[i]);
5119 break;
5120 }
cristyb32b90a2009-09-07 21:45:48 +00005121 if (LocaleCompare("interline-spacing",option+1) == 0)
5122 {
5123 if (*option == '+')
5124 break;
5125 i++;
5126 if (i == (long) (argc-1))
5127 ThrowMogrifyException(OptionError,"MissingArgument",option);
5128 if (IsGeometry(argv[i]) == MagickFalse)
5129 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5130 break;
5131 }
cristy3ed852e2009-09-05 21:47:34 +00005132 if (LocaleCompare("interpolate",option+1) == 0)
5133 {
5134 long
5135 interpolate;
5136
5137 if (*option == '+')
5138 break;
5139 i++;
5140 if (i == (long) argc)
5141 ThrowMogrifyException(OptionError,"MissingArgument",option);
5142 interpolate=ParseMagickOption(MagickInterpolateOptions,MagickFalse,
5143 argv[i]);
5144 if (interpolate < 0)
5145 ThrowMogrifyException(OptionError,"UnrecognizedInterpolateMethod",
5146 argv[i]);
5147 break;
5148 }
5149 if (LocaleCompare("interword-spacing",option+1) == 0)
5150 {
5151 if (*option == '+')
5152 break;
5153 i++;
5154 if (i == (long) (argc-1))
5155 ThrowMogrifyException(OptionError,"MissingArgument",option);
5156 if (IsGeometry(argv[i]) == MagickFalse)
5157 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5158 break;
5159 }
5160 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5161 }
5162 case 'k':
5163 {
5164 if (LocaleCompare("kerning",option+1) == 0)
5165 {
5166 if (*option == '+')
5167 break;
5168 i++;
5169 if (i == (long) (argc-1))
5170 ThrowMogrifyException(OptionError,"MissingArgument",option);
5171 if (IsGeometry(argv[i]) == MagickFalse)
5172 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5173 break;
5174 }
5175 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5176 }
5177 case 'l':
5178 {
5179 if (LocaleCompare("label",option+1) == 0)
5180 {
5181 if (*option == '+')
5182 break;
5183 i++;
5184 if (i == (long) argc)
5185 ThrowMogrifyException(OptionError,"MissingArgument",option);
5186 break;
5187 }
5188 if (LocaleCompare("lat",option+1) == 0)
5189 {
5190 if (*option == '+')
5191 break;
5192 i++;
5193 if (i == (long) argc)
5194 ThrowMogrifyException(OptionError,"MissingArgument",option);
5195 if (IsGeometry(argv[i]) == MagickFalse)
5196 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5197 }
5198 if (LocaleCompare("layers",option+1) == 0)
5199 {
5200 long
5201 type;
5202
5203 if (*option == '+')
5204 break;
5205 i++;
5206 if (i == (long) (argc-1))
5207 ThrowMogrifyException(OptionError,"MissingArgument",option);
5208 type=ParseMagickOption(MagickLayerOptions,MagickFalse,argv[i]);
5209 if (type < 0)
5210 ThrowMogrifyException(OptionError,"UnrecognizedLayerMethod",
5211 argv[i]);
5212 break;
5213 }
5214 if (LocaleCompare("level",option+1) == 0)
5215 {
5216 i++;
5217 if (i == (long) argc)
5218 ThrowMogrifyException(OptionError,"MissingArgument",option);
5219 if (IsGeometry(argv[i]) == MagickFalse)
5220 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5221 break;
5222 }
5223 if (LocaleCompare("level-colors",option+1) == 0)
5224 {
5225 i++;
5226 if (i == (long) argc)
5227 ThrowMogrifyException(OptionError,"MissingArgument",option);
5228 break;
5229 }
5230 if (LocaleCompare("linewidth",option+1) == 0)
5231 {
5232 if (*option == '+')
5233 break;
5234 i++;
5235 if (i == (long) argc)
5236 ThrowMogrifyException(OptionError,"MissingArgument",option);
5237 if (IsGeometry(argv[i]) == MagickFalse)
5238 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5239 break;
5240 }
5241 if (LocaleCompare("limit",option+1) == 0)
5242 {
5243 char
5244 *p;
5245
5246 double
5247 value;
5248
5249 long
5250 resource;
5251
5252 if (*option == '+')
5253 break;
5254 i++;
5255 if (i == (long) argc)
5256 ThrowMogrifyException(OptionError,"MissingArgument",option);
5257 resource=ParseMagickOption(MagickResourceOptions,MagickFalse,
5258 argv[i]);
5259 if (resource < 0)
5260 ThrowMogrifyException(OptionError,"UnrecognizedResourceType",
5261 argv[i]);
5262 i++;
5263 if (i == (long) argc)
5264 ThrowMogrifyException(OptionError,"MissingArgument",option);
5265 value=strtod(argv[i],&p);
5266 if ((p == argv[i]) && (LocaleCompare("unlimited",argv[i]) != 0))
5267 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5268 break;
5269 }
5270 if (LocaleCompare("liquid-rescale",option+1) == 0)
5271 {
5272 i++;
5273 if (i == (long) argc)
5274 ThrowMogrifyException(OptionError,"MissingArgument",option);
5275 if (IsGeometry(argv[i]) == MagickFalse)
5276 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5277 break;
5278 }
5279 if (LocaleCompare("list",option+1) == 0)
5280 {
5281 long
5282 list;
5283
5284 if (*option == '+')
5285 break;
5286 i++;
5287 if (i == (long) argc)
5288 ThrowMogrifyException(OptionError,"MissingArgument",option);
5289 list=ParseMagickOption(MagickListOptions,MagickFalse,argv[i]);
5290 if (list < 0)
5291 ThrowMogrifyException(OptionError,"UnrecognizedListType",argv[i]);
5292 (void) MogrifyImageInfo(image_info,(int) (i-j+1),(const char **)
5293 argv+j,exception);
5294 return(MagickTrue);
5295 }
5296 if (LocaleCompare("log",option+1) == 0)
5297 {
5298 if (*option == '+')
5299 break;
5300 i++;
5301 if ((i == (long) argc) ||
5302 (strchr(argv[i],'%') == (char *) NULL))
5303 ThrowMogrifyException(OptionError,"MissingArgument",option);
5304 break;
5305 }
5306 if (LocaleCompare("loop",option+1) == 0)
5307 {
5308 if (*option == '+')
5309 break;
5310 i++;
5311 if (i == (long) argc)
5312 ThrowMogrifyException(OptionError,"MissingArgument",option);
5313 if (IsGeometry(argv[i]) == MagickFalse)
5314 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5315 break;
5316 }
5317 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5318 }
5319 case 'm':
5320 {
5321 if (LocaleCompare("map",option+1) == 0)
5322 {
5323 global_colormap=(*option == '+') ? MagickTrue : MagickFalse;
5324 if (*option == '+')
5325 break;
5326 i++;
5327 if (i == (long) argc)
5328 ThrowMogrifyException(OptionError,"MissingArgument",option);
5329 break;
5330 }
5331 if (LocaleCompare("mask",option+1) == 0)
5332 {
5333 if (*option == '+')
5334 break;
5335 i++;
5336 if (i == (long) argc)
5337 ThrowMogrifyException(OptionError,"MissingArgument",option);
5338 break;
5339 }
5340 if (LocaleCompare("matte",option+1) == 0)
5341 break;
5342 if (LocaleCompare("mattecolor",option+1) == 0)
5343 {
5344 if (*option == '+')
5345 break;
5346 i++;
5347 if (i == (long) argc)
5348 ThrowMogrifyException(OptionError,"MissingArgument",option);
5349 break;
5350 }
cristyf40785b2010-03-06 02:27:27 +00005351 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00005352 break;
cristyf40785b2010-03-06 02:27:27 +00005353 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00005354 break;
cristy3ed852e2009-09-05 21:47:34 +00005355 if (LocaleCompare("modulate",option+1) == 0)
5356 {
5357 if (*option == '+')
5358 break;
5359 i++;
5360 if (i == (long) argc)
5361 ThrowMogrifyException(OptionError,"MissingArgument",option);
5362 if (IsGeometry(argv[i]) == MagickFalse)
5363 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5364 break;
5365 }
5366 if (LocaleCompare("median",option+1) == 0)
5367 {
5368 if (*option == '+')
5369 break;
5370 i++;
5371 if (i == (long) argc)
5372 ThrowMogrifyException(OptionError,"MissingArgument",option);
5373 if (IsGeometry(argv[i]) == MagickFalse)
5374 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5375 break;
5376 }
5377 if (LocaleCompare("monitor",option+1) == 0)
5378 break;
5379 if (LocaleCompare("monochrome",option+1) == 0)
5380 break;
5381 if (LocaleCompare("morph",option+1) == 0)
5382 {
5383 if (*option == '+')
5384 break;
5385 i++;
5386 if (i == (long) (argc-1))
5387 ThrowMogrifyException(OptionError,"MissingArgument",option);
5388 if (IsGeometry(argv[i]) == MagickFalse)
5389 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5390 break;
5391 }
anthony29188a82010-01-22 10:12:34 +00005392 if (LocaleCompare("morphology",option+1) == 0)
5393 {
5394 long
5395 op;
5396
5397 char
5398 token[MaxTextExtent];
5399
5400 i++;
5401 if (i == (long) argc)
5402 ThrowMogrifyException(OptionError,"MissingArgument",option);
5403 GetMagickToken(argv[i],NULL,token);
5404 op=ParseMagickOption(MagickMorphologyOptions,MagickFalse,token);
5405 if (op < 0)
5406 ThrowMogrifyException(OptionError,"UnrecognizedMorphologyMethod",
5407 token);
5408 i++;
5409 if (i == (long) (argc-1))
5410 ThrowMogrifyException(OptionError,"MissingArgument",option);
5411 GetMagickToken(argv[i],NULL,token);
5412 if ( isalpha((int)token[0]) )
5413 {
5414 op=ParseMagickOption(MagickKernelOptions,MagickFalse,token);
5415 if (op < 0)
5416 ThrowMogrifyException(OptionError,"UnrecognizedKernelType",
5417 token);
5418 }
5419#if 0
5420 /* DO NOT ENABLE, geometry can not handle user defined kernels
5421 * which include 'nan' values, though '-' are acceptable.
5422 */
5423 else if (IsGeometry(argv[i]) == MagickFalse)
5424 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5425#endif
5426 break;
5427 }
cristy3ed852e2009-09-05 21:47:34 +00005428 if (LocaleCompare("mosaic",option+1) == 0)
5429 break;
5430 if (LocaleCompare("motion-blur",option+1) == 0)
5431 {
5432 if (*option == '+')
5433 break;
5434 i++;
5435 if (i == (long) argc)
5436 ThrowMogrifyException(OptionError,"MissingArgument",option);
5437 if (IsGeometry(argv[i]) == MagickFalse)
5438 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5439 break;
5440 }
5441 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5442 }
5443 case 'n':
5444 {
5445 if (LocaleCompare("negate",option+1) == 0)
5446 break;
5447 if (LocaleCompare("noise",option+1) == 0)
5448 {
5449 i++;
5450 if (i == (long) argc)
5451 ThrowMogrifyException(OptionError,"MissingArgument",option);
5452 if (*option == '+')
5453 {
5454 long
5455 noise;
5456
5457 noise=ParseMagickOption(MagickNoiseOptions,MagickFalse,argv[i]);
5458 if (noise < 0)
5459 ThrowMogrifyException(OptionError,"UnrecognizedNoiseType",
5460 argv[i]);
5461 break;
5462 }
5463 if (IsGeometry(argv[i]) == MagickFalse)
5464 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5465 break;
5466 }
5467 if (LocaleCompare("noop",option+1) == 0)
5468 break;
5469 if (LocaleCompare("normalize",option+1) == 0)
5470 break;
5471 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5472 }
5473 case 'o':
5474 {
5475 if (LocaleCompare("opaque",option+1) == 0)
5476 {
cristy3ed852e2009-09-05 21:47:34 +00005477 i++;
5478 if (i == (long) argc)
5479 ThrowMogrifyException(OptionError,"MissingArgument",option);
5480 break;
5481 }
5482 if (LocaleCompare("ordered-dither",option+1) == 0)
5483 {
5484 if (*option == '+')
5485 break;
5486 i++;
5487 if (i == (long) argc)
5488 ThrowMogrifyException(OptionError,"MissingArgument",option);
5489 break;
5490 }
5491 if (LocaleCompare("orient",option+1) == 0)
5492 {
5493 long
5494 orientation;
5495
5496 orientation=UndefinedOrientation;
5497 if (*option == '+')
5498 break;
5499 i++;
5500 if (i == (long) (argc-1))
5501 ThrowMogrifyException(OptionError,"MissingArgument",option);
5502 orientation=ParseMagickOption(MagickOrientationOptions,MagickFalse,
5503 argv[i]);
5504 if (orientation < 0)
5505 ThrowMogrifyException(OptionError,"UnrecognizedImageOrientation",
5506 argv[i]);
5507 break;
5508 }
5509 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5510 }
5511 case 'p':
5512 {
5513 if (LocaleCompare("page",option+1) == 0)
5514 {
5515 if (*option == '+')
5516 break;
5517 i++;
5518 if (i == (long) argc)
5519 ThrowMogrifyException(OptionError,"MissingArgument",option);
5520 break;
5521 }
5522 if (LocaleCompare("paint",option+1) == 0)
5523 {
5524 if (*option == '+')
5525 break;
5526 i++;
5527 if (i == (long) argc)
5528 ThrowMogrifyException(OptionError,"MissingArgument",option);
5529 if (IsGeometry(argv[i]) == MagickFalse)
5530 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5531 break;
5532 }
5533 if (LocaleCompare("path",option+1) == 0)
5534 {
5535 (void) CloneString(&path,(char *) NULL);
5536 if (*option == '+')
5537 break;
5538 i++;
5539 if (i == (long) argc)
5540 ThrowMogrifyException(OptionError,"MissingArgument",option);
5541 (void) CloneString(&path,argv[i]);
5542 break;
5543 }
5544 if (LocaleCompare("pointsize",option+1) == 0)
5545 {
5546 if (*option == '+')
5547 break;
5548 i++;
5549 if (i == (long) argc)
5550 ThrowMogrifyException(OptionError,"MissingArgument",option);
5551 if (IsGeometry(argv[i]) == MagickFalse)
5552 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5553 break;
5554 }
5555 if (LocaleCompare("polaroid",option+1) == 0)
5556 {
5557 if (*option == '+')
5558 break;
5559 i++;
5560 if (i == (long) argc)
5561 ThrowMogrifyException(OptionError,"MissingArgument",option);
5562 if (IsGeometry(argv[i]) == MagickFalse)
5563 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5564 break;
5565 }
5566 if (LocaleCompare("posterize",option+1) == 0)
5567 {
5568 if (*option == '+')
5569 break;
5570 i++;
5571 if (i == (long) argc)
5572 ThrowMogrifyException(OptionError,"MissingArgument",option);
5573 if (IsGeometry(argv[i]) == MagickFalse)
5574 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5575 break;
5576 }
cristye7f51092010-01-17 00:39:37 +00005577 if (LocaleCompare("precision",option+1) == 0)
5578 {
5579 if (*option == '+')
5580 break;
5581 i++;
5582 if (i == (long) argc)
5583 ThrowMogrifyException(OptionError,"MissingArgument",option);
5584 if (IsGeometry(argv[i]) == MagickFalse)
5585 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5586 break;
5587 }
cristy3ed852e2009-09-05 21:47:34 +00005588 if (LocaleCompare("print",option+1) == 0)
5589 {
5590 if (*option == '+')
5591 break;
5592 i++;
5593 if (i == (long) argc)
5594 ThrowMogrifyException(OptionError,"MissingArgument",option);
5595 break;
5596 }
5597 if (LocaleCompare("process",option+1) == 0)
5598 {
5599 if (*option == '+')
5600 break;
5601 i++;
5602 if (i == (long) (argc-1))
5603 ThrowMogrifyException(OptionError,"MissingArgument",option);
5604 break;
5605 }
5606 if (LocaleCompare("profile",option+1) == 0)
5607 {
5608 i++;
5609 if (i == (long) argc)
5610 ThrowMogrifyException(OptionError,"MissingArgument",option);
5611 break;
5612 }
5613 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5614 }
5615 case 'q':
5616 {
5617 if (LocaleCompare("quality",option+1) == 0)
5618 {
5619 if (*option == '+')
5620 break;
5621 i++;
5622 if (i == (long) argc)
5623 ThrowMogrifyException(OptionError,"MissingArgument",option);
5624 if (IsGeometry(argv[i]) == MagickFalse)
5625 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5626 break;
5627 }
5628 if (LocaleCompare("quantize",option+1) == 0)
5629 {
5630 long
5631 colorspace;
5632
5633 if (*option == '+')
5634 break;
5635 i++;
5636 if (i == (long) (argc-1))
5637 ThrowMogrifyException(OptionError,"MissingArgument",option);
5638 colorspace=ParseMagickOption(MagickColorspaceOptions,MagickFalse,
5639 argv[i]);
5640 if (colorspace < 0)
5641 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
5642 argv[i]);
5643 break;
5644 }
5645 if (LocaleCompare("quiet",option+1) == 0)
5646 break;
5647 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5648 }
5649 case 'r':
5650 {
5651 if (LocaleCompare("radial-blur",option+1) == 0)
5652 {
5653 i++;
5654 if (i == (long) argc)
5655 ThrowMogrifyException(OptionError,"MissingArgument",option);
5656 if (IsGeometry(argv[i]) == MagickFalse)
5657 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5658 break;
5659 }
5660 if (LocaleCompare("raise",option+1) == 0)
5661 {
5662 i++;
5663 if (i == (long) argc)
5664 ThrowMogrifyException(OptionError,"MissingArgument",option);
5665 if (IsGeometry(argv[i]) == MagickFalse)
5666 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5667 break;
5668 }
5669 if (LocaleCompare("random-threshold",option+1) == 0)
5670 {
5671 if (*option == '+')
5672 break;
5673 i++;
5674 if (i == (long) argc)
5675 ThrowMogrifyException(OptionError,"MissingArgument",option);
5676 if (IsGeometry(argv[i]) == MagickFalse)
5677 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5678 break;
5679 }
5680 if (LocaleCompare("red-primary",option+1) == 0)
5681 {
5682 if (*option == '+')
5683 break;
5684 i++;
5685 if (i == (long) argc)
5686 ThrowMogrifyException(OptionError,"MissingArgument",option);
5687 if (IsGeometry(argv[i]) == MagickFalse)
5688 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5689 }
5690 if (LocaleCompare("region",option+1) == 0)
5691 {
5692 if (*option == '+')
5693 break;
5694 i++;
5695 if (i == (long) argc)
5696 ThrowMogrifyException(OptionError,"MissingArgument",option);
5697 if (IsGeometry(argv[i]) == MagickFalse)
5698 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5699 break;
5700 }
5701 if (LocaleCompare("render",option+1) == 0)
5702 break;
5703 if (LocaleCompare("repage",option+1) == 0)
5704 {
5705 if (*option == '+')
5706 break;
5707 i++;
5708 if (i == (long) argc)
5709 ThrowMogrifyException(OptionError,"MissingArgument",option);
5710 if (IsGeometry(argv[i]) == MagickFalse)
5711 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5712 break;
5713 }
5714 if (LocaleCompare("resample",option+1) == 0)
5715 {
5716 if (*option == '+')
5717 break;
5718 i++;
5719 if (i == (long) argc)
5720 ThrowMogrifyException(OptionError,"MissingArgument",option);
5721 if (IsGeometry(argv[i]) == MagickFalse)
5722 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5723 break;
5724 }
5725 if (LocaleCompare("resize",option+1) == 0)
5726 {
5727 if (*option == '+')
5728 break;
5729 i++;
5730 if (i == (long) argc)
5731 ThrowMogrifyException(OptionError,"MissingArgument",option);
5732 if (IsGeometry(argv[i]) == MagickFalse)
5733 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5734 break;
5735 }
5736 if (LocaleCompare("reverse",option+1) == 0)
5737 break;
5738 if (LocaleCompare("roll",option+1) == 0)
5739 {
5740 if (*option == '+')
5741 break;
5742 i++;
5743 if (i == (long) argc)
5744 ThrowMogrifyException(OptionError,"MissingArgument",option);
5745 if (IsGeometry(argv[i]) == MagickFalse)
5746 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5747 break;
5748 }
5749 if (LocaleCompare("rotate",option+1) == 0)
5750 {
5751 i++;
5752 if (i == (long) argc)
5753 ThrowMogrifyException(OptionError,"MissingArgument",option);
5754 if (IsGeometry(argv[i]) == MagickFalse)
5755 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5756 break;
5757 }
5758 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5759 }
5760 case 's':
5761 {
5762 if (LocaleCompare("sample",option+1) == 0)
5763 {
5764 if (*option == '+')
5765 break;
5766 i++;
5767 if (i == (long) argc)
5768 ThrowMogrifyException(OptionError,"MissingArgument",option);
5769 if (IsGeometry(argv[i]) == MagickFalse)
5770 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5771 break;
5772 }
5773 if (LocaleCompare("sampling-factor",option+1) == 0)
5774 {
5775 if (*option == '+')
5776 break;
5777 i++;
5778 if (i == (long) argc)
5779 ThrowMogrifyException(OptionError,"MissingArgument",option);
5780 if (IsGeometry(argv[i]) == MagickFalse)
5781 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5782 break;
5783 }
5784 if (LocaleCompare("scale",option+1) == 0)
5785 {
5786 if (*option == '+')
5787 break;
5788 i++;
5789 if (i == (long) argc)
5790 ThrowMogrifyException(OptionError,"MissingArgument",option);
5791 if (IsGeometry(argv[i]) == MagickFalse)
5792 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5793 break;
5794 }
5795 if (LocaleCompare("scene",option+1) == 0)
5796 {
5797 if (*option == '+')
5798 break;
5799 i++;
5800 if (i == (long) argc)
5801 ThrowMogrifyException(OptionError,"MissingArgument",option);
5802 if (IsGeometry(argv[i]) == MagickFalse)
5803 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5804 break;
5805 }
5806 if (LocaleCompare("seed",option+1) == 0)
5807 {
5808 if (*option == '+')
5809 break;
5810 i++;
5811 if (i == (long) argc)
5812 ThrowMogrifyException(OptionError,"MissingArgument",option);
5813 if (IsGeometry(argv[i]) == MagickFalse)
5814 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5815 break;
5816 }
5817 if (LocaleCompare("segment",option+1) == 0)
5818 {
5819 if (*option == '+')
5820 break;
5821 i++;
5822 if (i == (long) argc)
5823 ThrowMogrifyException(OptionError,"MissingArgument",option);
5824 if (IsGeometry(argv[i]) == MagickFalse)
5825 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5826 break;
5827 }
5828 if (LocaleCompare("selective-blur",option+1) == 0)
5829 {
5830 i++;
5831 if (i == (long) argc)
5832 ThrowMogrifyException(OptionError,"MissingArgument",option);
5833 if (IsGeometry(argv[i]) == MagickFalse)
5834 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5835 break;
5836 }
5837 if (LocaleCompare("separate",option+1) == 0)
5838 break;
5839 if (LocaleCompare("sepia-tone",option+1) == 0)
5840 {
5841 if (*option == '+')
5842 break;
5843 i++;
5844 if (i == (long) argc)
5845 ThrowMogrifyException(OptionError,"MissingArgument",option);
5846 if (IsGeometry(argv[i]) == MagickFalse)
5847 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5848 break;
5849 }
5850 if (LocaleCompare("set",option+1) == 0)
5851 {
5852 i++;
5853 if (i == (long) argc)
5854 ThrowMogrifyException(OptionError,"MissingArgument",option);
5855 if (*option == '+')
5856 break;
5857 i++;
5858 if (i == (long) argc)
5859 ThrowMogrifyException(OptionError,"MissingArgument",option);
5860 break;
5861 }
5862 if (LocaleCompare("shade",option+1) == 0)
5863 {
5864 i++;
5865 if (i == (long) argc)
5866 ThrowMogrifyException(OptionError,"MissingArgument",option);
5867 if (IsGeometry(argv[i]) == MagickFalse)
5868 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5869 break;
5870 }
5871 if (LocaleCompare("shadow",option+1) == 0)
5872 {
5873 if (*option == '+')
5874 break;
5875 i++;
5876 if (i == (long) argc)
5877 ThrowMogrifyException(OptionError,"MissingArgument",option);
5878 if (IsGeometry(argv[i]) == MagickFalse)
5879 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5880 break;
5881 }
5882 if (LocaleCompare("sharpen",option+1) == 0)
5883 {
5884 i++;
5885 if (i == (long) argc)
5886 ThrowMogrifyException(OptionError,"MissingArgument",option);
5887 if (IsGeometry(argv[i]) == MagickFalse)
5888 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5889 break;
5890 }
5891 if (LocaleCompare("shave",option+1) == 0)
5892 {
5893 if (*option == '+')
5894 break;
5895 i++;
5896 if (i == (long) argc)
5897 ThrowMogrifyException(OptionError,"MissingArgument",option);
5898 if (IsGeometry(argv[i]) == MagickFalse)
5899 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5900 break;
5901 }
5902 if (LocaleCompare("shear",option+1) == 0)
5903 {
5904 i++;
5905 if (i == (long) argc)
5906 ThrowMogrifyException(OptionError,"MissingArgument",option);
5907 if (IsGeometry(argv[i]) == MagickFalse)
5908 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5909 break;
5910 }
5911 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
5912 {
5913 i++;
5914 if (i == (long) (argc-1))
5915 ThrowMogrifyException(OptionError,"MissingArgument",option);
5916 if (IsGeometry(argv[i]) == MagickFalse)
5917 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5918 break;
5919 }
5920 if (LocaleCompare("size",option+1) == 0)
5921 {
5922 if (*option == '+')
5923 break;
5924 i++;
5925 if (i == (long) argc)
5926 ThrowMogrifyException(OptionError,"MissingArgument",option);
5927 if (IsGeometry(argv[i]) == MagickFalse)
5928 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5929 break;
5930 }
5931 if (LocaleCompare("sketch",option+1) == 0)
5932 {
5933 if (*option == '+')
5934 break;
5935 i++;
5936 if (i == (long) argc)
5937 ThrowMogrifyException(OptionError,"MissingArgument",option);
5938 if (IsGeometry(argv[i]) == MagickFalse)
5939 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5940 break;
5941 }
5942 if (LocaleCompare("solarize",option+1) == 0)
5943 {
5944 if (*option == '+')
5945 break;
5946 i++;
5947 if (i == (long) argc)
5948 ThrowMogrifyException(OptionError,"MissingArgument",option);
5949 if (IsGeometry(argv[i]) == MagickFalse)
5950 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5951 break;
5952 }
5953 if (LocaleCompare("sparse-color",option+1) == 0)
5954 {
5955 long
5956 op;
5957
5958 i++;
5959 if (i == (long) argc)
5960 ThrowMogrifyException(OptionError,"MissingArgument",option);
5961 op=ParseMagickOption(MagickSparseColorOptions,MagickFalse,argv[i]);
5962 if (op < 0)
5963 ThrowMogrifyException(OptionError,"UnrecognizedSparseColorMethod",
5964 argv[i]);
5965 i++;
5966 if (i == (long) (argc-1))
5967 ThrowMogrifyException(OptionError,"MissingArgument",option);
5968 break;
5969 }
5970 if (LocaleCompare("spread",option+1) == 0)
5971 {
5972 if (*option == '+')
5973 break;
5974 i++;
5975 if (i == (long) argc)
5976 ThrowMogrifyException(OptionError,"MissingArgument",option);
5977 if (IsGeometry(argv[i]) == MagickFalse)
5978 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5979 break;
5980 }
5981 if (LocaleCompare("stretch",option+1) == 0)
5982 {
5983 long
5984 stretch;
5985
5986 if (*option == '+')
5987 break;
5988 i++;
5989 if (i == (long) (argc-1))
5990 ThrowMogrifyException(OptionError,"MissingArgument",option);
5991 stretch=ParseMagickOption(MagickStretchOptions,MagickFalse,argv[i]);
5992 if (stretch < 0)
5993 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
5994 argv[i]);
5995 break;
5996 }
5997 if (LocaleCompare("strip",option+1) == 0)
5998 break;
5999 if (LocaleCompare("stroke",option+1) == 0)
6000 {
6001 if (*option == '+')
6002 break;
6003 i++;
6004 if (i == (long) argc)
6005 ThrowMogrifyException(OptionError,"MissingArgument",option);
6006 break;
6007 }
6008 if (LocaleCompare("strokewidth",option+1) == 0)
6009 {
6010 if (*option == '+')
6011 break;
6012 i++;
6013 if (i == (long) argc)
6014 ThrowMogrifyException(OptionError,"MissingArgument",option);
6015 if (IsGeometry(argv[i]) == MagickFalse)
6016 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6017 break;
6018 }
6019 if (LocaleCompare("style",option+1) == 0)
6020 {
6021 long
6022 style;
6023
6024 if (*option == '+')
6025 break;
6026 i++;
6027 if (i == (long) (argc-1))
6028 ThrowMogrifyException(OptionError,"MissingArgument",option);
6029 style=ParseMagickOption(MagickStyleOptions,MagickFalse,argv[i]);
6030 if (style < 0)
6031 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
6032 argv[i]);
6033 break;
6034 }
6035 if (LocaleCompare("swirl",option+1) == 0)
6036 {
6037 if (*option == '+')
6038 break;
6039 i++;
6040 if (i == (long) argc)
6041 ThrowMogrifyException(OptionError,"MissingArgument",option);
6042 if (IsGeometry(argv[i]) == MagickFalse)
6043 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6044 break;
6045 }
6046 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6047 }
6048 case 't':
6049 {
6050 if (LocaleCompare("taint",option+1) == 0)
6051 break;
6052 if (LocaleCompare("texture",option+1) == 0)
6053 {
6054 if (*option == '+')
6055 break;
6056 i++;
6057 if (i == (long) argc)
6058 ThrowMogrifyException(OptionError,"MissingArgument",option);
6059 break;
6060 }
6061 if (LocaleCompare("tile",option+1) == 0)
6062 {
6063 if (*option == '+')
6064 break;
6065 i++;
6066 if (i == (long) (argc-1))
6067 ThrowMogrifyException(OptionError,"MissingArgument",option);
6068 break;
6069 }
6070 if (LocaleCompare("tile-offset",option+1) == 0)
6071 {
6072 if (*option == '+')
6073 break;
6074 i++;
6075 if (i == (long) argc)
6076 ThrowMogrifyException(OptionError,"MissingArgument",option);
6077 if (IsGeometry(argv[i]) == MagickFalse)
6078 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6079 break;
6080 }
6081 if (LocaleCompare("tint",option+1) == 0)
6082 {
6083 if (*option == '+')
6084 break;
6085 i++;
6086 if (i == (long) (argc-1))
6087 ThrowMogrifyException(OptionError,"MissingArgument",option);
6088 if (IsGeometry(argv[i]) == MagickFalse)
6089 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6090 break;
6091 }
6092 if (LocaleCompare("transform",option+1) == 0)
6093 break;
6094 if (LocaleCompare("transpose",option+1) == 0)
6095 break;
6096 if (LocaleCompare("transverse",option+1) == 0)
6097 break;
6098 if (LocaleCompare("threshold",option+1) == 0)
6099 {
6100 if (*option == '+')
6101 break;
6102 i++;
6103 if (i == (long) argc)
6104 ThrowMogrifyException(OptionError,"MissingArgument",option);
6105 if (IsGeometry(argv[i]) == MagickFalse)
6106 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6107 break;
6108 }
6109 if (LocaleCompare("thumbnail",option+1) == 0)
6110 {
6111 if (*option == '+')
6112 break;
6113 i++;
6114 if (i == (long) argc)
6115 ThrowMogrifyException(OptionError,"MissingArgument",option);
6116 if (IsGeometry(argv[i]) == MagickFalse)
6117 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6118 break;
6119 }
6120 if (LocaleCompare("transparent",option+1) == 0)
6121 {
6122 i++;
6123 if (i == (long) argc)
6124 ThrowMogrifyException(OptionError,"MissingArgument",option);
6125 break;
6126 }
6127 if (LocaleCompare("transparent-color",option+1) == 0)
6128 {
6129 if (*option == '+')
6130 break;
6131 i++;
6132 if (i == (long) (argc-1))
6133 ThrowMogrifyException(OptionError,"MissingArgument",option);
6134 break;
6135 }
6136 if (LocaleCompare("treedepth",option+1) == 0)
6137 {
6138 if (*option == '+')
6139 break;
6140 i++;
6141 if (i == (long) argc)
6142 ThrowMogrifyException(OptionError,"MissingArgument",option);
6143 if (IsGeometry(argv[i]) == MagickFalse)
6144 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6145 break;
6146 }
6147 if (LocaleCompare("trim",option+1) == 0)
6148 break;
6149 if (LocaleCompare("type",option+1) == 0)
6150 {
6151 long
6152 type;
6153
6154 if (*option == '+')
6155 break;
6156 i++;
6157 if (i == (long) argc)
6158 ThrowMogrifyException(OptionError,"MissingArgument",option);
6159 type=ParseMagickOption(MagickTypeOptions,MagickFalse,argv[i]);
6160 if (type < 0)
6161 ThrowMogrifyException(OptionError,"UnrecognizedImageType",
6162 argv[i]);
6163 break;
6164 }
6165 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6166 }
6167 case 'u':
6168 {
6169 if (LocaleCompare("undercolor",option+1) == 0)
6170 {
6171 if (*option == '+')
6172 break;
6173 i++;
6174 if (i == (long) argc)
6175 ThrowMogrifyException(OptionError,"MissingArgument",option);
6176 break;
6177 }
6178 if (LocaleCompare("unique-colors",option+1) == 0)
6179 break;
6180 if (LocaleCompare("units",option+1) == 0)
6181 {
6182 long
6183 units;
6184
6185 if (*option == '+')
6186 break;
6187 i++;
6188 if (i == (long) argc)
6189 ThrowMogrifyException(OptionError,"MissingArgument",option);
6190 units=ParseMagickOption(MagickResolutionOptions,MagickFalse,
6191 argv[i]);
6192 if (units < 0)
6193 ThrowMogrifyException(OptionError,"UnrecognizedUnitsType",
6194 argv[i]);
6195 break;
6196 }
6197 if (LocaleCompare("unsharp",option+1) == 0)
6198 {
6199 i++;
6200 if (i == (long) argc)
6201 ThrowMogrifyException(OptionError,"MissingArgument",option);
6202 if (IsGeometry(argv[i]) == MagickFalse)
6203 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6204 break;
6205 }
6206 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6207 }
6208 case 'v':
6209 {
6210 if (LocaleCompare("verbose",option+1) == 0)
6211 {
6212 image_info->verbose=(*option == '-') ? MagickTrue : MagickFalse;
6213 break;
6214 }
6215 if ((LocaleCompare("version",option+1) == 0) ||
6216 (LocaleCompare("-version",option+1) == 0))
6217 {
6218 (void) fprintf(stdout,"Version: %s\n",
6219 GetMagickVersion((unsigned long *) NULL));
cristy610b2e22009-10-22 14:59:43 +00006220 (void) fprintf(stdout,"Copyright: %s\n",GetMagickCopyright());
6221 (void) fprintf(stdout,"Features: %s\n\n",GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00006222 break;
6223 }
6224 if (LocaleCompare("view",option+1) == 0)
6225 {
6226 if (*option == '+')
6227 break;
6228 i++;
6229 if (i == (long) argc)
6230 ThrowMogrifyException(OptionError,"MissingArgument",option);
6231 break;
6232 }
6233 if (LocaleCompare("vignette",option+1) == 0)
6234 {
6235 if (*option == '+')
6236 break;
6237 i++;
6238 if (i == (long) argc)
6239 ThrowMogrifyException(OptionError,"MissingArgument",option);
6240 if (IsGeometry(argv[i]) == MagickFalse)
6241 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6242 break;
6243 }
6244 if (LocaleCompare("virtual-pixel",option+1) == 0)
6245 {
6246 long
6247 method;
6248
6249 if (*option == '+')
6250 break;
6251 i++;
6252 if (i == (long) argc)
6253 ThrowMogrifyException(OptionError,"MissingArgument",option);
6254 method=ParseMagickOption(MagickVirtualPixelOptions,MagickFalse,
6255 argv[i]);
6256 if (method < 0)
6257 ThrowMogrifyException(OptionError,
6258 "UnrecognizedVirtualPixelMethod",argv[i]);
6259 break;
6260 }
6261 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6262 }
6263 case 'w':
6264 {
6265 if (LocaleCompare("wave",option+1) == 0)
6266 {
6267 i++;
6268 if (i == (long) argc)
6269 ThrowMogrifyException(OptionError,"MissingArgument",option);
6270 if (IsGeometry(argv[i]) == MagickFalse)
6271 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6272 break;
6273 }
6274 if (LocaleCompare("weight",option+1) == 0)
6275 {
6276 if (*option == '+')
6277 break;
6278 i++;
6279 if (i == (long) (argc-1))
6280 ThrowMogrifyException(OptionError,"MissingArgument",option);
6281 break;
6282 }
6283 if (LocaleCompare("white-point",option+1) == 0)
6284 {
6285 if (*option == '+')
6286 break;
6287 i++;
6288 if (i == (long) argc)
6289 ThrowMogrifyException(OptionError,"MissingArgument",option);
6290 if (IsGeometry(argv[i]) == MagickFalse)
6291 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6292 break;
6293 }
6294 if (LocaleCompare("white-threshold",option+1) == 0)
6295 {
6296 if (*option == '+')
6297 break;
6298 i++;
6299 if (i == (long) argc)
6300 ThrowMogrifyException(OptionError,"MissingArgument",option);
6301 if (IsGeometry(argv[i]) == MagickFalse)
6302 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6303 break;
6304 }
6305 if (LocaleCompare("write",option+1) == 0)
6306 {
6307 i++;
6308 if (i == (long) (argc-1))
6309 ThrowMogrifyException(OptionError,"MissingArgument",option);
6310 break;
6311 }
6312 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6313 }
6314 case '?':
6315 break;
6316 default:
6317 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6318 }
6319 fire=ParseMagickOption(MagickImageListOptions,MagickFalse,option+1) < 0 ?
6320 MagickFalse : MagickTrue;
6321 if (fire != MagickFalse)
6322 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
6323 }
6324 if (k != 0)
6325 ThrowMogrifyException(OptionError,"UnbalancedParenthesis",argv[i]);
6326 if (i != argc)
6327 ThrowMogrifyException(OptionError,"MissingAnImageFilename",argv[i]);
6328 DestroyMogrify();
6329 return(status != 0 ? MagickTrue : MagickFalse);
6330}
6331
6332/*
6333%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6334% %
6335% %
6336% %
6337+ M o g r i f y I m a g e I n f o %
6338% %
6339% %
6340% %
6341%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6342%
6343% MogrifyImageInfo() applies image processing settings to the image as
6344% prescribed by command line options.
6345%
6346% The format of the MogrifyImageInfo method is:
6347%
6348% MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,const int argc,
6349% const char **argv,ExceptionInfo *exception)
6350%
6351% A description of each parameter follows:
6352%
6353% o image_info: the image info..
6354%
6355% o argc: Specifies a pointer to an integer describing the number of
6356% elements in the argument vector.
6357%
6358% o argv: Specifies a pointer to a text array containing the command line
6359% arguments.
6360%
6361% o exception: return any errors or warnings in this structure.
6362%
6363*/
6364WandExport MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,
6365 const int argc,const char **argv,ExceptionInfo *exception)
6366{
6367 const char
6368 *option;
6369
6370 GeometryInfo
6371 geometry_info;
6372
6373 long
6374 count;
6375
6376 register long
6377 i;
6378
6379 /*
6380 Initialize method variables.
6381 */
6382 assert(image_info != (ImageInfo *) NULL);
6383 assert(image_info->signature == MagickSignature);
6384 if (image_info->debug != MagickFalse)
6385 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
6386 image_info->filename);
6387 if (argc < 0)
6388 return(MagickTrue);
6389 /*
6390 Set the image settings.
6391 */
6392 for (i=0; i < (long) argc; i++)
6393 {
6394 option=argv[i];
6395 if (IsMagickOption(option) == MagickFalse)
6396 continue;
6397 count=MagickMax(ParseMagickOption(MagickCommandOptions,MagickFalse,option),
6398 0L);
6399 if ((i+count) >= argc)
6400 break;
6401 switch (*(option+1))
6402 {
6403 case 'a':
6404 {
6405 if (LocaleCompare("adjoin",option+1) == 0)
6406 {
6407 image_info->adjoin=(*option == '-') ? MagickTrue : MagickFalse;
6408 break;
6409 }
6410 if (LocaleCompare("antialias",option+1) == 0)
6411 {
6412 image_info->antialias=(*option == '-') ? MagickTrue : MagickFalse;
6413 break;
6414 }
6415 if (LocaleCompare("attenuate",option+1) == 0)
6416 {
6417 if (*option == '+')
6418 {
6419 (void) DeleteImageOption(image_info,option+1);
6420 break;
6421 }
6422 (void) SetImageOption(image_info,option+1,argv[i+1]);
6423 break;
6424 }
6425 if (LocaleCompare("authenticate",option+1) == 0)
6426 {
6427 if (*option == '+')
6428 (void) CloneString(&image_info->authenticate,(char *) NULL);
6429 else
6430 (void) CloneString(&image_info->authenticate,argv[i+1]);
6431 break;
6432 }
6433 break;
6434 }
6435 case 'b':
6436 {
6437 if (LocaleCompare("background",option+1) == 0)
6438 {
6439 if (*option == '+')
6440 {
6441 (void) DeleteImageOption(image_info,option+1);
6442 (void) QueryColorDatabase(BackgroundColor,
6443 &image_info->background_color,exception);
6444 break;
6445 }
6446 (void) SetImageOption(image_info,option+1,argv[i+1]);
6447 (void) QueryColorDatabase(argv[i+1],&image_info->background_color,
6448 exception);
6449 break;
6450 }
6451 if (LocaleCompare("bias",option+1) == 0)
6452 {
6453 if (*option == '+')
6454 {
6455 (void) SetImageOption(image_info,option+1,"0.0");
6456 break;
6457 }
6458 (void) SetImageOption(image_info,option+1,argv[i+1]);
6459 break;
6460 }
6461 if (LocaleCompare("black-point-compensation",option+1) == 0)
6462 {
6463 if (*option == '+')
6464 {
6465 (void) SetImageOption(image_info,option+1,"false");
6466 break;
6467 }
6468 (void) SetImageOption(image_info,option+1,"true");
6469 break;
6470 }
6471 if (LocaleCompare("blue-primary",option+1) == 0)
6472 {
6473 if (*option == '+')
6474 {
6475 (void) SetImageOption(image_info,option+1,"0.0");
6476 break;
6477 }
6478 (void) SetImageOption(image_info,option+1,argv[i+1]);
6479 break;
6480 }
6481 if (LocaleCompare("bordercolor",option+1) == 0)
6482 {
6483 if (*option == '+')
6484 {
6485 (void) DeleteImageOption(image_info,option+1);
6486 (void) QueryColorDatabase(BorderColor,&image_info->border_color,
6487 exception);
6488 break;
6489 }
6490 (void) QueryColorDatabase(argv[i+1],&image_info->border_color,
6491 exception);
6492 (void) SetImageOption(image_info,option+1,argv[i+1]);
6493 break;
6494 }
6495 if (LocaleCompare("box",option+1) == 0)
6496 {
6497 if (*option == '+')
6498 {
6499 (void) SetImageOption(image_info,"undercolor","none");
6500 break;
6501 }
6502 (void) SetImageOption(image_info,"undercolor",argv[i+1]);
6503 break;
6504 }
6505 break;
6506 }
6507 case 'c':
6508 {
6509 if (LocaleCompare("cache",option+1) == 0)
6510 {
6511 MagickSizeType
6512 limit;
6513
6514 limit=MagickResourceInfinity;
6515 if (LocaleCompare("unlimited",argv[i+1]) != 0)
cristyf2f27272009-12-17 14:48:46 +00006516 limit=(MagickSizeType) SiPrefixToDouble(argv[i+1],100.0);
cristy3ed852e2009-09-05 21:47:34 +00006517 (void) SetMagickResourceLimit(MemoryResource,limit);
6518 (void) SetMagickResourceLimit(MapResource,2*limit);
6519 break;
6520 }
6521 if (LocaleCompare("caption",option+1) == 0)
6522 {
6523 if (*option == '+')
6524 {
6525 (void) DeleteImageOption(image_info,option+1);
6526 break;
6527 }
6528 (void) SetImageOption(image_info,option+1,argv[i+1]);
6529 break;
6530 }
6531 if (LocaleCompare("channel",option+1) == 0)
6532 {
6533 if (*option == '+')
6534 {
6535 image_info->channel=DefaultChannels;
6536 break;
6537 }
6538 image_info->channel=(ChannelType) ParseChannelOption(argv[i+1]);
6539 break;
6540 }
6541 if (LocaleCompare("colors",option+1) == 0)
6542 {
cristye27293e2009-12-18 02:53:20 +00006543 image_info->colors=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006544 break;
6545 }
6546 if (LocaleCompare("colorspace",option+1) == 0)
6547 {
6548 if (*option == '+')
6549 {
6550 image_info->colorspace=UndefinedColorspace;
6551 (void) SetImageOption(image_info,option+1,"undefined");
6552 break;
6553 }
6554 image_info->colorspace=(ColorspaceType) ParseMagickOption(
6555 MagickColorspaceOptions,MagickFalse,argv[i+1]);
6556 (void) SetImageOption(image_info,option+1,argv[i+1]);
6557 break;
6558 }
6559 if (LocaleCompare("compress",option+1) == 0)
6560 {
6561 if (*option == '+')
6562 {
6563 image_info->compression=UndefinedCompression;
6564 (void) SetImageOption(image_info,option+1,"undefined");
6565 break;
6566 }
6567 image_info->compression=(CompressionType) ParseMagickOption(
6568 MagickCompressOptions,MagickFalse,argv[i+1]);
6569 (void) SetImageOption(image_info,option+1,argv[i+1]);
6570 break;
6571 }
6572 if (LocaleCompare("comment",option+1) == 0)
6573 {
6574 if (*option == '+')
6575 {
6576 (void) DeleteImageOption(image_info,option+1);
6577 break;
6578 }
6579 (void) SetImageOption(image_info,option+1,argv[i+1]);
6580 break;
6581 }
6582 if (LocaleCompare("compose",option+1) == 0)
6583 {
6584 if (*option == '+')
6585 {
6586 (void) SetImageOption(image_info,option+1,"undefined");
6587 break;
6588 }
6589 (void) SetImageOption(image_info,option+1,argv[i+1]);
6590 break;
6591 }
6592 if (LocaleCompare("compress",option+1) == 0)
6593 {
6594 if (*option == '+')
6595 {
6596 image_info->compression=UndefinedCompression;
6597 (void) SetImageOption(image_info,option+1,"undefined");
6598 break;
6599 }
6600 image_info->compression=(CompressionType) ParseMagickOption(
6601 MagickCompressOptions,MagickFalse,argv[i+1]);
6602 (void) SetImageOption(image_info,option+1,argv[i+1]);
6603 break;
6604 }
6605 break;
6606 }
6607 case 'd':
6608 {
6609 if (LocaleCompare("debug",option+1) == 0)
6610 {
6611 if (*option == '+')
6612 (void) SetLogEventMask("none");
6613 else
6614 (void) SetLogEventMask(argv[i+1]);
6615 image_info->debug=IsEventLogging();
6616 break;
6617 }
6618 if (LocaleCompare("define",option+1) == 0)
6619 {
6620 if (*option == '+')
6621 {
6622 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6623 (void) DeleteImageRegistry(argv[i+1]+9);
6624 else
6625 (void) DeleteImageOption(image_info,argv[i+1]);
6626 break;
6627 }
6628 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6629 {
6630 (void) DefineImageRegistry(StringRegistryType,argv[i+1]+9,
6631 exception);
6632 break;
6633 }
6634 (void) DefineImageOption(image_info,argv[i+1]);
6635 break;
6636 }
6637 if (LocaleCompare("delay",option+1) == 0)
6638 {
6639 if (*option == '+')
6640 {
6641 (void) SetImageOption(image_info,option+1,"0");
6642 break;
6643 }
6644 (void) SetImageOption(image_info,option+1,argv[i+1]);
6645 break;
6646 }
6647 if (LocaleCompare("density",option+1) == 0)
6648 {
6649 /*
6650 Set image density.
6651 */
6652 if (*option == '+')
6653 {
6654 if (image_info->density != (char *) NULL)
6655 image_info->density=DestroyString(image_info->density);
6656 (void) SetImageOption(image_info,option+1,"72");
6657 break;
6658 }
6659 (void) CloneString(&image_info->density,argv[i+1]);
6660 (void) SetImageOption(image_info,option+1,argv[i+1]);
6661 break;
6662 }
6663 if (LocaleCompare("depth",option+1) == 0)
6664 {
6665 if (*option == '+')
6666 {
6667 image_info->depth=MAGICKCORE_QUANTUM_DEPTH;
6668 break;
6669 }
cristye27293e2009-12-18 02:53:20 +00006670 image_info->depth=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006671 break;
6672 }
6673 if (LocaleCompare("display",option+1) == 0)
6674 {
6675 if (*option == '+')
6676 {
6677 if (image_info->server_name != (char *) NULL)
6678 image_info->server_name=DestroyString(
6679 image_info->server_name);
6680 break;
6681 }
6682 (void) CloneString(&image_info->server_name,argv[i+1]);
6683 break;
6684 }
6685 if (LocaleCompare("dispose",option+1) == 0)
6686 {
6687 if (*option == '+')
6688 {
6689 (void) SetImageOption(image_info,option+1,"undefined");
6690 break;
6691 }
6692 (void) SetImageOption(image_info,option+1,argv[i+1]);
6693 break;
6694 }
6695 if (LocaleCompare("dither",option+1) == 0)
6696 {
6697 if (*option == '+')
6698 {
6699 image_info->dither=MagickFalse;
6700 (void) SetImageOption(image_info,option+1,"undefined");
6701 break;
6702 }
6703 (void) SetImageOption(image_info,option+1,argv[i+1]);
6704 image_info->dither=MagickTrue;
6705 break;
6706 }
6707 break;
6708 }
6709 case 'e':
6710 {
6711 if (LocaleCompare("encoding",option+1) == 0)
6712 {
6713 if (*option == '+')
6714 {
6715 (void) SetImageOption(image_info,option+1,"undefined");
6716 break;
6717 }
6718 (void) SetImageOption(image_info,option+1,argv[i+1]);
6719 break;
6720 }
6721 if (LocaleCompare("endian",option+1) == 0)
6722 {
6723 if (*option == '+')
6724 {
6725 image_info->endian=UndefinedEndian;
6726 (void) SetImageOption(image_info,option+1,"undefined");
6727 break;
6728 }
6729 image_info->endian=(EndianType) ParseMagickOption(
6730 MagickEndianOptions,MagickFalse,argv[i+1]);
6731 (void) SetImageOption(image_info,option+1,argv[i+1]);
6732 break;
6733 }
6734 if (LocaleCompare("extract",option+1) == 0)
6735 {
6736 /*
6737 Set image extract geometry.
6738 */
6739 if (*option == '+')
6740 {
6741 if (image_info->extract != (char *) NULL)
6742 image_info->extract=DestroyString(image_info->extract);
6743 break;
6744 }
6745 (void) CloneString(&image_info->extract,argv[i+1]);
6746 break;
6747 }
6748 break;
6749 }
6750 case 'f':
6751 {
6752 if (LocaleCompare("fill",option+1) == 0)
6753 {
6754 if (*option == '+')
6755 {
6756 (void) SetImageOption(image_info,option+1,"none");
6757 break;
6758 }
6759 (void) SetImageOption(image_info,option+1,argv[i+1]);
6760 break;
6761 }
6762 if (LocaleCompare("filter",option+1) == 0)
6763 {
6764 if (*option == '+')
6765 {
6766 (void) SetImageOption(image_info,option+1,"undefined");
6767 break;
6768 }
6769 (void) SetImageOption(image_info,option+1,argv[i+1]);
6770 break;
6771 }
6772 if (LocaleCompare("font",option+1) == 0)
6773 {
6774 if (*option == '+')
6775 {
6776 if (image_info->font != (char *) NULL)
6777 image_info->font=DestroyString(image_info->font);
6778 break;
6779 }
6780 (void) CloneString(&image_info->font,argv[i+1]);
6781 break;
6782 }
6783 if (LocaleCompare("format",option+1) == 0)
6784 {
6785 register const char
6786 *q;
6787
6788 for (q=strchr(argv[i+1],'%'); q != (char *) NULL; q=strchr(q+1,'%'))
6789 if (strchr("gkrz@[#",*(q+1)) != (char *) NULL)
6790 image_info->ping=MagickFalse;
6791 (void) SetImageOption(image_info,option+1,argv[i+1]);
6792 break;
6793 }
6794 if (LocaleCompare("fuzz",option+1) == 0)
6795 {
6796 if (*option == '+')
6797 {
6798 image_info->fuzz=0.0;
6799 (void) SetImageOption(image_info,option+1,"0");
6800 break;
6801 }
cristyf2f27272009-12-17 14:48:46 +00006802 image_info->fuzz=SiPrefixToDouble(argv[i+1],(double) QuantumRange+
cristy3ed852e2009-09-05 21:47:34 +00006803 1.0);
6804 (void) SetImageOption(image_info,option+1,argv[i+1]);
6805 break;
6806 }
6807 break;
6808 }
6809 case 'g':
6810 {
6811 if (LocaleCompare("gravity",option+1) == 0)
6812 {
6813 if (*option == '+')
6814 {
6815 (void) SetImageOption(image_info,option+1,"undefined");
6816 break;
6817 }
6818 (void) SetImageOption(image_info,option+1,argv[i+1]);
6819 break;
6820 }
6821 if (LocaleCompare("green-primary",option+1) == 0)
6822 {
6823 if (*option == '+')
6824 {
6825 (void) SetImageOption(image_info,option+1,"0.0");
6826 break;
6827 }
6828 (void) SetImageOption(image_info,option+1,argv[i+1]);
6829 break;
6830 }
6831 break;
6832 }
6833 case 'i':
6834 {
6835 if (LocaleCompare("intent",option+1) == 0)
6836 {
6837 if (*option == '+')
6838 {
6839 (void) SetImageOption(image_info,option+1,"undefined");
6840 break;
6841 }
6842 (void) SetImageOption(image_info,option+1,argv[i+1]);
6843 break;
6844 }
6845 if (LocaleCompare("interlace",option+1) == 0)
6846 {
6847 if (*option == '+')
6848 {
6849 image_info->interlace=UndefinedInterlace;
6850 (void) SetImageOption(image_info,option+1,"undefined");
6851 break;
6852 }
6853 image_info->interlace=(InterlaceType) ParseMagickOption(
6854 MagickInterlaceOptions,MagickFalse,argv[i+1]);
6855 (void) SetImageOption(image_info,option+1,argv[i+1]);
6856 break;
6857 }
cristyb32b90a2009-09-07 21:45:48 +00006858 if (LocaleCompare("interline-spacing",option+1) == 0)
6859 {
6860 if (*option == '+')
6861 {
6862 (void) SetImageOption(image_info,option+1,"undefined");
6863 break;
6864 }
6865 (void) SetImageOption(image_info,option+1,argv[i+1]);
6866 break;
6867 }
cristy3ed852e2009-09-05 21:47:34 +00006868 if (LocaleCompare("interpolate",option+1) == 0)
6869 {
6870 if (*option == '+')
6871 {
6872 (void) SetImageOption(image_info,option+1,"undefined");
6873 break;
6874 }
6875 (void) SetImageOption(image_info,option+1,argv[i+1]);
6876 break;
6877 }
6878 if (LocaleCompare("interword-spacing",option+1) == 0)
6879 {
6880 if (*option == '+')
6881 {
6882 (void) SetImageOption(image_info,option+1,"undefined");
6883 break;
6884 }
6885 (void) SetImageOption(image_info,option+1,argv[i+1]);
6886 break;
6887 }
6888 break;
6889 }
6890 case 'k':
6891 {
6892 if (LocaleCompare("kerning",option+1) == 0)
6893 {
6894 if (*option == '+')
6895 {
6896 (void) SetImageOption(image_info,option+1,"undefined");
6897 break;
6898 }
6899 (void) SetImageOption(image_info,option+1,argv[i+1]);
6900 break;
6901 }
6902 break;
6903 }
6904 case 'l':
6905 {
6906 if (LocaleCompare("label",option+1) == 0)
6907 {
6908 if (*option == '+')
6909 {
6910 (void) DeleteImageOption(image_info,option+1);
6911 break;
6912 }
6913 (void) SetImageOption(image_info,option+1,argv[i+1]);
6914 break;
6915 }
6916 if (LocaleCompare("limit",option+1) == 0)
6917 {
6918 MagickSizeType
6919 limit;
6920
6921 ResourceType
6922 type;
6923
6924 if (*option == '+')
6925 break;
6926 type=(ResourceType) ParseMagickOption(MagickResourceOptions,
6927 MagickFalse,argv[i+1]);
6928 limit=MagickResourceInfinity;
6929 if (LocaleCompare("unlimited",argv[i+2]) != 0)
cristyf2f27272009-12-17 14:48:46 +00006930 limit=(MagickSizeType) SiPrefixToDouble(argv[i+2],100.0);
cristy3ed852e2009-09-05 21:47:34 +00006931 (void) SetMagickResourceLimit(type,limit);
6932 break;
6933 }
6934 if (LocaleCompare("list",option+1) == 0)
6935 {
6936 long
6937 list;
6938
6939 /*
6940 Display configuration list.
6941 */
6942 list=ParseMagickOption(MagickListOptions,MagickFalse,argv[i+1]);
6943 switch (list)
6944 {
6945 case MagickCoderOptions:
6946 {
6947 (void) ListCoderInfo((FILE *) NULL,exception);
6948 break;
6949 }
6950 case MagickColorOptions:
6951 {
6952 (void) ListColorInfo((FILE *) NULL,exception);
6953 break;
6954 }
6955 case MagickConfigureOptions:
6956 {
6957 (void) ListConfigureInfo((FILE *) NULL,exception);
6958 break;
6959 }
6960 case MagickDelegateOptions:
6961 {
6962 (void) ListDelegateInfo((FILE *) NULL,exception);
6963 break;
6964 }
6965 case MagickFontOptions:
6966 {
6967 (void) ListTypeInfo((FILE *) NULL,exception);
6968 break;
6969 }
6970 case MagickFormatOptions:
6971 {
6972 (void) ListMagickInfo((FILE *) NULL,exception);
6973 break;
6974 }
6975 case MagickLocaleOptions:
6976 {
6977 (void) ListLocaleInfo((FILE *) NULL,exception);
6978 break;
6979 }
6980 case MagickLogOptions:
6981 {
6982 (void) ListLogInfo((FILE *) NULL,exception);
6983 break;
6984 }
6985 case MagickMagicOptions:
6986 {
6987 (void) ListMagicInfo((FILE *) NULL,exception);
6988 break;
6989 }
6990 case MagickMimeOptions:
6991 {
6992 (void) ListMimeInfo((FILE *) NULL,exception);
6993 break;
6994 }
6995 case MagickModuleOptions:
6996 {
6997 (void) ListModuleInfo((FILE *) NULL,exception);
6998 break;
6999 }
7000 case MagickPolicyOptions:
7001 {
7002 (void) ListPolicyInfo((FILE *) NULL,exception);
7003 break;
7004 }
7005 case MagickResourceOptions:
7006 {
7007 (void) ListMagickResourceInfo((FILE *) NULL,exception);
7008 break;
7009 }
7010 case MagickThresholdOptions:
7011 {
7012 (void) ListThresholdMaps((FILE *) NULL,exception);
7013 break;
7014 }
7015 default:
7016 {
7017 (void) ListMagickOptions((FILE *) NULL,(MagickOption) list,
7018 exception);
7019 break;
7020 }
7021 }
7022 }
7023 if (LocaleCompare("log",option+1) == 0)
7024 {
7025 if (*option == '+')
7026 break;
7027 (void) SetLogFormat(argv[i+1]);
7028 break;
7029 }
7030 if (LocaleCompare("loop",option+1) == 0)
7031 {
7032 if (*option == '+')
7033 {
7034 (void) SetImageOption(image_info,option+1,"0");
7035 break;
7036 }
7037 (void) SetImageOption(image_info,option+1,argv[i+1]);
7038 break;
7039 }
7040 break;
7041 }
7042 case 'm':
7043 {
7044 if (LocaleCompare("matte",option+1) == 0)
7045 {
7046 if (*option == '+')
7047 {
7048 (void) SetImageOption(image_info,option+1,"false");
7049 break;
7050 }
7051 (void) SetImageOption(image_info,option+1,"true");
7052 break;
7053 }
7054 if (LocaleCompare("mattecolor",option+1) == 0)
7055 {
7056 if (*option == '+')
7057 {
7058 (void) SetImageOption(image_info,option+1,argv[i+1]);
7059 (void) QueryColorDatabase(MatteColor,&image_info->matte_color,
7060 exception);
7061 break;
7062 }
7063 (void) SetImageOption(image_info,option+1,argv[i+1]);
7064 (void) QueryColorDatabase(argv[i+1],&image_info->matte_color,
7065 exception);
7066 break;
7067 }
7068 if (LocaleCompare("monitor",option+1) == 0)
7069 {
7070 (void) SetImageInfoProgressMonitor(image_info,MonitorProgress,
7071 (void *) NULL);
7072 break;
7073 }
7074 if (LocaleCompare("monochrome",option+1) == 0)
7075 {
7076 image_info->monochrome=(*option == '-') ? MagickTrue : MagickFalse;
7077 break;
7078 }
7079 break;
7080 }
7081 case 'o':
7082 {
7083 if (LocaleCompare("orient",option+1) == 0)
7084 {
7085 if (*option == '+')
7086 {
7087 image_info->orientation=UndefinedOrientation;
7088 (void) SetImageOption(image_info,option+1,"undefined");
7089 break;
7090 }
7091 image_info->orientation=(OrientationType) ParseMagickOption(
7092 MagickOrientationOptions,MagickFalse,argv[i+1]);
7093 (void) SetImageOption(image_info,option+1,"undefined");
7094 break;
7095 }
7096 }
7097 case 'p':
7098 {
7099 if (LocaleCompare("page",option+1) == 0)
7100 {
7101 char
7102 *canonical_page,
7103 page[MaxTextExtent];
7104
7105 const char
7106 *image_option;
7107
7108 MagickStatusType
7109 flags;
7110
7111 RectangleInfo
7112 geometry;
7113
7114 if (*option == '+')
7115 {
7116 (void) DeleteImageOption(image_info,option+1);
7117 (void) CloneString(&image_info->page,(char *) NULL);
7118 break;
7119 }
7120 (void) ResetMagickMemory(&geometry,0,sizeof(geometry));
7121 image_option=GetImageOption(image_info,"page");
7122 if (image_option != (const char *) NULL)
7123 flags=ParseAbsoluteGeometry(image_option,&geometry);
7124 canonical_page=GetPageGeometry(argv[i+1]);
7125 flags=ParseAbsoluteGeometry(canonical_page,&geometry);
7126 canonical_page=DestroyString(canonical_page);
7127 (void) FormatMagickString(page,MaxTextExtent,"%lux%lu",
7128 geometry.width,geometry.height);
7129 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
7130 (void) FormatMagickString(page,MaxTextExtent,"%lux%lu%+ld%+ld",
7131 geometry.width,geometry.height,geometry.x,geometry.y);
7132 (void) SetImageOption(image_info,option+1,page);
7133 (void) CloneString(&image_info->page,page);
7134 break;
7135 }
7136 if (LocaleCompare("pen",option+1) == 0)
7137 {
7138 if (*option == '+')
7139 {
7140 (void) SetImageOption(image_info,option+1,"none");
7141 break;
7142 }
7143 (void) SetImageOption(image_info,option+1,argv[i+1]);
7144 break;
7145 }
7146 if (LocaleCompare("ping",option+1) == 0)
7147 {
7148 image_info->ping=(*option == '-') ? MagickTrue : MagickFalse;
7149 break;
7150 }
7151 if (LocaleCompare("pointsize",option+1) == 0)
7152 {
7153 if (*option == '+')
7154 geometry_info.rho=0.0;
7155 else
7156 (void) ParseGeometry(argv[i+1],&geometry_info);
7157 image_info->pointsize=geometry_info.rho;
7158 break;
7159 }
cristye7f51092010-01-17 00:39:37 +00007160 if (LocaleCompare("precision",option+1) == 0)
7161 {
cristybf2766a2010-01-17 03:33:23 +00007162 (void) SetMagickPrecision(StringToInteger(argv[i+1]));
cristye7f51092010-01-17 00:39:37 +00007163 break;
7164 }
cristy3ed852e2009-09-05 21:47:34 +00007165 if (LocaleCompare("preview",option+1) == 0)
7166 {
7167 /*
7168 Preview image.
7169 */
7170 if (*option == '+')
7171 {
7172 image_info->preview_type=UndefinedPreview;
7173 break;
7174 }
7175 image_info->preview_type=(PreviewType) ParseMagickOption(
7176 MagickPreviewOptions,MagickFalse,argv[i+1]);
7177 break;
7178 }
7179 break;
7180 }
7181 case 'q':
7182 {
7183 if (LocaleCompare("quality",option+1) == 0)
7184 {
7185 /*
7186 Set image compression quality.
7187 */
7188 if (*option == '+')
7189 {
7190 image_info->quality=UndefinedCompressionQuality;
7191 (void) SetImageOption(image_info,option+1,"0");
7192 break;
7193 }
cristye27293e2009-12-18 02:53:20 +00007194 image_info->quality=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007195 (void) SetImageOption(image_info,option+1,argv[i+1]);
7196 break;
7197 }
7198 if (LocaleCompare("quiet",option+1) == 0)
7199 {
7200 static WarningHandler
7201 warning_handler = (WarningHandler) NULL;
7202
7203 if (*option == '+')
7204 {
7205 /*
7206 Restore error or warning messages.
7207 */
7208 warning_handler=SetWarningHandler(warning_handler);
7209 break;
7210 }
7211 /*
7212 Suppress error or warning messages.
7213 */
7214 warning_handler=SetWarningHandler((WarningHandler) NULL);
7215 break;
7216 }
7217 break;
7218 }
7219 case 'r':
7220 {
7221 if (LocaleCompare("red-primary",option+1) == 0)
7222 {
7223 if (*option == '+')
7224 {
7225 (void) SetImageOption(image_info,option+1,"0.0");
7226 break;
7227 }
7228 (void) SetImageOption(image_info,option+1,argv[i+1]);
7229 break;
7230 }
7231 break;
7232 }
7233 case 's':
7234 {
7235 if (LocaleCompare("sampling-factor",option+1) == 0)
7236 {
7237 /*
7238 Set image sampling factor.
7239 */
7240 if (*option == '+')
7241 {
7242 if (image_info->sampling_factor != (char *) NULL)
7243 image_info->sampling_factor=DestroyString(
7244 image_info->sampling_factor);
7245 break;
7246 }
7247 (void) CloneString(&image_info->sampling_factor,argv[i+1]);
7248 break;
7249 }
7250 if (LocaleCompare("scene",option+1) == 0)
7251 {
7252 /*
7253 Set image scene.
7254 */
7255 if (*option == '+')
7256 {
7257 image_info->scene=0;
7258 (void) SetImageOption(image_info,option+1,"0");
7259 break;
7260 }
cristye27293e2009-12-18 02:53:20 +00007261 image_info->scene=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007262 (void) SetImageOption(image_info,option+1,argv[i+1]);
7263 break;
7264 }
7265 if (LocaleCompare("seed",option+1) == 0)
7266 {
7267 unsigned long
7268 seed;
7269
7270 if (*option == '+')
7271 {
7272 seed=(unsigned long) time((time_t *) NULL);
7273 SeedPseudoRandomGenerator(seed);
7274 break;
7275 }
cristye27293e2009-12-18 02:53:20 +00007276 seed=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007277 SeedPseudoRandomGenerator(seed);
7278 break;
7279 }
7280 if (LocaleCompare("size",option+1) == 0)
7281 {
7282 if (*option == '+')
7283 {
7284 if (image_info->size != (char *) NULL)
7285 image_info->size=DestroyString(image_info->size);
7286 break;
7287 }
7288 (void) CloneString(&image_info->size,argv[i+1]);
7289 break;
7290 }
7291 if (LocaleCompare("stroke",option+1) == 0)
7292 {
7293 if (*option == '+')
7294 {
7295 (void) SetImageOption(image_info,option+1,"none");
7296 break;
7297 }
7298 (void) SetImageOption(image_info,option+1,argv[i+1]);
7299 break;
7300 }
7301 if (LocaleCompare("strokewidth",option+1) == 0)
7302 {
7303 if (*option == '+')
7304 {
7305 (void) SetImageOption(image_info,option+1,"0");
7306 break;
7307 }
7308 (void) SetImageOption(image_info,option+1,argv[i+1]);
7309 break;
7310 }
7311 break;
7312 }
7313 case 't':
7314 {
7315 if (LocaleCompare("taint",option+1) == 0)
7316 {
7317 if (*option == '+')
7318 {
7319 (void) SetImageOption(image_info,option+1,"false");
7320 break;
7321 }
7322 (void) SetImageOption(image_info,option+1,"true");
7323 break;
7324 }
7325 if (LocaleCompare("texture",option+1) == 0)
7326 {
7327 if (*option == '+')
7328 {
7329 if (image_info->texture != (char *) NULL)
7330 image_info->texture=DestroyString(image_info->texture);
7331 break;
7332 }
7333 (void) CloneString(&image_info->texture,argv[i+1]);
7334 break;
7335 }
7336 if (LocaleCompare("tile-offset",option+1) == 0)
7337 {
7338 if (*option == '+')
7339 {
7340 (void) SetImageOption(image_info,option+1,"0");
7341 break;
7342 }
7343 (void) SetImageOption(image_info,option+1,argv[i+1]);
7344 break;
7345 }
7346 if (LocaleCompare("transparent-color",option+1) == 0)
7347 {
7348 if (*option == '+')
7349 {
7350 (void) QueryColorDatabase("none",&image_info->transparent_color, exception);
7351 (void) SetImageOption(image_info,option+1,"none");
7352 break;
7353 }
7354 (void) QueryColorDatabase(argv[i+1],&image_info->transparent_color,
7355 exception);
7356 (void) SetImageOption(image_info,option+1,argv[i+1]);
7357 break;
7358 }
7359 if (LocaleCompare("type",option+1) == 0)
7360 {
7361 if (*option == '+')
7362 {
7363 image_info->type=UndefinedType;
7364 (void) SetImageOption(image_info,option+1,"undefined");
7365 break;
7366 }
7367 image_info->type=(ImageType) ParseMagickOption(MagickTypeOptions,
7368 MagickFalse,argv[i+1]);
7369 (void) SetImageOption(image_info,option+1,argv[i+1]);
7370 break;
7371 }
7372 break;
7373 }
7374 case 'u':
7375 {
7376 if (LocaleCompare("undercolor",option+1) == 0)
7377 {
7378 if (*option == '+')
7379 {
7380 (void) DeleteImageOption(image_info,option+1);
7381 break;
7382 }
7383 (void) SetImageOption(image_info,option+1,argv[i+1]);
7384 break;
7385 }
7386 if (LocaleCompare("units",option+1) == 0)
7387 {
7388 if (*option == '+')
7389 {
7390 image_info->units=UndefinedResolution;
7391 (void) SetImageOption(image_info,option+1,"undefined");
7392 break;
7393 }
7394 image_info->units=(ResolutionType) ParseMagickOption(
7395 MagickResolutionOptions,MagickFalse,argv[i+1]);
7396 (void) SetImageOption(image_info,option+1,argv[i+1]);
7397 break;
7398 }
7399 break;
7400 }
7401 case 'v':
7402 {
7403 if (LocaleCompare("verbose",option+1) == 0)
7404 {
7405 if (*option == '+')
7406 {
7407 image_info->verbose=MagickFalse;
7408 break;
7409 }
7410 image_info->verbose=MagickTrue;
7411 image_info->ping=MagickFalse;
7412 break;
7413 }
7414 if (LocaleCompare("view",option+1) == 0)
7415 {
7416 if (*option == '+')
7417 {
7418 if (image_info->view != (char *) NULL)
7419 image_info->view=DestroyString(image_info->view);
7420 break;
7421 }
7422 (void) CloneString(&image_info->view,argv[i+1]);
7423 break;
7424 }
7425 if (LocaleCompare("virtual-pixel",option+1) == 0)
7426 {
7427 if (*option == '+')
7428 {
7429 image_info->virtual_pixel_method=UndefinedVirtualPixelMethod;
7430 (void) SetImageOption(image_info,option+1,"undefined");
7431 break;
7432 }
7433 image_info->virtual_pixel_method=(VirtualPixelMethod)
7434 ParseMagickOption(MagickVirtualPixelOptions,MagickFalse,
7435 argv[i+1]);
7436 (void) SetImageOption(image_info,option+1,argv[i+1]);
7437 break;
7438 }
7439 break;
7440 }
7441 case 'w':
7442 {
7443 if (LocaleCompare("white-point",option+1) == 0)
7444 {
7445 if (*option == '+')
7446 {
7447 (void) SetImageOption(image_info,option+1,"0.0");
7448 break;
7449 }
7450 (void) SetImageOption(image_info,option+1,argv[i+1]);
7451 break;
7452 }
7453 break;
7454 }
7455 default:
7456 break;
7457 }
7458 i+=count;
7459 }
7460 return(MagickTrue);
7461}
7462
7463/*
7464%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7465% %
7466% %
7467% %
7468+ M o g r i f y I m a g e L i s t %
7469% %
7470% %
7471% %
7472%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7473%
7474% MogrifyImageList() applies any command line options that might affect the
7475% entire image list (e.g. -append, -coalesce, etc.).
7476%
7477% The format of the MogrifyImage method is:
7478%
7479% MagickBooleanType MogrifyImageList(ImageInfo *image_info,const int argc,
7480% const char **argv,Image **images,ExceptionInfo *exception)
7481%
7482% A description of each parameter follows:
7483%
7484% o image_info: the image info..
7485%
7486% o argc: Specifies a pointer to an integer describing the number of
7487% elements in the argument vector.
7488%
7489% o argv: Specifies a pointer to a text array containing the command line
7490% arguments.
7491%
7492% o images: the images.
7493%
7494% o exception: return any errors or warnings in this structure.
7495%
7496*/
7497WandExport MagickBooleanType MogrifyImageList(ImageInfo *image_info,
7498 const int argc,const char **argv,Image **images,ExceptionInfo *exception)
7499{
7500 ChannelType
7501 channel;
7502
7503 const char
7504 *option;
7505
7506 long
7507 count,
7508 index;
7509
7510 MagickStatusType
7511 status;
7512
7513 QuantizeInfo
7514 *quantize_info;
7515
7516 register long
7517 i;
7518
7519 /*
7520 Apply options to the image list.
7521 */
7522 assert(image_info != (ImageInfo *) NULL);
7523 assert(image_info->signature == MagickSignature);
7524 assert(images != (Image **) NULL);
7525 assert((*images)->signature == MagickSignature);
7526 if ((*images)->debug != MagickFalse)
7527 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
7528 (*images)->filename);
7529 if ((argc <= 0) || (*argv == (char *) NULL))
7530 return(MagickTrue);
7531 quantize_info=AcquireQuantizeInfo(image_info);
7532 channel=image_info->channel;
7533 status=MagickTrue;
7534 for (i=0; i < (long) argc; i++)
7535 {
cristy74fe8f12009-10-03 19:09:01 +00007536 if (*images == (Image *) NULL)
7537 break;
cristy3ed852e2009-09-05 21:47:34 +00007538 option=argv[i];
7539 if (IsMagickOption(option) == MagickFalse)
7540 continue;
7541 count=MagickMax(ParseMagickOption(MagickCommandOptions,MagickFalse,option),
7542 0L);
7543 if ((i+count) >= argc)
7544 break;
7545 status=MogrifyImageInfo(image_info,count+1,argv+i,exception);
7546 switch (*(option+1))
7547 {
7548 case 'a':
7549 {
7550 if (LocaleCompare("affinity",option+1) == 0)
7551 {
7552 (void) SyncImagesSettings(image_info,*images);
7553 if (*option == '+')
7554 {
7555 (void) RemapImages(quantize_info,*images,(Image *) NULL);
7556 InheritException(exception,&(*images)->exception);
7557 break;
7558 }
7559 i++;
7560 break;
7561 }
7562 if (LocaleCompare("append",option+1) == 0)
7563 {
7564 Image
7565 *append_image;
7566
7567 (void) SyncImagesSettings(image_info,*images);
7568 append_image=AppendImages(*images,*option == '-' ? MagickTrue :
7569 MagickFalse,exception);
7570 if (append_image == (Image *) NULL)
7571 {
7572 status=MagickFalse;
7573 break;
7574 }
7575 *images=DestroyImageList(*images);
7576 *images=append_image;
7577 break;
7578 }
7579 if (LocaleCompare("average",option+1) == 0)
7580 {
7581 Image
7582 *average_image;
7583
7584 (void) SyncImagesSettings(image_info,*images);
7585 average_image=AverageImages(*images,exception);
7586 if (average_image == (Image *) NULL)
7587 {
7588 status=MagickFalse;
7589 break;
7590 }
7591 *images=DestroyImageList(*images);
7592 *images=average_image;
7593 break;
7594 }
7595 break;
7596 }
7597 case 'c':
7598 {
7599 if (LocaleCompare("channel",option+1) == 0)
7600 {
7601 if (*option == '+')
7602 {
7603 channel=DefaultChannels;
7604 break;
7605 }
7606 channel=(ChannelType) ParseChannelOption(argv[i+1]);
7607 break;
7608 }
7609 if (LocaleCompare("clut",option+1) == 0)
7610 {
7611 Image
7612 *clut_image,
7613 *image;
7614
7615 (void) SyncImagesSettings(image_info,*images);
7616 image=RemoveFirstImageFromList(images);
7617 clut_image=RemoveFirstImageFromList(images);
7618 if (clut_image == (Image *) NULL)
7619 {
7620 status=MagickFalse;
7621 break;
7622 }
7623 (void) ClutImageChannel(image,channel,clut_image);
7624 clut_image=DestroyImage(clut_image);
7625 InheritException(exception,&image->exception);
7626 *images=DestroyImageList(*images);
7627 *images=image;
7628 break;
7629 }
7630 if (LocaleCompare("coalesce",option+1) == 0)
7631 {
7632 Image
7633 *coalesce_image;
7634
7635 (void) SyncImagesSettings(image_info,*images);
7636 coalesce_image=CoalesceImages(*images,exception);
7637 if (coalesce_image == (Image *) NULL)
7638 {
7639 status=MagickFalse;
7640 break;
7641 }
7642 *images=DestroyImageList(*images);
7643 *images=coalesce_image;
7644 break;
7645 }
7646 if (LocaleCompare("combine",option+1) == 0)
7647 {
7648 Image
7649 *combine_image;
7650
7651 (void) SyncImagesSettings(image_info,*images);
7652 combine_image=CombineImages(*images,channel,exception);
7653 if (combine_image == (Image *) NULL)
7654 {
7655 status=MagickFalse;
7656 break;
7657 }
7658 *images=DestroyImageList(*images);
7659 *images=combine_image;
7660 break;
7661 }
7662 if (LocaleCompare("composite",option+1) == 0)
7663 {
7664 Image
7665 *mask_image,
7666 *composite_image,
7667 *image;
7668
7669 RectangleInfo
7670 geometry;
7671
7672 (void) SyncImagesSettings(image_info,*images);
7673 image=RemoveFirstImageFromList(images);
7674 composite_image=RemoveFirstImageFromList(images);
7675 if (composite_image == (Image *) NULL)
7676 {
7677 status=MagickFalse;
7678 break;
7679 }
7680 (void) TransformImage(&composite_image,(char *) NULL,
7681 composite_image->geometry);
7682 SetGeometry(composite_image,&geometry);
7683 (void) ParseAbsoluteGeometry(composite_image->geometry,&geometry);
7684 GravityAdjustGeometry(image->columns,image->rows,image->gravity,
7685 &geometry);
7686 mask_image=RemoveFirstImageFromList(images);
7687 if (mask_image != (Image *) NULL)
7688 {
7689 if ((image->compose == DisplaceCompositeOp) ||
7690 (image->compose == DistortCompositeOp))
7691 {
7692 /*
7693 Merge Y displacement into X displacement image.
7694 */
7695 (void) CompositeImage(composite_image,CopyGreenCompositeOp,
7696 mask_image,0,0);
7697 mask_image=DestroyImage(mask_image);
7698 }
7699 else
7700 {
7701 /*
7702 Set a blending mask for the composition.
7703 */
7704 image->mask=mask_image;
7705 (void) NegateImage(image->mask,MagickFalse);
7706 }
7707 }
7708 (void) CompositeImageChannel(image,channel,image->compose,
7709 composite_image,geometry.x,geometry.y);
7710 if (image->mask != (Image *) NULL)
7711 image->mask=DestroyImage(image->mask);
7712 composite_image=DestroyImage(composite_image);
7713 InheritException(exception,&image->exception);
7714 *images=DestroyImageList(*images);
7715 *images=image;
7716 break;
7717 }
7718 if (LocaleCompare("crop",option+1) == 0)
7719 {
7720 MagickStatusType
7721 flags;
7722
7723 RectangleInfo
7724 geometry;
7725
7726 (void) SyncImagesSettings(image_info,*images);
7727 flags=ParseGravityGeometry(*images,argv[i+1],&geometry,exception);
7728 if (((geometry.width == 0) && (geometry.height == 0)) ||
7729 ((flags & XValue) != 0) || ((flags & YValue) != 0))
7730 break;
7731 (void) TransformImages(images,argv[i+1],(char *) NULL);
7732 InheritException(exception,&(*images)->exception);
7733 break;
7734 }
7735 break;
7736 }
7737 case 'd':
7738 {
7739 if (LocaleCompare("deconstruct",option+1) == 0)
7740 {
7741 Image
7742 *deconstruct_image;
7743
7744 (void) SyncImagesSettings(image_info,*images);
7745 deconstruct_image=DeconstructImages(*images,exception);
7746 if (deconstruct_image == (Image *) NULL)
7747 {
7748 status=MagickFalse;
7749 break;
7750 }
7751 *images=DestroyImageList(*images);
7752 *images=deconstruct_image;
7753 break;
7754 }
7755 if (LocaleCompare("delete",option+1) == 0)
7756 {
7757 if (*option == '+')
7758 DeleteImages(images,"-1",exception);
7759 else
7760 DeleteImages(images,argv[i+1],exception);
7761 break;
7762 }
7763 if (LocaleCompare("dither",option+1) == 0)
7764 {
7765 if (*option == '+')
7766 {
7767 quantize_info->dither=MagickFalse;
7768 break;
7769 }
7770 quantize_info->dither=MagickTrue;
7771 quantize_info->dither_method=(DitherMethod) ParseMagickOption(
7772 MagickDitherOptions,MagickFalse,argv[i+1]);
7773 break;
7774 }
7775 break;
7776 }
7777 case 'f':
7778 {
cristyf0a247f2009-10-04 00:20:03 +00007779 if (LocaleCompare("fft",option+1) == 0)
7780 {
7781 Image
7782 *fourier_image;
7783
7784 /*
7785 Implements the discrete Fourier transform (DFT).
7786 */
7787 (void) SyncImageSettings(image_info,*images);
7788 fourier_image=ForwardFourierTransformImage(*images,*option == '-' ?
7789 MagickTrue : MagickFalse,exception);
7790 if (fourier_image == (Image *) NULL)
7791 break;
7792 *images=DestroyImage(*images);
7793 *images=fourier_image;
7794 break;
7795 }
cristy3ed852e2009-09-05 21:47:34 +00007796 if (LocaleCompare("flatten",option+1) == 0)
7797 {
7798 Image
7799 *flatten_image;
7800
7801 (void) SyncImagesSettings(image_info,*images);
7802 flatten_image=MergeImageLayers(*images,FlattenLayer,exception);
7803 if (flatten_image == (Image *) NULL)
7804 break;
7805 *images=DestroyImageList(*images);
7806 *images=flatten_image;
7807 break;
7808 }
7809 if (LocaleCompare("fx",option+1) == 0)
7810 {
7811 Image
7812 *fx_image;
7813
7814 (void) SyncImagesSettings(image_info,*images);
7815 fx_image=FxImageChannel(*images,channel,argv[i+1],exception);
7816 if (fx_image == (Image *) NULL)
7817 {
7818 status=MagickFalse;
7819 break;
7820 }
7821 *images=DestroyImageList(*images);
7822 *images=fx_image;
7823 break;
7824 }
7825 break;
7826 }
7827 case 'h':
7828 {
7829 if (LocaleCompare("hald-clut",option+1) == 0)
7830 {
7831 Image
7832 *hald_image,
7833 *image;
7834
7835 (void) SyncImagesSettings(image_info,*images);
7836 image=RemoveFirstImageFromList(images);
7837 hald_image=RemoveFirstImageFromList(images);
7838 if (hald_image == (Image *) NULL)
7839 {
7840 status=MagickFalse;
7841 break;
7842 }
7843 (void) HaldClutImageChannel(image,channel,hald_image);
7844 hald_image=DestroyImage(hald_image);
7845 InheritException(exception,&image->exception);
cristy0aff6ea2009-11-14 01:40:53 +00007846 if (*images != (Image *) NULL)
7847 *images=DestroyImageList(*images);
cristy3ed852e2009-09-05 21:47:34 +00007848 *images=image;
7849 break;
7850 }
7851 break;
7852 }
7853 case 'i':
7854 {
7855 if (LocaleCompare("ift",option+1) == 0)
7856 {
7857 Image
cristy8587f882009-11-13 20:28:49 +00007858 *fourier_image,
7859 *magnitude_image,
7860 *phase_image;
cristy3ed852e2009-09-05 21:47:34 +00007861
7862 /*
7863 Implements the inverse fourier discrete Fourier transform (DFT).
7864 */
7865 (void) SyncImagesSettings(image_info,*images);
cristy8587f882009-11-13 20:28:49 +00007866 magnitude_image=RemoveFirstImageFromList(images);
7867 phase_image=RemoveFirstImageFromList(images);
7868 if (phase_image == (Image *) NULL)
7869 {
7870 status=MagickFalse;
7871 break;
7872 }
7873 fourier_image=InverseFourierTransformImage(magnitude_image,
7874 phase_image,*option == '-' ? MagickTrue : MagickFalse,exception);
cristy3ed852e2009-09-05 21:47:34 +00007875 if (fourier_image == (Image *) NULL)
7876 break;
cristy0aff6ea2009-11-14 01:40:53 +00007877 if (*images != (Image *) NULL)
7878 *images=DestroyImage(*images);
cristy3ed852e2009-09-05 21:47:34 +00007879 *images=fourier_image;
7880 break;
7881 }
7882 if (LocaleCompare("insert",option+1) == 0)
7883 {
7884 Image
7885 *p,
7886 *q;
7887
7888 index=0;
7889 if (*option != '+')
cristyf2f27272009-12-17 14:48:46 +00007890 index=StringToLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007891 p=RemoveLastImageFromList(images);
7892 if (p == (Image *) NULL)
7893 {
7894 (void) ThrowMagickException(exception,GetMagickModule(),
7895 OptionError,"NoSuchImage","`%s'",argv[i+1]);
7896 status=MagickFalse;
7897 break;
7898 }
7899 q=p;
7900 if (index == 0)
7901 PrependImageToList(images,q);
7902 else
7903 if (index == (long) GetImageListLength(*images))
7904 AppendImageToList(images,q);
7905 else
7906 {
7907 q=GetImageFromList(*images,index-1);
7908 if (q == (Image *) NULL)
7909 {
7910 (void) ThrowMagickException(exception,GetMagickModule(),
7911 OptionError,"NoSuchImage","`%s'",argv[i+1]);
7912 status=MagickFalse;
7913 break;
7914 }
7915 InsertImageInList(&q,p);
7916 }
7917 *images=GetFirstImageInList(q);
7918 break;
7919 }
7920 break;
7921 }
7922 case 'l':
7923 {
7924 if (LocaleCompare("layers",option+1) == 0)
7925 {
7926 Image
7927 *layers;
7928
7929 ImageLayerMethod
7930 method;
7931
7932 (void) SyncImagesSettings(image_info,*images);
7933 layers=(Image *) NULL;
7934 method=(ImageLayerMethod) ParseMagickOption(MagickLayerOptions,
7935 MagickFalse,argv[i+1]);
7936 switch (method)
7937 {
7938 case CoalesceLayer:
7939 {
7940 layers=CoalesceImages(*images,exception);
7941 break;
7942 }
7943 case CompareAnyLayer:
7944 case CompareClearLayer:
7945 case CompareOverlayLayer:
7946 default:
7947 {
7948 layers=CompareImageLayers(*images,method,exception);
7949 break;
7950 }
7951 case MergeLayer:
7952 case FlattenLayer:
7953 case MosaicLayer:
7954 case TrimBoundsLayer:
7955 {
7956 layers=MergeImageLayers(*images,method,exception);
7957 break;
7958 }
7959 case DisposeLayer:
7960 {
7961 layers=DisposeImages(*images,exception);
7962 break;
7963 }
7964 case OptimizeImageLayer:
7965 {
7966 layers=OptimizeImageLayers(*images,exception);
7967 break;
7968 }
7969 case OptimizePlusLayer:
7970 {
7971 layers=OptimizePlusImageLayers(*images,exception);
7972 break;
7973 }
7974 case OptimizeTransLayer:
7975 {
7976 OptimizeImageTransparency(*images,exception);
7977 break;
7978 }
7979 case RemoveDupsLayer:
7980 {
7981 RemoveDuplicateLayers(images,exception);
7982 break;
7983 }
7984 case RemoveZeroLayer:
7985 {
7986 RemoveZeroDelayLayers(images,exception);
7987 break;
7988 }
7989 case OptimizeLayer:
7990 {
7991 /*
7992 General Purpose, GIF Animation Optimizer.
7993 */
7994 layers=CoalesceImages(*images,exception);
7995 if (layers == (Image *) NULL)
7996 {
7997 status=MagickFalse;
7998 break;
7999 }
8000 InheritException(exception,&layers->exception);
8001 *images=DestroyImageList(*images);
8002 *images=layers;
8003 layers=OptimizeImageLayers(*images,exception);
8004 if (layers == (Image *) NULL)
8005 {
8006 status=MagickFalse;
8007 break;
8008 }
8009 InheritException(exception,&layers->exception);
8010 *images=DestroyImageList(*images);
8011 *images=layers;
8012 layers=(Image *) NULL;
8013 OptimizeImageTransparency(*images,exception);
8014 InheritException(exception,&(*images)->exception);
8015 (void) RemapImages(quantize_info,*images,(Image *) NULL);
8016 break;
8017 }
8018 case CompositeLayer:
8019 {
8020 CompositeOperator
8021 compose;
8022
8023 Image
8024 *source;
8025
8026 RectangleInfo
8027 geometry;
8028
8029 /*
8030 Split image sequence at the first 'NULL:' image.
8031 */
8032 source=(*images);
8033 while (source != (Image *) NULL)
8034 {
8035 source=GetNextImageInList(source);
8036 if ((source != (Image *) NULL) &&
8037 (LocaleCompare(source->magick,"NULL") == 0))
8038 break;
8039 }
8040 if (source != (Image *) NULL)
8041 {
8042 if ((GetPreviousImageInList(source) == (Image *) NULL) ||
8043 (GetNextImageInList(source) == (Image *) NULL))
8044 source=(Image *) NULL;
8045 else
8046 {
8047 /*
8048 Separate the two lists, junk the null: image.
8049 */
8050 source=SplitImageList(source->previous);
8051 DeleteImageFromList(&source);
8052 }
8053 }
8054 if (source == (Image *) NULL)
8055 {
8056 (void) ThrowMagickException(exception,GetMagickModule(),
8057 OptionError,"MissingNullSeparator","layers Composite");
8058 status=MagickFalse;
8059 break;
8060 }
8061 /*
8062 Adjust offset with gravity and virtual canvas.
8063 */
8064 SetGeometry(*images,&geometry);
8065 (void) ParseAbsoluteGeometry((*images)->geometry,&geometry);
8066 geometry.width=source->page.width != 0 ?
8067 source->page.width : source->columns;
8068 geometry.height=source->page.height != 0 ?
8069 source->page.height : source->rows;
8070 GravityAdjustGeometry((*images)->page.width != 0 ?
8071 (*images)->page.width : (*images)->columns,
8072 (*images)->page.height != 0 ? (*images)->page.height :
8073 (*images)->rows,(*images)->gravity,&geometry);
8074 compose=OverCompositeOp;
8075 option=GetImageOption(image_info,"compose");
8076 if (option != (const char *) NULL)
8077 compose=(CompositeOperator) ParseMagickOption(
8078 MagickComposeOptions,MagickFalse,option);
8079 CompositeLayers(*images,compose,source,geometry.x,geometry.y,
8080 exception);
8081 source=DestroyImageList(source);
8082 break;
8083 }
8084 }
8085 if (layers == (Image *) NULL)
8086 break;
8087 InheritException(exception,&layers->exception);
8088 *images=DestroyImageList(*images);
8089 *images=layers;
8090 break;
8091 }
8092 break;
8093 }
8094 case 'm':
8095 {
8096 if (LocaleCompare("map",option+1) == 0)
8097 {
8098 (void) SyncImagesSettings(image_info,*images);
8099 if (*option == '+')
8100 {
8101 (void) RemapImages(quantize_info,*images,(Image *) NULL);
8102 InheritException(exception,&(*images)->exception);
8103 break;
8104 }
8105 i++;
8106 break;
8107 }
cristyf40785b2010-03-06 02:27:27 +00008108 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00008109 {
8110 Image
cristyf40785b2010-03-06 02:27:27 +00008111 *maximum_image;
cristy1c274c92010-03-06 02:06:45 +00008112
8113 (void) SyncImagesSettings(image_info,*images);
cristyf40785b2010-03-06 02:27:27 +00008114 maximum_image=MaximumImages(*images,exception);
8115 if (maximum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00008116 {
8117 status=MagickFalse;
8118 break;
8119 }
8120 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00008121 *images=maximum_image;
cristy1c274c92010-03-06 02:06:45 +00008122 break;
8123 }
cristyf40785b2010-03-06 02:27:27 +00008124 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00008125 {
8126 Image
cristyf40785b2010-03-06 02:27:27 +00008127 *minimum_image;
cristy1c274c92010-03-06 02:06:45 +00008128
8129 (void) SyncImagesSettings(image_info,*images);
cristyf40785b2010-03-06 02:27:27 +00008130 minimum_image=MinimumImages(*images,exception);
8131 if (minimum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00008132 {
8133 status=MagickFalse;
8134 break;
8135 }
8136 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00008137 *images=minimum_image;
cristy1c274c92010-03-06 02:06:45 +00008138 break;
8139 }
cristy3ed852e2009-09-05 21:47:34 +00008140 if (LocaleCompare("morph",option+1) == 0)
8141 {
8142 Image
8143 *morph_image;
8144
8145 (void) SyncImagesSettings(image_info,*images);
cristye27293e2009-12-18 02:53:20 +00008146 morph_image=MorphImages(*images,StringToUnsignedLong(argv[i+1]),
cristy3ed852e2009-09-05 21:47:34 +00008147 exception);
8148 if (morph_image == (Image *) NULL)
8149 {
8150 status=MagickFalse;
8151 break;
8152 }
8153 *images=DestroyImageList(*images);
8154 *images=morph_image;
8155 break;
8156 }
8157 if (LocaleCompare("mosaic",option+1) == 0)
8158 {
8159 Image
8160 *mosaic_image;
8161
8162 (void) SyncImagesSettings(image_info,*images);
8163 mosaic_image=MergeImageLayers(*images,MosaicLayer,exception);
8164 if (mosaic_image == (Image *) NULL)
8165 {
8166 status=MagickFalse;
8167 break;
8168 }
8169 *images=DestroyImageList(*images);
8170 *images=mosaic_image;
8171 break;
8172 }
8173 break;
8174 }
8175 case 'p':
8176 {
8177 if (LocaleCompare("print",option+1) == 0)
8178 {
8179 char
8180 *string;
8181
8182 (void) SyncImagesSettings(image_info,*images);
8183 string=InterpretImageProperties(image_info,*images,argv[i+1]);
8184 if (string == (char *) NULL)
8185 break;
8186 InheritException(exception,&(*images)->exception);
8187 (void) fprintf(stdout,"%s",string);
8188 string=DestroyString(string);
8189 }
8190 if (LocaleCompare("process",option+1) == 0)
8191 {
8192 char
8193 **arguments;
8194
8195 int
8196 j,
8197 number_arguments;
8198
8199 (void) SyncImagesSettings(image_info,*images);
8200 arguments=StringToArgv(argv[i+1],&number_arguments);
8201 if (arguments == (char **) NULL)
8202 break;
8203 if ((argc > 1) && (strchr(arguments[1],'=') != (char *) NULL))
8204 {
8205 char
8206 breaker,
8207 quote,
8208 *token;
8209
8210 const char
8211 *arguments;
8212
8213 int
8214 next,
8215 status;
8216
8217 size_t
8218 length;
8219
8220 TokenInfo
8221 *token_info;
8222
8223 /*
8224 Support old style syntax, filter="-option arg".
8225 */
8226 length=strlen(argv[i+1]);
8227 token=(char *) NULL;
8228 if (~length >= MaxTextExtent)
8229 token=(char *) AcquireQuantumMemory(length+MaxTextExtent,
8230 sizeof(*token));
8231 if (token == (char *) NULL)
8232 break;
8233 next=0;
8234 arguments=argv[i+1];
8235 token_info=AcquireTokenInfo();
8236 status=Tokenizer(token_info,0,token,length,arguments,"","=",
8237 "\"",'\0',&breaker,&next,&quote);
8238 token_info=DestroyTokenInfo(token_info);
8239 if (status == 0)
8240 {
8241 const char
8242 *argv;
8243
8244 argv=(&(arguments[next]));
8245 (void) InvokeDynamicImageFilter(token,&(*images),1,&argv,
8246 exception);
8247 }
8248 token=DestroyString(token);
8249 break;
8250 }
8251 (void) InvokeDynamicImageFilter(arguments[1],&(*images),
8252 number_arguments-2,(const char **) arguments+2,exception);
8253 for (j=0; j < number_arguments; j++)
8254 arguments[j]=DestroyString(arguments[j]);
8255 arguments=(char **) RelinquishMagickMemory(arguments);
8256 break;
8257 }
8258 break;
8259 }
8260 case 'r':
8261 {
8262 if (LocaleCompare("reverse",option+1) == 0)
8263 {
8264 ReverseImageList(images);
8265 InheritException(exception,&(*images)->exception);
8266 break;
8267 }
8268 break;
8269 }
8270 case 's':
8271 {
8272 if (LocaleCompare("swap",option+1) == 0)
8273 {
8274 Image
8275 *p,
8276 *q,
8277 *swap;
8278
8279 long
8280 swap_index;
8281
8282 index=(-1);
8283 swap_index=(-2);
8284 if (*option != '+')
8285 {
8286 GeometryInfo
8287 geometry_info;
8288
8289 MagickStatusType
8290 flags;
8291
8292 swap_index=(-1);
8293 flags=ParseGeometry(argv[i+1],&geometry_info);
8294 index=(long) geometry_info.rho;
8295 if ((flags & SigmaValue) != 0)
8296 swap_index=(long) geometry_info.sigma;
8297 }
8298 p=GetImageFromList(*images,index);
8299 q=GetImageFromList(*images,swap_index);
8300 if ((p == (Image *) NULL) || (q == (Image *) NULL))
8301 {
8302 (void) ThrowMagickException(exception,GetMagickModule(),
8303 OptionError,"NoSuchImage","`%s'",(*images)->filename);
8304 status=MagickFalse;
8305 break;
8306 }
8307 if (p == q)
8308 break;
8309 swap=CloneImage(p,0,0,MagickTrue,exception);
8310 ReplaceImageInList(&p,CloneImage(q,0,0,MagickTrue,exception));
8311 ReplaceImageInList(&q,swap);
8312 *images=GetFirstImageInList(q);
8313 break;
8314 }
8315 break;
8316 }
8317 case 'w':
8318 {
8319 if (LocaleCompare("write",option+1) == 0)
8320 {
8321 Image
8322 *write_images;
8323
8324 ImageInfo
8325 *write_info;
8326
8327 (void) SyncImagesSettings(image_info,*images);
8328 write_images=(*images);
8329 if (*option == '+')
8330 write_images=CloneImageList(*images,exception);
8331 write_info=CloneImageInfo(image_info);
8332 status&=WriteImages(write_info,write_images,argv[i+1],exception);
8333 write_info=DestroyImageInfo(write_info);
8334 if (*option == '+')
8335 write_images=DestroyImageList(write_images);
8336 break;
8337 }
8338 break;
8339 }
8340 default:
8341 break;
8342 }
8343 i+=count;
8344 }
8345 quantize_info=DestroyQuantizeInfo(quantize_info);
8346 return(status != 0 ? MagickTrue : MagickFalse);
8347}
8348
8349/*
8350%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8351% %
8352% %
8353% %
8354+ M o g r i f y I m a g e s %
8355% %
8356% %
8357% %
8358%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8359%
8360% MogrifyImages() applies image processing options to a sequence of images as
8361% prescribed by command line options.
8362%
8363% The format of the MogrifyImage method is:
8364%
8365% MagickBooleanType MogrifyImages(ImageInfo *image_info,
8366% const MagickBooleanType post,const int argc,const char **argv,
8367% Image **images,Exceptioninfo *exception)
8368%
8369% A description of each parameter follows:
8370%
8371% o image_info: the image info..
8372%
8373% o post: If true, post process image list operators otherwise pre-process.
8374%
8375% o argc: Specifies a pointer to an integer describing the number of
8376% elements in the argument vector.
8377%
8378% o argv: Specifies a pointer to a text array containing the command line
8379% arguments.
8380%
8381% o images: the images.
8382%
8383% o exception: return any errors or warnings in this structure.
8384%
8385*/
8386WandExport MagickBooleanType MogrifyImages(ImageInfo *image_info,
8387 const MagickBooleanType post,const int argc,const char **argv,
8388 Image **images,ExceptionInfo *exception)
8389{
8390#define MogrifyImageTag "Mogrify/Image"
8391
8392 Image
8393 *image,
8394 *mogrify_images;
8395
cristy0e9f9c12010-02-11 03:00:47 +00008396 MagickBooleanType
8397 proceed;
8398
8399 MagickSizeType
8400 number_images;
8401
cristy3ed852e2009-09-05 21:47:34 +00008402 MagickStatusType
8403 status;
8404
8405 register long
8406 i;
8407
cristy3ed852e2009-09-05 21:47:34 +00008408 /*
8409 Apply options to individual images in the list.
8410 */
8411 assert(image_info != (ImageInfo *) NULL);
8412 assert(image_info->signature == MagickSignature);
8413 if (images == (Image **) NULL)
8414 return(MogrifyImage(image_info,argc,argv,images,exception));
8415 assert((*images)->signature == MagickSignature);
8416 if ((*images)->debug != MagickFalse)
8417 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
8418 (*images)->filename);
8419 if ((argc <= 0) || (*argv == (char *) NULL))
8420 return(MagickTrue);
8421 (void) SetImageInfoProgressMonitor(image_info,(MagickProgressMonitor) NULL,
8422 (void *) NULL);
8423 mogrify_images=NewImageList();
8424 number_images=GetImageListLength(*images);
8425 status=0;
8426 if (post == MagickFalse)
8427 status&=MogrifyImageList(image_info,argc,argv,images,exception);
8428 for (i=0; i < (long) number_images; i++)
8429 {
8430 image=RemoveFirstImageFromList(images);
8431 if (image == (Image *) NULL)
8432 continue;
8433 status&=MogrifyImage(image_info,argc,argv,&image,exception);
8434 AppendImageToList(&mogrify_images,image);
cristy0e9f9c12010-02-11 03:00:47 +00008435 proceed=SetImageProgress(image,MogrifyImageTag,(MagickOffsetType) i,
8436 number_images);
8437 if (proceed == MagickFalse)
8438 break;
cristy3ed852e2009-09-05 21:47:34 +00008439 }
8440 if (post != MagickFalse)
8441 status&=MogrifyImageList(image_info,argc,argv,&mogrify_images,exception);
8442 *images=mogrify_images;
8443 return(status != 0 ? MagickTrue : MagickFalse);
8444}