Rename LoadImage() to blendbench_LoadImage() because of naming conflicts with Windows...
[vlc.git] / modules / video_filter / blendbench.c
index 181b1e3..5a6214b 100644 (file)
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
-#include <errno.h>
-#include <stdlib.h>                                      /* malloc(), free() */
-#include <string.h>
-#include <math.h>
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
 
 #include <vlc/vlc.h>
 #include <vlc_sout.h>
@@ -117,8 +117,8 @@ struct filter_sys_t
     vlc_fourcc_t i_blend_chroma;
 };
 
-static int LoadImage( vlc_object_t *p_this, picture_t **pp_pic,
-                       vlc_fourcc_t i_chroma, char *psz_file, const char *psz_name )
+static int blendbench_LoadImage( vlc_object_t *p_this, picture_t **pp_pic,
+                                 vlc_fourcc_t i_chroma, char *psz_file, const char *psz_name )
 {
     image_handler_t *p_image;
     video_format_t fmt_in, fmt_out;
@@ -131,7 +131,8 @@ static int LoadImage( vlc_object_t *p_this, picture_t **pp_pic,
     *pp_pic = image_ReadUrl( p_image, psz_file, &fmt_in, &fmt_out );
     image_HandlerDelete( p_image );
 
-    if( *pp_pic == NULL ) {
+    if( *pp_pic == NULL )
+    {
         msg_Err( p_this, "Unable to load %s image", psz_name );
         return VLC_EGENERIC;
     }
@@ -139,6 +140,8 @@ static int LoadImage( vlc_object_t *p_this, picture_t **pp_pic,
     msg_Dbg( p_this, "%s image has dim %d x %d (Y plane)", psz_name,
              (*pp_pic)->p[Y_PLANE].i_visible_pitch,
              (*pp_pic)->p[Y_PLANE].i_visible_lines );
+
+    return VLC_SUCCESS;
 }
 
 /*****************************************************************************
@@ -153,10 +156,8 @@ 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_sys = p_filter->p_sys;
     p_sys->b_done = VLC_FALSE;
 
@@ -175,7 +176,7 @@ static int Create( vlc_object_t *p_this )
     psz_temp = var_CreateGetStringCommand( p_filter, CFG_PREFIX "base-chroma" );
     p_sys->i_base_chroma = VLC_FOURCC( psz_temp[0], psz_temp[1],
                                        psz_temp[2], psz_temp[3] );
-    LoadImage( p_this, &p_sys->p_base_image, p_sys->i_base_chroma,
+    blendbench_LoadImage( p_this, &p_sys->p_base_image, p_sys->i_base_chroma,
                var_CreateGetStringCommand( p_filter, CFG_PREFIX "base-image" ),
                "Base" );
 
@@ -183,7 +184,7 @@ static int Create( vlc_object_t *p_this )
                                            CFG_PREFIX "blend-chroma" );
     p_sys->i_blend_chroma = VLC_FOURCC( psz_temp[0], psz_temp[1],
                                         psz_temp[2], psz_temp[3] );
-    LoadImage( p_this, &p_sys->p_blend_image, p_sys->i_blend_chroma,
+    blendbench_LoadImage( p_this, &p_sys->p_blend_image, p_sys->i_blend_chroma,
                var_CreateGetStringCommand( p_filter, CFG_PREFIX "blend-image" ),
                "Blend" );
 
@@ -208,26 +209,35 @@ static void Destroy( vlc_object_t *p_this )
 static picture_t *Filter( filter_t *p_filter, picture_t *p_pic )
 {
     filter_sys_t *p_sys = p_filter->p_sys;
+    filter_t *p_blend;
 
     if( p_sys->b_done )
-    {
         return p_pic;
-    }
-
-    filter_t *p_blend;
 
     p_blend = vlc_object_create( p_filter, VLC_OBJECT_FILTER );
+    if( !p_blend )
+    {
+        p_pic->pf_release( p_pic );
+        return NULL;
+    }
     vlc_object_attach( p_blend, p_filter );
     p_blend->fmt_out.video = p_sys->p_base_image->format;
     p_blend->fmt_in.video = p_sys->p_blend_image->format;
     p_blend->p_module = module_Need( p_blend, "video blending", 0, 0 );
+    if( !p_blend->p_module )
+    {
+        p_pic->pf_release( p_pic );
+        vlc_object_detach( p_blend );
+        vlc_object_release( p_blend );
+        return NULL;
+    }
 
     mtime_t time = mdate();
     for( int i_iter = 0; i_iter < p_sys->i_loops; ++i_iter )
     {
         p_blend->pf_video_blend( p_blend, p_sys->p_base_image,
-                                 p_sys->p_base_image, p_sys->p_blend_image, 0,
-                                 0, p_sys->i_alpha );
+                                 p_sys->p_base_image, p_sys->p_blend_image,
+                                 0, 0, p_sys->i_alpha );
     }
     time = mdate() - time;
 
@@ -242,7 +252,7 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_pic )
     module_Unneed( p_blend, p_blend->p_module );
 
     vlc_object_detach( p_blend );
-    vlc_object_destroy( p_blend );
+    vlc_object_release( p_blend );
 
     p_sys->b_done = VLC_TRUE;
     return p_pic;