Vuo  2.1.2
VuoColor.h
Go to the documentation of this file.
1 
10 #pragma once
11 
12 #include "VuoBoolean.h"
13 #include "VuoReal.h"
14 #include "VuoText.h"
15 
16 #ifdef __cplusplus
17 extern "C" {
18 #endif
19 
21 typedef const struct VuoList_VuoColor_struct { void *l; } * VuoList_VuoColor;
22 #define VuoList_VuoColor_TYPE_DEFINED
23 
40 typedef struct
41 {
42  float r,g,b,a;
43 } VuoColor;
44 
46 struct json_object * VuoColor_getJson(const VuoColor value);
47 char *VuoColor_getShortSummary(const VuoColor value);
48 char *VuoColor_getSummary(const VuoColor value);
49 
50 #define VuoColor_SUPPORTS_COMPARISON
51 bool VuoColor_areEqual(const VuoColor a, const VuoColor b);
52 bool VuoColor_isLessThan(const VuoColor a, const VuoColor b);
53 
54 bool VuoColor_areEqualWithinTolerance(const VuoColor a, const VuoColor b, const float tolerance);
55 
63 static inline VuoColor VuoColor_makeWithRGBA(VuoReal r, VuoReal g, VuoReal b, VuoReal a) __attribute__((const));
65 {
66  VuoColor c = {(float)r,(float)g,(float)b,(float)a};
67  return c;
68 }
69 
77 static inline void VuoColor_getRGBA(VuoColor color, VuoReal *r, VuoReal *g, VuoReal *b, VuoReal *a)
78 {
79  *r = color.r;
80  *g = color.g;
81  *b = color.b;
82  *a = color.a;
83 }
84 
88 static inline VuoColor VuoColor_premultiply(VuoColor c) __attribute__((const));
90 {
91  return (VuoColor){ c.r*c.a, c.g*c.a, c.b*c.a, c.a };
92 }
93 
94 VuoColor VuoColor_makeWithHSLA(VuoReal hue, VuoReal saturation, VuoReal luminosity, VuoReal alpha);
95 void VuoColor_getHSLA(VuoColor color, VuoReal *h, VuoReal *s, VuoReal *l, VuoReal *a);
97 
98 VuoText VuoColor_getHex(VuoColor color, VuoBoolean includeAlpha);
99 
101 
106 static inline bool VuoColor_isOpaque(VuoColor color)
107 {
108  return color.a >= 1.;
109 }
110 
112 
113 VuoReal VuoColor_brightness(VuoColor color, int32_t /*VuoThresholdType*/ type);
114 
118 static inline VuoColor VuoColor_lerp(VuoColor a, VuoColor b, float t) __attribute__((const));
119 static inline VuoColor VuoColor_lerp(VuoColor a, VuoColor b, float t)
120 {
121  // Premultiply, then mix, then unpremultiply.
122  VuoColor ap = VuoColor_makeWithRGBA(a.r*a.a, a.g*a.a, a.b*a.a, a.a);
123  VuoColor bp = VuoColor_makeWithRGBA(b.r*b.a, b.g*b.a, b.b*b.a, b.a);
124 
126  ap.r*(1-t) + bp.r*t,
127  ap.g*(1-t) + bp.g*t,
128  ap.b*(1-t) + bp.b*t,
129  ap.a*(1-t) + bp.a*t);
130 
131  float alpha = VuoReal_makeNonzero(mixed.a);
132  return VuoColor_makeWithRGBA(mixed.r/alpha, mixed.g/alpha, mixed.b/alpha, mixed.a);
133 }
134 
136 
140 char * VuoColor_getString(const VuoColor value);
144 
149 #ifdef __cplusplus
150 }
151 #endif