Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Namespaces | Macros | Enumerations | Functions
color.h File Reference
#include <stdint.h>
#include <algorithm>
#include <array>
#include <cstdint>
#include <cstdlib>
#include <ostream>
#include <type_traits>
#include "impeller/geometry/scalar.h"
#include "impeller/geometry/type_traits.h"

Go to the source code of this file.

Classes

struct  impeller::ColorMatrix
 
struct  impeller::Color
 
struct  impeller::ColorHSB
 

Namespaces

namespace  impeller
 
namespace  std
 

Macros

#define IMPELLER_FOR_EACH_BLEND_MODE(V)
 

Enumerations

enum class  impeller::YUVColorSpace { impeller::kBT601LimitedRange , impeller::kBT601FullRange }
 
enum class  impeller::BlendMode : uint8_t {
  impeller::kClear = 0 , impeller::kSource , impeller::kDestination , impeller::kSourceOver ,
  impeller::kDestinationOver , impeller::kSourceIn , impeller::kDestinationIn , impeller::kSourceOut ,
  impeller::kDestinationOut , impeller::kSourceATop , impeller::kDestinationATop , impeller::kXor ,
  impeller::kPlus , impeller::kModulate , impeller::kScreen , impeller::kOverlay ,
  impeller::kDarken , impeller::kLighten , impeller::kColorDodge , impeller::kColorBurn ,
  impeller::kHardLight , impeller::kSoftLight , impeller::kDifference , impeller::kExclusion ,
  impeller::kMultiply , impeller::kHue , impeller::kSaturation , impeller::kColor ,
  impeller::kLuminosity , impeller::kLast = kLuminosity
}
 

Functions

const char * impeller::BlendModeToString (BlendMode blend_mode)
 
template<class T , class = std::enable_if_t<std::is_arithmetic_v<T>>>
constexpr Color impeller::operator+ (T value, const Color &c)
 
template<class T , class = std::enable_if_t<std::is_arithmetic_v<T>>>
constexpr Color impeller::operator- (T value, const Color &c)
 
template<class T , class = std::enable_if_t<std::is_arithmetic_v<T>>>
constexpr Color impeller::operator* (T value, const Color &c)
 
template<class T , class = std::enable_if_t<std::is_arithmetic_v<T>>>
constexpr Color impeller::operator/ (T value, const Color &c)
 
std::string impeller::ColorToString (const Color &color)
 
std::ostream & std::operator<< (std::ostream &out, const impeller::Color &c)
 

Macro Definition Documentation

◆ IMPELLER_FOR_EACH_BLEND_MODE

#define IMPELLER_FOR_EACH_BLEND_MODE (   V)
Value:
V(Clear) \
V(Source) \
V(Destination) \
V(SourceOver) \
V(DestinationOver) \
V(SourceIn) \
V(DestinationIn) \
V(SourceOut) \
V(DestinationOut) \
V(SourceATop) \
V(DestinationATop) \
V(Xor) \
V(Plus) \
V(Modulate) \
V(Screen) \
V(Overlay) \
V(Darken) \
V(Lighten) \
V(ColorDodge) \
V(ColorBurn) \
V(HardLight) \
V(SoftLight) \
V(Difference) \
V(Exclusion) \
V(Multiply) \
V(Hue) \
V(Saturation) \
V(Color) \
V(Luminosity)
#define V(name)
Definition raw_object.h:124

Definition at line 19 of file color.h.

49 {
50
51struct ColorHSB;
52struct Vector4;
53
55
56/// All blend modes assume that both the source (fragment output) and
57/// destination (first color attachment) have colors with premultiplied alpha.
58enum class BlendMode : uint8_t {
59 // The following blend modes are able to be used as pipeline blend modes or
60 // via `BlendFilterContents`.
61 kClear = 0,
62 kSource,
72 kXor,
73 kPlus,
75
76 // The following blend modes use equations that are not available for
77 // pipelines on most graphics devices without extensions, and so they are
78 // only able to be used via `BlendFilterContents`.
79 kScreen,
81 kDarken,
90 kHue,
92 kColor,
94
96};
97
98const char* BlendModeToString(BlendMode blend_mode);
99
100/// 4x5 matrix for transforming the color and alpha components of a Bitmap.
101///
102/// [ a, b, c, d, e,
103/// f, g, h, i, j,
104/// k, l, m, n, o,
105/// p, q, r, s, t ]
106///
107/// When applied to a color [R, G, B, A], the resulting color is computed as:
108///
109/// R’ = a*R + b*G + c*B + d*A + e;
110/// G’ = f*R + g*G + h*B + i*A + j;
111/// B’ = k*R + l*G + m*B + n*A + o;
112/// A’ = p*R + q*G + r*B + s*A + t;
113///
114/// That resulting color [R’, G’, B’, A’] then has each channel clamped to the 0
115/// to 1 range.
116struct ColorMatrix {
117 Scalar array[20];
118};
119
120/**
121 * Represents a RGBA color
122 */
123struct Color {
124 /**
125 * The red color component (0 to 1)
126 */
127 Scalar red = 0.0;
128
129 /**
130 * The green color component (0 to 1)
131 */
132 Scalar green = 0.0;
133
134 /**
135 * The blue color component (0 to 1)
136 */
137 Scalar blue = 0.0;
138
139 /**
140 * The alpha component of the color (0 to 1)
141 */
142 Scalar alpha = 0.0;
143
144 constexpr Color() {}
145
146 explicit Color(const ColorHSB& hsbColor);
147
148 explicit Color(const Vector4& value);
149
150 constexpr Color(Scalar r, Scalar g, Scalar b, Scalar a)
151 : red(r), green(g), blue(b), alpha(a) {}
152
153 static constexpr Color MakeRGBA8(uint8_t r, uint8_t g, uint8_t b, uint8_t a) {
154 return Color(
155 static_cast<Scalar>(r) / 255.0f, static_cast<Scalar>(g) / 255.0f,
156 static_cast<Scalar>(b) / 255.0f, static_cast<Scalar>(a) / 255.0f);
157 }
158
159 /// @brief Convert this color to a 32-bit representation.
160 static constexpr uint32_t ToIColor(Color color) {
161 return (((std::lround(color.alpha * 255.0f) & 0xff) << 24) |
162 ((std::lround(color.red * 255.0f) & 0xff) << 16) |
163 ((std::lround(color.green * 255.0f) & 0xff) << 8) |
164 ((std::lround(color.blue * 255.0f) & 0xff) << 0)) &
165 0xFFFFFFFF;
166 }
167
168 constexpr inline bool operator==(const Color& c) const {
169 return ScalarNearlyEqual(red, c.red) && ScalarNearlyEqual(green, c.green) &&
170 ScalarNearlyEqual(blue, c.blue) && ScalarNearlyEqual(alpha, c.alpha);
171 }
172
173 constexpr inline Color operator+(const Color& c) const {
174 return {red + c.red, green + c.green, blue + c.blue, alpha + c.alpha};
175 }
176
177 template <class T, class = std::enable_if_t<std::is_arithmetic_v<T>>>
178 constexpr inline Color operator+(T value) const {
179 auto v = static_cast<Scalar>(value);
180 return {red + v, green + v, blue + v, alpha + v};
181 }
182
183 constexpr inline Color operator-(const Color& c) const {
184 return {red - c.red, green - c.green, blue - c.blue, alpha - c.alpha};
185 }
186
187 template <class T, class = std::enable_if_t<std::is_arithmetic_v<T>>>
188 constexpr inline Color operator-(T value) const {
189 auto v = static_cast<Scalar>(value);
190 return {red - v, green - v, blue - v, alpha - v};
191 }
192
193 constexpr inline Color operator*(const Color& c) const {
194 return {red * c.red, green * c.green, blue * c.blue, alpha * c.alpha};
195 }
196
197 template <class T, class = std::enable_if_t<std::is_arithmetic_v<T>>>
198 constexpr inline Color operator*(T value) const {
199 auto v = static_cast<Scalar>(value);
200 return {red * v, green * v, blue * v, alpha * v};
201 }
202
203 constexpr inline Color operator/(const Color& c) const {
204 return {red * c.red, green * c.green, blue * c.blue, alpha * c.alpha};
205 }
206
207 template <class T, class = std::enable_if_t<std::is_arithmetic_v<T>>>
208 constexpr inline Color operator/(T value) const {
209 auto v = static_cast<Scalar>(value);
210 return {red / v, green / v, blue / v, alpha / v};
211 }
212
213 constexpr Color Premultiply() const {
214 return {red * alpha, green * alpha, blue * alpha, alpha};
215 }
216
217 constexpr Color Unpremultiply() const {
218 if (ScalarNearlyEqual(alpha, 0.0f)) {
219 return Color::BlackTransparent();
220 }
221 return {red / alpha, green / alpha, blue / alpha, alpha};
222 }
223
224 /**
225 * @brief Return a color that is linearly interpolated between colors a
226 * and b, according to the value of t.
227 *
228 * @param a The lower color.
229 * @param b The upper color.
230 * @param t A value between 0.0f and 1.0f, inclusive.
231 * @return constexpr Color
232 */
233 constexpr static Color Lerp(Color a, Color b, Scalar t) {
234 return a + (b - a) * t;
235 }
236
237 constexpr Color Clamp01() const {
238 return Color(std::clamp(red, 0.0f, 1.0f), std::clamp(green, 0.0f, 1.0f),
239 std::clamp(blue, 0.0f, 1.0f), std::clamp(alpha, 0.0f, 1.0f));
240 }
241
242 /**
243 * @brief Convert to R8G8B8A8 representation.
244 *
245 * @return constexpr std::array<u_int8, 4>
246 */
247 constexpr std::array<uint8_t, 4> ToR8G8B8A8() const {
248 uint8_t r = std::round(red * 255.0f);
249 uint8_t g = std::round(green * 255.0f);
250 uint8_t b = std::round(blue * 255.0f);
251 uint8_t a = std::round(alpha * 255.0f);
252 return {r, g, b, a};
253 }
254
255 static constexpr Color White() { return {1.0f, 1.0f, 1.0f, 1.0f}; }
256
257 static constexpr Color Black() { return {0.0f, 0.0f, 0.0f, 1.0f}; }
258
259 static constexpr Color WhiteTransparent() { return {1.0f, 1.0f, 1.0f, 0.0f}; }
260
261 static constexpr Color BlackTransparent() { return {0.0f, 0.0f, 0.0f, 0.0f}; }
262
263 static constexpr Color Red() { return {1.0f, 0.0f, 0.0f, 1.0f}; }
264
265 static constexpr Color Green() { return {0.0f, 1.0f, 0.0f, 1.0f}; }
266
267 static constexpr Color Blue() { return {0.0f, 0.0f, 1.0f, 1.0f}; }
268
269 constexpr Color WithAlpha(Scalar new_alpha) const {
270 return {red, green, blue, new_alpha};
271 }
272
273 static constexpr Color AliceBlue() {
274 return {240.0f / 255.0f, 248.0f / 255.0f, 255.0f / 255.0f, 1.0f};
275 }
276
277 static constexpr Color AntiqueWhite() {
278 return {250.0f / 255.0f, 235.0f / 255.0f, 215.0f / 255.0f, 1.0f};
279 }
280
281 static constexpr Color Aqua() {
282 return {0.0f / 255.0f, 255.0f / 255.0f, 255.0f / 255.0f, 1.0f};
283 }
284
285 static constexpr Color AquaMarine() {
286 return {127.0f / 255.0f, 255.0f / 255.0f, 212.0f / 255.0f, 1.0f};
287 }
288
289 static constexpr Color Azure() {
290 return {240.0f / 255.0f, 255.0f / 255.0f, 255.0f / 255.0f, 1.0f};
291 }
292
293 static constexpr Color Beige() {
294 return {245.0f / 255.0f, 245.0f / 255.0f, 220.0f / 255.0f, 1.0f};
295 }
296
297 static constexpr Color Bisque() {
298 return {255.0f / 255.0f, 228.0f / 255.0f, 196.0f / 255.0f, 1.0f};
299 }
300
301 static constexpr Color BlanchedAlmond() {
302 return {255.0f / 255.0f, 235.0f / 255.0f, 205.0f / 255.0f, 1.0f};
303 }
304
305 static constexpr Color BlueViolet() {
306 return {138.0f / 255.0f, 43.0f / 255.0f, 226.0f / 255.0f, 1.0f};
307 }
308
309 static constexpr Color Brown() {
310 return {165.0f / 255.0f, 42.0f / 255.0f, 42.0f / 255.0f, 1.0f};
311 }
312
313 static constexpr Color BurlyWood() {
314 return {222.0f / 255.0f, 184.0f / 255.0f, 135.0f / 255.0f, 1.0f};
315 }
316
317 static constexpr Color CadetBlue() {
318 return {95.0f / 255.0f, 158.0f / 255.0f, 160.0f / 255.0f, 1.0f};
319 }
320
321 static constexpr Color Chartreuse() {
322 return {127.0f / 255.0f, 255.0f / 255.0f, 0.0f / 255.0f, 1.0f};
323 }
324
325 static constexpr Color Chocolate() {
326 return {210.0f / 255.0f, 105.0f / 255.0f, 30.0f / 255.0f, 1.0f};
327 }
328
329 static constexpr Color Coral() {
330 return {255.0f / 255.0f, 127.0f / 255.0f, 80.0f / 255.0f, 1.0f};
331 }
332
333 static constexpr Color CornflowerBlue() {
334 return {100.0f / 255.0f, 149.0f / 255.0f, 237.0f / 255.0f, 1.0f};
335 }
336
337 static constexpr Color Cornsilk() {
338 return {255.0f / 255.0f, 248.0f / 255.0f, 220.0f / 255.0f, 1.0f};
339 }
340
341 static constexpr Color Crimson() {
342 return {220.0f / 255.0f, 20.0f / 255.0f, 60.0f / 255.0f, 1.0f};
343 }
344
345 static constexpr Color Cyan() {
346 return {0.0f / 255.0f, 255.0f / 255.0f, 255.0f / 255.0f, 1.0f};
347 }
348
349 static constexpr Color DarkBlue() {
350 return {0.0f / 255.0f, 0.0f / 255.0f, 139.0f / 255.0f, 1.0f};
351 }
352
353 static constexpr Color DarkCyan() {
354 return {0.0f / 255.0f, 139.0f / 255.0f, 139.0f / 255.0f, 1.0f};
355 }
356
357 static constexpr Color DarkGoldenrod() {
358 return {184.0f / 255.0f, 134.0f / 255.0f, 11.0f / 255.0f, 1.0f};
359 }
360
361 static constexpr Color DarkGray() {
362 return {169.0f / 255.0f, 169.0f / 255.0f, 169.0f / 255.0f, 1.0f};
363 }
364
365 static constexpr Color DarkGreen() {
366 return {0.0f / 255.0f, 100.0f / 255.0f, 0.0f / 255.0f, 1.0f};
367 }
368
369 static constexpr Color DarkGrey() {
370 return {169.0f / 255.0f, 169.0f / 255.0f, 169.0f / 255.0f, 1.0f};
371 }
372
373 static constexpr Color DarkKhaki() {
374 return {189.0f / 255.0f, 183.0f / 255.0f, 107.0f / 255.0f, 1.0f};
375 }
376
377 static constexpr Color DarkMagenta() {
378 return {139.0f / 255.0f, 0.0f / 255.0f, 139.0f / 255.0f, 1.0f};
379 }
380
381 static constexpr Color DarkOliveGreen() {
382 return {85.0f / 255.0f, 107.0f / 255.0f, 47.0f / 255.0f, 1.0f};
383 }
384
385 static constexpr Color DarkOrange() {
386 return {255.0f / 255.0f, 140.0f / 255.0f, 0.0f / 255.0f, 1.0f};
387 }
388
389 static constexpr Color DarkOrchid() {
390 return {153.0f / 255.0f, 50.0f / 255.0f, 204.0f / 255.0f, 1.0f};
391 }
392
393 static constexpr Color DarkRed() {
394 return {139.0f / 255.0f, 0.0f / 255.0f, 0.0f / 255.0f, 1.0f};
395 }
396
397 static constexpr Color DarkSalmon() {
398 return {233.0f / 255.0f, 150.0f / 255.0f, 122.0f / 255.0f, 1.0f};
399 }
400
401 static constexpr Color DarkSeagreen() {
402 return {143.0f / 255.0f, 188.0f / 255.0f, 143.0f / 255.0f, 1.0f};
403 }
404
405 static constexpr Color DarkSlateBlue() {
406 return {72.0f / 255.0f, 61.0f / 255.0f, 139.0f / 255.0f, 1.0f};
407 }
408
409 static constexpr Color DarkSlateGray() {
410 return {47.0f / 255.0f, 79.0f / 255.0f, 79.0f / 255.0f, 1.0f};
411 }
412
413 static constexpr Color DarkSlateGrey() {
414 return {47.0f / 255.0f, 79.0f / 255.0f, 79.0f / 255.0f, 1.0f};
415 }
416
417 static constexpr Color DarkTurquoise() {
418 return {0.0f / 255.0f, 206.0f / 255.0f, 209.0f / 255.0f, 1.0f};
419 }
420
421 static constexpr Color DarkViolet() {
422 return {148.0f / 255.0f, 0.0f / 255.0f, 211.0f / 255.0f, 1.0f};
423 }
424
425 static constexpr Color DeepPink() {
426 return {255.0f / 255.0f, 20.0f / 255.0f, 147.0f / 255.0f, 1.0f};
427 }
428
429 static constexpr Color DeepSkyBlue() {
430 return {0.0f / 255.0f, 191.0f / 255.0f, 255.0f / 255.0f, 1.0f};
431 }
432
433 static constexpr Color DimGray() {
434 return {105.0f / 255.0f, 105.0f / 255.0f, 105.0f / 255.0f, 1.0f};
435 }
436
437 static constexpr Color DimGrey() {
438 return {105.0f / 255.0f, 105.0f / 255.0f, 105.0f / 255.0f, 1.0f};
439 }
440
441 static constexpr Color DodgerBlue() {
442 return {30.0f / 255.0f, 144.0f / 255.0f, 255.0f / 255.0f, 1.0f};
443 }
444
445 static constexpr Color Firebrick() {
446 return {178.0f / 255.0f, 34.0f / 255.0f, 34.0f / 255.0f, 1.0f};
447 }
448
449 static constexpr Color FloralWhite() {
450 return {255.0f / 255.0f, 250.0f / 255.0f, 240.0f / 255.0f, 1.0f};
451 }
452
453 static constexpr Color ForestGreen() {
454 return {34.0f / 255.0f, 139.0f / 255.0f, 34.0f / 255.0f, 1.0f};
455 }
456
457 static constexpr Color Fuchsia() {
458 return {255.0f / 255.0f, 0.0f / 255.0f, 255.0f / 255.0f, 1.0f};
459 }
460
461 static constexpr Color Gainsboro() {
462 return {220.0f / 255.0f, 220.0f / 255.0f, 220.0f / 255.0f, 1.0f};
463 }
464
465 static constexpr Color Ghostwhite() {
466 return {248.0f / 255.0f, 248.0f / 255.0f, 255.0f / 255.0f, 1.0f};
467 }
468
469 static constexpr Color Gold() {
470 return {255.0f / 255.0f, 215.0f / 255.0f, 0.0f / 255.0f, 1.0f};
471 }
472
473 static constexpr Color Goldenrod() {
474 return {218.0f / 255.0f, 165.0f / 255.0f, 32.0f / 255.0f, 1.0f};
475 }
476
477 static constexpr Color Gray() {
478 return {128.0f / 255.0f, 128.0f / 255.0f, 128.0f / 255.0f, 1.0f};
479 }
480
481 static constexpr Color GreenYellow() {
482 return {173.0f / 255.0f, 255.0f / 255.0f, 47.0f / 255.0f, 1.0f};
483 }
484
485 static constexpr Color Grey() {
486 return {128.0f / 255.0f, 128.0f / 255.0f, 128.0f / 255.0f, 1.0f};
487 }
488
489 static constexpr Color Honeydew() {
490 return {240.0f / 255.0f, 255.0f / 255.0f, 240.0f / 255.0f, 1.0f};
491 }
492
493 static constexpr Color HotPink() {
494 return {255.0f / 255.0f, 105.0f / 255.0f, 180.0f / 255.0f, 1.0f};
495 }
496
497 static constexpr Color IndianRed() {
498 return {205.0f / 255.0f, 92.0f / 255.0f, 92.0f / 255.0f, 1.0f};
499 }
500
501 static constexpr Color Indigo() {
502 return {75.0f / 255.0f, 0.0f / 255.0f, 130.0f / 255.0f, 1.0f};
503 }
504
505 static constexpr Color Ivory() {
506 return {255.0f / 255.0f, 255.0f / 255.0f, 240.0f / 255.0f, 1.0f};
507 }
508
509 static constexpr Color Khaki() {
510 return {240.0f / 255.0f, 230.0f / 255.0f, 140.0f / 255.0f, 1.0f};
511 }
512
513 static constexpr Color Lavender() {
514 return {230.0f / 255.0f, 230.0f / 255.0f, 250.0f / 255.0f, 1.0f};
515 }
516
517 static constexpr Color LavenderBlush() {
518 return {255.0f / 255.0f, 240.0f / 255.0f, 245.0f / 255.0f, 1.0f};
519 }
520
521 static constexpr Color LawnGreen() {
522 return {124.0f / 255.0f, 252.0f / 255.0f, 0.0f / 255.0f, 1.0f};
523 }
524
525 static constexpr Color LemonChiffon() {
526 return {255.0f / 255.0f, 250.0f / 255.0f, 205.0f / 255.0f, 1.0f};
527 }
528
529 static constexpr Color LightBlue() {
530 return {173.0f / 255.0f, 216.0f / 255.0f, 230.0f / 255.0f, 1.0f};
531 }
532
533 static constexpr Color LightCoral() {
534 return {240.0f / 255.0f, 128.0f / 255.0f, 128.0f / 255.0f, 1.0f};
535 }
536
537 static constexpr Color LightCyan() {
538 return {224.0f / 255.0f, 255.0f / 255.0f, 255.0f / 255.0f, 1.0f};
539 }
540
541 static constexpr Color LightGoldenrodYellow() {
542 return {50.0f / 255.0f, 250.0f / 255.0f, 210.0f / 255.0f, 1.0f};
543 }
544
545 static constexpr Color LightGray() {
546 return {211.0f / 255.0f, 211.0f / 255.0f, 211.0f / 255.0f, 1.0f};
547 }
548
549 static constexpr Color LightGreen() {
550 return {144.0f / 255.0f, 238.0f / 255.0f, 144.0f / 255.0f, 1.0f};
551 }
552
553 static constexpr Color LightGrey() {
554 return {211.0f / 255.0f, 211.0f / 255.0f, 211.0f / 255.0f, 1.0f};
555 }
556
557 static constexpr Color LightPink() {
558 return {255.0f / 255.0f, 182.0f / 255.0f, 193.0f / 255.0f, 1.0f};
559 }
560
561 static constexpr Color LightSalmon() {
562 return {255.0f / 255.0f, 160.0f / 255.0f, 122.0f / 255.0f, 1.0f};
563 }
564
565 static constexpr Color LightSeaGreen() {
566 return {32.0f / 255.0f, 178.0f / 255.0f, 170.0f / 255.0f, 1.0f};
567 }
568
569 static constexpr Color LightSkyBlue() {
570 return {135.0f / 255.0f, 206.0f / 255.0f, 250.0f / 255.0f, 1.0f};
571 }
572
573 static constexpr Color LightSlateGray() {
574 return {119.0f / 255.0f, 136.0f / 255.0f, 153.0f / 255.0f, 1.0f};
575 }
576
577 static constexpr Color LightSlateGrey() {
578 return {119.0f / 255.0f, 136.0f / 255.0f, 153.0f / 255.0f, 1.0f};
579 }
580
581 static constexpr Color LightSteelBlue() {
582 return {176.0f / 255.0f, 196.0f / 255.0f, 222.0f / 255.0f, 1.0f};
583 }
584
585 static constexpr Color LightYellow() {
586 return {255.0f / 255.0f, 255.0f / 255.0f, 224.0f / 255.0f, 1.0f};
587 }
588
589 static constexpr Color Lime() {
590 return {0.0f / 255.0f, 255.0f / 255.0f, 0.0f / 255.0f, 1.0f};
591 }
592
593 static constexpr Color LimeGreen() {
594 return {50.0f / 255.0f, 205.0f / 255.0f, 50.0f / 255.0f, 1.0f};
595 }
596
597 static constexpr Color Linen() {
598 return {250.0f / 255.0f, 240.0f / 255.0f, 230.0f / 255.0f, 1.0f};
599 }
600
601 static constexpr Color Magenta() {
602 return {255.0f / 255.0f, 0.0f / 255.0f, 255.0f / 255.0f, 1.0f};
603 }
604
605 static constexpr Color Maroon() {
606 return {128.0f / 255.0f, 0.0f / 255.0f, 0.0f / 255.0f, 1.0f};
607 }
608
609 static constexpr Color MediumAquamarine() {
610 return {102.0f / 255.0f, 205.0f / 255.0f, 170.0f / 255.0f, 1.0f};
611 }
612
613 static constexpr Color MediumBlue() {
614 return {0.0f / 255.0f, 0.0f / 255.0f, 205.0f / 255.0f, 1.0f};
615 }
616
617 static constexpr Color MediumOrchid() {
618 return {186.0f / 255.0f, 85.0f / 255.0f, 211.0f / 255.0f, 1.0f};
619 }
620
621 static constexpr Color MediumPurple() {
622 return {147.0f / 255.0f, 112.0f / 255.0f, 219.0f / 255.0f, 1.0f};
623 }
624
625 static constexpr Color MediumSeagreen() {
626 return {60.0f / 255.0f, 179.0f / 255.0f, 113.0f / 255.0f, 1.0f};
627 }
628
629 static constexpr Color MediumSlateBlue() {
630 return {123.0f / 255.0f, 104.0f / 255.0f, 238.0f / 255.0f, 1.0f};
631 }
632
633 static constexpr Color MediumSpringGreen() {
634 return {0.0f / 255.0f, 250.0f / 255.0f, 154.0f / 255.0f, 1.0f};
635 }
636
637 static constexpr Color MediumTurquoise() {
638 return {72.0f / 255.0f, 209.0f / 255.0f, 204.0f / 255.0f, 1.0f};
639 }
640
641 static constexpr Color MediumVioletRed() {
642 return {199.0f / 255.0f, 21.0f / 255.0f, 133.0f / 255.0f, 1.0f};
643 }
644
645 static constexpr Color MidnightBlue() {
646 return {25.0f / 255.0f, 25.0f / 255.0f, 112.0f / 255.0f, 1.0f};
647 }
648
649 static constexpr Color MintCream() {
650 return {245.0f / 255.0f, 255.0f / 255.0f, 250.0f / 255.0f, 1.0f};
651 }
652
653 static constexpr Color MistyRose() {
654 return {255.0f / 255.0f, 228.0f / 255.0f, 225.0f / 255.0f, 1.0f};
655 }
656
657 static constexpr Color Moccasin() {
658 return {255.0f / 255.0f, 228.0f / 255.0f, 181.0f / 255.0f, 1.0f};
659 }
660
661 static constexpr Color NavajoWhite() {
662 return {255.0f / 255.0f, 222.0f / 255.0f, 173.0f / 255.0f, 1.0f};
663 }
664
665 static constexpr Color Navy() {
666 return {0.0f / 255.0f, 0.0f / 255.0f, 128.0f / 255.0f, 1.0f};
667 }
668
669 static constexpr Color OldLace() {
670 return {253.0f / 255.0f, 245.0f / 255.0f, 230.0f / 255.0f, 1.0f};
671 }
672
673 static constexpr Color Olive() {
674 return {128.0f / 255.0f, 128.0f / 255.0f, 0.0f / 255.0f, 1.0f};
675 }
676
677 static constexpr Color OliveDrab() {
678 return {107.0f / 255.0f, 142.0f / 255.0f, 35.0f / 255.0f, 1.0f};
679 }
680
681 static constexpr Color Orange() {
682 return {255.0f / 255.0f, 165.0f / 255.0f, 0.0f / 255.0f, 1.0f};
683 }
684
685 static constexpr Color OrangeRed() {
686 return {255.0f / 255.0f, 69.0f / 255.0f, 0.0f / 255.0f, 1.0f};
687 }
688
689 static constexpr Color Orchid() {
690 return {218.0f / 255.0f, 112.0f / 255.0f, 214.0f / 255.0f, 1.0f};
691 }
692
693 static constexpr Color PaleGoldenrod() {
694 return {238.0f / 255.0f, 232.0f / 255.0f, 170.0f / 255.0f, 1.0f};
695 }
696
697 static constexpr Color PaleGreen() {
698 return {152.0f / 255.0f, 251.0f / 255.0f, 152.0f / 255.0f, 1.0f};
699 }
700
701 static constexpr Color PaleTurquoise() {
702 return {175.0f / 255.0f, 238.0f / 255.0f, 238.0f / 255.0f, 1.0f};
703 }
704
705 static constexpr Color PaleVioletRed() {
706 return {219.0f / 255.0f, 112.0f / 255.0f, 147.0f / 255.0f, 1.0f};
707 }
708
709 static constexpr Color PapayaWhip() {
710 return {255.0f / 255.0f, 239.0f / 255.0f, 213.0f / 255.0f, 1.0f};
711 }
712
713 static constexpr Color Peachpuff() {
714 return {255.0f / 255.0f, 218.0f / 255.0f, 185.0f / 255.0f, 1.0f};
715 }
716
717 static constexpr Color Peru() {
718 return {205.0f / 255.0f, 133.0f / 255.0f, 63.0f / 255.0f, 1.0f};
719 }
720
721 static constexpr Color Pink() {
722 return {255.0f / 255.0f, 192.0f / 255.0f, 203.0f / 255.0f, 1.0f};
723 }
724
725 static constexpr Color Plum() {
726 return {221.0f / 255.0f, 160.0f / 255.0f, 221.0f / 255.0f, 1.0f};
727 }
728
729 static constexpr Color PowderBlue() {
730 return {176.0f / 255.0f, 224.0f / 255.0f, 230.0f / 255.0f, 1.0f};
731 }
732
733 static constexpr Color Purple() {
734 return {128.0f / 255.0f, 0.0f / 255.0f, 128.0f / 255.0f, 1.0f};
735 }
736
737 static constexpr Color RosyBrown() {
738 return {188.0f / 255.0f, 143.0f / 255.0f, 143.0f / 255.0f, 1.0f};
739 }
740
741 static constexpr Color RoyalBlue() {
742 return {65.0f / 255.0f, 105.0f / 255.0f, 225.0f / 255.0f, 1.0f};
743 }
744
745 static constexpr Color SaddleBrown() {
746 return {139.0f / 255.0f, 69.0f / 255.0f, 19.0f / 255.0f, 1.0f};
747 }
748
749 static constexpr Color Salmon() {
750 return {250.0f / 255.0f, 128.0f / 255.0f, 114.0f / 255.0f, 1.0f};
751 }
752
753 static constexpr Color SandyBrown() {
754 return {244.0f / 255.0f, 164.0f / 255.0f, 96.0f / 255.0f, 1.0f};
755 }
756
757 static constexpr Color Seagreen() {
758 return {46.0f / 255.0f, 139.0f / 255.0f, 87.0f / 255.0f, 1.0f};
759 }
760
761 static constexpr Color Seashell() {
762 return {255.0f / 255.0f, 245.0f / 255.0f, 238.0f / 255.0f, 1.0f};
763 }
764
765 static constexpr Color Sienna() {
766 return {160.0f / 255.0f, 82.0f / 255.0f, 45.0f / 255.0f, 1.0f};
767 }
768
769 static constexpr Color Silver() {
770 return {192.0f / 255.0f, 192.0f / 255.0f, 192.0f / 255.0f, 1.0f};
771 }
772
773 static constexpr Color SkyBlue() {
774 return {135.0f / 255.0f, 206.0f / 255.0f, 235.0f / 255.0f, 1.0f};
775 }
776
777 static constexpr Color SlateBlue() {
778 return {106.0f / 255.0f, 90.0f / 255.0f, 205.0f / 255.0f, 1.0f};
779 }
780
781 static constexpr Color SlateGray() {
782 return {112.0f / 255.0f, 128.0f / 255.0f, 144.0f / 255.0f, 1.0f};
783 }
784
785 static constexpr Color SlateGrey() {
786 return {112.0f / 255.0f, 128.0f / 255.0f, 144.0f / 255.0f, 1.0f};
787 }
788
789 static constexpr Color Snow() {
790 return {255.0f / 255.0f, 250.0f / 255.0f, 250.0f / 255.0f, 1.0f};
791 }
792
793 static constexpr Color SpringGreen() {
794 return {0.0f / 255.0f, 255.0f / 255.0f, 127.0f / 255.0f, 1.0f};
795 }
796
797 static constexpr Color SteelBlue() {
798 return {70.0f / 255.0f, 130.0f / 255.0f, 180.0f / 255.0f, 1.0f};
799 }
800
801 static constexpr Color Tan() {
802 return {210.0f / 255.0f, 180.0f / 255.0f, 140.0f / 255.0f, 1.0f};
803 }
804
805 static constexpr Color Teal() {
806 return {0.0f / 255.0f, 128.0f / 255.0f, 128.0f / 255.0f, 1.0f};
807 }
808
809 static constexpr Color Thistle() {
810 return {216.0f / 255.0f, 191.0f / 255.0f, 216.0f / 255.0f, 1.0f};
811 }
812
813 static constexpr Color Tomato() {
814 return {255.0f / 255.0f, 99.0f / 255.0f, 71.0f / 255.0f, 1.0f};
815 }
816
817 static constexpr Color Turquoise() {
818 return {64.0f / 255.0f, 224.0f / 255.0f, 208.0f / 255.0f, 1.0f};
819 }
820
821 static constexpr Color Violet() {
822 return {238.0f / 255.0f, 130.0f / 255.0f, 238.0f / 255.0f, 1.0f};
823 }
824
825 static constexpr Color Wheat() {
826 return {245.0f / 255.0f, 222.0f / 255.0f, 179.0f / 255.0f, 1.0f};
827 }
828
829 static constexpr Color Whitesmoke() {
830 return {245.0f / 255.0f, 245.0f / 255.0f, 245.0f / 255.0f, 1.0f};
831 }
832
833 static constexpr Color Yellow() {
834 return {255.0f / 255.0f, 255.0f / 255.0f, 0.0f / 255.0f, 1.0f};
835 }
836
837 static constexpr Color YellowGreen() {
838 return {154.0f / 255.0f, 205.0f / 255.0f, 50.0f / 255.0f, 1.0f};
839 }
840
841 static Color Random() {
842 return {
843 // This method is not used for cryptographic purposes.
844 // NOLINTBEGIN(clang-analyzer-security.insecureAPI.rand)
845 static_cast<Scalar>((std::rand() % 255) / 255.0f), //
846 static_cast<Scalar>((std::rand() % 255) / 255.0f), //
847 static_cast<Scalar>((std::rand() % 255) / 255.0f), //
848 // NOLINTEND(clang-analyzer-security.insecureAPI.rand)
849 1.0f //
850
851 };
852 }
853
854 /// @brief Blends an unpremultiplied destination color into a given
855 /// unpremultiplied source color to form a new unpremultiplied color.
856 ///
857 /// If either the source or destination are premultiplied, the result
858 /// will be incorrect.
859 Color Blend(Color source, BlendMode blend_mode) const;
860
861 /// @brief A color filter that transforms colors through a 4x5 color matrix.
862 ///
863 /// This filter can be used to change the saturation of pixels, convert
864 /// from YUV to RGB, etc.
865 ///
866 /// Each channel of the output color is clamped to the 0 to 1 range.
867 ///
868 /// @see `ColorMatrix`
869 Color ApplyColorMatrix(const ColorMatrix& color_matrix) const;
870
871 /// @brief Convert the color from linear space to sRGB space.
872 ///
873 /// The color is assumed to be unpremultiplied. If the color is
874 /// premultipled, the conversion output will be incorrect.
875 Color LinearToSRGB() const;
876
877 /// @brief Convert the color from sRGB space to linear space.
878 ///
879 /// The color is assumed to be unpremultiplied. If the color is
880 /// premultipled, the conversion output will be incorrect.
881 Color SRGBToLinear() const;
882
883 constexpr bool IsTransparent() const { return alpha == 0.0f; }
884
885 constexpr bool IsOpaque() const { return alpha == 1.0f; }
886};
887
888template <class T, class = std::enable_if_t<std::is_arithmetic_v<T>>>
889constexpr inline Color operator+(T value, const Color& c) {
890 return c + static_cast<Scalar>(value);
891}
892
893template <class T, class = std::enable_if_t<std::is_arithmetic_v<T>>>
894constexpr inline Color operator-(T value, const Color& c) {
895 auto v = static_cast<Scalar>(value);
896 return {v - c.red, v - c.green, v - c.blue, v - c.alpha};
897}
898
899template <class T, class = std::enable_if_t<std::is_arithmetic_v<T>>>
900constexpr inline Color operator*(T value, const Color& c) {
901 return c * static_cast<Scalar>(value);
902}
903
904template <class T, class = std::enable_if_t<std::is_arithmetic_v<T>>>
905constexpr inline Color operator/(T value, const Color& c) {
906 auto v = static_cast<Scalar>(value);
907 return {v / c.red, v / c.green, v / c.blue, v / c.alpha};
908}
909
910std::string ColorToString(const Color& color);
911
912/**
913 * Represents a color by its constituent hue, saturation, brightness and alpha
914 */
915struct ColorHSB {
916 /**
917 * The hue of the color (0 to 1)
918 */
919 Scalar hue;
920
921 /**
922 * The saturation of the color (0 to 1)
923 */
925
926 /**
927 * The brightness of the color (0 to 1)
928 */
929 Scalar brightness;
930
931 /**
932 * The alpha of the color (0 to 1)
933 */
934 Scalar alpha;
935
936 constexpr ColorHSB(Scalar h, Scalar s, Scalar b, Scalar a)
937 : hue(h), saturation(s), brightness(b), alpha(a) {}
938
939 static ColorHSB FromRGB(Color rgb);
940
941 Color ToRGBA() const;
942};
943
944static_assert(sizeof(Color) == 4 * sizeof(Scalar));
945
946} // namespace impeller
947
948namespace std {
949
950inline std::ostream& operator<<(std::ostream& out, const impeller::Color& c) {
951 out << "(" << c.red << ", " << c.green << ", " << c.blue << ", " << c.alpha
952 << ")";
953 return out;
954}
955
956} // namespace std
957
958#endif // FLUTTER_IMPELLER_GEOMETRY_COLOR_H_
static constexpr SkColor kColor
SkColor4f color
@ kExclusion
rc = s + d - two(s*d), ra = kSrcOver
@ kSaturation
saturation of source with hue and luminosity of destination
@ kColorBurn
darken destination to reflect source
@ kPlus
r = min(s + d, 1)
@ kLighten
rc = s + d - min(s*da, d*sa), ra = kSrcOver
@ kHue
hue of source with saturation and luminosity of destination
@ kModulate
r = s*d
@ kMultiply
r = s*(1-da) + d*(1-sa) + s*d
@ kColorDodge
brighten destination to reflect source
@ kScreen
r = s + d - s*d
@ kXor
r = s*(1-da) + d*(1-sa)
@ kLuminosity
luminosity of source with hue and saturation of destination
@ kSoftLight
lighten or darken, depending on source
@ kDifference
rc = s + d - 2*(min(s*da, d*sa)), ra = kSrcOver
@ kOverlay
multiply or screen, depending on destination
@ kHardLight
multiply or screen, depending on source
@ kDarken
rc = s + d - max(s*da, d*sa), ra = kSrcOver
@ kClear
r = 0
static SkSize operator*(SkISize u, SkScalar s)
@ kBT601LimitedRange
Definition embedder.h:611
@ kBT601FullRange
Definition embedder.h:610
bool operator==(const FlutterPoint &a, const FlutterPoint &b)
SkBitmap source
Definition examples.cpp:28
static bool b
struct MyStruct s
struct MyStruct a[10]
uint8_t value
static void hue(float dr, float dg, float db, float *sr, float *sg, float *sb)
Definition hsl.cpp:92
static void saturation(float dr, float dg, float db, float *sr, float *sg, float *sb)
Definition hsl.cpp:105
YUVColorSpace
Definition color.h:55
constexpr Color operator-(T value, const Color &c)
Definition color.h:895
float Scalar
Definition scalar.h:18
constexpr Color operator/(T value, const Color &c)
Definition color.h:906
constexpr Color operator+(T value, const Color &c)
Definition color.h:890
const char * BlendModeToString(BlendMode blend_mode)
Definition color.cc:47
BlendMode
Definition color.h:59
std::string ColorToString(const Color &color)
Definition color.cc:410
constexpr bool ScalarNearlyEqual(Scalar x, Scalar y, Scalar tolerance=kEhCloseEnough)
Definition scalar.h:30
T Lerp(const T &a, const T &b, float t)
Definition ref_ptr.h:256
std::ostream & operator<<(std::ostream &out, const impeller::Color &c)
Definition color.h:951
SkScalar h
#define T
Definition DM.cpp:425
Scalar blue
Definition color.h:138
Scalar alpha
Definition color.h:143
Scalar red
Definition color.h:128
Scalar green
Definition color.h:133