[FFmpeg-devel] [PATCH] lavfi: add erosion & dilation filter

Paul B Mahol onemda at gmail.com
Fri Feb 27 09:17:49 CET 2015


On 2/26/15, Clement Boesch <u at pkh.me> wrote:
> On Wed, Feb 25, 2015 at 02:55:58PM +0000, Paul B Mahol wrote:
>> Signed-off-by: Paul B Mahol <onemda at gmail.com>
>> ---
>>  doc/filters.texi          |  34 ++++++
>>  libavfilter/Makefile      |   2 +
>>  libavfilter/allfilters.c  |   2 +
>>  libavfilter/vf_neighbor.c | 289
>> ++++++++++++++++++++++++++++++++++++++++++++++
>>  4 files changed, 327 insertions(+)
>>  create mode 100644 libavfilter/vf_neighbor.c
>>
>> diff --git a/doc/filters.texi b/doc/filters.texi
>> index baef346..13ba797 100644
>> --- a/doc/filters.texi
>> +++ b/doc/filters.texi
>> @@ -3728,6 +3728,23 @@ FFmpeg was configured with @code{--enable-opencl}.
>> Default value is 0.
>>
>>  @end table
>>
>> + at section dilation
>> +
>> +Apply dilation effect to the video.
>> +
>> +This filter replaces the pixel by the local(3x3) maximum.
>> +
>> +It accepts the following parameters:
>> +
>> + at table @option
>> + at item threshold
>> +Allows to limit the maximum change, default is 65535.
>> +
>> + at item coordinates
>> +Flag which specifies the pixel to refer to. Default is 255 ie. all eight
>> +pixels are used.
>> + at end table
>> +
>>  @section drawbox
>>
>>  Draw a colored box on the input image.
>> @@ -4437,6 +4454,23 @@ value.
>>
>>  @end table
>>
>> + at section erosion
>> +
>> +Apply erosion effect to the video.
>> +
>> +This filter replaces the pixel by the local(3x3) minimum.
>> +
>> +It accepts the following parameters:
>> +
>> + at table @option
>> + at item threshold
>> +Allows to limit the maximum change, default is 65535.
>> +
>> + at item coordinates
>> +Flag which specifies the pixel to refer to. Default is 255 ie. all eight
>> +pixels are used.
>> + at end table
>> +
> [...]
>> +static int config_input(AVFilterLink *inlink)
>> +{
>> +    EDContext *s = inlink->dst->priv;
>> +    const AVPixFmtDescriptor *desc =
>> av_pix_fmt_desc_get(inlink->format);
>> +    int ret;
>> +
>> +    if ((ret = av_image_fill_linesizes(s->linesize, inlink->format,
>> inlink->w)) < 0)
>> +        return ret;
>> +
>> +    s->planeheight[1] = s->planeheight[2] = FF_CEIL_RSHIFT(inlink->h,
>> desc->log2_chroma_h);
>> +    s->planeheight[0] = s->planeheight[3] = inlink->h;
>> +
>> +    s->nb_planes = av_pix_fmt_count_planes(inlink->format);
>
>> +    s->buffer = av_malloc(3 * (s->linesize[0] + 32));
>
> av_malloc_array() relevant?
>
>> +    if (!s->buffer)
>> +        return AVERROR(ENOMEM);
>> +
>> +    return 0;
>> +}
>> +
>> +static inline void line_copy8(uint8_t *line, const uint8_t *srcp, int
>> width, int mergin)
>> +{
>> +    memcpy(line, srcp, width);
>> +
>
>> +    for (int i = mergin; i > 0; i--) {
>
> int should be declared out of the scope
>
>> +        line[-i] = line[i];
>> +        line[width - 1 + i] = line[width - 1 - i];
>> +    }
>> +}
>> +
> [...]
>
> No other comment from me. May I ask if there was a special use case of
> this or that's just because the effect were neat and simple to implement?

Is was neat and simple to implement and I may add other effects too.
>
> --
> Clement B.
>


More information about the ffmpeg-devel mailing list