[PATCH] Add vflipfix filter.
Stefano Sabatini
stefano.sabatini-lala
Sat Nov 6 20:45:38 CET 2010
---
libavfilter/Makefile | 1 +
libavfilter/allfilters.c | 1 +
libavfilter/vf_vflipfix.c | 132 +++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 134 insertions(+), 0 deletions(-)
create mode 100644 libavfilter/vf_vflipfix.c
diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index 210510f..461d24d 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -42,6 +42,7 @@ OBJS-$(CONFIG_SLICIFY_FILTER) += vf_slicify.o
OBJS-$(CONFIG_TRANSPOSE_FILTER) += vf_transpose.o
OBJS-$(CONFIG_UNSHARP_FILTER) += vf_unsharp.o
OBJS-$(CONFIG_VFLIP_FILTER) += vf_vflip.o
+OBJS-$(CONFIG_VFLIPFIX_FILTER) += vf_vflipfix.o
OBJS-$(CONFIG_YADIF_FILTER) += vf_yadif.o
OBJS-$(CONFIG_BUFFER_FILTER) += vsrc_buffer.o
diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
index 9e3ba14..04a8010 100644
--- a/libavfilter/allfilters.c
+++ b/libavfilter/allfilters.c
@@ -63,6 +63,7 @@ void avfilter_register_all(void)
REGISTER_FILTER (TRANSPOSE, transpose, vf);
REGISTER_FILTER (UNSHARP, unsharp, vf);
REGISTER_FILTER (VFLIP, vflip, vf);
+ REGISTER_FILTER (VFLIPFIX, vflipfix, vf);
REGISTER_FILTER (YADIF, yadif, vf);
REGISTER_FILTER (BUFFER, buffer, vsrc);
diff --git a/libavfilter/vf_vflipfix.c b/libavfilter/vf_vflipfix.c
new file mode 100644
index 0000000..656ac3e
--- /dev/null
+++ b/libavfilter/vf_vflipfix.c
@@ -0,0 +1,132 @@
+/*
+ * Copyright (c) 2010 Stefano Sabatini
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * vertically flip filter in case of negative linesizes
+ */
+
+#include "avfilter.h"
+#include "libavutil/pixdesc.h"
+
+typedef struct {
+ int vsub;
+ AVFilterBufferRef *flipped_picref;
+} FlipContext;
+
+static int config_props(AVFilterLink *inlink)
+{
+ FlipContext *flip = inlink->dst->priv;
+ flip->vsub = av_pix_fmt_descriptors[inlink->format].log2_chroma_h;
+
+ return 0;
+}
+
+static AVFilterBufferRef *get_video_buffer(AVFilterLink *inlink, int perms,
+ int w, int h)
+{
+ FlipContext *flip = inlink->dst->priv;
+ AVFilterBufferRef *picref = avfilter_get_video_buffer(inlink->dst->outputs[0],
+ perms, w, h);
+
+ if (picref->linesize[0] < 0) {
+ /* allocate a new frame and return it */
+ flip->flipped_picref = picref;
+ picref = avfilter_default_get_video_buffer(inlink, perms, w, h);
+ }
+ return picref;
+}
+
+static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref)
+{
+ FlipContext *flip = inlink->dst->priv;
+ AVFilterLink *outlink = inlink->dst->outputs[0];
+
+ if (flip->flipped_picref) {
+ outlink->out_buf = flip->flipped_picref;
+ avfilter_copy_buffer_ref_props(outlink->out_buf, picref);
+ } else
+ outlink->out_buf = picref;
+
+ avfilter_start_frame(inlink->dst->outputs[0],
+ avfilter_ref_buffer(outlink->out_buf, ~0));
+}
+
+static void null_draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir)
+{
+ FlipContext *flip = inlink->dst->priv;
+ if (!flip->flipped_picref)
+ avfilter_null_draw_slice(inlink, y, h, slice_dir);
+}
+
+static void end_frame(AVFilterLink *inlink)
+{
+ FlipContext *flip = inlink->dst->priv;
+ AVFilterLink *outlink = inlink->dst->outputs[0];
+ AVFilterBufferRef *inpic = inlink->cur_buf;
+ AVFilterBufferRef *outpic = flip->flipped_picref;
+ uint8_t *inrow, *outrow;
+ int plane, i, h;
+
+ if (!flip->flipped_picref) {
+ avfilter_end_frame(outlink);
+ return;
+ }
+
+ /* vflip image */
+ for (plane = 0; plane < 4 && inpic->data[plane]; plane++) {
+ h = plane == 1 || plane == 2 ? inlink->h>>flip->vsub : inlink->h;
+ inrow = inpic ->data[plane];
+ outrow = outpic->data[plane];
+
+ for (i = 0; i < h; i++) {
+ memcpy(outrow, inrow, -outpic->linesize[plane]);
+ inrow += inpic ->linesize[plane];
+ outrow += outpic->linesize[plane];
+ }
+ }
+
+ flip->flipped_picref = NULL;
+ avfilter_unref_buffer(inpic);
+ avfilter_draw_slice(outlink, 0, inlink->h, 1);
+ avfilter_end_frame(outlink);
+ avfilter_unref_buffer(outpic);
+}
+
+AVFilter avfilter_vf_vflipfix = {
+ .name = "vflipfix",
+ .description = NULL_IF_CONFIG_SMALL("Vertically flip the input video."),
+ .priv_size = sizeof(FlipContext),
+
+ .inputs = (AVFilterPad[]) {{ .name = "default",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .config_props = config_props,
+ .get_video_buffer = get_video_buffer,
+ .start_frame = start_frame,
+ .draw_slice = null_draw_slice,
+ .end_frame = end_frame,
+ .min_perms = AV_PERM_READ, },
+ { .name = NULL}},
+ .outputs = (AVFilterPad[]) {{ .name = "default",
+ .type = AVMEDIA_TYPE_VIDEO, },
+ { .name = NULL}},
+
+ .capabilities = AVFILTER_CAP_SUPPORT_NEG_LINESIZES,
+};
--
1.7.1
--lrZ03NoBR/3+SXJZ
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment; filename="0004-Implement-ff_avfilter_graph_adjust-and-vflipfix-auto.patch"
More information about the ffmpeg-devel
mailing list