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 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
244 } | 244 } |
245 | 245 |
246 void SkGradientShaderBase::flipGradientColors() { | 246 void SkGradientShaderBase::flipGradientColors() { |
247 FlipGradientColors(fOrigColors, fRecs, fOrigColors, fRecs, fColorCount); | 247 FlipGradientColors(fOrigColors, fRecs, fOrigColors, fRecs, fColorCount); |
248 } | 248 } |
249 | 249 |
250 bool SkGradientShaderBase::isOpaque() const { | 250 bool SkGradientShaderBase::isOpaque() const { |
251 return fColorsAreOpaque; | 251 return fColorsAreOpaque; |
252 } | 252 } |
253 | 253 |
254 static unsigned rndivbyte(unsigned numer, unsigned denom) { | |
bungeman-skia
2014/08/21 14:15:43
rounded_divide?
It isn't totally clear that the '
reed1
2014/08/21 20:07:39
Done.
| |
255 unsigned result = (numer + (denom >> 1)) / denom; | |
256 SkASSERT(SkToU8(result) == result); | |
257 return result; | |
258 } | |
259 | |
260 bool SkGradientShaderBase::onAsLuminanceColor(SkColor* lum) const { | |
261 // we just compute an average color | |
262 int r = 0; | |
263 int g = 0; | |
264 int b = 0; | |
265 const int n = fColorCount; | |
266 for (int i = 0; i < n; ++i) { | |
267 SkColor c = fOrigColors[i]; | |
268 r += SkColorGetR(c); | |
269 g += SkColorGetG(c); | |
270 b += SkColorGetB(c); | |
271 } | |
272 *lum = SkColorSetRGB(rndivbyte(r, n),rndivbyte(g, n), rndivbyte(b, n)); | |
273 return true; | |
274 } | |
275 | |
254 SkGradientShaderBase::GradientShaderBaseContext::GradientShaderBaseContext( | 276 SkGradientShaderBase::GradientShaderBaseContext::GradientShaderBaseContext( |
255 const SkGradientShaderBase& shader, const ContextRec& rec) | 277 const SkGradientShaderBase& shader, const ContextRec& rec) |
256 : INHERITED(shader, rec) | 278 : INHERITED(shader, rec) |
257 , fCache(shader.refCache(getPaintAlpha())) | 279 , fCache(shader.refCache(getPaintAlpha())) |
258 { | 280 { |
259 const SkMatrix& inverse = this->getTotalInverse(); | 281 const SkMatrix& inverse = this->getTotalInverse(); |
260 | 282 |
261 fDstToIndex.setConcat(shader.fPtsToUnit, inverse); | 283 fDstToIndex.setConcat(shader.fPtsToUnit, inverse); |
262 | 284 |
263 fDstToIndexProc = fDstToIndex.getMapXYProc(); | 285 fDstToIndexProc = fDstToIndex.getMapXYProc(); |
(...skipping 884 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1148 (*stops)[i] = stop; | 1170 (*stops)[i] = stop; |
1149 stop = i < outColors - 1 ? stop + random->nextUScalar1() * (1.f - st op) : 1.f; | 1171 stop = i < outColors - 1 ? stop + random->nextUScalar1() * (1.f - st op) : 1.f; |
1150 } | 1172 } |
1151 } | 1173 } |
1152 *tm = static_cast<SkShader::TileMode>(random->nextULessThan(SkShader::kTileM odeCount)); | 1174 *tm = static_cast<SkShader::TileMode>(random->nextULessThan(SkShader::kTileM odeCount)); |
1153 | 1175 |
1154 return outColors; | 1176 return outColors; |
1155 } | 1177 } |
1156 | 1178 |
1157 #endif | 1179 #endif |
OLD | NEW |