OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 inline SkPMFloat& SkPMFloat::operator=(const SkPMFloat& that) { | 8 inline SkPMFloat& SkPMFloat::operator=(const SkPMFloat& that) { |
9 fColors = that.fColors; | 9 fColors = that.fColors; |
10 return *this; | 10 return *this; |
11 } | 11 } |
12 | 12 |
13 // For SkPMFloat(SkPMFColor), we widen our 8 bit components (fix8) to 8-bit comp
onents in 16 bits | 13 // For SkPMFloat(SkPMFColor), we widen our 8 bit components (fix8) to 8-bit comp
onents in 16 bits |
14 // (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. |
15 | 15 |
16 // 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, |
17 // 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. |
18 // clamped() uses vqmovn to clamp while narrowing instead of just narrowing with
vmovn. | 18 // clamped() uses vqmovn to clamp while narrowing instead of just narrowing with
vmovn. |
19 | 19 |
20 inline SkPMFloat::SkPMFloat(SkPMColor c) { | 20 inline SkPMFloat::SkPMFloat(SkPMColor c) { |
21 SkPMColorAssert(c); | 21 SkPMColorAssert(c); |
22 uint8x8_t fix8 = (uint8x8_t)vdup_n_u32(c); | 22 uint8x8_t fix8 = (uint8x8_t)vdup_n_u32(c); |
23 uint16x8_t fix8_16 = vmovl_u8(fix8); | 23 uint16x8_t fix8_16 = vmovl_u8(fix8); |
24 uint32x4_t fix8_32 = vmovl_u16(vget_low_u16(fix8_16)); | 24 uint32x4_t fix8_32 = vmovl_u16(vget_low_u16(fix8_16)); |
25 fColors = vcvtq_f32_u32(fix8_32); | 25 fColors = vcvtq_f32_u32(fix8_32); |
26 SkASSERT(this->isValid()); | 26 SkASSERT(this->isValid()); |
27 } | 27 } |
28 | 28 |
29 inline SkPMColor SkPMFloat::get() const { | 29 inline SkPMColor SkPMFloat::trunc() const { |
30 SkASSERT(this->isValid()); | 30 uint32x4_t fix8_32 = vcvtq_u32_f32(fColors); // vcvtq_u32_f32 truncates |
31 float32x4_t add_half = vaddq_f32(fColors, vdupq_n_f32(0.5f)); | |
32 uint32x4_t fix8_32 = vcvtq_u32_f32(add_half); // vcvtq_u32_f32 truncates,
so round manually | |
33 uint16x4_t fix8_16 = vmovn_u32(fix8_32); | 31 uint16x4_t fix8_16 = vmovn_u32(fix8_32); |
34 uint8x8_t fix8 = vmovn_u16(vcombine_u16(fix8_16, vdup_n_u16(0))); | 32 uint8x8_t fix8 = vmovn_u16(vcombine_u16(fix8_16, vdup_n_u16(0))); |
35 SkPMColor c = vget_lane_u32((uint32x2_t)fix8, 0); | 33 SkPMColor c = vget_lane_u32((uint32x2_t)fix8, 0); |
36 SkPMColorAssert(c); | 34 SkPMColorAssert(c); |
37 return c; | 35 return c; |
38 } | 36 } |
39 | 37 |
| 38 inline SkPMColor SkPMFloat::get() const { |
| 39 SkASSERT(this->isValid()); |
| 40 return SkPMFloat(Sk4f(0.5f) + *this).trunc(); |
| 41 } |
| 42 |
40 inline SkPMColor SkPMFloat::clamped() const { | 43 inline SkPMColor SkPMFloat::clamped() const { |
41 float32x4_t add_half = vaddq_f32(fColors, vdupq_n_f32(0.5f)); | 44 float32x4_t add_half = vaddq_f32(fColors, vdupq_n_f32(0.5f)); |
42 uint32x4_t fix8_32 = vcvtq_u32_f32(add_half); // vcvtq_u32_f32 truncates,
so round manually | 45 uint32x4_t fix8_32 = vcvtq_u32_f32(add_half); // vcvtq_u32_f32 truncates,
so round manually |
43 uint16x4_t fix8_16 = vqmovn_u32(fix8_32); | 46 uint16x4_t fix8_16 = vqmovn_u32(fix8_32); |
44 uint8x8_t fix8 = vqmovn_u16(vcombine_u16(fix8_16, vdup_n_u16(0))); | 47 uint8x8_t fix8 = vqmovn_u16(vcombine_u16(fix8_16, vdup_n_u16(0))); |
45 SkPMColor c = vget_lane_u32((uint32x2_t)fix8, 0); | 48 SkPMColor c = vget_lane_u32((uint32x2_t)fix8, 0); |
46 SkPMColorAssert(c); | 49 SkPMColorAssert(c); |
47 return c; | 50 return c; |
48 } | 51 } |
49 | 52 |
(...skipping 16 matching lines...) Expand all Loading... |
66 } | 69 } |
67 | 70 |
68 inline void SkPMFloat::ClampTo4PMColors( | 71 inline void SkPMFloat::ClampTo4PMColors( |
69 const SkPMFloat& a, const SkPMFloat& b, const SkPMFloat&c, const SkPMFlo
at& d, | 72 const SkPMFloat& a, const SkPMFloat& b, const SkPMFloat&c, const SkPMFlo
at& d, |
70 SkPMColor colors[4]) { | 73 SkPMColor colors[4]) { |
71 colors[0] = a.clamped(); | 74 colors[0] = a.clamped(); |
72 colors[1] = b.clamped(); | 75 colors[1] = b.clamped(); |
73 colors[2] = c.clamped(); | 76 colors[2] = c.clamped(); |
74 colors[3] = d.clamped(); | 77 colors[3] = d.clamped(); |
75 } | 78 } |
OLD | NEW |