LYGIA Shader Library

YCbCr2rgb (lygia/color/space/YCbCr2rgb)

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

Use:

YCbCr2rgb(<vec3|vec4> color)

Check it on Github


#ifndef FNC_YCBCR2RGB
#define FNC_YCBCR2RGB
vec3 YCbCr2rgb(const in vec3 ycbcr) {
    float cb = ycbcr.y - .5;
    float cr = ycbcr.z - .5;
    float y = ycbcr.x;
    float r = 1.402 * cr;
    float g = -.344 * cb - .714 * cr;
    float b = 1.772 * cb;
    return vec3(r, g, b) + y;
}

vec4 YCbCr2rgb(const in vec4 ycbcr) {
    return vec4(YCbCr2rgb(ycbcr.rgb),ycbcr.a);
}
#endif

Use:

YCbCr2rgb(<float3|float4> color)

Check it on Github


#ifndef FNC_YCBCR2RGB
#define FNC_YCBCR2RGB
float3 YCbCr2rgb(in float3 ycbcr) {
    float cb = ycbcr.y - .5;
    float cr = ycbcr.z - .5;
    float y = ycbcr.x;
    float r = 1.402 * cr;
    float g = -.344 * cb - .714 * cr;
    float b = 1.772 * cb;
    return float3(r, g, b) + y;
}

float4 YCbCr2rgb(in float4 ycbcr) {
    return float4(YCbCr2rgb(ycbcr.rgb),ycbcr.a);
}
#endif

Use:

YCbCr2rgb(<float3|float4> color)

Check it on Github


#ifndef FNC_YCBCR2RGB
#define FNC_YCBCR2RGB
float3 YCbCr2rgb( float3 ycbcr) {
    float cb = ycbcr.y - .5;
    float cr = ycbcr.z - .5;
    float y = ycbcr.x;
    float r = 1.402 * cr;
    float g = -.344 * cb - .714 * cr;
    float b = 1.772 * cb;
    return float3(r, g, b) + y;
}

float4 YCbCr2rgb( float4 ycbcr) {
    return float4(YCbCr2rgb(ycbcr.rgb),ycbcr.a);
}
#endif

Check it on Github


fn YCbCr2rgb(ycbcr: vec3f) -> vec3f {
    let cb = ycbcr.y - 0.5;
    let cr = ycbcr.z - 0.5;
    let y = ycbcr.x;
    let r = 1.402 * cr;
    let g = -0.344 * cb - 0.714 * cr;
    let b = 1.772 * cb;
    return vec3f(r, g, b) + y;
}

Licenses

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