[FFmpeg-devel] [PATCH 6/6] Add rotate90 filter.

Michael Niedermayer michaelni
Sun Oct 17 11:05:34 CEST 2010


On Fri, Oct 15, 2010 at 01:13:59AM +0200, Stefano Sabatini wrote:
> ---
>  doc/filters.texi           |    6 ++
>  libavfilter/Makefile       |    1 +
>  libavfilter/allfilters.c   |    1 +
>  libavfilter/vf_transpose.c |  173 ++++++++++++++++++++++++++++++++++++++++++++
>  4 files changed, 181 insertions(+), 0 deletions(-)
> 
> diff --git a/doc/filters.texi b/doc/filters.texi
> index d4552da..d8a185a 100644
> --- a/doc/filters.texi
> +++ b/doc/filters.texi
> @@ -438,6 +438,12 @@ format=monow, pixdesctest
>  
>  can be used to test the monowhite pixel format descriptor definition.
>  
> + at section rotate90
> +
> +Rotate the input video of an angle multiple of 90 degrees, also
> +negative values are accepted. If not specified a default value of 90
> +is assumed.
> +
>  @section scale
>  
>  Scale the input video to @var{width}:@var{height} and/or convert the image format.
> diff --git a/libavfilter/Makefile b/libavfilter/Makefile
> index 38d2762..a2d42c6 100644
> --- a/libavfilter/Makefile
> +++ b/libavfilter/Makefile
> @@ -35,6 +35,7 @@ OBJS-$(CONFIG_OCV_SMOOTH_FILTER)             += vf_libopencv.o
>  OBJS-$(CONFIG_PAD_FILTER)                    += vf_pad.o
>  OBJS-$(CONFIG_PIXDESCTEST_FILTER)            += vf_pixdesctest.o
>  OBJS-$(CONFIG_PIXELASPECT_FILTER)            += vf_aspect.o
> +OBJS-$(CONFIG_ROTATE90_FILTER)               += vf_transpose.o
>  OBJS-$(CONFIG_SCALE_FILTER)                  += vf_scale.o
>  OBJS-$(CONFIG_SETTB_FILTER)                  += vf_settb.o
>  OBJS-$(CONFIG_SLICIFY_FILTER)                += vf_slicify.o
> diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
> index bade1dd..52db2ea 100644
> --- a/libavfilter/allfilters.c
> +++ b/libavfilter/allfilters.c
> @@ -55,6 +55,7 @@ void avfilter_register_all(void)
>      REGISTER_FILTER (PAD,         pad,         vf);
>      REGISTER_FILTER (PIXDESCTEST, pixdesctest, vf);
>      REGISTER_FILTER (PIXELASPECT, pixelaspect, vf);
> +    REGISTER_FILTER (ROTATE90,    rotate90,    vf);
>      REGISTER_FILTER (SCALE,       scale,       vf);
>      REGISTER_FILTER (SETTB,       settb,       vf);
>      REGISTER_FILTER (SLICIFY,     slicify,     vf);
> diff --git a/libavfilter/vf_transpose.c b/libavfilter/vf_transpose.c
> index a14fadd..166ee53 100644
> --- a/libavfilter/vf_transpose.c
> +++ b/libavfilter/vf_transpose.c
> @@ -115,6 +115,8 @@ static int query_formats(AVFilterContext *ctx)
>      return 0;
>  }
>  
> +#if CONFIG_TRANSPOSE_FILTER
> +
>  typedef struct {
>      int hsub, vsub;
>      int nb_planes;
> @@ -227,3 +229,174 @@ AVFilter avfilter_vf_transpose = {
>                                      .type            = AVMEDIA_TYPE_VIDEO, },
>                                    { .name = NULL}},
>  };
> +
> +#endif /* CONFIG_TRANSPOSE_FILTER */
> +
> +#if CONFIG_ROTATE90_FILTER
> +
> +typedef struct {
> +    int angle;
> +    int hsub, vsub;
> +    int pixsteps[4];
> +} Rotate90Context;
> +
> +static void invert(uint8_t *dst[4], int dst_linesizes[4],
> +                   uint8_t *src[4], int src_linesizes[4],
> +                   int dstw, int dsth,
> +                   int pixsteps[4], int hsub, int vsub)
> +{
> +    int plane;
> +
> +    for (plane = 0; plane < 4 && dst[plane]; plane++) {
> +        int hsub1 = plane == 1 || plane == 2 ? hsub : 0;
> +        int vsub1 = plane == 1 || plane == 2 ? vsub : 0;
> +        int pixstep = pixsteps[plane];
> +        int outw = dstw>>hsub1;
> +        int outh = dsth>>vsub1;
> +        uint8_t *out, *in;
> +        int outlinesize, inlinesize;
> +        int x, y;
> +
> +        out = dst[plane]; outlinesize = dst_linesizes[plane];
> +        in  = src[plane]; inlinesize  = src_linesizes[plane];
> +
> +        for (y = 0; y < outh; y++) {
> +            for (x = 0; x < outw; x++) {
> +                int32_t v;
> +                int x1 = outw -1 -x;
> +                int y1 = outh -1 -y;
> +
> +                switch (pixstep) {
> +                case 1:
> +                    *(out + x) = *(in + y1*inlinesize + x1);
> +                    break;
> +                case 2:
> +                    *((uint16_t *)(out + 2*x)) = *((uint16_t *)(in + y1*inlinesize + x1*2));
> +                    break;
> +                case 3:
> +                    v = AV_RB24(in + y1*inlinesize + x1*3);
> +                    AV_WB24(out + 3*x, v);
> +                    break;
> +                case 4:
> +                    *((uint32_t *)(out + 4*x)) = *((uint32_t *)(in + y1*inlinesize + x1*4));
> +                    break;
> +                }
> +            }

please put the for loop inside the switch



[...]

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

The greatest way to live with honor in this world is to be what we pretend
to be. -- Socrates
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20101017/a3ca586a/attachment.pgp>



More information about the ffmpeg-devel mailing list