SkColor Reference
===
# Color
Types, consts, functions, and macros for colors.
## Overview
## Define
SkColor uses preprocessor definitions to inline code and constants, and to abstract platform-specific functionality.
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
.
## Function
## Typedef
SkColor typedef
define a data type.
## 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
### Example
### See Also
SkPaint::getAlpha
## Define SkColorGetR
#define SkColorGetR(color) (((color) >> 16) & 0xFF)
Returns red component of Color, from zero to 255.
### Parameters
### 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
### 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
### 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
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
## 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
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
## 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
### Return Value
Premultiplied Color
### Example
### See Also
SkPreMultiplyARGB
---