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

Side by Side Diff: src/effects/SkPerlinNoiseShader.cpp

Issue 132053002: Use truncation, not rounding, when converting perlin noise seed (required by SVG spec). (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Add comment Created 6 years, 11 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2013 Google Inc. 2 * Copyright 2013 Google Inc.
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 "SkDither.h" 8 #include "SkDither.h"
9 #include "SkPerlinNoiseShader.h" 9 #include "SkPerlinNoiseShader.h"
10 #include "SkColorFilter.h" 10 #include "SkColorFilter.h"
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 if (result <= 0) 117 if (result <= 0)
118 result += kRandMaximum; 118 result += kRandMaximum;
119 fSeed = result; 119 fSeed = result;
120 return result; 120 return result;
121 } 121 }
122 122
123 void init(SkScalar seed) 123 void init(SkScalar seed)
124 { 124 {
125 static const SkScalar gInvBlockSizef = SkScalarInvert(SkIntToScalar(kBlo ckSize)); 125 static const SkScalar gInvBlockSizef = SkScalarInvert(SkIntToScalar(kBlo ckSize));
126 126
127 // According to the SVG spec, we must truncate (not round) the seed valu e.
128 fSeed = SkScalarTruncToInt(seed);
127 // The seed value clamp to the range [1, kRandMaximum - 1]. 129 // The seed value clamp to the range [1, kRandMaximum - 1].
128 fSeed = SkScalarRoundToInt(seed);
129 if (fSeed <= 0) { 130 if (fSeed <= 0) {
130 fSeed = -(fSeed % (kRandMaximum - 1)) + 1; 131 fSeed = -(fSeed % (kRandMaximum - 1)) + 1;
131 } 132 }
132 if (fSeed > kRandMaximum - 1) { 133 if (fSeed > kRandMaximum - 1) {
133 fSeed = kRandMaximum - 1; 134 fSeed = kRandMaximum - 1;
134 } 135 }
135 for (int channel = 0; channel < 4; ++channel) { 136 for (int channel = 0; channel < 4; ++channel) {
136 for (int i = 0; i < kBlockSize; ++i) { 137 for (int i = 0; i < kBlockSize; ++i) {
137 fLatticeSelector[i] = i; 138 fLatticeSelector[i] = i;
138 fNoise[channel][i][0] = (random() % (2 * kBlockSize)); 139 fNoise[channel][i][0] = (random() % (2 * kBlockSize));
(...skipping 1246 matching lines...) Expand 10 before | Expand all | Expand 10 after
1385 str->append(" seed: "); 1386 str->append(" seed: ");
1386 str->appendScalar(fSeed); 1387 str->appendScalar(fSeed);
1387 str->append(" stitch tiles: "); 1388 str->append(" stitch tiles: ");
1388 str->append(fStitchTiles ? "true " : "false "); 1389 str->append(fStitchTiles ? "true " : "false ");
1389 1390
1390 this->INHERITED::toString(str); 1391 this->INHERITED::toString(str);
1391 1392
1392 str->append(")"); 1393 str->append(")");
1393 } 1394 }
1394 #endif 1395 #endif
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698