[FFmpeg-devel] [PATCH 2/2] Add hflip filter.
Michael Niedermayer
michaelni
Wed Aug 4 14:23:49 CEST 2010
On Sat, Jul 31, 2010 at 02:07:29AM +0200, Stefano Sabatini wrote:
> ---
> doc/filters.texi | 10 ++++
> libavfilter/Makefile | 1 +
> libavfilter/allfilters.c | 1 +
> libavfilter/vf_hflip.c | 127 ++++++++++++++++++++++++++++++++++++++++++++++
> 4 files changed, 139 insertions(+), 0 deletions(-)
> create mode 100644 libavfilter/vf_hflip.c
>
> diff --git a/doc/filters.texi b/doc/filters.texi
> index 3ce60b3..4186301 100644
> --- a/doc/filters.texi
> +++ b/doc/filters.texi
> @@ -56,6 +56,16 @@ The following command:
>
> will convert the input video to the format ``yuv420p''.
>
> + at section hflip
> +
> +Flip the input video horizontally.
> +
> +For example to horizontally flip the video in input with
> + at file{ffmpeg}:
> + at example
> +ffmpeg -i in.avi -vf "hflip" out.avi
> + at end example
> +
> @section noformat
>
> Force libavfilter not to use any of the specified pixel formats for the
> diff --git a/libavfilter/Makefile b/libavfilter/Makefile
> index b7d3ddb..e25ff85 100644
> --- a/libavfilter/Makefile
> +++ b/libavfilter/Makefile
> @@ -17,6 +17,7 @@ OBJS = allfilters.o \
> OBJS-$(CONFIG_ASPECT_FILTER) += vf_aspect.o
> OBJS-$(CONFIG_CROP_FILTER) += vf_crop.o
> OBJS-$(CONFIG_FORMAT_FILTER) += vf_format.o
> +OBJS-$(CONFIG_HFLIP_FILTER) += vf_hflip.o
> OBJS-$(CONFIG_NOFORMAT_FILTER) += vf_format.o
> OBJS-$(CONFIG_NULL_FILTER) += vf_null.o
> OBJS-$(CONFIG_PAD_FILTER) += vf_pad.o
> diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
> index 3282a31..657e5d5 100644
> --- a/libavfilter/allfilters.c
> +++ b/libavfilter/allfilters.c
> @@ -37,6 +37,7 @@ void avfilter_register_all(void)
> REGISTER_FILTER (ASPECT, aspect, vf);
> REGISTER_FILTER (CROP, crop, vf);
> REGISTER_FILTER (FORMAT, format, vf);
> + REGISTER_FILTER (HFLIP, hflip, vf);
> REGISTER_FILTER (NOFORMAT, noformat, vf);
> REGISTER_FILTER (NULL, null, vf);
> REGISTER_FILTER (PAD, pad, vf);
> diff --git a/libavfilter/vf_hflip.c b/libavfilter/vf_hflip.c
> new file mode 100644
> index 0000000..199b33f
> --- /dev/null
> +++ b/libavfilter/vf_hflip.c
> @@ -0,0 +1,127 @@
> +/*
> + * Copyright (c) 2007 Benoit Fouet
> + * 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
> + */
> +
> +/**
> + * @flip
> + * horizontal flip filter
> + */
> +
> +#include "avfilter.h"
> +#include "libavutil/pixdesc.h"
> +
> +typedef struct {
> + int max_step[4]; ///< max pixel step for each plane, expressed as a number of bytes
> + int hsub, vsub; ///< chroma subsampling
> +} FlipContext;
> +
> +static int query_formats(AVFilterContext *ctx)
> +{
> + static const enum PixelFormat pix_fmts[] = {
> + PIX_FMT_RGB48BE, PIX_FMT_RGB48LE,
> + PIX_FMT_ARGB, PIX_FMT_RGBA,
> + PIX_FMT_ABGR, PIX_FMT_BGRA,
> + PIX_FMT_RGB24, PIX_FMT_BGR24,
> + PIX_FMT_RGB565BE, PIX_FMT_RGB565LE,
> + PIX_FMT_RGB555BE, PIX_FMT_RGB555LE,
> + PIX_FMT_BGR565BE, PIX_FMT_BGR565LE,
> + PIX_FMT_BGR555BE, PIX_FMT_BGR555LE,
> + PIX_FMT_GRAY16BE, PIX_FMT_GRAY16LE,
> + PIX_FMT_YUV420P16LE, PIX_FMT_YUV420P16BE,
> + PIX_FMT_YUV422P16LE, PIX_FMT_YUV422P16BE,
> + PIX_FMT_YUV444P16LE, PIX_FMT_YUV444P16BE,
> + PIX_FMT_YUV444P, PIX_FMT_YUV422P,
> + PIX_FMT_YUV420P, PIX_FMT_YUV411P,
> + PIX_FMT_YUV410P, PIX_FMT_YUV440P,
> + PIX_FMT_YUVJ444P, PIX_FMT_YUVJ422P,
> + PIX_FMT_YUVJ420P, PIX_FMT_YUVJ440P,
> + PIX_FMT_YUVA420P,
> + PIX_FMT_RGB8, PIX_FMT_BGR8,
> + PIX_FMT_RGB4_BYTE, PIX_FMT_BGR4_BYTE,
> + PIX_FMT_PAL8, PIX_FMT_GRAY8,
> + PIX_FMT_NONE
> + };
> +
> + avfilter_set_common_formats(ctx, avfilter_make_format_list(pix_fmts));
> + return 0;
> +}
> +
> +static int config_props(AVFilterLink *inlink)
> +{
> + FlipContext *flip = inlink->dst->priv;
> + const AVPixFmtDescriptor *pix_desc = &av_pix_fmt_descriptors[inlink->format];
> + int i;
> +
> + memset(flip->max_step, 0, sizeof(flip->max_step));
> + for (i = 0; i < 4; i++) {
> + const AVComponentDescriptor *comp = &(pix_desc->comp[i]);
> + if ((comp->step_minus1+1) > flip->max_step[comp->plane])
> + flip->max_step[comp->plane] = comp->step_minus1+1;
> + }
> +
> + flip->hsub = av_pix_fmt_descriptors[inlink->format].log2_chroma_w;
> + flip->vsub = av_pix_fmt_descriptors[inlink->format].log2_chroma_h;
> +
> + return 0;
> +}
> +
> +static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir)
> +{
> + FlipContext *flip = inlink->dst->priv;
> + AVFilterPicRef *inpic = inlink->cur_pic;
> + AVFilterPicRef *outpic = inlink->dst->outputs[0]->outpic;
> + uint8_t *inrow, *outrow;
> + int i, j, plane, step, hsub, vsub;
> +
> + for (plane = 0; plane < 4 && inpic->data[plane]; plane++) {
> + step = flip->max_step[plane];
> + hsub = (plane == 1 || plane == 2) ? flip->hsub : 0;
> + vsub = (plane == 1 || plane == 2) ? flip->vsub : 0;
> +
> + outrow = outpic->data[plane] + (y>>vsub) * outpic->linesize[plane];
> + inrow = inpic ->data[plane] + (y>>vsub) * inpic ->linesize[plane] + ((inlink->w >> hsub) - 1) * step;
> + for (i = 0; i < h>>vsub; i++) {
> + for (j = 0; j < (inlink->w >> hsub); j++)
> + memcpy(outrow + j*step, inrow - j*step, step);
variable length memcpy on a per pixel base is slow
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
Observe your enemies, for they first find out your faults. -- Antisthenes
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 190 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20100804/7771a41e/attachment.pgp>
More information about the ffmpeg-devel
mailing list