8 #ifndef SkColor_DEFINED
9 #define SkColor_DEFINED
14 #include "include/private/base/SkCPUTypes.h"
50 return SkASSERT(a <= 255 && r <= 255 && g <= 255 && b <= 255),
51 (a << 24) | (r << 16) | (g << 8) | (b << 0);
57 #define SkColorSetRGB(r, g, b) SkColorSetARGB(0xFF, r, g, b)
61 #define SkColorGetA(color) (((color) >> 24) & 0xFF)
65 #define SkColorGetR(color) (((color) >> 16) & 0xFF)
69 #define SkColorGetG(color) (((color) >> 8) & 0xFF)
73 #define SkColorGetB(color) (((color) >> 0) & 0xFF)
83 return (c & 0x00FFFFFF) | (a << 24);
261 template <SkAlphaType kAT>
274 return fA == other.
fA &&
fR == other.
fR &&
fG == other.
fG &&
fB == other.
fB;
283 return !(*
this == other);
292 return {
fR * scale,
fG * scale,
fB * scale,
fA * scale };
308 const float*
vec()
const {
return &
fR; }
325 SkASSERT(index >= 0 && index < 4);
326 return this->
vec()[index];
335 SkASSERT(index >= 0 && index < 4);
336 return this->
vec()[index];
345 SkASSERT(fA <= 1.0f && fA >= 0.0f);
351 SkASSERT(
fA >= 0.0f &&
fA <= 1.0f);
352 return fR >= 0.0f &&
fR <= 1.0f &&
353 fG >= 0.0f &&
fG <= 1.0f &&
354 fB >= 0.0f &&
fB <= 1.0f;
399 return { 0, 0, 0, 0 };
401 float invAlpha = 1 /
fA;
402 return {
fR * invAlpha,
fG * invAlpha,
fB * invAlpha,
fA };
416 return {
fR,
fG,
fB, 1.0f };
429 template <> SK_API
SkColor SkColor4f::toSkColor()
const;
430 template <> SK_API uint32_t SkColor4f::toBytes_RGBA()
const;
431 template <> SK_API
SkColor4f SkColor4f::FromBytes_RGBA(uint32_t color);
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
Definition: SkAlphaType.h:29
@ kUnpremul_SkAlphaType
pixel components are independent of alpha
Definition: SkAlphaType.h:30
constexpr SkColor SK_ColorYELLOW
Represents fully opaque yellow.
Definition: SkColor.h:139
constexpr SkColor SK_ColorLTGRAY
Represents fully opaque light gray.
Definition: SkColor.h:118
#define SkColorGetR(color)
Returns red component of color, from zero to 255.
Definition: SkColor.h:65
constexpr SkColor SK_ColorMAGENTA
Represents fully opaque magenta.
Definition: SkColor.h:147
#define SkColorGetG(color)
Returns green component of color, from zero to 255.
Definition: SkColor.h:69
SK_API SkPMColor SkPreMultiplyARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b)
Returns a SkPMColor value from unpremultiplied 8-bit component values.
SK_API SkPMColor SkPreMultiplyColor(SkColor c)
Returns pmcolor closest to color c.
uint32_t SkColor
32-bit ARGB color value, unpremultiplied.
Definition: SkColor.h:37
constexpr SkColor SK_ColorCYAN
Represents fully opaque cyan.
Definition: SkColor.h:143
uint8_t SkAlpha
8-bit type for an alpha value.
Definition: SkColor.h:26
constexpr SkColor SK_ColorTRANSPARENT
Represents fully transparent SkColor.
Definition: SkColor.h:99
uint32_t SkPMColor
32-bit ARGB color value, premultiplied.
Definition: SkColor.h:205
SK_API SkColor SkHSVToColor(U8CPU alpha, const SkScalar hsv[3])
Converts HSV components to an ARGB color.
constexpr SkColor SK_ColorGRAY
Represents fully opaque gray.
Definition: SkColor.h:113
SkColorChannel
Describes different color channels one can manipulate.
Definition: SkColor.h:228
constexpr SkColor SK_ColorBLUE
Represents fully opaque blue.
Definition: SkColor.h:135
static constexpr SkColor SkColorSetA(SkColor c, U8CPU a)
Returns unpremultiplied color with red, blue, and green set from c; and alpha set from a.
Definition: SkColor.h:82
constexpr SkAlpha SK_AlphaOPAQUE
Represents fully opaque SkAlpha value.
Definition: SkColor.h:94
SK_API void SkRGBToHSV(U8CPU red, U8CPU green, U8CPU blue, SkScalar hsv[3])
Converts RGB to its HSV components.
constexpr SkColor SK_ColorRED
Represents fully opaque red.
Definition: SkColor.h:126
static constexpr SkColor SkColorSetARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b)
Returns color value from 8-bit component values.
Definition: SkColor.h:49
static void SkColorToHSV(SkColor color, SkScalar hsv[3])
Converts ARGB to its HSV components.
Definition: SkColor.h:169
constexpr SkColor SK_ColorBLACK
Represents fully opaque black.
Definition: SkColor.h:103
constexpr SkColor SK_ColorGREEN
Represents fully opaque green.
Definition: SkColor.h:131
SkColorChannelFlag
Used to represent the channels available in a color type or texture format as a mask.
Definition: SkColor.h:238
@ kRGB_SkColorChannelFlags
Definition: SkColor.h:247
@ kRGBA_SkColorChannelFlags
Definition: SkColor.h:248
@ kRed_SkColorChannelFlag
Definition: SkColor.h:239
@ kGrayAlpha_SkColorChannelFlags
Definition: SkColor.h:245
@ kRG_SkColorChannelFlags
Definition: SkColor.h:246
@ kGreen_SkColorChannelFlag
Definition: SkColor.h:240
@ kAlpha_SkColorChannelFlag
Definition: SkColor.h:242
@ kGray_SkColorChannelFlag
Definition: SkColor.h:243
@ kBlue_SkColorChannelFlag
Definition: SkColor.h:241
#define SkColorGetB(color)
Returns blue component of color, from zero to 255.
Definition: SkColor.h:73
constexpr SkColor SK_ColorWHITE
Represents fully opaque white.
Definition: SkColor.h:122
constexpr SkAlpha SK_AlphaTRANSPARENT
Represents fully transparent SkAlpha value.
Definition: SkColor.h:89
constexpr SkColor SK_ColorDKGRAY
Represents fully opaque dark gray.
Definition: SkColor.h:108
float SkScalar
Definition: SkScalar.h:14
Definition: SkColor.h:433
constexpr SkColor4f kLtGray
Definition: SkColor.h:438
constexpr SkColor4f kMagenta
Definition: SkColor.h:445
constexpr SkColor4f kGreen
Definition: SkColor.h:441
constexpr SkColor4f kRed
Definition: SkColor.h:440
constexpr SkColor4f kWhite
Definition: SkColor.h:439
constexpr SkColor4f kCyan
Definition: SkColor.h:444
constexpr SkColor4f kTransparent
Definition: SkColor.h:434
constexpr SkColor4f kBlack
Definition: SkColor.h:435
constexpr SkColor4f kGray
Definition: SkColor.h:437
constexpr SkColor4f kBlue
Definition: SkColor.h:442
constexpr SkColor4f kYellow
Definition: SkColor.h:443
constexpr SkColor4f kDkGray
Definition: SkColor.h:436
RGBA color value, holding four floating point components.
RGBA color value, holding four floating point components.
Definition: SkColor.h:262
const float * vec() const
Returns a pointer to components of SkRGBA4f, for array access.
Definition: SkColor.h:308
SkColor toSkColor() const
Returns closest SkColor to SkRGBA4f.
float fB
blue component
Definition: SkColor.h:265
SkRGBA4f operator*(float scale) const
Returns SkRGBA4f multiplied by scale.
Definition: SkColor.h:291
float * vec()
Returns a pointer to components of SkRGBA4f, for array access.
Definition: SkColor.h:314
bool fitsInBytes() const
Returns true if all channels are in [0, 1].
Definition: SkColor.h:350
SkRGBA4f operator*(const SkRGBA4f &scale) const
Returns SkRGBA4f multiplied component-wise by scale.
Definition: SkColor.h:300
static SkRGBA4f FromBytes_RGBA(uint32_t color)
bool operator!=(const SkRGBA4f &other) const
Compares SkRGBA4f with other, and returns true if not all components are equal.
Definition: SkColor.h:282
bool operator==(const SkRGBA4f &other) const
Compares SkRGBA4f with other, and returns true if all components are equal.
Definition: SkColor.h:273
std::array< float, 4 > array() const
As a std::array<float, 4>
Definition: SkColor.h:317
float fR
red component
Definition: SkColor.h:263
SkRGBA4f makeOpaque() const
Returns a copy of the SkRGBA4f but with alpha component set to 1.0f.
Definition: SkColor.h:415
SkRGBA4f< kUnpremul_SkAlphaType > unpremul() const
Returns SkRGBA4f unpremultiplied by alpha.
Definition: SkColor.h:395
uint32_t toBytes_RGBA() const
static SkRGBA4f FromColor(SkColor color)
Returns closest SkRGBA4f to SkColor.
float operator[](int index) const
Returns one component.
Definition: SkColor.h:324
float fG
green component
Definition: SkColor.h:264
static SkRGBA4f FromPMColor(SkPMColor)
Returns closest SkRGBA4f to SkPMColor.
SkRGBA4f< kPremul_SkAlphaType > premul() const
Returns SkRGBA4f premultiplied by alpha.
Definition: SkColor.h:385
float & operator[](int index)
Returns one component.
Definition: SkColor.h:334
float fA
alpha component
Definition: SkColor.h:266
bool isOpaque() const
Returns true if SkRGBA4f is an opaque color.
Definition: SkColor.h:344