OLD | NEW |
| 1 /* |
| 2 * Copyright 2015 Google Inc. |
| 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. |
| 6 */ |
| 7 |
1 inline SkPMFloat& SkPMFloat::operator=(const SkPMFloat& that) { | 8 inline SkPMFloat& SkPMFloat::operator=(const SkPMFloat& that) { |
2 fColors = that.fColors; | 9 fColors = that.fColors; |
3 return *this; | 10 return *this; |
4 } | 11 } |
5 | 12 |
6 // For SkPMFloat(SkPMColor), we widen our 8 bit components (fix8) to 8-bit compo
nents in 16 bits | 13 // For SkPMFloat(SkPMColor), we widen our 8 bit components (fix8) to 8-bit compo
nents in 16 bits |
7 // (fix8_16), then widen those to 8-bit-in-32-bits (fix8_32), and finally conver
t those to floats. | 14 // (fix8_16), then widen those to 8-bit-in-32-bits (fix8_32), and finally conver
t those to floats. |
8 | 15 |
9 // get() and clamped() do the opposite, working from floats to 8-bit-in-32-bit, | 16 // get() and clamped() do the opposite, working from floats to 8-bit-in-32-bit, |
10 // to 8-bit-in-16-bit, back down to 8-bit components. | 17 // to 8-bit-in-16-bit, back down to 8-bit components. |
(...skipping 16 matching lines...) Expand all Loading... |
27 inline SkPMColor SkPMFloat::clamped() const { | 34 inline SkPMColor SkPMFloat::clamped() const { |
28 // We don't use _mm_cvtps_epi32, because we want precise control over how 0.
5 rounds (up). | 35 // We don't use _mm_cvtps_epi32, because we want precise control over how 0.
5 rounds (up). |
29 __m128i fix8_32 = _mm_cvttps_epi32(_mm_add_ps(_mm_set1_ps(0.5f), fColors)), | 36 __m128i fix8_32 = _mm_cvttps_epi32(_mm_add_ps(_mm_set1_ps(0.5f), fColors)), |
30 fix8_16 = _mm_packus_epi16(fix8_32, fix8_32), | 37 fix8_16 = _mm_packus_epi16(fix8_32, fix8_32), |
31 fix8 = _mm_packus_epi16(fix8_16, fix8_16); | 38 fix8 = _mm_packus_epi16(fix8_16, fix8_16); |
32 SkPMColor c = _mm_cvtsi128_si32(fix8); | 39 SkPMColor c = _mm_cvtsi128_si32(fix8); |
33 SkPMColorAssert(c); | 40 SkPMColorAssert(c); |
34 return c; | 41 return c; |
35 } | 42 } |
36 | 43 |
37 inline void SkPMFloat::From4PMColors(SkPMFloat floats[4], const SkPMColor colors
[4]) { | 44 inline void SkPMFloat::From4PMColors(const SkPMColor colors[4], |
| 45 SkPMFloat* a, SkPMFloat* b, SkPMFloat* c, S
kPMFloat* d) { |
38 // Haven't beaten this yet. | 46 // Haven't beaten this yet. |
39 for (int i = 0; i < 4; i++) { floats[i] = FromPMColor(colors[i]); } | 47 *a = FromPMColor(colors[0]); |
| 48 *b = FromPMColor(colors[1]); |
| 49 *c = FromPMColor(colors[2]); |
| 50 *d = FromPMColor(colors[3]); |
40 } | 51 } |
41 | 52 |
42 inline void SkPMFloat::To4PMColors(SkPMColor colors[4], const SkPMFloat floats[4
]) { | 53 inline void SkPMFloat::To4PMColors( |
43 SkASSERT(floats[0].isValid() && floats[1].isValid() | 54 const SkPMFloat& a, const SkPMFloat& b, const SkPMFloat&c, const SkPMFlo
at& d, |
44 && floats[2].isValid() && floats[3].isValid()); | 55 SkPMColor colors[4]) { |
45 // Haven't beaten this yet. | 56 // Haven't beaten this yet. |
46 ClampTo4PMColors(colors, floats); | 57 ClampTo4PMColors(a,b,c,d, colors); |
47 } | 58 } |
48 | 59 |
49 inline void SkPMFloat::ClampTo4PMColors(SkPMColor colors[4], const SkPMFloat flo
ats[4]) { | 60 inline void SkPMFloat::ClampTo4PMColors( |
| 61 const SkPMFloat& a, const SkPMFloat& b, const SkPMFloat&c, const SkPMFlo
at& d, |
| 62 SkPMColor colors[4]) { |
50 // Same as _SSSE3.h's. We use 3 _mm_packus_epi16() where the naive loop use
s 8. | 63 // Same as _SSSE3.h's. We use 3 _mm_packus_epi16() where the naive loop use
s 8. |
51 // We don't use _mm_cvtps_epi32, because we want precise control over how 0.
5 rounds (up). | 64 // We don't use _mm_cvtps_epi32, because we want precise control over how 0.
5 rounds (up). |
52 __m128i c0 = _mm_cvttps_epi32(_mm_add_ps(_mm_set1_ps(0.5f), floats[0].fColor
s)), | 65 __m128i c0 = _mm_cvttps_epi32(_mm_add_ps(_mm_set1_ps(0.5f), a.fColors)), |
53 c1 = _mm_cvttps_epi32(_mm_add_ps(_mm_set1_ps(0.5f), floats[1].fColor
s)), | 66 c1 = _mm_cvttps_epi32(_mm_add_ps(_mm_set1_ps(0.5f), b.fColors)), |
54 c2 = _mm_cvttps_epi32(_mm_add_ps(_mm_set1_ps(0.5f), floats[2].fColor
s)), | 67 c2 = _mm_cvttps_epi32(_mm_add_ps(_mm_set1_ps(0.5f), c.fColors)), |
55 c3 = _mm_cvttps_epi32(_mm_add_ps(_mm_set1_ps(0.5f), floats[3].fColor
s)); | 68 c3 = _mm_cvttps_epi32(_mm_add_ps(_mm_set1_ps(0.5f), d.fColors)); |
56 __m128i c3210 = _mm_packus_epi16(_mm_packus_epi16(c0, c1), | 69 __m128i c3210 = _mm_packus_epi16(_mm_packus_epi16(c0, c1), |
57 _mm_packus_epi16(c2, c3)); | 70 _mm_packus_epi16(c2, c3)); |
58 _mm_storeu_si128((__m128i*)colors, c3210); | 71 _mm_storeu_si128((__m128i*)colors, c3210); |
59 SkPMColorAssert(colors[0]); | 72 SkPMColorAssert(colors[0]); |
60 SkPMColorAssert(colors[1]); | 73 SkPMColorAssert(colors[1]); |
61 SkPMColorAssert(colors[2]); | 74 SkPMColorAssert(colors[2]); |
62 SkPMColorAssert(colors[3]); | 75 SkPMColorAssert(colors[3]); |
63 } | 76 } |
OLD | NEW |