Commit c5cc4e52 authored by Derk-Jan Hartman's avatar Derk-Jan Hartman

* Introduced a new text_style_t

* basic support for SSA formatted subs. (disable with --no-subsdec-formatted option)
* changes to freetype renderer to support the font color, size and alpha options of text_style_t (other options are possible, just not implemented yet. Full text_style_t support requires a more advanced renderer though. )
* changes to modules to support text_style_t instead of the old sub options.
* Some changes to subsdec to only iconv to UTF-8 if source is !UTF-8.

refs #82

not supported are style runs (styles on substrings).

parent 42bc34f9
......@@ -39,7 +39,7 @@
* if used inside a transcoding command. For example:
*
* vlc dvdsimple:///dev/dvd --extraintf rc
* --sout='#transcode{osd}:std{access=udp,mux=ts,dst=dest_ipaddr}'
* --sout='#transcode{osd}:std{access=udp,mux=ts,url=dest_ipaddr}'
* --osdmenu-file=share/osdmenu/dvd.cfg
*
* Each OSD menu element, called "action", defines a hotkey action. Each action
......@@ -117,18 +117,47 @@ extern "C" {
#define OSD_MUTE_ICON 4
/**
* Text style information.
* This struct is currently ignored
* Text style
*
* A text style is used to specify the formatting of text.
* A font renderer can use the supplied information to render the text specified.
*/
struct text_style_t
{
int i_size;
uint32_t i_color;
vlc_bool_t b_italic;
vlc_bool_t b_bold;
vlc_bool_t b_underline;
char * psz_fontname; /**< The name of the font */
int i_font_size; /**< The font size in pixels */
int i_font_color; /**< The color of the text 0xRRGGBB (native endianness) */
int i_font_alpha; /**< The transparency of the text.
0x00 is fully opaque, 0xFF fully transparent */
int i_style_flags; /**< Formatting style flags */
int i_outline_color; /**< The color of the outline 0xRRGGBB */
int i_outline_alpha; /**< The transparency of the outline.
0x00 is fully opaque, 0xFF fully transparent */
int i_shadow_color; /**< The color of the shadow 0xRRGGBB */
int i_shadow_alpha; /**< The transparency of the shadow.
0x00 is fully opaque, 0xFF fully transparent */
int i_background_color; /**< The color of the background 0xRRGGBB */
int i_background_alpha; /**< The transparency of the background.
0x00 is fully opaque, 0xFF fully transparent */
int i_outline_width; /**< The width of the outline in pixels */
int i_shadow_width; /**< The width of the shadow in pixels */
int i_spacing; /**< The spaceing between glyphs in pixels */
int i_text_align; /**< An alignment hint for the text */
};
static const text_style_t default_text_style = { 22, 0xffffff, VLC_FALSE, VLC_FALSE, VLC_FALSE };
/* Style flags for \ref text_style_t */
#define STYLE_BOLD 1
#define STYLE_ITALIC 2
#define STYLE_OUTLINE 4
#define STYLE_SHADOW 8
#define STYLE_BACKGROUND 16
#define STYLE_UNDERLINE 32
#define STYLE_STRIKEOUT 64
static const text_style_t default_text_style = { NULL, 22, 0xffffff, 0xff, STYLE_OUTLINE,
0x000000, 0xff, 0x000000, 0xff, 0xffffff, 0x80, 1, 0, -1, 0 };
/**
* OSD menu button states
......
......@@ -209,10 +209,7 @@ struct subpicture_region_t
int i_y; /**< position of region */
char *psz_text; /**< text string comprising this region */
int i_text_color; /**< text color (RGB native endianess) */
int i_text_alpha; /**< text transparency */
int i_text_size; /**< text size */
int i_text_align; /**< horizontal alignment hint for */
text_style_t *p_style; /* a description of the text style formatting */
subpicture_region_t *p_next; /**< next region in the list */
subpicture_region_t *p_cache; /**< modified version of this region */
......
......@@ -821,15 +821,11 @@ static int DisplayAnchor( intf_thread_t *p_intf,
{
text_style_t *p_style = NULL;
text_style_t blue_with_underline = default_text_style;
blue_with_underline.b_underline = VLC_TRUE;
blue_with_underline.i_color = 0x22ff22;
if( psz_anchor_url )
{
/* Should display subtitle underlined and in blue, but it looks
* like VLC doesn't implement any text styles yet. D'oh! */
p_style = &blue_with_underline;
// p_style = &blue_with_underline;
}
......@@ -837,7 +833,7 @@ static int DisplayAnchor( intf_thread_t *p_intf,
* coordinates. Need to look at the subpicture display system to
* work out why. */
if ( vout_ShowTextAbsolute( p_vout, DEFAULT_CHAN,
psz_anchor_description, p_style, OSD_ALIGN_BOTTOM,
psz_anchor_description, NULL, OSD_ALIGN_BOTTOM,
i_margin_h, i_margin_v, i_now, 0 ) == VLC_SUCCESS )
{
/* Displayed successfully */
......
This diff is collapsed.
......@@ -398,13 +398,13 @@ static int Render( filter_t *p_filter, subpicture_region_t *p_region,
i_glyph_tmax = __MAX( i_glyph_tmax, p_glyph->top );
}
if( p_line->i_width < i_width )
if( p_region->p_style && p_line->i_width < i_width )
{
if( p_region->i_text_align == SUBPICTURE_ALIGN_RIGHT )
if( p_region->p_style->i_text_align == SUBPICTURE_ALIGN_RIGHT )
{
i_align_offset = i_width - p_line->i_width;
}
else if( p_region->i_text_align != SUBPICTURE_ALIGN_LEFT )
else if( p_region->p_style->i_text_align != SUBPICTURE_ALIGN_LEFT )
{
i_align_offset = ( i_width - p_line->i_width ) / 2;
}
......@@ -475,13 +475,13 @@ static void DrawBlack( line_desc_t *p_line, int i_width, subpicture_region_t *p_
i_glyph_tmax = __MAX( i_glyph_tmax, p_glyph->top );
}
if( p_line->i_width < i_width )
if( p_region->p_style && p_line->i_width < i_width )
{
if( p_region->i_text_align == SUBPICTURE_ALIGN_RIGHT )
if( p_region->p_style->i_text_align == SUBPICTURE_ALIGN_RIGHT )
{
i_align_offset = i_width - p_line->i_width;
}
else if( p_region->i_text_align != SUBPICTURE_ALIGN_LEFT )
else if( p_region->p_style->i_text_align != SUBPICTURE_ALIGN_LEFT )
{
i_align_offset = ( i_width - p_line->i_width ) / 2;
}
......@@ -625,13 +625,13 @@ static int RenderYUVA( filter_t *p_filter, subpicture_region_t *p_region,
i_glyph_tmax = __MAX( i_glyph_tmax, p_glyph->top );
}
if( p_line->i_width < i_width )
if( p_region->p_style && p_line->i_width < i_width )
{
if( p_region->i_text_align == SUBPICTURE_ALIGN_RIGHT )
if( p_region->p_style->i_text_align == SUBPICTURE_ALIGN_RIGHT )
{
i_align_offset = i_width - p_line->i_width;
}
else if( p_region->i_text_align != SUBPICTURE_ALIGN_LEFT )
else if( p_region->p_style->i_text_align != SUBPICTURE_ALIGN_LEFT )
{
i_align_offset = ( i_width - p_line->i_width ) / 2;
}
......@@ -668,7 +668,7 @@ static int RenderYUVA( filter_t *p_filter, subpicture_region_t *p_region,
}
/* Apply the alpha setting */
for( i = 0; i < fmt.i_height * i_pitch; i++ )
for( i = 0; i < (int)fmt.i_height * i_pitch; i++ )
p_dst_a[i] = p_dst_a[i] * (255 - i_alpha) / 255;
return VLC_SUCCESS;
......@@ -702,13 +702,21 @@ static int RenderText( filter_t *p_filter, subpicture_region_t *p_region_out,
psz_string = p_region_in->psz_text;
if( !psz_string || !*psz_string ) return VLC_EGENERIC;
i_font_color = __MAX( __MIN( p_region_in->i_text_color, 0xFFFFFF ), 0 );
if( i_font_color == 0xFFFFFF ) i_font_color = p_sys->i_font_color;
if( p_region_in->p_style )
{
i_font_color = __MAX( __MIN( p_region_in->p_style->i_font_color, 0xFFFFFF ), 0 );
i_font_alpha = __MAX( __MIN( p_region_in->p_style->i_font_alpha, 255 ), 0 );
i_font_size = __MAX( __MIN( p_region_in->p_style->i_font_size, 255 ), 0 );
}
else
{
i_font_color = p_sys->i_font_color;
i_font_alpha = 255 - p_sys->i_font_opacity;
i_font_size = p_sys->i_default_font_size;
}
i_font_alpha = __MAX( __MIN( p_region_in->i_text_alpha, 255 ), 0 );
if( i_font_color == 0xFFFFFF ) i_font_color = p_sys->i_font_color;
if( !i_font_alpha ) i_font_alpha = 255 - p_sys->i_font_opacity;
i_font_size = __MAX( __MIN( p_region_in->i_text_size, 255 ), 0 );
SetFontSize( p_filter, i_font_size );
i_red = ( i_font_color & 0x00FF0000 ) >> 16;
......@@ -752,7 +760,7 @@ static int RenderText( filter_t *p_filter, subpicture_region_t *p_region_out,
if( i_in_bytes )
{
msg_Warn( p_filter, "failed to convert string to unicode (%s), "
"bytes left %d", strerror(errno), i_in_bytes );
"bytes left %d", strerror(errno), (int)i_in_bytes );
goto error;
}
*(uint32_t*)p_out_buffer = 0;
......@@ -799,7 +807,7 @@ static int RenderText( filter_t *p_filter, subpicture_region_t *p_region_out,
/* Calculate relative glyph positions and a bounding box for the
* entire string */
if( !(p_line = NewLine( psz_string )) )
if( !(p_line = NewLine( (byte_t *)psz_string )) )
{
msg_Err( p_filter, "out of memory" );
goto error;
......@@ -823,7 +831,7 @@ static int RenderText( filter_t *p_filter, subpicture_region_t *p_region_out,
if( i_char == '\n' )
{
psz_line_start = psz_unicode;
if( !(p_next = NewLine( psz_string )) )
if( !(p_next = NewLine( (byte_t *)psz_string )) )
{
msg_Err( p_filter, "out of memory" );
goto error;
......@@ -890,7 +898,7 @@ static int RenderText( filter_t *p_filter, subpicture_region_t *p_region_out,
{
p_line->pp_glyphs[ i ] = NULL;
FreeLine( p_line );
p_line = NewLine( psz_string );
p_line = NewLine( (byte_t *)psz_string );
if( p_prev ) p_prev->p_next = p_line;
else p_lines = p_line;
......@@ -989,7 +997,7 @@ static line_desc_t *NewLine( byte_t *psz_string )
/* We don't use CountUtf8Characters() here because we are not acutally
* sure the string is utf8. Better be safe than sorry. */
i_count = strlen( psz_string );
i_count = strlen( (char *)psz_string );
p_line->pp_glyphs = malloc( sizeof(FT_BitmapGlyph) * ( i_count + 1 ) );
if( p_line->pp_glyphs == NULL )
......
......@@ -66,7 +66,7 @@ struct filter_sys_t
char *psz_marquee; /* marquee string */
int i_font_color, i_font_opacity, i_font_size; /* font control */
text_style_t *p_style; /* font control */
time_t last_time;
......@@ -165,15 +165,17 @@ static int CreateFilter( vlc_object_t *p_this )
return VLC_ENOOBJ;
}
p_sys->p_style = malloc( sizeof( text_style_t ) );
memcpy( p_sys->p_style, &default_text_style, sizeof( text_style_t ) );
p_sys->i_xoff = var_CreateGetInteger( p_input->p_libvlc , "marq-x" );
p_sys->i_yoff = var_CreateGetInteger( p_input->p_libvlc , "marq-y" );
p_sys->i_timeout = var_CreateGetInteger( p_input->p_libvlc , "marq-timeout" );
p_sys->i_pos = var_CreateGetInteger( p_input->p_libvlc , "marq-position" );
p_sys->psz_marquee = var_CreateGetString( p_input->p_libvlc, "marq-marquee" );
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" );
p_sys->p_style->i_font_alpha = 255 - var_CreateGetInteger( p_input->p_libvlc , "marq-opacity" );
p_sys->p_style->i_font_color = var_CreateGetInteger( p_input->p_libvlc , "marq-color" );
p_sys->p_style->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 );
......@@ -203,6 +205,7 @@ static void DestroyFilter( vlc_object_t *p_this )
filter_sys_t *p_sys = p_filter->p_sys;
vlc_object_t *p_input;
if( p_sys->p_style ) free( p_sys->p_style );
if( p_sys->psz_marquee ) free( p_sys->psz_marquee );
free( p_sys );
......@@ -293,10 +296,7 @@ static subpicture_t *Filter( filter_t *p_filter, mtime_t date )
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;
p_spu->p_region->p_style = p_sys->p_style;
p_sys->b_need_update = VLC_FALSE;
return p_spu;
......@@ -326,15 +326,15 @@ static int MarqueeCallback( vlc_object_t *p_this, char const *psz_var,
}
else if ( !strncmp( psz_var, "marq-color", 8 ) ) /* "marq-col" */
{
p_sys->i_font_color = newval.i_int;
p_sys->p_style->i_font_color = newval.i_int;
}
else if ( !strncmp( psz_var, "marq-opacity", 8 ) ) /* "marq-opa" */
{
p_sys->i_font_opacity = newval.i_int;
p_sys->p_style->i_font_alpha = 255 - newval.i_int;
}
else if ( !strncmp( psz_var, "marq-size", 6 ) )
{
p_sys->i_font_size = newval.i_int;
p_sys->p_style->i_font_size = newval.i_int;
}
else if ( !strncmp( psz_var, "marq-timeout", 12 ) )
{
......
......@@ -91,7 +91,7 @@ struct filter_sys_t
char *psz_marquee; /* marquee string */
int i_font_color, i_font_opacity, i_font_size; /* font control */
text_style_t *p_style; /* font control */
mtime_t last_date;
......@@ -212,13 +212,15 @@ static int CreateFilter( vlc_object_t *p_this )
p_sys->i_ttl = __MAX( 0, var_CreateGetInteger( p_filter, "rss-ttl" ) );
p_sys->psz_marquee = (char *)malloc( p_sys->i_length );
p_sys->p_style = malloc( sizeof( text_style_t ));
memcpy( p_sys->p_style, &default_text_style, sizeof( text_style_t ));
p_sys->i_xoff = var_CreateGetInteger( p_filter, "rss-x" );
p_sys->i_yoff = var_CreateGetInteger( p_filter, "rss-y" );
p_sys->i_pos = var_CreateGetInteger( p_filter, "rss-position" );
var_Create( p_filter, "rss-opacity", VLC_VAR_INTEGER|VLC_VAR_DOINHERIT );
p_sys->i_font_opacity = var_CreateGetInteger( p_filter, "rss-opacity" );
p_sys->i_font_color = var_CreateGetInteger( p_filter, "rss-color" );
p_sys->i_font_size = var_CreateGetInteger( p_filter, "rss-size" );
p_sys->p_style->i_font_alpha = 255 - var_CreateGetInteger( p_filter, "rss-opacity" );
p_sys->p_style->i_font_color = var_CreateGetInteger( p_filter, "rss-color" );
p_sys->p_style->i_font_size = var_CreateGetInteger( p_filter, "rss-size" );
if( FetchRSS( p_filter ) )
{
......@@ -258,6 +260,7 @@ static void DestroyFilter( vlc_object_t *p_this )
vlc_mutex_lock( &p_sys->lock );
if( p_sys->p_style ) free( p_sys->p_style );
if( p_sys->psz_marquee ) free( p_sys->psz_marquee );
free( p_sys->psz_urls );
FreeRSS( p_filter );
......@@ -383,9 +386,7 @@ static subpicture_t *Filter( filter_t *p_filter, mtime_t date )
p_spu->b_absolute = VLC_TRUE;
}
p_spu->i_height = 1;
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;
p_spu->p_region->p_style = p_sys->p_style;
vlc_mutex_unlock( &p_sys->lock );
return p_spu;
......
......@@ -60,10 +60,10 @@ static char *ppsz_color_descriptions[] = { N_("Default"), N_("Black"),
*****************************************************************************/
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, i_font_size; /* font control */
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) */
text_style_t *p_style; /* font control */
time_t last_time;
};
......@@ -145,14 +145,17 @@ static int CreateFilter( vlc_object_t *p_this )
return VLC_ENOOBJ;
}
p_sys->p_style = malloc( sizeof( text_style_t ) );
memcpy( p_sys->p_style, &default_text_style, sizeof( text_style_t ) );
p_sys->i_xoff = var_CreateGetInteger( p_input->p_libvlc , "time-x" );
p_sys->i_yoff = var_CreateGetInteger( p_input->p_libvlc , "time-y" );
p_sys->psz_format = var_CreateGetString( p_input->p_libvlc, "time-format" );
p_sys->i_pos = var_CreateGetInteger( p_input->p_libvlc , "time-position" );
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" );
p_sys->p_style->i_font_alpha = 255 - var_CreateGetInteger( p_input->p_libvlc , "time-opacity" );
p_sys->p_style->i_font_color = var_CreateGetInteger( p_input->p_libvlc , "time-color" );
p_sys->p_style->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 );
......@@ -179,6 +182,7 @@ static void DestroyFilter( vlc_object_t *p_this )
filter_sys_t *p_sys = p_filter->p_sys;
vlc_object_t *p_input;
if( p_sys->p_style ) free( p_sys->p_style );
if( p_sys->psz_format ) free( p_sys->psz_format );
free( p_sys );
/* Delete the time variables */
......@@ -268,14 +272,12 @@ static subpicture_t *Filter( filter_t *p_filter, mtime_t date )
}
else
{ /* set to an absolute xy, referenced to upper left corner */
p_spu->i_flags = OSD_ALIGN_LEFT | OSD_ALIGN_TOP;
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;
p_spu->p_region->p_style = p_sys->p_style;
return p_spu;
}
......@@ -303,15 +305,15 @@ static int TimeCallback( vlc_object_t *p_this, char const *psz_var,
}
else if ( !strncmp( psz_var, "time-color", 8 ) ) /* "time-c" */
{
p_sys->i_font_color = newval.i_int;
p_sys->p_style->i_font_color = newval.i_int;
}
else if ( !strncmp( psz_var, "time-opacity", 8 ) ) /* "time-o" */
{
p_sys->i_font_opacity = newval.i_int;
p_sys->p_style->i_font_alpha = 255 - newval.i_int;
}
else if ( !strncmp( psz_var, "time-size", 6 ) )
{
p_sys->i_font_size = newval.i_int;
p_sys->p_style->i_font_size = newval.i_int;
}
else if ( !strncmp( psz_var, "time-position", 8 ) )
/* willing to accept a match against time-pos */
......
......@@ -256,7 +256,7 @@ subpicture_region_t *__spu_CreateRegion( vlc_object_t *p_this,
p_region->p_cache = 0;
p_region->fmt = *p_fmt;
p_region->psz_text = 0;
p_region->i_text_color = 0xFFFFFF;
p_region->p_style = NULL;
if( p_fmt->i_chroma == VLC_FOURCC('Y','U','V','P') )
p_fmt->p_palette = p_region->fmt.p_palette =
......@@ -299,7 +299,7 @@ subpicture_region_t *__spu_MakeRegion( vlc_object_t *p_this,
p_region->p_cache = 0;
p_region->fmt = *p_fmt;
p_region->psz_text = 0;
p_region->i_text_color = 0xFFFFFF;
p_region->p_style = NULL;
if( p_fmt->i_chroma == VLC_FOURCC('Y','U','V','P') )
p_fmt->p_palette = p_region->fmt.p_palette =
......@@ -324,7 +324,6 @@ void __spu_DestroyRegion( vlc_object_t *p_this, subpicture_region_t *p_region )
if( p_region->picture.pf_release )
p_region->picture.pf_release( &p_region->picture );
if( p_region->fmt.p_palette ) free( p_region->fmt.p_palette );
if( p_region->psz_text ) free( p_region->psz_text );
if( p_region->p_cache ) __spu_DestroyRegion( p_this, p_region->p_cache );
free( p_region );
}
......@@ -591,8 +590,9 @@ void spu_RenderSubpictures( spu_t *p_spu, video_format_t *p_fmt,
{
if( p_spu->p_text && p_spu->p_text->p_module &&
p_spu->p_text->pf_render_text )
{
p_region->i_text_align = p_subpic->i_flags & 0x3;
{/*
if( p_region->p_style )
p_region->p_style->i_text_align = p_subpic->i_flags & 0x3; */
p_spu->p_text->pf_render_text( p_spu->p_text,
p_region, p_region );
}
......
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