• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2016 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 #include "include/private/SkColorData.h"
9 #include "src/base/SkVx.h"
10 
11 #include <cstdint>
12 
swizzle_rb(const skvx::float4 & x)13 static inline skvx::float4 swizzle_rb(const skvx::float4& x) {
14     return skvx::shuffle<2, 1, 0, 3>(x);
15 }
16 
swizzle_rb_if_bgra(const skvx::float4 & x)17 static inline skvx::float4 swizzle_rb_if_bgra(const skvx::float4& x) {
18 #if defined(SK_PMCOLOR_IS_BGRA)
19     return swizzle_rb(x);
20 #else
21     return x;
22 #endif
23 }
24 
Sk4f_fromL32(uint32_t px)25 static inline skvx::float4 Sk4f_fromL32(uint32_t px) {
26     return skvx::cast<float>(skvx::byte4::Load(&px)) * (1 / 255.0f);
27 }
28 
Sk4f_toL32(const skvx::float4 & px)29 static inline uint32_t Sk4f_toL32(const skvx::float4& px) {
30     uint32_t l32;
31     // For the expected positive color values, the +0.5 before the pin and cast effectively rounds
32     // to the nearest int without having to call round() or lrint().
33     skvx::cast<uint8_t>(skvx::pin(px * 255.f + 0.5f, skvx::float4(0.f), skvx::float4(255.f)))
34                        .store(&l32);
35     return l32;
36 }
37