[FFmpeg-devel] [PATCH] lavfi: add erosion, dilation, median, deflate & inflate filter

Nicolas George george at nsup.org
Sun Mar 1 18:25:15 CET 2015


Le primidi 11 ventôse, an CCXXIII, Paul B Mahol a écrit :
> +    AVFilterContext *ctx = inlink->dst;
> +    AVFilterLink *outlink = ctx->outputs[0];
> +    EDContext *s = ctx->priv;
> +    AVFrame *out;
> +    int plane, y, x, i;
> +
> +    out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
> +    if (!out) {
> +        av_frame_free(&in);
> +        return AVERROR(ENOMEM);
> +    }
> +    av_frame_copy_props(out, in);
> +
> +    for (plane = 0; plane < s->nb_planes; plane++) {
> +        if (s->planes & (1 << plane)) {
> +            const uint8_t *src = in->data[plane];
> +            uint8_t *dst = out->data[plane];
> +            int stride = in->linesize[plane];
> +            int height = s->planeheight[plane];
> +            int width  = s->planewidth[plane];
> +            uint8_t *p0 = s->buffer + 16;
> +            uint8_t *p1 = p0 + s->planewidth[0];
> +            uint8_t *p2 = p1 + s->planewidth[0];
> +            uint8_t *orig = p0, *end = p2;
> +
> +
> +            line_copy8(p0, src + stride, width, 1);
> +            line_copy8(p1, src, width, 1);
> +
> +            for (y = 0; y < height; y++) {
<snip>
> +                }
> +
> +                p0 = p1;
> +                p1 = p2;
> +                p2 = (p2 == end) ? orig: p2 + s->planewidth[0];
> +                dst += out->linesize[plane];
> +            }
> +        } else {
> +            av_image_copy_plane(out->data[plane], out->linesize[plane],
> +                                in->data[plane], in->linesize[plane],
> +                                s->planewidth[plane], s->planeheight[plane]);
> +        }
> +    }
> +
> +    av_frame_free(&in);
> +    return ff_filter_frame(outlink, out);
> +}

I find that much duplicated code (can you tell from which one of the five
filters this excerpt comes from?) is a very bad idea. Better program use
functions with parameters or possibly macros than copy-paste.

Regards,

-- 
  Nicolas George
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20150301/6a037a46/attachment.asc>


More information about the ffmpeg-devel mailing list