aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/SkGaussFilter.cpp
diff options
context:
space:
mode:
authorGravatar Herbert Derby <herb@google.com>2017-12-06 18:02:43 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-12-07 14:50:20 +0000
commit8ba13f63020b2301d2a97392804d14e5e6f7b2b2 (patch)
tree505581927be6e0ce23d91cf23c1d4dfd33ce5c8e /src/core/SkGaussFilter.cpp
parent66db75da67fb4c75207c2e495765e1e74584e3b1 (diff)
Fix buffer off-by-one error.
The maximum number of Gaussian factors produces is 5. But, 6 elements are needed to calculate those 5. BUG=chromium:792316 Change-Id: Ief356f6c21bed7e90e33900989744c27cfe8a9a9 Reviewed-on: https://skia-review.googlesource.com/81560 Reviewed-by: Mike Klein <mtklein@chromium.org> Commit-Queue: Herb Derby <herb@google.com>
Diffstat (limited to 'src/core/SkGaussFilter.cpp')
-rw-r--r--src/core/SkGaussFilter.cpp6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/core/SkGaussFilter.cpp b/src/core/SkGaussFilter.cpp
index 5bbdc05f43..a134b06321 100644
--- a/src/core/SkGaussFilter.cpp
+++ b/src/core/SkGaussFilter.cpp
@@ -82,10 +82,14 @@ static int calculate_bessel_factors(double sigma, double *gauss) {
// "Scale-Space for Discrete Signals" by Tony Lindeberg.
// gauss(n; var) = besselI_n(var) / (e^var)
auto d = std::exp(var);
- double b[6] = {besselI_0(var), besselI_1(var)};
+ double b[SkGaussFilter::kGaussArrayMax] = {besselI_0(var), besselI_1(var)};
gauss[0] = b[0]/d;
gauss[1] = b[1]/d;
+ // The code below is tricky, and written to mirror the recursive equations from the book.
+ // The maximum spread for sigma == 2 is guass[4], but in order to know to stop guass[5]
+ // is calculated. At this point n == 5 meaning that gauss[0..4] are the factors, but a 6th
+ // element was used to calculate them.
int n = 1;
// The recurrence relation below is from "Numerical Recipes" 3rd Edition.
// Equation 6.5.16 p.282