Commit 6b385019 authored by Mark Moriarty's avatar Mark Moriarty

dynamic, per-subpicture, font size control -- i_font_size added to...

dynamic, per-subpicture, font size control -- i_font_size added to subpicture_region_t, new marq-size and time-size shortcuts, accessible from rc
parent 8c93323c
......@@ -58,7 +58,8 @@ struct filter_t
int, int, int );
subpicture_t * ( *pf_sub_filter ) ( filter_t *, mtime_t );
subpicture_t * ( *pf_render_string ) ( filter_t *, block_t *, int, int );
/* pf_render_string maps to RenderText in freetype.c */
subpicture_t * ( *pf_render_string ) ( filter_t *, block_t *, int, int, int );
/*
* Buffers allocation
......
......@@ -209,6 +209,7 @@ struct subpicture_region_t
int i_x; /**< position of region */
int i_y; /**< position of region */
int i_font_color, i_font_opacity; /**< controls for text subpictures */
int i_font_size;
subpicture_region_t *p_next; /**< next region in the list */
subpicture_region_t *p_cache; /**< modified version of this region */
/**@}*/
......
......@@ -373,6 +373,8 @@ static void Run( intf_thread_t *p_intf )
var_AddCallback( p_intf, "marq-opacity", Other, NULL );
var_Create( p_intf, "marq-timeout", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
var_AddCallback( p_intf, "marq-timeout", Other, NULL );
var_Create( p_intf, "marq-size", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
var_AddCallback( p_intf, "marq-size", Other, NULL );
var_Create( p_intf, "mosaic-alpha", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
var_AddCallback( p_intf, "mosaic-alpha", Other, NULL );
......@@ -412,6 +414,8 @@ static void Run( intf_thread_t *p_intf )
var_AddCallback( p_intf, "time-color", Other, NULL );
var_Create( p_intf, "time-opacity", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
var_AddCallback( p_intf, "time-opacity", Other, NULL );
var_Create( p_intf, "time-size", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
var_AddCallback( p_intf, "time-size", Other, NULL );
var_Create( p_intf, "pause", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
var_AddCallback( p_intf, "pause", Input, NULL );
......@@ -710,6 +714,7 @@ static void Run( intf_thread_t *p_intf )
msg_rc(_("| marq-color # . . . . font color of marquee, RGB\n"));
msg_rc(_("| marq-opacity # . . . . . . . .opacity of marquee\n"));
msg_rc(_("| marq-timeout T. . . . timeout of marquee, in ms\n"));
msg_rc(_("| marq-size # . . . font size of marquee, in pixels\n"));
msg_rc( "| \n");
msg_rc(_("| time-format STRING . . . overlay STRING in video\n"));
msg_rc(_("| time-x X . . . . .offset of timestamp, from left\n"));
......@@ -717,6 +722,7 @@ static void Run( intf_thread_t *p_intf )
msg_rc(_("| time-position #. . . .relative position control\n"));
msg_rc(_("| time-color # . . . font color of timestamp, RGB\n"));
msg_rc(_("| time-opacity # . . . . . . .opacity of timestamp\n"));
msg_rc(_("| time-size # . .font size of timestamp, in pixels\n"));
msg_rc( "| \n");
}
msg_rc(_("| help . . . . . . . . . . . . . this help message\n"));
......@@ -1044,6 +1050,14 @@ static int Other( vlc_object_t *p_this, char const *psz_cmd,
var_Set( p_inp->p_libvlc, "marq-opacity", val );
}
}
else if( !strcmp( psz_cmd, "marq-size" ) )
{
if( strlen( newval.psz_string ) > 0)
{
val.i_int = atoi( newval.psz_string );
var_Set( p_inp->p_libvlc, "marq-size", val );
}
}
else if( !strcmp( psz_cmd, "marq-timeout" ) )
{
if( strlen( newval.psz_string ) > 0)
......@@ -1193,7 +1207,15 @@ static int Other( vlc_object_t *p_this, char const *psz_cmd,
var_Set( p_inp->p_libvlc, "time-opacity", val );
}
}
else if( !strcmp( psz_cmd, "time-size" ) )
{
if( strlen( newval.psz_string ) > 0)
{
val.i_int = atoi( newval.psz_string );
var_Set( p_inp->p_libvlc, "time-size", val );
}
}
/*
* sanity check
*/
......
......@@ -71,7 +71,7 @@ static int Create ( vlc_object_t * );
static void Destroy( vlc_object_t * );
/* The RenderText call maps to pf_render_string, defined in vlc_filter.h */
static subpicture_t *RenderText( filter_t *, block_t *, int, int );
static subpicture_t *RenderText( filter_t *, block_t *, int, int, int );
static line_desc_t *NewLine( byte_t * );
/*****************************************************************************
......@@ -171,6 +171,7 @@ struct filter_sys_t
uint8_t i_font_opacity; /* freetype-opacity */
int i_font_color; /* freetype-color */
int i_red, i_blue, i_green; /* function vars to render */
int i_font_size;
uint8_t i_opacity; /* function var to render */
uint8_t pi_gamma[256];
};
......@@ -186,7 +187,6 @@ static int Create( vlc_object_t *p_this )
filter_sys_t *p_sys;
char *psz_fontfile = NULL;
int i, i_error;
int i_fontsize = 0;
vlc_value_t val;
/* Allocate structure */
......@@ -198,6 +198,7 @@ static int Create( vlc_object_t *p_this )
}
p_sys->p_face = 0;
p_sys->p_library = 0;
p_sys->i_font_size = 0;
for( i = 0; i < 256; i++ )
{
......@@ -272,24 +273,24 @@ static int Create( vlc_object_t *p_this )
var_Get( p_filter, "freetype-fontsize", &val );
if( val.i_int )
{
i_fontsize = val.i_int;
p_sys->i_font_size = val.i_int;
}
else
{
var_Get( p_filter, "freetype-rel-fontsize", &val );
i_fontsize = (int)p_filter->fmt_out.video.i_height / val.i_int;
p_sys->i_font_size = (int)p_filter->fmt_out.video.i_height / val.i_int;
}
if( i_fontsize <= 0 )
if( p_sys->i_font_size <= 0 )
{
msg_Warn( p_filter, "Invalid fontsize, using 12" );
i_fontsize = 12;
p_sys->i_font_size = 12;
}
msg_Dbg( p_filter, "Using fontsize: %i", i_fontsize);
msg_Dbg( p_filter, "Using fontsize: %i", p_sys->i_font_size);
i_error = FT_Set_Pixel_Sizes( p_sys->p_face, 0, i_fontsize );
i_error = FT_Set_Pixel_Sizes( p_sys->p_face, 0, p_sys->i_font_size );
if( i_error )
{
msg_Err( p_filter, "couldn't set font size to %d", i_fontsize );
msg_Err( p_filter, "couldn't set font size to %d", p_sys->i_font_size );
goto error;
}
......@@ -328,7 +329,7 @@ static void Destroy( vlc_object_t *p_this )
*****************************************************************************/
static void Render( filter_t *p_filter, subpicture_t *p_spu,
subpicture_data_t *p_string, uint8_t opacity,
int red, int green, int blue )
int red, int green, int blue)
{
filter_sys_t *p_sys = p_filter->p_sys;
line_desc_t *p_line;
......@@ -336,7 +337,7 @@ static void Render( filter_t *p_filter, subpicture_t *p_spu,
video_format_t fmt;
int i, x, y, i_pitch;
uint8_t i_y, i_u, i_v; /* YUV values, derived from incoming RGB */
/* calculate text color components: */
i_y = (uint8_t) ( ( 66 * red + 129 * green + 25 * blue + 128) >> 8) + 16;
i_u = (uint8_t) ( ( -38 * red - 74 * green + 112 * blue + 128) >> 8) + 128;
......@@ -440,7 +441,7 @@ static void Render( filter_t *p_filter, subpicture_t *p_spu,
* the vout method by this module
*/
static subpicture_t *RenderText( filter_t *p_filter, block_t *p_block,
int font_color, int font_opacity )
int font_color, int font_opacity, int font_size )
{
filter_sys_t *p_sys = p_filter->p_sys;
subpicture_t *p_subpic = 0;
......@@ -502,10 +503,28 @@ static subpicture_t *RenderText( filter_t *p_filter, block_t *p_block,
#endif
if( iconv_handle == (vlc_iconv_t)-1 )
{
msg_Warn( p_filter, "unable to do convertion" );
msg_Warn( p_filter, "unable to do conversion" );
goto error;
}
/* Set up the glyphs for the desired font size. By definition,
p_sys->i_font_size is a valid value, else the initial Create would
have failed. Using -1 as a flag to use the freetype-fontsize */
if ( font_size < 0 )
{
FT_Set_Pixel_Sizes( p_sys->p_face, 0, p_sys->i_font_size );
}
else
{
i_error = FT_Set_Pixel_Sizes( p_sys->p_face, 0, font_size );
if( i_error )
{
msg_Warn( p_filter, "Invalid font size to RenderText, using %d",
p_sys->i_font_size );
FT_Set_Pixel_Sizes( p_sys->p_face, 0, p_sys->i_font_size );
}
}
{
char *p_in_buffer, *p_out_buffer;
size_t i_in_bytes, i_out_bytes, i_out_bytes_left, i_ret;
......
......@@ -66,7 +66,7 @@ struct filter_sys_t
char *psz_marquee; /* marquee string */
int i_font_color, i_font_opacity; /* font color control */
int i_font_color, i_font_opacity, i_font_size; /* font control */
time_t last_time;
vlc_bool_t b_absolute; /* position control, relative vs. absolute */
......@@ -87,6 +87,10 @@ struct filter_sys_t
#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 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, " \
......@@ -124,6 +128,7 @@ vlc_module_begin();
OPACITY_TEXT, OPACITY_LONGTEXT, VLC_FALSE );
add_integer( "marq-color", -1, NULL, COLOR_TEXT, COLOR_LONGTEXT, VLC_TRUE );
change_integer_list( pi_color_values, ppsz_color_descriptions, 0 );
add_integer( "marq-size", -1, NULL, SIZE_TEXT, SIZE_LONGTEXT, VLC_FALSE );
set_description( _("Marquee display sub filter") );
add_shortcut( "marq" );
......@@ -137,7 +142,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 ) );
......@@ -162,6 +166,7 @@ static int CreateFilter( vlc_object_t *p_this )
var_Create( p_input->p_libvlc, "marq-opacity", VLC_VAR_INTEGER|VLC_VAR_DOINHERIT );
p_sys->i_font_opacity = var_CreateGetInteger( p_input->p_libvlc , "marq-opacity" );
p_sys->i_font_color = var_CreateGetInteger( p_input->p_libvlc , "marq-color" );
p_sys->i_font_size = var_CreateGetInteger( p_input->p_libvlc , "marq-size" );
var_AddCallback( p_input->p_libvlc, "marq-x", MarqueeCallback, p_sys );
var_AddCallback( p_input->p_libvlc, "marq-y", MarqueeCallback, p_sys );
......@@ -170,6 +175,7 @@ static int CreateFilter( vlc_object_t *p_this )
var_AddCallback( p_input->p_libvlc, "marq-position", MarqueeCallback, p_sys );
var_AddCallback( p_input->p_libvlc, "marq-color", MarqueeCallback, p_sys );
var_AddCallback( p_input->p_libvlc, "marq-opacity", MarqueeCallback, p_sys );
var_AddCallback( p_input->p_libvlc, "marq-size", MarqueeCallback, p_sys );
vlc_object_release( p_input );
......@@ -206,6 +212,8 @@ static void DestroyFilter( vlc_object_t *p_this )
var_Destroy( p_input->p_libvlc , "marq-position" );
var_Destroy( p_input->p_libvlc , "marq-color");
var_Destroy( p_input->p_libvlc , "marq-opacity");
var_Destroy( p_input->p_libvlc , "marq-size");
vlc_object_release( p_input );
}
......@@ -263,7 +271,8 @@ static subpicture_t *Filter( filter_t *p_filter, mtime_t date )
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->p_region->i_font_opacity = p_sys->i_font_opacity;
p_spu->p_region->i_font_size = p_sys->i_font_size;
p_spu->i_flags = p_sys->i_pos;
......@@ -301,6 +310,10 @@ static int MarqueeCallback( vlc_object_t *p_this, char const *psz_var,
{
p_sys->i_font_opacity = newval.i_int;
}
else if ( !strncmp( psz_var, "marq-size", 6 ) )
{
p_sys->i_font_size = newval.i_int;
}
else if ( !strncmp( psz_var, "marq-timeout", 12 ) )
{
p_sys->i_timeout = newval.i_int;
......
......@@ -61,7 +61,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 */
int i_font_color, i_font_opacity, i_font_size; /* font control */
vlc_bool_t b_absolute; /* position control, relative vs. absolute */
time_t last_time;
......@@ -76,6 +76,10 @@ struct filter_sys_t
#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 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, " \
......@@ -110,6 +114,7 @@ vlc_module_begin();
OPACITY_TEXT, OPACITY_LONGTEXT, VLC_FALSE );
add_integer( "time-color", -1, 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();
......@@ -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 );
}
......@@ -257,7 +266,8 @@ static subpicture_t *Filter( filter_t *p_filter, mtime_t date )
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->p_region->i_font_opacity = p_sys->i_font_opacity;
p_spu->p_region->i_font_size = p_sys->i_font_size;
p_spu->i_flags = p_sys->i_pos;
......@@ -285,14 +295,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 */
{
......
......@@ -259,6 +259,7 @@ subpicture_region_t *__spu_CreateRegion( vlc_object_t *p_this,
p_region->psz_text = 0;
p_region->i_font_color = -1; /* default to using freetype-color -opacity */
p_region->i_font_opacity = -1;
p_region->i_font_size = -1; /* and the freetype fontsize */
if( p_fmt->i_chroma == VLC_FOURCC('Y','U','V','P') )
p_fmt->p_palette = p_region->fmt.p_palette =
......@@ -567,7 +568,8 @@ void spu_RenderSubpictures( spu_t *p_spu, video_format_t *p_fmt,
/* the actual call to RenderText in freetype.c: */
p_subpic_tmp = p_spu->p_text->pf_render_string(
p_spu->p_text, p_new_block,
p_region->i_font_color, p_region->i_font_opacity);
p_region->i_font_color, p_region->i_font_opacity,
p_region->i_font_size);
if( p_subpic_tmp )
{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment