aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/effects/GrMatrixConvolutionEffect.cpp
diff options
context:
space:
mode:
authorGravatar Greg Daniel <egdaniel@google.com>2018-04-03 14:03:15 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-04-03 18:51:40 +0000
commit4eda8d9fb3bd304a26ec8332e2410f97a3131e68 (patch)
tree184d1766512ede38217d14ca6e41b8260e9dca62 /src/gpu/effects/GrMatrixConvolutionEffect.cpp
parente11382bde0f259983d51fa4427242d9988c9d027 (diff)
Check for divide by zero in fill_in_2D_gaussian_kernel
Same change as the 1D one, but now with more dimensions!! Bug: skia:7769 Change-Id: I152031780ab71ba106d4fa65d52960ec4358274e Reviewed-on: https://skia-review.googlesource.com/118262 Commit-Queue: Greg Daniel <egdaniel@google.com> Reviewed-by: Brian Osman <brianosman@google.com>
Diffstat (limited to 'src/gpu/effects/GrMatrixConvolutionEffect.cpp')
-rw-r--r--src/gpu/effects/GrMatrixConvolutionEffect.cpp15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/gpu/effects/GrMatrixConvolutionEffect.cpp b/src/gpu/effects/GrMatrixConvolutionEffect.cpp
index ffbcf500ab..56b012afe5 100644
--- a/src/gpu/effects/GrMatrixConvolutionEffect.cpp
+++ b/src/gpu/effects/GrMatrixConvolutionEffect.cpp
@@ -215,8 +215,19 @@ bool GrMatrixConvolutionEffect::onIsEqual(const GrFragmentProcessor& sBase) cons
static void fill_in_2D_gaussian_kernel(float* kernel, int width, int height,
SkScalar sigmaX, SkScalar sigmaY) {
SkASSERT(width * height <= MAX_KERNEL_SIZE);
- const float sigmaXDenom = 1.0f / (2.0f * SkScalarToFloat(SkScalarSquare(sigmaX)));
- const float sigmaYDenom = 1.0f / (2.0f * SkScalarToFloat(SkScalarSquare(sigmaY)));
+ const float twoSigmaSqrdX = 2.0f * SkScalarToFloat(SkScalarSquare(sigmaX));
+ const float twoSigmaSqrdY = 2.0f * SkScalarToFloat(SkScalarSquare(sigmaY));
+
+ if (SkScalarNearlyZero(twoSigmaSqrdX, SK_ScalarNearlyZero) ||
+ SkScalarNearlyZero(twoSigmaSqrdY, SK_ScalarNearlyZero)) {
+ for (int i = 0; i < width * height; ++i) {
+ kernel[i] = 0.0f;
+ }
+ return;
+ }
+
+ const float sigmaXDenom = 1.0f / twoSigmaSqrdX;
+ const float sigmaYDenom = 1.0f / twoSigmaSqrdY;
const int xRadius = width / 2;
const int yRadius = height / 2;