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 namespace { // See SkPMFloat.h | 8 namespace { // See SkPMFloat.h |
9 | 9 |
| 10 static_assert(SK_A32_SHIFT == 24, "This file assumes little-endian."); |
| 11 |
10 inline SkPMFloat::SkPMFloat(SkPMColor c) { | 12 inline SkPMFloat::SkPMFloat(SkPMColor c) { |
11 SkPMColorAssert(c); | 13 SkPMColorAssert(c); |
12 uint8x8_t fix8 = (uint8x8_t)vdup_n_u32(c); | 14 uint8x8_t fix8 = (uint8x8_t)vdup_n_u32(c); |
13 uint16x8_t fix8_16 = vmovl_u8(fix8); | 15 uint16x8_t fix8_16 = vmovl_u8(fix8); |
14 uint32x4_t fix8_32 = vmovl_u16(vget_low_u16(fix8_16)); | 16 uint32x4_t fix8_32 = vmovl_u16(vget_low_u16(fix8_16)); |
15 fVec = vmulq_f32(vcvtq_f32_u32(fix8_32), vdupq_n_f32(1.0f/255)); | 17 fVec = vmulq_f32(vcvtq_f32_u32(fix8_32), vdupq_n_f32(1.0f/255)); |
16 SkASSERT(this->isValid()); | 18 SkASSERT(this->isValid()); |
17 } | 19 } |
18 | 20 |
19 inline SkPMColor SkPMFloat::round() const { | 21 inline SkPMColor SkPMFloat::round() const { |
20 // vcvt_u32_f32 truncates, so we round manually by adding a half before conv
erting. | 22 // vcvt_u32_f32 truncates, so we round manually by adding a half before conv
erting. |
21 float32x4_t rounded = vmlaq_f32(vdupq_n_f32(0.5f), fVec, vdupq_n_f32(255)); | 23 float32x4_t rounded = vmlaq_f32(vdupq_n_f32(0.5f), fVec, vdupq_n_f32(255)); |
22 uint32x4_t fix8_32 = vcvtq_u32_f32(rounded); | 24 uint32x4_t fix8_32 = vcvtq_u32_f32(rounded); |
23 uint16x4_t fix8_16 = vqmovn_u32(fix8_32); | 25 uint16x4_t fix8_16 = vqmovn_u32(fix8_32); |
24 uint8x8_t fix8 = vqmovn_u16(vcombine_u16(fix8_16, vdup_n_u16(0))); | 26 uint8x8_t fix8 = vqmovn_u16(vcombine_u16(fix8_16, vdup_n_u16(0))); |
25 SkPMColor c = vget_lane_u32((uint32x2_t)fix8, 0); | 27 SkPMColor c = vget_lane_u32((uint32x2_t)fix8, 0); |
26 SkPMColorAssert(c); | 28 SkPMColorAssert(c); |
27 return c; | 29 return c; |
28 } | 30 } |
29 | 31 |
30 inline Sk4f SkPMFloat::alphas() const { | 32 inline Sk4f SkPMFloat::alphas() const { |
31 static_assert(SK_A32_SHIFT == 24, "Assuming little-endian."); | |
32 return vdupq_lane_f32(vget_high_f32(fVec), 1); // Duplicate high lane of hi
gh half i.e. lane 3. | 33 return vdupq_lane_f32(vget_high_f32(fVec), 1); // Duplicate high lane of hi
gh half i.e. lane 3. |
33 } | 34 } |
34 | 35 |
| 36 inline SkPMFloat SkPMFloat::FromBGRx(SkColor c) { |
| 37 uint8x8_t fix8 = (uint8x8_t)vdup_n_u32(c); |
| 38 #if defined(SK_PMCOLOR_IS_RGBA) |
| 39 fix8 = vtbl1_u8(fix8, vcreate_u8(0x0300010203000102ULL)); // 03 00 01 02, 2
x, i.e. swap R&B. |
| 40 #endif |
| 41 uint16x8_t fix8_16 = vmovl_u8(fix8); |
| 42 uint32x4_t fix8_32 = vmovl_u16(vget_low_u16(fix8_16)); |
| 43 fix8_32 = vsetq_lane_u32(0xFF, fix8_32, 3); // Force alpha to 1. |
| 44 |
| 45 SkPMFloat pmf = Sk4f(vmulq_f32(vcvtq_f32_u32(fix8_32), vdupq_n_f32(1.0f/255)
)); |
| 46 SkASSERT(pmf.isValid()); |
| 47 return pmf; |
| 48 } |
| 49 |
35 } // namespace | 50 } // namespace |
OLD | NEW |