LYGIA Shader Library

rgb2yuv (lygia/color/space/rgb2yuv)

Pass a color in RGB and get it in YUB

Use:

rgb2yuv(<vec3|vec4> color)

Check it on Github


#ifndef MAT_RGB2YUV
#define MAT_RGB2YUV
#ifdef YUV_SDTV
const mat3 RGB2YUV = mat3(
    0.299, -0.14713,  0.615,
    0.587, -0.28886, -0.51499,
    0.114,  0.436,   -0.10001
);
#else
const mat3 RGB2YUV = mat3(
    0.2126,  -0.09991, 0.615,
    0.7152,  -0.33609,-0.55861,
    0.0722,   0.426,  -0.05639
);
#endif
#endif

#ifndef FNC_RGB2YUV
#define FNC_RGB2YUV
vec3 rgb2yuv(const in vec3 rgb) { return RGB2YUV * rgb; }
vec4 rgb2yuv(const in vec4 rgb) { return vec4(rgb2yuv(rgb.rgb),rgb.a); }
#endif

Use:

rgb2yuv(<float3|float4> color)

Check it on Github


#ifndef MAT_RGB2YUV
#define MAT_RGB2YUV
#ifdef YUV_SDTV
static const float3x3 RGB2YUV = float3x3(
    0.299, -0.14713,  0.615,
    0.587, -0.28886, -0.51499,
    0.114,  0.436,   -0.10001
);
#else
static const float3x3 RGB2YUV = float3x3(
    0.2126,  -0.09991, 0.615,
    0.7152,  -0.33609,-0.55861,
    0.0722,   0.426,  -0.05639
);
#endif
#endif

#ifndef FNC_RGB2YUV
#define FNC_RGB2YUV
float3 rgb2yuv(in float3 rgb) { return mul(RGB2YUV, rgb); }
float4 rgb2yuv(in float4 rgb) { return float4(rgb2yuv(rgb.rgb),rgb.a); }
#endif

Use:

rgb2yuv(<float3|float4> color)

Check it on Github


#ifndef MAT_RGB2YUV
#define MAT_RGB2YUV
#ifdef YUV_SDTV
constant matrix<float, 3, 3> RGB2YUV = matrix<float, 3, 3>(
    0.299, -0.14713,  0.615,
    0.587, -0.28886, -0.51499,
    0.114,  0.436,   -0.10001
);
#else
constant matrix<float, 3, 3> RGB2YUV = matrix<float, 3, 3>(
    0.2126,  -0.09991, 0.615,
    0.7152,  -0.33609,-0.55861,
    0.0722,   0.426,  -0.05639
);
#endif
#endif

#ifndef FNC_RGB2YUV
#define FNC_RGB2YUV
float3 rgb2yuv( float3 rgb) { return RGB2YUV * rgb; }
float4 rgb2yuv( float4 rgb) { return float4(rgb2yuv(rgb.rgb),rgb.a); }
#endif

Check it on Github


// #ifdef YUV_SDTV
// const RGB2YUV = mat3x3<f32>(
//     vec3f(0.299, -0.14713,  0.615),
//     vec3f(0.587, -0.28886, -0.51499),
//     vec3f(0.114,  0.436,   -0.10001)
// );
// #else
const RGB2YUV = mat3x3<f32>(
    vec3f(0.2126,  -.09991, .615),
    vec3f(0.7152,  -.33609,-.55861),
    vec3f(0.0722,   .426,  -.05639)
);
// #endif

fn rgb2yuv(rgb: vec3f) -> vec3f {
    return RGB2YUV * rgb;
}

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