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

Unified Diff: src/effects/SkEmbossMaskFilter.cpp

Issue 21835004: Blur refactoring (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Removed unneeded #includes Created 7 years, 4 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/SkBlurMaskFilter.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
===================================================================
--- src/effects/SkEmbossMaskFilter.cpp (revision 10932)
+++ src/effects/SkEmbossMaskFilter.cpp (working copy)
@@ -26,6 +26,12 @@
SkMaskFilter* SkBlurMaskFilter::CreateEmboss(const SkScalar direction[3],
SkScalar ambient, SkScalar specular,
SkScalar blurRadius) {
+ return SkBlurMaskFilter::CreateEmboss(SkBlurMask::ConvertRadiusToSigma(blurRadius),
+ direction, ambient, specular);
+}
+
+SkMaskFilter* SkBlurMaskFilter::CreateEmboss(SkScalar blurSigma, const SkScalar direction[3],
+ SkScalar ambient, SkScalar specular) {
if (direction == NULL) {
return NULL;
}
@@ -42,7 +48,7 @@
light.fAmbient = SkToU8(am);
light.fSpecular = SkToU8(sp);
- return SkNEW_ARGS(SkEmbossMaskFilter, (light, blurRadius));
+ return SkNEW_ARGS(SkEmbossMaskFilter, (blurSigma, light));
}
///////////////////////////////////////////////////////////////////////////////
@@ -56,9 +62,16 @@
}
}
+SkEmbossMaskFilter::SkEmbossMaskFilter(SkScalar blurSigma, const Light& light)
+ : fBlurSigma(blurSigma), fLight(light) {
+ normalize(fLight.fDirection);
+}
+
SkEmbossMaskFilter::SkEmbossMaskFilter(const Light& light, SkScalar blurRadius)
- : fLight(light), fBlurRadius(blurRadius) {
+ : fLight(light) {
normalize(fLight.fDirection);
+
+ fBlurSigma = SkBlurMask::ConvertRadiusToSigma(blurRadius);
}
SkMask::Format SkEmbossMaskFilter::getFormat() const {
@@ -66,17 +79,17 @@
}
bool SkEmbossMaskFilter::filterMask(SkMask* dst, const SkMask& src,
- const SkMatrix& matrix, SkIPoint* margin) const {
- SkScalar radius = matrix.mapRadius(fBlurRadius);
+ const SkMatrix& matrix, SkIPoint* margin) const {
+ SkScalar sigma = matrix.mapRadius(fBlurSigma);
- if (!SkBlurMask::Blur(dst, src, radius, SkBlurMask::kInner_Style,
- SkBlurMask::kLow_Quality)) {
+ if (!SkBlurMask::BoxBlur(dst, src, sigma, SkBlurMask::kInner_Style,
+ SkBlurMask::kLow_Quality)) {
return false;
}
dst->fFormat = SkMask::k3D_Format;
if (margin) {
- margin->set(SkScalarCeil(radius), SkScalarCeil(radius));
+ margin->set(SkScalarCeil(3*sigma), SkScalarCeil(3*sigma));
}
if (src.fImage == NULL) {
@@ -121,7 +134,18 @@
SkASSERT(buffer.getArrayCount() == sizeof(Light));
buffer.readByteArray(&fLight);
SkASSERT(fLight.fPad == 0); // for the font-cache lookup to be clean
- fBlurRadius = buffer.readScalar();
+ fBlurSigma = buffer.readScalar();
+#ifndef DELETE_THIS_CODE_WHEN_SKPS_ARE_REBUILT_AT_V13_AND_ALL_OTHER_INSTANCES_TOO
+ // Fixing this must be done in two stages. When the skps are recaptured in V13,
+ // remove the ConvertRadiusToSigma but retain the absolute value.
+ // At the same time, switch the code in flatten to write a positive value.
+ // When the skps are captured in V14 the absolute value can be removed.
+ if (fBlurSigma > 0) {
+ fBlurSigma = SkBlurMask::ConvertRadiusToSigma(fBlurSigma);
+ } else {
+ fBlurSigma = -fBlurSigma;
+ }
+#endif
}
void SkEmbossMaskFilter::flatten(SkFlattenableWriteBuffer& buffer) const {
@@ -130,7 +154,7 @@
Light tmpLight = fLight;
tmpLight.fPad = 0; // for the font-cache lookup to be clean
buffer.writeByteArray(&tmpLight, sizeof(tmpLight));
- buffer.writeScalar(fBlurRadius);
+ buffer.writeScalar(-fBlurSigma);
}
#ifdef SK_DEVELOPER
@@ -148,8 +172,8 @@
str->appendf("ambient: %d specular: %d ",
fLight.fAmbient, fLight.fSpecular);
- str->append("blurRadius: ");
- str->appendScalar(fBlurRadius);
+ str->append("blurSigma: ");
+ str->appendScalar(fBlurSigma);
str->append(")");
}
#endif
« no previous file with comments | « src/effects/SkBlurMaskFilter.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698