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