Flutter Impeller
impeller::ColorHSB Struct Reference

#include <color.h>

Public Member Functions

constexpr ColorHSB (Scalar h, Scalar s, Scalar b, Scalar a)
 
Color ToRGBA () const
 

Static Public Member Functions

static ColorHSB FromRGB (Color rgb)
 

Public Attributes

Scalar hue
 
Scalar saturation
 
Scalar brightness
 
Scalar alpha
 

Detailed Description

Represents a color by its constituent hue, saturation, brightness and alpha

Definition at line 916 of file color.h.

Constructor & Destructor Documentation

◆ ColorHSB()

constexpr impeller::ColorHSB::ColorHSB ( Scalar  h,
Scalar  s,
Scalar  b,
Scalar  a 
)
inlineconstexpr

Definition at line 937 of file color.h.

938  : hue(h), saturation(s), brightness(b), alpha(a) {}

Referenced by FromRGB().

Member Function Documentation

◆ FromRGB()

ColorHSB impeller::ColorHSB::FromRGB ( Color  rgb)
static

Definition at line 52 of file color.cc.

52  {
53  Scalar R = rgb.red;
54  Scalar G = rgb.green;
55  Scalar B = rgb.blue;
56 
57  Scalar v = 0.0;
58  Scalar x = 0.0;
59  Scalar f = 0.0;
60 
61  int64_t i = 0;
62 
63  x = fmin(R, G);
64  x = fmin(x, B);
65 
66  v = fmax(R, G);
67  v = fmax(v, B);
68 
69  if (v == x) {
70  return ColorHSB(0.0, 0.0, v, rgb.alpha);
71  }
72 
73  f = (R == x) ? G - B : ((G == x) ? B - R : R - G);
74  i = (R == x) ? 3 : ((G == x) ? 5 : 1);
75 
76  return ColorHSB(((i - f / (v - x)) / 6.0), (v - x) / v, v, rgb.alpha);
77 }

References impeller::Color::alpha, impeller::Color::blue, ColorHSB(), impeller::Color::green, and impeller::Color::red.

◆ ToRGBA()

Color impeller::ColorHSB::ToRGBA ( ) const

Definition at line 79 of file color.cc.

79  {
80  Scalar h = hue * 6.0;
81  Scalar s = saturation;
82  Scalar v = brightness;
83 
84  Scalar m = 0.0;
85  Scalar n = 0.0;
86  Scalar f = 0.0;
87 
88  int64_t i = 0;
89 
90  if (h == 0) {
91  h = 0.01;
92  }
93 
94  if (h == 0.0) {
95  return Color(v, v, v, alpha);
96  }
97 
98  i = static_cast<int64_t>(floor(h));
99 
100  f = h - i;
101 
102  if (!(i & 1)) {
103  f = 1 - f;
104  }
105 
106  m = v * (1 - s);
107  n = v * (1 - s * f);
108 
109  switch (i) {
110  case 6:
111  case 0:
112  return Color(v, n, m, alpha);
113  case 1:
114  return Color(n, v, m, alpha);
115  case 2:
116  return Color(m, v, n, alpha);
117  case 3:
118  return Color(m, n, v, alpha);
119  case 4:
120  return Color(n, m, v, alpha);
121  case 5:
122  return Color(v, m, n, alpha);
123  }
124  return Color(0, 0, 0, alpha);
125 }

References alpha, brightness, hue, and saturation.

Member Data Documentation

◆ alpha

Scalar impeller::ColorHSB::alpha

The alpha of the color (0 to 1)

Definition at line 935 of file color.h.

Referenced by ToRGBA().

◆ brightness

Scalar impeller::ColorHSB::brightness

The brightness of the color (0 to 1)

Definition at line 930 of file color.h.

Referenced by ToRGBA().

◆ hue

Scalar impeller::ColorHSB::hue

The hue of the color (0 to 1)

Definition at line 920 of file color.h.

Referenced by ToRGBA().

◆ saturation

Scalar impeller::ColorHSB::saturation

The saturation of the color (0 to 1)

Definition at line 925 of file color.h.

Referenced by ToRGBA().


The documentation for this struct was generated from the following files:
impeller::Scalar
float Scalar
Definition: scalar.h:18
impeller::ColorHSB::brightness
Scalar brightness
Definition: color.h:930
impeller::ColorHSB::alpha
Scalar alpha
Definition: color.h:935
impeller::ColorHSB::saturation
Scalar saturation
Definition: color.h:925
impeller::ColorHSB::ColorHSB
constexpr ColorHSB(Scalar h, Scalar s, Scalar b, Scalar a)
Definition: color.h:937
impeller::saturated::b
SI b
Definition: saturated_math.h:87
impeller::ColorHSB::hue
Scalar hue
Definition: color.h:920