]> git.sesse.net Git - vlc/blobdiff - modules/video_filter/distort.c
* ALL: use i_visible_lines in plane_t.
[vlc] / modules / video_filter / distort.c
index c3ba5fa82a349ba67ea83aeb852f5d16e12c4c82..10a570282173fb70c7acde6bf4dae70a43941dc3 100644 (file)
@@ -1,8 +1,8 @@
 /*****************************************************************************
  * distort.c : Misc video effects plugin for vlc
  *****************************************************************************
- * Copyright (C) 2000, 2001 VideoLAN
- * $Id: distort.c,v 1.1 2002/08/04 17:23:43 sam Exp $
+ * Copyright (C) 2000, 2001, 2002, 2003 VideoLAN
+ * $Id$
  *
  * Authors: Samuel Hocevar <sam@zoy.org>
  *
@@ -10,7 +10,7 @@
  * 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
@@ -24,7 +24,6 @@
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
-#include <errno.h>
 #include <stdlib.h>                                      /* malloc(), free() */
 #include <string.h>
 
@@ -51,20 +50,26 @@ static void Render    ( vout_thread_t *, picture_t * );
 static void DistortWave    ( vout_thread_t *, picture_t *, picture_t * );
 static void DistortRipple  ( vout_thread_t *, picture_t *, picture_t * );
 
+static int  SendEvents   ( vlc_object_t *, char const *,
+                           vlc_value_t, vlc_value_t, void * );
+
 /*****************************************************************************
  * Module descriptor
  *****************************************************************************/
 #define MODE_TEXT N_("Distort mode")
-#define MODE_LONGTEXT N_("one of \"wave\" and \"ripple\"")
+#define MODE_LONGTEXT N_("Distort mode, one of \"wave\" and \"ripple\"")
 
-static char *mode_list[] = { "wave", "ripple", NULL };
+static char *mode_list[] = { "wave", "ripple" };
+static char *mode_list_text[] = { N_("Wave"), N_("Ripple") };
 
 vlc_module_begin();
-    add_category_hint( N_("Miscellaneous"), NULL );
-    add_string_from_list( "distort-mode", "wave", mode_list, NULL,
-                          MODE_TEXT, MODE_LONGTEXT );
-    set_description( _("miscellaneous video effects module") );
+    set_description( _("Distort video filter") );
     set_capability( "video filter", 0 );
+
+    add_string( "distort-mode", "wave", NULL, MODE_TEXT, MODE_LONGTEXT,
+                VLC_FALSE );
+        change_string_list( mode_list, mode_list_text, 0 );
+
     add_shortcut( "distort" );
     set_callbacks( Create, Destroy );
 vlc_module_end();
@@ -85,6 +90,14 @@ struct vout_sys_t
     mtime_t last_date;
 };
 
+/*****************************************************************************
+ * Control: control facility for the vout (forwards to child vout)
+ *****************************************************************************/
+static int Control( vout_thread_t *p_vout, int i_query, va_list args )
+{
+    return vout_vaControl( p_vout->p_sys->p_vout, i_query, args );
+}
+
 /*****************************************************************************
  * Create: allocates Distort video thread output method
  *****************************************************************************
@@ -100,7 +113,7 @@ static int Create( vlc_object_t *p_this )
     if( p_vout->p_sys == NULL )
     {
         msg_Err( p_vout, "out of memory" );
-        return( 1 );
+        return VLC_ENOMEM;
     }
 
     p_vout->pf_init = Init;
@@ -108,63 +121,40 @@ static int Create( vlc_object_t *p_this )
     p_vout->pf_manage = NULL;
     p_vout->pf_render = Render;
     p_vout->pf_display = NULL;
+    p_vout->pf_control = Control;
 
     p_vout->p_sys->i_mode = 0;
-    /* Look what method was requested from command line*/
-    if( !(psz_method = psz_method_tmp = config_GetPsz( p_vout, "filter" )) )
-    {
-        msg_Err( p_vout, "configuration variable %s empty", "filter" );
-        return( 1 );
-    }
-    while( *psz_method && *psz_method != ':' )
-    {
-        psz_method++;
-    }
 
-    if( !strcmp( psz_method, ":wave" ) )
+    if( !(psz_method = psz_method_tmp
+          = config_GetPsz( p_vout, "distort-mode" )) )
     {
+        msg_Err( p_vout, "configuration variable %s empty, using 'wave'",
+                         "distort-mode" );
         p_vout->p_sys->i_mode = DISTORT_MODE_WAVE;
     }
-    else if( !strcmp( psz_method, ":ripple" ) )
+    else
     {
-        p_vout->p_sys->i_mode = DISTORT_MODE_RIPPLE;
-    }
-    free( psz_method_tmp );
-    if( !p_vout->p_sys->i_mode )
-    {
-        /* No method given in commandline. Look what method was
-         requested in configuration system */
-        if( !(psz_method = psz_method_tmp
-              = config_GetPsz( p_vout, "distort-mode" )) )
+
+        if( !strcmp( psz_method, "wave" ) )
         {
-            msg_Err( p_vout, "configuration variable %s empty, using 'wave'",
-                             "distort-mode" );
             p_vout->p_sys->i_mode = DISTORT_MODE_WAVE;
         }
-        else {
-        
-            if( !strcmp( psz_method, "wave" ) )
-            {
-                p_vout->p_sys->i_mode = DISTORT_MODE_WAVE;
-            }
-            else if( !strcmp( psz_method, "ripple" ) )
-            {
-                p_vout->p_sys->i_mode = DISTORT_MODE_RIPPLE;
-            }
-            
-            else
-            {
-                msg_Err( p_vout, "no valid distort mode provided, "
-                                 "using wave" );
-                p_vout->p_sys->i_mode = DISTORT_MODE_WAVE;
-            }
+        else if( !strcmp( psz_method, "ripple" ) )
+        {
+            p_vout->p_sys->i_mode = DISTORT_MODE_RIPPLE;
+        }
+        else
+        {
+            msg_Err( p_vout, "no valid distort mode provided, "
+                             "using wave" );
+            p_vout->p_sys->i_mode = DISTORT_MODE_WAVE;
         }
     }
     free( psz_method_tmp );
-    
-    return( 0 );
+
+    return VLC_SUCCESS;
 }
-    
+
 /*****************************************************************************
  * Init: initialize Distort video thread output method
  *****************************************************************************/
@@ -184,8 +174,7 @@ static int Init( vout_thread_t *p_vout )
     /* Try to open the real video output */
     msg_Dbg( p_vout, "spawning the real video output" );
 
-    p_vout->p_sys->p_vout =
-        vout_CreateThread( p_vout,
+    p_vout->p_sys->p_vout = vout_Create( p_vout,
                            p_vout->render.i_width, p_vout->render.i_height,
                            p_vout->render.i_chroma, p_vout->render.i_aspect );
 
@@ -193,16 +182,19 @@ static int Init( vout_thread_t *p_vout )
     if( p_vout->p_sys->p_vout == NULL )
     {
         msg_Err( p_vout, "cannot open vout, aborting" );
-
-        return( 0 );
+        return VLC_EGENERIC;
     }
+
     ALLOCATE_DIRECTBUFFERS( VOUT_MAX_PICTURES );
 
+    ADD_CALLBACKS( p_vout->p_sys->p_vout, SendEvents );
+
+    ADD_PARENT_CALLBACKS( SendEventsToChild );
+
     p_vout->p_sys->f_angle = 0.0;
     p_vout->p_sys->last_date = 0;
 
-    return( 0 );
+    return VLC_SUCCESS;
 }
 
 /*****************************************************************************
@@ -229,7 +221,14 @@ static void Destroy( vlc_object_t *p_this )
 {
     vout_thread_t *p_vout = (vout_thread_t *)p_this;
 
-    vout_DestroyThread( p_vout->p_sys->p_vout );
+    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 );
+    }
+
+    DEL_PARENT_CALLBACKS( SendEventsToChild );
 
     free( p_vout->p_sys );
 }
@@ -292,13 +291,13 @@ static void DistortWave( vout_thread_t *p_vout, picture_t *p_inpic,
     for( i_index = 0 ; i_index < p_inpic->i_planes ; i_index++ )
     {
         int i_line, i_num_lines, i_offset;
-        u8 black_pixel;
-        u8 *p_in, *p_out;
+        uint8_t black_pixel;
+        uint8_t *p_in, *p_out;
 
         p_in = p_inpic->p[i_index].p_pixels;
         p_out = p_outpic->p[i_index].p_pixels;
 
-        i_num_lines = p_inpic->p[i_index].i_lines;
+        i_num_lines = p_inpic->p[i_index].i_visible_lines;
 
         black_pixel = ( i_index == Y_PLANE ) ? 0x00 : 0x80;
 
@@ -306,17 +305,17 @@ static void DistortWave( vout_thread_t *p_vout, picture_t *p_inpic,
         for( i_line = 0 ; i_line < i_num_lines ; i_line++ )
         {
             /* Calculate today's offset, don't go above 1/20th of the screen */
-            i_offset = (double)(p_inpic->p[i_index].i_pitch)
+            i_offset = (int)( (double)(p_inpic->p[i_index].i_visible_pitch)
                          * sin( f_angle + 10.0 * (double)i_line
                                                / (double)i_num_lines )
-                         / 20.0;
+                         / 20.0 );
 
             if( i_offset )
             {
                 if( i_offset < 0 )
                 {
                     p_vout->p_vlc->pf_memcpy( p_out, p_in - i_offset,
-                                 p_inpic->p[i_index].i_pitch + i_offset );
+                             p_inpic->p[i_index].i_visible_pitch + i_offset );
                     p_in += p_inpic->p[i_index].i_pitch;
                     p_out += p_outpic->p[i_index].i_pitch;
                     memset( p_out + i_offset, black_pixel, -i_offset );
@@ -324,7 +323,7 @@ static void DistortWave( vout_thread_t *p_vout, picture_t *p_inpic,
                 else
                 {
                     p_vout->p_vlc->pf_memcpy( p_out + i_offset, p_in,
-                                 p_inpic->p[i_index].i_pitch - i_offset );
+                             p_inpic->p[i_index].i_visible_pitch - i_offset );
                     memset( p_out, black_pixel, i_offset );
                     p_in += p_inpic->p[i_index].i_pitch;
                     p_out += p_outpic->p[i_index].i_pitch;
@@ -333,7 +332,7 @@ static void DistortWave( vout_thread_t *p_vout, picture_t *p_inpic,
             else
             {
                 p_vout->p_vlc->pf_memcpy( p_out, p_in,
-                                          p_inpic->p[i_index].i_pitch );
+                                          p_inpic->p[i_index].i_visible_pitch );
                 p_in += p_inpic->p[i_index].i_pitch;
                 p_out += p_outpic->p[i_index].i_pitch;
             }
@@ -359,42 +358,44 @@ static void DistortRipple( vout_thread_t *p_vout, picture_t *p_inpic,
     for( i_index = 0 ; i_index < p_inpic->i_planes ; i_index++ )
     {
         int i_line, i_first_line, i_num_lines, i_offset;
-        u8 black_pixel;
-        u8 *p_in, *p_out;
+        uint8_t black_pixel;
+        uint8_t *p_in, *p_out;
 
         black_pixel = ( i_index == Y_PLANE ) ? 0x00 : 0x80;
 
-        i_num_lines = p_inpic->p[i_index].i_lines;
+        i_num_lines = p_inpic->p[i_index].i_visible_lines;
 
         i_first_line = i_num_lines * 4 / 5;
 
         p_in = p_inpic->p[i_index].p_pixels;
         p_out = p_outpic->p[i_index].p_pixels;
 
-        p_vout->p_vlc->pf_memcpy( p_out, p_in,
-                                  i_first_line * p_inpic->p[i_index].i_pitch );
-
-        p_in += i_first_line * p_inpic->p[i_index].i_pitch;
-        p_out += i_first_line * p_outpic->p[i_index].i_pitch;
+        for( i_line = 0 ; i_line < i_first_line ; i_line++ )
+        {
+            p_vout->p_vlc->pf_memcpy( p_out, p_in,
+                                      p_inpic->p[i_index].i_visible_pitch );
+            p_in += p_inpic->p[i_index].i_pitch;
+            p_out += p_outpic->p[i_index].i_pitch;
+        }
 
         /* Ok, we do 3 times the sin() calculation for each line. So what ? */
         for( i_line = i_first_line ; i_line < i_num_lines ; i_line++ )
         {
             /* Calculate today's offset, don't go above 1/20th of the screen */
-            i_offset = (double)(p_inpic->p[i_index].i_pitch)
+            i_offset = (int)( (double)(p_inpic->p[i_index].i_pitch)
                          * sin( f_angle + 2.0 * (double)i_line
                                               / (double)( 1 + i_line
                                                             - i_first_line) )
                          * (double)(i_line - i_first_line)
                          / (double)i_num_lines
-                         / 8.0;
+                         / 8.0 );
 
             if( i_offset )
             {
                 if( i_offset < 0 )
                 {
                     p_vout->p_vlc->pf_memcpy( p_out, p_in - i_offset,
-                                 p_inpic->p[i_index].i_pitch + i_offset );
+                             p_inpic->p[i_index].i_visible_pitch + i_offset );
                     p_in -= p_inpic->p[i_index].i_pitch;
                     p_out += p_outpic->p[i_index].i_pitch;
                     memset( p_out + i_offset, black_pixel, -i_offset );
@@ -402,7 +403,7 @@ static void DistortRipple( vout_thread_t *p_vout, picture_t *p_inpic,
                 else
                 {
                     p_vout->p_vlc->pf_memcpy( p_out + i_offset, p_in,
-                                 p_inpic->p[i_index].i_pitch - i_offset );
+                             p_inpic->p[i_index].i_visible_pitch - i_offset );
                     memset( p_out, black_pixel, i_offset );
                     p_in -= p_inpic->p[i_index].i_pitch;
                     p_out += p_outpic->p[i_index].i_pitch;
@@ -411,7 +412,7 @@ static void DistortRipple( vout_thread_t *p_vout, picture_t *p_inpic,
             else
             {
                 p_vout->p_vlc->pf_memcpy( p_out, p_in,
-                                          p_inpic->p[i_index].i_pitch );
+                                          p_inpic->p[i_index].i_visible_pitch );
                 p_in -= p_inpic->p[i_index].i_pitch;
                 p_out += p_outpic->p[i_index].i_pitch;
             }
@@ -419,3 +420,25 @@ static void DistortRipple( vout_thread_t *p_vout, picture_t *p_inpic,
         }
     }
 }
+
+/*****************************************************************************
+ * SendEvents: forward mouse and keyboard events to the parent p_vout
+ *****************************************************************************/
+static int SendEvents( vlc_object_t *p_this, char const *psz_var,
+                       vlc_value_t oldval, vlc_value_t newval, void *p_data )
+{
+    var_Set( (vlc_object_t *)p_data, psz_var, newval );
+
+    return VLC_SUCCESS;
+}
+
+/*****************************************************************************
+ * SendEventsToChild: forward events to the child/children vout
+ *****************************************************************************/
+static int SendEventsToChild( vlc_object_t *p_this, char const *psz_var,
+                       vlc_value_t oldval, vlc_value_t newval, void *p_data )
+{
+    vout_thread_t *p_vout = (vout_thread_t *)p_this;
+    var_Set( p_vout->p_sys->p_vout, psz_var, newval );
+    return VLC_SUCCESS;
+}