From cf85191cb7322b9cfeda3a872ef22e6df4f97860 Mon Sep 17 00:00:00 2001 From: Philip Sequeira Date: Sat, 12 Nov 2016 13:19:40 -0500 Subject: vo_opengl: blend against background color for --alpha=blend Do it after color management, etc. so that it matches the color drawn in the margins. --- DOCS/man/options.rst | 3 ++- video/out/opengl/video.c | 22 ++++++++++++++-------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/DOCS/man/options.rst b/DOCS/man/options.rst index 731da7836e..20744a0323 100644 --- a/DOCS/man/options.rst +++ b/DOCS/man/options.rst @@ -4581,7 +4581,8 @@ The following video options are currently all specific to ``--vo=opengl`` and blend-tiles Blend the frame against a 16x16 gray/white tiles background (default). blend - Blend the frame against a black background. + Blend the frame against the background color (``--background``, normally + black). yes Try to create a framebuffer with alpha component. This only makes sense if the video contains alpha information (which is extremely rare). May diff --git a/video/out/opengl/video.c b/video/out/opengl/video.c index a59a8e4ffa..498d89259e 100644 --- a/video/out/opengl/video.c +++ b/video/out/opengl/video.c @@ -2013,8 +2013,6 @@ static void pass_convert_yuv(struct gl_video *p) p->components = 3; if (!p->has_alpha || p->opts.alpha_mode == ALPHA_NO) { GLSL(color.a = 1.0;) - } else if (p->opts.alpha_mode == ALPHA_BLEND) { - GLSL(color = vec4(color.rgb * color.a, 1.0);) } else { // alpha present in image p->components = 4; GLSL(color = vec4(color.rgb * color.a, color.a);) @@ -2537,12 +2535,20 @@ static void pass_draw_to_screen(struct gl_video *p, int fbo) pass_colormanage(p, p->image_params.color, false); - // Draw checkerboard pattern to indicate transparency - if (p->has_alpha && p->opts.alpha_mode == ALPHA_BLEND_TILES) { - GLSLF("// transparency checkerboard\n"); - GLSL(bvec2 tile = lessThan(fract(gl_FragCoord.xy / 32.0), vec2(0.5));) - GLSL(vec3 background = vec3(tile.x == tile.y ? 1.0 : 0.75);) - GLSL(color.rgb = mix(background, color.rgb, color.a);) + if (p->has_alpha){ + if (p->opts.alpha_mode == ALPHA_BLEND_TILES) { + // Draw checkerboard pattern to indicate transparency + GLSLF("// transparency checkerboard\n"); + GLSL(bvec2 tile = lessThan(fract(gl_FragCoord.xy / 32.0), vec2(0.5));) + GLSL(vec3 background = vec3(tile.x == tile.y ? 1.0 : 0.75);) + GLSL(color.rgb = mix(background, color.rgb, color.a);) + } else if (p->opts.alpha_mode == ALPHA_BLEND) { + // Blend into background color (usually black) + struct m_color c = p->opts.background; + GLSLF("vec4 background = vec4(%f, %f, %f, %f);\n", + c.r / 255.0, c.g / 255.0, c.b / 255.0, c.a / 255.0); + GLSL(color = mix(background, vec4(color.rgb, 1.0), color.a);) + } } pass_opt_hook_point(p, "OUTPUT", NULL); -- cgit v1.2.3