OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 "SkLinearGradient.h" | 8 #include "SkLinearGradient.h" |
9 | 9 |
10 static const float kInv255Float = 1.0f / 255; | 10 static const float kInv255Float = 1.0f / 255; |
(...skipping 709 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
720 * TODOs | 720 * TODOs |
721 * | 721 * |
722 * - tilemodes | 722 * - tilemodes |
723 * - interp before or after premul | 723 * - interp before or after premul |
724 * - perspective | 724 * - perspective |
725 * - optimizations | 725 * - optimizations |
726 * - use fixed (32bit or 16bit) instead of floats? | 726 * - use fixed (32bit or 16bit) instead of floats? |
727 */ | 727 */ |
728 | 728 |
729 static Sk4f lerp_color(float fx, const SkLinearGradient::LinearGradientContext::
Rec* rec) { | 729 static Sk4f lerp_color(float fx, const SkLinearGradient::LinearGradientContext::
Rec* rec) { |
| 730 SkASSERT(fx >= rec[0].fPos); |
| 731 SkASSERT(fx <= rec[1].fPos); |
| 732 |
730 const float p0 = rec[0].fPos; | 733 const float p0 = rec[0].fPos; |
731 const Sk4f c0 = rec[0].fColor; | 734 const Sk4f c0 = rec[0].fColor; |
732 const Sk4f c1 = rec[1].fColor; | 735 const Sk4f c1 = rec[1].fColor; |
733 const Sk4f diffc = c1 - c0; | 736 const Sk4f diffc = c1 - c0; |
734 const float scale = rec[1].fPosScale; | 737 const float scale = rec[1].fPosScale; |
735 const float t = (fx - p0) * scale; | 738 const float t = (fx - p0) * scale; |
736 return c0 + Sk4f(t) * diffc; | 739 return c0 + Sk4f(t) * diffc; |
737 } | 740 } |
738 | 741 |
739 template <bool apply_alpha> void ramp(SkPMColor dstC[], int n, const Sk4f& c, co
nst Sk4f& dc, | 742 template <bool apply_alpha> void ramp(SkPMColor dstC[], int n, const Sk4f& c, co
nst Sk4f& dc, |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
887 dither0 = ditherCell[rowIndex]; | 890 dither0 = ditherCell[rowIndex]; |
888 dither1 = ditherCell[rowIndex + 1]; | 891 dither1 = ditherCell[rowIndex + 1]; |
889 if (x & 1) { | 892 if (x & 1) { |
890 SkTSwap(dither0, dither1); | 893 SkTSwap(dither0, dither1); |
891 } | 894 } |
892 } | 895 } |
893 const float dither[2] = { dither0, dither1 }; | 896 const float dither[2] = { dither0, dither1 }; |
894 const float invDx = 1 / dx; | 897 const float invDx = 1 / dx; |
895 | 898 |
896 if (SkScalarNearlyZero(dx)) { // gradient is vertical | 899 if (SkScalarNearlyZero(dx)) { // gradient is vertical |
897 Sk4f c = lerp_color(fx, find_forward(fRecs.begin(), SkTPin(fx, 0.0f, 1.0
f))); | 900 const float pinFx = SkTPin(fx, 0.0f, 1.0f); |
| 901 Sk4f c = lerp_color(pinFx, find_forward(fRecs.begin(), pinFx)); |
898 if (fApplyAlphaAfterInterp) { | 902 if (fApplyAlphaAfterInterp) { |
899 fill<true>(dstC, count, c + dither0, c + dither1); | 903 fill<true>(dstC, count, c + dither0, c + dither1); |
900 } else { | 904 } else { |
901 fill<false>(dstC, count, c + dither0, c + dither1); | 905 fill<false>(dstC, count, c + dither0, c + dither1); |
902 } | 906 } |
903 return; | 907 return; |
904 } | 908 } |
905 | 909 |
906 if (dx > 0) { | 910 if (dx > 0) { |
907 if (fApplyAlphaAfterInterp) { | 911 if (fApplyAlphaAfterInterp) { |
908 this->shade4_dx_clamp<true, true>(dstC, count, fx, dx, invDx, dither
); | 912 this->shade4_dx_clamp<true, true>(dstC, count, fx, dx, invDx, dither
); |
909 } else { | 913 } else { |
910 this->shade4_dx_clamp<false, true>(dstC, count, fx, dx, invDx, dithe
r); | 914 this->shade4_dx_clamp<false, true>(dstC, count, fx, dx, invDx, dithe
r); |
911 } | 915 } |
912 } else { | 916 } else { |
913 if (fApplyAlphaAfterInterp) { | 917 if (fApplyAlphaAfterInterp) { |
914 this->shade4_dx_clamp<true, false>(dstC, count, fx, dx, invDx, dithe
r); | 918 this->shade4_dx_clamp<true, false>(dstC, count, fx, dx, invDx, dithe
r); |
915 } else { | 919 } else { |
916 this->shade4_dx_clamp<false, false>(dstC, count, fx, dx, invDx, dith
er); | 920 this->shade4_dx_clamp<false, false>(dstC, count, fx, dx, invDx, dith
er); |
917 } | 921 } |
918 } | 922 } |
919 } | 923 } |
920 | 924 |
OLD | NEW |