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 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 } | 126 } |
127 | 127 |
128 if (fApplyAlphaAfterInterp) { | 128 if (fApplyAlphaAfterInterp) { |
129 // Our fColor values are in PMColor order, but are still unpremultiplied
, allowing us to | 129 // Our fColor values are in PMColor order, but are still unpremultiplied
, allowing us to |
130 // interpolate in unpremultiplied space first, and then scale by alpha r
ight before we | 130 // interpolate in unpremultiplied space first, and then scale by alpha r
ight before we |
131 // convert to SkPMColor bytes. | 131 // convert to SkPMColor bytes. |
132 const float paintAlpha = ctx.fPaint->getAlpha() * kInv255Float; | 132 const float paintAlpha = ctx.fPaint->getAlpha() * kInv255Float; |
133 const Sk4f scale(1, 1, 1, paintAlpha); | 133 const Sk4f scale(1, 1, 1, paintAlpha); |
134 for (int i = 0; i < count; ++i) { | 134 for (int i = 0; i < count; ++i) { |
135 uint32_t c = SkSwizzle_Color_to_PMColor(shader.fOrigColors[i]); | 135 uint32_t c = SkSwizzle_Color_to_PMColor(shader.fOrigColors[i]); |
136 rec[i].fColor = SkNx_cast<float>(Sk4b::Load((const uint8_t*)&c)) * s
cale; | 136 rec[i].fColor = SkNx_cast<float>(Sk4b::Load(&c)) * scale; |
137 if (i > 0) { | 137 if (i > 0) { |
138 SkASSERT(rec[i - 1].fPos <= rec[i].fPos); | 138 SkASSERT(rec[i - 1].fPos <= rec[i].fPos); |
139 } | 139 } |
140 } | 140 } |
141 } else { | 141 } else { |
142 // Our fColor values are premultiplied, so converting to SkPMColor is ju
st a matter | 142 // Our fColor values are premultiplied, so converting to SkPMColor is ju
st a matter |
143 // of converting the floats down to bytes. | 143 // of converting the floats down to bytes. |
144 unsigned alphaScale = ctx.fPaint->getAlpha() + (ctx.fPaint->getAlpha() >
> 7); | 144 unsigned alphaScale = ctx.fPaint->getAlpha() + (ctx.fPaint->getAlpha() >
> 7); |
145 for (int i = 0; i < count; ++i) { | 145 for (int i = 0; i < count; ++i) { |
146 SkPMColor pmc = SkPreMultiplyColor(shader.fOrigColors[i]); | 146 SkPMColor pmc = SkPreMultiplyColor(shader.fOrigColors[i]); |
147 pmc = SkAlphaMulQ(pmc, alphaScale); | 147 pmc = SkAlphaMulQ(pmc, alphaScale); |
148 rec[i].fColor = SkNx_cast<float>(Sk4b::Load((const uint8_t*)&pmc)); | 148 rec[i].fColor = SkNx_cast<float>(Sk4b::Load(&pmc)); |
149 if (i > 0) { | 149 if (i > 0) { |
150 SkASSERT(rec[i - 1].fPos <= rec[i].fPos); | 150 SkASSERT(rec[i - 1].fPos <= rec[i].fPos); |
151 } | 151 } |
152 } | 152 } |
153 } | 153 } |
154 } | 154 } |
155 | 155 |
156 #define NO_CHECK_ITER \ | 156 #define NO_CHECK_ITER \ |
157 do { \ | 157 do { \ |
158 unsigned fi = SkGradFixedToFixed(fx) >> SkGradientShaderBase::kCache32Shift;
\ | 158 unsigned fi = SkGradFixedToFixed(fx) >> SkGradientShaderBase::kCache32Shift;
\ |
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
508 rec -= 1; | 508 rec -= 1; |
509 SkASSERT(rec[0].fPos >= 0 && rec[0].fPos <= 1); | 509 SkASSERT(rec[0].fPos >= 0 && rec[0].fPos <= 1); |
510 SkASSERT(rec[1].fPos >= 0 && rec[1].fPos <= 1); | 510 SkASSERT(rec[1].fPos >= 0 && rec[1].fPos <= 1); |
511 SkASSERT(rec[0].fPos <= rec[1].fPos); | 511 SkASSERT(rec[0].fPos <= rec[1].fPos); |
512 } | 512 } |
513 return rec; | 513 return rec; |
514 } | 514 } |
515 | 515 |
516 template <bool apply_alpha> SkPMColor trunc_from_255(const Sk4f& x) { | 516 template <bool apply_alpha> SkPMColor trunc_from_255(const Sk4f& x) { |
517 SkPMColor c; | 517 SkPMColor c; |
518 SkNx_cast<uint8_t>(x).store((uint8_t*)&c); | 518 SkNx_cast<uint8_t>(x).store(&c); |
519 if (apply_alpha) { | 519 if (apply_alpha) { |
520 c = SkPreMultiplyARGB(SkGetPackedA32(c), SkGetPackedR32(c), | 520 c = SkPreMultiplyARGB(SkGetPackedA32(c), SkGetPackedR32(c), |
521 SkGetPackedG32(c), SkGetPackedB32(c)); | 521 SkGetPackedG32(c), SkGetPackedB32(c)); |
522 } | 522 } |
523 return c; | 523 return c; |
524 } | 524 } |
525 | 525 |
526 template <bool apply_alpha> void fill(SkPMColor dst[], int count, | 526 template <bool apply_alpha> void fill(SkPMColor dst[], int count, |
527 const Sk4f& c4, const Sk4f& c4other) { | 527 const Sk4f& c4, const Sk4f& c4other) { |
528 sk_memset32_dither(dst, trunc_from_255<apply_alpha>(c4), | 528 sk_memset32_dither(dst, trunc_from_255<apply_alpha>(c4), |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
741 } | 741 } |
742 } else { | 742 } else { |
743 if (fApplyAlphaAfterInterp) { | 743 if (fApplyAlphaAfterInterp) { |
744 this->shade4_dx_clamp<true, false>(dstC, count, fx, dx, invDx, dithe
r); | 744 this->shade4_dx_clamp<true, false>(dstC, count, fx, dx, invDx, dithe
r); |
745 } else { | 745 } else { |
746 this->shade4_dx_clamp<false, false>(dstC, count, fx, dx, invDx, dith
er); | 746 this->shade4_dx_clamp<false, false>(dstC, count, fx, dx, invDx, dith
er); |
747 } | 747 } |
748 } | 748 } |
749 } | 749 } |
750 | 750 |
OLD | NEW |