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

Unified Diff: src/effects/SkEmbossMaskFilter.cpp

Issue 1693013002: Check bounds before casting float to integer in SamplePatch.cpp and SkBlurMaskFilter::CreateEmboss. (Closed) Base URL: https://skia.googlesource.com/skia@unit-scalar-clamp-to-byte
Patch Set: Created 4 years, 10 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 | « samplecode/SamplePatch.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/effects/SkEmbossMaskFilter.cpp
diff --git a/src/effects/SkEmbossMaskFilter.cpp b/src/effects/SkEmbossMaskFilter.cpp
index 64afa49447dfb8614394e266a51a0929dfdb7dfd..aacc191ff7ddfb6645683b047de904589c0cb9d7 100644
--- a/src/effects/SkEmbossMaskFilter.cpp
+++ b/src/effects/SkEmbossMaskFilter.cpp
@@ -17,15 +17,6 @@ SkMaskFilter* SkEmbossMaskFilter::Create(SkScalar blurSigma, const Light& light)
return new SkEmbossMaskFilter(blurSigma, light);
}
-static inline int pin2byte(int n) {
- if (n < 0) {
- n = 0;
- } else if (n > 0xFF) {
- n = 0xFF;
- }
- return n;
-}
-
SkMaskFilter* SkBlurMaskFilter::CreateEmboss(const SkScalar direction[3],
SkScalar ambient, SkScalar specular,
SkScalar blurRadius) {
@@ -39,17 +30,14 @@ SkMaskFilter* SkBlurMaskFilter::CreateEmboss(SkScalar blurSigma, const SkScalar
return nullptr;
}
- // ambient should be 0...1 as a scalar
- int am = pin2byte(SkScalarToFixed(ambient) >> 8);
-
- // specular should be 0..15.99 as a scalar
- int sp = pin2byte(SkScalarToFixed(specular) >> 12);
-
SkEmbossMaskFilter::Light light;
memcpy(light.fDirection, direction, sizeof(light.fDirection));
- light.fAmbient = SkToU8(am);
- light.fSpecular = SkToU8(sp);
+ // ambient should be 0...1 as a scalar
+ light.fAmbient = SkUnitScalarClampToByte(ambient);
+ // specular should be 0..15.99 as a scalar
+ static const SkScalar kSpecularMultiplier = SkIntToScalar(255) / 16;
+ light.fSpecular = static_cast<U8CPU>(SkScalarPin(specular, 0, 16) * kSpecularMultiplier + 0.5);
return SkEmbossMaskFilter::Create(blurSigma, light);
}
« no previous file with comments | « samplecode/SamplePatch.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698