Skip to content
Snippets Groups Projects

Color management architecture: color profiles

Merged Pekka Paalanen requested to merge pq/weston:mr/color-output into main
All threads resolved!
4 files
+ 54
6
Compare changes
  • Side-by-side
  • Inline
Files
4
  • 25a4bb53
    Add a new shader requirements bit input_is_premult which says whether
    the texture sampling results in premultiplied alpha or not. Currently
    this can be deduced fully from the shader texture variant, but in the
    future there might a protocol extension to explicitly control it. Hence
    the need for a new bit.
    
    yuva2rgba() is changed to produce straight alpha always. This makes
    sample_input_texture() sometimes produce straight or premultiplied
    alpha. The input_is_premult bit needs to match sample_input_texture()
    behavior. Doing this should save three multiplications in the shader for
    straight alpha formats.
    
    pipeline_premult() function is added, because in the future another
    pipeline working on straight alpha will be needed.
    
    Signed-off-by: default avatarPekka Paalanen <pekka.paalanen@collabora.com>
@@ -53,6 +53,7 @@ precision mediump float;
* snippet.
*/
compile_const int c_variant = DEF_VARIANT;
compile_const bool c_input_is_premult = DEF_INPUT_IS_PREMULT;
compile_const bool c_green_tint = DEF_GREEN_TINT;
vec4
@@ -79,7 +80,6 @@ yuva2rgba(vec4 yuva)
color_out.g = Y - 0.39176229 * su - 0.81296764 * sv;
color_out.b = Y + 2.01723214 * su;
color_out.rgb *= yuva.w;
color_out.a = yuva.w;
return color_out;
@@ -141,16 +141,31 @@ sample_input_texture()
return yuva2rgba(yuva);
}
vec4
pipeline_premult(vec4 color, compile_const bool input_is_premult)
{
/* Ensure premultiplied alpha, apply view alpha (opacity) */
if (input_is_premult) {
color *= alpha;
} else {
color.a *= alpha;
color.rgb *= color.a;
}
return color;
}
void
main()
{
vec4 color;
/* Electrical (non-linear) RGBA values, pre-multiplied */
/* Electrical (non-linear) RGBA values, may be premult or not */
color = sample_input_texture();
/* View alpha (opacity) */
color *= alpha;
color = pipeline_premult(color, c_input_is_premult);
/* color is guaranteed premult here */
if (c_green_tint)
color = vec4(0.0, 0.3, 0.0, 0.2) + color * 0.8;
Loading