Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Namespaces | Macros | Typedefs | Enumerations | Functions | Variables
SkColor.h File Reference
#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>

Go to the source code of this file.

Classes

struct  SkRGBA4f< kAT >
 

Namespaces

namespace  SkColors
 

Macros

#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)
 

Typedefs

typedef uint8_t SkAlpha
 
typedef uint32_t SkColor
 
typedef uint32_t SkPMColor
 
using SkColor4f = SkRGBA4f< kUnpremul_SkAlphaType >
 

Enumerations

enum class  SkColorChannel {
  kR , kG , kB , kA ,
  kLastEnum = kA
}
 
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
}
 

Functions

static constexpr SkColor SkColorSetARGB (U8CPU a, U8CPU r, U8CPU g, U8CPU b)
 
static constexpr SkColor SkColorSetA (SkColor c, U8CPU a)
 
SK_API void SkRGBToHSV (U8CPU red, U8CPU green, U8CPU blue, SkScalar hsv[3])
 
static void SkColorToHSV (SkColor color, SkScalar hsv[3])
 
SK_API SkColor SkHSVToColor (U8CPU alpha, const SkScalar hsv[3])
 
static SkColor SkHSVToColor (const SkScalar hsv[3])
 
SK_API SkPMColor SkPreMultiplyARGB (U8CPU a, U8CPU r, U8CPU g, U8CPU b)
 
SK_API SkPMColor SkPreMultiplyColor (SkColor c)
 

Variables

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

Definition in file SkColor.h.

Macro Definition Documentation

◆ SkColorGetA

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

Returns alpha byte from color value.

Definition at line 61 of file SkColor.h.

◆ SkColorGetB

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

Returns blue component of color, from zero to 255.

Definition at line 73 of file SkColor.h.

◆ SkColorGetG

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

Returns green component of color, from zero to 255.

Definition at line 69 of file SkColor.h.

◆ SkColorGetR

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

Returns red component of color, from zero to 255.

Definition at line 65 of file SkColor.h.

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

Definition at line 57 of file SkColor.h.

Typedef Documentation

◆ SkAlpha

typedef uint8_t SkAlpha

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

Definition at line 26 of file SkColor.h.

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

Definition at line 37 of file SkColor.h.

◆ SkColor4f

Definition at line 426 of file SkColor.h.

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

Definition at line 205 of file SkColor.h.

Enumeration Type Documentation

◆ SkColorChannel

enum class SkColorChannel
strong

Describes different color channels one can manipulate

Enumerator
kR 
kG 
kB 
kA 
kLastEnum 

Definition at line 228 of file SkColor.h.

228 {
229 kR, // the red channel
230 kG, // the green channel
231 kB, // the blue channel
232 kA, // the alpha channel
233
234 kLastEnum = kA,
235};

◆ 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 

Definition at line 238 of file SkColor.h.

238 : uint32_t {
239 kRed_SkColorChannelFlag = 1 << static_cast<uint32_t>(SkColorChannel::kR),
240 kGreen_SkColorChannelFlag = 1 << static_cast<uint32_t>(SkColorChannel::kG),
241 kBlue_SkColorChannelFlag = 1 << static_cast<uint32_t>(SkColorChannel::kB),
242 kAlpha_SkColorChannelFlag = 1 << static_cast<uint32_t>(SkColorChannel::kA),
244 // Convenience values
249};
@ kRGB_SkColorChannelFlags
Definition SkColor.h:247
@ kRGBA_SkColorChannelFlags
Definition SkColor.h:248
@ kRed_SkColorChannelFlag
Definition SkColor.h:239
@ kGrayAlpha_SkColorChannelFlags
Definition SkColor.h:245
@ kRG_SkColorChannelFlags
Definition SkColor.h:246
@ kGreen_SkColorChannelFlag
Definition SkColor.h:240
@ kAlpha_SkColorChannelFlag
Definition SkColor.h:242
@ kGray_SkColorChannelFlag
Definition SkColor.h:243
@ kBlue_SkColorChannelFlag
Definition SkColor.h:241

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

Definition at line 82 of file SkColor.h.

82 {
83 return (c & 0x00FFFFFF) | (a << 24);
84}
struct MyStruct a[10]

◆ 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

Definition at line 49 of file SkColor.h.

49 {
50 return SkASSERT(a <= 255 && r <= 255 && g <= 255 && b <= 255),
51 (a << 24) | (r << 16) | (g << 8) | (b << 0);
52}
#define SkASSERT(cond)
Definition SkAssert.h:116
static bool b

◆ 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

Definition at line 169 of file SkColor.h.

169 {
171}
SkColor4f color
#define SkColorGetR(color)
Definition SkColor.h:65
#define SkColorGetG(color)
Definition SkColor.h:69
SK_API void SkRGBToHSV(U8CPU red, U8CPU green, U8CPU blue, SkScalar hsv[3])
Definition SkColor.cpp:38
#define SkColorGetB(color)
Definition SkColor.h:73

◆ 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

Definition at line 196 of file SkColor.h.

196 {
197 return SkHSVToColor(0xFF, hsv);
198}
SK_API SkColor SkHSVToColor(U8CPU alpha, const SkScalar hsv[3])
Definition SkColor.cpp:78

◆ 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

Definition at line 78 of file SkColor.cpp.

78 {
79 SkASSERT(hsv);
80
81 SkScalar s = SkTPin(hsv[1], 0.0f, 1.0f);
82 SkScalar v = SkTPin(hsv[2], 0.0f, 1.0f);
83
84 U8CPU v_byte = SkScalarRoundToInt(v * 255);
85
86 if (SkScalarNearlyZero(s)) { // shade of gray
87 return SkColorSetARGB(a, v_byte, v_byte, v_byte);
88 }
89 SkScalar hx = (hsv[0] < 0 || hsv[0] >= SkIntToScalar(360)) ? 0 : hsv[0]/60;
91 SkScalar f = hx - w;
92
93 unsigned p = SkScalarRoundToInt((SK_Scalar1 - s) * v * 255);
94 unsigned q = SkScalarRoundToInt((SK_Scalar1 - (s * f)) * v * 255);
95 unsigned t = SkScalarRoundToInt((SK_Scalar1 - (s * (SK_Scalar1 - f))) * v * 255);
96
97 unsigned r, g, b;
98
99 SkASSERT((unsigned)(w) < 6);
100 switch ((unsigned)(w)) {
101 case 0: r = v_byte; g = t; b = p; break;
102 case 1: r = q; g = v_byte; b = p; break;
103 case 2: r = p; g = v_byte; b = t; break;
104 case 3: r = p; g = q; b = v_byte; break;
105 case 4: r = t; g = p; b = v_byte; break;
106 default: r = v_byte; g = p; b = q; break;
107 }
108 return SkColorSetARGB(a, r, g, b);
109}
unsigned U8CPU
Definition SkCPUTypes.h:18
static constexpr SkColor SkColorSetARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b)
Definition SkColor.h:49
#define SkScalarFloorToScalar(x)
Definition SkScalar.h:30
static bool SkScalarNearlyZero(SkScalar x, SkScalar tolerance=SK_ScalarNearlyZero)
Definition SkScalar.h:101
#define SK_Scalar1
Definition SkScalar.h:18
#define SkScalarRoundToInt(x)
Definition SkScalar.h:37
#define SkIntToScalar(x)
Definition SkScalar.h:57
static constexpr const T & SkTPin(const T &x, const T &lo, const T &hi)
Definition SkTPin.h:19
float SkScalar
Definition extension.cpp:12
struct MyStruct s
SkScalar w

◆ 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

Definition at line 17 of file SkColor.cpp.

17 {
18 return SkPremultiplyARGBInline(a, r, g, b);
19}
static SkPMColor SkPremultiplyARGBInline(U8CPU a, U8CPU r, U8CPU g, U8CPU b)

◆ 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

Definition at line 21 of file SkColor.cpp.

21 {
24}
#define SkColorGetA(color)
Definition SkColor.h:61

◆ 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

Definition at line 38 of file SkColor.cpp.

38 {
39 SkASSERT(hsv);
40
41 unsigned min = std::min(r, std::min(g, b));
42 unsigned max = std::max(r, std::max(g, b));
43 unsigned delta = max - min;
44
46 SkASSERT(v >= 0 && v <= SK_Scalar1);
47
48 if (0 == delta) { // we're a shade of gray
49 hsv[0] = 0;
50 hsv[1] = 0;
51 hsv[2] = v;
52 return;
53 }
54
55 SkScalar s = ByteDivToScalar(delta, max);
56 SkASSERT(s >= 0 && s <= SK_Scalar1);
57
58 SkScalar h;
59 if (r == max) {
60 h = ByteDivToScalar(g - b, delta);
61 } else if (g == max) {
62 h = SkIntToScalar(2) + ByteDivToScalar(b - r, delta);
63 } else { // b == max
64 h = SkIntToScalar(4) + ByteDivToScalar(r - g, delta);
65 }
66
67 h *= 60;
68 if (h < 0) {
69 h += SkIntToScalar(360);
70 }
71 SkASSERT(h >= 0 && h < SkIntToScalar(360));
72
73 hsv[0] = h;
74 hsv[1] = s;
75 hsv[2] = v;
76}
static SkScalar ByteDivToScalar(int numer, U8CPU denom)
Definition SkColor.cpp:33
static SkScalar ByteToScalar(U8CPU x)
Definition SkColor.cpp:28
static float max(float r, float g, float b)
Definition hsl.cpp:49
static float min(float r, float g, float b)
Definition hsl.cpp:48
SkScalar h

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.

Definition at line 94 of file SkColor.h.

◆ SK_AlphaTRANSPARENT

constexpr SkAlpha SK_AlphaTRANSPARENT = 0x00
constexpr

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

Definition at line 89 of file SkColor.h.

◆ SK_ColorBLACK

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

Represents fully opaque black.

Definition at line 103 of file SkColor.h.

◆ SK_ColorBLUE

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

Represents fully opaque blue.

Definition at line 135 of file SkColor.h.

◆ SK_ColorCYAN

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

Represents fully opaque cyan. HTML aqua is equivalent.

Definition at line 143 of file SkColor.h.

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

Definition at line 108 of file SkColor.h.

◆ SK_ColorGRAY

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

Represents fully opaque gray. Note that HTML gray is equivalent to 0xFF808080.

Definition at line 113 of file SkColor.h.

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

Definition at line 131 of file SkColor.h.

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

Definition at line 118 of file SkColor.h.

◆ SK_ColorMAGENTA

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

Represents fully opaque magenta. HTML fuchsia is equivalent.

Definition at line 147 of file SkColor.h.

◆ SK_ColorRED

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

Represents fully opaque red.

Definition at line 126 of file SkColor.h.

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

Definition at line 99 of file SkColor.h.

◆ SK_ColorWHITE

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

Represents fully opaque white.

Definition at line 122 of file SkColor.h.

◆ SK_ColorYELLOW

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

Represents fully opaque yellow.

Definition at line 139 of file SkColor.h.