Index: src/effects/gradients/SkGradientShader.cpp |
diff --git a/src/effects/gradients/SkGradientShader.cpp b/src/effects/gradients/SkGradientShader.cpp |
index b14a3f7e4fb9ae6972b0f1ccc6c3be24b86d8264..791d34dcb79931d2cdf53b73628125754fac55e7 100644 |
--- a/src/effects/gradients/SkGradientShader.cpp |
+++ b/src/effects/gradients/SkGradientShader.cpp |
@@ -326,6 +326,28 @@ bool SkGradientShaderBase::isOpaque() const { |
return fColorsAreOpaque; |
} |
+static unsigned rounded_divide(unsigned numer, unsigned denom) { |
+ return (numer + (denom >> 1)) / denom; |
+} |
+ |
+bool SkGradientShaderBase::onAsLuminanceColor(SkColor* lum) const { |
+ // we just compute an average color. |
+ // possibly we could weight this based on the proportional width for each color |
+ // assuming they are not evenly distributed in the fPos array. |
+ int r = 0; |
+ int g = 0; |
+ int b = 0; |
+ const int n = fColorCount; |
+ for (int i = 0; i < n; ++i) { |
tomhudson
2014/08/29 22:52:43
Seems like this works well for the trivial case (2
reed1
2014/09/02 13:52:55
Agreed. I have a comment to that effect just above
|
+ SkColor c = fOrigColors[i]; |
+ r += SkColorGetR(c); |
+ g += SkColorGetG(c); |
+ b += SkColorGetB(c); |
+ } |
+ *lum = SkColorSetRGB(rounded_divide(r, n), rounded_divide(g, n), rounded_divide(b, n)); |
+ return true; |
+} |
+ |
SkGradientShaderBase::GradientShaderBaseContext::GradientShaderBaseContext( |
const SkGradientShaderBase& shader, const ContextRec& rec) |
: INHERITED(shader, rec) |