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 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 } | 143 } |
144 | 144 |
145 if (fApplyAlphaAfterInterp) { | 145 if (fApplyAlphaAfterInterp) { |
146 // Our fColor values are in PMColor order, but are still unpremultiplied
, allowing us to | 146 // Our fColor values are in PMColor order, but are still unpremultiplied
, allowing us to |
147 // interpolate in unpremultiplied space first, and then scale by alpha r
ight before we | 147 // interpolate in unpremultiplied space first, and then scale by alpha r
ight before we |
148 // convert to SkPMColor bytes. | 148 // convert to SkPMColor bytes. |
149 const float paintAlpha = ctx.fPaint->getAlpha() * kInv255Float; | 149 const float paintAlpha = ctx.fPaint->getAlpha() * kInv255Float; |
150 const Sk4f scale(1, 1, 1, paintAlpha); | 150 const Sk4f scale(1, 1, 1, paintAlpha); |
151 for (int i = 0; i < count; ++i) { | 151 for (int i = 0; i < count; ++i) { |
152 uint32_t c = SkSwizzle_Color_to_PMColor(shader.fOrigColors[i]); | 152 uint32_t c = SkSwizzle_Color_to_PMColor(shader.fOrigColors[i]); |
153 rec[i].fColor = Sk4f::FromBytes((const uint8_t*)&c) * scale; | 153 rec[i].fColor = SkNx_cast<float>(Sk4b::Load((const uint8_t*)&c)) * s
cale; |
154 if (i > 0) { | 154 if (i > 0) { |
155 SkASSERT(rec[i - 1].fPos <= rec[i].fPos); | 155 SkASSERT(rec[i - 1].fPos <= rec[i].fPos); |
156 } | 156 } |
157 } | 157 } |
158 } else { | 158 } else { |
159 // Our fColor values are premultiplied, so converting to SkPMColor is ju
st a matter | 159 // Our fColor values are premultiplied, so converting to SkPMColor is ju
st a matter |
160 // of converting the floats down to bytes. | 160 // of converting the floats down to bytes. |
161 unsigned alphaScale = ctx.fPaint->getAlpha() + (ctx.fPaint->getAlpha() >
> 7); | 161 unsigned alphaScale = ctx.fPaint->getAlpha() + (ctx.fPaint->getAlpha() >
> 7); |
162 for (int i = 0; i < count; ++i) { | 162 for (int i = 0; i < count; ++i) { |
163 SkPMColor pmc = SkPreMultiplyColor(shader.fOrigColors[i]); | 163 SkPMColor pmc = SkPreMultiplyColor(shader.fOrigColors[i]); |
164 pmc = SkAlphaMulQ(pmc, alphaScale); | 164 pmc = SkAlphaMulQ(pmc, alphaScale); |
165 rec[i].fColor = Sk4f::FromBytes((const uint8_t*)&pmc); | 165 rec[i].fColor = SkNx_cast<float>(Sk4b::Load((const uint8_t*)&pmc)); |
166 if (i > 0) { | 166 if (i > 0) { |
167 SkASSERT(rec[i - 1].fPos <= rec[i].fPos); | 167 SkASSERT(rec[i - 1].fPos <= rec[i].fPos); |
168 } | 168 } |
169 } | 169 } |
170 } | 170 } |
171 } | 171 } |
172 | 172 |
173 #define NO_CHECK_ITER \ | 173 #define NO_CHECK_ITER \ |
174 do { \ | 174 do { \ |
175 unsigned fi = SkGradFixedToFixed(fx) >> SkGradientShaderBase::kCache32Shift;
\ | 175 unsigned fi = SkGradFixedToFixed(fx) >> SkGradientShaderBase::kCache32Shift;
\ |
(...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
692 rec -= 1; | 692 rec -= 1; |
693 SkASSERT(rec[0].fPos >= 0 && rec[0].fPos <= 1); | 693 SkASSERT(rec[0].fPos >= 0 && rec[0].fPos <= 1); |
694 SkASSERT(rec[1].fPos >= 0 && rec[1].fPos <= 1); | 694 SkASSERT(rec[1].fPos >= 0 && rec[1].fPos <= 1); |
695 SkASSERT(rec[0].fPos <= rec[1].fPos); | 695 SkASSERT(rec[0].fPos <= rec[1].fPos); |
696 } | 696 } |
697 return rec; | 697 return rec; |
698 } | 698 } |
699 | 699 |
700 template <bool apply_alpha> SkPMColor trunc_from_255(const Sk4f& x) { | 700 template <bool apply_alpha> SkPMColor trunc_from_255(const Sk4f& x) { |
701 SkPMColor c; | 701 SkPMColor c; |
702 x.toBytes((uint8_t*)&c); | 702 SkNx_cast<uint8_t>(x).store((uint8_t*)&c); |
703 if (apply_alpha) { | 703 if (apply_alpha) { |
704 c = SkPreMultiplyARGB(SkGetPackedA32(c), SkGetPackedR32(c), | 704 c = SkPreMultiplyARGB(SkGetPackedA32(c), SkGetPackedR32(c), |
705 SkGetPackedG32(c), SkGetPackedB32(c)); | 705 SkGetPackedG32(c), SkGetPackedB32(c)); |
706 } | 706 } |
707 return c; | 707 return c; |
708 } | 708 } |
709 | 709 |
710 template <bool apply_alpha> void fill(SkPMColor dst[], int count, | 710 template <bool apply_alpha> void fill(SkPMColor dst[], int count, |
711 const Sk4f& c4, const Sk4f& c4other) { | 711 const Sk4f& c4, const Sk4f& c4other) { |
712 sk_memset32_dither(dst, trunc_from_255<apply_alpha>(c4), | 712 sk_memset32_dither(dst, trunc_from_255<apply_alpha>(c4), |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
744 template <bool apply_alpha> void ramp(SkPMColor dstC[], int n, const Sk4f& c, co
nst Sk4f& dc, | 744 template <bool apply_alpha> void ramp(SkPMColor dstC[], int n, const Sk4f& c, co
nst Sk4f& dc, |
745 const Sk4f& dither0, const Sk4f& dither1)
{ | 745 const Sk4f& dither0, const Sk4f& dither1)
{ |
746 Sk4f dc2 = dc + dc; | 746 Sk4f dc2 = dc + dc; |
747 Sk4f dc4 = dc2 + dc2; | 747 Sk4f dc4 = dc2 + dc2; |
748 Sk4f cd0 = c + dither0; | 748 Sk4f cd0 = c + dither0; |
749 Sk4f cd1 = c + dc + dither1; | 749 Sk4f cd1 = c + dc + dither1; |
750 Sk4f cd2 = cd0 + dc2; | 750 Sk4f cd2 = cd0 + dc2; |
751 Sk4f cd3 = cd1 + dc2; | 751 Sk4f cd3 = cd1 + dc2; |
752 while (n >= 4) { | 752 while (n >= 4) { |
753 if (!apply_alpha) { | 753 if (!apply_alpha) { |
754 Sk4f::ToBytes((uint8_t*)dstC, cd0, cd1, cd2, cd3); | 754 Sk4f_ToBytes((uint8_t*)dstC, cd0, cd1, cd2, cd3); |
755 dstC += 4; | 755 dstC += 4; |
756 } else { | 756 } else { |
757 *dstC++ = trunc_from_255<apply_alpha>(cd0); | 757 *dstC++ = trunc_from_255<apply_alpha>(cd0); |
758 *dstC++ = trunc_from_255<apply_alpha>(cd1); | 758 *dstC++ = trunc_from_255<apply_alpha>(cd1); |
759 *dstC++ = trunc_from_255<apply_alpha>(cd2); | 759 *dstC++ = trunc_from_255<apply_alpha>(cd2); |
760 *dstC++ = trunc_from_255<apply_alpha>(cd3); | 760 *dstC++ = trunc_from_255<apply_alpha>(cd3); |
761 } | 761 } |
762 cd0 = cd0 + dc4; | 762 cd0 = cd0 + dc4; |
763 cd1 = cd1 + dc4; | 763 cd1 = cd1 + dc4; |
764 cd2 = cd2 + dc4; | 764 cd2 = cd2 + dc4; |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
922 } | 922 } |
923 } else { | 923 } else { |
924 if (fApplyAlphaAfterInterp) { | 924 if (fApplyAlphaAfterInterp) { |
925 this->shade4_dx_clamp<true, false>(dstC, count, fx, dx, invDx, dithe
r); | 925 this->shade4_dx_clamp<true, false>(dstC, count, fx, dx, invDx, dithe
r); |
926 } else { | 926 } else { |
927 this->shade4_dx_clamp<false, false>(dstC, count, fx, dx, invDx, dith
er); | 927 this->shade4_dx_clamp<false, false>(dstC, count, fx, dx, invDx, dith
er); |
928 } | 928 } |
929 } | 929 } |
930 } | 930 } |
931 | 931 |
OLD | NEW |