SkColor Reference === # Color Types, consts, functions, and macros for colors. ## Overview
Topic Description
Defines preprocessor definitions of functions, values
Functions global and class member functions
Related Functions similar member functions grouped together
Typedef Declarations types defined by other types
## Define SkColor uses preprocessor definitions to inline code and constants, and to abstract platform-specific functionality.
Topic Description
SkColorGetA returns Alpha component
SkColorGetB returns blue component
SkColorGetG returns green component
SkColorGetR returns red component
SkColorSetRGB returns opaque Color
Color constants can be helpful to write code, documenting the meaning of values the represent transparency and color values. The use of Color constants is not required. ## Constant SkColor related constants are defined by enum, enum class, #define, const, and constexpr.
Topic Description
SK AlphaOPAQUE fully opaque SkAlpha
SK AlphaTRANSPARENT fully transparent SkAlpha
SK ColorBLACK black Color
SK ColorBLUE blue Color
SK ColorCYAN cyan Color
SK ColorDKGRAY dark gray Color
SK ColorGRAY gray Color
SK ColorGREEN green Color
SK ColorLTGRAY light gray Color
SK ColorMAGENTA magenta Color
SK ColorRED red Color
SK ColorTRANSPARENT transparent Color
SK ColorWHITE white Color
SK ColorYELLOW yellow Color
## Function
Topic Description
SkColorSetA returns Color with transparency
SkColorSetARGB returns Color Alpha and RGB combined
SkColorToHSV converts RGB to HSV
SkHSVToColor converts HSV with Alpha to RGB
SkHSVToColor(U8CPU alpha, const SkScalar hsv[3])
SkPreMultiplyARGB converts Unpremultiplied ARGB to Premultiplied PMColor
SkPreMultiplyColor converts Unpremultiplied Color to Premultiplied PMColor
SkRGBToHSV converts RGB to HSV
## Typedef SkColor typedef define a data type.
Topic Description
SkAlpha defines Alpha as eight bits
SkColor defines Color as 32 bits
SkPMColor defines Premultiplied Color as 32 bits
## Alpha Alpha represents the transparency of Color. Color with Alpha of zero is fully transparent. Color with Alpha of 255 is fully opaque. Some, but not all pixel formats contain Alpha. Pixels with Alpha may store it as unsigned integers or floating point values. Unsigned integer Alpha ranges from zero, fully transparent, to all bits set, fully opaque. Floating point Alpha ranges from zero, fully transparent, to one, fully opaque. ## Typedef SkAlpha
typedef uint8_t SkAlpha;
8-bit type for an alpha value. 255 is 100% opaque, zero is 100% transparent. ## Typedef SkColor
typedef uint32_t SkColor;
32-bit ARGB Color value, Unpremultiplied. Color components are always in a known order. This is different from SkPMColor, which has its bytes in a configuration dependent order, to match the format of kBGRA_8888_SkColorType bitmaps. SkColor is the type used to specify colors in SkPaint and in gradients. Color that is Premultiplied has the same component values as Color that is Unpremultiplied if Alpha is 255, fully opaque, although may have the component values in a different order. ### See Also SkPMColor ## SkColorSetARGB
static constexpr inline SkColor SkColorSetARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b)
Returns Color value from 8-bit component values. Asserts if SK_DEBUG is defined if a, r, g, or b exceed 255. Since Color is Unpremultiplied, a may be smaller than the largest of r, g, and b. ### Parameters
a amount of Alpha, from fully transparent (0) to fully opaque (255)
r amount of red, from no red (0) to full red (255)
g amount of green, from no green (0) to full green (255)
b amount of blue, from no blue (0) to full blue (255)
### Return Value color and alpha, Unpremultiplied ### Example
### See Also SkColorSetRGB SkPaint::setARGB SkPaint::setColor SkColorSetA --- ## Define SkColorSetRGB
    #define SkColorSetRGB(r, g, b)  SkColorSetARGB(0xFF, r, g, b)
Returns Color value from 8-bit component values, with Alpha set fully opaque to 255. ### Parameters
r amount of red, from no red (0) to full red (255)
g amount of green, from no green (0) to full green (255)
b amount of blue, from no blue (0) to full blue (255)
### Return Value color with opaque alpha ### Example
### See Also SkColorSetARGB ## Define SkColorGetA
    #define SkColorGetA(color)      (((color) >> 24) & 0xFF)
Returns Alpha byte from Color value. ### Parameters
color SkColor, a 32-bit unsigned int, in 0xAARRGGBB format
### Example
### See Also SkPaint::getAlpha ## Define SkColorGetR
    #define SkColorGetR(color)      (((color) >> 16) & 0xFF)
Returns red component of Color, from zero to 255. ### Parameters
color SkColor, a 32-bit unsigned int, in 0xAARRGGBB format
### Return Value red byte ### Example
### See Also SkColorGetG SkColorGetB ## Define SkColorGetG
    #define SkColorGetG(color)      (((color) >>  8) & 0xFF)
Returns green component of Color, from zero to 255. ### Parameters
color SkColor, a 32-bit unsigned int, in 0xAARRGGBB format
### Return Value green byte ### Example
### See Also SkColorGetR SkColorGetB ## Define SkColorGetB
    #define SkColorGetB(color)      (((color) >>  0) & 0xFF)
Returns blue component of Color, from zero to 255. ### Parameters
color SkColor, a 32-bit unsigned int, in 0xAARRGGBB format
### Return Value blue byte ### Example
### See Also SkColorGetR SkColorGetG ## SkColorSetA
static constexpr inline SkColor SkColorSetA(SkColor c, U8CPU a)
Returns Unpremultiplied Color with red, blue, and green set from c; and alpha set from a. Alpha component of c is ignored and is replaced by a in result. ### Parameters
c packed RGB, eight bits per component
a Alpha: transparent at zero, fully opaque at 255
### Return Value Color with transparency ### Example
### See Also SkColorSetARGB --- ## Alpha Constants ### Constants
Const Value Description
SK_AlphaTRANSPARENT 0x00 fully transparent SkAlpha
SK_AlphaOPAQUE 0xFF fully opaque SkAlpha
    constexpr SkAlpha SK AlphaTRANSPARENT = 0x00;
    constexpr SkAlpha SK AlphaOPAQUE      = 0xFF;
Alpha constants are conveniences to represent fully transparent and fully opaque colors and masks. Their use is not required. ### Constants
Const Value Details Description
SK_AlphaTRANSPARENT 0x00 Transparent  Represents fully transparent SkAlpha value. SkAlpha ranges from zero, fully transparent; to 255, fully opaque.
SK_AlphaOPAQUE 0xFF Opaque  Represents fully opaque SkAlpha value. SkAlpha ranges from zero, fully transparent; to 255, fully opaque.
## Alpha Constants Transparent ### Example
Color the parts of the bitmap red if they mostly contain transparent pixels.
### See Also SkAlpha SK ColorTRANSPARENT SK AlphaOPAQUE ## Alpha Constants Opaque ### Example
### See Also SkAlpha SK AlphaTRANSPARENT ## Color Constants ### Constants
Const Value Description
SK_ColorTRANSPARENT 0x00000000 transparent Color
SK_ColorBLACK 0xFF000000 black Color
SK_ColorDKGRAY 0xFF444444 dark gray Color
SK_ColorGRAY 0xFF888888 gray Color
SK_ColorLTGRAY 0xFFCCCCCC light gray Color
SK_ColorWHITE 0xFFFFFFFF white Color
SK_ColorRED 0xFFFF0000 red Color
SK_ColorGREEN 0xFF00FF00 green Color
SK_ColorBLUE 0xFF0000FF blue Color
SK_ColorYELLOW 0xFFFFFF00 yellow Color
SK_ColorCYAN 0xFF00FFFF cyan Color
SK_ColorMAGENTA 0xFFFF00FF magenta Color
    constexpr SkColor SK ColorTRANSPARENT = SkColorSetARGB(0x00, 0x00, 0x00, 0x00);
    constexpr SkColor SK ColorBLACK       = SkColorSetARGB(0xFF, 0x00, 0x00, 0x00);
    constexpr SkColor SK ColorDKGRAY      = SkColorSetARGB(0xFF, 0x44, 0x44, 0x44);
    constexpr SkColor SK ColorGRAY        = SkColorSetARGB(0xFF, 0x88, 0x88, 0x88);
    constexpr SkColor SK ColorLTGRAY      = SkColorSetARGB(0xFF, 0xCC, 0xCC, 0xCC);
    constexpr SkColor SK ColorWHITE       = SkColorSetARGB(0xFF, 0xFF, 0xFF, 0xFF);
    constexpr SkColor SK ColorRED         = SkColorSetARGB(0xFF, 0xFF, 0x00, 0x00);
    constexpr SkColor SK ColorGREEN       = SkColorSetARGB(0xFF, 0x00, 0xFF, 0x00);
    constexpr SkColor SK ColorBLUE        = SkColorSetARGB(0xFF, 0x00, 0x00, 0xFF);
    constexpr SkColor SK ColorYELLOW      = SkColorSetARGB(0xFF, 0xFF, 0xFF, 0x00);
    constexpr SkColor SK ColorCYAN        = SkColorSetARGB(0xFF, 0x00, 0xFF, 0xFF);
    constexpr SkColor SK ColorMAGENTA     = SkColorSetARGB(0xFF, 0xFF, 0x00, 0xFF);
Color names are provided as conveniences, but are not otherwise special. The values chosen for names may not be the same as values used by SVG, HTML, CSS, or colors named by a platform. ### Example
### Constants
Const Value Details Description
SK_ColorTRANSPARENT 0x00000000 Transparent  Represents fully transparent SkColor. May be used to initialize a destination containing a mask or a non-rectangular image.
SK_ColorBLACK 0xFF000000 Black  Represents fully opaque black.
SK_ColorDKGRAY 0xFF444444 Represents fully opaque dark gray. Note that SVG darkgray is equivalent to 0xFFA9A9A9.
SK_ColorGRAY 0xFF888888 Represents fully opaque gray. Note that HTML Gray is equivalent to 0xFF808080.
SK_ColorLTGRAY 0xFFCCCCCC Represents fully opaque light gray. HTML Silver is equivalent to 0xFFC0C0C0. Note that SVG lightgray is equivalent to 0xFFD3D3D3.
SK_ColorWHITE 0xFFFFFFFF Represents fully opaque white.
SK_ColorRED 0xFFFF0000 Represents fully opaque red.
SK_ColorGREEN 0xFF00FF00 Represents fully opaque green. HTML Lime is equivalent. Note that HTML Green is equivalent to 0xFF008000.
SK_ColorBLUE 0xFF0000FF Represents fully opaque blue.
SK_ColorYELLOW 0xFFFFFF00 Represents fully opaque yellow.
SK_ColorCYAN 0xFF00FFFF Represents fully opaque cyan. HTML Aqua is equivalent.
SK_ColorMAGENTA 0xFFFF00FF Represents fully opaque magenta. HTML Fuchsia is equivalent.
## Color Constants Transparent ### Example
### See Also SK AlphaTRANSPARENT SkCanvas::clear ## Color Constants Black ### Example
### See Also SK ColorTRANSPARENT ## Color Constants White ### Example
### See Also SK ColorTRANSPARENT ## HSV ## HSV Hue Hue represents an angle, in degrees, on a color wheel. Hue has a positive value modulo 360, where zero degrees is red. ## HSV Saturation Saturation represents the intensity of the color. Saturation varies from zero, with no Hue contribution; to one, with full Hue contribution. ## HSV Value Value represents the lightness of the color. Value varies from zero, black; to one, full brightness. ## SkRGBToHSV
void SkRGBToHSV(U8CPU red, U8CPU green, U8CPU blue, SkScalar hsv[3])
Converts RGB to its HSV components. hsv[0] contains HSV Hue, a value from zero to less than 360. hsv[1] contains HSV Saturation, a value from zero to one. hsv[2] contains HSV Value, a value from zero to one. ### Parameters
red red component value from zero to 255
green green component value from zero to 255
blue blue component value from zero to 255
hsv three element array which holds the resulting HSV components
### Example
### See Also SkColorToHSV SkHSVToColor --- ## SkColorToHSV
void SkColorToHSV(SkColor color, SkScalar hsv[3])
Converts ARGB to its HSV components. Alpha in ARGB is ignored. hsv[0] contains HSV Hue, and is assigned a value from zero to less than 360. hsv[1] contains HSV Saturation, a value from zero to one. hsv[2] contains HSV Value, a value from zero to one. ### Parameters
color ARGB color to convert
hsv three element array which holds the resulting HSV components
### Example
### See Also SkRGBToHSV SkHSVToColor --- ## SkHSVToColor
SkColor SkHSVToColor(U8CPU alpha, const SkScalar hsv[3])
Converts HSV components to an ARGB color. Alpha is passed through unchanged. hsv[0] represents HSV Hue, an angle from zero to less than 360. hsv[1] represents HSV Saturation, and varies from zero to one. hsv[2] represents HSV Value, and varies from zero to one. Out of range hsv values are pinned. ### Parameters
alpha Alpha component of the returned ARGB color
hsv three element array which holds the input HSV components
### Return Value ARGB equivalent to HSV ### Example
### See Also SkColorToHSV SkRGBToHSV ---
SkColor SkHSVToColor(const SkScalar hsv[3])
Converts HSV components to an ARGB color. Alpha is set to 255. hsv[0] represents HSV Hue, an angle from zero to less than 360. hsv[1] represents HSV Saturation, and varies from zero to one. hsv[2] represents HSV Value, and varies from zero to one. Out of range hsv values are pinned. ### Parameters
hsv three element array which holds the input HSV components
### Return Value RGB equivalent to HSV ### Example
### See Also SkColorToHSV SkRGBToHSV --- ## PMColor ## Typedef SkPMColor
typedef uint32_t SkPMColor;
32-bit ARGB color value, Premultiplied. The byte order for this value is configuration dependent, matching the format of kBGRA_8888_SkColorType bitmaps. This is different from SkColor, which is Unpremultiplied, and is always in the same byte order. ## SkPreMultiplyARGB
SkPMColor SkPreMultiplyARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b)
Returns a SkPMColor value from Unpremultiplied 8-bit component values. ### Parameters
a amount of Alpha, from fully transparent (0) to fully opaque (255)
r amount of red, from no red (0) to full red (255)
g amount of green, from no green (0) to full green (255)
b amount of blue, from no blue (0) to full blue (255)
### Return Value Premultiplied Color ### Example
### See Also SkPreMultiplyColor --- ## SkPreMultiplyColor
SkPMColor SkPreMultiplyColor(SkColor c)
Returns PMColor closest to Color c. Multiplies c RGB components by the c Alpha, and arranges the bytes to match the format of kN32_SkColorType. ### Parameters
c Unpremultiplied ARGB Color
### Return Value Premultiplied Color ### Example
### See Also SkPreMultiplyARGB ---