[FFmpeg-soc] [soc]: r634 - in libavfilter: Makefile allfilters.h avfilter.c vf_vflip.c

koorogi subversion at mplayerhq.hu
Wed Aug 8 19:22:54 CEST 2007


Author: koorogi
Date: Wed Aug  8 19:22:54 2007
New Revision: 634

Log:
Add a vertical flip filter


Added:
   libavfilter/vf_vflip.c
Modified:
   libavfilter/Makefile
   libavfilter/allfilters.h
   libavfilter/avfilter.c

Modified: libavfilter/Makefile
==============================================================================
--- libavfilter/Makefile	(original)
+++ libavfilter/Makefile	Wed Aug  8 19:22:54 2007
@@ -14,6 +14,7 @@ OBJS-yes = vsrc_dummy.o \
            vf_passthrough.o \
            vf_rgb2bgr.o \
            vf_slicify.o \
+           vf_vflip.o \
 
 HEADERS = avfilter.h
 

Modified: libavfilter/allfilters.h
==============================================================================
--- libavfilter/allfilters.h	(original)
+++ libavfilter/allfilters.h	Wed Aug  8 19:22:54 2007
@@ -28,4 +28,5 @@ extern AVFilter vf_graph;
 extern AVFilter vf_passthrough;
 extern AVFilter vf_rgb2bgr;
 extern AVFilter vf_slicify;
+extern AVFilter vf_vflip;
 extern AVFilter vo_sdl;

Modified: libavfilter/avfilter.c
==============================================================================
--- libavfilter/avfilter.c	(original)
+++ libavfilter/avfilter.c	Wed Aug  8 19:22:54 2007
@@ -221,6 +221,7 @@ void avfilter_init(void)
     avfilter_register(&vf_passthrough);
     avfilter_register(&vf_rgb2bgr);
     avfilter_register(&vf_slicify);
+    avfilter_register(&vf_vflip);
     avfilter_register(&vo_sdl);
 }
 

Added: libavfilter/vf_vflip.c
==============================================================================
--- (empty file)
+++ libavfilter/vf_vflip.c	Wed Aug  8 19:22:54 2007
@@ -0,0 +1,125 @@
+/*
+ * Vertical flip filter
+ * copyright (c) 2007 Bobby Bingham
+ *
+ * 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
+ */
+
+#include <string.h>
+#include <stdio.h>
+
+#include "avfilter.h"
+
+typedef struct
+{
+    int vsub;   //< chroma subsampling
+} FlipContext;
+
+static int *query_in_formats(AVFilterLink *link)
+{
+    return avfilter_make_format_list(31,
+                PIX_FMT_YUV444P,  PIX_FMT_YUV422P,  PIX_FMT_YUV420P,
+                PIX_FMT_YUV411P,  PIX_FMT_YUV410P,
+                PIX_FMT_YUYV422,  PIX_FMT_UYVY422,  PIX_FMT_UYYVYY411,
+                PIX_FMT_YUVJ444P, PIX_FMT_YUVJ422P, PIX_FMT_YUVJ420P,
+                PIX_FMT_YUV440P,  PIX_FMT_YUVJ440P,
+                PIX_FMT_RGB32,    PIX_FMT_BGR32,
+                PIX_FMT_RGB32_1,  PIX_FMT_BGR32_1,
+                PIX_FMT_RGB24,    PIX_FMT_BGR24,
+                PIX_FMT_RGB565,   PIX_FMT_BGR565,
+                PIX_FMT_RGB555,   PIX_FMT_BGR555,
+                PIX_FMT_RGB8,     PIX_FMT_BGR8,
+                PIX_FMT_RGB4_BYTE,PIX_FMT_BGR4_BYTE,
+                PIX_FMT_GRAY16BE, PIX_FMT_GRAY16LE,
+                PIX_FMT_GRAY8,    PIX_FMT_PAL8);
+}
+
+static int config_input(AVFilterLink *link)
+{
+    FlipContext *flip = link->dst->priv;
+    int tmp;
+
+    avcodec_get_chroma_sub_sample(link->format, &tmp, &flip->vsub);
+
+    return avfilter_config_link(link->dst->outputs[0]);
+}
+
+static void start_frame(AVFilterLink *link, AVFilterPicRef *picref)
+{
+    FlipContext *flip = link->dst->priv;
+    AVFilterPicRef *ref2 = avfilter_ref_pic(picref, ~0);
+    int i;
+
+    ref2->data[0] += (ref2->h-1) * ref2->linesize[0];
+    ref2->linesize[0] = -ref2->linesize[0];
+    for(i = 1; i < 4; i ++) {
+        if(ref2->data[i]) {
+            ref2->data[i] += ((ref2->h >> flip->vsub)-1) * ref2->linesize[i];
+            ref2->linesize[i] = -ref2->linesize[i];
+        }
+    }
+
+    link->cur_pic = picref;
+
+    avfilter_start_frame(link->dst->outputs[0], ref2);
+}
+
+static void end_frame(AVFilterLink *link)
+{
+    avfilter_unref_pic(link->cur_pic);
+    link->cur_pic = NULL;
+    avfilter_end_frame(link->dst->outputs[0]);
+}
+
+static void draw_slice(AVFilterLink *link, uint8_t *data[4], int y, int h)
+{
+    AVFilterContext *ctx = link->dst;
+    AVFilterPicRef *pic = link->cur_pic;
+    FlipContext *flip = ctx->priv;
+
+    uint8_t *src[4];
+    int i;
+
+    memcpy(src, data, sizeof(src));
+
+    src[0] += (y+h-1) * pic->linesize[0];
+    for(i = 0; i < 4; i ++)
+        if(src[i])
+            src[i] += (((y+h) >> flip->vsub)-1) * pic->linesize[i];
+
+    avfilter_draw_slice(ctx->outputs[0], src, pic->h - (y+h), h);
+}
+
+AVFilter vf_vflip =
+{
+    .name      = "vflip",
+    .author    = "Bobby Bingham",
+    .priv_size = sizeof(FlipContext),
+
+    .inputs    = (AVFilterPad[]) {{ .name            = "default",
+                                    .type            = AV_PAD_VIDEO,
+                                    .start_frame     = start_frame,
+                                    .draw_slice      = draw_slice,
+                                    .end_frame       = end_frame,
+                                    .query_formats   = query_in_formats,
+                                    .config_props    = config_input, },
+                                  { .name = NULL}},
+    .outputs   = (AVFilterPad[]) {{ .name            = "default",
+                                    .type            = AV_PAD_VIDEO, },
+                                  { .name = NULL}},
+};
+



More information about the FFmpeg-soc mailing list