From 284baef71b619d4d07d9a837e0a5196e860f5e1c Mon Sep 17 00:00:00 2001
From: Wu Jianhua <jianhua.wu@intel.com>
Date: Wed, 23 Feb 2022 19:25:38 +0800
Subject: [PATCH 04/10] avfilter/vf_blend_vulkan: add negation blend mode

Use the commands below to test: (href: https://trac.ffmpeg.org/wiki/Blend)

I. make an image for test
ffmpeg -f lavfi -i color=s=256x256,geq=r='H-1-Y':g='H-1-Y':b='H-1-Y' -frames 1 \
-y -pix_fmt yuv420p test.jpg

II. blend in sw
ffmpeg -i test.jpg -vf "split[a][b];[b]transpose[b];[a][b]blend=all_mode=negation,\
pseudocolor=preset=turbo" -y negation_sw.jpg

III. blend in vulkan
ffmpeg -init_hw_device vulkan -i test.jpg -vf "split[a][b];[b]transpose[b];\
[a]hwupload[a];[b]hwupload[b];[a][b]blend_vulkan=all_mode=negation,hwdownload,\
format=yuv420p,pseudocolor=preset=turbo" -y negation_vulkan.jpg

Signed-off-by: Wu Jianhua <jianhua.wu@intel.com>
---
 libavfilter/vf_blend_vulkan.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/libavfilter/vf_blend_vulkan.c b/libavfilter/vf_blend_vulkan.c
index 670df47499..4d409b138b 100644
--- a/libavfilter/vf_blend_vulkan.c
+++ b/libavfilter/vf_blend_vulkan.c
@@ -86,6 +86,7 @@ DEFINE_BLEND_MODE(ADDITION, FN(min(MAX, A + B)))
 DEFINE_BLEND_MODE(AVERAGE,  FN((A + B) * HALF))
 DEFINE_BLEND_MODE(SUBTRACT, FN(max(MIN, A - B)))
 DEFINE_BLEND_MODE(MULTIPLY, FN(1.0f * A * B / 1.0f))
+DEFINE_BLEND_MODE(NEGATION, FN(MAX - abs(MAX - A - B)))
 
 static inline void init_blend_func(FilterParamsVulkan *param)
 {
@@ -100,6 +101,7 @@ static inline void init_blend_func(FilterParamsVulkan *param)
     CASE(SUBTRACT)
     CASE(NORMAL)
     CASE(MULTIPLY)
+    CASE(NEGATION)
     default: param->blend = NULL; break;
     }
 
@@ -474,6 +476,7 @@ static const AVOption blend_vulkan_options[] = {
         { "subtract", "", 0, AV_OPT_TYPE_CONST, { .i64 = BLEND_SUBTRACT }, 0, 0, FLAGS, "mode" },
         { "normal",   "", 0, AV_OPT_TYPE_CONST, { .i64 = BLEND_NORMAL   }, 0, 0, FLAGS, "mode" },
         { "multiply", "", 0, AV_OPT_TYPE_CONST, { .i64 = BLEND_MULTIPLY }, 0, 0, FLAGS, "mode" },
+        { "negation", "", 0, AV_OPT_TYPE_CONST, { .i64 = BLEND_NEGATION }, 0, 0, FLAGS, "mode" },
 
     { "c0_opacity",  "set color component #0 opacity", OFFSET(params[0].opacity), AV_OPT_TYPE_DOUBLE, { .dbl = 1 }, 0, 1, FLAGS },
     { "c1_opacity",  "set color component #1 opacity", OFFSET(params[1].opacity), AV_OPT_TYPE_DOUBLE, { .dbl = 1 }, 0, 1, FLAGS },
-- 
2.25.1

