Remove crop/padd code from imgresample module. Imgresample is now only
authorAntoine Cellerier <dionoea@videolan.org>
Sat, 7 Jun 2008 22:47:20 +0000 (00:47 +0200)
committerAntoine Cellerier <dionoea@videolan.org>
Mon, 9 Jun 2008 08:05:35 +0000 (10:05 +0200)
1 submodule (well, 1 main module) which can take care of resizing and
chroma conversion (basically it's the old chroma.c code). All the files
have been merged in imgresample.c. In the long run I might split
resizing and chroma conversion to 2 submodules (performance impact would
be nil). (This is untested.)

modules/codec/ffmpeg/Modules.am
modules/codec/ffmpeg/chroma.c [deleted file]
modules/codec/ffmpeg/imgresample.c
modules/codec/ffmpeg/imgresample.h [deleted file]
modules/codec/ffmpeg/video_filter.c [deleted file]

index bdb15eb..43352a0 100644 (file)
@@ -19,9 +19,6 @@ EXTRA_libavcodec_plugin_la_SOURCES = \
 
 SOURCES_imgresample = \
        imgresample.c \
-       imgresample.h \
-       chroma.c \
-       video_filter.c \
        chroma.h \
        $(NULL)
 
diff --git a/modules/codec/ffmpeg/chroma.c b/modules/codec/ffmpeg/chroma.c
deleted file mode 100644 (file)
index 61f1f60..0000000
+++ /dev/null
@@ -1,201 +0,0 @@
-/*****************************************************************************
- * chroma.c: chroma conversion using ffmpeg library
- *****************************************************************************
- * Copyright (C) 1999-2008 the VideoLAN team
- * $Id$
- *
- * Authors: Gildas Bazin <gbazin@videolan.org>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program 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 General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
- *****************************************************************************/
-
-/*****************************************************************************
- * Preamble
- *****************************************************************************/
-
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#endif
-
-#include <vlc_common.h>
-#include <vlc_vout.h>
-#include <vlc_filter.h>
-
-/* ffmpeg header */
-#ifdef HAVE_LIBAVCODEC_AVCODEC_H
-#   include <libavcodec/avcodec.h>
-#elif defined(HAVE_FFMPEG_AVCODEC_H)
-#   include <ffmpeg/avcodec.h>
-#else
-#   include <avcodec.h>
-#endif
-
-#include "chroma.h"
-
-static void ChromaConversion( filter_t *, picture_t *, picture_t * );
-static picture_t *ChromaConversion_Filter( filter_t *, picture_t * );
-
-/*****************************************************************************
- * chroma_sys_t: chroma method descriptor
- *****************************************************************************
- * This structure is part of the chroma transformation descriptor, it
- * describes the chroma plugin specific properties.
- *****************************************************************************/
-struct filter_sys_t
-{
-    int i_src_vlc_chroma;
-    int i_src_ffmpeg_chroma;
-    int i_dst_vlc_chroma;
-    int i_dst_ffmpeg_chroma;
-    AVPicture tmp_pic;
-    ImgReSampleContext *p_rsc;
-};
-
-/*****************************************************************************
- * OpenChroma: allocate a chroma function
- *****************************************************************************
- * This function allocates and initializes a chroma function
- *****************************************************************************/
-int OpenChroma( vlc_object_t *p_this )
-{
-    filter_t *p_filter = (filter_t *)p_this;
-    int i_ffmpeg_chroma[2], i_vlc_chroma[2], i;
-
-    /*
-     * Check the source chroma first, then the destination chroma
-     */
-    i_vlc_chroma[0] = p_filter->fmt_in.video.i_chroma;
-    i_vlc_chroma[1] = p_filter->fmt_out.video.i_chroma;
-    for( i = 0; i < 2; i++ )
-    {
-        i_ffmpeg_chroma[i] = GetFfmpegChroma( i_vlc_chroma[i] );
-        if( i_ffmpeg_chroma[i] < 0 ) return VLC_EGENERIC;
-    }
-
-    p_filter->pf_video_filter = ChromaConversion_Filter;
-
-    p_filter->p_sys = malloc( sizeof( filter_sys_t ) );
-    if( p_filter->p_sys == NULL )
-    {
-        return VLC_ENOMEM;
-    }
-
-    p_filter->p_sys->i_src_vlc_chroma = p_filter->fmt_in.video.i_chroma;
-    p_filter->p_sys->i_dst_vlc_chroma = p_filter->fmt_out.video.i_chroma;
-    p_filter->p_sys->i_src_ffmpeg_chroma = i_ffmpeg_chroma[0];
-    p_filter->p_sys->i_dst_ffmpeg_chroma = i_ffmpeg_chroma[1];
-
-    if( ( p_filter->fmt_in.video.i_height != p_filter->fmt_out.video.i_height ||
-          p_filter->fmt_in.video.i_width != p_filter->fmt_out.video.i_width ) &&
-        ( p_filter->p_sys->i_dst_vlc_chroma == VLC_FOURCC('I','4','2','0') ||
-          p_filter->p_sys->i_dst_vlc_chroma == VLC_FOURCC('Y','V','1','2') ))
-    {
-        msg_Dbg( p_filter, "preparing to resample picture" );
-        p_filter->p_sys->p_rsc =
-            img_resample_init( p_filter->fmt_out.video.i_width,
-                               p_filter->fmt_out.video.i_height,
-                               p_filter->fmt_in.video.i_width,
-                               p_filter->fmt_in.video.i_height );
-        avpicture_alloc( &p_filter->p_sys->tmp_pic,
-                         p_filter->p_sys->i_dst_ffmpeg_chroma,
-                         p_filter->fmt_in.video.i_width,
-                         p_filter->fmt_in.video.i_height );
-    }
-    else
-    {
-        msg_Dbg( p_filter, "no resampling" );
-        p_filter->p_sys->p_rsc = NULL;
-    }
-
-    return VLC_SUCCESS;
-}
-
-VIDEO_FILTER_WRAPPER( ChromaConversion )
-
-/*****************************************************************************
- * ChromaConversion: actual chroma conversion function
- *****************************************************************************/
-static void ChromaConversion( filter_t *p_filter,
-                              picture_t *p_src, picture_t *p_dest )
-{
-    AVPicture src_pic;
-    AVPicture dest_pic;
-    int i;
-
-    /* Prepare the AVPictures for converion */
-    for( i = 0; i < p_src->i_planes; i++ )
-    {
-        src_pic.data[i] = p_src->p[i].p_pixels;
-        src_pic.linesize[i] = p_src->p[i].i_pitch;
-    }
-    for( i = 0; i < p_dest->i_planes; i++ )
-    {
-        dest_pic.data[i] = p_dest->p[i].p_pixels;
-        dest_pic.linesize[i] = p_dest->p[i].i_pitch;
-    }
-
-    /* Special cases */
-    if( p_filter->p_sys->i_src_vlc_chroma == VLC_FOURCC('Y','V','1','2') ||
-        p_filter->p_sys->i_src_vlc_chroma == VLC_FOURCC('Y','V','U','9') )
-    {
-        /* Invert U and V */
-        src_pic.data[1] = p_src->p[2].p_pixels;
-        src_pic.data[2] = p_src->p[1].p_pixels;
-    }
-    if( p_filter->p_sys->i_dst_vlc_chroma == VLC_FOURCC('Y','V','1','2') ||
-        p_filter->p_sys->i_dst_vlc_chroma == VLC_FOURCC('Y','V','U','9') )
-    {
-        /* Invert U and V */
-        dest_pic.data[1] = p_dest->p[2].p_pixels;
-        dest_pic.data[2] = p_dest->p[1].p_pixels;
-    }
-    if( p_filter->p_sys->i_src_ffmpeg_chroma == PIX_FMT_RGB24 )
-        if( p_filter->fmt_in.video.i_bmask == 0x00ff0000 )
-            p_filter->p_sys->i_src_ffmpeg_chroma = PIX_FMT_BGR24;
-
-    if( p_filter->p_sys->p_rsc )
-    {
-        img_convert( &p_filter->p_sys->tmp_pic,
-                     p_filter->p_sys->i_dst_ffmpeg_chroma,
-                     &src_pic, p_filter->p_sys->i_src_ffmpeg_chroma,
-                     p_filter->fmt_in.video.i_width,
-                     p_filter->fmt_in.video.i_height );
-        img_resample( p_filter->p_sys->p_rsc, &dest_pic,
-                      &p_filter->p_sys->tmp_pic );
-    }
-    else
-    {
-        img_convert( &dest_pic, p_filter->p_sys->i_dst_ffmpeg_chroma,
-                     &src_pic, p_filter->p_sys->i_src_ffmpeg_chroma,
-                     p_filter->fmt_in.video.i_width,
-                     p_filter->fmt_in.video.i_height );
-    }
-}
-
-/*****************************************************************************
- * CloseChroma: free the chroma function
- *****************************************************************************
- * This function frees the previously allocated chroma function
- *****************************************************************************/
-void CloseChroma( vlc_object_t *p_this )
-{
-    filter_t *p_filter = (filter_t *)p_this;
-    if( p_filter->p_sys->p_rsc )
-    {
-        img_resample_close( p_filter->p_sys->p_rsc );
-        avpicture_free( &p_filter->p_sys->tmp_pic );
-    }
-    free( p_filter->p_sys );
-}
index 75c605f..4fd025a 100644 (file)
 
 #include <vlc_common.h>
 #include <vlc_plugin.h>
-#include <vlc_codec.h>
+#include <vlc_vout.h>
+#include <vlc_filter.h>
 
-#include "imgresample.h"
+/* ffmpeg header */
+#ifdef HAVE_LIBAVCODEC_AVCODEC_H
+#   include <libavcodec/avcodec.h>
+#elif defined(HAVE_FFMPEG_AVCODEC_H)
+#   include <ffmpeg/avcodec.h>
+#else
+#   include <avcodec.h>
+#endif
+
+#include "chroma.h"
+
+/*****************************************************************************
+ * Local prototypes
+ *****************************************************************************/
+static int  OpenFilter( vlc_object_t * );
+static void CloseFilter( vlc_object_t * );
+
+static void Conversion( filter_t *, picture_t *, picture_t * );
+static picture_t *Conversion_Filter( filter_t *, picture_t * );
 
 /*****************************************************************************
  * Module descriptor
@@ -42,16 +61,157 @@ vlc_module_begin();
     set_capability( "video filter2", 50 );
     set_callbacks( OpenFilter, CloseFilter );
     set_description( N_("FFmpeg video filter") );
+vlc_module_end();
+
+/*****************************************************************************
+ * chroma_sys_t: chroma method descriptor
+ *****************************************************************************
+ * This structure is part of the chroma transformation descriptor, it
+ * describes the chroma plugin specific properties.
+ *****************************************************************************/
+struct filter_sys_t
+{
+    int i_src_vlc_chroma;
+    int i_src_ffmpeg_chroma;
+    int i_dst_vlc_chroma;
+    int i_dst_ffmpeg_chroma;
+    AVPicture tmp_pic;
+    ImgReSampleContext *p_rsc;
+};
 
-    /* crop/padd submodule */
-    add_submodule();
-    set_capability( "crop padd", 10 ); /* FIXME / Remove */
-    set_callbacks( OpenCropPadd, CloseFilter );
-    set_description( N_("FFmpeg crop padd filter") );
+/*****************************************************************************
+ * OpenFilter: allocate a chroma function
+ *****************************************************************************
+ * This function allocates and initializes a chroma function
+ *****************************************************************************/
+int OpenFilter( vlc_object_t *p_this )
+{
+    filter_t *p_filter = (filter_t *)p_this;
+    int i_ffmpeg_chroma[2], i_vlc_chroma[2], i;
 
-    /* chroma conversion submodule */
-    add_submodule();
-    set_capability( "video filter2", 50 );
-    set_callbacks( OpenChroma, CloseChroma );
-    set_description( N_("FFmpeg chroma conversion") );
-vlc_module_end();
+    /*
+     * Check the source chroma first, then the destination chroma
+     */
+    i_vlc_chroma[0] = p_filter->fmt_in.video.i_chroma;
+    i_vlc_chroma[1] = p_filter->fmt_out.video.i_chroma;
+    for( i = 0; i < 2; i++ )
+    {
+        i_ffmpeg_chroma[i] = GetFfmpegChroma( i_vlc_chroma[i] );
+        if( i_ffmpeg_chroma[i] < 0 ) return VLC_EGENERIC;
+    }
+
+    p_filter->pf_video_filter = Conversion_Filter;
+
+    p_filter->p_sys = malloc( sizeof( filter_sys_t ) );
+    if( p_filter->p_sys == NULL )
+    {
+        return VLC_ENOMEM;
+    }
+
+    p_filter->p_sys->i_src_vlc_chroma = p_filter->fmt_in.video.i_chroma;
+    p_filter->p_sys->i_dst_vlc_chroma = p_filter->fmt_out.video.i_chroma;
+    p_filter->p_sys->i_src_ffmpeg_chroma = i_ffmpeg_chroma[0];
+    p_filter->p_sys->i_dst_ffmpeg_chroma = i_ffmpeg_chroma[1];
+
+    if( ( p_filter->fmt_in.video.i_height != p_filter->fmt_out.video.i_height ||
+          p_filter->fmt_in.video.i_width != p_filter->fmt_out.video.i_width ) &&
+        ( p_filter->p_sys->i_dst_vlc_chroma == VLC_FOURCC('I','4','2','0') ||
+          p_filter->p_sys->i_dst_vlc_chroma == VLC_FOURCC('Y','V','1','2') ))
+    {
+        msg_Dbg( p_filter, "preparing to resample picture" );
+        p_filter->p_sys->p_rsc =
+            img_resample_init( p_filter->fmt_out.video.i_width,
+                               p_filter->fmt_out.video.i_height,
+                               p_filter->fmt_in.video.i_width,
+                               p_filter->fmt_in.video.i_height );
+        avpicture_alloc( &p_filter->p_sys->tmp_pic,
+                         p_filter->p_sys->i_dst_ffmpeg_chroma,
+                         p_filter->fmt_in.video.i_width,
+                         p_filter->fmt_in.video.i_height );
+    }
+    else
+    {
+        msg_Dbg( p_filter, "no resampling" );
+        p_filter->p_sys->p_rsc = NULL;
+    }
+
+    return VLC_SUCCESS;
+}
+
+VIDEO_FILTER_WRAPPER( Conversion )
+
+/*****************************************************************************
+ * ChromaConversion: actual chroma conversion function
+ *****************************************************************************/
+static void Conversion( filter_t *p_filter,
+                        picture_t *p_src, picture_t *p_dest )
+{
+    AVPicture src_pic;
+    AVPicture dest_pic;
+    int i;
+
+    /* Prepare the AVPictures for converion */
+    for( i = 0; i < p_src->i_planes; i++ )
+    {
+        src_pic.data[i] = p_src->p[i].p_pixels;
+        src_pic.linesize[i] = p_src->p[i].i_pitch;
+    }
+    for( i = 0; i < p_dest->i_planes; i++ )
+    {
+        dest_pic.data[i] = p_dest->p[i].p_pixels;
+        dest_pic.linesize[i] = p_dest->p[i].i_pitch;
+    }
+
+    /* Special cases */
+    if( p_filter->p_sys->i_src_vlc_chroma == VLC_FOURCC('Y','V','1','2') ||
+        p_filter->p_sys->i_src_vlc_chroma == VLC_FOURCC('Y','V','U','9') )
+    {
+        /* Invert U and V */
+        src_pic.data[1] = p_src->p[2].p_pixels;
+        src_pic.data[2] = p_src->p[1].p_pixels;
+    }
+    if( p_filter->p_sys->i_dst_vlc_chroma == VLC_FOURCC('Y','V','1','2') ||
+        p_filter->p_sys->i_dst_vlc_chroma == VLC_FOURCC('Y','V','U','9') )
+    {
+        /* Invert U and V */
+        dest_pic.data[1] = p_dest->p[2].p_pixels;
+        dest_pic.data[2] = p_dest->p[1].p_pixels;
+    }
+    if( p_filter->p_sys->i_src_ffmpeg_chroma == PIX_FMT_RGB24 )
+        if( p_filter->fmt_in.video.i_bmask == 0x00ff0000 )
+            p_filter->p_sys->i_src_ffmpeg_chroma = PIX_FMT_BGR24;
+
+    if( p_filter->p_sys->p_rsc )
+    {
+        img_convert( &p_filter->p_sys->tmp_pic,
+                     p_filter->p_sys->i_dst_ffmpeg_chroma,
+                     &src_pic, p_filter->p_sys->i_src_ffmpeg_chroma,
+                     p_filter->fmt_in.video.i_width,
+                     p_filter->fmt_in.video.i_height );
+        img_resample( p_filter->p_sys->p_rsc, &dest_pic,
+                      &p_filter->p_sys->tmp_pic );
+    }
+    else
+    {
+        img_convert( &dest_pic, p_filter->p_sys->i_dst_ffmpeg_chroma,
+                     &src_pic, p_filter->p_sys->i_src_ffmpeg_chroma,
+                     p_filter->fmt_in.video.i_width,
+                     p_filter->fmt_in.video.i_height );
+    }
+}
+
+/*****************************************************************************
+ * CloseFilter: free the chroma function
+ *****************************************************************************
+ * This function frees the previously allocated chroma function
+ *****************************************************************************/
+void CloseFilter( vlc_object_t *p_this )
+{
+    filter_t *p_filter = (filter_t *)p_this;
+    if( p_filter->p_sys->p_rsc )
+    {
+        img_resample_close( p_filter->p_sys->p_rsc );
+        avpicture_free( &p_filter->p_sys->tmp_pic );
+    }
+    free( p_filter->p_sys );
+}
diff --git a/modules/codec/ffmpeg/imgresample.h b/modules/codec/ffmpeg/imgresample.h
deleted file mode 100644 (file)
index 803dd6c..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-/*****************************************************************************
- * imgresample.h: scaling and chroma conversion using the old libavcodec API
- *****************************************************************************
- * Copyright (C) 2001-2008 the VideoLAN team
- * $Id$
- *
- * Authors: Laurent Aimar <fenrir@via.ecp.fr>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program 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 General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
- *****************************************************************************/
-
-/* Chroma conversion module */
-int  OpenChroma( vlc_object_t * );
-void CloseChroma( vlc_object_t * );
-
-/* Video filter module */
-int  OpenFilter( vlc_object_t * );
-int  OpenCropPadd( vlc_object_t * ); /* XXX: This could be removed */
-void CloseFilter( vlc_object_t * );
diff --git a/modules/codec/ffmpeg/video_filter.c b/modules/codec/ffmpeg/video_filter.c
deleted file mode 100644 (file)
index 5faf72e..0000000
+++ /dev/null
@@ -1,565 +0,0 @@
-/*****************************************************************************
- * video filter: video filter doing chroma conversion and resizing
- *               using the ffmpeg library
- *****************************************************************************
- * Copyright (C) 1999-2001 the VideoLAN team
- * $Id$
- *
- * Authors: Gildas Bazin <gbazin@videolan.org>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program 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 General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
- *****************************************************************************/
-
-/*****************************************************************************
- * Preamble
- *****************************************************************************/
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#endif
-
-#include <vlc_common.h>
-#include <vlc_codec.h>
-#include <vlc_vout.h>
-#include <vlc_filter.h>
-
-/* ffmpeg header */
-#ifdef HAVE_LIBAVCODEC_AVCODEC_H
-#   include <libavcodec/avcodec.h>
-#elif defined(HAVE_FFMPEG_AVCODEC_H)
-#   include <ffmpeg/avcodec.h>
-#else
-#   include <avcodec.h>
-#endif
-
-#include "chroma.h"
-
-static int CheckInit( filter_t *p_filter );
-static picture_t *Process( filter_t *p_filter, picture_t *p_pic );
-
-/*****************************************************************************
- * filter_sys_t : filter descriptor
- *****************************************************************************/
-struct filter_sys_t
-{
-    bool b_resize;
-    bool b_convert;
-    bool b_resize_first;
-    bool b_enable_croppadd;
-
-    es_format_t fmt_in;
-    int i_src_ffmpeg_chroma;
-    es_format_t fmt_out;
-    int i_dst_ffmpeg_chroma;
-
-    AVPicture tmp_pic;
-
-    ImgReSampleContext *p_rsc;
-};
-
-/*****************************************************************************
- * OpenFilterEx: common code to OpenFilter and OpenCropPadd
- *****************************************************************************/
-static int OpenFilterEx( vlc_object_t *p_this, bool b_enable_croppadd )
-{
-    filter_t *p_filter = (filter_t*)p_this;
-    filter_sys_t *p_sys;
-    bool b_convert, b_resize;
-
-    /* Check if we can handle that formats */
-    if( GetFfmpegChroma( p_filter->fmt_in.video.i_chroma ) < 0 ||
-        GetFfmpegChroma( p_filter->fmt_out.video.i_chroma ) < 0 )
-    {
-        return VLC_EGENERIC;
-    }
-
-    b_resize =
-        ( p_filter->fmt_in.video.i_width != p_filter->fmt_out.video.i_width ) ||
-        ( p_filter->fmt_in.video.i_height != p_filter->fmt_out.video.i_height );
-
-    if ( b_enable_croppadd )
-    {
-        b_resize = b_resize ||
-           ( p_filter->fmt_in.video.i_visible_width != p_filter->fmt_in.video.i_width ) ||
-           ( p_filter->fmt_in.video.i_visible_height != p_filter->fmt_in.video.i_height ) ||
-           ( p_filter->fmt_in.video.i_x_offset != 0 ) ||
-           ( p_filter->fmt_in.video.i_y_offset != 0 ) ||
-           ( p_filter->fmt_out.video.i_visible_width != p_filter->fmt_out.video.i_width ) ||
-           ( p_filter->fmt_out.video.i_visible_height != p_filter->fmt_out.video.i_height ) ||
-           ( p_filter->fmt_out.video.i_x_offset != 0 ) ||
-           ( p_filter->fmt_out.video.i_y_offset != 0 );
-    }
-
-    b_convert =
-        ( p_filter->fmt_in.video.i_chroma != p_filter->fmt_out.video.i_chroma );
-
-    if( !b_resize && !b_convert )
-    {
-        /* Nothing to do */
-        return VLC_EGENERIC;
-    }
-
-    /* Allocate the memory needed to store the decoder's structure */
-    if( ( p_filter->p_sys = p_sys =
-          (filter_sys_t *)malloc(sizeof(filter_sys_t)) ) == NULL )
-    {
-        msg_Err( p_filter, "out of memory" );
-        return VLC_EGENERIC;
-    }
-
-    /* Misc init */
-    p_sys->p_rsc = NULL;
-    p_sys->b_enable_croppadd = b_enable_croppadd;
-    p_sys->i_src_ffmpeg_chroma =
-        GetFfmpegChroma( p_filter->fmt_in.video.i_chroma );
-    p_sys->i_dst_ffmpeg_chroma =
-        GetFfmpegChroma( p_filter->fmt_out.video.i_chroma );
-    p_filter->pf_video_filter = Process;
-    es_format_Init( &p_sys->fmt_in, 0, 0 );
-    es_format_Init( &p_sys->fmt_out, 0, 0 );
-
-    /* Dummy alloc, will be reallocated in CheckInit */
-    avpicture_alloc( &p_sys->tmp_pic, p_sys->i_src_ffmpeg_chroma,
-                     p_filter->fmt_out.video.i_width,
-                     p_filter->fmt_out.video.i_height );
-
-    if( CheckInit( p_filter ) != VLC_SUCCESS )
-    {
-        if( p_sys->p_rsc ) img_resample_close( p_sys->p_rsc );
-        avpicture_free( &p_sys->tmp_pic );
-        free( p_sys );
-        return VLC_EGENERIC;
-    }
-
-    msg_Dbg( p_filter, "input: %ix%i %4.4s -> %ix%i %4.4s",
-             p_filter->fmt_in.video.i_width, p_filter->fmt_in.video.i_height,
-             (char *)&p_filter->fmt_in.video.i_chroma,
-             p_filter->fmt_out.video.i_width, p_filter->fmt_out.video.i_height,
-             (char *)&p_filter->fmt_out.video.i_chroma );
-
-    return VLC_SUCCESS;
-}
-
-/*****************************************************************************
- * OpenFilter: probe the filter and return score
- *****************************************************************************/
-int OpenFilter( vlc_object_t *p_this )
-{
-    return OpenFilterEx( p_this, false );
-}
-
-/*****************************************************************************
- * OpenCropPadd: probe the filter and return score
- *****************************************************************************/
-int OpenCropPadd( vlc_object_t *p_this )
-{
-    return OpenFilterEx( p_this, true );
-}
-
-
-/*****************************************************************************
- * CloseFilter: clean up the filter
- *****************************************************************************/
-void CloseFilter( vlc_object_t *p_this )
-{
-    filter_t *p_filter = (filter_t*)p_this;
-    filter_sys_t *p_sys = p_filter->p_sys;
-
-    if( p_sys->p_rsc ) img_resample_close( p_sys->p_rsc );
-    avpicture_free( &p_sys->tmp_pic );
-
-    free( p_sys );
-}
-
-/*****************************************************************************
- * CheckInit: Initialise filter when necessary
- *****************************************************************************/
-static int CheckInit( filter_t *p_filter )
-{
-    filter_sys_t *p_sys = p_filter->p_sys;
-    bool b_change;
-    int i_croptop=0;
-    int i_cropbottom=0;
-    int i_cropleft=0;
-    int i_cropright=0;
-    int i_paddtop=0;
-    int i_paddbottom=0;
-    int i_paddleft=0;
-    int i_paddright=0;
-
-    b_change = ( p_filter->fmt_in.video.i_width != p_sys->fmt_in.video.i_width ) ||
-        ( p_filter->fmt_in.video.i_height != p_sys->fmt_in.video.i_height ) ||
-        ( p_filter->fmt_out.video.i_width != p_sys->fmt_out.video.i_width ) ||
-        ( p_filter->fmt_out.video.i_height != p_sys->fmt_out.video.i_height );
-
-    if ( p_sys->b_enable_croppadd )
-    {
-        b_change = b_change ||
-            ( p_filter->fmt_in.video.i_y_offset != p_sys->fmt_in.video.i_y_offset ) ||
-            ( p_filter->fmt_in.video.i_x_offset != p_sys->fmt_in.video.i_x_offset ) ||
-            ( p_filter->fmt_in.video.i_visible_width != p_sys->fmt_in.video.i_visible_width ) ||
-            ( p_filter->fmt_in.video.i_visible_height != p_sys->fmt_in.video.i_visible_height ) ||
-            ( p_filter->fmt_out.video.i_y_offset != p_sys->fmt_out.video.i_y_offset ) ||
-            ( p_filter->fmt_out.video.i_x_offset != p_sys->fmt_out.video.i_x_offset ) ||
-            ( p_filter->fmt_out.video.i_visible_width != p_sys->fmt_out.video.i_visible_width ) ||
-            ( p_filter->fmt_out.video.i_visible_height != p_sys->fmt_out.video.i_visible_height );
-    }
-
-    if ( b_change )
-    {
-        if( p_sys->p_rsc ) img_resample_close( p_sys->p_rsc );
-
-        p_sys->p_rsc = NULL;
-        p_sys->b_convert =
-          ( p_filter->fmt_in.video.i_chroma != p_filter->fmt_out.video.i_chroma );
-
-        p_sys->b_resize =
-          ( p_filter->fmt_in.video.i_width != p_filter->fmt_out.video.i_width ) ||
-          ( p_filter->fmt_in.video.i_height != p_filter->fmt_out.video.i_height );
-
-        p_sys->b_resize_first =
-          ( p_filter->fmt_in.video.i_width * p_filter->fmt_in.video.i_height ) >
-          ( p_filter->fmt_out.video.i_width * p_filter->fmt_out.video.i_height );
-
-        if( p_sys->b_resize &&
-            ( p_sys->i_src_ffmpeg_chroma != PIX_FMT_YUV420P ) &&
-            ( p_sys->i_src_ffmpeg_chroma != PIX_FMT_YUVJ420P ) &&
-            ( p_sys->i_dst_ffmpeg_chroma != PIX_FMT_YUV420P ) &&
-            ( p_sys->i_dst_ffmpeg_chroma != PIX_FMT_YUVJ420P ) )
-        {
-            msg_Err( p_filter, "img_resample_init only deals with I420" );
-            return VLC_EGENERIC;
-        }
-        else if( ( p_sys->i_src_ffmpeg_chroma != PIX_FMT_YUV420P ) &&
-                 ( p_sys->i_src_ffmpeg_chroma != PIX_FMT_YUVJ420P ) )
-        {
-            p_sys->b_resize_first = false;
-        }
-        else if( ( p_sys->i_dst_ffmpeg_chroma != PIX_FMT_YUV420P ) &&
-                 ( p_sys->i_dst_ffmpeg_chroma != PIX_FMT_YUVJ420P ) )
-        {
-            p_sys->b_resize_first = true;
-        }
-
-        if ( p_sys->b_enable_croppadd )
-        {
-            p_sys->b_resize = p_sys->b_resize ||
-                ( p_filter->fmt_in.video.i_visible_width != p_filter->fmt_in.video.i_width ) ||
-                ( p_filter->fmt_in.video.i_visible_height != p_filter->fmt_in.video.i_height ) ||
-                ( p_filter->fmt_in.video.i_x_offset != 0 ) ||
-                ( p_filter->fmt_in.video.i_y_offset != 0 ) ||
-                ( p_filter->fmt_out.video.i_visible_width != p_filter->fmt_out.video.i_width ) ||
-                ( p_filter->fmt_out.video.i_visible_height != p_filter->fmt_out.video.i_height ) ||
-                ( p_filter->fmt_out.video.i_x_offset != 0 ) ||
-                ( p_filter->fmt_out.video.i_y_offset != 0 );
-        }
-
-        if( p_sys->b_resize )
-        {
-            if ( p_sys->b_enable_croppadd )
-            {
-                i_croptop = p_filter->fmt_in.video.i_y_offset;
-                i_cropbottom = p_filter->fmt_in.video.i_height
-                                       - p_filter->fmt_in.video.i_visible_height
-                                       - p_filter->fmt_in.video.i_y_offset;
-                i_cropleft = p_filter->fmt_in.video.i_x_offset;
-                i_cropright = p_filter->fmt_in.video.i_width
-                                      - p_filter->fmt_in.video.i_visible_width
-                                      - p_filter->fmt_in.video.i_x_offset;
-
-
-                i_paddtop = p_filter->fmt_out.video.i_y_offset;
-                i_paddbottom = p_filter->fmt_out.video.i_height
-                                       - p_filter->fmt_out.video.i_visible_height
-                                       - p_filter->fmt_out.video.i_y_offset;
-                i_paddleft = p_filter->fmt_out.video.i_x_offset;
-                i_paddright = p_filter->fmt_out.video.i_width
-                                      - p_filter->fmt_out.video.i_visible_width
-                                      - p_filter->fmt_out.video.i_x_offset;
-            }
-
-            p_sys->p_rsc = img_resample_full_init(
-                               p_filter->fmt_out.video.i_width,
-                               p_filter->fmt_out.video.i_height,
-                               p_filter->fmt_in.video.i_width,
-                               p_filter->fmt_in.video.i_height,
-                               i_croptop,i_cropbottom,
-                               i_cropleft,i_cropright,
-                               i_paddtop,i_paddbottom,
-                               i_paddleft,i_paddright );
-
-            if( !p_sys->p_rsc )
-            {
-                msg_Err( p_filter, "img_resample_init failed" );
-                return VLC_EGENERIC;
-            }
-
-            msg_Dbg( p_filter, "input: %ix%i -> %ix%i",
-                p_filter->fmt_out.video.i_width,
-                p_filter->fmt_out.video.i_height,
-                p_filter->fmt_in.video.i_width,
-                p_filter->fmt_in.video.i_height);
-
-        }
-
-        avpicture_free( &p_sys->tmp_pic );
-
-        if( p_sys->b_resize_first )
-        {
-            /* Resizing then conversion */
-            avpicture_alloc( &p_sys->tmp_pic, p_sys->i_src_ffmpeg_chroma,
-                             p_filter->fmt_out.video.i_width,
-                             p_filter->fmt_out.video.i_height );
-        }
-        else
-        {
-            /* Conversion then resizing */
-            avpicture_alloc( &p_sys->tmp_pic, p_sys->i_dst_ffmpeg_chroma,
-                             p_filter->fmt_in.video.i_width,
-                             p_filter->fmt_in.video.i_height );
-        }
-
-        p_sys->fmt_in = p_filter->fmt_in;
-        p_sys->fmt_out = p_filter->fmt_out;
-    }
-
-    return VLC_SUCCESS;
-}
-
-/* fill padd code from ffmpeg */
-static int padcolor[3] = { 16, 128, 128 };
-
-/* Expects img to be yuv420 */
-static void fill_pad_region( AVPicture* img, int height, int width,
-        int padtop, int padbottom, int padleft, int padright, int *color )
-{
-    int i, y, shift;
-    uint8_t *optr;
-
-    for ( i = 0; i < 3; i++ )
-    {
-        shift = ( i == 0 ) ? 0 : 1;
-
-        if ( padtop || padleft )
-        {
-            memset( img->data[i], color[i], ( ( ( img->linesize[i] * padtop ) +
-                            padleft ) >> shift) );
-        }
-
-        if ( padleft || padright )
-        {
-            optr = img->data[i] + ( img->linesize[i] * ( padtop >> shift ) ) +
-                ( img->linesize[i] - ( padright >> shift ) );
-
-            for ( y = 0; y < ( ( height - ( padtop + padbottom ) ) >> shift ); y++ )
-            {
-                memset( optr, color[i], ( padleft + padright ) >> shift );
-                optr += img->linesize[i];
-            }
-        }
-
-        if (padbottom)
-        {
-            optr = img->data[i] + ( img->linesize[i] * ( ( height - padbottom ) >> shift ) );
-            memset( optr, color[i], ( ( img->linesize[i] * padbottom ) >> shift ) );
-        }
-    }
-}
-
-/* Workaround, because old libavcodec doesnt know how to padd */
-static void img_resample_padd( ImgReSampleContext *s, AVPicture *output,
-        const AVPicture *input, int padtop, int padleft )
-{
-    AVPicture nopadd_pic = *output;
-
-    /* shift out top and left padding for old ffmpeg */
-    nopadd_pic.data[0] += ( nopadd_pic.linesize[0] * padtop + padleft );
-    nopadd_pic.data[1] += ( nopadd_pic.linesize[1] * padtop + padleft ) >> 1;
-    nopadd_pic.data[2] += ( nopadd_pic.linesize[2] * padtop + padleft ) >> 1;
-    img_resample( s, &nopadd_pic, input );
-}
-
-
-/*****************************************************************************
- * Do the processing here
- *****************************************************************************/
-static picture_t *Process( filter_t *p_filter, picture_t *p_pic )
-{
-    filter_sys_t *p_sys = p_filter->p_sys;
-    AVPicture src_pic, dest_pic;
-    AVPicture *p_src, *p_dst;
-    picture_t *p_pic_dst;
-    int i;
-
-    /* Check if format properties changed */
-    if( CheckInit( p_filter ) != VLC_SUCCESS ) return 0;
-
-    /* Request output picture */
-    p_pic_dst = p_filter->pf_vout_buffer_new( p_filter );
-    if( !p_pic_dst )
-    {
-        msg_Warn( p_filter, "can't get output picture" );
-        p_pic->pf_release( p_pic );
-        return NULL;
-    }
-
-    /* Prepare the AVPictures for the conversion */
-    for( i = 0; i < p_pic->i_planes; i++ )
-    {
-        src_pic.data[i] = p_pic->p[i].p_pixels;
-        src_pic.linesize[i] = p_pic->p[i].i_pitch;
-    }
-    for( i = 0; i < p_pic_dst->i_planes; i++ )
-    {
-        dest_pic.data[i] = p_pic_dst->p[i].p_pixels;
-        dest_pic.linesize[i] = p_pic_dst->p[i].i_pitch;
-    }
-
-    /* Special cases */
-    if( p_filter->fmt_in.video.i_chroma == VLC_FOURCC('Y','V','1','2') ||
-        p_filter->fmt_in.video.i_chroma == VLC_FOURCC('Y','V','U','9') )
-    {
-        /* Invert U and V */
-        src_pic.data[1] = p_pic->p[2].p_pixels;
-        src_pic.data[2] = p_pic->p[1].p_pixels;
-    }
-    if( p_filter->fmt_out.video.i_chroma == VLC_FOURCC('Y','V','1','2') ||
-        p_filter->fmt_out.video.i_chroma == VLC_FOURCC('Y','V','U','9') )
-    {
-        /* Invert U and V */
-        dest_pic.data[1] = p_pic_dst->p[2].p_pixels;
-        dest_pic.data[2] = p_pic_dst->p[1].p_pixels;
-    }
-    if( p_sys->i_src_ffmpeg_chroma == PIX_FMT_RGB24 )
-        if( p_filter->fmt_in.video.i_bmask == 0x00ff0000 )
-            p_sys->i_src_ffmpeg_chroma = PIX_FMT_BGR24;
-
-    p_src = &src_pic;
-
-    if( p_sys->b_resize && p_sys->p_rsc )
-    {
-        p_dst = &dest_pic;
-        if( p_sys->b_resize_first )
-        {
-            if( p_sys->b_convert ) p_dst = &p_sys->tmp_pic;
-
-            img_resample( p_sys->p_rsc, p_dst, p_src );
-
-            if (p_sys->b_enable_croppadd)
-            {
-                if (p_filter->fmt_out.video.i_visible_width != p_filter->fmt_out.video.i_width ||
-                    p_filter->fmt_out.video.i_visible_height != p_filter->fmt_out.video.i_height ||
-                    p_filter->fmt_out.video.i_x_offset != 0 ||
-                    p_filter->fmt_out.video.i_y_offset != 0)
-                {
-                    fill_pad_region(p_dst, p_filter->fmt_out.video.i_height,
-                                    p_filter->fmt_out.video.i_width,
-                                    p_filter->fmt_out.video.i_y_offset,
-                                    p_filter->fmt_out.video.i_height
-                                      - p_filter->fmt_out.video.i_visible_height
-                                      - p_filter->fmt_out.video.i_y_offset,
-                                    p_filter->fmt_out.video.i_x_offset,
-                                    p_filter->fmt_out.video.i_width
-                                      - p_filter->fmt_out.video.i_visible_width
-                                      - p_filter->fmt_out.video.i_x_offset,
-                                    padcolor);
-                }
-            }
-
-            p_src = p_dst;
-        }
-    }
-
-    if( p_sys->b_convert )
-    {
-        video_format_t *p_fmt = &p_filter->fmt_out.video;
-        p_dst = &dest_pic;
-        if( p_sys->b_resize && !p_sys->b_resize_first )
-        {
-            p_dst = &p_sys->tmp_pic;
-            p_fmt = &p_filter->fmt_in.video;
-        }
-
-        img_convert( p_dst, p_sys->i_dst_ffmpeg_chroma,
-                     p_src, p_sys->i_src_ffmpeg_chroma,
-                     p_fmt->i_width, p_fmt->i_height );
-
-        p_src = p_dst;
-    }
-
-    if( p_sys->b_resize && !p_sys->b_resize_first && p_sys->p_rsc )
-    {
-        p_dst = &dest_pic;
-
-        img_resample( p_sys->p_rsc, p_dst, p_src );
-
-        if (p_sys->b_enable_croppadd)
-        {
-            if (p_filter->fmt_out.video.i_visible_width != p_filter->fmt_out.video.i_width ||
-                p_filter->fmt_out.video.i_visible_height != p_filter->fmt_out.video.i_height ||
-                p_filter->fmt_out.video.i_x_offset != 0 ||
-                p_filter->fmt_out.video.i_y_offset != 0)
-            {
-                fill_pad_region(p_dst, p_filter->fmt_out.video.i_height,
-                                p_filter->fmt_out.video.i_width,
-                                p_filter->fmt_out.video.i_y_offset,
-                                p_filter->fmt_out.video.i_height
-                                  - p_filter->fmt_out.video.i_visible_height
-                                  - p_filter->fmt_out.video.i_y_offset,
-                                p_filter->fmt_out.video.i_x_offset,
-                                p_filter->fmt_out.video.i_width
-                                  - p_filter->fmt_out.video.i_visible_width
-                                  - p_filter->fmt_out.video.i_x_offset,
-                                padcolor);
-            }
-        }
-    }
-
-    /* Special case for RV32 -> YUVA */
-    if( !p_sys->b_resize &&
-        p_filter->fmt_in.video.i_chroma == VLC_FOURCC('R','V','3','2') &&
-        p_filter->fmt_out.video.i_chroma == VLC_FOURCC('Y','U','V','A') )
-    {
-        uint8_t *p_src = p_pic->p[0].p_pixels;
-        int i_src_pitch = p_pic->p[0].i_pitch;
-        uint8_t *p_dst = p_pic_dst->p[3].p_pixels;
-        int i_dst_pitch = p_pic_dst->p[3].i_pitch;
-        uint32_t l,j;
-
-        for( l = 0; l < p_filter->fmt_out.video.i_height; l++ )
-        {
-            for( j = 0; j < p_filter->fmt_out.video.i_width; j++ )
-            {
-              p_dst[j] = p_src[j*4+3];
-            }
-            p_src += i_src_pitch;
-            p_dst += i_dst_pitch;
-        }
-    }
-    else if( p_filter->fmt_out.video.i_chroma == VLC_FOURCC('Y','U','V','A') )
-    {
-        /* Special case for YUVA */
-        memset( p_pic_dst->p[3].p_pixels, 0xFF,
-                p_pic_dst->p[3].i_pitch * p_pic_dst->p[3].i_lines );
-    }
-
-    p_pic_dst->date = p_pic->date;
-    p_pic_dst->b_force = p_pic->b_force;
-    p_pic_dst->i_nb_fields = p_pic->i_nb_fields;
-    p_pic_dst->b_progressive = p_pic->b_progressive;
-    p_pic_dst->b_top_field_first = p_pic->b_top_field_first;
-
-    p_pic->pf_release( p_pic );
-    return p_pic_dst;
-}