void Magick::Image::colorMatrix (const unsigned int order_,
const double *color_matrix_)
{
- double
- *values;
-
KernelInfo
*kernel_info;
kernel_info=AcquireKernelInfo("1");
kernel_info->width=order_;
kernel_info->height=order_;
- values=kernel_info->values;
kernel_info->values=(double *) color_matrix_;
MagickCore::Image* newImage =
ColorMatrixImage( image(), kernel_info, &exceptionInfo );
- kernel_info->values=values;
+ kernel_info->values=(double *) NULL;
kernel_info=DestroyKernelInfo(kernel_info);
replaceImage( newImage );
throwException( exceptionInfo );
{ "Morphology", { {"kernel", StringReference},
{"channel", MagickChannelOptions}, {"method", MagickMorphologyOptions},
{"iterations", IntegerReference} } },
- { "ColorMatrix", { {"matrix", StringReference} } },
+ { "ColorMatrix", { {"matrix", ArrayReference} } },
};
static SplayTreeInfo
case 108: /* Recolor */
case 134: /* ColorMatrix */
{
- KernelInfo
+ AV
+ *av;
+
+ double
*color_matrix;
+ KernelInfo
+ *kernel_info;
+
+ unsigned long
+ order;
+
if (attribute_flag[0] == 0)
break;
- color_matrix=AcquireKernelInfo(argument_list[0].string_reference);
- if (color_matrix == (KernelInfo *) NULL)
- break;
- image=ColorMatrixImage(image,color_matrix,exception);
- color_matrix=DestroyKernelInfo(color_matrix);
+ av=(AV *) argument_list[0].array_reference;
+ order=(unsigned long) sqrt(av_len(av)+1);
+ color_matrix=(double *) AcquireQuantumMemory(order,order*
+ sizeof(*color_matrix));
+ if (color_matrix == (double *) NULL)
+ {
+ ThrowPerlException(exception,ResourceLimitFatalError,
+ "MemoryAllocationFailed",PackageName);
+ goto PerlException;
+ }
+ for (j=0; (j < (long) (order*order)) && (j < (av_len(av)+1)); j++)
+ color_matrix[j]=(double) SvNV(*(av_fetch(av,j,0)));
+ for ( ; j < (long) (order*order); j++)
+ color_matrix[j]=0.0;
+ kernel_info=AcquireKernelInfo((const char *) NULL);
+ kernel_info->width=order;
+ kernel_info->height=order;
+ kernel_info->values=color_matrix;
+ image=ColorMatrixImage(image,kernel_info,exception);
+ kernel_info->values=(double *) NULL;
+ kernel_info=DestroyKernelInfo(kernel_info);
+ color_matrix=(double *) RelinquishMagickMemory(color_matrix);
break;
}
}
MagickExport Image *RecolorImage(const Image *image,const unsigned long order,
const double *color_matrix,ExceptionInfo *exception)
{
- double
- *values;
-
KernelInfo
*kernel_info;
Image
*recolor_image;
- kernel_info=AcquireKernelInfo("1");
+ kernel_info=AcquireKernelInfo((const char *) NULL);
kernel_info->width=order;
kernel_info->height=order;
- values=kernel_info->values;
kernel_info->values=(double *) color_matrix;
recolor_image=ColorMatrixImage(image,kernel_info,exception);
- kernel_info->values=values;
+ kernel_info->values=(double *) NULL;
kernel_info=DestroyKernelInfo(kernel_info);
return(recolor_image);
}
double
nan = sqrt((double)-1.0); /* Special Value : Not A Number */
- assert(kernel_string != (const char *) NULL);
+ if (kernel_string == (const char *) NULL)
+ {
+ kernel=(KernelInfo *) AcquireMagickMemory(sizeof(*kernel));
+ if (kernel == (KernelInfo *)NULL)
+ return(kernel);
+ (void) ResetMagickMemory(kernel,0,sizeof(*kernel));
+ kernel->type=UserDefinedKernel;
+ kernel->signature=MagickSignature;
+ return(kernel);
+ }
SetGeometryInfo(&args);
/* does it start with an alpha - Return a builtin kernel */
GetMagickToken(kernel_string,&p,token);
- if ( isalpha((int)token[0]) )
+ if (isalpha((int) ((unsigned char) *token)) != 0)
{
long
type;