Flutter Engine
The Flutter Engine
Functions
SkColor.cpp File Reference
#include "include/core/SkColor.h"
#include "include/core/SkColorPriv.h"
#include "include/private/SkColorData.h"
#include "include/private/base/SkTPin.h"
#include "src/base/SkVx.h"
#include "src/core/SkSwizzlePriv.h"
#include <algorithm>

Go to the source code of this file.

Functions

SkPMColor SkPreMultiplyARGB (U8CPU a, U8CPU r, U8CPU g, U8CPU b)
 
SkPMColor SkPreMultiplyColor (SkColor c)
 
static SkScalar ByteToScalar (U8CPU x)
 
static SkScalar ByteDivToScalar (int numer, U8CPU denom)
 
void SkRGBToHSV (U8CPU r, U8CPU g, U8CPU b, SkScalar hsv[3])
 
SkColor SkHSVToColor (U8CPU a, const SkScalar hsv[3])
 

Function Documentation

◆ ByteDivToScalar()

static SkScalar ByteDivToScalar ( int  numer,
U8CPU  denom 
)
inlinestatic

Definition at line 33 of file SkColor.cpp.

33 {
34 // cast to keep the answer signed
35 return SkIntToScalar(numer) / (int)denom;
36}
#define SkIntToScalar(x)
Definition: SkScalar.h:57

◆ ByteToScalar()

static SkScalar ByteToScalar ( U8CPU  x)
inlinestatic

Definition at line 28 of file SkColor.cpp.

28 {
29 SkASSERT(x <= 255);
30 return SkIntToScalar(x) / 255;
31}
#define SkASSERT(cond)
Definition: SkAssert.h:116
double x

◆ 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
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
static constexpr const T & SkTPin(const T &x, const T &lo, const T &hi)
Definition: SkTPin.h:19
float SkScalar
Definition: extension.cpp:12
static bool b
struct MyStruct s
struct MyStruct a[10]
SkScalar w

◆ SkPreMultiplyARGB()

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)
Definition: SkColorPriv.h:126

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

Definition at line 21 of file SkColor.cpp.

21 {
24}
#define SkColorGetR(color)
Definition: SkColor.h:65
#define SkColorGetG(color)
Definition: SkColor.h:69
#define SkColorGetA(color)
Definition: SkColor.h:61
#define SkColorGetB(color)
Definition: SkColor.h:73

◆ 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
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
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) {
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