#define Minimize(assign,value) assign=MagickMin(assign,value)
#define Maximize(assign,value) assign=MagickMax(assign,value)
+/* Integer Factorial Function - for a Binomial kernel */
+#if 1
+static inline size_t fact(size_t n)
+{
+ size_t l,f;
+ for(f=1, l=2; l <= n; f=f*l, l++);
+ return(f);
+}
+#elif 1 /* glibc floating point alternatives */
+#define fact(n) ((size_t)tgamma((double)n+1))
+#else
+#define fact(n) ((size_t)lgamma((double)n+1))
+#endif
+
+
/* Currently these are only internal to this module */
static void
CalcKernelMetaData(KernelInfo *),
% Note that the first argument is the width of the kernel and not the
% radius of the kernel.
%
+% Binomial:[{radius}]
+% Generate a discrete kernel using a 2 dimentional Pascel's Triangle
+% of values.
+%
% # Still to be implemented...
% #
% # Filter2D
case LoGKernel:
case BlurKernel:
case CometKernel:
+ case BinomialKernel:
case DiamondKernel:
case SquareKernel:
case RectangleKernel:
RotateKernelInfo(kernel, args->xi); /* Rotate by angle */
break;
}
+ case BinomialKernel:
+ {
+ size_t
+ order_f;
+
+ if (args->rho < 1.0)
+ kernel->width = kernel->height = 3; /* default radius = 1 */
+ else
+ kernel->width = kernel->height = ((size_t)args->rho)*2+1;
+ kernel->x = kernel->y = (ssize_t) (kernel->width-1)/2;
+
+ order_f = fact(kernel->width-1);
+
+ kernel->values=(double *) AcquireAlignedMemory(kernel->width,
+ kernel->height*sizeof(*kernel->values));
+ if (kernel->values == (double *) NULL)
+ return(DestroyKernelInfo(kernel));
+
+ /* set all kernel values within diamond area to scale given */
+ for ( i=0, v=0; v < (ssize_t)kernel->height; v++)
+ { size_t
+ alpha = order_f / ( fact(v) * fact(kernel->height-v-1) );
+ for ( u=0; u < (ssize_t)kernel->width; u++, i++)
+ kernel->positive_range += kernel->values[i] = (double)
+ (alpha * order_f / ( fact(u) * fact(kernel->height-u-1) ));
+ }
+ kernel->minimum = 1.0;
+ kernel->maximum = kernel->values[kernel->x+kernel->y*kernel->width];
+ kernel->negative_range = 0.0;
+ break;
+ }
/*
Convolution Kernels - Well Known Named Constant Kernels
{ "LoG", LoGKernel, UndefinedOptionFlag, MagickFalse },
{ "Blur", BlurKernel, UndefinedOptionFlag, MagickFalse },
{ "Comet", CometKernel, UndefinedOptionFlag, MagickFalse },
+ { "Binomial", BinomialKernel, UndefinedOptionFlag, MagickFalse },
{ "Laplacian", LaplacianKernel, UndefinedOptionFlag, MagickFalse },
{ "Sobel", SobelKernel, UndefinedOptionFlag, MagickFalse },
{ "FreiChen", FreiChenKernel, UndefinedOptionFlag, MagickFalse },
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
-% CloneImageOptions() clones one or more image options.
+% CloneImageOptions() clones all global image options, to another image_info
%
% The format of the CloneImageOptions method is:
%
%
% A description of each parameter follows:
%
-% o image_info: the image info.
+% o image_info: the image info to recieve the cloned options.
%
-% o clone_info: the clone image info.
+% o clone_info: the source image info for options to clone.
%
*/
MagickExport MagickBooleanType CloneImageOptions(ImageInfo *image_info,
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% DefineImageOption() associates an assignment string of the form
-% "key=value" with an image option. It is equivelent to SetImageOption().
+% "key=value" with a global image option. It is equivelent to
+% SetImageOption().
%
% The format of the DefineImageOption method is:
%
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
-% DeleteImageOption() deletes an key from the image map.
+% DeleteImageOption() deletes an key from the global image options.
%
% Returns MagickTrue is the option is found and deleted from the Options.
%
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
-% DestroyImageOptions() releases memory associated with image option values.
+% DestroyImageOptions() destroys all global options and associated memory
+% attached to the given image_info image list.
%
% The format of the DestroyDefines method is:
%
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
-% GetImageOption() gets a value associated with an image option.
+% GetImageOption() gets a value associated with the global image options.
+%
+% The returned string is a constant string in the tree and should NOT be
+% freed by the caller.
%
% The format of the GetImageOption method is:
%
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
-% GetNextImageOption() gets the next image option value.
+% GetNextImageOption() gets the next global option value.
%
% The format of the GetNextImageOption method is:
%
%
% RemoveImageOption() removes an option from the image and returns its value.
%
+% In this case the ConstantString() value returned should be freed by the
+% caller when finished.
+%
% The format of the RemoveImageOption method is:
%
% char *RemoveImageOption(ImageInfo *image_info,const char *option)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% ResetImageOptions() resets the image_info option. That is, it deletes
-% all options associated with the image_info structure.
+% all global options associated with the image_info structure.
%
% The format of the ResetImageOptions method is:
%
image_info->options=NewSplayTree(CompareSplayTreeString,
RelinquishMagickMemory,RelinquishMagickMemory);
- /* Delete Option if NULL */
+ /* Delete Option if NULL -- empty string values are valid! */
if (value == (const char *) NULL)
return(DeleteImageOption(image_info,option));