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>
209 <td
class=
'left' colspan=4> %s</td>
218 value.r, value.g, value.b, value.a,
261 if (saturation < 0.00001)
262 r = g = b = luminosity;
265 VuoReal hueWrapped = fmod(hue, 1);
266 float (^hue2rgb)(
float p,
float q,
float t) = ^(
float p,
float q,
float t) {
267 if (t < 0.f) t += 1.f;
268 if (t > 1.f) t -= 1.f;
269 if (t < 1.f/6.f)
return p + (q - p) * 6.f * t;
270 if (t < 1.f/2.f)
return q;
271 if (t < 2.f/3.f)
return p + (q - p) * (2.f/3.f - t) * 6.f;
277 float q = luminosity < 0.5f ? l * (1.f + s) : l + s - l * s;
278 float p = 2.f * l - q;
279 r = hue2rgb(p, q, hueWrapped + 1.f/3.f);
280 g = hue2rgb(p, q, hueWrapped);
281 b = hue2rgb(p, q, hueWrapped - 1.f/3.f);
299 float max = fmax(r, fmax(g, b));
300 float min = fmin(r, fmin(g, b));
301 *h = *s = *l = (max + min) / 2.f;
310 *s = *l > 0.5f ? d / (2.f - max - min) : d / (max + min);
312 *h = (g - b) / d + (g < b ? 6.f : 0.f);
314 *h = (b - r) / d + 2.f;
316 *h = (r - g) / d + 4.f;
326 float max = fmax(color.r, fmax(color.g, color.b));
327 float min = fmin(color.r, fmin(color.g, color.b));
328 return (max + min) / 2.;
355 *k = 1. -
MAX(
MAX(r, g), b);
360 *c = (1. - r - *k) / (1. - *k);
361 *m = (1. - g - *k) / (1. - *k);
362 *y = (1. - b - *k) / (1. - *k);
376 for (
unsigned long i = 1; i <= colorCount; ++i)
379 result.r += color.r * color.a;
380 result.g += color.g * color.a;
381 result.b += color.b * color.a;
385 if (result.a < 0.00001)
388 result.r /= result.a;
389 result.g /= result.a;
390 result.b /= result.a;
391 result.a /= colorCount;
409 for (
size_t i = 0; i < itemCount; ++i)
426 if (type == VuoThresholdType_Rec601)
427 return c.r * .299 + c.g * .587 + c.b * .114;
428 else if (type == VuoThresholdType_Rec709)
430 pow(c.r, 2.2) * .2126
431 + pow(c.g, 2.2) * .7152
432 + pow(c.b, 2.2) * .0722,
434 else if (type == VuoThresholdType_Desaturate)
435 return (
MAX(c.r,
MAX(c.g, c.b)) +
MIN(c.r,
MIN(c.g, c.b))) / 2.;
436 else if (type == VuoThresholdType_RGBAverage)
437 return (c.r + c.g + c.b) / 3.;
438 else if (type == VuoThresholdType_RGBMaximum)
439 return MAX(c.r,
MAX(c.g, c.b));
440 else if (type == VuoThresholdType_RGBMinimum)
441 return MIN(c.r,
MIN(c.g, c.b));
442 else if (type == VuoThresholdType_Red)
444 else if (type == VuoThresholdType_Green)
446 else if (type == VuoThresholdType_Blue)
468 return fabs(a.r - b.r) <= tolerance
469 && fabs(a.g - b.g) <= tolerance
470 && fabs(a.b - b.b) <= tolerance
471 && fabs(a.a - b.a) <= tolerance;
479 if (a.r < b.r)
return true;
480 if (a.r > b.r)
return false;
482 if (a.g < b.g)
return true;
483 if (a.g > b.g)
return false;
485 if (a.b < b.b)
return true;
486 if (a.b > b.b)
return false;
488 if (a.a < b.a)
return true;