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 27 matching lines...) Expand all Loading... |
38 if (noiseValue >= limitValue) { | 38 if (noiseValue >= limitValue) { |
39 noiseValue -= newValue; | 39 noiseValue -= newValue; |
40 } | 40 } |
41 if (noiseValue >= limitValue - 1) { | 41 if (noiseValue >= limitValue - 1) { |
42 noiseValue -= newValue - 1; | 42 noiseValue -= newValue - 1; |
43 } | 43 } |
44 return noiseValue; | 44 return noiseValue; |
45 } | 45 } |
46 | 46 |
47 inline SkScalar smoothCurve(SkScalar t) { | 47 inline SkScalar smoothCurve(SkScalar t) { |
48 static const SkScalar SK_Scalar3 = SkFloatToScalar(3.0f); | 48 static const SkScalar SK_Scalar3 = 3.0f; |
49 | 49 |
50 // returns t * t * (3 - 2 * t) | 50 // returns t * t * (3 - 2 * t) |
51 return SkScalarMul(SkScalarSquare(t), SK_Scalar3 - 2 * t); | 51 return SkScalarMul(SkScalarSquare(t), SK_Scalar3 - 2 * t); |
52 } | 52 } |
53 | 53 |
54 } // end namespace | 54 } // end namespace |
55 | 55 |
56 struct SkPerlinNoiseShader::StitchData { | 56 struct SkPerlinNoiseShader::StitchData { |
57 StitchData() | 57 StitchData() |
58 : fWidth(0) | 58 : fWidth(0) |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 for (int i = 0; i < kBlockSize; ++i) { | 158 for (int i = 0; i < kBlockSize; ++i) { |
159 for (int channel = 0; channel < 4; ++channel) { | 159 for (int channel = 0; channel < 4; ++channel) { |
160 for (int j = 0; j < 2; ++j) { | 160 for (int j = 0; j < 2; ++j) { |
161 fNoise[channel][i][j] = noise[channel][fLatticeSelector[
i]][j]; | 161 fNoise[channel][i][j] = noise[channel][fLatticeSelector[
i]][j]; |
162 } | 162 } |
163 } | 163 } |
164 } | 164 } |
165 } | 165 } |
166 | 166 |
167 // Half of the largest possible value for 16 bit unsigned int | 167 // Half of the largest possible value for 16 bit unsigned int |
168 static const SkScalar gHalfMax16bits = SkFloatToScalar(32767.5f); | 168 static const SkScalar gHalfMax16bits = 32767.5f; |
169 | 169 |
170 // Compute gradients from permutated noise data | 170 // Compute gradients from permutated noise data |
171 for (int channel = 0; channel < 4; ++channel) { | 171 for (int channel = 0; channel < 4; ++channel) { |
172 for (int i = 0; i < kBlockSize; ++i) { | 172 for (int i = 0; i < kBlockSize; ++i) { |
173 fGradient[channel][i] = SkPoint::Make( | 173 fGradient[channel][i] = SkPoint::Make( |
174 SkScalarMul(SkIntToScalar(fNoise[channel][i][0] - kBlockSize
), | 174 SkScalarMul(SkIntToScalar(fNoise[channel][i][0] - kBlockSize
), |
175 gInvBlockSizef), | 175 gInvBlockSizef), |
176 SkScalarMul(SkIntToScalar(fNoise[channel][i][1] - kBlockSize
), | 176 SkScalarMul(SkIntToScalar(fNoise[channel][i][1] - kBlockSize
), |
177 gInvBlockSizef)); | 177 gInvBlockSizef)); |
178 fGradient[channel][i].normalize(); | 178 fGradient[channel][i].normalize(); |
(...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
722 GR_DEFINE_EFFECT_TEST(GrPerlinNoiseEffect); | 722 GR_DEFINE_EFFECT_TEST(GrPerlinNoiseEffect); |
723 | 723 |
724 GrEffectRef* GrPerlinNoiseEffect::TestCreate(SkRandom* random, | 724 GrEffectRef* GrPerlinNoiseEffect::TestCreate(SkRandom* random, |
725 GrContext* context, | 725 GrContext* context, |
726 const GrDrawTargetCaps&, | 726 const GrDrawTargetCaps&, |
727 GrTexture**) { | 727 GrTexture**) { |
728 int numOctaves = random->nextRangeU(2, 10); | 728 int numOctaves = random->nextRangeU(2, 10); |
729 bool stitchTiles = random->nextBool(); | 729 bool stitchTiles = random->nextBool(); |
730 SkScalar seed = SkIntToScalar(random->nextU()); | 730 SkScalar seed = SkIntToScalar(random->nextU()); |
731 SkISize tileSize = SkISize::Make(random->nextRangeU(4, 4096), random->nextR
angeU(4, 4096)); | 731 SkISize tileSize = SkISize::Make(random->nextRangeU(4, 4096), random->nextR
angeU(4, 4096)); |
732 SkScalar baseFrequencyX = random->nextRangeScalar(SkFloatToScalar(0.01f), | 732 SkScalar baseFrequencyX = random->nextRangeScalar(0.01f, |
733 SkFloatToScalar(0.99f)); | 733 0.99f); |
734 SkScalar baseFrequencyY = random->nextRangeScalar(SkFloatToScalar(0.01f), | 734 SkScalar baseFrequencyY = random->nextRangeScalar(0.01f, |
735 SkFloatToScalar(0.99f)); | 735 0.99f); |
736 | 736 |
737 SkShader* shader = random->nextBool() ? | 737 SkShader* shader = random->nextBool() ? |
738 SkPerlinNoiseShader::CreateFractalNoise(baseFrequencyX, baseFrequencyY,
numOctaves, seed, | 738 SkPerlinNoiseShader::CreateFractalNoise(baseFrequencyX, baseFrequencyY,
numOctaves, seed, |
739 stitchTiles ? &tileSize : NULL)
: | 739 stitchTiles ? &tileSize : NULL)
: |
740 SkPerlinNoiseShader::CreateTubulence(baseFrequencyX, baseFrequencyY, num
Octaves, seed, | 740 SkPerlinNoiseShader::CreateTubulence(baseFrequencyX, baseFrequencyY, num
Octaves, seed, |
741 stitchTiles ? &tileSize : NULL); | 741 stitchTiles ? &tileSize : NULL); |
742 | 742 |
743 SkPaint paint; | 743 SkPaint paint; |
744 GrEffectRef* effect = shader->asNewEffect(context, paint); | 744 GrEffectRef* effect = shader->asNewEffect(context, paint); |
745 | 745 |
(...skipping 632 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1378 str->append(" seed: "); | 1378 str->append(" seed: "); |
1379 str->appendScalar(fSeed); | 1379 str->appendScalar(fSeed); |
1380 str->append(" stitch tiles: "); | 1380 str->append(" stitch tiles: "); |
1381 str->append(fStitchTiles ? "true " : "false "); | 1381 str->append(fStitchTiles ? "true " : "false "); |
1382 | 1382 |
1383 this->INHERITED::toString(str); | 1383 this->INHERITED::toString(str); |
1384 | 1384 |
1385 str->append(")"); | 1385 str->append(")"); |
1386 } | 1386 } |
1387 #endif | 1387 #endif |
OLD | NEW |