## rgb2YCbCr (`lygia`/`color`/`space`/`rgb2YCbCr`)

convert RGB to YCbCr according to https://en.wikipedia.org/wiki/YCbCr

Use:

``````rgb2YCbCr(<vec3|vec4> color)
``````

Check it on Github

``````
#ifndef FNC_RGB2YCBCR
#define FNC_RGB2YCBCR
vec3 rgb2YCbCr(in vec3 rgb){
float y = dot(rgb, vec3(.299, .587, .114));
float cb = .5 + dot(rgb, vec3(-.168736, -.331264, .5));
float cr = .5 + dot(rgb, vec3(.5, -.418688, -.081312));
return vec3(y, cb, cr);
}

vec4 rgb2YCbCr(in vec4 rgb) {
return vec4(rgb2YCbCr(rgb.rgb),rgb.a);
}
#endif
``````

Use:

``````rgb2YCbCr(<float3|float4> color)
``````

Check it on Github

``````
#ifndef FNC_RGB2YCBCR
#define FNC_RGB2YCBCR
float3 rgb2YCbCr(in float3 rgb){
float y = dot(rgb, float3(.299, .587, .114));
float cb = .5 + dot(rgb, float3(-.168736, -.331264, .5));
float cr = .5 + dot(rgb, float3(.5, -.418688, -.081312));
return float3(y, cb, cr);
}

float4 rgb2YCbCr(in float4 rgb) {
return float4(rgb2YCbCr(rgb.rgb),rgb.a);
}
#endif
``````

Check it on Github

``````fn rgb2YCbCr(rgb: vec3<f32>) -> vec3<f32> {
let y = dot(rgb, vec3<f32>(0.299, 0.587, 0.114));
let cb = 0.5 + dot(rgb, vec3<f32>(-0.168736, -0.331264, 0.5));
let cr = 0.5 + dot(rgb, vec3<f32>(0.5, -0.418688, -0.081312));
return vec3<f32>(y, cb, cr);
}

``````