/plugins/ImageMagick-6.3.2/wand/mogrify.c
C | 6683 lines | 5890 code | 235 blank | 558 comment | 2356 complexity | 86a449ee3127915f3d6a0808fc5a0ece MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, LGPL-2.1
Large files files are truncated, but you can click here to view the full file
- /*
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- % %
- % %
- % %
- % M M OOO GGGGG RRRR IIIII FFFFF Y Y %
- % MM MM O O G R R I F Y Y %
- % M M M O O G GGG RRRR I FFF Y %
- % M M O O G G R R I F Y %
- % M M OOO GGGG R R IIIII F Y %
- % %
- % %
- % ImageMagick Module Methods %
- % %
- % Software Design %
- % John Cristy %
- % March 2000 %
- % %
- % %
- % Copyright 1999-2006 ImageMagick Studio LLC, a non-profit organization %
- % dedicated to making software imaging solutions freely available. %
- % %
- % You may not use this file except in compliance with the License. You may %
- % obtain a copy of the License at %
- % %
- % http://www.imagemagick.org/script/license.php %
- % %
- % Unless required by applicable law or agreed to in writing, software %
- % distributed under the License is distributed on an "AS IS" BASIS, %
- % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
- % See the License for the specific language governing permissions and %
- % limitations under the License. %
- % %
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- %
- %
- %
- */
- /*
- Include declarations.
- */
- #include "wand/studio.h"
- #include "wand/MagickWand.h"
- #include "wand/mogrify-private.h"
- /*
- Define declarations.
- */
- #define ThrowWandFatalException(severity,tag,context) \
- { \
- ExceptionInfo \
- exception; \
- \
- GetExceptionInfo(&exception); \
- (void) ThrowMagickException(&exception,GetMagickModule(),severity,tag, \
- "`%s'",context); \
- CatchException(&exception); \
- (void) DestroyExceptionInfo(&exception); \
- }
- #define UndefinedCompressionQuality 0UL
- /*
- Constant declaration.
- */
- static const char
- *BackgroundColor = "#fff", /* white */
- *BorderColor = "#dfdfdf", /* gray */
- *MatteColor = "#bdbdbd"; /* gray */
- /*
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- % %
- % %
- % %
- + M o g r i f y I m a g e %
- % %
- % %
- % %
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- %
- % MogrifyImage() applies image processing options to an image as prescribed
- % by command line options.
- %
- % The format of the MogrifyImage method is:
- %
- % MagickBooleanType MogrifyImage(ImageInfo *image_info,const int argc,
- % const char **argv,Image **image)
- %
- % A description of each parameter follows:
- %
- % o image_info: The image info..
- %
- % o argc: Specifies a pointer to an integer describing the number of
- % elements in the argument vector.
- %
- % o argv: Specifies a pointer to a text array containing the command line
- % arguments.
- %
- % o image: The image.
- %
- % o exception: Return any errors or warnings in this structure.
- %
- */
- static inline long MagickMax(const long x,const long y)
- {
- if (x > y)
- return(x);
- return(y);
- }
- static MagickBooleanType MonitorProgress(const char *tag,
- const MagickOffsetType quantum,const MagickSizeType span,
- void *wand_unused(client_data))
- {
- char
- message[MaxTextExtent];
- const char
- *locale_message;
- if (span < 2)
- return(MagickTrue);
- (void) FormatMagickString(message,MaxTextExtent,"Monitor/%s",tag);
- locale_message=GetLocaleMessage(message);
- if (locale_message == message)
- locale_message=tag;
- (void) fprintf(stdout,"%s: %02ld%%\r",locale_message,(long)
- (100L*quantum/(span-1)));
- if ((MagickSizeType) quantum == (span-1))
- (void) fprintf(stdout,"\n");
- (void) fflush(stdout);
- return(MagickTrue);
- }
- WandExport MagickBooleanType MogrifyImage(ImageInfo *image_info,const int argc,
- const char **argv,Image **image,ExceptionInfo *exception)
- {
- ChannelType
- channel;
- const char
- *format,
- *option;
- DrawInfo
- *draw_info;
- GeometryInfo
- geometry_info;
- Image
- *region_image;
- long
- count;
- MagickBooleanType
- status;
- MagickPixelPacket
- fill;
- MagickStatusType
- flags;
- QuantizeInfo
- *quantize_info;
- RectangleInfo
- geometry,
- region_geometry;
- register long
- i;
- /*
- Initialize method variables.
- */
- assert(image_info != (const ImageInfo *) NULL);
- assert(image_info->signature == MagickSignature);
- assert(image != (Image **) NULL);
- assert((*image)->signature == MagickSignature);
- if ((*image)->debug != MagickFalse)
- (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",(*image)->filename);
- if (argc < 0)
- return(MagickTrue);
- for (i=0; i < (long) argc; i++)
- if (strlen(argv[i]) > (MaxTextExtent/2-1))
- ThrowWandFatalException(OptionFatalError,"OptionLengthExceedsLimit",
- argv[i]);
- draw_info=CloneDrawInfo(image_info,(DrawInfo *) NULL);
- quantize_info=AcquireQuantizeInfo(image_info);
- SetGeometryInfo(&geometry_info);
- channel=image_info->channel;
- GetMagickPixelPacket(*image,&fill);
- SetMagickPixelPacket(&(*image)->background_color,(IndexPacket *) NULL,&fill);
- format=GetImageOption(image_info,"format");
- SetGeometry(*image,®ion_geometry);
- region_image=NewImageList();
- /*
- Transmogrify the image.
- */
- for (i=0; i < (long) argc; i++)
- {
- option=argv[i];
- if (IsMagickOption(option) == MagickFalse)
- continue;
- count=MagickMax(ParseMagickOption(MagickCommandOptions,MagickFalse,option),
- 0L);
- if ((i+count) >= argc)
- break;
- status=MogrifyImageInfo(image_info,count+1,argv+i,exception);
- switch (*(option+1))
- {
- case 'a':
- {
- if (LocaleCompare("adaptive-blur",option+1) == 0)
- {
- Image
- *blur_image;
- /*
- Blur image.
- */
- flags=ParseGeometry(argv[i+1],&geometry_info);
- if ((flags & SigmaValue) == 0)
- geometry_info.sigma=1.0;
- blur_image=AdaptiveBlurImageChannel(*image,channel,
- geometry_info.rho,geometry_info.sigma,exception);
- if (blur_image == (Image *) NULL)
- break;
- InheritException(&blur_image->exception,exception);
- *image=DestroyImage(*image);
- *image=blur_image;
- break;
- }
- if (LocaleCompare("adaptive-resize",option+1) == 0)
- {
- Image
- *resize_image;
- /*
- Resize image.
- */
- (void) ParseSizeGeometry(*image,argv[i+1],&geometry);
- resize_image=AdaptiveResizeImage(*image,geometry.width,
- geometry.height,exception);
- if (resize_image == (Image *) NULL)
- break;
- InheritException(&resize_image->exception,exception);
- *image=DestroyImage(*image);
- *image=resize_image;
- break;
- }
- if (LocaleCompare("adaptive-sharpen",option+1) == 0)
- {
- Image
- *sharp_image;
- /*
- Sharpen image.
- */
- flags=ParseGeometry(argv[i+1],&geometry_info);
- if ((flags & SigmaValue) == 0)
- geometry_info.sigma=1.0;
- sharp_image=AdaptiveSharpenImageChannel(*image,channel,
- geometry_info.rho,geometry_info.sigma,exception);
- if (sharp_image == (Image *) NULL)
- break;
- InheritException(&sharp_image->exception,exception);
- *image=DestroyImage(*image);
- *image=sharp_image;
- break;
- }
- if (LocaleCompare("affine",option+1) == 0)
- {
- /*
- Affine matrix.
- */
- if (*option == '+')
- {
- GetAffineMatrix(&draw_info->affine);
- break;
- }
- (void) ParseAffineGeometry(argv[i+1],&draw_info->affine);
- break;
- }
- if (LocaleCompare("annotate",option+1) == 0)
- {
- char
- geometry[MaxTextExtent];
- /*
- Annotate image.
- */
- SetGeometryInfo(&geometry_info);
- flags=ParseGeometry(argv[i+1],&geometry_info);
- if ((flags & SigmaValue) == 0)
- geometry_info.sigma=geometry_info.rho;
- (void) CloneString(&draw_info->text,InterpretImageProperties(
- image_info,*image,argv[i+2]));
- (void) FormatMagickString(geometry,MaxTextExtent,"%+f%+f",
- geometry_info.xi,geometry_info.psi);
- (void) CloneString(&draw_info->geometry,geometry);
- draw_info->affine.sx=cos(DegreesToRadians(
- fmod(geometry_info.rho,360.0)));
- draw_info->affine.rx=sin(DegreesToRadians(
- fmod(geometry_info.rho,360.0)));
- draw_info->affine.ry=(-sin(DegreesToRadians(
- fmod(geometry_info.sigma,360.0))));
- draw_info->affine.sy=cos(DegreesToRadians(
- fmod(geometry_info.sigma,360.0)));
- (void) AnnotateImage(*image,draw_info);
- break;
- }
- if (LocaleCompare("antialias",option+1) == 0)
- {
- draw_info->stroke_antialias=(*option == '-') ? MagickTrue :
- MagickFalse;
- draw_info->text_antialias=(*option == '-') ? MagickTrue :
- MagickFalse;
- break;
- }
- if (LocaleCompare("auto-orient",option+1) == 0)
- {
- Image
- *orient_image;
- orient_image=NewImageList();
- switch ((*image)->orientation)
- {
- case TopRightOrientation:
- {
- orient_image=FlopImage(*image,exception);
- break;
- }
- case BottomRightOrientation:
- {
- orient_image=RotateImage(*image,180.0,exception);
- break;
- }
- case BottomLeftOrientation:
- {
- orient_image=FlipImage(*image,exception);
- break;
- }
- case LeftTopOrientation:
- {
- orient_image=TransposeImage(*image,exception);
- break;
- }
- case RightTopOrientation:
- {
- orient_image=RotateImage(*image,90.0,exception);
- break;
- }
- case RightBottomOrientation:
- {
- orient_image=TransverseImage(*image,exception);
- break;
- }
- case LeftBottomOrientation:
- {
- orient_image=RotateImage(*image,270.0,exception);
- break;
- }
- default:
- break;
- }
- if (orient_image == (Image *) NULL)
- break;
- InheritException(&orient_image->exception,exception);
- *image=DestroyImage(*image);
- *image=orient_image;
- break;
- }
- break;
- }
- case 'b':
- {
- if (LocaleCompare("background",option+1) == 0)
- {
- if (*option == '+')
- {
- (void) QueryColorDatabase(BackgroundColor,
- &(*image)->background_color,exception);
- break;
- }
- (void) QueryColorDatabase(argv[i+1],&(*image)->background_color,
- exception);
- break;
- }
- if (LocaleCompare("bias",option+1) == 0)
- {
- (*image)->bias=StringToDouble(argv[i+1],QuantumRange);
- break;
- }
- if (LocaleCompare("black-threshold",option+1) == 0)
- {
- /*
- Threshold black image.
- */
- (void) BlackThresholdImage(*image,argv[i+1]);
- break;
- }
- if (LocaleCompare("black-point-compensation",option+1) == 0)
- {
- (*image)->black_point_compensation=(*option == '-') ? MagickTrue :
- MagickFalse;
- break;
- }
- if (LocaleCompare("blue-primary",option+1) == 0)
- {
- /*
- Blue chromaticity primary point.
- */
- if (*option == '+')
- {
- (*image)->chromaticity.blue_primary.x=0.0;
- (*image)->chromaticity.blue_primary.y=0.0;
- break;
- }
- flags=ParseGeometry(argv[i+1],&geometry_info);
- (*image)->chromaticity.blue_primary.x=geometry_info.rho;
- (*image)->chromaticity.blue_primary.y=geometry_info.sigma;
- if ((flags & SigmaValue) == 0)
- (*image)->chromaticity.blue_primary.y=
- (*image)->chromaticity.blue_primary.x;
- break;
- }
- if (LocaleCompare("blur",option+1) == 0)
- {
- Image
- *blur_image;
- /*
- Gaussian blur image.
- */
- flags=ParseGeometry(argv[i+1],&geometry_info);
- if ((flags & SigmaValue) == 0)
- geometry_info.sigma=1.0;
- blur_image=BlurImageChannel(*image,channel,
- geometry_info.rho,geometry_info.sigma,exception);
- if (blur_image == (Image *) NULL)
- break;
- InheritException(&blur_image->exception,exception);
- *image=DestroyImage(*image);
- *image=blur_image;
- break;
- }
- if (LocaleCompare("border",option+1) == 0)
- {
- Image
- *border_image;
- /*
- Surround image with a border of solid color.
- */
- flags=ParsePageGeometry(*image,argv[i+1],&geometry);
- if ((flags & SigmaValue) == 0)
- geometry.height=geometry.width;
- border_image=BorderImage(*image,&geometry,exception);
- if (border_image == (Image *) NULL)
- break;
- InheritException(&border_image->exception,exception);
- *image=DestroyImage(*image);
- *image=border_image;
- break;
- }
- if (LocaleCompare("bordercolor",option+1) == 0)
- {
- if (*option == '+')
- {
- (void) QueryColorDatabase(BorderColor,&(*image)->border_color,
- exception);
- draw_info->border_color=(*image)->border_color;
- break;
- }
- (void) QueryColorDatabase(argv[i+1],&(*image)->border_color,
- exception);
- draw_info->border_color=(*image)->border_color;
- break;
- }
- if (LocaleCompare("box",option+1) == 0)
- {
- (void) QueryColorDatabase(argv[i+1],&draw_info->undercolor,
- exception);
- break;
- }
- break;
- }
- case 'c':
- {
- if (LocaleCompare("cache",option+1) == 0)
- {
- unsigned long
- limit;
- limit=(~0UL);
- if (LocaleCompare("unlimited",argv[i+1]) != 0)
- limit=(unsigned long) atol(argv[i+1]);
- (void) SetMagickResourceLimit(MemoryResource,limit);
- (void) SetMagickResourceLimit(MapResource,2*limit);
- break;
- }
- if (LocaleCompare("channel",option+1) == 0)
- {
- if (*option == '+')
- {
- channel=DefaultChannels;
- break;
- }
- channel=(ChannelType) ParseChannelOption(argv[i+1]);
- break;
- }
- if (LocaleCompare("charcoal",option+1) == 0)
- {
- Image
- *charcoal_image;
- /*
- Charcoal image.
- */
- flags=ParseGeometry(argv[i+1],&geometry_info);
- if ((flags & SigmaValue) == 0)
- geometry_info.sigma=1.0;
- charcoal_image=CharcoalImage(*image,geometry_info.rho,
- geometry_info.sigma,exception);
- if (charcoal_image == (Image *) NULL)
- break;
- InheritException(&charcoal_image->exception,exception);
- *image=DestroyImage(*image);
- *image=charcoal_image;
- break;
- }
- if (LocaleCompare("chop",option+1) == 0)
- {
- Image
- *chop_image;
- /*
- Chop the image.
- */
- (void) ParseGravityGeometry(*image,argv[i+1],&geometry);
- chop_image=ChopImage(*image,&geometry,exception);
- if (chop_image == (Image *) NULL)
- break;
- InheritException(&chop_image->exception,exception);
- *image=DestroyImage(*image);
- *image=chop_image;
- break;
- }
- if (LocaleCompare("clip",option+1) == 0)
- {
- if (*option == '+')
- {
- (void) SetImageClipMask(*image,(Image *) NULL);
- break;
- }
- (void) ClipImage(*image);
- break;
- }
- if (LocaleCompare("clip-mask",option+1) == 0)
- {
- Image
- *mask;
- ImageInfo
- *mask_info;
- long
- y;
- register long
- x;
- register PixelPacket
- *q;
- if (*option == '+')
- {
- /*
- Remove a mask.
- */
- (void) SetImageMask(*image,(Image *) NULL);
- break;
- }
- /*
- Set the image mask.
- */
- mask_info=CloneImageInfo(image_info);
- (void) CopyMagickString(mask_info->filename,argv[i+1],
- MaxTextExtent);
- mask=ReadImage(mask_info,exception);
- CatchException(exception);
- mask_info=DestroyImageInfo(mask_info);
- if (mask == (Image *) NULL)
- break;
- for (y=0; y < (long) mask->rows; y++)
- {
- q=GetImagePixels(mask,0,y,mask->columns,1);
- if (q == (PixelPacket *) NULL)
- break;
- for (x=0; x < (long) mask->columns; x++)
- {
- if (mask->matte == MagickFalse)
- q->opacity=PixelIntensityToQuantum(q);
- q->red=q->opacity;
- q->green=q->opacity;
- q->blue=q->opacity;
- q++;
- }
- if (SyncImagePixels(mask) == MagickFalse)
- break;
- }
- if (SetImageStorageClass(mask,DirectClass) == MagickFalse)
- return(MagickFalse);
- mask->matte=MagickTrue;
- (void) SetImageClipMask(*image,mask);
- break;
- }
- if (LocaleCompare("clip-path",option+1) == 0)
- {
- (void) ClipPathImage(*image,argv[i+1],
- *option == '-' ? MagickTrue : MagickFalse);
- break;
- }
- if (LocaleCompare("colorize",option+1) == 0)
- {
- Image
- *colorize_image;
- /*
- Colorize the image.
- */
- colorize_image=ColorizeImage(*image,argv[i+1],draw_info->fill,
- exception);
- if (colorize_image == (Image *) NULL)
- break;
- InheritException(&colorize_image->exception,exception);
- *image=DestroyImage(*image);
- *image=colorize_image;
- break;
- }
- if (LocaleCompare("colors",option+1) == 0)
- {
- /*
- Reduce the number of colors in the image.
- */
- quantize_info->number_colors=(unsigned long) atol(argv[i+1]);
- if (quantize_info->number_colors == 0)
- break;
- if (((*image)->storage_class == DirectClass) ||
- (*image)->colors > quantize_info->number_colors)
- (void) QuantizeImage(quantize_info,*image);
- else
- CompressImageColormap(*image);
- break;
- }
- if (LocaleCompare("colorspace",option+1) == 0)
- {
- ColorspaceType
- colorspace;
- if (*option == '+')
- {
- (void) SetImageColorspace(*image,RGBColorspace);
- break;
- }
- colorspace=(ColorspaceType) ParseMagickOption(
- MagickColorspaceOptions,MagickFalse,argv[i+1]);
- (void) SetImageColorspace(*image,colorspace);
- break;
- }
- if (LocaleCompare("compose",option+1) == 0)
- {
- if (*option == '+')
- {
- (*image)->compose=OverCompositeOp;
- break;
- }
- (*image)->compose=(CompositeOperator) ParseMagickOption(
- MagickCompositeOptions,MagickFalse,argv[i+1]);
- break;
- }
- if (LocaleCompare("compress",option+1) == 0)
- {
- if (*option == '+')
- {
- (*image)->compression=UndefinedCompression;
- break;
- }
- (*image)->compression=(CompressionType) ParseMagickOption(
- MagickCompressionOptions,MagickFalse,argv[i+1]);
- break;
- }
- if (LocaleCompare("contrast",option+1) == 0)
- {
- (void) ContrastImage(*image,(*option == '-') ? MagickTrue :
- MagickFalse);
- break;
- }
- if (LocaleCompare("contrast-stretch",option+1) == 0)
- {
- GeometryInfo
- geometry_info;
- MagickRealType
- black_point,
- white_point;
- MagickStatusType
- flags;
- /*
- Parse levels.
- */
- flags=ParseGeometry(argv[i+1],&geometry_info);
- black_point=geometry_info.rho;
- white_point=(MagickRealType) (*image)->columns*(*image)->rows;
- if ((flags & SigmaValue) != 0)
- white_point=geometry_info.sigma;
- if ((flags & PercentValue) != 0)
- {
- black_point*=(MagickRealType) (*image)->columns*
- (*image)->rows/100.0f;
- white_point*=(MagickRealType) (*image)->columns*
- (*image)->rows/100.0f;
- }
- if ((flags & SigmaValue) == 0)
- white_point=(MagickRealType) (*image)->columns*(*image)->rows-
- black_point;
- (void) ContrastStretchImageChannel(*image,channel,black_point,
- white_point);
- break;
- }
- if (LocaleCompare("convolve",option+1) == 0)
- {
- char
- *p,
- token[MaxTextExtent];
- double
- *kernel;
- Image
- *convolve_image;
- register long
- x;
- unsigned long
- order;
- /*
- Convolve image.
- */
- p=(char *) argv[i+1];
- for (x=0; *p != '\0'; x++)
- {
- GetMagickToken(p,&p,token);
- if (*token == ',')
- GetMagickToken(p,&p,token);
- }
- order=(unsigned long) sqrt((double) x+1.0);
- kernel=(double *) AcquireMagickMemory(order*order*sizeof(*kernel));
- if (kernel == (double *) NULL)
- ThrowWandFatalException(ResourceLimitFatalError,
- "MemoryAllocationFailed",(*image)->filename);
- p=(char *) argv[i+1];
- for (x=0; *p != '\0'; x++)
- {
- GetMagickToken(p,&p,token);
- if (*token == ',')
- GetMagickToken(p,&p,token);
- kernel[x]=atof(token);
- }
- for ( ; x < (long) (order*order); x++)
- kernel[x]=0.0;
- convolve_image=ConvolveImageChannel(*image,channel,order,kernel,
- exception);
- kernel=(double *) RelinquishMagickMemory(kernel);
- if (convolve_image == (Image *) NULL)
- break;
- InheritException(&convolve_image->exception,exception);
- *image=DestroyImage(*image);
- *image=convolve_image;
- break;
- }
- if (LocaleCompare("crop",option+1) == 0)
- {
- if (*option == '+')
- break;
- break;
- }
- if (LocaleCompare("cycle",option+1) == 0)
- {
- /*
- Cycle an image colormap.
- */
- (void) CycleColormapImage(*image,atoi(argv[i+1]));
- break;
- }
- break;
- }
- case 'd':
- {
- if (LocaleCompare("debug",option+1) == 0)
- {
- if (*option == '+')
- {
- (void) SetLogEventMask("none");
- break;
- }
- (void) SetLogEventMask(argv[i+1]);
- break;
- }
- if (LocaleCompare("density",option+1) == 0)
- {
- GeometryInfo
- geometry_info;
- /*
- Set image density.
- */
- (void) CloneString(&draw_info->density,argv[i+1]);
- flags=ParseGeometry(argv[i+1],&geometry_info);
- (*image)->x_resolution=geometry_info.rho;
- (*image)->y_resolution=geometry_info.sigma;
- if ((flags & SigmaValue) == 0)
- (*image)->y_resolution=(*image)->x_resolution;
- break;
- }
- if (LocaleCompare("despeckle",option+1) == 0)
- {
- Image
- *despeckle_image;
- /*
- Reduce the speckles within an image.
- */
- despeckle_image=DespeckleImage(*image,exception);
- if (despeckle_image == (Image *) NULL)
- break;
- InheritException(&despeckle_image->exception,exception);
- *image=DestroyImage(*image);
- *image=despeckle_image;
- break;
- }
- if (LocaleCompare("display",option+1) == 0)
- {
- (void) CloneString(&draw_info->server_name,argv[i+1]);
- break;
- }
- if (LocaleCompare("dither",option+1) == 0)
- {
- quantize_info->dither=(*option == '-') ? MagickTrue : MagickFalse;
- break;
- }
- if (LocaleCompare("draw",option+1) == 0)
- {
- /*
- Draw image.
- */
- (void) CloneString(&draw_info->primitive,argv[i+1]);
- (void) DrawImage(*image,draw_info);
- break;
- }
- break;
- }
- case 'e':
- {
- if (LocaleCompare("edge",option+1) == 0)
- {
- Image
- *edge_image;
- /*
- Enhance edges in the image.
- */
- flags=ParseGeometry(argv[i+1],&geometry_info);
- if ((flags & SigmaValue) == 0)
- geometry_info.sigma=1.0;
- edge_image=EdgeImage(*image,geometry_info.rho,exception);
- if (edge_image == (Image *) NULL)
- break;
- InheritException(&edge_image->exception,exception);
- *image=DestroyImage(*image);
- *image=edge_image;
- break;
- }
- if (LocaleCompare("emboss",option+1) == 0)
- {
- Image
- *emboss_image;
- /*
- Gaussian embossen image.
- */
- flags=ParseGeometry(argv[i+1],&geometry_info);
- if ((flags & SigmaValue) == 0)
- geometry_info.sigma=1.0;
- emboss_image=EmbossImage(*image,geometry_info.rho,
- geometry_info.sigma,exception);
- if (emboss_image == (Image *) NULL)
- break;
- InheritException(&emboss_image->exception,exception);
- *image=DestroyImage(*image);
- *image=emboss_image;
- break;
- }
- if (LocaleCompare("encoding",option+1) == 0)
- {
- (void) CloneString(&draw_info->encoding,argv[i+1]);
- break;
- }
- if (LocaleCompare("endian",option+1) == 0)
- {
- if (*option == '+')
- {
- (*image)->endian=LSBEndian;
- break;
- }
- (*image)->endian=(EndianType) ParseMagickOption(MagickEndianOptions,
- MagickFalse,argv[i+1]);
- break;
- }
- if (LocaleCompare("enhance",option+1) == 0)
- {
- Image
- *enhance_image;
- /*
- Enhance image.
- */
- enhance_image=EnhanceImage(*image,exception);
- if (enhance_image == (Image *) NULL)
- break;
- InheritException(&enhance_image->exception,exception);
- *image=DestroyImage(*image);
- *image=enhance_image;
- break;
- }
- if (LocaleCompare("equalize",option+1) == 0)
- {
- /*
- Equalize image.
- */
- (void) EqualizeImage(*image);
- break;
- }
- if (LocaleCompare("evaluate",option+1) == 0)
- {
- double
- constant;
- MagickEvaluateOperator
- op;
- op=(MagickEvaluateOperator) ParseMagickOption(MagickEvaluateOptions,
- MagickFalse,argv[i+1]);
- constant=StringToDouble(argv[i+2],QuantumRange);
- (void) EvaluateImageChannel(*image,channel,op,constant,
- exception);
- break;
- }
- if (LocaleCompare("extent",option+1) == 0)
- {
- Image
- *extent_image;
- /*
- Set the image extent.
- */
- (void) ParseGravityGeometry(*image,argv[i+1],&geometry);
- extent_image=ExtentImage(*image,&geometry,exception);
- if (extent_image == (Image *) NULL)
- break;
- InheritException(&extent_image->exception,exception);
- *image=DestroyImage(*image);
- *image=extent_image;
- break;
- }
- break;
- }
- case 'f':
- {
- if (LocaleCompare("family",option+1) == 0)
- {
- if (*option == '+')
- draw_info->family=(char *) RelinquishMagickMemory(
- draw_info->family);
- else
- (void) CloneString(&draw_info->family,argv[i+1]);
- break;
- }
- if (LocaleCompare("fill",option+1) == 0)
- {
- ExceptionInfo
- *sans;
- if (*option == '+')
- {
- (void) QueryMagickColor("none",&fill,exception);
- (void) QueryColorDatabase("none",&draw_info->fill,exception);
- break;
- }
- sans=AcquireExceptionInfo();
- (void) QueryMagickColor(argv[i+1],&fill,sans);
- status=QueryColorDatabase(argv[i+1],&draw_info->fill,sans);
- sans=DestroyExceptionInfo(sans);
- if (status == MagickFalse)
- draw_info->fill_pattern=ReadImage(image_info,exception);
- break;
- }
- if (LocaleCompare("filter",option+1) == 0)
- {
- if (*option == '+')
- {
- (*image)->filter=UndefinedFilter;
- break;
- }
- (*image)->filter=(FilterTypes) ParseMagickOption(
- MagickFilterOptions,MagickFalse,argv[i+1]);
- break;
- }
- if (LocaleCompare("flip",option+1) == 0)
- {
- Image
- *flip_image;
- /*
- Flip image scanlines.
- */
- flip_image=FlipImage(*image,exception);
- if (flip_image == (Image *) NULL)
- break;
- InheritException(&flip_image->exception,exception);
- *image=DestroyImage(*image);
- *image=flip_image;
- break;
- }
- if (LocaleCompare("flop",option+1) == 0)
- {
- Image
- *flop_image;
- /*
- Flop image scanlines.
- */
- flop_image=FlopImage(*image,exception);
- if (flop_image == (Image *) NULL)
- break;
- InheritException(&flop_image->exception,exception);
- *image=DestroyImage(*image);
- *image=flop_image;
- break;
- }
- if (LocaleCompare("floodfill",option+1) == 0)
- {
- PixelPacket
- target;
- /*
- Floodfill image.
- */
- (void) ParsePageGeometry(*image,argv[i+1],&geometry);
- (void) QueryColorDatabase(argv[i+2],&target,exception);
- (void) ColorFloodfillImage(*image,draw_info,target,geometry.x,
- geometry.y,FloodfillMethod);
- break;
- }
- if (LocaleCompare("font",option+1) == 0)
- {
- if (*option == '+')
- {
- draw_info->font=(char *) RelinquishMagickMemory(
- draw_info->font);
- break;
- }
- (void) CloneString(&draw_info->font,argv[i+1]);
- break;
- }
- if (LocaleCompare("format",option+1) == 0)
- {
- format=argv[i+1];
- break;
- }
- if (LocaleCompare("frame",option+1) == 0)
- {
- FrameInfo
- frame_info;
- Image
- *frame_image;
- /*
- Surround image with an ornamental border.
- */
- (void) ParsePageGeometry(*image,argv[i+1],&geometry);
- frame_info.width=geometry.width;
- frame_info.height=geometry.height;
- frame_info.outer_bevel=geometry.x;
- frame_info.inner_bevel=geometry.y;
- frame_info.x=(long) frame_info.width;
- frame_info.y=(long) frame_info.height;
- frame_info.width=(*image)->columns+2*frame_info.width;
- frame_info.height=(*image)->rows+2*frame_info.height;
- frame_image=FrameImage(*image,&frame_info,exception);
- if (frame_image == (Image *) NULL)
- break;
- InheritException(&frame_image->exception,exception);
- *image=DestroyImage(*image);
- *image=frame_image;
- break;
- }
- if (LocaleCompare("fuzz",option+1) == 0)
- {
- if (*option == '+')
- {
- (*image)->fuzz=0.0;
- break;
- }
- (*image)->fuzz=StringToDouble(argv[i+1],QuantumRange+1.0);
- break;
- }
- break;
- }
- case 'g':
- {
- if (LocaleCompare("gamma",option+1) == 0)
- {
- if (*option == '+')
- (*image)->gamma=atof(argv[i+1]);
- else
- {
- if (strchr(argv[i+1],',') != (char *) NULL)
- (void) GammaImage(*image,argv[i+1]);
- else
- (void) GammaImageChannel(*image,channel,
- atof(argv[i+1]));
- }
- break;
- }
- if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
- (LocaleCompare("gaussian",option+1) == 0))
- {
- Image
- *gaussian_image;
- /*
- Gaussian blur image.
- */
- flags=ParseGeometry(argv[i+1],&geometry_info);
- if ((flags & SigmaValue) == 0)
- geometry_info.sigma=1.0;
- gaussian_image=GaussianBlurImageChannel(*image,channel,
- geometry_info.rho,geometry_info.sigma,exception);
- if (gaussian_image == (Image *) NULL)
- break;
- InheritException(&gaussian_image->exception,exception);
- *image=DestroyImage(*image);
- *image=gaussian_image;
- break;
- }
- if (LocaleCompare("geometry",option+1) == 0)
- {
- if (*option == '+')
- {
- if ((*image)->geometry != (char *) NULL)
- (*image)->geometry=(char *) RelinquishMagickMemory(
- (*image)->geometry);
- break;
- }
- (void) CloneString(&(*image)->geometry,argv[i+1]);
- flags=ParseSizeGeometry(*image,argv[i+1],&geometry);
- if (((flags & XValue) == 0) && ((flags & YValue) == 0))
- {
- Image
- *zoom_image;
- /*
- Resize image.
- */
- zoom_image=ZoomImage(*image,geometry.width,geometry.height,
- exception);
- if (zoom_image == (Image *) NULL)
- break;
- InheritException(&zoom_image->exception,exception);
- *image=DestroyImage(*image);
- *image=zoom_image;
- }
- break;
- }
- if (LocaleCompare("gravity",option+1) == 0)
- {
- if (*option == '+')
- (*image)->gravity=UndefinedGravity;
- else
- (*image)->gravity=(GravityType) ParseMagickOption(
- MagickGravityOptions,MagickFalse,argv[i+1]);
- draw_info->gravity=(*image)->gravity;
- break;
- }
- if (LocaleCompare("green-primary",option+1) == 0)
- {
- /*
- Green chromaticity primary point.
- */
- if (*option == '+')
- {
- (*image)->chromaticity.green_primary.x=0.0;
- (*image)->chromaticity.green_primary.y=0.0;
- break;
- }
- flags=ParseGeometry(argv[i+1],&geometry_info);
- (*image)->chromaticity.green_primary.x=geometry_info.rho;
- (*image)->chromaticity.green_primary.y=geometry_info.sigma;
- if ((flags & SigmaValue) == 0)
- (*image)->chromaticity.green_primary.y=
- (*image)->chromaticity.green_primary.x;
- break;
- }
- break;
- }
- case 'i':
- {
- if (LocaleCompare("identify",option+1) == 0)
- {
- char
- *text;
- if (format == (char *) NULL)
- {
- (void) IdentifyImage(*image,stdout,image_info->verbose);
- break;
- }
- text=InterpretImageProperties(image_info,*image,format);
- if (text == (char *) NULL)
- break;
- (void) fputs(text,stdout);
- (void) fputc('\n',stdout);
- text=(char *) RelinquishMagickMemory(text);
- break;
- }
- if (LocaleCompare("implode",option+1) == 0)
- {
- Image
- *implode_image;
- /*
- Implode image.
- */
- (void) ParseGeometry(argv[i+1],&geometry_info);
- implode_image=ImplodeImage(*image,geometry_info.rho,exception);
- if (implode_image == (Image *) NULL)
- break;
- InheritException(&implode_image->exception,exception);
- *image=DestroyImage(*image);
- *image=implode_image;
- break;
- }
- if (LocaleCompare("intent",option+1) == 0)
- {
- if (*option == '+')
- {
- (*image)->rendering_intent=UndefinedIntent;
- break;
- }
- (*image)->rendering_intent=(RenderingIntent) ParseMagickOption(
- MagickIntentOptions,MagickFalse,argv[i+1]);
- break;
- }
- if (LocaleCompare("interlace",option+1) == 0)
- {
- /*
- Interlace method.
- */
- if (*option == '+')
- {
- (*image)->interlace=UndefinedInterlace;
- break;
- }
- (*image)->interlace=(InterlaceType) ParseMagickOption(
- MagickInterlaceOptions,MagickFalse,argv[i+1]);
- break;
- }
- if (LocaleCompare("interpolate",option+1) == 0)
- {
- /*
- Interpolate method.
- */
- if (*option == '+')
- {
- (*image)->interpolate=UndefinedInterpolatePixel;
- break;
- }
- (*image)->interpolate=(InterpolatePixelMethod) ParseMagickOption(
- MagickInterpolateOptions,MagickFalse,argv[i+1]);
- break;
- }
- break;
- }
- case 'l':
- {
- if (LocaleCompare("lat",option+1) == 0)
- {
- Image
- *threshold_image;
- /*
- Local adaptive threshold image.
- */
- flags=ParseGeometry(argv[i+1],&geometry_info);
- if ((flags & PercentValue) != 0)
- geometry_info.xi=QuantumRange*geometry_info.xi/100.0;
- threshold_image=AdaptiveThresholdImage(*image,(unsigned long)
- geometry_info.rho,(unsigned long) geometry_info.sigma,
- (long) geometry_info.xi,exception);
- if (threshold_image == (Image *) NULL)
- break;
- InheritException(&threshold_image->exception,exception);
- *image=DestroyImage(*image);
- *image=threshold_image;
- break;
- }
- if (LocaleCompare("level",option+1) == 0)
- {
- GeometryInfo
- geometry_info;
- MagickRealType
- black_point,
- gamma,
- white_point;
- MagickStatusType
- flags;
- /*
- Parse levels.
- */
- flags=ParseGeometry(argv[i+1],&geometry_info);
- black_point=geometry_info.rho;
- white_point=(MagickRealType) QuantumRange;
- if ((flags & SigmaValue) != 0)
- white_point=geometry_info.sigma;
- gamma=1.0;
- if ((flags & XiValue) != 0)
- gamma=geometry_info.xi;
- if ((white_point <= 10.0) && (gamma > 10.0))
- {
- MagickRealType
- swap;
- swap=gamma;
- gamma=white_point;
- white_point=swap;
- }
- if ((flags & PercentValue) != 0)
- {
- black_point*=(MagickRealType) (QuantumRange/100.0);
- white_point*=(MagickRealType) (QuantumRange/100.0);
- }
- if ((flags & SigmaValue) == 0)
- white_point=(MagickRealType) QuantumRange-black_point;
- (void) LevelImageChannel(*image,channel,black_point,white_point,
- gamma);
- break;
- }
- if (LocaleCompare("limit",option+1) == 0)
- {
- ResourceType
- type;
- unsigned long
- limit;
- if (*option == '+')
- break;
- type=(ResourceType) ParseMagickOption(MagickResourceOptions,
- MagickFalse,argv[i+1]);
- limit=(~0UL);
- if (LocaleCompare("unlimited",argv[i+2]) != 0)
- limit=(unsigned long) atol(argv[i+2]);
- (void) SetMagickResourceLimit(type,limit);
- break;
- }
- if (LocaleCompare("linear-stretch",option+1) == 0)
- {
- GeometryInfo
- geometry_info;
- MagickRealType
- black_point,
- white_point;
- MagickStatusType
- flags;
- /*
- Parse levels.
- */
- flags=ParseGeometry(argv[i+1],&geometry_info);
- black_point=geometry_info.rho;
- white_point=(MagickRealType) (*image)->columns*(*image)->rows;
- if ((flags & SigmaValue) != 0)
- white_point=geometry_info.sigma;
- if ((flags & PercentValue) != 0)
- {
- black_point*=(MagickRealType) (*image)->columns*
- (*image)->rows/100.0f;
- white_point*=(MagickRealType) (*image)->columns*
- (*image)->rows/100.0f;
- }
- if ((flags & SigmaValue) == 0)
- white_point=(MagickRealType) (*image)->columns*(*image)->rows-
- black_point;
- (void) LinearStretchImage(*image,black_point,white_point);
- break;
- }
- if (LocaleCompare("linewidth",option+1) == 0)
- {
- draw_info->stroke_width=atof(argv[i+1]);
- break;
- }
- if (LocaleCompare("loop",option+1) == 0)
- {
- /*
- Set image iterations.
- */
- (*image)->iterations=(unsigned long) atol(argv[i+1]);
- break;
- }
- break;
- }
- case 'm':
- {
- if (LocaleCompare("map",option+1) == 0)
- {
- Image
- *map_image;
- ImageInfo
- *map_info;
- /*
- Transform image colors to match this set of colors.
- */
- if (*option == '+')
- break;
- map_info=CloneImageInfo(image_info);
- (void) CopyMagickString(map_info->filename,argv[i+1],
- MaxTextExtent);
- map_image=ReadImage(map_info,exception);
- map_info=DestroyImageInfo(map_info);
- CatchException(exception);
- if (map_image == (Image *) NULL)
- break;
- (void) MapImage(*image,map_image,quantize_info->dither);
- map_image=DestroyImage(map_image);
- break;
- }
- if (LocaleCompare("mask",option+1) == 0)
- {
- Image
- *mask;
- ImageInfo
- *mask_info;
- if (*option == '+')
- {
- /*
- Remove a mask.
- */
- (void) SetImageMask(*image,(Image *) NULL);
- break;
- }
- /*
- Set the image mask.
- */
- mask_info=CloneImageInfo(image_info);
- (void) CopyMagickString(mask_info->filename,argv[i+1],
- MaxTextExtent);
- mask=ReadImage(mask_info,exception);
- CatchException(exception);
- mask_info=DestroyImageInfo(mask_info);
- if (mask == (Image *) NULL)
- break;
- (void) SetImageMask(*image,mask);
- break;
- }
- if (LocaleCompare("matte",option+1) == 0)
- {
- if (*option == '-')
- if ((*image)->matte == MagickFalse)
- (void) SetImageOpacity(*image,OpaqueOpacity);
- (*image)->matte=(*option == '-') ? MagickTrue : MagickFalse;
- break;
- }
- if (LocaleCompare("mattecolor",option+1) == 0)
- {
- if (*option == '+')
- {
- (void) QueryColorDatabase(MatteColor,&(*image)->matte_color,
- exception);
- break;
- }
- (void) QueryColorDatabase(argv[i+1],&(*image)->matte_color,
- exception);
- break;
- }
- if (LocaleCompare("median",option+1) == 0)
- {
- Image
- *median_image;
- /*
- Median filter image.
- */
- (void) ParseGeometry(argv[i+1],&geometry_info);
- median_image=MedianFilterImage(*image,geometry_info.rho,exception);
- if (median_image == (Image *) NULL)
- break;
- InheritException(&median_image->exception,exception);
- *image=DestroyImage(*image);
- *image=median_image;
- break;
- }
- if (LocaleCompare("modulate",option+1) == 0)
- {
- (void) ModulateImage(*image,argv[i+1]);
- break;
- }
- if (LocaleCompare("monitor",option+1) == 0)
- {
- (void) SetImageProgressMonitor(*image,MonitorProgress,
- (void *) NULL);
- break;
- }
- if (LocaleCom…
Large files files are truncated, but you can click here to view the full file