Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/FFmpeg/FFmpeg.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLynne <dev@lynne.ee>2020-04-23 20:08:14 +0300
committerLynne <dev@lynne.ee>2020-04-23 20:23:45 +0300
commitf66ac83c22d8c088832ce8df922b08a0caa11833 (patch)
tree99a9c21af628580f19b0c07fdc9c9d1a4b7d52ab /libavfilter/vf_overlay_vulkan.c
parent4e81324362c3ddff0b9424a41387f8e380c792c6 (diff)
overlay_vulkan: add support for overlaying images with an alpha channel
Diffstat (limited to 'libavfilter/vf_overlay_vulkan.c')
-rw-r--r--libavfilter/vf_overlay_vulkan.c25
1 files changed, 23 insertions, 2 deletions
diff --git a/libavfilter/vf_overlay_vulkan.c b/libavfilter/vf_overlay_vulkan.c
index 7cedcc6e88..83cfae40e2 100644
--- a/libavfilter/vf_overlay_vulkan.c
+++ b/libavfilter/vf_overlay_vulkan.c
@@ -59,11 +59,27 @@ static const char overlay_noalpha[] = {
C(0, } )
};
+static const char overlay_alpha[] = {
+ C(0, void overlay_alpha_opaque(int i, ivec2 pos) )
+ C(0, { )
+ C(1, vec4 res = texture(main_img[i], pos); )
+ C(1, if ((o_offset[i].x <= pos.x) && (o_offset[i].y <= pos.y) &&
+ (pos.x < (o_offset[i].x + o_size[i].x)) &&
+ (pos.y < (o_offset[i].y + o_size[i].y))) { )
+ C(2, vec4 ovr = texture(overlay_img[i], pos - o_offset[i]); )
+ C(2, res = ovr * ovr.a + res * (1.0f - ovr.a); )
+ C(2, res.a = 1.0f; )
+ C(2, imageStore(output_img[i], pos, res); )
+ C(1, } )
+ C(1, imageStore(output_img[i], pos, res); )
+ C(0, } )
+};
+
static av_cold int init_filter(AVFilterContext *ctx)
{
int err;
OverlayVulkanContext *s = ctx->priv;
- VkSampler *sampler = ff_vk_init_sampler(ctx, 1, VK_FILTER_LINEAR);
+ VkSampler *sampler = ff_vk_init_sampler(ctx, 1, VK_FILTER_NEAREST);
if (!sampler)
return AVERROR_EXTERNAL;
@@ -73,6 +89,7 @@ static av_cold int init_filter(AVFilterContext *ctx)
{ /* Create the shader */
const int planes = av_pix_fmt_count_planes(s->vkctx.output_format);
+ const int ialpha = av_pix_fmt_desc_get(s->vkctx.input_format)->flags & AV_PIX_FMT_FLAG_ALPHA;
VulkanDescriptorSetBinding desc_i[3] = {
{
@@ -126,12 +143,16 @@ static av_cold int init_filter(AVFilterContext *ctx)
RET(ff_vk_add_descriptor_set(ctx, s->pl, shd, &desc_b, 1, 0)); /* set 1 */
GLSLD( overlay_noalpha );
+ GLSLD( overlay_alpha );
GLSLC(0, void main() );
GLSLC(0, { );
GLSLC(1, ivec2 pos = ivec2(gl_GlobalInvocationID.xy); );
GLSLF(1, int planes = %i; ,planes);
GLSLC(1, for (int i = 0; i < planes; i++) { );
- GLSLC(2, overlay_noalpha(i, pos); );
+ if (ialpha)
+ GLSLC(2, overlay_alpha_opaque(i, pos); );
+ else
+ GLSLC(2, overlay_noalpha(i, pos); );
GLSLC(1, } );
GLSLC(0, } );