8 #ifndef SkColorPriv_DEFINED
9 #define SkColorPriv_DEFINED
12 #include "include/private/base/SkMath.h"
13 #include "include/private/base/SkTPin.h"
14 #include "include/private/base/SkTo.h"
25 SkASSERT(SkToU8(alpha) == alpha);
34 #define SkAlphaMul(value, alpha256) (((value) * (alpha256)) >> 8)
37 return static_cast<U8CPU
>(SkTPin(x, 0.0f, 1.0f) * 255 + 0.5);
45 #define SK_A32_MASK ((1 << SK_A32_BITS) - 1)
46 #define SK_R32_MASK ((1 << SK_R32_BITS) - 1)
47 #define SK_G32_MASK ((1 << SK_G32_BITS) - 1)
48 #define SK_B32_MASK ((1 << SK_B32_BITS) - 1)
62 #define SK_RGBA_R32_SHIFT 0
63 #define SK_RGBA_G32_SHIFT 8
64 #define SK_RGBA_B32_SHIFT 16
65 #define SK_RGBA_A32_SHIFT 24
67 #define SK_BGRA_B32_SHIFT 0
68 #define SK_BGRA_G32_SHIFT 8
69 #define SK_BGRA_R32_SHIFT 16
70 #define SK_BGRA_A32_SHIFT 24
72 #if defined(SK_PMCOLOR_IS_RGBA) || defined(SK_PMCOLOR_IS_BGRA)
73 #error "Configure PMCOLOR by setting SK_R32_SHIFT."
78 #if (SK_A32_SHIFT == SK_RGBA_A32_SHIFT && \
79 SK_R32_SHIFT == SK_RGBA_R32_SHIFT && \
80 SK_G32_SHIFT == SK_RGBA_G32_SHIFT && \
81 SK_B32_SHIFT == SK_RGBA_B32_SHIFT)
82 #define SK_PMCOLOR_IS_RGBA
83 #elif (SK_A32_SHIFT == SK_BGRA_A32_SHIFT && \
84 SK_R32_SHIFT == SK_BGRA_R32_SHIFT && \
85 SK_G32_SHIFT == SK_BGRA_G32_SHIFT && \
86 SK_B32_SHIFT == SK_BGRA_B32_SHIFT)
87 #define SK_PMCOLOR_IS_BGRA
89 #error "need 32bit packing to be either RGBA or BGRA"
92 #define SkGetPackedA32(packed) ((uint32_t)((packed) << (24 - SK_A32_SHIFT)) >> 24)
93 #define SkGetPackedR32(packed) ((uint32_t)((packed) << (24 - SK_R32_SHIFT)) >> 24)
94 #define SkGetPackedG32(packed) ((uint32_t)((packed) << (24 - SK_G32_SHIFT)) >> 24)
95 #define SkGetPackedB32(packed) ((uint32_t)((packed) << (24 - SK_B32_SHIFT)) >> 24)
97 #define SkA32Assert(a) SkASSERT((unsigned)(a) <= SK_A32_MASK)
98 #define SkR32Assert(r) SkASSERT((unsigned)(r) <= SK_R32_MASK)
99 #define SkG32Assert(g) SkASSERT((unsigned)(g) <= SK_G32_MASK)
100 #define SkB32Assert(b) SkASSERT((unsigned)(b) <= SK_B32_MASK)
133 r = SkMulDiv255Round(r, a);
134 g = SkMulDiv255Round(g, a);
135 b = SkMulDiv255Round(b, a);
142 static SK_ALWAYS_INLINE uint32_t
SkAlphaMulQ(uint32_t c,
unsigned scale) {
143 uint32_t mask = 0xFF00FF;
145 uint32_t rb = ((c & mask) * scale) >> 8;
146 uint32_t ag = ((c >> 8) & mask) * scale;
147 return (rb & mask) | (ag & ~mask);
153 uint32_t mask = 0xFF00FF;
154 uint32_t rb = (((dst & mask) * scale) >> 8) & mask;
155 uint32_t ag = (((dst >> 8) & mask) * scale) & ~mask;
161 return std::min(rb & 0x000001FF, 0x000000FFU) |
162 std::min(ag & 0x0001FF00, 0x0000FF00U) |
163 std::min(rb & 0x01FF0000, 0x00FF0000U) |
#define SkB32Assert(b)
Definition: SkColorPriv.h:100
static SkPMColor SkPMSrcOver(SkPMColor src, SkPMColor dst)
Definition: SkColorPriv.h:150
static SK_ALWAYS_INLINE uint32_t SkAlphaMulQ(uint32_t c, unsigned scale)
Definition: SkColorPriv.h:142
#define SkA32Assert(a)
Definition: SkColorPriv.h:97
static SkPMColor SkPremultiplyARGBInline(U8CPU a, U8CPU r, U8CPU g, U8CPU b)
Definition: SkColorPriv.h:126
#define SkG32Assert(g)
Definition: SkColorPriv.h:99
#define SkGetPackedA32(packed)
Definition: SkColorPriv.h:92
#define SkR32Assert(r)
Definition: SkColorPriv.h:98
static U8CPU SkUnitScalarClampToByte(SkScalar x)
Definition: SkColorPriv.h:36
static unsigned SkAlpha255To256(U8CPU alpha)
Turn 0..255 into 0..256 by adding 1 at the half-way point.
Definition: SkColorPriv.h:24
static SkPMColor SkPackARGB32(U8CPU a, U8CPU r, U8CPU g, U8CPU b)
Pack the components into a SkPMColor, checking (in the debug version) that the components are 0....
Definition: SkColorPriv.h:106
static SkPMColor SkPackARGB32NoCheck(U8CPU a, U8CPU r, U8CPU g, U8CPU b)
Same as SkPackARGB32, but this version guarantees to not check that the values are premultiplied in t...
Definition: SkColorPriv.h:120
Types, consts, functions, and macros for colors.
uint32_t SkPMColor
32-bit ARGB color value, premultiplied.
Definition: SkColor.h:205
float SkScalar
Definition: SkScalar.h:14
#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