]> git.sesse.net Git - vlc/blobdiff - modules/video_filter/time.c
Make Zorglub less unhappy
[vlc] / modules / video_filter / time.c
index e2a7dff4d12ffdcebda6c871ef4da22ca33db478..ed32e298b5b14f085422a75bfeb38a8c0e8d0877 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * time.c : time display video plugin for vlc
  *****************************************************************************
- * Copyright (C) 2003-2005 VideoLAN
+ * Copyright (C) 2003-2005 the VideoLAN team
  * $Id$
  *
  * Authors: Sigmund Augdal <sigmunau@idi.ntnu.no>
@@ -27,6 +27,8 @@
 #include <stdlib.h>                                      /* malloc(), free() */
 #include <string.h>
 
+#include <time.h>
+
 #include <vlc/vlc.h>
 #include <vlc/vout.h>
 
@@ -61,8 +63,7 @@ struct filter_sys_t
     int i_xoff, i_yoff;  /* offsets for the display string in the video window */
     char *psz_format;    /* time format string */
     int i_pos;  /* permit relative positioning (top, bottom, left, right, center) */
-    int  i_font_color, i_font_opacity; /* font color control */
-    vlc_bool_t b_absolute;  /* position control, relative vs. absolute */
+    int  i_font_color, i_font_opacity, i_font_size; /* font control */
 
     time_t last_time;
 };
@@ -73,12 +74,16 @@ struct filter_sys_t
 #define POSX_LONGTEXT N_("X offset, from the left screen edge" )
 #define POSY_TEXT N_("Y offset, from the top")
 #define POSY_LONGTEXT N_("Y offset, down from the top" )
-#define OPACITY_TEXT N_("Opacity, -1..255")
-#define OPACITY_LONGTEXT N_("The opacity (inverse of transparency) of overlay text. " \
-    "-1 = use freetype-opacity, 0 = transparent, 255 = totally opaque. " )
+#define OPACITY_TEXT N_("Opacity, 0..255")
+#define OPACITY_LONGTEXT N_("The opacity (inverse of transparency) of " \
+    "overlay text. 0 = transparent, 255 = totally opaque. " )
+#define SIZE_TEXT N_("Font size, pixels")
+#define SIZE_LONGTEXT N_("Specify the font size, in pixels, " \
+    "with -1 = use freetype-fontsize" )
+
 #define COLOR_TEXT N_("Text Default Color")
-#define COLOR_LONGTEXT N_("The color of overlay text. 1 byte for each color, hexadecimal." \
-    "-1 = use freetype-color, #000000 = all colors off, " \
+#define COLOR_LONGTEXT N_("The color of overlay text. 1 byte for each color, hexadecimal. " \
+    "#000000 = all colors off, " \
     "0xFF0000 = just Red, 0xFFFFFF = all color on [White]" )
 #define POS_TEXT N_("Time position")
 #define POS_LONGTEXT N_( \
@@ -106,10 +111,11 @@ vlc_module_begin();
     add_integer( "time-position", 9, NULL, POS_TEXT, POS_LONGTEXT, VLC_TRUE );
     /* 9 sets the default to bottom-left, minimizing jitter */
     change_integer_list( pi_pos_values, ppsz_pos_descriptions, 0 );
-    add_integer_with_range( "time-opacity", -1, -1, 255, NULL,
+    add_integer_with_range( "time-opacity", 255, 0, 255, NULL,
         OPACITY_TEXT, OPACITY_LONGTEXT, VLC_FALSE );
-    add_integer( "time-color", -1, NULL, COLOR_TEXT, COLOR_LONGTEXT, VLC_TRUE );
+    add_integer( "time-color", 0xFFFFFF, NULL, COLOR_TEXT, COLOR_LONGTEXT, VLC_TRUE );
         change_integer_list( pi_color_values, ppsz_color_descriptions, 0 );
+    add_integer( "time-size", -1, NULL, SIZE_TEXT, SIZE_LONGTEXT, VLC_FALSE );
     set_description( _("Time display sub filter") );
     add_shortcut( "time" );
 vlc_module_end();
@@ -122,7 +128,6 @@ static int CreateFilter( vlc_object_t *p_this )
     filter_t *p_filter = (filter_t *)p_this;
     filter_sys_t *p_sys;
     vlc_object_t *p_input;
-    vlc_value_t     val;
 
     /* Allocate structure */
     p_sys = p_filter->p_sys = malloc( sizeof( filter_sys_t ) );
@@ -145,13 +150,15 @@ static int CreateFilter( vlc_object_t *p_this )
     var_Create( p_input->p_libvlc, "time-opacity", VLC_VAR_INTEGER|VLC_VAR_DOINHERIT );
     p_sys->i_font_opacity = var_CreateGetInteger( p_input->p_libvlc , "time-opacity" );
     p_sys->i_font_color = var_CreateGetInteger( p_input->p_libvlc , "time-color" );
-    
+    p_sys->i_font_size = var_CreateGetInteger( p_input->p_libvlc , "time-size" );
+   
     var_AddCallback( p_input->p_libvlc, "time-x", TimeCallback, p_sys );
     var_AddCallback( p_input->p_libvlc, "time-y", TimeCallback, p_sys );
     var_AddCallback( p_input->p_libvlc, "time-format", TimeCallback, p_sys );
     var_AddCallback( p_input->p_libvlc, "time-position", TimeCallback, p_sys );
     var_AddCallback( p_input->p_libvlc, "time-color", TimeCallback, p_sys );
     var_AddCallback( p_input->p_libvlc, "time-opacity", TimeCallback, p_sys );
+    var_AddCallback( p_input->p_libvlc, "time-size", TimeCallback, p_sys );
 
     vlc_object_release( p_input );
 
@@ -184,6 +191,8 @@ static void DestroyFilter( vlc_object_t *p_this )
     var_Destroy( p_input->p_libvlc , "time-position" );
     var_Destroy( p_input->p_libvlc , "time-color");
     var_Destroy( p_input->p_libvlc , "time-opacity");
+    var_Destroy( p_input->p_libvlc , "time-size");
+   
     vlc_object_release( p_input );
 }
 
@@ -224,16 +233,9 @@ static subpicture_t *Filter( filter_t *p_filter, mtime_t date )
 
     if( p_sys->last_time == time( NULL ) ) return NULL;
 
-    p_sys->b_absolute = VLC_TRUE;
-    if( p_sys->i_xoff < 0 || p_sys->i_yoff < 0 )
-    {
-        p_sys->b_absolute = VLC_FALSE;
-    }
-
     p_spu = p_filter->pf_sub_buffer_new( p_filter );
     if( !p_spu ) return NULL;
 
-    p_spu->b_absolute = p_sys->b_absolute;
     memset( &fmt, 0, sizeof(video_format_t) );
     fmt.i_chroma = VLC_FOURCC('T','E','X','T');
     fmt.i_aspect = 0;
@@ -253,13 +255,25 @@ static subpicture_t *Filter( filter_t *p_filter, mtime_t date )
     p_spu->i_start = date;
     p_spu->i_stop  = 0;
     p_spu->b_ephemer = VLC_TRUE;
-    p_spu->b_absolute = VLC_FALSE;
-    p_spu->i_x = p_sys->i_xoff;
-    p_spu->i_y = p_sys->i_yoff;
-    p_spu->p_region->i_font_color = p_sys->i_font_color;
-    p_spu->p_region->i_font_opacity = p_sys->i_font_opacity;;
 
-    p_spu->i_flags = p_sys->i_pos;
+    /*  where to locate the string: */
+    if( p_sys->i_xoff < 0 || p_sys->i_yoff < 0 )
+    {   /* set to one of the 9 relative locations */
+        p_spu->i_flags = p_sys->i_pos;
+        p_spu->i_x = 0;
+        p_spu->i_y = 0;
+        p_spu->b_absolute = VLC_FALSE;
+    }
+    else
+    {   /*  set to an absolute xy, referenced to upper left corner */
+           p_spu->i_flags = OSD_ALIGN_LEFT | OSD_ALIGN_TOP;
+        p_spu->i_x = p_sys->i_xoff;
+        p_spu->i_y = p_sys->i_yoff;
+        p_spu->b_absolute = VLC_TRUE;
+    }
+    p_spu->p_region->i_text_color = p_sys->i_font_color;
+    p_spu->p_region->i_text_alpha = 255 - p_sys->i_font_opacity;
+    p_spu->p_region->i_text_size = p_sys->i_font_size;
 
     return p_spu;
 }
@@ -285,14 +299,18 @@ static int TimeCallback( vlc_object_t *p_this, char const *psz_var,
     {
         p_sys->i_yoff = newval.i_int;
     }
-    else if ( !strncmp( psz_var, "time-color", 8 ) )  /* "time-col" */ 
+    else if ( !strncmp( psz_var, "time-color", 8 ) )  /* "time-c" */ 
     {
         p_sys->i_font_color = newval.i_int;
     }
-    else if ( !strncmp( psz_var, "time-opacity", 8 ) ) /* "time-opa" */ 
+    else if ( !strncmp( psz_var, "time-opacity", 8 ) ) /* "time-o" */ 
     {
         p_sys->i_font_opacity = newval.i_int;
     }
+    else if ( !strncmp( psz_var, "time-size", 6 ) )
+    {
+        p_sys->i_font_size = newval.i_int;
+    }
     else if ( !strncmp( psz_var, "time-position", 8 ) )
     /* willing to accept a match against time-pos */
     {