OLD | NEW |
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 Loading... |
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 Loading... |
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 |
OLD | NEW |