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) |