28 template <color_space ColorSpace,
typename BaseComponent,
typename ViewComponent,
typename Derived>
34 template <color_space ColorSpace,
typename BaseComponent,
typename ViewComponent,
typename Derived>
40 template <color_space ColorSpace,
typename BaseComponent,
typename ViewComponent,
typename Derived>
43 return (red() << RedShift) | (green() << GreenShift) | (blue() << BlueShift) | (alpha() << AlphaShift);
46 template <color_space ColorSpace,
typename BaseComponent,
typename ViewComponent,
typename Derived>
52 template <color_space ColorSpace,
typename BaseComponent,
typename ViewComponent,
typename Derived>
58 template <color_space ColorSpace,
typename BaseComponent,
typename ViewComponent,
typename Derived>
61 return (red<double>() + green<double>() + blue<double>()) / 3.0;
64 template <color_space ColorSpace,
typename BaseComponent,
typename ViewComponent,
typename Derived>
67 return std::abs(intensity() - aOther.
intensity()) <= aThreshold;
70 template <color_space ColorSpace,
typename BaseComponent,
typename ViewComponent,
typename Derived>
74 (self_type::template red<double>() + aOther.template red<double>()) / 2.0,
75 (self_type::template green<double>() + aOther.template green<double>()) / 2.0,
76 (self_type::template blue<double>() + aOther.template blue<double>()) / 2.0,
77 (base_type::template alpha<double>() + aOther.template alpha<double>()) / 2.0 };
80 template <color_space ColorSpace,
typename BaseComponent,
typename ViewComponent,
typename Derived>
81 inline typename basic_rgb_color<ColorSpace, BaseComponent, ViewComponent, Derived>::return_type basic_rgb_color<ColorSpace, BaseComponent, ViewComponent, Derived>::mix(
const basic_rgb_color<ColorSpace, BaseComponent, ViewComponent, Derived>& aOther,
scalar aValue)
const
84 (self_type::template red<double>() * (1 - aValue) + aOther.template red<double>() * aValue),
85 (self_type::template green<double>() * (1 - aValue) + aOther.template green<double>() * aValue),
86 (self_type::template blue<double>() * (1 - aValue) + aOther.template blue<double>() * aValue),
87 (base_type::template alpha<double>() * (1 - aValue) + aOther.template alpha<double>() * aValue) };
90 template <color_space ColorSpace,
typename BaseComponent,
typename ViewComponent,
typename Derived>
93 return to_hsl().lightness() >= aThreshold;
96 template <color_space ColorSpace,
typename BaseComponent,
typename ViewComponent,
typename Derived>
99 return to_hsl().lightness() < aThreshold;
102 template <color_space ColorSpace,
typename BaseComponent,
typename ViewComponent,
typename Derived>
109 template <color_space ColorSpace,
typename BaseComponent,
typename ViewComponent,
typename Derived>
116 template <color_space ColorSpace,
typename BaseComponent,
typename ViewComponent,
typename Derived>
124 template <color_space ColorSpace,
typename BaseComponent,
typename ViewComponent,
typename Derived>
132 template <color_space ColorSpace,
typename BaseComponent,
typename ViewComponent,
typename Derived>
136 return darken(aDelta);
138 return lighten(aDelta);
141 template <color_space ColorSpace,
typename BaseComponent,
typename ViewComponent,
typename Derived>
145 return lighten(aDelta);
147 return darken(aDelta);
150 template <color_space ColorSpace,
typename BaseComponent,
typename ViewComponent,
typename Derived>
154 return darker(aDelta);
156 return lighter(aDelta);
159 template <color_space ColorSpace,
typename BaseComponent,
typename ViewComponent,
typename Derived>
163 return lighter(aDelta);
165 return darker(aDelta);
168 template <color_space ColorSpace,
typename BaseComponent,
typename ViewComponent,
typename Derived>
175 template <color_space ColorSpace,
typename BaseComponent,
typename ViewComponent,
typename Derived>
183 template <color_space ColorSpace,
typename BaseComponent,
typename ViewComponent,
typename Derived>
191 template <color_space ColorSpace,
typename BaseComponent,
typename ViewComponent,
typename Derived>
197 template <color_space ColorSpace,
typename BaseComponent,
typename ViewComponent,
typename Derived>
200 view_component newRed = std::numeric_limits<view_component>::max() - red() < aDelta ? std::numeric_limits<view_component>::max() : red() + aDelta;
201 view_component newGreen = std::numeric_limits<view_component>::max() - green() < aDelta ? std::numeric_limits<view_component>::max() : green() + aDelta;
202 view_component newBlue = std::numeric_limits<view_component>::max() - blue() < aDelta ? std::numeric_limits<view_component>::max() : blue() + aDelta;
207 template <color_space ColorSpace,
typename BaseComponent,
typename ViewComponent,
typename Derived>
210 view_component newRed = red() < aDelta ? std::numeric_limits<view_component>::min() : red() - aDelta;
211 view_component newGreen = green() < aDelta ? std::numeric_limits<view_component>::min() : green() - aDelta;
212 view_component newBlue = blue() < aDelta ? std::numeric_limits<view_component>::min() : blue() - aDelta;
217 template <color_space ColorSpace,
typename BaseComponent,
typename ViewComponent,
typename Derived>
223 template <color_space ColorSpace,
typename BaseComponent,
typename ViewComponent,
typename Derived>
226 return base_type::operator==(aOther);
229 template <color_space ColorSpace,
typename BaseComponent,
typename ViewComponent,
typename Derived>
237 template <color_space ColorSpace,
typename BaseComponent,
typename ViewComponent,
typename Derived>
240 std::ostringstream result;
241 result <<
"rgba(" <<
static_cast<int>(red()) <<
", " <<
static_cast<int>(green()) <<
", " <<
static_cast<int>(blue()) <<
", " << alpha() / 255.0 <<
");";
245 template <color_space ColorSpace,
typename BaseComponent,
typename ViewComponent,
typename Derived>
248 std::ostringstream result;
249 result <<
"#" << std::uppercase << std::hex << std::setfill(
'0') << std::setw(6) << with_alpha(0).as_argb();
251 result << std::uppercase << std::hex << std::setfill('0') << std::setw(2) << static_cast<uint32_t>(alpha());
255 template <color_space ColorSpace,
typename BaseComponent,
typename ViewComponent,
typename Derived>
256 inline typename basic_rgb_color<ColorSpace, BaseComponent, ViewComponent, Derived>::return_type operator+(
const basic_rgb_color<ColorSpace, BaseComponent, ViewComponent, Derived>& aLeft,
typename basic_rgb_color<ColorSpace, BaseComponent, ViewComponent, Derived>::view_component aRight)
263 template <color_space ColorSpace,
typename BaseComponent,
typename ViewComponent,
typename Derived>
264 inline typename basic_rgb_color<ColorSpace, BaseComponent, ViewComponent, Derived>::return_type operator-(
const basic_rgb_color<ColorSpace, BaseComponent, ViewComponent, Derived>& aLeft,
typename basic_rgb_color<ColorSpace, BaseComponent, ViewComponent, Derived>::view_component aRight)
271 template <color_space ColorSpace,
typename BaseComponent,
typename ViewComponent,
typename Derived>
275 result *=
vec4 { aCoefficient, aCoefficient, aCoefficient, aCoefficient };
279 template <
typename Elem,
typename Traits, color_space ColorSpace,
typename BaseComponent,
typename ViewComponent,
typename Derived>
280 inline std::basic_ostream<Elem, Traits>& operator<<(std::basic_ostream<Elem, Traits>& aStream,
const basic_rgb_color<ColorSpace, BaseComponent, ViewComponent, Derived>& aColor)
282 aStream << std::setprecision(4) <<
"[" << aColor.red<
double>() <<
", " << aColor.green<
double>() <<
", " << aColor.blue<
double>() <<
", " << aColor.alpha<
double>() <<
"]";
286 template <
typename Elem,
typename Traits, color_space ColorSpace,
typename BaseComponent,
typename ViewComponent,
typename Derived>
289 auto previousImbued = aStream.getloc();
293 aStream >> ignore >> aColor[0] >> aColor[1] >> aColor[2] >> aColor[3] >> ignore;
294 aStream.imbue(previousImbued);
ViewComponent view_component
return_type & lighten(view_component aDelta)
return_type lighter(view_component aDelta) const
static return_type from_hsv(scalar aHue, scalar aSaturation, scalar aValue, scalar aAlpha=1.0)
return_type & darken(view_component aDelta)
bool operator==(const self_type &aOther) const
return_type operator~() const
return_type mix(const self_type &aOther, scalar aValue) const
std::string to_string() const
return_type shaded(view_component aDelta) const
return_type & unshade(view_component aDelta)
return_type mid(const self_type &aOther) const
bool similar_intensity(const self_type &aOther, scalar aThreshold=0.5) const
return_type unshaded(view_component aDelta) const
bool operator<(const self_type &aOther) const
bool light(scalar aThreshold=0.50) const
return_type inverse() const
color_return_type_cracker< self_type, derived_type >::return_type return_type
bool dark(scalar aThreshold=0.50) const
return_type same_lightness_as(const self_type &aOther) const
return_type & operator+=(view_component aDelta)
std::string to_hex_string() const
static return_type from_hsl(scalar aHue, scalar aSaturation, scalar aLightness, scalar aAlpha=1.0)
return_type & shade(view_component aDelta)
return_type & operator-=(view_component aDelta)
return_type with_lightness(scalar aLightness) const
return_type monochrome() const
return_type darker(view_component aDelta) const
ViewComponent view_component
void set_lightness(double aLightness)
void to_rgb(scalar &aRed, scalar &aGreen, scalar &aBlue, scalar &aAlpha) const
double saturation() const
void to_rgb(scalar &aRed, scalar &aGreen, scalar &aBlue, scalar &aAlpha) const
std::basic_istream< Elem, Traits > & operator>>(std::basic_istream< Elem, Traits > &aStream, basic_point< T > &aPoint)
basic_delta< CoordinateType > operator-(const basic_delta< CoordinateType > &left, CoordinateType s)
basic_delta< CoordinateType > operator*(const basic_delta< CoordinateType > &left, CoordinateType s)
basic_delta< CoordinateType > operator+(const basic_delta< CoordinateType > &left, CoordinateType s)