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