12 float cmax, cmin, h, s, v, cdelta;
15 cmax =
max(rgb[0],
max(rgb[1], rgb[2]));
16 cmin =
min(rgb[0],
min(rgb[1], rgb[2]));
32 c = (
float3(cmax) - rgb.xyz) / cdelta;
37 else if (rgb.
y == cmax) {
38 h = 2.0f + c[0] - c[2];
41 h = 4.0f + c[1] - c[0];
51 outcol =
float4(h, s, v, rgb.
w);
57 float i, f, p, q, t, h, s, v;
77 q = v * (1.0f - (s * f));
78 t = v * (1.0f - (s * (1.0f - f)));
106 float cmax, cmin, h, s, l;
108 cmax =
max(rgb[0],
max(rgb[1], rgb[2]));
109 cmin =
min(rgb[0],
min(rgb[1], rgb[2]));
110 l =
min(1.0f, (cmax + cmin) / 2.0f);
116 float cdelta = cmax - cmin;
117 s = l > 0.5f ? cdelta / (2.0f - cmax - cmin) : cdelta / (cmax + cmin);
118 if (cmax == rgb[0]) {
119 h = (rgb[1] - rgb[2]) / cdelta + (rgb[1] < rgb[2] ? 6.0f : 0.0f);
121 else if (cmax == rgb[1]) {
122 h = (rgb[2] - rgb[0]) / cdelta + 2.0f;
125 h = (rgb[0] - rgb[1]) / cdelta + 4.0f;
130 outcol =
float4(h, s, l, rgb.
w);
136 float nr, ng, nb, chroma, h, s, l;
142 nr =
abs(h * 6.0f - 3.0f) - 1.0f;
143 ng = 2.0f -
abs(h * 6.0f - 2.0f);
144 nb = 2.0f -
abs(h * 6.0f - 4.0f);
146 nr =
clamp(nr, 0.0f, 1.0f);
147 nb =
clamp(nb, 0.0f, 1.0f);
148 ng =
clamp(ng, 0.0f, 1.0f);
150 chroma = (1.0f -
abs(2.0f * l - 1.0f)) * s;
153 (nr - 0.5f) * chroma + l, (ng - 0.5f) * chroma + l, (nb - 0.5f) * chroma + l, hsl.
w);
162 ycca.xyz -=
float3(16.0f, 128.0f, 128.0f);
163 color.rgb =
float3x3(1.164f, 1.164f, 1.164f, 0.0f, -0.392f, 2.017f, 1.596f, -0.813f, 0.0f) *
173 ycca.xyz -=
float3(16.0f, 128.0f, 128.0f);
174 color.rgb =
float3x3(1.164f, 1.164f, 1.164f, 0.0f, -0.213f, 2.115f, 1.793f, -0.534f, 0.0f) *
184 color.rgb =
float3x3(1.0f, 1.0f, 1.0f, 0.0f, -0.34414f, 1.772f, 1.402f, -0.71414f, 0.0f) *
186 color.rgb +=
float3(-179.456f, 135.45984f, -226.816f);
197 ycca.xyz =
float3x3(0.257f, -0.148f, 0.439f, 0.504f, -0.291f, -0.368f, 0.098f, 0.439f, -0.071f) *
199 ycca.xyz +=
float3(16.0f, 128.0f, 128.0f);
208 ycca.xyz =
float3x3(0.183f, -0.101f, 0.439f, 0.614f, -0.338f, -0.399f, 0.062f, 0.439f, -0.040f) *
210 ycca.xyz +=
float3(16.0f, 128.0f, 128.0f);
220 0.299f, -0.16874f, 0.5f, 0.587f, -0.33126f, -0.41869f, 0.114f, 0.5f, -0.08131f) *
222 ycca.xyz +=
float3(0.0f, 128.0f, 128.0f);
232 color.rgb =
float3x3(1.0f, 1.0f, 1.0f, 0.0f, -0.21482f, 2.12798f, 1.28033f, -0.38059f, 0.0f) *
244 0.2126f, -0.09991f, 0.615f, 0.7152f, -0.33609f, -0.55861f, 0.0722f, 0.436f, -0.05639f) *
254 result =
float4(color.rgb, 1.0f);
260 result =
float4(color.rgb * color.a, color.a);
266 if (color.a == 0.0f || color.a == 1.0f) {
270 result =
float4(color.rgb / color.a, color.a);
276 if (color < 0.0031308f) {
277 return (color < 0.0f) ? 0.0f : color * 12.92f;
280 return 1.055f *
pow(color, 1.0f / 2.4f) - 0.055f;
291 if (color < 0.04045f) {
292 return (color < 0.0f) ? 0.0f : color * (1.0f / 12.92f);
295 return pow((color + 0.055f) * (1.0f / 1.055f), 2.4f);
306 return dot(color, luminance_coefficients);
void color_alpha_unpremultiply(float4 color, float4 &result)
float linear_rgb_to_srgb(float color)
void hsl_to_rgb(float4 hsl, float4 &outcol)
float srgb_to_linear_rgb(float color)
void ycca_to_rgba_jpeg(float4 ycca, float4 &color)
void rgba_to_ycca_itu_601(float4 rgba, float4 &ycca)
void rgb_to_hsv(float4 rgb, float4 &outcol)
void rgba_to_yuva_itu_709(float4 rgba, float4 &yuva)
void color_alpha_clear(float4 color, float4 &result)
void rgba_to_ycca_itu_709(float4 rgba, float4 &ycca)
float get_luminance(float3 color, float3 luminance_coefficients)
void hsv_to_rgb(float4 hsv, float4 &outcol)
void ycca_to_rgba_itu_601(float4 ycca, float4 &color)
void rgba_to_ycca_jpeg(float4 rgba, float4 &ycca)
void ycca_to_rgba_itu_709(float4 ycca, float4 &color)
void color_alpha_premultiply(float4 color, float4 &result)
void rgb_to_hsl(float4 rgb, float4 &outcol)
void yuva_to_rgba_itu_709(float4 yuva, float4 &color)
float dot(VecOp< float, D >, VecOp< float, D >) RET
constexpr T clamp(T, U, U) RET