OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2006 The Android Open Source Project | 2 * Copyright 2006 The Android Open Source Project |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkGradientShaderPriv.h" | 8 #include "SkGradientShaderPriv.h" |
9 #include "SkLinearGradient.h" | 9 #include "SkLinearGradient.h" |
10 #include "SkRadialGradient.h" | 10 #include "SkRadialGradient.h" |
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
319 } | 319 } |
320 | 320 |
321 void SkGradientShaderBase::flipGradientColors() { | 321 void SkGradientShaderBase::flipGradientColors() { |
322 FlipGradientColors(fOrigColors, fRecs, fOrigColors, fRecs, fColorCount); | 322 FlipGradientColors(fOrigColors, fRecs, fOrigColors, fRecs, fColorCount); |
323 } | 323 } |
324 | 324 |
325 bool SkGradientShaderBase::isOpaque() const { | 325 bool SkGradientShaderBase::isOpaque() const { |
326 return fColorsAreOpaque; | 326 return fColorsAreOpaque; |
327 } | 327 } |
328 | 328 |
329 static unsigned rounded_divide(unsigned numer, unsigned denom) { | |
330 return (numer + (denom >> 1)) / denom; | |
331 } | |
332 | |
333 bool SkGradientShaderBase::onAsLuminanceColor(SkColor* lum) const { | |
334 // we just compute an average color. | |
335 // possibly we could weight this based on the proportional width for each co lor | |
336 // assuming they are not evenly distributed in the fPos array. | |
337 int r = 0; | |
338 int g = 0; | |
339 int b = 0; | |
340 const int n = fColorCount; | |
341 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
| |
342 SkColor c = fOrigColors[i]; | |
343 r += SkColorGetR(c); | |
344 g += SkColorGetG(c); | |
345 b += SkColorGetB(c); | |
346 } | |
347 *lum = SkColorSetRGB(rounded_divide(r, n), rounded_divide(g, n), rounded_div ide(b, n)); | |
348 return true; | |
349 } | |
350 | |
329 SkGradientShaderBase::GradientShaderBaseContext::GradientShaderBaseContext( | 351 SkGradientShaderBase::GradientShaderBaseContext::GradientShaderBaseContext( |
330 const SkGradientShaderBase& shader, const ContextRec& rec) | 352 const SkGradientShaderBase& shader, const ContextRec& rec) |
331 : INHERITED(shader, rec) | 353 : INHERITED(shader, rec) |
332 , fCache(shader.refCache(getPaintAlpha())) | 354 , fCache(shader.refCache(getPaintAlpha())) |
333 { | 355 { |
334 const SkMatrix& inverse = this->getTotalInverse(); | 356 const SkMatrix& inverse = this->getTotalInverse(); |
335 | 357 |
336 fDstToIndex.setConcat(shader.fPtsToUnit, inverse); | 358 fDstToIndex.setConcat(shader.fPtsToUnit, inverse); |
337 | 359 |
338 fDstToIndexProc = fDstToIndex.getMapXYProc(); | 360 fDstToIndexProc = fDstToIndex.getMapXYProc(); |
(...skipping 884 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1223 (*stops)[i] = stop; | 1245 (*stops)[i] = stop; |
1224 stop = i < outColors - 1 ? stop + random->nextUScalar1() * (1.f - st op) : 1.f; | 1246 stop = i < outColors - 1 ? stop + random->nextUScalar1() * (1.f - st op) : 1.f; |
1225 } | 1247 } |
1226 } | 1248 } |
1227 *tm = static_cast<SkShader::TileMode>(random->nextULessThan(SkShader::kTileM odeCount)); | 1249 *tm = static_cast<SkShader::TileMode>(random->nextULessThan(SkShader::kTileM odeCount)); |
1228 | 1250 |
1229 return outColors; | 1251 return outColors; |
1230 } | 1252 } |
1231 | 1253 |
1232 #endif | 1254 #endif |
OLD | NEW |