22 "description" :
"A color, with component values specifying red, green, blue, and alpha (opacity).",
23 "keywords" : [
"rgba" ],
53 json_type t = json_object_get_type(js);
54 if (t == json_type_string)
56 const char *s = json_object_get_string(js);
59 size_t len = strlen(s);
65 color.r = (float)r / 15;
66 color.g = (float)g / 15;
67 color.b = (float)b / 15;
76 color.r = (float)r / 15;
77 color.g = (float)g / 15;
78 color.b = (float)b / 15;
79 color.a = (float)a / 15;
86 color.r = (float)r / 255;
87 color.g = (float)g / 255;
88 color.b = (float)b / 255;
97 color.r = (float)r / 255;
98 color.g = (float)g / 255;
99 color.b = (float)b / 255;
100 color.a = (float)a / 255;
107 sscanf(s,
"%20g, %20g, %20g, %20g", &color.r, &color.g, &color.b, &color.a);
111 else if (t == json_type_array)
113 int len = json_object_array_length(js);
115 color.r = json_object_get_double(json_object_array_get_idx(js, 0));
117 color.g = json_object_get_double(json_object_array_get_idx(js, 1));
119 color.b = json_object_get_double(json_object_array_get_idx(js, 2));
121 color.a = json_object_get_double(json_object_array_get_idx(js, 3));
128 if (json_object_object_get_ex(js,
"r", &o))
131 if (json_object_object_get_ex(js,
"g", &o))
134 if (json_object_object_get_ex(js,
"b", &o))
137 if (json_object_object_get_ex(js,
"a", &o))
167 return VuoText_format(
"<span style='background-color:#%02x%02x%02x;'> </span> %4.02f, %4.02f, %4.02f, %4.02f",
171 value.r, value.g, value.b, value.a);
181 th,td { text-align: right; }
182 td { font-weight: normal; }
183 .left { text-align: left; }
185 <table cellspacing=6>
187 <td
class=
'left'><span style=
'background-color:%s;'> </span></td>
195 <td width=40>%4.03f</td>
196 <td width=40>%4.03f</td>
197 <td width=40>%4.03f</td>
198 <td width=40>%4.03f</td>
209 <td
class=
'left' colspan=4> <code>%s</code></td>
217 VuoText hexWithOptionalAlpha = hex;
224 value.r, value.g, value.b, value.a,
267 if (saturation < 0.00001)
268 r = g = b = luminosity;
271 VuoReal hueWrapped = fmod(hue, 1);
272 float (^hue2rgb)(
float p,
float q,
float t) = ^(
float p,
float q,
float t) {
273 if (t < 0.f) t += 1.f;
274 if (t > 1.f) t -= 1.f;
275 if (t < 1.f/6.f)
return p + (q - p) * 6.f * t;
276 if (t < 1.f/2.f)
return q;
277 if (t < 2.f/3.f)
return p + (q - p) * (2.f/3.f - t) * 6.f;
283 float q = luminosity < 0.5f ? l * (1.f + s) : l + s - l * s;
284 float p = 2.f * l - q;
285 r = hue2rgb(p, q, hueWrapped + 1.f/3.f);
286 g = hue2rgb(p, q, hueWrapped);
287 b = hue2rgb(p, q, hueWrapped - 1.f/3.f);
305 float max = fmax(r, fmax(g, b));
306 float min = fmin(r, fmin(g, b));
307 *h = *s = *l = (max + min) / 2.f;
316 *s = *l > 0.5f ? d / (2.f - max - min) : d / (max + min);
318 *h = (g - b) / d + (g < b ? 6.f : 0.f);
320 *h = (b - r) / d + 2.f;
322 *h = (r - g) / d + 4.f;
332 float max = fmax(color.r, fmax(color.g, color.b));
333 float min = fmin(color.r, fmin(color.g, color.b));
334 return (max + min) / 2.;
346 for (
unsigned long i = 1; i <= colorCount; ++i)
349 result.r += color.r * color.a;
350 result.g += color.g * color.a;
351 result.b += color.b * color.a;
355 if (result.a < 0.00001)
358 result.r /= result.a;
359 result.g /= result.a;
360 result.b /= result.a;
361 result.a /= colorCount;
379 for (
size_t i = 0; i < itemCount; ++i)
396 if (type == VuoThresholdType_Rec601)
397 return c.r * .299 + c.g * .587 + c.b * .114;
398 else if (type == VuoThresholdType_Rec709)
400 pow(c.r, 2.2) * .2126
401 + pow(c.g, 2.2) * .7152
402 + pow(c.b, 2.2) * .0722,
404 else if (type == VuoThresholdType_Desaturate)
405 return (
MAX(c.r,
MAX(c.g, c.b)) +
MIN(c.r,
MIN(c.g, c.b))) / 2.;
406 else if (type == VuoThresholdType_RGBAverage)
407 return (c.r + c.g + c.b) / 3.;
408 else if (type == VuoThresholdType_RGBMaximum)
409 return MAX(c.r,
MAX(c.g, c.b));
410 else if (type == VuoThresholdType_RGBMinimum)
411 return MIN(c.r,
MIN(c.g, c.b));
412 else if (type == VuoThresholdType_Red)
414 else if (type == VuoThresholdType_Green)
416 else if (type == VuoThresholdType_Blue)
438 return fabs(a.r - b.r) <= tolerance
439 && fabs(a.g - b.g) <= tolerance
440 && fabs(a.b - b.b) <= tolerance
441 && fabs(a.a - b.a) <= tolerance;
449 if (a.r < b.r)
return true;
450 if (a.r > b.r)
return false;
452 if (a.g < b.g)
return true;
453 if (a.g > b.g)
return false;
455 if (a.b < b.b)
return true;
456 if (a.b > b.b)
return false;
458 if (a.a < b.a)
return true;