Community Issues Reference Playground

SkColor Reference

typedef uint8_t SkAlpha;
typedef uint32_t SkColor;

static constexpr SkColor SkColorSetARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b);
#define SkColorSetRGB(r, g, b) SkColorSetARGB(0xFF, r, g, b)
#define SkColorGetA(color) (((color) >> 24) & 0xFF)
#define SkColorGetR(color) (((color) >> 16) & 0xFF)
#define SkColorGetG(color) (((color) >> 8) & 0xFF)
#define SkColorGetB(color) (((color) >> 0) & 0xFF)

static constexpr SkColor SkColorSetA(SkColor c, U8CPU a);
constexpr SkAlpha SK_AlphaTRANSPARENT = 0x00;
constexpr SkAlpha SK_AlphaOPAQUE = 0xFF;
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);

void SkRGBToHSV(U8CPU red, U8CPU green, U8CPU blue, SkScalar hsv[3]);

static void SkColorToHSV(SkColor color, SkScalar hsv[3]);

SkColor SkHSVToColor(U8CPU alpha, const SkScalar hsv[3]);

static SkColor SkHSVToColor(const SkScalar hsv[3]);
typedef uint32_t SkPMColor;

SkPMColor SkPreMultiplyARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b);

SkPMColor SkPreMultiplyColor(SkColor c);
template <SkAlphaType kAT>
struct SkRGBA4f {
    // SkRGBA4f interface
};
template <> SkColor4f SkColor4f::FromColor(SkColor);
template <> SkColor SkColor4f::toSkColor() const;

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.

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 uint8_t SkAlpha;

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


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


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(r, g, b) SkColorSetARGB(0xFF, r, g, b)
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(color) (((color) >> 24) & 0xFF)
color

Returns Alpha byte from Color value.

Parameters

color SkColor, a 32-bit unsigned int, in 0xAARRGGBB format

Example

See Also

SkPaint::getAlpha


#define SkColorGetR(color) (((color) >> 16) & 0xFF)
color

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(color) (((color) >> 8) & 0xFF)
color

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(color) (((color) >> 0) & 0xFF)
color

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


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


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 Description
SK_AlphaTRANSPARENT 0x00 Represents fully transparent SkAlpha value. SkAlpha ranges from zero, fully transparent; to 255, fully opaque.
SK_AlphaOPAQUE 0xFF Represents fully opaque SkAlpha value. SkAlpha ranges from zero, fully transparent; to 255, fully opaque.

Example

Color the parts of the bitmap red if they mostly contain transparent pixels.

Example

Color the parts of the bitmap green if they contain fully opaque pixels.

See Also

SkAlpha SK_ColorTRANSPARENT SK_ColorBLACK


constexpr SkColor SK_ColorTRANSPARENT;
constexpr SkColor SK_ColorBLACK;
constexpr SkColor SK_ColorDKGRAY;
constexpr SkColor SK_ColorGRAY;
constexpr SkColor SK_ColorLTGRAY;
constexpr SkColor SK_ColorWHITE;
constexpr SkColor SK_ColorRED;
constexpr SkColor SK_ColorGREEN;
constexpr SkColor SK_ColorBLUE;
constexpr SkColor SK_ColorYELLOW;
constexpr SkColor SK_ColorCYAN;
constexpr SkColor SK_ColorMAGENTA;

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.

Constants

Const Value Description
SK_ColorTRANSPARENT 0x00000000 Represents fully transparent SkColor. May be used to initialize a destination containing a mask or a non-rectangular image.
SK_ColorBLACK 0xFF000000 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.

Example

Example

SK_ColorTRANSPARENT sets Color Alpha and components to zero.

Example

SK_ColorBLACK sets Color Alpha to one and components to zero.

Example

SK_ColorWHITE sets Color Alpha and components to one.

See Also

SK_ColorTRANSPARENT SkCanvas::clear SK_AlphaOPAQUE

Hue represents an angle, in degrees, on a color wheel. Hue has a positive value modulo 360, where zero degrees is red.

Saturation represents the intensity of the color. Saturation varies from zero, with no Hue contribution; to one, with full Hue contribution.

Value represents the lightness of the color. Value varies from zero, black; to one, full brightness.


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


static 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


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


static 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


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.


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


SkPMColor SkPreMultiplyColor(SkColor c)

Returns PM_Color 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