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