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