OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 #include "SkColorMatrixFilter.h" | 8 #include "SkColorMatrixFilter.h" |
9 #include "SkColorMatrix.h" | 9 #include "SkColorMatrix.h" |
10 #include "SkColorPriv.h" | 10 #include "SkColorPriv.h" |
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
445 enum { | 445 enum { |
446 kAlphaRowStartIdx = 15, | 446 kAlphaRowStartIdx = 15, |
447 kAlphaRowTranslateIdx = 19, | 447 kAlphaRowTranslateIdx = 19, |
448 }; | 448 }; |
449 | 449 |
450 SkScalar outputA = 0; | 450 SkScalar outputA = 0; |
451 for (int i = 0; i < 4; ++i) { | 451 for (int i = 0; i < 4; ++i) { |
452 // If any relevant component of the color to be passed through the m
atrix is non-const | 452 // If any relevant component of the color to be passed through the m
atrix is non-const |
453 // then we can't know the final result. | 453 // then we can't know the final result. |
454 if (0 != fMatrix.fMat[kAlphaRowStartIdx + i]) { | 454 if (0 != fMatrix.fMat[kAlphaRowStartIdx + i]) { |
455 if (!(inout->fValidFlags & kRGBAFlags[i])) { | 455 if (!(inout->validFlags() & kRGBAFlags[i])) { |
456 inout->fValidFlags = 0; | 456 inout->setToUnknown(); |
457 return; | 457 return; |
458 } else { | 458 } else { |
459 uint32_t component = (inout->fColor >> kShifts[i]) & 0xFF; | 459 uint32_t component = (inout->color() >> kShifts[i]) & 0xFF; |
460 outputA += fMatrix.fMat[kAlphaRowStartIdx + i] * component; | 460 outputA += fMatrix.fMat[kAlphaRowStartIdx + i] * component; |
461 } | 461 } |
462 } | 462 } |
463 } | 463 } |
464 outputA += fMatrix.fMat[kAlphaRowTranslateIdx]; | 464 outputA += fMatrix.fMat[kAlphaRowTranslateIdx]; |
465 inout->fValidFlags = kA_GrColorComponentFlag; | |
466 // We pin the color to [0,1]. This would happen to the *final* color out
put from the frag | 465 // We pin the color to [0,1]. This would happen to the *final* color out
put from the frag |
467 // shader but currently the effect does not pin its own output. So in th
e case of over/ | 466 // shader but currently the effect does not pin its own output. So in th
e case of over/ |
468 // underflow this may deviate from the actual result. Maybe the effect s
hould pin its | 467 // underflow this may deviate from the actual result. Maybe the effect s
hould pin its |
469 // result if the matrix could over/underflow for any component? | 468 // result if the matrix could over/underflow for any component? |
470 inout->fColor = static_cast<uint8_t>(SkScalarPin(outputA, 0, 255)) << Gr
Color_SHIFT_A; | 469 inout->setToOther(kA_GrColorComponentFlag, |
471 inout->fIsSingleComponent = false; | 470 static_cast<uint8_t>(SkScalarPin(outputA, 0, 255)) <<
GrColor_SHIFT_A); |
472 } | 471 } |
473 | 472 |
474 SkColorMatrix fMatrix; | 473 SkColorMatrix fMatrix; |
475 | 474 |
476 typedef GrFragmentProcessor INHERITED; | 475 typedef GrFragmentProcessor INHERITED; |
477 }; | 476 }; |
478 | 477 |
479 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(ColorMatrixEffect); | 478 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(ColorMatrixEffect); |
480 | 479 |
481 GrFragmentProcessor* ColorMatrixEffect::TestCreate(SkRandom* random, | 480 GrFragmentProcessor* ColorMatrixEffect::TestCreate(SkRandom* random, |
(...skipping 20 matching lines...) Expand all Loading... |
502 str->append("matrix: ("); | 501 str->append("matrix: ("); |
503 for (int i = 0; i < 20; ++i) { | 502 for (int i = 0; i < 20; ++i) { |
504 str->appendScalar(fMatrix.fMat[i]); | 503 str->appendScalar(fMatrix.fMat[i]); |
505 if (i < 19) { | 504 if (i < 19) { |
506 str->append(", "); | 505 str->append(", "); |
507 } | 506 } |
508 } | 507 } |
509 str->append(")"); | 508 str->append(")"); |
510 } | 509 } |
511 #endif | 510 #endif |
OLD | NEW |