Skia
2D Graphics Library
SkColor.h File Reference

Types, consts, functions, and macros for colors. More...

#include "include/core/SkAlphaType.h"
#include "include/core/SkScalar.h"
#include "include/core/SkTypes.h"
#include "include/private/base/SkCPUTypes.h"
#include <array>
#include <cstdint>
Include dependency graph for SkColor.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  SkRGBA4f< kAT >
 RGBA color value, holding four floating point components. More...
 

Namespaces

 SkColors
 

Macros

#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. More...
 
#define SkColorGetA(color)   (((color) >> 24) & 0xFF)
 Returns alpha byte from color value. More...
 
#define SkColorGetR(color)   (((color) >> 16) & 0xFF)
 Returns red component of color, from zero to 255. More...
 
#define SkColorGetG(color)   (((color) >> 8) & 0xFF)
 Returns green component of color, from zero to 255. More...
 
#define SkColorGetB(color)   (((color) >> 0) & 0xFF)
 Returns blue component of color, from zero to 255. More...
 

Typedefs

typedef uint8_t SkAlpha
 8-bit type for an alpha value. More...
 
typedef uint32_t SkColor
 32-bit ARGB color value, unpremultiplied. More...
 
typedef uint32_t SkPMColor
 32-bit ARGB color value, premultiplied. More...
 
using SkColor4f = SkRGBA4f< kUnpremul_SkAlphaType >
 

Enumerations

enum class  SkColorChannel {
  kR , kG , kB , kA ,
  kLastEnum = kA
}
 Describes different color channels one can manipulate. More...
 
enum  SkColorChannelFlag : uint32_t {
  kRed_SkColorChannelFlag = 1 << static_cast<uint32_t>(SkColorChannel::kR) , kGreen_SkColorChannelFlag = 1 << static_cast<uint32_t>(SkColorChannel::kG) , kBlue_SkColorChannelFlag = 1 << static_cast<uint32_t>(SkColorChannel::kB) , kAlpha_SkColorChannelFlag = 1 << static_cast<uint32_t>(SkColorChannel::kA) ,
  kGray_SkColorChannelFlag = 0x10 , kGrayAlpha_SkColorChannelFlags = kGray_SkColorChannelFlag | kAlpha_SkColorChannelFlag , kRG_SkColorChannelFlags = kRed_SkColorChannelFlag | kGreen_SkColorChannelFlag , kRGB_SkColorChannelFlags = kRG_SkColorChannelFlags | kBlue_SkColorChannelFlag ,
  kRGBA_SkColorChannelFlags = kRGB_SkColorChannelFlags | kAlpha_SkColorChannelFlag
}
 Used to represent the channels available in a color type or texture format as a mask. More...
 

Functions

static constexpr SkColor SkColorSetARGB (U8CPU a, U8CPU r, U8CPU g, U8CPU b)
 Returns color value from 8-bit component values. More...
 
static constexpr SkColor SkColorSetA (SkColor c, U8CPU a)
 Returns unpremultiplied color with red, blue, and green set from c; and alpha set from a. More...
 
SK_API void SkRGBToHSV (U8CPU red, U8CPU green, U8CPU blue, SkScalar hsv[3])
 Converts RGB to its HSV components. More...
 
static void SkColorToHSV (SkColor color, SkScalar hsv[3])
 Converts ARGB to its HSV components. More...
 
SK_API SkColor SkHSVToColor (U8CPU alpha, const SkScalar hsv[3])
 Converts HSV components to an ARGB color. More...
 
static SkColor SkHSVToColor (const SkScalar hsv[3])
 Converts HSV components to an ARGB color. More...
 
SK_API SkPMColor SkPreMultiplyARGB (U8CPU a, U8CPU r, U8CPU g, U8CPU b)
 Returns a SkPMColor value from unpremultiplied 8-bit component values. More...
 
SK_API SkPMColor SkPreMultiplyColor (SkColor c)
 Returns pmcolor closest to color c. More...
 

Variables

constexpr SkAlpha SK_AlphaTRANSPARENT = 0x00
 Represents fully transparent SkAlpha value. More...
 
constexpr SkAlpha SK_AlphaOPAQUE = 0xFF
 Represents fully opaque SkAlpha value. More...
 
constexpr SkColor SK_ColorTRANSPARENT = SkColorSetARGB(0x00, 0x00, 0x00, 0x00)
 Represents fully transparent SkColor. More...
 
constexpr SkColor SK_ColorBLACK = SkColorSetARGB(0xFF, 0x00, 0x00, 0x00)
 Represents fully opaque black. More...
 
constexpr SkColor SK_ColorDKGRAY = SkColorSetARGB(0xFF, 0x44, 0x44, 0x44)
 Represents fully opaque dark gray. More...
 
constexpr SkColor SK_ColorGRAY = SkColorSetARGB(0xFF, 0x88, 0x88, 0x88)
 Represents fully opaque gray. More...
 
constexpr SkColor SK_ColorLTGRAY = SkColorSetARGB(0xFF, 0xCC, 0xCC, 0xCC)
 Represents fully opaque light gray. More...
 
constexpr SkColor SK_ColorWHITE = SkColorSetARGB(0xFF, 0xFF, 0xFF, 0xFF)
 Represents fully opaque white. More...
 
constexpr SkColor SK_ColorRED = SkColorSetARGB(0xFF, 0xFF, 0x00, 0x00)
 Represents fully opaque red. More...
 
constexpr SkColor SK_ColorGREEN = SkColorSetARGB(0xFF, 0x00, 0xFF, 0x00)
 Represents fully opaque green. More...
 
constexpr SkColor SK_ColorBLUE = SkColorSetARGB(0xFF, 0x00, 0x00, 0xFF)
 Represents fully opaque blue. More...
 
constexpr SkColor SK_ColorYELLOW = SkColorSetARGB(0xFF, 0xFF, 0xFF, 0x00)
 Represents fully opaque yellow. More...
 
constexpr SkColor SK_ColorCYAN = SkColorSetARGB(0xFF, 0x00, 0xFF, 0xFF)
 Represents fully opaque cyan. More...
 
constexpr SkColor SK_ColorMAGENTA = SkColorSetARGB(0xFF, 0xFF, 0x00, 0xFF)
 Represents fully opaque magenta. More...
 
constexpr SkColor4f SkColors::kTransparent = {0, 0, 0, 0}
 
constexpr SkColor4f SkColors::kBlack = {0, 0, 0, 1}
 
constexpr SkColor4f SkColors::kDkGray = {0.25f, 0.25f, 0.25f, 1}
 
constexpr SkColor4f SkColors::kGray = {0.50f, 0.50f, 0.50f, 1}
 
constexpr SkColor4f SkColors::kLtGray = {0.75f, 0.75f, 0.75f, 1}
 
constexpr SkColor4f SkColors::kWhite = {1, 1, 1, 1}
 
constexpr SkColor4f SkColors::kRed = {1, 0, 0, 1}
 
constexpr SkColor4f SkColors::kGreen = {0, 1, 0, 1}
 
constexpr SkColor4f SkColors::kBlue = {0, 0, 1, 1}
 
constexpr SkColor4f SkColors::kYellow = {1, 1, 0, 1}
 
constexpr SkColor4f SkColors::kCyan = {0, 1, 1, 1}
 
constexpr SkColor4f SkColors::kMagenta = {1, 0, 1, 1}
 

Detailed Description

Types, consts, functions, and macros for colors.

Macro Definition Documentation

◆ SkColorGetA

#define SkColorGetA (   color)    (((color) >> 24) & 0xFF)

Returns alpha byte from color value.

◆ SkColorGetB

#define SkColorGetB (   color)    (((color) >> 0) & 0xFF)

Returns blue component of color, from zero to 255.

◆ SkColorGetG

#define SkColorGetG (   color)    (((color) >> 8) & 0xFF)

Returns green component of color, from zero to 255.

◆ SkColorGetR

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

Returns red component of color, from zero to 255.

◆ SkColorSetRGB

#define SkColorSetRGB (   r,
  g,
 
)    SkColorSetARGB(0xFF, r, g, b)

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

Typedef Documentation

◆ SkAlpha

typedef uint8_t SkAlpha

8-bit type for an alpha value.

255 is 100% opaque, zero is 100% transparent.

◆ 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.

◆ SkColor4f

◆ 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.

Enumeration Type Documentation

◆ SkColorChannel

enum SkColorChannel
strong

Describes different color channels one can manipulate.

Enumerator
kR 
kG 
kB 
kA 
kLastEnum 

◆ SkColorChannelFlag

enum SkColorChannelFlag : uint32_t

Used to represent the channels available in a color type or texture format as a mask.

Enumerator
kRed_SkColorChannelFlag 
kGreen_SkColorChannelFlag 
kBlue_SkColorChannelFlag 
kAlpha_SkColorChannelFlag 
kGray_SkColorChannelFlag 
kGrayAlpha_SkColorChannelFlags 
kRG_SkColorChannelFlags 
kRGB_SkColorChannelFlags 
kRGBA_SkColorChannelFlags 

Function Documentation

◆ SkColorSetA()

static constexpr SkColor SkColorSetA ( SkColor  c,
U8CPU  a 
)
inlinestaticconstexpr

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
cpacked RGB, eight bits per component
aalpha: transparent at zero, fully opaque at 255
Returns
color with transparency

◆ SkColorSetARGB()

static constexpr SkColor SkColorSetARGB ( U8CPU  a,
U8CPU  r,
U8CPU  g,
U8CPU  b 
)
inlinestaticconstexpr

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
aamount of alpha, from fully transparent (0) to fully opaque (255)
ramount of red, from no red (0) to full red (255)
gamount of green, from no green (0) to full green (255)
bamount of blue, from no blue (0) to full blue (255)
Returns
color and alpha, unpremultiplied

◆ SkColorToHSV()

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

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
colorARGB color to convert
hsvthree element array which holds the resulting HSV components

◆ SkHSVToColor() [1/2]

static SkColor SkHSVToColor ( const SkScalar  hsv[3])
inlinestatic

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
hsvthree element array which holds the input HSV components
Returns
RGB equivalent to HSV

◆ SkHSVToColor() [2/2]

SK_API 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
alphaalpha component of the returned ARGB color
hsvthree element array which holds the input HSV components
Returns
ARGB equivalent to HSV

◆ SkPreMultiplyARGB()

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

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

Parameters
aamount of alpha, from fully transparent (0) to fully opaque (255)
ramount of red, from no red (0) to full red (255)
gamount of green, from no green (0) to full green (255)
bamount of blue, from no blue (0) to full blue (255)
Returns
premultiplied color

◆ SkPreMultiplyColor()

SK_API 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
cunpremultiplied ARGB color
Returns
premultiplied color

◆ SkRGBToHSV()

SK_API 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
redred component value from zero to 255
greengreen component value from zero to 255
blueblue component value from zero to 255
hsvthree element array which holds the resulting HSV components

Variable Documentation

◆ SK_AlphaOPAQUE

constexpr SkAlpha SK_AlphaOPAQUE = 0xFF
constexpr

Represents fully opaque SkAlpha value.

SkAlpha ranges from zero, fully transparent; to 255, fully opaque.

◆ SK_AlphaTRANSPARENT

constexpr SkAlpha SK_AlphaTRANSPARENT = 0x00
constexpr

Represents fully transparent SkAlpha value.

SkAlpha ranges from zero, fully transparent; to 255, fully opaque.

◆ SK_ColorBLACK

constexpr SkColor SK_ColorBLACK = SkColorSetARGB(0xFF, 0x00, 0x00, 0x00)
constexpr

Represents fully opaque black.

◆ SK_ColorBLUE

constexpr SkColor SK_ColorBLUE = SkColorSetARGB(0xFF, 0x00, 0x00, 0xFF)
constexpr

Represents fully opaque blue.

◆ SK_ColorCYAN

constexpr SkColor SK_ColorCYAN = SkColorSetARGB(0xFF, 0x00, 0xFF, 0xFF)
constexpr

Represents fully opaque cyan.

HTML aqua is equivalent.

◆ SK_ColorDKGRAY

constexpr SkColor SK_ColorDKGRAY = SkColorSetARGB(0xFF, 0x44, 0x44, 0x44)
constexpr

Represents fully opaque dark gray.

Note that SVG dark gray is equivalent to 0xFFA9A9A9.

◆ SK_ColorGRAY

constexpr SkColor SK_ColorGRAY = SkColorSetARGB(0xFF, 0x88, 0x88, 0x88)
constexpr

Represents fully opaque gray.

Note that HTML gray is equivalent to 0xFF808080.

◆ SK_ColorGREEN

constexpr SkColor SK_ColorGREEN = SkColorSetARGB(0xFF, 0x00, 0xFF, 0x00)
constexpr

Represents fully opaque green.

HTML lime is equivalent. Note that HTML green is equivalent to 0xFF008000.

◆ SK_ColorLTGRAY

constexpr SkColor SK_ColorLTGRAY = SkColorSetARGB(0xFF, 0xCC, 0xCC, 0xCC)
constexpr

Represents fully opaque light gray.

HTML silver is equivalent to 0xFFC0C0C0. Note that SVG light gray is equivalent to 0xFFD3D3D3.

◆ SK_ColorMAGENTA

constexpr SkColor SK_ColorMAGENTA = SkColorSetARGB(0xFF, 0xFF, 0x00, 0xFF)
constexpr

Represents fully opaque magenta.

HTML fuchsia is equivalent.

◆ SK_ColorRED

constexpr SkColor SK_ColorRED = SkColorSetARGB(0xFF, 0xFF, 0x00, 0x00)
constexpr

Represents fully opaque red.

◆ SK_ColorTRANSPARENT

constexpr SkColor SK_ColorTRANSPARENT = SkColorSetARGB(0x00, 0x00, 0x00, 0x00)
constexpr

Represents fully transparent SkColor.

May be used to initialize a destination containing a mask or a non-rectangular image.

◆ SK_ColorWHITE

constexpr SkColor SK_ColorWHITE = SkColorSetARGB(0xFF, 0xFF, 0xFF, 0xFF)
constexpr

Represents fully opaque white.

◆ SK_ColorYELLOW

constexpr SkColor SK_ColorYELLOW = SkColorSetARGB(0xFF, 0xFF, 0xFF, 0x00)
constexpr

Represents fully opaque yellow.