lygia
/color
/space
/rgb2YPbPr
)Pass a color in RGB and get it in YPbPr from http://www.equasys.de/colorconversion.html
Use:
<vec3|vec4> rgb2YPbPr(<vec3|vec4> color)
#ifndef MAT_RGB2PBPR
#define MAT_RGB2PBPR
#ifdef YPBPR_SDTV
const mat3 RGB2PBPR = mat3(
0.299, -0.169, 0.5,
0.587, -0.331, -0.419,
0.114, 0.5, -0.081
);
#else
const mat3 RGB2PBPR = mat3(
0.2126, -0.1145721060573399, 0.5,
0.7152, -0.3854278939426601, -0.4541529083058166,
0.0722, 0.5, -0.0458470916941834
);
#endif
#endif
#ifndef FNC_RGB2YPBPR
#define FNC_RGB2YPBPR
vec3 rgb2YPbPr(const in vec3 rgb) { return RGB2PBPR * rgb; }
vec4 rgb2YPbPr(const in vec4 rgb) { return vec4(rgb2YPbPr(rgb.rgb),rgb.a); }
#endif
Use:
<float3|float4> rgb2YPbPr(<float3|float4> color)
#ifndef MAT_RGB2PBPR
#define MAT_RGB2PBPR
#ifdef YPBPR_SDTV
static const float3x3 RGB2PBPR = float3x3(
.299, -.169, .5,
.587, -.331, -.419,
.114, .5, -.081
);
#else
static const float3x3 RGB2PBPR = float3x3(
0.2126, -0.1145721060573399, 0.5,
0.7152, -0.3854278939426601, -0.4541529083058166,
0.0722, 0.5, -0.0458470916941834
);
#endif
#endif
#ifndef FNC_RGB2YPBPR
#define FNC_RGB2YPBPR
float3 rgb2YPbPr(in float3 rgb) { return mul(RGB2PBPR, rgb); }
float4 rgb2YPbPr(in float4 rgb) { return float4(rgb2YPbPr(rgb.rgb),rgb.a); }
#endif
Use:
<float3|float4> rgb2YPbPr(<float3|float4> color)
#ifndef MAT_RGB2PBPR
#define MAT_RGB2PBPR
#ifdef YPBPR_SDTV
constant matrix<float, 3, 3> RGB2PBPR = matrix<float, 3, 3>(
0.299, -0.169, 0.5,
0.587, -0.331, -0.419,
0.114, 0.5, -0.081
);
#else
constant matrix<float, 3, 3> RGB2PBPR = matrix<float, 3, 3>(
0.2126, -0.1145721060573399, 0.5,
0.7152, -0.3854278939426601, -0.4541529083058166,
0.0722, 0.5, -0.0458470916941834
);
#endif
#endif
#ifndef FNC_RGB2YPBPR
#define FNC_RGB2YPBPR
float3 rgb2YPbPr( float3 rgb) { return RGB2PBPR * rgb; }
float4 rgb2YPbPr( float4 rgb) { return float4(rgb2YPbPr(rgb.rgb),rgb.a); }
#endif
// #ifdef YPBPR_SDTV
// const RGB2YPBPR = mat3x3<f32>(
// vec3f(0.299, -0.169, 0.5),
// vec3f(0.587, -0.331, -0.419),
// vec3f(0.114, 0.5, -0.081)
// );
// #else
const RGB2YPBPR = mat3x3<f32>(
vec3f(0.2126, -0.1145721060573399, 0.5),
vec3f(0.7152, -0.3854278939426601, -0.4541529083058166),
vec3f(0.0722, 0.5, -0.0458470916941834)
);
// #endif
fn rgb2YPbPr(rgb: vec3f) -> vec3f { return RGB2YPBPR * rgb; }
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.
Sign up for the news letter bellow, joing the LYGIA's channel on Discord or follow the Github repository