From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 62FEF40DB9 for ; Fri, 11 Mar 2022 08:05:28 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id BD6AE68B20C; Fri, 11 Mar 2022 10:05:26 +0200 (EET) Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3576A68B180 for ; Fri, 11 Mar 2022 10:05:19 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1646985924; x=1678521924; h=from:to:cc:subject:date:message-id; bh=+lZiPoCY+DyKvqyHO+BcLtrgzhyog8o775QUVAO+PEE=; b=V3SqkxZzXYNMuCHPCSEI4r1uCbcrUF5FXLE1opA8wNmc9I6fBk2TUMmU oX3OrQ7dJ+/14PtG/b2GmYVESX/wyt6cSHKL1aZAF5hk5EuHgBmR3K9LW DwXBguUMmC4dMLAAjuuibZv5Z4hrtB0FgFl8R37jRKdEkdoL+80Fb/Uzx fWag3NwxdJYxaC7B+YBZ0BiVgL7mMr1WTk+J1QA9FR8WL+BjeEUKY29Bw tUC7M4pyZlSnuKPcRnuYdVls52go9Flf/Qfu/jVYrRwQtJAKj8cMkedSH lizRBgQmEeV0EHzSYbqBDMt3cPB8KsSLh+3eO039iIHUXHF4LrXiNVtrY g==; X-IronPort-AV: E=McAfee;i="6200,9189,10282"; a="255258999" X-IronPort-AV: E=Sophos;i="5.90,173,1643702400"; d="scan'208";a="255258999" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Mar 2022 00:05:16 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.90,173,1643702400"; d="scan'208";a="538916267" Received: from otc-skl-e5-server.sh.intel.com ([10.239.43.106]) by orsmga007.jf.intel.com with ESMTP; 11 Mar 2022 00:04:55 -0800 From: jianhua.wu-at-intel.com@ffmpeg.org To: ffmpeg-devel@ffmpeg.org Date: Fri, 11 Mar 2022 16:04:52 +0800 Message-Id: <20220311080452.53253-1-jianhua.wu@intel.com> X-Mailer: git-send-email 2.17.1 Subject: [FFmpeg-devel] [PATCH v2] avfilter/vf_blend_vulkan: add more blend modes X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Wu Jianhua MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: From: Wu Jianhua This commit includes addition, average, subtract, negation, extremity, difference, darken, lighten, exclusion and phoenix blend modes. 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=addition,\ pseudocolor=preset=turbo" -y addition_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=addition,hwdownload,\ format=yuv420p,pseudocolor=preset=turbo" -y addition_vulkan.jpg Signed-off-by: Wu Jianhua --- libavfilter/vf_blend_vulkan.c | 47 ++++++++++++++++++++++++++++++++--- 1 file changed, 44 insertions(+), 3 deletions(-) diff --git a/libavfilter/vf_blend_vulkan.c b/libavfilter/vf_blend_vulkan.c index fcc21cbc8d..264fe703b2 100644 --- a/libavfilter/vf_blend_vulkan.c +++ b/libavfilter/vf_blend_vulkan.c @@ -68,10 +68,31 @@ static const char blend_##MODE##_func[] = { \ #define A top #define B bottom +#define MAX vec4(1.0) +#define HALF vec4(0.5) +#define MIN vec4(0.0) + +#ifdef min +#undef min +#endif +#ifdef max +#undef max +#endif + #define FN(EXPR) A + ((EXPR) - A) * opacity DEFINE_BLEND_MODE(NORMAL, A * opacity + B * (1.0f - opacity)) -DEFINE_BLEND_MODE(MULTIPLY, FN(1.0f * A * B / 1.0f)) +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))) +DEFINE_BLEND_MODE(EXTREMITY, FN(abs(MAX - A - B))) +DEFINE_BLEND_MODE(DIFFERENCE, FN(abs(A - B))) +DEFINE_BLEND_MODE(DARKEN, FN(min(A, B))) +DEFINE_BLEND_MODE(LIGHTEN, FN(max(A, B))) +DEFINE_BLEND_MODE(EXCLUSION, FN(A + B - 2 * A * B / MAX)) +DEFINE_BLEND_MODE(PHOENIX, FN(min(A, B) - max(A, B) + MAX)) static inline void init_blend_func(FilterParamsVulkan *param) { @@ -81,8 +102,18 @@ static inline void init_blend_func(FilterParamsVulkan *param) break; switch (param->mode) { + CASE(ADDITION) + CASE(AVERAGE) + CASE(SUBTRACT) CASE(NORMAL) CASE(MULTIPLY) + CASE(NEGATION) + CASE(EXTREMITY) + CASE(DIFFERENCE) + CASE(DARKEN) + CASE(LIGHTEN) + CASE(EXCLUSION) + CASE(PHOENIX) default: param->blend = NULL; break; } @@ -452,8 +483,18 @@ static const AVOption blend_vulkan_options[] = { { "c2_mode", "set component #2 blend mode", OFFSET(params[2].mode), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, BLEND_NB - 1, FLAGS, "mode" }, { "c3_mode", "set component #3 blend mode", OFFSET(params[3].mode), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, BLEND_NB - 1, FLAGS, "mode" }, { "all_mode", "set blend mode for all components", OFFSET(all_mode), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, BLEND_NB - 1, 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" }, + { "addition", "", 0, AV_OPT_TYPE_CONST, { .i64 = BLEND_ADDITION }, 0, 0, FLAGS, "mode" }, + { "average", "", 0, AV_OPT_TYPE_CONST, { .i64 = BLEND_AVERAGE }, 0, 0, FLAGS, "mode" }, + { "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" }, + { "extremity", "", 0, AV_OPT_TYPE_CONST, { .i64 = BLEND_EXTREMITY }, 0, 0, FLAGS, "mode" }, + { "difference", "", 0, AV_OPT_TYPE_CONST, { .i64 = BLEND_DIFFERENCE }, 0, 0, FLAGS, "mode" }, + { "darken", "", 0, AV_OPT_TYPE_CONST, { .i64 = BLEND_DARKEN }, 0, 0, FLAGS, "mode" }, + { "lighten", "", 0, AV_OPT_TYPE_CONST, { .i64 = BLEND_LIGHTEN }, 0, 0, FLAGS, "mode" }, + { "exclusion", "", 0, AV_OPT_TYPE_CONST, { .i64 = BLEND_EXCLUSION }, 0, 0, FLAGS, "mode" }, + { "phoenix", "", 0, AV_OPT_TYPE_CONST, { .i64 = BLEND_PHOENIX }, 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.17.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".