diff mbox series

[FFmpeg-devel] avfilter/elbg: Extend filter to include alpha values in the quantization procedure

Message ID MN2PR04MB59815BFA519370D3F8D21A41BAA69@MN2PR04MB5981.namprd04.prod.outlook.com
State Accepted
Commit 8983c3d7e4acf9b216599cce218acbea498154c7
Headers show
Series [FFmpeg-devel] avfilter/elbg: Extend filter to include alpha values in the quantization procedure | expand

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished
andriy/make_ppc success Make finished
andriy/make_fate_ppc success Make fate finished

Commit Message

Soft Works Sept. 26, 2021, 4:57 a.m. UTC
Usage example:

ffmpeg -y -loglevel verbose -i "..\fate-suite\apng\o_sample.png" -filter_complex "elbg=pal8=1:use_alpha=1" -frames:v 1 out.png

Signed-off-by: softworkz <softworkz@hotmail.com>
---
 doc/filters.texi      |  4 ++++
 libavfilter/vf_elbg.c | 25 ++++++++++++++++---------
 2 files changed, 20 insertions(+), 9 deletions(-)

Comments

Michael Niedermayer Sept. 26, 2021, 4:52 p.m. UTC | #1
On Sun, Sep 26, 2021 at 04:57:25AM +0000, Soft Works wrote:
> Usage example:
> 
> ffmpeg -y -loglevel verbose -i "..\fate-suite\apng\o_sample.png" -filter_complex "elbg=pal8=1:use_alpha=1" -frames:v 1 out.png
> 
> Signed-off-by: softworkz <softworkz@hotmail.com>
> ---
>  doc/filters.texi      |  4 ++++
>  libavfilter/vf_elbg.c | 25 ++++++++++++++++---------
>  2 files changed, 20 insertions(+), 9 deletions(-)

will apply

thx

[...]
Soft Works Sept. 26, 2021, 5:56 p.m. UTC | #2
> -----Original Message-----
> From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf Of
> Michael Niedermayer
> Sent: Sunday, 26 September 2021 18:52
> To: FFmpeg development discussions and patches <ffmpeg-
> devel@ffmpeg.org>
> Subject: Re: [FFmpeg-devel] [PATCH] avfilter/elbg: Extend filter to
> include alpha values in the quantization procedure
> 
> On Sun, Sep 26, 2021 at 04:57:25AM +0000, Soft Works wrote:
> > Usage example:
> >
> > ffmpeg -y -loglevel verbose -i "..\fate-suite\apng\o_sample.png" -
> filter_complex "elbg=pal8=1:use_alpha=1" -frames:v 1 out.png
> >
> > Signed-off-by: softworkz <softworkz@hotmail.com>
> > ---
> >  doc/filters.texi      |  4 ++++
> >  libavfilter/vf_elbg.c | 25 ++++++++++++++++---------
> >  2 files changed, 20 insertions(+), 9 deletions(-)
> 
> will apply

Thank you.

Please allow me another note: I think the naming of this filter
is terrible. I've gone through the list of all ffmpeg filters
many more times than the typical user, but without the specific
pointers I had gotten from you and a few other devs, I would 
have never identified the "elbg" filter as something that 
would do what I'm looking for.

Given the great results that this algorithm can provide, it's
a bit sad when this filter would remain to be a widely unknown
hidden gem in the future.

No matter whether, 'posterize', 'color_quantize', 'elbg_palettize'
- everything would be better than 'elbg'...

Kind regards,
softworkz
Michael Niedermayer Sept. 27, 2021, 3:29 p.m. UTC | #3
On Sun, Sep 26, 2021 at 05:56:36PM +0000, Soft Works wrote:
> 
> 
> > -----Original Message-----
> > From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf Of
> > Michael Niedermayer
> > Sent: Sunday, 26 September 2021 18:52
> > To: FFmpeg development discussions and patches <ffmpeg-
> > devel@ffmpeg.org>
> > Subject: Re: [FFmpeg-devel] [PATCH] avfilter/elbg: Extend filter to
> > include alpha values in the quantization procedure
> > 
> > On Sun, Sep 26, 2021 at 04:57:25AM +0000, Soft Works wrote:
> > > Usage example:
> > >
> > > ffmpeg -y -loglevel verbose -i "..\fate-suite\apng\o_sample.png" -
> > filter_complex "elbg=pal8=1:use_alpha=1" -frames:v 1 out.png
> > >
> > > Signed-off-by: softworkz <softworkz@hotmail.com>
> > > ---
> > >  doc/filters.texi      |  4 ++++
> > >  libavfilter/vf_elbg.c | 25 ++++++++++++++++---------
> > >  2 files changed, 20 insertions(+), 9 deletions(-)
> > 
> > will apply
> 
> Thank you.
> 
> Please allow me another note: I think the naming of this filter
> is terrible. I've gone through the list of all ffmpeg filters
> many more times than the typical user, but without the specific
> pointers I had gotten from you and a few other devs, I would 
> have never identified the "elbg" filter as something that 
> would do what I'm looking for.

i would tend to agree, yes, in fact i think
finding filters based on what they do is hard
and iam not sure their names alone should be how they need to be found

thx

[...]
Paul B Mahol Sept. 27, 2021, 4:37 p.m. UTC | #4
On Mon, Sep 27, 2021 at 5:30 PM Michael Niedermayer <michael@niedermayer.cc>
wrote:

> On Sun, Sep 26, 2021 at 05:56:36PM +0000, Soft Works wrote:
> >
> >
> > > -----Original Message-----
> > > From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf Of
> > > Michael Niedermayer
> > > Sent: Sunday, 26 September 2021 18:52
> > > To: FFmpeg development discussions and patches <ffmpeg-
> > > devel@ffmpeg.org>
> > > Subject: Re: [FFmpeg-devel] [PATCH] avfilter/elbg: Extend filter to
> > > include alpha values in the quantization procedure
> > >
> > > On Sun, Sep 26, 2021 at 04:57:25AM +0000, Soft Works wrote:
> > > > Usage example:
> > > >
> > > > ffmpeg -y -loglevel verbose -i "..\fate-suite\apng\o_sample.png" -
> > > filter_complex "elbg=pal8=1:use_alpha=1" -frames:v 1 out.png
> > > >
> > > > Signed-off-by: softworkz <softworkz@hotmail.com>
> > > > ---
> > > >  doc/filters.texi      |  4 ++++
> > > >  libavfilter/vf_elbg.c | 25 ++++++++++++++++---------
> > > >  2 files changed, 20 insertions(+), 9 deletions(-)
> > >
> > > will apply
> >
> > Thank you.
> >
> > Please allow me another note: I think the naming of this filter
> > is terrible. I've gone through the list of all ffmpeg filters
> > many more times than the typical user, but without the specific
> > pointers I had gotten from you and a few other devs, I would
> > have never identified the "elbg" filter as something that
> > would do what I'm looking for.
>
> i would tend to agree, yes, in fact i think
> finding filters based on what they do is hard
> and iam not sure their names alone should be how they need to be found
>

Every filter have short description. So next time use grep or search
feature.


>
> thx
>
> [...]
> --
> Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
>
> Old school: Use the lowest level language in which you can solve the
> problem
>             conveniently.
> New school: Use the highest level language in which the latest
> supercomputer
>             can solve the problem without the user falling asleep waiting.
> _______________________________________________
> 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".
>
Soft Works Sept. 28, 2021, 3:42 p.m. UTC | #5
> -----Original Message-----
> From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf Of
> Paul B Mahol
> Sent: Monday, 27 September 2021 18:37
> To: FFmpeg development discussions and patches <ffmpeg-
> devel@ffmpeg.org>
> Subject: Re: [FFmpeg-devel] [PATCH] avfilter/elbg: Extend filter to
> include alpha values in the quantization procedure
> 
> On Mon, Sep 27, 2021 at 5:30 PM Michael Niedermayer
> <michael@niedermayer.cc>
> wrote:
> 
> > On Sun, Sep 26, 2021 at 05:56:36PM +0000, Soft Works wrote:
> > >
> > >
> > > > -----Original Message-----
> > > > From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf
> Of
> > > > Michael Niedermayer
> > > > Sent: Sunday, 26 September 2021 18:52
> > > > To: FFmpeg development discussions and patches <ffmpeg-
> > > > devel@ffmpeg.org>
> > > > Subject: Re: [FFmpeg-devel] [PATCH] avfilter/elbg: Extend
> filter to
> > > > include alpha values in the quantization procedure
> > > >
> > > > On Sun, Sep 26, 2021 at 04:57:25AM +0000, Soft Works wrote:
> > > > > Usage example:
> > > > >
> > > > > ffmpeg -y -loglevel verbose -i "..\fate-
> suite\apng\o_sample.png" -
> > > > filter_complex "elbg=pal8=1:use_alpha=1" -frames:v 1 out.png
> > > > >
> > > > > Signed-off-by: softworkz <softworkz@hotmail.com>
> > > > > ---
> > > > >  doc/filters.texi      |  4 ++++
> > > > >  libavfilter/vf_elbg.c | 25 ++++++++++++++++---------
> > > > >  2 files changed, 20 insertions(+), 9 deletions(-)
> > > >
> > > > will apply
> > >
> > > Thank you.
> > >
> > > Please allow me another note: I think the naming of this filter
> > > is terrible. I've gone through the list of all ffmpeg filters
> > > many more times than the typical user, but without the specific
> > > pointers I had gotten from you and a few other devs, I would
> > > have never identified the "elbg" filter as something that
> > > would do what I'm looking for.
> >
> > i would tend to agree, yes, in fact i think
> > finding filters based on what they do is hard
> > and iam not sure their names alone should be how they need to be
> found
> >

The names can't be it alone, but good naming would be a helpful 
element.


> Every filter have short description. So next time use grep or search
> feature.

You have added a large range of audio filters and I'm sure many of
them are very useful, but I'm afraid that often I do not have the
slightest clue about what they are doing, not even when reading the
description text ;-)

softworkz
Paul B Mahol Sept. 28, 2021, 4:05 p.m. UTC | #6
On Tue, Sep 28, 2021 at 5:43 PM Soft Works <softworkz@hotmail.com> wrote:

>
>
> > -----Original Message-----
> > From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf Of
> > Paul B Mahol
> > Sent: Monday, 27 September 2021 18:37
> > To: FFmpeg development discussions and patches <ffmpeg-
> > devel@ffmpeg.org>
> > Subject: Re: [FFmpeg-devel] [PATCH] avfilter/elbg: Extend filter to
> > include alpha values in the quantization procedure
> >
> > On Mon, Sep 27, 2021 at 5:30 PM Michael Niedermayer
> > <michael@niedermayer.cc>
> > wrote:
> >
> > > On Sun, Sep 26, 2021 at 05:56:36PM +0000, Soft Works wrote:
> > > >
> > > >
> > > > > -----Original Message-----
> > > > > From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf
> > Of
> > > > > Michael Niedermayer
> > > > > Sent: Sunday, 26 September 2021 18:52
> > > > > To: FFmpeg development discussions and patches <ffmpeg-
> > > > > devel@ffmpeg.org>
> > > > > Subject: Re: [FFmpeg-devel] [PATCH] avfilter/elbg: Extend
> > filter to
> > > > > include alpha values in the quantization procedure
> > > > >
> > > > > On Sun, Sep 26, 2021 at 04:57:25AM +0000, Soft Works wrote:
> > > > > > Usage example:
> > > > > >
> > > > > > ffmpeg -y -loglevel verbose -i "..\fate-
> > suite\apng\o_sample.png" -
> > > > > filter_complex "elbg=pal8=1:use_alpha=1" -frames:v 1 out.png
> > > > > >
> > > > > > Signed-off-by: softworkz <softworkz@hotmail.com>
> > > > > > ---
> > > > > >  doc/filters.texi      |  4 ++++
> > > > > >  libavfilter/vf_elbg.c | 25 ++++++++++++++++---------
> > > > > >  2 files changed, 20 insertions(+), 9 deletions(-)
> > > > >
> > > > > will apply
> > > >
> > > > Thank you.
> > > >
> > > > Please allow me another note: I think the naming of this filter
> > > > is terrible. I've gone through the list of all ffmpeg filters
> > > > many more times than the typical user, but without the specific
> > > > pointers I had gotten from you and a few other devs, I would
> > > > have never identified the "elbg" filter as something that
> > > > would do what I'm looking for.
> > >
> > > i would tend to agree, yes, in fact i think
> > > finding filters based on what they do is hard
> > > and iam not sure their names alone should be how they need to be
> > found
> > >
>
> The names can't be it alone, but good naming would be a helpful
> element.
>
>
> > Every filter have short description. So next time use grep or search
> > feature.
>
> You have added a large range of audio filters and I'm sure many of
> them are very useful, but I'm afraid that often I do not have the
> slightest clue about what they are doing, not even when reading the
> description text ;-)
>

Are you audio engineer? Follow documentation.


>
> softworkz
> _______________________________________________
> 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".
>
Soft Works Sept. 28, 2021, 5:16 p.m. UTC | #7
> -----Original Message-----
> From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf Of
> Paul B Mahol
> Sent: Tuesday, 28 September 2021 18:05
> To: FFmpeg development discussions and patches <ffmpeg-
> devel@ffmpeg.org>
> Subject: Re: [FFmpeg-devel] [PATCH] avfilter/elbg: Extend filter to
> include alpha values in the quantization procedure
> 
> On Tue, Sep 28, 2021 at 5:43 PM Soft Works <softworkz@hotmail.com>
> wrote:
> 
> >
> >
> > > -----Original Message-----
> > > From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf Of
> > > Paul B Mahol
> > > Sent: Monday, 27 September 2021 18:37
> > > To: FFmpeg development discussions and patches <ffmpeg-
> > > devel@ffmpeg.org>
> > > Subject: Re: [FFmpeg-devel] [PATCH] avfilter/elbg: Extend filter
> to
> > > include alpha values in the quantization procedure
> > >
> > > On Mon, Sep 27, 2021 at 5:30 PM Michael Niedermayer
> > > <michael@niedermayer.cc>
> > > wrote:
> > >
> > > > On Sun, Sep 26, 2021 at 05:56:36PM +0000, Soft Works wrote:
> > > > >
> > > > >
> > > > > > -----Original Message-----
> > > > > > From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On
> Behalf
> > > Of
> > > > > > Michael Niedermayer
> > > > > > Sent: Sunday, 26 September 2021 18:52
> > > > > > To: FFmpeg development discussions and patches <ffmpeg-
> > > > > > devel@ffmpeg.org>
> > > > > > Subject: Re: [FFmpeg-devel] [PATCH] avfilter/elbg: Extend
> > > filter to
> > > > > > include alpha values in the quantization procedure
> > > > > >
> > > > > > On Sun, Sep 26, 2021 at 04:57:25AM +0000, Soft Works wrote:
> > > > > > > Usage example:
> > > > > > >
> > > > > > > ffmpeg -y -loglevel verbose -i "..\fate-
> > > suite\apng\o_sample.png" -
> > > > > > filter_complex "elbg=pal8=1:use_alpha=1" -frames:v 1
> out.png
> > > > > > >
> > > > > > > Signed-off-by: softworkz <softworkz@hotmail.com>
> > > > > > > ---
> > > > > > >  doc/filters.texi      |  4 ++++
> > > > > > >  libavfilter/vf_elbg.c | 25 ++++++++++++++++---------
> > > > > > >  2 files changed, 20 insertions(+), 9 deletions(-)
> > > > > >
> > > > > > will apply
> > > > >
> > > > > Thank you.
> > > > >
> > > > > Please allow me another note: I think the naming of this
> filter
> > > > > is terrible. I've gone through the list of all ffmpeg filters
> > > > > many more times than the typical user, but without the
> specific
> > > > > pointers I had gotten from you and a few other devs, I would
> > > > > have never identified the "elbg" filter as something that
> > > > > would do what I'm looking for.
> > > >
> > > > i would tend to agree, yes, in fact i think
> > > > finding filters based on what they do is hard
> > > > and iam not sure their names alone should be how they need to
> be
> > > found
> > > >
> >
> > The names can't be it alone, but good naming would be a helpful
> > element.
> >
> >
> > > Every filter have short description. So next time use grep or
> search
> > > feature.
> >
> > You have added a large range of audio filters and I'm sure many of
> > them are very useful, but I'm afraid that often I do not have the
> > slightest clue about what they are doing, not even when reading the
> > description text ;-)
> >
> 
> Are you audio engineer? Follow documentation.

Accidentally, I'm quite familiar with audio production and studio 
technology, that's why I'm sure that even for audio engineers it's 
not always clear what the filters are doing. The documentation is 
often too minimal and it would be nice when it would include 
example use cases and example command lines.
Same as for the elbg filter, I don't mean it in a negative way.
What I mean is that it's somewhat unfortunate to put so much effort
in developing those filters, when their benefits remain to be invisible
for the majority of users.

softworkz
Paul B Mahol Sept. 28, 2021, 5:35 p.m. UTC | #8
On Tue, Sep 28, 2021 at 7:16 PM Soft Works <softworkz@hotmail.com> wrote:

>
>
> > -----Original Message-----
> > From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf Of
> > Paul B Mahol
> > Sent: Tuesday, 28 September 2021 18:05
> > To: FFmpeg development discussions and patches <ffmpeg-
> > devel@ffmpeg.org>
> > Subject: Re: [FFmpeg-devel] [PATCH] avfilter/elbg: Extend filter to
> > include alpha values in the quantization procedure
> >
> > On Tue, Sep 28, 2021 at 5:43 PM Soft Works <softworkz@hotmail.com>
> > wrote:
> >
> > >
> > >
> > > > -----Original Message-----
> > > > From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf Of
> > > > Paul B Mahol
> > > > Sent: Monday, 27 September 2021 18:37
> > > > To: FFmpeg development discussions and patches <ffmpeg-
> > > > devel@ffmpeg.org>
> > > > Subject: Re: [FFmpeg-devel] [PATCH] avfilter/elbg: Extend filter
> > to
> > > > include alpha values in the quantization procedure
> > > >
> > > > On Mon, Sep 27, 2021 at 5:30 PM Michael Niedermayer
> > > > <michael@niedermayer.cc>
> > > > wrote:
> > > >
> > > > > On Sun, Sep 26, 2021 at 05:56:36PM +0000, Soft Works wrote:
> > > > > >
> > > > > >
> > > > > > > -----Original Message-----
> > > > > > > From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On
> > Behalf
> > > > Of
> > > > > > > Michael Niedermayer
> > > > > > > Sent: Sunday, 26 September 2021 18:52
> > > > > > > To: FFmpeg development discussions and patches <ffmpeg-
> > > > > > > devel@ffmpeg.org>
> > > > > > > Subject: Re: [FFmpeg-devel] [PATCH] avfilter/elbg: Extend
> > > > filter to
> > > > > > > include alpha values in the quantization procedure
> > > > > > >
> > > > > > > On Sun, Sep 26, 2021 at 04:57:25AM +0000, Soft Works wrote:
> > > > > > > > Usage example:
> > > > > > > >
> > > > > > > > ffmpeg -y -loglevel verbose -i "..\fate-
> > > > suite\apng\o_sample.png" -
> > > > > > > filter_complex "elbg=pal8=1:use_alpha=1" -frames:v 1
> > out.png
> > > > > > > >
> > > > > > > > Signed-off-by: softworkz <softworkz@hotmail.com>
> > > > > > > > ---
> > > > > > > >  doc/filters.texi      |  4 ++++
> > > > > > > >  libavfilter/vf_elbg.c | 25 ++++++++++++++++---------
> > > > > > > >  2 files changed, 20 insertions(+), 9 deletions(-)
> > > > > > >
> > > > > > > will apply
> > > > > >
> > > > > > Thank you.
> > > > > >
> > > > > > Please allow me another note: I think the naming of this
> > filter
> > > > > > is terrible. I've gone through the list of all ffmpeg filters
> > > > > > many more times than the typical user, but without the
> > specific
> > > > > > pointers I had gotten from you and a few other devs, I would
> > > > > > have never identified the "elbg" filter as something that
> > > > > > would do what I'm looking for.
> > > > >
> > > > > i would tend to agree, yes, in fact i think
> > > > > finding filters based on what they do is hard
> > > > > and iam not sure their names alone should be how they need to
> > be
> > > > found
> > > > >
> > >
> > > The names can't be it alone, but good naming would be a helpful
> > > element.
> > >
> > >
> > > > Every filter have short description. So next time use grep or
> > search
> > > > feature.
> > >
> > > You have added a large range of audio filters and I'm sure many of
> > > them are very useful, but I'm afraid that often I do not have the
> > > slightest clue about what they are doing, not even when reading the
> > > description text ;-)
> > >
> >
> > Are you audio engineer? Follow documentation.
>
> Accidentally, I'm quite familiar with audio production and studio
> technology, that's why I'm sure that even for audio engineers it's
> not always clear what the filters are doing. The documentation is
> often too minimal and it would be nice when it would include
> example use cases and example command lines.
> Same as for the elbg filter, I don't mean it in a negative way.
> What I mean is that it's somewhat unfortunate to put so much effort
> in developing those filters, when their benefits remain to be invisible
> for the majority of users.
>

Give examples, propose improvements, elbg is not only filter.



>
> softworkz
>
>
> _______________________________________________
> 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".
>
Soft Works Sept. 28, 2021, 5:56 p.m. UTC | #9
> -----Original Message-----
> From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf Of
> Paul B Mahol
> Sent: Tuesday, 28 September 2021 19:35
> To: FFmpeg development discussions and patches <ffmpeg-
> devel@ffmpeg.org>
> Subject: Re: [FFmpeg-devel] [PATCH] avfilter/elbg: Extend filter to
> include alpha values in the quantization procedure
> 
> On Tue, Sep 28, 2021 at 7:16 PM Soft Works <softworkz@hotmail.com>
> wrote:
> 
> >
> >
> > > -----Original Message-----
> > > From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf Of
> > > Paul B Mahol
> > > Sent: Tuesday, 28 September 2021 18:05
> > > To: FFmpeg development discussions and patches <ffmpeg-
> > > devel@ffmpeg.org>
> > > Subject: Re: [FFmpeg-devel] [PATCH] avfilter/elbg: Extend filter
> to
> > > include alpha values in the quantization procedure
> > >

[..]

> > > Are you audio engineer? Follow documentation.
> >
> > Accidentally, I'm quite familiar with audio production and studio
> > technology, that's why I'm sure that even for audio engineers it's
> > not always clear what the filters are doing. The documentation is
> > often too minimal and it would be nice when it would include
> > example use cases and example command lines.
> > Same as for the elbg filter, I don't mean it in a negative way.
> > What I mean is that it's somewhat unfortunate to put so much effort
> > in developing those filters, when their benefits remain to be
> invisible
> > for the majority of users.
> >
> 
> Give examples, propose improvements, elbg is not only filter.

It's not my current focus, but I think it would be a good idea 
in general when the .texi docs would include at least one working
example for each filter that demonstrates the provided capability
at its best.
By 'working example', I mean a command line that is not just using
placeholders (like '-I INPUT') but specific public streams like 
from https://streams.videolan.org/ffmpeg/ 

I've done that for the new subtitle filters and I think it would
be very helpful for users to better understand a filter's benefits
when there's an example that can be run and allows to look at 
the results.

Kind regards,
softworkz
diff mbox series

Patch

diff --git a/doc/filters.texi b/doc/filters.texi
index 7e4806235c..fa450b3eb4 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -11396,6 +11396,10 @@  will try to use a good random seed on a best effort basis.
 @item pal8
 Set pal8 output pixel format. This option does not work with codebook
 length greater than 256. Default is disabled.
+
+@item use_alpha
+Include alpha values in the quantization calculation. Allows creating
+palettized output images (e.g. PNG8) with multiple alpha smooth blending.
 @end table
 
 @section entropy
diff --git a/libavfilter/vf_elbg.c b/libavfilter/vf_elbg.c
index 0bebcdbda5..7f40be6092 100644
--- a/libavfilter/vf_elbg.c
+++ b/libavfilter/vf_elbg.c
@@ -46,6 +46,7 @@  typedef struct ELBGFilterContext {
     int codebook_length;
     const AVPixFmtDescriptor *pix_desc;
     uint8_t rgba_map[4];
+    int use_alpha;
     int pal8;
 } ELBGFilterContext;
 
@@ -60,6 +61,7 @@  static const AVOption elbg_options[] = {
     { "seed", "set the random seed", OFFSET(lfg_seed), AV_OPT_TYPE_INT64, {.i64 = -1}, -1, UINT32_MAX, FLAGS },
     { "s",    "set the random seed", OFFSET(lfg_seed), AV_OPT_TYPE_INT64, { .i64 = -1 }, -1, UINT32_MAX, FLAGS },
     { "pal8", "set the pal8 output", OFFSET(pal8), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, FLAGS },
+    { "use_alpha", "use alpha channel for mapping", OFFSET(use_alpha), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS },
     { NULL }
 };
 
@@ -105,7 +107,7 @@  static int query_formats(AVFilterContext *ctx)
     return 0;
 }
 
-#define NB_COMPONENTS 3
+#define NB_COMPONENTS 4
 
 static int config_input(AVFilterLink *inlink)
 {
@@ -138,6 +140,7 @@  static int config_input(AVFilterLink *inlink)
 #define R 0
 #define G 1
 #define B 2
+#define A 3
 
 static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
 {
@@ -148,6 +151,7 @@  static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
     const uint8_t r_idx  = elbg->rgba_map[R];
     const uint8_t g_idx  = elbg->rgba_map[G];
     const uint8_t b_idx  = elbg->rgba_map[B];
+    const uint8_t a_idx  = elbg->rgba_map[A];
 
     /* build the codeword */
     p0 = frame->data[0];
@@ -155,9 +159,10 @@  static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
     for (i = 0; i < inlink->h; i++) {
         p = p0;
         for (j = 0; j < inlink->w; j++) {
-            elbg->codeword[k++] = p[r_idx];
-            elbg->codeword[k++] = p[g_idx];
             elbg->codeword[k++] = p[b_idx];
+            elbg->codeword[k++] = p[g_idx];
+            elbg->codeword[k++] = p[r_idx];
+            elbg->codeword[k++] = elbg->use_alpha ? p[a_idx] : 0xff;
             p += elbg->pix_desc->nb_components;
         }
         p0 += frame->linesize[0];
@@ -188,10 +193,11 @@  static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
         p0 = (uint8_t *)out->data[0];
 
         for (i = 0; i < elbg->codebook_length; i++) {
-            pal[i] =  0xFFU                 << 24  |
-                     (elbg->codebook[i*3  ] << 16) |
-                     (elbg->codebook[i*3+1] <<  8) |
-                      elbg->codebook[i*3+2];
+            const int al =  elbg->use_alpha ? elbg->codebook[i*4+3] : 0xff;
+            pal[i] =  al                    << 24  |
+                     (elbg->codebook[i*4+2] << 16) |
+                     (elbg->codebook[i*4+1] <<  8) |
+                      elbg->codebook[i*4  ];
         }
 
         k = 0;
@@ -214,9 +220,10 @@  static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
         p = p0;
         for (j = 0; j < inlink->w; j++) {
             int cb_idx = NB_COMPONENTS * elbg->codeword_closest_codebook_idxs[k++];
-            p[r_idx] = elbg->codebook[cb_idx];
+            p[b_idx] = elbg->codebook[cb_idx];
             p[g_idx] = elbg->codebook[cb_idx+1];
-            p[b_idx] = elbg->codebook[cb_idx+2];
+            p[r_idx] = elbg->codebook[cb_idx+2];
+            p[a_idx] = elbg->use_alpha ? elbg->codebook[cb_idx+3] : 0xFFu;
             p += elbg->pix_desc->nb_components;
         }
         p0 += frame->linesize[0];