Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
SkSwizzlePriv.h
Go to the documentation of this file.
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#ifndef SkSwizzlePriv_DEFINED
9#define SkSwizzlePriv_DEFINED
10
12#include "src/base/SkVx.h"
13
14#include <cstdint>
15
16namespace SkOpts {
17 // Swizzle input into some sort of 8888 pixel, {premul,unpremul} x {rgba,bgra}.
18 using Swizzle_8888_u32 = void (*)(uint32_t*, const uint32_t*, int);
19 extern Swizzle_8888_u32 RGBA_to_BGRA, // i.e. just swap RB
20 RGBA_to_rgbA, // i.e. just premultiply
21 RGBA_to_bgrA, // i.e. swap RB and premultiply
22 rgbA_to_RGBA, // i.e. just unpremultiply
23 rgbA_to_BGRA, // i.e. swap RB and unpremultiply
24 inverted_CMYK_to_RGB1, // i.e. convert color space
25 inverted_CMYK_to_BGR1; // i.e. convert color space
26
27 using Swizzle_8888_u8 = void (*)(uint32_t*, const uint8_t*, int);
28 extern Swizzle_8888_u8 RGB_to_RGB1, // i.e. insert an opaque alpha
29 RGB_to_BGR1, // i.e. swap RB and insert an opaque alpha
30 gray_to_RGB1, // i.e. expand to color channels + an opaque alpha
31 grayA_to_RGBA, // i.e. expand to color channels
32 grayA_to_rgbA; // i.e. expand to color channels and premultiply
33
34 void Init_Swizzler();
35} // namespace SkOpts
36
37static inline skvx::float4 swizzle_rb(const skvx::float4& x) {
38 return skvx::shuffle<2, 1, 0, 3>(x);
39}
40
42#if defined(SK_PMCOLOR_IS_BGRA)
43 return swizzle_rb(x);
44#else
45 return x;
46#endif
47}
48
49static inline skvx::float4 Sk4f_fromL32(uint32_t px) {
50 return skvx::cast<float>(skvx::byte4::Load(&px)) * (1 / 255.0f);
51}
52
53static inline uint32_t Sk4f_toL32(const skvx::float4& px) {
54 uint32_t l32;
55 // For the expected positive color values, the +0.5 before the pin and cast effectively rounds
56 // to the nearest int without having to call round() or lrint().
57 skvx::cast<uint8_t>(skvx::pin(px * 255.f + 0.5f, skvx::float4(0.f), skvx::float4(255.f)))
58 .store(&l32);
59 return l32;
60}
61#endif // SkSwizzlePriv_DEFINED
static skvx::float4 swizzle_rb_if_bgra(const skvx::float4 &x)
static skvx::float4 Sk4f_fromL32(uint32_t px)
static uint32_t Sk4f_toL32(const skvx::float4 &px)
static skvx::float4 swizzle_rb(const skvx::float4 &x)
Type::kYUV Type::kRGBA() int(0.7 *637)
double x
void(*)(uint32_t *, const uint8_t *, int) Swizzle_8888_u8
void(*)(uint32_t *, const uint32_t *, int) Swizzle_8888_u32
Swizzle_8888_u8 gray_to_RGB1
Swizzle_8888_u32 RGBA_to_rgbA
Swizzle_8888_u8 RGB_to_RGB1
Swizzle_8888_u8 grayA_to_rgbA
Swizzle_8888_u8 RGB_to_BGR1
Swizzle_8888_u8 grayA_to_RGBA
Swizzle_8888_u32 RGBA_to_BGRA
Swizzle_8888_u32 RGBA_to_bgrA
void Init_Swizzler()
Swizzle_8888_u32 rgbA_to_BGRA
Swizzle_8888_u32 inverted_CMYK_to_BGR1
Swizzle_8888_u32 inverted_CMYK_to_RGB1
Swizzle_8888_u32 rgbA_to_RGBA
SINT Vec< N, T > pin(const Vec< N, T > &x, const Vec< N, T > &lo, const Vec< N, T > &hi)
Definition SkVx.h:655
static SKVX_ALWAYS_INLINE Vec Load(const void *ptr)
Definition SkVx.h:109
SKVX_ALWAYS_INLINE void store(void *ptr) const
Definition SkVx.h:112