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

Side by Side Diff: src/effects/gradients/SkGradientShader.cpp

Issue 492963002: extend SkShader to report a luminance-color to be used for gamma correction (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 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 unified diff | Download patch
OLDNEW
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
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
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698