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

8-bit type for an alpha value. 255 is 100% opaque, zero is 100% transparent.

Typedef 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

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

Return Value

color and alpha, Unpremultiplied

Example

See Also

SkColorSetRGB SkPaint::setARGB SkPaint::setColor SkColorSetA


Define SkColorSetRGB

Returns Color value from 8-bit component values, with Alpha set fully opaque to 255.

Parameters

Return Value

color with opaque alpha

Example

See Also

SkColorSetARGB

Define SkColorGetA

Returns Alpha byte from Color value.

Parameters

Example

See Also

SkPaint::getAlpha

Define SkColorGetR

Returns red component of Color, from zero to 255.

Parameters

Return Value

red byte

Example

See Also

SkColorGetG SkColorGetB

Define SkColorGetG

Returns green component of Color, from zero to 255.

Parameters

Return Value

green byte

Example

See Also

SkColorGetR SkColorGetB

Define SkColorGetB

Returns blue component of Color, from zero to 255.

Parameters

Return Value

blue byte

Example

See Also

SkColorGetR SkColorGetG

SkColorSetA

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

Return Value

Color with transparency

Example

See Also

SkColorSetARGB


Alpha Constants

Constants

Alpha constants are conveniences to represent fully transparent and fully opaque colors and masks. Their use is not required.

Constants

Alpha Constants Transparent

Example

See Also

SkAlpha SK ColorTRANSPARENT SK AlphaOPAQUE

Alpha Constants Opaque

Example

See Also

SkAlpha SK AlphaTRANSPARENT

Color Constants

Constants

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

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

Example

See Also

SkColorToHSV SkHSVToColor


SkColorToHSV

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

Example

See Also

SkRGBToHSV SkHSVToColor


SkHSVToColor

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

Return Value

ARGB equivalent to HSV

Example

See Also

SkColorToHSV SkRGBToHSV


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

Return Value

RGB equivalent to HSV

Example

See Also

SkColorToHSV SkRGBToHSV


PMColor

Typedef 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

Returns a SkPMColor value from Unpremultiplied 8-bit component values.

Parameters

Return Value

Premultiplied Color

Example

See Also

SkPreMultiplyColor


SkPreMultiplyColor

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