Vuo 2.4.4
Loading...
Searching...
No Matches
VuoColor.h
Go to the documentation of this file.
1
10#ifndef VuoColor_h
11#define VuoColor_h
12
13#include "VuoBoolean.h"
14#include "VuoReal.h"
15#include "VuoText.h"
16
17#ifdef __cplusplus
18extern "C" {
19#endif
20
36typedef struct
37{
38 float r,g,b,a;
39} VuoColor;
40
41#define VuoColor_SUPPORTS_COMPARISON
42#include "VuoList_VuoColor.h"
43
44VuoColor VuoColor_makeFromJson(struct json_object * js);
45struct json_object * VuoColor_getJson(const VuoColor value);
46char *VuoColor_getShortSummary(const VuoColor value);
47char *VuoColor_getSummary(const VuoColor value);
48
49bool VuoColor_areEqual(const VuoColor a, const VuoColor b);
50bool VuoColor_isLessThan(const VuoColor a, const VuoColor b);
51
52bool VuoColor_areEqualWithinTolerance(const VuoColor a, const VuoColor b, const float tolerance);
53
61static inline VuoColor VuoColor_makeWithRGBA(VuoReal r, VuoReal g, VuoReal b, VuoReal a) __attribute__((const));
63{
64 VuoColor c = {(float)r,(float)g,(float)b,(float)a};
65 return c;
66}
67
75static inline void VuoColor_getRGBA(VuoColor color, VuoReal *r, VuoReal *g, VuoReal *b, VuoReal *a)
76{
77 *r = color.r;
78 *g = color.g;
79 *b = color.b;
80 *a = color.a;
81}
82
86static inline VuoColor VuoColor_premultiply(VuoColor c) __attribute__((const));
88{
89 return (VuoColor){ c.r*c.a, c.g*c.a, c.b*c.a, c.a };
90}
91
92VuoColor VuoColor_makeWithHSLA(VuoReal hue, VuoReal saturation, VuoReal luminosity, VuoReal alpha);
93void VuoColor_getHSLA(VuoColor color, VuoReal *h, VuoReal *s, VuoReal *l, VuoReal *a);
95
96VuoText VuoColor_getHex(VuoColor color, VuoBoolean includeAlpha);
97
99
104static inline bool VuoColor_isOpaque(VuoColor color)
105{
106 return color.a >= 1.;
107}
108
110
111VuoReal VuoColor_brightness(VuoColor color, int32_t /*VuoThresholdType*/ type);
112
116static inline VuoColor VuoColor_lerp(VuoColor a, VuoColor b, float t) __attribute__((const));
117static inline VuoColor VuoColor_lerp(VuoColor a, VuoColor b, float t)
118{
119 // Premultiply, then mix, then unpremultiply.
120 VuoColor ap = VuoColor_makeWithRGBA(a.r*a.a, a.g*a.a, a.b*a.a, a.a);
121 VuoColor bp = VuoColor_makeWithRGBA(b.r*b.a, b.g*b.a, b.b*b.a, b.a);
122
124 ap.r*(1-t) + bp.r*t,
125 ap.g*(1-t) + bp.g*t,
126 ap.b*(1-t) + bp.b*t,
127 ap.a*(1-t) + bp.a*t);
128
129 float alpha = VuoReal_makeNonzero(mixed.a);
130 return VuoColor_makeWithRGBA(mixed.r/alpha, mixed.g/alpha, mixed.b/alpha, mixed.a);
131}
132
134
137char * VuoColor_getString(const VuoColor value);
141
146#ifdef __cplusplus
147}
148#endif
149
150#endif