22 "description" :
"A color, with component values specifying red, green, blue, and alpha (opacity).",
23 "keywords" : [
"rgba" ],
51 json_type t = json_object_get_type(js);
52 if (t == json_type_string)
54 const char *s = json_object_get_string(js);
57 size_t len = strlen(s);
63 color.r = (float)r / 15;
64 color.g = (float)g / 15;
65 color.b = (float)b / 15;
74 color.r = (float)r / 15;
75 color.g = (float)g / 15;
76 color.b = (float)b / 15;
77 color.a = (float)a / 15;
84 color.r = (float)r / 255;
85 color.g = (float)g / 255;
86 color.b = (float)b / 255;
95 color.r = (float)r / 255;
96 color.g = (float)g / 255;
97 color.b = (float)b / 255;
98 color.a = (float)a / 255;
105 sscanf(s,
"%20g, %20g, %20g, %20g", &color.r, &color.g, &color.b, &color.a);
109 else if (t == json_type_array)
111 int len = json_object_array_length(js);
113 color.r = json_object_get_double(json_object_array_get_idx(js, 0));
115 color.g = json_object_get_double(json_object_array_get_idx(js, 1));
117 color.b = json_object_get_double(json_object_array_get_idx(js, 2));
119 color.a = json_object_get_double(json_object_array_get_idx(js, 3));
126 if (json_object_object_get_ex(js,
"r", &o))
129 if (json_object_object_get_ex(js,
"g", &o))
132 if (json_object_object_get_ex(js,
"b", &o))
135 if (json_object_object_get_ex(js,
"a", &o))
165 return VuoText_format(
"<span style='background-color:#%02x%02x%02x;'> </span> %4.02f, %4.02f, %4.02f, %4.02f",
169 value.r, value.g, value.b, value.a);
179 th,td { text-align: right; }
180 td { font-weight: normal; }
181 .left { text-align: left; }
183 <table cellspacing=6>
185 <td
class=
'left'><span style=
'background-color:%s;'> </span></td>
207 <td
class=
'left' colspan=4> %s</td>
216 value.r, value.g, value.b, value.a,
259 if (saturation < 0.00001)
260 r = g = b = luminosity;
263 VuoReal hueWrapped = fmod(hue, 1);
264 float (^hue2rgb)(
float p,
float q,
float t) = ^(
float p,
float q,
float t) {
265 if (t < 0.f) t += 1.f;
266 if (t > 1.f) t -= 1.f;
267 if (t < 1.f/6.f)
return p + (q - p) * 6.f * t;
268 if (t < 1.f/2.f)
return q;
269 if (t < 2.f/3.f)
return p + (q - p) * (2.f/3.f - t) * 6.f;
275 float q = luminosity < 0.5f ? l * (1.f + s) : l + s - l * s;
276 float p = 2.f * l - q;
277 r = hue2rgb(p, q, hueWrapped + 1.f/3.f);
278 g = hue2rgb(p, q, hueWrapped);
279 b = hue2rgb(p, q, hueWrapped - 1.f/3.f);
297 float max = fmax(r, fmax(g, b));
298 float min = fmin(r, fmin(g, b));
299 *h = *s = *l = (max + min) / 2.f;
308 *s = *l > 0.5f ? d / (2.f - max - min) : d / (max + min);
310 *h = (g - b) / d + (g < b ? 6.f : 0.f);
312 *h = (b - r) / d + 2.f;
314 *h = (r - g) / d + 4.f;
324 float max = fmax(color.r, fmax(color.g, color.b));
325 float min = fmin(color.r, fmin(color.g, color.b));
326 return (max + min) / 2.;
353 *k = 1. -
MAX(
MAX(r, g), b);
358 *c = (1. - r - *k) / (1. - *k);
359 *m = (1. - g - *k) / (1. - *k);
360 *y = (1. - b - *k) / (1. - *k);
374 for (
unsigned long i = 1; i <= colorCount; ++i)
377 result.r += color.r * color.a;
378 result.g += color.g * color.a;
379 result.b += color.b * color.a;
383 if (result.a < 0.00001)
386 result.r /= result.a;
387 result.g /= result.a;
388 result.b /= result.a;
389 result.a /= colorCount;
407 for (
size_t i = 0; i < itemCount; ++i)
424 if (type == VuoThresholdType_Rec601)
425 return c.r * .299 + c.g * .587 + c.b * .114;
426 else if (type == VuoThresholdType_Rec709)
428 pow(c.r, 2.2) * .2126
429 + pow(c.g, 2.2) * .7152
430 + pow(c.b, 2.2) * .0722,
432 else if (type == VuoThresholdType_Desaturate)
433 return (
MAX(c.r,
MAX(c.g, c.b)) +
MIN(c.r,
MIN(c.g, c.b))) / 2.;
434 else if (type == VuoThresholdType_RGBAverage)
435 return (c.r + c.g + c.b) / 3.;
436 else if (type == VuoThresholdType_RGBMaximum)
437 return MAX(c.r,
MAX(c.g, c.b));
438 else if (type == VuoThresholdType_RGBMinimum)
439 return MIN(c.r,
MIN(c.g, c.b));
440 else if (type == VuoThresholdType_Red)
442 else if (type == VuoThresholdType_Green)
444 else if (type == VuoThresholdType_Blue)
466 return fabs(a.r - b.r) <= tolerance
467 && fabs(a.g - b.g) <= tolerance
468 && fabs(a.b - b.b) <= tolerance
469 && fabs(a.a - b.a) <= tolerance;
477 if (a.r < b.r)
return true;
478 if (a.r > b.r)
return false;
480 if (a.g < b.g)
return true;
481 if (a.g > b.g)
return false;
483 if (a.b < b.b)
return true;
484 if (a.b > b.b)
return false;
486 if (a.a < b.a)
return true;