]> git.sesse.net Git - vlc/blobdiff - modules/video_filter/magnify.c
Use picture helpers (Yield,Release,CopyProperties).
[vlc] / modules / video_filter / magnify.c
index 9b5f492281addbb1dc3b762cc7331eade403a164..316cfcaff3fa41a4e56aa22974babe8edacd1f36 100644 (file)
@@ -29,7 +29,8 @@
 # include "config.h"
 #endif
 
-#include <vlc/vlc.h>
+#include <vlc_common.h>
+#include <vlc_plugin.h>
 #include <vlc_vout.h>
 
 #include <math.h>
@@ -60,8 +61,8 @@ static int  MouseEvent   ( vlc_object_t *, char const *,
  * Module descriptor
  *****************************************************************************/
 vlc_module_begin();
-    set_description( _("Magnify/Zoom interactive video filter") );
-    set_shortname( _( "Magnify" ));
+    set_description( N_("Magnify/Zoom interactive video filter") );
+    set_shortname( N_( "Magnify" ));
     set_capability( "video filter", 0 );
     set_category( CAT_VIDEO );
     set_subcategory( SUBCAT_VIDEO_VFILTER );
@@ -81,7 +82,7 @@ struct vout_sys_t
     int i_zoom; /* zoom level in percent */
     int i_x, i_y; /* top left corner coordinates in original image */
 
-    vlc_bool_t b_visible; /* is "interface" visible ? */
+    bool b_visible; /* is "interface" visible ? */
 };
 
 /*****************************************************************************
@@ -112,10 +113,7 @@ static int Create( vlc_object_t *p_this )
     /* Allocate structure */
     p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
     if( p_vout->p_sys == NULL )
-    {
-        msg_Err( p_vout, "out of memory" );
         return VLC_ENOMEM;
-    }
 
     p_vout->p_sys->p_image = image_HandlerCreate( p_vout );
 
@@ -167,7 +165,7 @@ static int Init( vout_thread_t *p_vout )
     p_vout->p_sys->i_y = 0;
 #define ZOOM_FACTOR 8
     p_vout->p_sys->i_zoom = 2*ZOOM_FACTOR;
-    p_vout->p_sys->b_visible = VLC_TRUE;
+    p_vout->p_sys->b_visible = true;
 
     var_AddCallback( p_vout->p_sys->p_vout, "mouse-x", MouseEvent, p_vout );
     var_AddCallback( p_vout->p_sys->p_vout, "mouse-y", MouseEvent, p_vout );
@@ -188,6 +186,10 @@ static void End( vout_thread_t *p_vout )
 {
     int i_index;
 
+    DEL_PARENT_CALLBACKS( SendEventsToChild );
+
+    DEL_CALLBACKS( p_vout->p_sys->p_vout, SendEvents );
+
     /* Free the fake output buffers we allocated */
     for( i_index = I_OUTPUTPICTURES ; i_index ; )
     {
@@ -198,6 +200,8 @@ static void End( vout_thread_t *p_vout )
     var_DelCallback( p_vout->p_sys->p_vout, "mouse-x", MouseEvent, p_vout);
     var_DelCallback( p_vout->p_sys->p_vout, "mouse-y", MouseEvent, p_vout);
     var_DelCallback( p_vout->p_sys->p_vout, "mouse-clicked", MouseEvent, p_vout);
+
+    vout_CloseAndRelease( p_vout->p_sys->p_vout );
 }
 
 /*****************************************************************************
@@ -207,16 +211,8 @@ static void Destroy( vlc_object_t *p_this )
 {
     vout_thread_t *p_vout = (vout_thread_t *)p_this;
 
-    if( p_vout->p_sys->p_vout )
-    {
-        DEL_CALLBACKS( p_vout->p_sys->p_vout, SendEvents );
-        vlc_object_detach( p_vout->p_sys->p_vout );
-        vout_Destroy( p_vout->p_sys->p_vout );
-    }
-
     image_HandlerDelete( p_vout->p_sys->p_image );
 
-    DEL_PARENT_CALLBACKS( SendEventsToChild );
 
     free( p_vout->p_sys );
 }
@@ -243,7 +239,7 @@ static void Render( vout_thread_t *p_vout, picture_t *p_pic )
     while( ( p_outpic = vout_CreatePicture( p_vout->p_sys->p_vout, 0, 0, 0 ) )
               == NULL )
     {
-        if( p_vout->b_die || p_vout->b_error )
+        if( !vlc_object_alive (p_vout) || p_vout->b_error )
         {
             return;
         }
@@ -361,8 +357,7 @@ static void Render( vout_thread_t *p_vout, picture_t *p_pic )
     {
         for( i_plane = 0; i_plane < p_pic->i_planes; i_plane++ )
         {
-        p_vout->p_libvlc->
-        pf_memcpy( p_outpic->p[i_plane].p_pixels, p_pic->p[i_plane].p_pixels,
+        vlc_memcpy( p_outpic->p[i_plane].p_pixels, p_pic->p[i_plane].p_pixels,
             p_outpic->p[i_plane].i_lines * p_outpic->p[i_plane].i_pitch );
         }
     }
@@ -379,19 +374,19 @@ static void Render( vout_thread_t *p_vout, picture_t *p_pic )
         {
             for( y=0; y<p_converted->p[i_plane].i_visible_lines; y++)
             {
-                p_vout->p_libvlc->pf_memcpy(
+                vlc_memcpy(
                 p_outpic->p[i_plane].p_pixels+y*p_outpic->p[i_plane].i_pitch,
                 p_converted->p[i_plane].p_pixels+y*p_converted->p[i_plane].i_pitch,
                 p_converted->p[i_plane].i_visible_pitch );
             }
         }
-        p_converted->pf_release( p_converted );
+        picture_Release( p_converted );
 
         /* white rectangle on visualization */
         v_w = p_oyp->i_pitch*ZOOM_FACTOR/(VIS_ZOOM*o_zoom);
         v_h = (o_y+p_oyp->i_lines*ZOOM_FACTOR/o_zoom)/VIS_ZOOM;
         /* top line */
-        p_vout->p_libvlc->pf_memset( p_oyp->p_pixels
+        vlc_memset( p_oyp->p_pixels
                                      + o_y/VIS_ZOOM*p_oyp->i_pitch
                                      + o_x/VIS_ZOOM, 0xff, v_w+1 );
 
@@ -407,7 +402,7 @@ static void Render( vout_thread_t *p_vout, picture_t *p_pic )
             ] = 0xff;
         }
         /* bottom line */
-        p_vout->p_libvlc->pf_memset( p_oyp->p_pixels
+        vlc_memset( p_oyp->p_pixels
                                      + v_h*p_oyp->i_pitch
                                      + o_x/VIS_ZOOM, 0xff, v_w+1 );
 
@@ -450,18 +445,14 @@ o o X o o o X X X X X o o X X X X o o o X X X X X o o X X X o o o X X X o o X o
     if( p_vout->p_sys->b_visible )
     {
         /* zoom gauge */
-        p_vout->p_libvlc->pf_memset( p_oyp->p_pixels
-                                     + (v_h+9)*p_oyp->i_pitch,
-                                     0xff, 41 );
+        vlc_memset( p_oyp->p_pixels + (v_h+9)*p_oyp->i_pitch, 0xff, 41 );
         for( y = v_h + 10; y < v_h + 90; y++ )
         {
             int width = v_h + 90 - y;
             width = (width*width)/160;
-            if( (80 - y + v_h)*10 < o_zoom )
+            if( (80 - y + v_h)*ZOOM_FACTOR/10 < o_zoom )
             {
-                p_vout->p_libvlc->pf_memset( p_oyp->p_pixels
-                                             + y*p_oyp->i_pitch,
-                                             0xff, width );
+                vlc_memset( p_oyp->p_pixels + y*p_oyp->i_pitch, 0xff, width );
             }
             else
             {
@@ -470,7 +461,6 @@ o o X o o o X X X X X o o X X X X o o o X X X X X o o X X X o o o X X X o o X o
             }
         }
     }
-
     vout_DisplayPicture( p_vout->p_sys->p_vout, p_outpic );
 }
 
@@ -550,7 +540,7 @@ static int MouseEvent( vlc_object_t *p_this, char const *psz_var,
                 && mouse&MOUSE_CLICKED )
             {
             /* mouse is over the "VLC ZOOM HIDE" text */
-                p_vout->p_sys->b_visible = VLC_FALSE;
+                p_vout->p_sys->b_visible = false;
             }
             else if(    (int)p_vout->output.i_height/VIS_ZOOM + 9 <= valy.i_int
                      && valy.i_int <= (int)p_vout->output.i_height/VIS_ZOOM + 90
@@ -581,7 +571,7 @@ static int MouseEvent( vlc_object_t *p_this, char const *psz_var,
                 && valy.i_int <= 10 && mouse&MOUSE_CLICKED )
             {
             /* mouse is over the "VLC ZOOM SHOW" text */
-                p_vout->p_sys->b_visible = VLC_TRUE;
+                p_vout->p_sys->b_visible = true;
             }
             else if( mouse&MOUSE_MOVE_X && !(mouse&MOUSE_CLICKED) )
             {