Flutter Engine
The Flutter Engine
Macros | Functions
SkColorPriv.h File Reference
#include "include/core/SkColor.h"
#include "include/private/base/SkMath.h"
#include "include/private/base/SkTPin.h"
#include "include/private/base/SkTo.h"
#include <algorithm>

Go to the source code of this file.

Macros

#define SkAlphaMul(value, alpha256)   (((value) * (alpha256)) >> 8)
 
#define SK_A32_BITS   8
 
#define SK_R32_BITS   8
 
#define SK_G32_BITS   8
 
#define SK_B32_BITS   8
 
#define SK_A32_MASK   ((1 << SK_A32_BITS) - 1)
 
#define SK_R32_MASK   ((1 << SK_R32_BITS) - 1)
 
#define SK_G32_MASK   ((1 << SK_G32_BITS) - 1)
 
#define SK_B32_MASK   ((1 << SK_B32_BITS) - 1)
 
#define SK_RGBA_R32_SHIFT   0
 
#define SK_RGBA_G32_SHIFT   8
 
#define SK_RGBA_B32_SHIFT   16
 
#define SK_RGBA_A32_SHIFT   24
 
#define SK_BGRA_B32_SHIFT   0
 
#define SK_BGRA_G32_SHIFT   8
 
#define SK_BGRA_R32_SHIFT   16
 
#define SK_BGRA_A32_SHIFT   24
 
#define SkGetPackedA32(packed)   ((uint32_t)((packed) << (24 - SK_A32_SHIFT)) >> 24)
 
#define SkGetPackedR32(packed)   ((uint32_t)((packed) << (24 - SK_R32_SHIFT)) >> 24)
 
#define SkGetPackedG32(packed)   ((uint32_t)((packed) << (24 - SK_G32_SHIFT)) >> 24)
 
#define SkGetPackedB32(packed)   ((uint32_t)((packed) << (24 - SK_B32_SHIFT)) >> 24)
 
#define SkA32Assert(a)   SkASSERT((unsigned)(a) <= SK_A32_MASK)
 
#define SkR32Assert(r)   SkASSERT((unsigned)(r) <= SK_R32_MASK)
 
#define SkG32Assert(g)   SkASSERT((unsigned)(g) <= SK_G32_MASK)
 
#define SkB32Assert(b)   SkASSERT((unsigned)(b) <= SK_B32_MASK)
 

Functions

static unsigned SkAlpha255To256 (U8CPU alpha)
 
static U8CPU SkUnitScalarClampToByte (SkScalar x)
 
static SkPMColor SkPackARGB32 (U8CPU a, U8CPU r, U8CPU g, U8CPU b)
 
static SkPMColor SkPackARGB32NoCheck (U8CPU a, U8CPU r, U8CPU g, U8CPU b)
 
static SkPMColor SkPremultiplyARGBInline (U8CPU a, U8CPU r, U8CPU g, U8CPU b)
 
static SK_ALWAYS_INLINE uint32_t SkAlphaMulQ (uint32_t c, unsigned scale)
 
static SkPMColor SkPMSrcOver (SkPMColor src, SkPMColor dst)
 

Macro Definition Documentation

◆ SK_A32_BITS

#define SK_A32_BITS   8

Definition at line 40 of file SkColorPriv.h.

◆ SK_A32_MASK

#define SK_A32_MASK   ((1 << SK_A32_BITS) - 1)

Definition at line 45 of file SkColorPriv.h.

◆ SK_B32_BITS

#define SK_B32_BITS   8

Definition at line 43 of file SkColorPriv.h.

◆ SK_B32_MASK

#define SK_B32_MASK   ((1 << SK_B32_BITS) - 1)

Definition at line 48 of file SkColorPriv.h.

◆ SK_BGRA_A32_SHIFT

#define SK_BGRA_A32_SHIFT   24

Definition at line 70 of file SkColorPriv.h.

◆ SK_BGRA_B32_SHIFT

#define SK_BGRA_B32_SHIFT   0

Definition at line 67 of file SkColorPriv.h.

◆ SK_BGRA_G32_SHIFT

#define SK_BGRA_G32_SHIFT   8

Definition at line 68 of file SkColorPriv.h.

◆ SK_BGRA_R32_SHIFT

#define SK_BGRA_R32_SHIFT   16

Definition at line 69 of file SkColorPriv.h.

◆ SK_G32_BITS

#define SK_G32_BITS   8

Definition at line 42 of file SkColorPriv.h.

◆ SK_G32_MASK

#define SK_G32_MASK   ((1 << SK_G32_BITS) - 1)

Definition at line 47 of file SkColorPriv.h.

◆ SK_R32_BITS

#define SK_R32_BITS   8

Definition at line 41 of file SkColorPriv.h.

◆ SK_R32_MASK

#define SK_R32_MASK   ((1 << SK_R32_BITS) - 1)

Definition at line 46 of file SkColorPriv.h.

◆ SK_RGBA_A32_SHIFT

#define SK_RGBA_A32_SHIFT   24

Definition at line 65 of file SkColorPriv.h.

◆ SK_RGBA_B32_SHIFT

#define SK_RGBA_B32_SHIFT   16

Definition at line 64 of file SkColorPriv.h.

◆ SK_RGBA_G32_SHIFT

#define SK_RGBA_G32_SHIFT   8

Definition at line 63 of file SkColorPriv.h.

◆ SK_RGBA_R32_SHIFT

#define SK_RGBA_R32_SHIFT   0

Definition at line 62 of file SkColorPriv.h.

◆ SkA32Assert

#define SkA32Assert (   a)    SkASSERT((unsigned)(a) <= SK_A32_MASK)

Definition at line 97 of file SkColorPriv.h.

◆ SkAlphaMul

#define SkAlphaMul (   value,
  alpha256 
)    (((value) * (alpha256)) >> 8)

Multiplify value by 0..256, and shift the result down 8 (i.e. return (value * alpha256) >> 8)

Definition at line 34 of file SkColorPriv.h.

◆ SkB32Assert

#define SkB32Assert (   b)    SkASSERT((unsigned)(b) <= SK_B32_MASK)

Definition at line 100 of file SkColorPriv.h.

◆ SkG32Assert

#define SkG32Assert (   g)    SkASSERT((unsigned)(g) <= SK_G32_MASK)

Definition at line 99 of file SkColorPriv.h.

◆ SkGetPackedA32

#define SkGetPackedA32 (   packed)    ((uint32_t)((packed) << (24 - SK_A32_SHIFT)) >> 24)

Definition at line 92 of file SkColorPriv.h.

◆ SkGetPackedB32

#define SkGetPackedB32 (   packed)    ((uint32_t)((packed) << (24 - SK_B32_SHIFT)) >> 24)

Definition at line 95 of file SkColorPriv.h.

◆ SkGetPackedG32

#define SkGetPackedG32 (   packed)    ((uint32_t)((packed) << (24 - SK_G32_SHIFT)) >> 24)

Definition at line 94 of file SkColorPriv.h.

◆ SkGetPackedR32

#define SkGetPackedR32 (   packed)    ((uint32_t)((packed) << (24 - SK_R32_SHIFT)) >> 24)

Definition at line 93 of file SkColorPriv.h.

◆ SkR32Assert

#define SkR32Assert (   r)    SkASSERT((unsigned)(r) <= SK_R32_MASK)

Definition at line 98 of file SkColorPriv.h.

Function Documentation

◆ SkAlpha255To256()

static unsigned SkAlpha255To256 ( U8CPU  alpha)
inlinestatic

Turn 0..255 into 0..256 by adding 1 at the half-way point. Used to turn a byte into a scale value, so that we can say scale * value >> 8 instead of alpha * value / 255.

In debugging, asserts that alpha is 0..255

Definition at line 24 of file SkColorPriv.h.

24 {
25 SkASSERT(SkToU8(alpha) == alpha);
26 // this one assues that blending on top of an opaque dst keeps it that way
27 // even though it is less accurate than a+(a>>7) for non-opaque dsts
28 return alpha + 1;
29}
#define SkASSERT(cond)
Definition: SkAssert.h:116
constexpr uint8_t SkToU8(S x)
Definition: SkTo.h:22

◆ SkAlphaMulQ()

static SK_ALWAYS_INLINE uint32_t SkAlphaMulQ ( uint32_t  c,
unsigned  scale 
)
static

Definition at line 142 of file SkColorPriv.h.

142 {
143 uint32_t mask = 0xFF00FF;
144
145 uint32_t rb = ((c & mask) * scale) >> 8;
146 uint32_t ag = ((c >> 8) & mask) * scale;
147 return (rb & mask) | (ag & ~mask);
148}
const Scalar scale

◆ SkPackARGB32()

static SkPMColor SkPackARGB32 ( U8CPU  a,
U8CPU  r,
U8CPU  g,
U8CPU  b 
)
inlinestatic

Pack the components into a SkPMColor, checking (in the debug version) that the components are 0..255, and are already premultiplied (i.e. alpha >= color)

Definition at line 106 of file SkColorPriv.h.

106 {
107 SkA32Assert(a);
108 SkASSERT(r <= a);
109 SkASSERT(g <= a);
110 SkASSERT(b <= a);
111
112 return (a << SK_A32_SHIFT) | (r << SK_R32_SHIFT) |
113 (g << SK_G32_SHIFT) | (b << SK_B32_SHIFT);
114}
#define SkA32Assert(a)
Definition: SkColorPriv.h:97
#define SK_R32_SHIFT
Definition: SkTypes.h:44
#define SK_A32_SHIFT
Definition: SkTypes.h:54
#define SK_B32_SHIFT
Definition: SkTypes.h:50
#define SK_G32_SHIFT
Definition: SkTypes.h:53
static bool b
struct MyStruct a[10]

◆ SkPackARGB32NoCheck()

static SkPMColor SkPackARGB32NoCheck ( U8CPU  a,
U8CPU  r,
U8CPU  g,
U8CPU  b 
)
inlinestatic

Same as SkPackARGB32, but this version guarantees to not check that the values are premultiplied in the debug version.

Definition at line 120 of file SkColorPriv.h.

120 {
121 return (a << SK_A32_SHIFT) | (r << SK_R32_SHIFT) |
122 (g << SK_G32_SHIFT) | (b << SK_B32_SHIFT);
123}

◆ SkPMSrcOver()

static SkPMColor SkPMSrcOver ( SkPMColor  src,
SkPMColor  dst 
)
inlinestatic

Definition at line 150 of file SkColorPriv.h.

150 {
151 uint32_t scale = SkAlpha255To256(255 - SkGetPackedA32(src));
152
153 uint32_t mask = 0xFF00FF;
154 uint32_t rb = (((dst & mask) * scale) >> 8) & mask;
155 uint32_t ag = (((dst >> 8) & mask) * scale) & ~mask;
156
157 rb += (src & mask);
158 ag += (src & ~mask);
159
160 // Color channels (but not alpha) can overflow, so we have to saturate to 0xFF in each lane.
161 return std::min(rb & 0x000001FF, 0x000000FFU) |
162 std::min(ag & 0x0001FF00, 0x0000FF00U) |
163 std::min(rb & 0x01FF0000, 0x00FF0000U) |
164 (ag & 0xFF000000);
165}
#define SkGetPackedA32(packed)
Definition: SkColorPriv.h:92
static unsigned SkAlpha255To256(U8CPU alpha)
Definition: SkColorPriv.h:24
static float min(float r, float g, float b)
Definition: hsl.cpp:48
dst
Definition: cp.py:12

◆ SkPremultiplyARGBInline()

static SkPMColor SkPremultiplyARGBInline ( U8CPU  a,
U8CPU  r,
U8CPU  g,
U8CPU  b 
)
inlinestatic

Definition at line 126 of file SkColorPriv.h.

126 {
127 SkA32Assert(a);
128 SkR32Assert(r);
129 SkG32Assert(g);
130 SkB32Assert(b);
131
132 if (a != 255) {
133 r = SkMulDiv255Round(r, a);
134 g = SkMulDiv255Round(g, a);
135 b = SkMulDiv255Round(b, a);
136 }
137 return SkPackARGB32(a, r, g, b);
138}
#define SkB32Assert(b)
Definition: SkColorPriv.h:100
#define SkG32Assert(g)
Definition: SkColorPriv.h:99
#define SkR32Assert(r)
Definition: SkColorPriv.h:98
static SkPMColor SkPackARGB32(U8CPU a, U8CPU r, U8CPU g, U8CPU b)
Definition: SkColorPriv.h:106
static U8CPU SkMulDiv255Round(U16CPU a, U16CPU b)
Definition: SkMath.h:73

◆ SkUnitScalarClampToByte()

static U8CPU SkUnitScalarClampToByte ( SkScalar  x)
inlinestatic

Definition at line 36 of file SkColorPriv.h.

36 {
37 return static_cast<U8CPU>(SkTPin(x, 0.0f, 1.0f) * 255 + 0.5);
38}
unsigned U8CPU
Definition: SkCPUTypes.h:18
static constexpr const T & SkTPin(const T &x, const T &lo, const T &hi)
Definition: SkTPin.h:19
double x