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 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
403 if (channel == 3) { // Scale alpha by paint value | 403 if (channel == 3) { // Scale alpha by paint value |
404 turbulenceFunctionResult = SkScalarMul(turbulenceFunctionResult, | 404 turbulenceFunctionResult = SkScalarMul(turbulenceFunctionResult, |
405 SkScalarDiv(SkIntToScalar(getPaintAlpha()), SkIntToScalar(255))); | 405 SkScalarDiv(SkIntToScalar(getPaintAlpha()), SkIntToScalar(255))); |
406 } | 406 } |
407 | 407 |
408 // Clamp result | 408 // Clamp result |
409 return SkScalarPin(turbulenceFunctionResult, 0, SK_Scalar1); | 409 return SkScalarPin(turbulenceFunctionResult, 0, SK_Scalar1); |
410 } | 410 } |
411 | 411 |
412 SkPMColor SkPerlinNoiseShader::shade(const SkPoint& point, StitchData& stitchDat
a) const { | 412 SkPMColor SkPerlinNoiseShader::shade(const SkPoint& point, StitchData& stitchDat
a) const { |
413 SkMatrix matrix = fMatrix; | |
414 matrix.postConcat(getLocalMatrix()); | |
415 SkMatrix invMatrix; | |
416 if (!matrix.invert(&invMatrix)) { | |
417 invMatrix.reset(); | |
418 } else { | |
419 invMatrix.postConcat(invMatrix); // Square the matrix | |
420 } | |
421 // This (1,1) translation is due to WebKit's 1 based coordinates for the noi
se | |
422 // (as opposed to 0 based, usually). The same adjustment is in the setData()
function. | |
423 matrix.postTranslate(SK_Scalar1, SK_Scalar1); | |
424 SkPoint newPoint; | 413 SkPoint newPoint; |
425 matrix.mapPoints(&newPoint, &point, 1); | 414 fMatrix.mapPoints(&newPoint, &point, 1); |
426 invMatrix.mapPoints(&newPoint, &newPoint, 1); | |
427 newPoint.fX = SkScalarRoundToScalar(newPoint.fX); | 415 newPoint.fX = SkScalarRoundToScalar(newPoint.fX); |
428 newPoint.fY = SkScalarRoundToScalar(newPoint.fY); | 416 newPoint.fY = SkScalarRoundToScalar(newPoint.fY); |
429 | 417 |
430 U8CPU rgba[4]; | 418 U8CPU rgba[4]; |
431 for (int channel = 3; channel >= 0; --channel) { | 419 for (int channel = 3; channel >= 0; --channel) { |
432 rgba[channel] = SkScalarFloorToInt(255 * | 420 rgba[channel] = SkScalarFloorToInt(255 * |
433 calculateTurbulenceValueForPoint(channel, *fPaintingData, stitchData
, newPoint)); | 421 calculateTurbulenceValueForPoint(channel, *fPaintingData, stitchData
, newPoint)); |
434 } | 422 } |
435 return SkPreMultiplyARGB(rgba[3], rgba[0], rgba[1], rgba[2]); | 423 return SkPreMultiplyARGB(rgba[3], rgba[0], rgba[1], rgba[2]); |
436 } | 424 } |
437 | 425 |
438 bool SkPerlinNoiseShader::setContext(const SkBitmap& device, const SkPaint& pain
t, | 426 bool SkPerlinNoiseShader::setContext(const SkBitmap& device, const SkPaint& pain
t, |
439 const SkMatrix& matrix) { | 427 const SkMatrix& matrix) { |
440 fMatrix = matrix; | 428 SkMatrix newMatrix = matrix; |
| 429 newMatrix.postConcat(getLocalMatrix()); |
| 430 SkMatrix invMatrix; |
| 431 if (!newMatrix.invert(&invMatrix)) { |
| 432 invMatrix.reset(); |
| 433 } |
| 434 // This (1,1) translation is due to WebKit's 1 based coordinates for the noi
se |
| 435 // (as opposed to 0 based, usually). The same adjustment is in the setData()
function. |
| 436 newMatrix.postTranslate(SK_Scalar1, SK_Scalar1); |
| 437 newMatrix.postConcat(invMatrix); |
| 438 newMatrix.postConcat(invMatrix); |
| 439 fMatrix = newMatrix; |
441 return INHERITED::setContext(device, paint, matrix); | 440 return INHERITED::setContext(device, paint, matrix); |
442 } | 441 } |
443 | 442 |
444 void SkPerlinNoiseShader::shadeSpan(int x, int y, SkPMColor result[], int count)
{ | 443 void SkPerlinNoiseShader::shadeSpan(int x, int y, SkPMColor result[], int count)
{ |
445 SkPoint point = SkPoint::Make(SkIntToScalar(x), SkIntToScalar(y)); | 444 SkPoint point = SkPoint::Make(SkIntToScalar(x), SkIntToScalar(y)); |
446 StitchData stitchData; | 445 StitchData stitchData; |
447 for (int i = 0; i < count; ++i) { | 446 for (int i = 0; i < count; ++i) { |
448 result[i] = shade(point, stitchData); | 447 result[i] = shade(point, stitchData); |
449 point.fX += SK_Scalar1; | 448 point.fX += SK_Scalar1; |
450 } | 449 } |
(...skipping 896 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1347 str->append(" seed: "); | 1346 str->append(" seed: "); |
1348 str->appendScalar(fSeed); | 1347 str->appendScalar(fSeed); |
1349 str->append(" stitch tiles: "); | 1348 str->append(" stitch tiles: "); |
1350 str->append(fStitchTiles ? "true " : "false "); | 1349 str->append(fStitchTiles ? "true " : "false "); |
1351 | 1350 |
1352 this->INHERITED::toString(str); | 1351 this->INHERITED::toString(str); |
1353 | 1352 |
1354 str->append(")"); | 1353 str->append(")"); |
1355 } | 1354 } |
1356 #endif | 1355 #endif |
OLD | NEW |