diff mbox

[FFmpeg-devel] avfilter: add colorhold filter

Message ID 20190113181833.23731-1-onemda@gmail.com
State Superseded
Headers show

Commit Message

Paul B Mahol Jan. 13, 2019, 6:18 p.m. UTC
Signed-off-by: Paul B Mahol <onemda@gmail.com>
---
 doc/filters.texi          | 14 ++++++
 libavfilter/Makefile      |  1 +
 libavfilter/allfilters.c  |  1 +
 libavfilter/vf_colorkey.c | 93 ++++++++++++++++++++++++++++++++++++++-
 4 files changed, 108 insertions(+), 1 deletion(-)

Comments

Paul B Mahol Jan. 13, 2019, 6:24 p.m. UTC | #1
On 1/13/19, Paul B Mahol <onemda@gmail.com> wrote:
> Signed-off-by: Paul B Mahol <onemda@gmail.com>
> ---
>  doc/filters.texi          | 14 ++++++
>  libavfilter/Makefile      |  1 +
>  libavfilter/allfilters.c  |  1 +
>  libavfilter/vf_colorkey.c | 93 ++++++++++++++++++++++++++++++++++++++-
>  4 files changed, 108 insertions(+), 1 deletion(-)
>

Forgot to write in commit log:

This work is obviously sponsored by Carl Eugen Hoyos, by 50 $.
Paul B Mahol Jan. 14, 2019, 5:51 p.m. UTC | #2
On 1/13/19, Paul B Mahol <onemda@gmail.com> wrote:
> On 1/13/19, Paul B Mahol <onemda@gmail.com> wrote:
>> Signed-off-by: Paul B Mahol <onemda@gmail.com>
>> ---
>>  doc/filters.texi          | 14 ++++++
>>  libavfilter/Makefile      |  1 +
>>  libavfilter/allfilters.c  |  1 +
>>  libavfilter/vf_colorkey.c | 93 ++++++++++++++++++++++++++++++++++++++-
>>  4 files changed, 108 insertions(+), 1 deletion(-)
>>
>
> Forgot to write in commit log:
>
> This work is obviously sponsored by Carl Eugen Hoyos, by 50 $.
>

Will apply ASAP!
Nicolas George Jan. 14, 2019, 5:58 p.m. UTC | #3
Paul B Mahol (12019-01-14):
> Will apply ASAP!

I have spotted at least one problem (conditional compilation) but I have
no time to make a real review until at least ten days, alas.

Regards,
Paul B Mahol Jan. 14, 2019, 6:14 p.m. UTC | #4
On 1/14/19, Nicolas George <george@nsup.org> wrote:
> Paul B Mahol (12019-01-14):
>> Will apply ASAP!
>
> I have spotted at least one problem (conditional compilation) but I have
> no time to make a real review until at least ten days, alas.

If you have no time for real review why not disconnect from
internet/mailing list.
Paul B Mahol Jan. 21, 2019, 3:06 p.m. UTC | #5
On 1/14/19, Paul B Mahol <onemda@gmail.com> wrote:
> On 1/13/19, Paul B Mahol <onemda@gmail.com> wrote:
>> On 1/13/19, Paul B Mahol <onemda@gmail.com> wrote:
>>> Signed-off-by: Paul B Mahol <onemda@gmail.com>
>>> ---
>>>  doc/filters.texi          | 14 ++++++
>>>  libavfilter/Makefile      |  1 +
>>>  libavfilter/allfilters.c  |  1 +
>>>  libavfilter/vf_colorkey.c | 93 ++++++++++++++++++++++++++++++++++++++-
>>>  4 files changed, 108 insertions(+), 1 deletion(-)
>>>
>>
>> Forgot to write in commit log:
>>
>> This work is obviously sponsored by Carl Eugen Hoyos, by 50 $.
>>
>
> Will apply ASAP!
>

Time have come to apply this.
Nicolas George Jan. 21, 2019, 3:14 p.m. UTC | #6
Paul B Mahol (12019-01-21):
> Time have come to apply this.

Not unless you fix the flaws. Get somebody to do a proper review.
Paul B Mahol Jan. 21, 2019, 3:58 p.m. UTC | #7
On 1/21/19, Nicolas George <george@nsup.org> wrote:
> Paul B Mahol (12019-01-21):
>> Time have come to apply this.
>
> Not unless you fix the flaws. Get somebody to do a proper review.
>

This was reviewed, and I will apply it.
Nicolas George Jan. 21, 2019, 4:08 p.m. UTC | #8
Paul B Mahol (12019-01-21):
> This was reviewed, and I will apply it.

I see no trace of it on the mailing-list. And if it was true, the flaw I
spotted would have been fixed.

If you apply as is, I will revert.

Get a REAL review, public, on the mailing list.

Regards,
Paul B Mahol Jan. 21, 2019, 4:16 p.m. UTC | #9
On 1/21/19, Nicolas George <george@nsup.org> wrote:
> Paul B Mahol (12019-01-21):
>> This was reviewed, and I will apply it.
>
> I see no trace of it on the mailing-list. And if it was true, the flaw I
> spotted would have been fixed.
>
> If you apply as is, I will revert.

Michael will remove your commit rights then.
You are blocking my patch, and not providing useful review at all.
You are just bad person.

>
> Get a REAL review, public, on the mailing list.
>
> Regards,
>
> --
>   Nicolas George
>
Nicolas George Jan. 21, 2019, 4:18 p.m. UTC | #10
Paul B Mahol (12019-01-21):
> You are blocking my patch,

Yes I am blocking your patch: it is bad. Fix it.

*Your* rights should be revoked if you push without review.

> and not providing useful review at all.

I do not owe you a review. You have been repeatedly rude towards me, why
should I make a gift of my time to you?
Paul B Mahol Jan. 21, 2019, 4:25 p.m. UTC | #11
On 1/21/19, Nicolas George <george@nsup.org> wrote:
> Paul B Mahol (12019-01-21):
>> You are blocking my patch,
>
> Yes I am blocking your patch: it is bad. Fix it.
>
> *Your* rights should be revoked if you push without review.

No.

>> and not providing useful review at all.
>
> I do not owe you a review. You have been repeatedly rude towards me, why
> should I make a gift of my time to you?

You can only block patch if you provide actual review.
Those are rules.

You are rude to me, not other way around.
Nicolas George Jan. 21, 2019, 4:26 p.m. UTC | #12
Paul B Mahol (12019-01-21):
> You can only block patch if you provide actual review.
> Those are rules.

You just invented that rule.

There is a flaw, do not push without fixing it. I stand firm on it will
not repeat it.

Regards,
Paul B Mahol Jan. 21, 2019, 4:31 p.m. UTC | #13
On 1/21/19, Nicolas George <george@nsup.org> wrote:
> Paul B Mahol (12019-01-21):
>> You can only block patch if you provide actual review.
>> Those are rules.
>
> You just invented that rule.

No, see Michael commits patches without review (thank Carl, not from
you) all the time.

>
> There is a flaw, do not push without fixing it. I stand firm on it will
> not repeat it.

You have not provided actual review, just pointed some minor nuisance.
Nicolas George Jan. 21, 2019, 4:32 p.m. UTC | #14
Paul B Mahol (12019-01-21):
> No, see Michael commits patches without review (thank Carl, not from
> you) all the time.

Yes, but not when flaws were pointed.

> You have not provided actual review,

Once again: I will not, I do not owe you my time.

> just pointed some minor nuisance.

"Minor" is your judgement. Do not push without fixing them and without a
proper review.
Paul B Mahol Jan. 21, 2019, 4:41 p.m. UTC | #15
On 1/21/19, Nicolas George <george@nsup.org> wrote:
> Paul B Mahol (12019-01-21):
>> No, see Michael commits patches without review (thank Carl, not from
>> you) all the time.
>
> Yes, but not when flaws were pointed.
>
>> You have not provided actual review,
>
> Once again: I will not, I do not owe you my time.

They why you reply to my patches at all?

>
>> just pointed some minor nuisance.
>
> "Minor" is your judgement. Do not push without fixing them and without a
> proper review.

Or what? I'm ignoring you all the time, and nobody cares.
Nicolas George Jan. 21, 2019, 4:45 p.m. UTC | #16
Paul B Mahol (12019-01-21):
> They why you reply to my patches at all?

Because they are bad. I am not doing it for you, I am doing it for the
project.

> Or what? I'm ignoring you all the time, and nobody cares.

Thanks, you just said explicitly that you violated the rules of this
project. This will be remembered if you have the bad idea of pushing
without review.

Good bye.
Paul B Mahol Jan. 21, 2019, 4:49 p.m. UTC | #17
On 1/21/19, Nicolas George <george@nsup.org> wrote:
> Paul B Mahol (12019-01-21):
>> They why you reply to my patches at all?
>
> Because they are bad. I am not doing it for you, I am doing it for the
> project.

This really hurts me, because its obviously not correct. And you are
doing this for your minor pride and not for project.

>
>> Or what? I'm ignoring you all the time, and nobody cares.
>
> Thanks, you just said explicitly that you violated the rules of this
> project. This will be remembered if you have the bad idea of pushing
> without review.

Actually nobody takes you seriously when you review my patches.
Michael Niedermayer Jan. 21, 2019, 10:29 p.m. UTC | #18
On Mon, Jan 14, 2019 at 07:14:13PM +0100, Paul B Mahol wrote:
> On 1/14/19, Nicolas George <george@nsup.org> wrote:
> > Paul B Mahol (12019-01-14):
> >> Will apply ASAP!
> >
> > I have spotted at least one problem (conditional compilation) but I have
> > no time to make a real review until at least ten days, alas.
> 
> If you have no time for real review why not disconnect from
> internet/mailing list.

on IRC:
<durandal_1707> michaelni: please tell nicolas to stop blocking my patches for no reason
* durandal_1707 has quit (Ping timeout: 245 seconds)

i dont really want to be drawn into this.
Why?
because you are both inteligent adults, and you are certainly capable to
resolve this together yourself without anyone else ... if you want to solve it
instead of both wanting to win against the other.
Try to win together
Each of you try to understand the other and help him achieve what he wants.
I think nicolas wants a issue with conditional compilation fixed and wants
someone to do a more complete review
I think paul wants the patch pushed into git.

anyway, just me 2 cents, iam not good at these "mediation" things also
iam not sure iam neutral enough, so if anyone someone else should do this.
just replying as i was asked

Thanks and sorry that my mail here likely wont solve things, as i said
iam not good at this :(

[...]
diff mbox

Patch

diff --git a/doc/filters.texi b/doc/filters.texi
index d06dfe089f..2aa122cc77 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -6533,6 +6533,20 @@  ffmpeg -i background.png -i video.mp4 -filter_complex "[1:v]colorkey=0x3BBD1E:0.
 @end example
 @end itemize
 
+@section colorhold
+Remove all color information for all RGB colors except for certain one.
+
+The filter accepts the following options:
+
+@table @option
+@item color
+The color which will not be replaced with neutral gray.
+
+@item similarity
+Similarity percentage with the above color.
+0.01 matches only the exact key color, while 1.0 matches everything.
+@end table
+
 @section colorlevels
 
 Adjust video input frames using levels.
diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index 8283389f6e..5925b4bb03 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -176,6 +176,7 @@  OBJS-$(CONFIG_CODECVIEW_FILTER)              += vf_codecview.o
 OBJS-$(CONFIG_COLORBALANCE_FILTER)           += vf_colorbalance.o
 OBJS-$(CONFIG_COLORCHANNELMIXER_FILTER)      += vf_colorchannelmixer.o
 OBJS-$(CONFIG_COLORKEY_FILTER)               += vf_colorkey.o
+OBJS-$(CONFIG_COLORHOLD_FILTER)              += vf_colorkey.o
 OBJS-$(CONFIG_COLORLEVELS_FILTER)            += vf_colorlevels.o
 OBJS-$(CONFIG_COLORMATRIX_FILTER)            += vf_colormatrix.o
 OBJS-$(CONFIG_COLORSPACE_FILTER)             += vf_colorspace.o colorspace.o colorspacedsp.o
diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
index b91cff2ce7..0e0e12a5e0 100644
--- a/libavfilter/allfilters.c
+++ b/libavfilter/allfilters.c
@@ -165,6 +165,7 @@  extern AVFilter ff_vf_codecview;
 extern AVFilter ff_vf_colorbalance;
 extern AVFilter ff_vf_colorchannelmixer;
 extern AVFilter ff_vf_colorkey;
+extern AVFilter ff_vf_colorhold;
 extern AVFilter ff_vf_colorlevels;
 extern AVFilter ff_vf_colormatrix;
 extern AVFilter ff_vf_colorspace;
diff --git a/libavfilter/vf_colorkey.c b/libavfilter/vf_colorkey.c
index 3d65e59d42..ea54e367b7 100644
--- a/libavfilter/vf_colorkey.c
+++ b/libavfilter/vf_colorkey.c
@@ -34,6 +34,9 @@  typedef struct ColorkeyContext {
     uint8_t colorkey_rgba[4];
     float similarity;
     float blend;
+
+    int (*do_slice)(AVFilterContext *ctx, void *arg,
+                    int jobnr, int nb_jobs);
 } ColorkeyContext;
 
 static uint8_t do_colorkey_pixel(ColorkeyContext *ctx, uint8_t r, uint8_t g, uint8_t b)
@@ -77,15 +80,64 @@  static int do_colorkey_slice(AVFilterContext *avctx, void *arg, int jobnr, int n
     return 0;
 }
 
+static int do_colorhold_slice(AVFilterContext *avctx, void *arg, int jobnr, int nb_jobs)
+{
+    AVFrame *frame = arg;
+
+    const int slice_start = (frame->height * jobnr) / nb_jobs;
+    const int slice_end = (frame->height * (jobnr + 1)) / nb_jobs;
+
+    ColorkeyContext *ctx = avctx->priv;
+
+    int o, x, y;
+
+    for (y = slice_start; y < slice_end; ++y) {
+        for (x = 0; x < frame->width; ++x) {
+            int t, r, g, b;
+
+            o = frame->linesize[0] * y + x * 4;
+            r = frame->data[0][o + ctx->co[0]];
+            g = frame->data[0][o + ctx->co[1]];
+            b = frame->data[0][o + ctx->co[2]];
+
+            t = do_colorkey_pixel(ctx, r, g, b);
+
+            if (t > 0) {
+                int a = (r + g + b) / 3;
+
+                frame->data[0][o + ctx->co[0]] = a;
+                frame->data[0][o + ctx->co[1]] = a;
+                frame->data[0][o + ctx->co[2]] = a;
+            }
+        }
+    }
+
+    return 0;
+}
+
+static av_cold int init_filter(AVFilterContext *avctx)
+{
+    ColorkeyContext *ctx = avctx->priv;
+
+    if (!strcmp(avctx->filter->name, "colorkey")) {
+        ctx->do_slice = do_colorkey_slice;
+    } else {
+        ctx->do_slice = do_colorhold_slice;
+    }
+
+    return 0;
+}
+
 static int filter_frame(AVFilterLink *link, AVFrame *frame)
 {
     AVFilterContext *avctx = link->dst;
+    ColorkeyContext *ctx = avctx->priv;
     int res;
 
     if (res = av_frame_make_writable(frame))
         return res;
 
-    if (res = avctx->internal->execute(avctx, do_colorkey_slice, frame, NULL, FFMIN(frame->height, ff_filter_get_nb_threads(avctx))))
+    if (res = avctx->internal->execute(avctx, ctx->do_slice, frame, NULL, FFMIN(frame->height, ff_filter_get_nb_threads(avctx))))
         return res;
 
     return ff_filter_frame(avctx->outputs[0], frame);
@@ -163,7 +215,46 @@  AVFilter ff_vf_colorkey = {
     .priv_size     = sizeof(ColorkeyContext),
     .priv_class    = &colorkey_class,
     .query_formats = query_formats,
+    .init          = init_filter,
     .inputs        = colorkey_inputs,
     .outputs       = colorkey_outputs,
     .flags         = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC | AVFILTER_FLAG_SLICE_THREADS,
 };
+
+static const AVFilterPad colorhold_inputs[] = {
+    {
+        .name = "default",
+        .type = AVMEDIA_TYPE_VIDEO,
+        .filter_frame = filter_frame,
+    },
+    { NULL }
+};
+
+static const AVFilterPad colorhold_outputs[] = {
+    {
+        .name = "default",
+        .type = AVMEDIA_TYPE_VIDEO,
+        .config_props  = config_output,
+    },
+    { NULL }
+};
+
+static const AVOption colorhold_options[] = {
+    { "color", "set the colorhold key color", OFFSET(colorkey_rgba), AV_OPT_TYPE_COLOR, { .str = "black" }, CHAR_MIN, CHAR_MAX, FLAGS },
+    { "similarity", "set the colorhold similarity value", OFFSET(similarity), AV_OPT_TYPE_FLOAT, { .dbl = 0.01 }, 0.01, 1.0, FLAGS },
+    { NULL }
+};
+
+AVFILTER_DEFINE_CLASS(colorhold);
+
+AVFilter ff_vf_colorhold = {
+    .name          = "colorhold",
+    .description   = NULL_IF_CONFIG_SMALL("Turns a certain color range into gray. Operates on RGB colors."),
+    .priv_size     = sizeof(ColorkeyContext),
+    .priv_class    = &colorhold_class,
+    .query_formats = query_formats,
+    .init          = init_filter,
+    .inputs        = colorhold_inputs,
+    .outputs       = colorhold_outputs,
+    .flags         = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC | AVFILTER_FLAG_SLICE_THREADS,
+};