diff mbox

[FFmpeg-devel] avfilter: add differencemax mode to the blend video filter

Message ID 20170731113255.6129-1-jdarnley@obe.tv
State New
Headers show

Commit Message

James Darnley July 31, 2017, 11:32 a.m. UTC
---
 Changelog              | 1 +
 doc/filters.texi       | 1 +
 libavfilter/blend.h    | 1 +
 libavfilter/vf_blend.c | 4 ++++
 4 files changed, 7 insertions(+)

Comments

Paul B Mahol July 31, 2017, 11:45 a.m. UTC | #1
On 7/31/17, James Darnley <jdarnley@obe.tv> wrote:
> ---
>  Changelog              | 1 +
>  doc/filters.texi       | 1 +
>  libavfilter/blend.h    | 1 +
>  libavfilter/vf_blend.c | 4 ++++
>  4 files changed, 7 insertions(+)
>

How this compares with lut2 filter regarding speed?
James Darnley July 31, 2017, 1:01 p.m. UTC | #2
On 2017-07-31 13:45, Paul B Mahol wrote:
> On 7/31/17, James Darnley <jdarnley@obe.tv> wrote:
>> ---
>>  Changelog              | 1 +
>>  doc/filters.texi       | 1 +
>>  libavfilter/blend.h    | 1 +
>>  libavfilter/vf_blend.c | 4 ++++
>>  4 files changed, 7 insertions(+)
>>
> 
> How this compares with lut2 filter regarding speed?

Blending testsrc and testsrc2 at hd720 yuv420p I get ~81fps using my
addition.  Using lut2 I get ~80 fps.  Using no filters and rendering
just those 2 source I get 103 fps.

That is without SIMD though.  With SIMD I would expect blend to win.
I'm actually surprised that evaluating the expression isn't dead slow.
diff mbox

Patch

diff --git a/Changelog b/Changelog
index 187ae7950a..894776d63a 100644
--- a/Changelog
+++ b/Changelog
@@ -29,6 +29,7 @@  version <next>:
 - limiter video filter
 - libvmaf video filter
 - Dolby E decoder and SMPTE 337M demuxer
+- blend video filter gets differencemax mode
 
 version 3.3:
 - CrystalHD decoder moved to new decode API
diff --git a/doc/filters.texi b/doc/filters.texi
index 4c1ef0f485..149be70245 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -4859,6 +4859,7 @@  Available values for component modes are:
 @item darken
 @item difference
 @item difference128
+@item differencemax
 @item divide
 @item dodge
 @item freeze
diff --git a/libavfilter/blend.h b/libavfilter/blend.h
index 0f27b4d29d..97d2145eb7 100644
--- a/libavfilter/blend.h
+++ b/libavfilter/blend.h
@@ -34,6 +34,7 @@  enum BlendMode {
     BLEND_DARKEN,
     BLEND_DIFFERENCE,
     BLEND_DIFFERENCE128,
+    BLEND_DIFFERENCEMAX,
     BLEND_DIVIDE,
     BLEND_DODGE,
     BLEND_EXCLUSION,
diff --git a/libavfilter/vf_blend.c b/libavfilter/vf_blend.c
index 9bde3b22a1..efbb936961 100644
--- a/libavfilter/vf_blend.c
+++ b/libavfilter/vf_blend.c
@@ -73,6 +73,7 @@  typedef struct ThreadData {
     { "darken",     "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_DARKEN},     0, 0, FLAGS, "mode" },\
     { "difference", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_DIFFERENCE}, 0, 0, FLAGS, "mode" },\
     { "difference128", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_DIFFERENCE128}, 0, 0, FLAGS, "mode" },\
+    { "differencemax", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_DIFFERENCEMAX}, 0, 0, FLAGS, "mode" },\
     { "divide",     "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_DIVIDE},     0, 0, FLAGS, "mode" },\
     { "dodge",      "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_DODGE},      0, 0, FLAGS, "mode" },\
     { "exclusion",  "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_EXCLUSION},  0, 0, FLAGS, "mode" },\
@@ -245,6 +246,7 @@  DEFINE_BLEND8(negation,   255 - FFABS(255 - A - B))
 DEFINE_BLEND8(extremity,  FFABS(255 - A - B))
 DEFINE_BLEND8(difference, FFABS(A - B))
 DEFINE_BLEND8(difference128, av_clip_uint8(128 + A - B))
+DEFINE_BLEND8(differencemax, (A < B ? 0 : B > A ? 255 : 128))
 DEFINE_BLEND8(screen,     SCREEN(1, A, B))
 DEFINE_BLEND8(overlay,    (A < 128) ? MULTIPLY(2, A, B) : SCREEN(2, A, B))
 DEFINE_BLEND8(hardlight,  (B < 128) ? MULTIPLY(2, B, A) : SCREEN(2, B, A))
@@ -288,6 +290,7 @@  DEFINE_BLEND16(negation,   65535 - FFABS(65535 - A - B))
 DEFINE_BLEND16(extremity,  FFABS(65535 - A - B))
 DEFINE_BLEND16(difference, FFABS(A - B))
 DEFINE_BLEND16(difference128, av_clip_uint16(32768 + A - B))
+DEFINE_BLEND16(differencemax, (A < B ? 0 : B > A ? 65535 : 32768))
 DEFINE_BLEND16(screen,     SCREEN(1, A, B))
 DEFINE_BLEND16(overlay,    (A < 32768) ? MULTIPLY(2, A, B) : SCREEN(2, A, B))
 DEFINE_BLEND16(hardlight,  (B < 32768) ? MULTIPLY(2, B, A) : SCREEN(2, B, A))
@@ -457,6 +460,7 @@  void ff_blend_init(FilterParams *param, int is_16bit)
     case BLEND_DARKEN:     param->blend = is_16bit ? blend_darken_16bit     : blend_darken_8bit;     break;
     case BLEND_DIFFERENCE: param->blend = is_16bit ? blend_difference_16bit : blend_difference_8bit; break;
     case BLEND_DIFFERENCE128: param->blend = is_16bit ? blend_difference128_16bit: blend_difference128_8bit; break;
+    case BLEND_DIFFERENCEMAX: param->blend = is_16bit ? blend_differencemax_16bit: blend_differencemax_8bit; break;
     case BLEND_DIVIDE:     param->blend = is_16bit ? blend_divide_16bit     : blend_divide_8bit;     break;
     case BLEND_DODGE:      param->blend = is_16bit ? blend_dodge_16bit      : blend_dodge_8bit;      break;
     case BLEND_EXCLUSION:  param->blend = is_16bit ? blend_exclusion_16bit  : blend_exclusion_8bit;  break;