LYGIA Shader Library

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(const in vec3 rgb){
    float y = dot(rgb, vec3(0.299, 0.587, 0.114));
    float cb = .5 + dot(rgb, vec3(-0.168736, -0.331264, 0.5));
    float cr = .5 + dot(rgb, vec3(0.5, -0.418688, -0.081312));
    return vec3(y, cb, cr);
}

vec4 rgb2YCbCr(const 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: vec3f) -> vec3f {
    let y = dot(rgb, vec3f(0.299, 0.587, 0.114));
    let cb = 0.5 + dot(rgb, vec3f(-0.168736, -0.331264, 0.5));
    let cr = 0.5 + dot(rgb, vec3f(0.5, -0.418688, -0.081312));
    return vec3f(y, cb, cr);
}

License

LYGIA is dual-licensed under the Prosperity License and the Patron License for sponsors and contributors.

Sponsors and contributors are automatically added to the Patron License and they can ignore the any non-commercial rule of the Prosperity Licensed software (please take a look to the exception).

It's also possible to get a permanent comercial license hook to a single and specific version of LYGIA.

Get the latest news and releases

Sign up for the news letter bellow, joing the LYGIA's channel on Discord or follow the Github repository