| 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 // For SkPMFloat(SkPMFColor), we widen our 8 bit components (fix8) to 8-bit comp
onents in 16 bits | 8 // For SkPMFloat(SkPMFColor), we widen our 8 bit components (fix8) to 8-bit comp
onents in 16 bits |
| 9 // (fix8_16), then widen those to 8-bit-in-32-bits (fix8_32), and finally conver
t those to floats. | 9 // (fix8_16), then widen those to 8-bit-in-32-bits (fix8_32), and finally conver
t those to floats. |
| 10 | 10 |
| 11 // round() and roundClamp() do the opposite, working from floats to 8-bit-in-32-
bit, | 11 // round() and roundClamp() do the opposite, working from floats to 8-bit-in-32-
bit, |
| 12 // to 8-bit-in-16-bit, back down to 8-bit components. | 12 // to 8-bit-in-16-bit, back down to 8-bit components. |
| 13 // roundClamp() uses vqmovn to clamp while narrowing instead of just narrowing w
ith vmovn. | 13 // roundClamp() uses vqmovn to clamp while narrowing instead of just narrowing w
ith vmovn. |
| 14 | 14 |
| 15 inline SkPMFloat::SkPMFloat(SkPMColor c) { | 15 inline SkPMFloat::SkPMFloat(SkPMColor c) { |
| 16 SkPMColorAssert(c); | 16 SkPMColorAssert(c); |
| 17 uint8x8_t fix8 = (uint8x8_t)vdup_n_u32(c); | 17 uint8x8_t fix8 = (uint8x8_t)vdup_n_u32(c); |
| 18 uint16x8_t fix8_16 = vmovl_u8(fix8); | 18 uint16x8_t fix8_16 = vmovl_u8(fix8); |
| 19 uint32x4_t fix8_32 = vmovl_u16(vget_low_u16(fix8_16)); | 19 uint32x4_t fix8_32 = vmovl_u16(vget_low_u16(fix8_16)); |
| 20 fColors = vcvtq_f32_u32(fix8_32); | 20 fColors = vcvtq_f32_u32(fix8_32); |
| 21 SkASSERT(this->isValid()); | 21 SkASSERT(this->isValid()); |
| 22 } | 22 } |
| 23 | 23 |
| 24 inline SkPMColor SkPMFloat::trunc() const { | 24 inline SkPMColor SkPMFloat::trunc() const { |
| 25 uint32x4_t fix8_32 = vcvtq_u32_f32(fVec); // vcvtq_u32_f32 truncates | 25 uint32x4_t fix8_32 = vcvtq_u32_f32(fColors.vec()); // vcvtq_u32_f32 trunc
ates |
| 26 uint16x4_t fix8_16 = vmovn_u32(fix8_32); | 26 uint16x4_t fix8_16 = vmovn_u32(fix8_32); |
| 27 uint8x8_t fix8 = vmovn_u16(vcombine_u16(fix8_16, vdup_n_u16(0))); | 27 uint8x8_t fix8 = vmovn_u16(vcombine_u16(fix8_16, vdup_n_u16(0))); |
| 28 SkPMColor c = vget_lane_u32((uint32x2_t)fix8, 0); | 28 SkPMColor c = vget_lane_u32((uint32x2_t)fix8, 0); |
| 29 SkPMColorAssert(c); | 29 SkPMColorAssert(c); |
| 30 return c; | 30 return c; |
| 31 } | 31 } |
| 32 | 32 |
| 33 inline SkPMColor SkPMFloat::round() const { | 33 inline SkPMColor SkPMFloat::round() const { |
| 34 return SkPMFloat(Sk4f(0.5f) + *this).trunc(); | 34 return SkPMFloat(Sk4f(0.5f) + *this).trunc(); |
| 35 } | 35 } |
| 36 | 36 |
| 37 inline SkPMColor SkPMFloat::roundClamp() const { | 37 inline SkPMColor SkPMFloat::roundClamp() const { |
| 38 float32x4_t add_half = vaddq_f32(fVec, vdupq_n_f32(0.5f)); | 38 float32x4_t add_half = vaddq_f32(fColors.vec(), vdupq_n_f32(0.5f)); |
| 39 uint32x4_t fix8_32 = vcvtq_u32_f32(add_half); // vcvtq_u32_f32 truncates,
so round manually | 39 uint32x4_t fix8_32 = vcvtq_u32_f32(add_half); // vcvtq_u32_f32 truncates,
so round manually |
| 40 uint16x4_t fix8_16 = vqmovn_u32(fix8_32); | 40 uint16x4_t fix8_16 = vqmovn_u32(fix8_32); |
| 41 uint8x8_t fix8 = vqmovn_u16(vcombine_u16(fix8_16, vdup_n_u16(0))); | 41 uint8x8_t fix8 = vqmovn_u16(vcombine_u16(fix8_16, vdup_n_u16(0))); |
| 42 SkPMColor c = vget_lane_u32((uint32x2_t)fix8, 0); | 42 SkPMColor c = vget_lane_u32((uint32x2_t)fix8, 0); |
| 43 SkPMColorAssert(c); | 43 SkPMColorAssert(c); |
| 44 return c; | 44 return c; |
| 45 } | 45 } |
| 46 | 46 |
| 47 // TODO: we should be able to beat these loops on all three methods. | 47 // TODO: we should be able to beat these loops on all three methods. |
| 48 inline void SkPMFloat::From4PMColors(const SkPMColor colors[4], | 48 inline void SkPMFloat::From4PMColors(const SkPMColor colors[4], |
| (...skipping 14 matching lines...) Expand all Loading... |
| 63 } | 63 } |
| 64 | 64 |
| 65 inline void SkPMFloat::RoundClampTo4PMColors( | 65 inline void SkPMFloat::RoundClampTo4PMColors( |
| 66 const SkPMFloat& a, const SkPMFloat& b, const SkPMFloat&c, const SkPMFlo
at& d, | 66 const SkPMFloat& a, const SkPMFloat& b, const SkPMFloat&c, const SkPMFlo
at& d, |
| 67 SkPMColor colors[4]) { | 67 SkPMColor colors[4]) { |
| 68 colors[0] = a.roundClamp(); | 68 colors[0] = a.roundClamp(); |
| 69 colors[1] = b.roundClamp(); | 69 colors[1] = b.roundClamp(); |
| 70 colors[2] = c.roundClamp(); | 70 colors[2] = c.roundClamp(); |
| 71 colors[3] = d.roundClamp(); | 71 colors[3] = d.roundClamp(); |
| 72 } | 72 } |
| OLD | NEW |