From: Cristy Date: Tue, 15 Aug 2017 22:44:44 +0000 (-0400) Subject: https://www.imagemagick.org/discourse-server/viewtopic.php?f=2&t=32506 X-Git-Tag: 7.0.6-8~7 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b86955f5082fce69b77d62ecd5b10733a0fcf1f4;p=imagemagick https://www.imagemagick.org/discourse-server/viewtopic.php?f=2&t=32506 --- diff --git a/ChangeLog b/ChangeLog index 7fa05948f..53980e852 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,7 +1,7 @@ 2017-08-14 7.0.6-7 Cristy * Fixed numerous memory leaks (reference https://github.com/ImageMagick/ImageMagick/issues). - * Support spline-lobes resize filter. Define the lobes with the + * Support CubicSpline resize filter. Define the lobes with the -define filter:lobes={2,3,4} (reference https://www.imagemagick.org/discourse-server/viewtopic.php?f=2&t=32506). * Prevent assertion failure when creating PDF thumbnail (reference diff --git a/MagickCore/option.c b/MagickCore/option.c index e3bd97ec5..2fb55175d 100644 --- a/MagickCore/option.c +++ b/MagickCore/option.c @@ -1164,7 +1164,7 @@ static const OptionInfo { "Sinc", SincFilter, UndefinedOptionFlag, MagickFalse }, { "SincFast", SincFastFilter, UndefinedOptionFlag, MagickFalse }, { "Spline", SplineFilter, UndefinedOptionFlag, MagickFalse }, - { "SplineLobes", SplineLobesFilter, UndefinedOptionFlag, MagickFalse }, + { "CubicSpline", CubicSplineFilter, UndefinedOptionFlag, MagickFalse }, { "Triangle", TriangleFilter, UndefinedOptionFlag, MagickFalse }, { "Welch", WelchFilter, UndefinedOptionFlag, MagickFalse }, { "Welsh", WelchFilter, UndefinedOptionFlag, MagickTrue }, /*misspell*/ diff --git a/MagickCore/resample.h b/MagickCore/resample.h index 6fdbc532e..2086e3c5c 100644 --- a/MagickCore/resample.h +++ b/MagickCore/resample.h @@ -62,7 +62,7 @@ typedef enum CosineFilter, SplineFilter, LanczosRadiusFilter, - SplineLobesFilter, + CubicSplineFilter, SentinelFilter /* a count of all the filters, not a real filter */ } FilterType; diff --git a/MagickCore/resize.c b/MagickCore/resize.c index 7bf59e17f..608e086c3 100644 --- a/MagickCore/resize.c +++ b/MagickCore/resize.c @@ -244,6 +244,46 @@ static double CubicBC(const double x,const ResizeFilter *resize_filter) return(0.0); } +static double CubicSpline(const double x,const ResizeFilter *resize_filter) +{ + if (resize_filter->support <= 2.0) + { + /* + 2-lobe Spline filter. + */ + if (x < 1.0) + return(((x-9.0/5.0)*x-1.0/5.0)*x+1.0); + if (x < 2.0) + return(((-1.0/3.0*(x-1.0)+4.0/5.0)*(x-1.0)-7.0/15.0)*(x-1.0)); + return(0.0); + } + if (resize_filter->support <= 3.0) + { + /* + 3-lobe Spline filter. + */ + if (x < 1.0) + return(((13.0/11.0*x-453.0/209.0)*x-3.0/209.0)*x+1.0); + if (x < 2.0) + return(((-6.0/11.0*(x-1.0)+270.0/209.0)*(x-1.0)-156.0/209.0)*(x-1.0)); + if (x < 3.0) + return(((1.0/11.0*(x-2.0)-45.0/209.0)*(x-2.0)+26.0/209.0)*(x-2.0)); + return(0.0); + } + /* + 4-lobe Spline filter. + */ + if (x < 1.0) + return(((49.0/41.0*x-6387.0/2911.0)*x-3.0/2911.0)*x+1.0); + if (x < 2.0) + return(((-24.0/41.0*(x-1.0)+4032.0/2911.0)*(x-1.0)-2328.0/2911.0)*(x-1.0)); + if (x < 3.0) + return(((6.0/41.0*(x-2.0)-1008.0/2911.0)*(x-2.0)+582.0/2911.0)*(x-2.0)); + if (x < 4.0) + return(((-1.0/41.0*(x-3.0)+168.0/2911.0)*(x-3.0)-97.0/2911.0)*(x-3.0)); + return(0.0); +} + static double Gaussian(const double x,const ResizeFilter *resize_filter) { /* @@ -500,46 +540,6 @@ static double SincFast(const double x, } } -static double SplineLobes(const double x,const ResizeFilter *resize_filter) -{ - if (resize_filter->support <= 2.0) - { - /* - 2-lobe Spline filter. - */ - if (x < 1.0) - return(((x-9.0/5.0)*x-1.0/5.0)*x+1.0); - if (x < 2.0) - return(((-1.0/3.0*(x-1.0)+4.0/5.0)*(x-1.0)-7.0/15.0)*(x-1.0)); - return(0.0); - } - if (resize_filter->support <= 3.0) - { - /* - 3-lobe Spline filter. - */ - if (x < 1.0) - return(((13.0/11.0*x-453.0/209.0)*x-3.0/209.0)*x+1.0); - if (x < 2.0) - return(((-6.0/11.0*(x-1.0)+270.0/209.0)*(x-1.0)-156.0/209.0)*(x-1.0)); - if (x < 3.0) - return(((1.0/11.0*(x-2.0)-45.0/209.0)*(x-2.0)+26.0/209.0)*(x-2.0)); - return(0.0); - } - /* - 4-lobe Spline filter. - */ - if (x < 1.0) - return(((49.0/41.0*x-6387.0/2911.0)*x-3.0/2911.0)*x+1.0); - if (x < 2.0) - return(((-24.0/41.0*(x-1.0)+4032.0/2911.0)*(x-1.0)-2328.0/2911.0)*(x-1.0)); - if (x < 3.0) - return(((6.0/41.0*(x-2.0)-1008.0/2911.0)*(x-2.0)+582.0/2911.0)*(x-2.0)); - if (x < 4.0) - return(((-1.0/41.0*(x-3.0)+168.0/2911.0)*(x-3.0)-97.0/2911.0)*(x-3.0)); - return(0.0); -} - static double Triangle(const double x, const ResizeFilter *magick_unused(resize_filter)) { @@ -824,7 +824,7 @@ MagickPrivate ResizeFilter *AcquireResizeFilter(const Image *image, { LanczosFilter, CosineFilter }, /* Cosine window (3 lobes) */ { SplineFilter, BoxFilter }, /* Spline Cubic Filter */ { LanczosRadiusFilter, LanczosFilter }, /* Lanczos with integer radius */ - { SplineLobesFilter, BoxFilter }, /* SplineLobes (n lobes) */ + { CubicSplineFilter, BoxFilter }, /* CubicSpline (2/3/4 lobes) */ }; /* Table mapping the filter/window from the above table to an actual function. @@ -888,7 +888,7 @@ MagickPrivate ResizeFilter *AcquireResizeFilter(const Image *image, { Cosine, 1.0, 1.0, 0.0, 0.0, CosineWeightingFunction }, /* Low level cosine window */ { CubicBC, 2.0, 2.0, 1.0, 0.0, CubicBCWeightingFunction }, /* Cubic B-Spline (B=1,C=0) */ { SincFast, 3.0, 1.0, 0.0, 0.0, SincFastWeightingFunction }, /* Lanczos, Interger Radius */ - { SplineLobes, 2.0, 0.5, 0.0, 0.0, BoxWeightingFunction }, /* Spline Lobes 2-lobed */ + { CubicSpline,2.0, 0.5, 0.0, 0.0, BoxWeightingFunction }, /* Spline Lobes 2-lobed */ }; /* The known zero crossings of the Jinc() or more accurately the Jinc(x*PI)