]> git.sesse.net Git - vlc/blobdiff - modules/video_filter/seamcarving.c
Usefull coment instead of "Gruik" (evenif I like the previous one...)
[vlc] / modules / video_filter / seamcarving.c
index 19c4372172e0af4911e01563c9589f036bebfc4d..cd0edac3dd90d9c8b79b30c90474b9c827964aa6 100644 (file)
  * Preamble
  *****************************************************************************/
 
-#include <vlc/vlc.h>
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <vlc_common.h>
+#include <vlc_plugin.h>
 #include <vlc_sout.h>
 #include <vlc_vout.h>
 
 #include "vlc_filter.h"
+#include "filter_picture.h"
 
 #include <assert.h>
 
@@ -54,8 +60,8 @@ static void FilterSeamCarving( filter_t *, picture_t *, picture_t * );
 #define FILTER_PREFIX "seamcarving-"
 
 vlc_module_begin();
-    set_description( _("Seam Carving video filter") );
-    set_shortname( _( "Seam Carvinf" ));
+    set_description( N_("Seam Carving video filter") );
+    set_shortname( N_( "Seam Carving" ));
     set_capability( "video filter2", 0 );
     set_category( CAT_VIDEO );
     set_subcategory( SUBCAT_VIDEO_VFILTER );
@@ -63,10 +69,6 @@ vlc_module_begin();
     set_callbacks( Create, Destroy );
 vlc_module_end();
 
-static const char *ppsz_filter_options[] = {
-    NULL
-};
-
 struct filter_sys_t
 {
     int *p_energy;
@@ -82,19 +84,13 @@ static int Create( vlc_object_t *p_this )
     /* Allocate structure */
     p_filter->p_sys = malloc( sizeof( filter_sys_t ) );
     if( p_filter->p_sys == NULL )
-    {
-        msg_Err( p_filter, "out of memory" );
         return VLC_ENOMEM;
-    }
 
     p_filter->pf_video_filter = Filter;
     p_filter->p_sys->p_energy = NULL;
     p_filter->p_sys->p_grad = NULL;
     p_filter->p_sys->i_crop = 0;
 
-    config_ChainParse( p_filter, FILTER_PREFIX, ppsz_filter_options,
-                   p_filter->p_cfg );
-
     var_Create( p_filter, "crop", VLC_VAR_INTEGER|VLC_VAR_ISCOMMAND );
     var_AddCallback( p_filter, "crop", CropCallback, p_filter->p_sys );
 
@@ -121,27 +117,17 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_pic )
     if( !p_outpic )
     {
         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;
     }
 
     FilterSeamCarving( p_filter, p_pic, p_outpic );
 
-    p_outpic->date = p_pic->date;
-    p_outpic->b_force = p_pic->b_force;
-    p_outpic->i_nb_fields = p_pic->i_nb_fields;
-    p_outpic->b_progressive = p_pic->b_progressive;
-    p_outpic->b_top_field_first = p_pic->b_top_field_first;
-
-    if( p_pic->pf_release )
-        p_pic->pf_release( p_pic );
-
-    return p_outpic;
+    return CopyInfoAndRelease( p_outpic, p_pic );
 }
 
-static inline int min3( int a, int b, int c );
-static inline int min( int a, int b );
+static inline int my_min3( int a, int b, int c );
+static inline int my_min( int a, int b );
 static int RemoveVerticalSeam( filter_t *p_filter, picture_t *p_inpic, picture_t *p_outpic, int i_src_visible );
 
 //#define DRAW_GRADIENT
@@ -162,16 +148,15 @@ static void FilterSeamCarving( filter_t *p_filter, picture_t *p_inpic,
         p_filter->p_sys->p_grad = (int*)malloc(i_src_pitch * i_num_lines * sizeof(int));
 
 //#if defined( DRAW_GRADIENT ) || defined( DRAW_ENERGY ) || defined( DRAW_SEAM )
-    p_filter->p_libvlc->pf_memcpy( p_outpic->p[Y_PLANE].p_pixels,
-                                   p_inpic->p[Y_PLANE].p_pixels,
+    vlc_memcpy( p_outpic->p[Y_PLANE].p_pixels, p_inpic->p[Y_PLANE].p_pixels,
         p_outpic->p[Y_PLANE].i_lines * p_outpic->p[Y_PLANE].i_pitch );
 //#else
-//    p_filter->p_libvlc->pf_memset( p_outpix, 0x80,
+//    vlc_memset( p_outpix, 0x80,
 //        p_outpic->p[Y_PLANE].i_lines * p_outpic->p[Y_PLANE].i_pitch );
 //#endif
-    p_filter->p_libvlc->pf_memset( p_outpic->p[U_PLANE].p_pixels, 0x80,
+    vlc_memset( p_outpic->p[U_PLANE].p_pixels, 0x80,
         p_outpic->p[U_PLANE].i_lines * p_outpic->p[U_PLANE].i_pitch );
-    p_filter->p_libvlc->pf_memset( p_outpic->p[V_PLANE].p_pixels, 0x80,
+    vlc_memset( p_outpic->p[V_PLANE].p_pixels, 0x80,
         p_outpic->p[V_PLANE].i_lines * p_outpic->p[V_PLANE].i_pitch );
 
 #if defined( DRAW_GRADIENT ) || defined( DRAW_ENERGY ) || defined( DRAW_SEAM )
@@ -186,7 +171,7 @@ static void FilterSeamCarving( filter_t *p_filter, picture_t *p_inpic,
     i_src_visible = RemoveVerticalSeam( p_filter, p_outpic, p_outpic, i_src_visible );
     int y;
     for( y = 0; y < p_outpic->p[Y_PLANE].i_lines; y++ )
-        p_filter->p_libvlc->pf_memset( p_outpic->p[Y_PLANE].p_pixels + y*p_outpic->p[Y_PLANE].i_pitch + i_src_visible, 0x00, p_outpic->p[Y_PLANE].i_pitch - i_src_visible );
+        vlc_memset( p_outpic->p[Y_PLANE].p_pixels + y*p_outpic->p[Y_PLANE].i_pitch + i_src_visible, 0x00, p_outpic->p[Y_PLANE].i_pitch - i_src_visible );
     j += k;
     if( j == 100 ) k = -1;
     if( j == 1 ) k = 1;
@@ -243,7 +228,6 @@ static int RemoveVerticalSeam( filter_t *p_filter, picture_t *p_inpic, picture_t
     const int i_src_pitch = p_inpic->p[Y_PLANE].i_pitch;
     const int i_num_lines = p_inpic->p[Y_PLANE].i_visible_lines;
 
-    const uint8_t *p_inpix = p_inpic->p[Y_PLANE].p_pixels;
     uint8_t *p_outpix = p_outpic->p[Y_PLANE].p_pixels;
 
     int *p_energy = p_filter->p_sys->p_energy;
@@ -264,15 +248,15 @@ static int RemoveVerticalSeam( filter_t *p_filter, picture_t *p_inpic, picture_t
         /* Compute line y's minimum energy value for paths ending on
          * each x */
         x = 1;
-        p_energy[x] = min( p_energy_prev[x  ]+p_grad[x  ],
+        p_energy[x] = my_min( p_energy_prev[x  ]+p_grad[x  ],
                            p_energy_prev[x+1]+p_grad[x+1] );
         for( x = 2; x < i_src_visible - 2; x++ )
         {
-            p_energy[x] = min3( p_energy_prev[x-1]+p_grad[x-1],
+            p_energy[x] = my_min3( p_energy_prev[x-1]+p_grad[x-1],
                                 p_energy_prev[x  ]+p_grad[x  ],
                                 p_energy_prev[x+1]+p_grad[x+1] );
         }
-        p_energy[x] = min( p_energy_prev[x-1]+p_grad[x-1],
+        p_energy[x] = my_min( p_energy_prev[x-1]+p_grad[x-1],
                            p_energy_prev[x  ]+p_grad[x  ] );
 
 #ifdef DRAW_ENERGY
@@ -353,7 +337,7 @@ static int RemoveVerticalSeam( filter_t *p_filter, picture_t *p_inpic, picture_t
 #endif
 }
 
-static inline int min3( int a, int b, int c )
+static inline int my_min3( int a, int b, int c )
 {
     if( a < b )
     {
@@ -363,7 +347,7 @@ static inline int min3( int a, int b, int c )
     if( b < c ) return b;
     return c;
 }
-static inline int min( int a, int b )
+static inline int my_min( int a, int b )
 {
     return a < b ? a : b;
 }
@@ -372,6 +356,7 @@ static int CropCallback( vlc_object_t *p_this, char const *psz_var,
                                 vlc_value_t oldval, vlc_value_t newval,
                                 void *p_data )
 {
+    VLC_UNUSED(p_this); VLC_UNUSED(psz_var); VLC_UNUSED(oldval);
     filter_sys_t *p_sys = (filter_sys_t *)p_data;
     p_sys->i_crop = newval.i_int;
     return VLC_SUCCESS;