[FFmpeg-devel] [PATCH 3/4] Factorize dilate and smooth end frame common code.
Stefano Sabatini
stefano.sabatini-lala
Sat Sep 11 15:59:24 CEST 2010
---
libavfilter/vf_libopencv.c | 63 +++++++++++++++++++++++---------------------
1 files changed, 33 insertions(+), 30 deletions(-)
diff --git a/libavfilter/vf_libopencv.c b/libavfilter/vf_libopencv.c
index 6c535f0..b0b80d0 100644
--- a/libavfilter/vf_libopencv.c
+++ b/libavfilter/vf_libopencv.c
@@ -63,6 +63,25 @@ static int query_formats(AVFilterContext *ctx)
static void null_draw_slice(AVFilterLink *link, int y, int h, int slice_dir) { }
+static void ocv_end_frame(AVFilterLink *inlink, void filter_fn(void *, IplImage *, IplImage *))
+{
+ void *priv = inlink->dst->priv;
+ AVFilterLink *outlink= inlink->dst->outputs[0];
+ AVFilterBufferRef *inpicref = inlink ->cur_buf;
+ AVFilterBufferRef *outpicref = outlink->out_buf;
+ IplImage inimg, outimg;
+
+ fill_iplimage_from_picref(&inimg , inpicref , inlink->format);
+ fill_iplimage_from_picref(&outimg, outpicref, inlink->format);
+ filter_fn(priv, &inimg, &outimg);
+ fill_picref_from_iplimage(outpicref, &outimg, inlink->format);
+
+ avfilter_unref_buffer(inpicref);
+ avfilter_draw_slice(outlink, 0, outlink->h, 1);
+ avfilter_end_frame(outlink);
+ avfilter_unref_buffer(outpicref);
+}
+
static int read_shape_from_file(int *cols, int *rows, int **values, const char *filename, void *log_ctx)
{
char *p, *buf;
@@ -179,23 +198,15 @@ static av_cold int dilate_init(AVFilterContext *ctx, const char *args, void *opa
return 0;
}
-static void dilate_end_frame(AVFilterLink *inlink)
+static void dilate_end_frame_filter(void *priv, IplImage *inimg, IplImage *outimg)
{
- DilateContext *dilate = inlink->dst->priv;
- AVFilterLink *outlink= inlink->dst->outputs[0];
- AVFilterBufferRef *inpicref = inlink ->cur_buf;
- AVFilterBufferRef *outpicref = outlink->out_buf;
- IplImage inimg, outimg;
-
- fill_iplimage_from_picref(&inimg , inpicref , inlink->format);
- fill_iplimage_from_picref(&outimg, outpicref, inlink->format);
- cvDilate(&inimg, &outimg, NULL, dilate->iterations_nb);
- fill_picref_from_iplimage(outpicref, &outimg, inlink->format);
+ DilateContext *dilate = priv;
+ cvDilate(inimg, outimg, NULL, dilate->iterations_nb);
+}
- avfilter_unref_buffer(inpicref);
- avfilter_draw_slice(outlink, 0, outlink->h, 1);
- avfilter_end_frame(outlink);
- avfilter_unref_buffer(outpicref);
+static void dilate_end_frame(AVFilterLink *inlink)
+{
+ ocv_end_frame(inlink, dilate_end_frame_filter);
}
AVFilter avfilter_vf_ocv_dilate = {
@@ -271,23 +282,15 @@ static av_cold int smooth_init(AVFilterContext *ctx, const char *args, void *opa
return 0;
}
-static void smooth_end_frame(AVFilterLink *inlink)
+static void smooth_end_frame_filter(void *priv, IplImage *inimg, IplImage *outimg)
{
- SmoothContext *smooth = inlink->dst->priv;
- AVFilterLink *outlink= inlink->dst->outputs[0];
- AVFilterBufferRef *inpicref = inlink ->cur_buf;
- AVFilterBufferRef *outpicref = outlink->out_buf;
- IplImage inimg, outimg;
-
- fill_iplimage_from_picref(&inimg , inpicref , inlink->format);
- fill_iplimage_from_picref(&outimg, outpicref, inlink->format);
- cvSmooth(&inimg, &outimg, smooth->type, smooth->param1, smooth->param2, smooth->param3, smooth->param4);
- fill_picref_from_iplimage(outpicref, &outimg, inlink->format);
+ SmoothContext *smooth = priv;
+ cvSmooth(inimg, outimg, smooth->type, smooth->param1, smooth->param2, smooth->param3, smooth->param4);
+}
- avfilter_unref_buffer(inpicref);
- avfilter_draw_slice(outlink, 0, outlink->h, 1);
- avfilter_end_frame(outlink);
- avfilter_unref_buffer(outpicref);
+static void smooth_end_frame(AVFilterLink *inlink)
+{
+ ocv_end_frame(inlink, smooth_end_frame_filter);
}
AVFilter avfilter_vf_ocv_smooth = {
--
1.7.1
More information about the ffmpeg-devel
mailing list