Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(84)

Side by Side Diff: include/effects/SkLightingImageFilter.h

Issue 23533042: Fixed issues found by fuzzer (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | src/effects/SkBicubicImageFilter.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2012 The Android Open Source Project 2 * Copyright 2012 The Android Open Source Project
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 8
9 #ifndef SkLightingImageFilter_DEFINED 9 #ifndef SkLightingImageFilter_DEFINED
10 #define SkLightingImageFilter_DEFINED 10 #define SkLightingImageFilter_DEFINED
11 11
12 #include "SkImageFilter.h" 12 #include "SkImageFilter.h"
13 #include "SkColor.h" 13 #include "SkColor.h"
14 14
15 class SK_API SkPoint3 { 15 class SK_API SkPoint3 {
16 public: 16 public:
17 SkPoint3() {} 17 SkPoint3() {}
18 SkPoint3(SkScalar x, SkScalar y, SkScalar z) 18 SkPoint3(SkScalar x, SkScalar y, SkScalar z)
19 : fX(x), fY(y), fZ(z) {} 19 : fX(x), fY(y), fZ(z) {}
20 SkScalar dot(const SkPoint3& other) const { 20 SkScalar dot(const SkPoint3& other) const {
21 return SkScalarMul(fX, other.fX) 21 return SkScalarMul(fX, other.fX)
22 + SkScalarMul(fY, other.fY) 22 + SkScalarMul(fY, other.fY)
23 + SkScalarMul(fZ, other.fZ); 23 + SkScalarMul(fZ, other.fZ);
24 } 24 }
25 SkScalar maxComponent() const { 25 SkScalar maxComponent() const {
26 return fX > fY ? (fX > fZ ? fX : fZ) : (fY > fZ ? fY : fZ); 26 return fX > fY ? (fX > fZ ? fX : fZ) : (fY > fZ ? fY : fZ);
27 } 27 }
28 void normalize() { 28 void normalize() {
29 SkScalar scale = SkScalarInvert(SkScalarSqrt(dot(*this))); 29 // Small epsilon is added to prevent division by 0.
30 SkScalar scale = SkScalarInvert(SkScalarSqrt(dot(*this)) + SK_ScalarNear lyZero);
30 fX = SkScalarMul(fX, scale); 31 fX = SkScalarMul(fX, scale);
31 fY = SkScalarMul(fY, scale); 32 fY = SkScalarMul(fY, scale);
32 fZ = SkScalarMul(fZ, scale); 33 fZ = SkScalarMul(fZ, scale);
33 } 34 }
34 SkPoint3 operator*(SkScalar scalar) const { 35 SkPoint3 operator*(SkScalar scalar) const {
35 return SkPoint3(SkScalarMul(fX, scalar), 36 return SkPoint3(SkScalarMul(fX, scalar),
36 SkScalarMul(fY, scalar), 37 SkScalarMul(fY, scalar),
37 SkScalarMul(fZ, scalar)); 38 SkScalarMul(fZ, scalar));
38 } 39 }
39 SkPoint3 operator-(const SkPoint3& other) const { 40 SkPoint3 operator-(const SkPoint3& other) const {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 const SkLight* light() const { return fLight; } 84 const SkLight* light() const { return fLight; }
84 SkScalar surfaceScale() const { return fSurfaceScale; } 85 SkScalar surfaceScale() const { return fSurfaceScale; }
85 86
86 private: 87 private:
87 typedef SkImageFilter INHERITED; 88 typedef SkImageFilter INHERITED;
88 SkLight* fLight; 89 SkLight* fLight;
89 SkScalar fSurfaceScale; 90 SkScalar fSurfaceScale;
90 }; 91 };
91 92
92 #endif 93 #endif
OLDNEW
« no previous file with comments | « no previous file | src/effects/SkBicubicImageFilter.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698