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

Unified Diff: src/effects/SkLightingImageFilter.cpp

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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/effects/SkBicubicImageFilter.cpp ('k') | tests/ImageFilterTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/effects/SkLightingImageFilter.cpp
diff --git a/src/effects/SkLightingImageFilter.cpp b/src/effects/SkLightingImageFilter.cpp
index 999b8f8bfa2863e54e71adfc628fc475f2e71eb5..c519790e2349ae2fe773b737f8a6c02bad57be3e 100644
--- a/src/effects/SkLightingImageFilter.cpp
+++ b/src/effects/SkLightingImageFilter.cpp
@@ -64,9 +64,9 @@ public:
colorScale = SkScalarClampMax(colorScale, SK_Scalar1);
SkPoint3 color(lightColor * colorScale);
return SkPackARGB32(255,
- SkScalarFloorToInt(color.fX),
- SkScalarFloorToInt(color.fY),
- SkScalarFloorToInt(color.fZ));
+ SkClampMax(SkScalarFloorToInt(color.fX), 255),
+ SkClampMax(SkScalarFloorToInt(color.fY), 255),
+ SkClampMax(SkScalarFloorToInt(color.fZ), 255));
}
private:
SkScalar fKD;
@@ -84,10 +84,10 @@ public:
SkScalarPow(normal.dot(halfDir), fShininess));
colorScale = SkScalarClampMax(colorScale, SK_Scalar1);
SkPoint3 color(lightColor * colorScale);
- return SkPackARGB32(SkScalarFloorToInt(color.maxComponent()),
- SkScalarFloorToInt(color.fX),
- SkScalarFloorToInt(color.fY),
- SkScalarFloorToInt(color.fZ));
+ return SkPackARGB32(SkClampMax(SkScalarFloorToInt(color.maxComponent()), 255),
+ SkClampMax(SkScalarFloorToInt(color.fX), 255),
+ SkClampMax(SkScalarFloorToInt(color.fY), 255),
+ SkClampMax(SkScalarFloorToInt(color.fZ), 255));
}
private:
SkScalar fKS;
@@ -673,7 +673,7 @@ public:
: INHERITED(color),
fLocation(location),
fTarget(target),
- fSpecularExponent(specularExponent)
+ fSpecularExponent(SkScalarPin(specularExponent, kSpecularExponentMin, kSpecularExponentMax))
{
fS = target - location;
fS.normalize();
@@ -778,6 +778,9 @@ protected:
}
private:
+ static const SkScalar kSpecularExponentMin;
+ static const SkScalar kSpecularExponentMax;
+
typedef SkLight INHERITED;
SkPoint3 fLocation;
SkPoint3 fTarget;
@@ -788,6 +791,11 @@ private:
SkPoint3 fS;
};
+// According to the spec, the specular term should be in the range [1, 128] :
+// http://www.w3.org/TR/SVG/filters.html#feSpecularLightingSpecularExponentAttribute
+const SkScalar SkSpotLight::kSpecularExponentMin = SkFloatToScalar(1.0f);
+const SkScalar SkSpotLight::kSpecularExponentMax = SkFloatToScalar(128.0f);
+
///////////////////////////////////////////////////////////////////////////////
SkLightingImageFilter::SkLightingImageFilter(SkLight* light, SkScalar surfaceScale, SkImageFilter* input, const SkIRect* cropRect)
« no previous file with comments | « src/effects/SkBicubicImageFilter.cpp ('k') | tests/ImageFilterTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698