Used video_format_ScaleCropAr in scale.c/swscale.c
[vlc.git] / modules / video_filter / scale.c
index 727420c..66384db 100644 (file)
 # include "config.h"
 #endif
 
-#include <vlc/vlc.h>
+#include <vlc_common.h>
 #include <vlc_plugin.h>
-#include <vlc_vout.h>
-#include "vlc_filter.h"
-
-/*****************************************************************************
- * filter_sys_t : filter descriptor
- *****************************************************************************/
-struct filter_sys_t
-{
-    es_format_t fmt_in;
-    es_format_t fmt_out;
-};
+#include <vlc_filter.h>
 
 /****************************************************************************
  * Local prototypes
  ****************************************************************************/
 static int  OpenFilter ( vlc_object_t * );
-static void CloseFilter( vlc_object_t * );
-
 static picture_t *Filter( filter_t *, picture_t * );
 
 /*****************************************************************************
  * Module descriptor
  *****************************************************************************/
-vlc_module_begin();
-    set_description( N_("Video scaling filter") );
-    set_capability( "video filter2", 10000 );
-//    set_category( CAT_VIDEO );
-//    set_subcategory( SUBCAT_VIDEO_VFILTER2 );
-    set_callbacks( OpenFilter, CloseFilter );
-vlc_module_end();
+vlc_module_begin ()
+    set_description( N_("Video scaling filter") )
+    set_capability( "video filter2", 10 )
+    set_callbacks( OpenFilter, NULL )
+vlc_module_end ()
 
 /*****************************************************************************
  * OpenFilter: probe the filter and return score
@@ -69,26 +55,19 @@ vlc_module_end();
 static int OpenFilter( vlc_object_t *p_this )
 {
     filter_t *p_filter = (filter_t*)p_this;
-    filter_sys_t *p_sys;
 
-    if( ( p_filter->fmt_in.video.i_chroma != VLC_FOURCC('Y','U','V','P') &&
-          p_filter->fmt_in.video.i_chroma != VLC_FOURCC('Y','U','V','A') &&
-          p_filter->fmt_in.video.i_chroma != VLC_FOURCC('I','4','2','0') &&
-          p_filter->fmt_in.video.i_chroma != VLC_FOURCC('Y','V','1','2') &&
-          p_filter->fmt_in.video.i_chroma != VLC_FOURCC('R','G','B','A') ) ||
+    if( ( p_filter->fmt_in.video.i_chroma != VLC_CODEC_YUVP &&
+          p_filter->fmt_in.video.i_chroma != VLC_CODEC_YUVA &&
+          p_filter->fmt_in.video.i_chroma != VLC_CODEC_I420 &&
+          p_filter->fmt_in.video.i_chroma != VLC_CODEC_YV12 &&
+          p_filter->fmt_in.video.i_chroma != VLC_CODEC_RGB32 &&
+          p_filter->fmt_in.video.i_chroma != VLC_CODEC_RGBA ) ||
         p_filter->fmt_in.video.i_chroma != p_filter->fmt_out.video.i_chroma )
     {
         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;
-    }
-
+    video_format_ScaleCropAr( &p_filter->fmt_out.video, &p_filter->fmt_in.video );
     p_filter->pf_video_filter = Filter;
 
     msg_Dbg( p_filter, "%ix%i -> %ix%i", p_filter->fmt_in.video.i_width,
@@ -98,17 +77,6 @@ static int OpenFilter( vlc_object_t *p_this )
     return VLC_SUCCESS;
 }
 
-/*****************************************************************************
- * CloseFilter: clean up the filter
- *****************************************************************************/
-static void CloseFilter( vlc_object_t *p_this )
-{
-    filter_t *p_filter = (filter_t*)p_this;
-    filter_sys_t *p_sys = p_filter->p_sys;
-
-    free( p_sys );
-}
-
 /****************************************************************************
  * Filter: the whole thing
  ****************************************************************************/
@@ -127,17 +95,18 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_pic )
         (p_filter->fmt_out.video.i_width == 0) )
         return NULL;
 
+    video_format_ScaleCropAr( &p_filter->fmt_out.video, &p_filter->fmt_in.video );
+
     /* Request output picture */
-    p_pic_dst = p_filter->pf_vout_buffer_new( p_filter );
+    p_pic_dst = filter_NewPicture( p_filter );
     if( !p_pic_dst )
     {
-        msg_Warn( p_filter, "can't get output picture" );
-        if( p_pic->pf_release )
-            p_pic->pf_release( p_pic );
+        picture_Release( p_pic );
         return NULL;
     }
 
-    if( p_filter->fmt_in.video.i_chroma != VLC_FOURCC('R','G','B','A') )
+    if( p_filter->fmt_in.video.i_chroma != VLC_CODEC_RGBA &&
+        p_filter->fmt_in.video.i_chroma != VLC_CODEC_RGB32 )
     {
         for( i_plane = 0; i_plane < p_pic_dst->i_planes; i_plane++ )
         {
@@ -228,12 +197,7 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_pic )
         }
     }
 
-    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 );
+    picture_CopyProperties( p_pic_dst, p_pic );
+    picture_Release( p_pic );
     return p_pic_dst;
 }