Vuo  2.4.0
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
17extern "C" {
18#endif
19
21typedef const struct VuoList_VuoColor_struct { void *l; } * VuoList_VuoColor;
22#define VuoList_VuoColor_TYPE_DEFINED
24
40typedef struct
41{
42 float r,g,b,a;
43} VuoColor;
44
46struct json_object * VuoColor_getJson(const VuoColor value);
47char *VuoColor_getShortSummary(const VuoColor value);
48char *VuoColor_getSummary(const VuoColor value);
49
50#define VuoColor_SUPPORTS_COMPARISON
51bool VuoColor_areEqual(const VuoColor a, const VuoColor b);
52bool VuoColor_isLessThan(const VuoColor a, const VuoColor b);
53
54bool VuoColor_areEqualWithinTolerance(const VuoColor a, const VuoColor b, const float tolerance);
55
63static 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
77static 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
88static 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
94VuoColor VuoColor_makeWithHSLA(VuoReal hue, VuoReal saturation, VuoReal luminosity, VuoReal alpha);
95void VuoColor_getHSLA(VuoColor color, VuoReal *h, VuoReal *s, VuoReal *l, VuoReal *a);
97
98VuoText VuoColor_getHex(VuoColor color, VuoBoolean includeAlpha);
99
101
106static inline bool VuoColor_isOpaque(VuoColor color)
107{
108 return color.a >= 1.;
109}
110
112
113VuoReal VuoColor_brightness(VuoColor color, int32_t /*VuoThresholdType*/ type);
114
118static inline VuoColor VuoColor_lerp(VuoColor a, VuoColor b, float t) __attribute__((const));
119static 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
140char * VuoColor_getString(const VuoColor value);
144
149#ifdef __cplusplus
150}
151#endif