8#ifndef skgpu_Swizzle_DEFINED
9#define skgpu_Swizzle_DEFINED
32 explicit constexpr Swizzle(
const char c[4]);
43 constexpr uint16_t
asKey()
const {
return fKey; }
48 constexpr char operator[](
int i)
const {
return IToC(this->channelIndex(
i)); }
55 constexpr std::array<float, 4>
applyTo(std::array<float, 4>
color)
const;
58 template <SkAlphaType AlphaType>
78 constexpr int channelIndex(
int i)
const {
80 return (fKey >> (4*
i)) & 0xfU;
83 static constexpr float ComponentIndexToFloat(std::array<float, 4>,
size_t idx);
84 static constexpr int CToI(
char c);
85 static constexpr char IToC(
int idx);
93 : fKey(static_cast<uint16_t>((CToI(c[0]) << 0) | (CToI(c[1]) << 4) | (CToI(c[2]) << 8) |
94 (CToI(c[3]) << 12))) {}
97 return Swizzle(
static_cast<uint16_t
>((this->channelIndex(
i) << 0) | (CToI(
'0') << 4) |
98 (CToI(
'0') << 8) | (CToI(
'0') << 12)));
104 size_t idx = (
key & 15);
105 float outR = ComponentIndexToFloat(
color, idx);
108 float outG = ComponentIndexToFloat(
color, idx);
111 float outB = ComponentIndexToFloat(
color, idx);
114 float outA = ComponentIndexToFloat(
color, idx);
115 return { outR, outG, outB, outA };
118constexpr float Swizzle::ComponentIndexToFloat(std::array<float, 4>
color,
size_t idx) {
122 if (idx ==
static_cast<size_t>(CToI(
'1'))) {
125 if (idx ==
static_cast<size_t>(CToI(
'0'))) {
131constexpr int Swizzle::CToI(
char c) {
144constexpr char Swizzle::IToC(
int idx) {
146 case CToI(
'r'): return
'r';
147 case CToI(
'g'): return
'g';
148 case CToI(
'b'): return
'b';
149 case CToI(
'a'): return
'a';
150 case CToI(
'0'): return
'0';
151 case CToI(
'1'): return
'1';
158 for (
unsigned i = 0;
i < 4; ++
i) {
159 int idx = (
b.fKey >> (4U *
i)) & 0xfU;
160 if (idx != CToI(
'0') && idx != CToI(
'1')) {
163 idx = ((
a.fKey >> (4 * idx)) & 0xfU);
165 key |= (idx << (4U *
i));
constexpr std::array< float, 4 > applyTo(std::array< float, 4 > color) const
constexpr Swizzle(const Swizzle &)=default
static constexpr Swizzle RRRA()
constexpr uint16_t asKey() const
constexpr SkRGBA4f< AlphaType > applyTo(SkRGBA4f< AlphaType > color) const
constexpr bool operator==(const Swizzle &that) const
constexpr Swizzle & operator=(const Swizzle &that)=default
constexpr Swizzle selectChannelInR(int i) const
constexpr char operator[](int i) const
static constexpr Swizzle Concat(const Swizzle &a, const Swizzle &b)
SkString asString() const
std::true_type sk_is_trivially_relocatable
static constexpr Swizzle BGRA()
static constexpr Swizzle RGBA()
constexpr bool operator!=(const Swizzle &that) const
void apply(SkRasterPipeline *) const
static constexpr Swizzle RGB1()
std::array< float, 4 > array() const