From d2a821e0b5f25e7f98168ca125176f476b3dec22 Mon Sep 17 00:00:00 2001 From: Sigmund Augdal Helberg Date: Sat, 5 Mar 2005 13:42:09 +0000 Subject: [PATCH] All: change of text-renderer api. Now pf_render_text takes a subpicture and a subpicture region, and returns a new region in the given subpicture. freetype.c: additional cleanup (coding style, cosmetics) --- include/vlc_filter.h | 2 +- modules/misc/freetype.c | 101 ++++++++++++++-------------- src/video_output/vout_subpictures.c | 37 +++------- 3 files changed, 59 insertions(+), 81 deletions(-) diff --git a/include/vlc_filter.h b/include/vlc_filter.h index 8e85b6a7bc..3e58c9ca3a 100644 --- a/include/vlc_filter.h +++ b/include/vlc_filter.h @@ -59,7 +59,7 @@ struct filter_t subpicture_t * ( *pf_sub_filter ) ( filter_t *, mtime_t ); /* pf_render_string maps to RenderText in freetype.c */ - subpicture_t * ( *pf_render_string ) ( filter_t *, block_t *, int, int, int ); + subpicture_region_t *( *pf_render_string ) ( filter_t *, subpicture_t *, subpicture_region_t * ); /* * Buffers allocation diff --git a/modules/misc/freetype.c b/modules/misc/freetype.c index 9b6b825300..ed9c2cc512 100644 --- a/modules/misc/freetype.c +++ b/modules/misc/freetype.c @@ -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, int ); +static subpicture_region_t *RenderText( filter_t *, subpicture_t *, subpicture_region_t* );//block_t *, int, int, int ); static line_desc_t *NewLine( byte_t * ); /***************************************************************************** @@ -153,7 +153,7 @@ struct line_desc_t line_desc_t *p_next; }; -static void Render ( filter_t *, subpicture_t *, subpicture_data_t *, uint8_t, +static subpicture_region_t *Render ( filter_t *, subpicture_t *, subpicture_data_t *, uint8_t, int, int, int ); static void FreeString( subpicture_data_t * ); static void FreeLine( line_desc_t * ); @@ -328,9 +328,10 @@ static void Destroy( vlc_object_t *p_this ) ***************************************************************************** * This function merges the previously rendered freetype glyphs into a picture *****************************************************************************/ -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) +static subpicture_region_t *Render( filter_t *p_filter, subpicture_t *p_spu, + subpicture_data_t *p_string, + uint8_t opacity, + int red, int green, int blue) { filter_sys_t *p_sys = p_filter->p_sys; line_desc_t *p_line; @@ -338,6 +339,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 */ + subpicture_region_t *p_region; /* calculate text color components: */ i_y = (uint8_t) ( ( 66 * red + 129 * green + 25 * blue + 128) >> 8) + 16; @@ -351,25 +353,25 @@ static void Render( filter_t *p_filter, subpicture_t *p_spu, fmt.i_width = fmt.i_visible_width = p_string->i_width + 2; fmt.i_height = fmt.i_visible_height = p_string->i_height + 2; fmt.i_x_offset = fmt.i_y_offset = 0; - p_spu->p_region = p_spu->pf_create_region( VLC_OBJECT(p_filter), &fmt ); - if( !p_spu->p_region ) + p_region = p_spu->pf_create_region( VLC_OBJECT(p_filter), &fmt ); + if( !p_region ) { msg_Err( p_filter, "cannot allocate SPU region" ); - return; + return NULL; } - p_spu->p_region->i_x = p_spu->p_region->i_y = 0; - p_y = p_spu->p_region->picture.Y_PIXELS; - p_u = p_spu->p_region->picture.U_PIXELS; - p_v = p_spu->p_region->picture.V_PIXELS; - p_a = p_spu->p_region->picture.A_PIXELS; - i_pitch = p_spu->p_region->picture.Y_PITCH; + p_region->i_x = p_region->i_y = 0; + p_y = p_region->picture.Y_PIXELS; + p_u = p_region->picture.U_PIXELS; + p_v = p_region->picture.V_PIXELS; + p_a = p_region->picture.A_PIXELS; + i_pitch = p_region->picture.Y_PITCH; /* Initialize the region pixels */ - memset( p_y, 0x00, i_pitch * p_spu->p_region->fmt.i_height ); - memset( p_u, 0x80, i_pitch * p_spu->p_region->fmt.i_height ); - memset( p_v, 0x80, i_pitch * p_spu->p_region->fmt.i_height ); - memset( p_a, 0x00, i_pitch * p_spu->p_region->fmt.i_height ); + memset( p_y, 0x00, i_pitch * p_region->fmt.i_height ); + memset( p_u, 0x80, i_pitch * p_region->fmt.i_height ); + memset( p_v, 0x80, i_pitch * p_region->fmt.i_height ); + memset( p_a, 0x00, i_pitch * p_region->fmt.i_height ); #define pi_gamma p_sys->pi_gamma @@ -433,6 +435,7 @@ static void Render( filter_t *p_filter, subpicture_t *p_spu, #undef pi_gamma } } + return p_region; } /** @@ -441,11 +444,11 @@ static void Render( filter_t *p_filter, subpicture_t *p_spu, * needed glyphs into memory. It is used as pf_add_string callback in * 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_size ) +static subpicture_region_t *RenderText( filter_t *p_filter, + subpicture_t *p_subpic, + subpicture_region_t *p_region ) { filter_sys_t *p_sys = p_filter->p_sys; - subpicture_t *p_subpic = 0; subpicture_data_t *p_string = 0; line_desc_t *p_line = 0, *p_next = 0, *p_prev = 0; int i, i_pen_y, i_pen_x, i_error, i_glyph_index, i_previous; @@ -453,6 +456,8 @@ static subpicture_t *RenderText( filter_t *p_filter, block_t *p_block, int i_string_length; char *psz_string; vlc_iconv_t iconv_handle = (vlc_iconv_t)(-1); + int i_font_color, i_font_opacity, i_font_size; + subpicture_region_t *p_res; FT_BBox line; FT_BBox glyph_size; @@ -460,9 +465,12 @@ static subpicture_t *RenderText( filter_t *p_filter, block_t *p_block, FT_Glyph tmp_glyph; /* Sanity check */ - if( !p_block ) return NULL; - psz_string = p_block->p_buffer; + if( !p_region ) return NULL; + psz_string = p_region->psz_text; if( !psz_string || !*psz_string ) goto error; + i_font_color = p_region->i_font_color; + i_font_opacity = p_region->i_font_opacity; + i_font_size = p_region->i_font_size; result.x = 0; result.y = 0; @@ -471,15 +479,6 @@ static subpicture_t *RenderText( filter_t *p_filter, block_t *p_block, line.yMin = 0; line.yMax = 0; - /* Create and initialize a subpicture */ - p_subpic = p_filter->pf_sub_buffer_new( p_filter ); - if( !p_subpic ) goto error; - - p_subpic->i_start = p_block->i_pts; - p_subpic->i_stop = p_block->i_pts + p_block->i_length; - p_subpic->b_ephemer = (p_block->i_length == 0); - p_subpic->b_absolute = VLC_FALSE; - /* Create and initialize private data for the subpicture */ p_string = malloc( sizeof(subpicture_data_t) ); if( !p_string ) @@ -511,18 +510,18 @@ static subpicture_t *RenderText( filter_t *p_filter, block_t *p_block, /* 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 ) + if ( i_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 ); + i_error = FT_Set_Pixel_Sizes( p_sys->p_face, 0, i_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 ); + 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 ); } } @@ -707,38 +706,36 @@ static subpicture_t *RenderText( filter_t *p_filter, block_t *p_block, #undef face #undef glyph /* check to see whether to use the default color/opacity, or another one: */ - if( font_color < 0 ) + if( i_font_color < 0 ) { - p_sys->i_blue = p_sys->i_font_color & 0x000000FF; - p_sys->i_green = (p_sys->i_font_color & 0x0000FF00)/256; - p_sys->i_red = (p_sys->i_font_color & 0x00FF0000)/(256*256); + p_sys->i_blue = p_sys->i_font_color & 0x000000FF; + p_sys->i_green = ( p_sys->i_font_color & 0x0000FF00 ) >> 8; + p_sys->i_red = ( p_sys->i_font_color & 0x00FF0000 ) >> 16; } else { - p_sys->i_blue = font_color & 0x000000FF; - p_sys->i_green = (font_color & 0x0000FF00)/256; - p_sys->i_red = (font_color & 0x00FF0000)/(256*256); - } - if( font_opacity < 0 ) + p_sys->i_blue = i_font_color & 0x000000FF; + p_sys->i_green = ( i_font_color & 0x0000FF00 ) >> 8; + p_sys->i_red = ( i_font_color & 0x00FF0000 ) >> 16; + } + if( i_font_opacity < 0 ) { p_sys->i_opacity = p_sys->i_font_opacity; } else { - p_sys->i_opacity = (uint8_t) ( font_opacity & 0x000000FF ); + p_sys->i_opacity = (uint8_t)( i_font_opacity & 0x000000FF ); } - Render( p_filter, p_subpic, p_string, p_sys->i_opacity, - p_sys->i_red, p_sys->i_green, p_sys->i_blue ); + p_res = Render( p_filter, p_subpic, p_string, p_sys->i_opacity, + p_sys->i_red, p_sys->i_green, p_sys->i_blue ); FreeString( p_string ); - block_Release( p_block ); if( psz_unicode_orig ) free( psz_unicode_orig ); - return p_subpic; + return p_res; error: FreeString( p_string ); if( p_subpic ) p_filter->pf_sub_buffer_del( p_filter, p_subpic ); - block_Release( p_block ); if( psz_unicode_orig ) free( psz_unicode_orig ); return NULL; } diff --git a/src/video_output/vout_subpictures.c b/src/video_output/vout_subpictures.c index 2ab33eb276..9cd81136d2 100644 --- a/src/video_output/vout_subpictures.c +++ b/src/video_output/vout_subpictures.c @@ -472,7 +472,7 @@ void spu_RenderSubpictures( spu_t *p_spu, video_format_t *p_fmt, /* Load the text rendering module */ if( !p_spu->p_text && p_region ) { - p_spu->p_text = vlc_object_create( p_spu, VLC_OBJECT_FILTER ); + p_spu->p_text = vlc_object_create( p_spu, VLC_OBJECT_FILTER ); vlc_object_attach( p_spu->p_text, p_spu ); p_spu->p_text->fmt_out.video.i_width = @@ -553,33 +553,15 @@ void spu_RenderSubpictures( spu_t *p_spu, video_format_t *p_fmt, { /* TODO: do it in a less hacky way * (modify text renderer API) */ - subpicture_t *p_subpic_tmp; - subpicture_region_t tmp_region; - block_t *p_new_block = - block_New( p_spu, strlen(p_region->psz_text) + 1 ); - if( p_new_block ) - { - memcpy( p_new_block->p_buffer, p_region->psz_text, - p_new_block->i_buffer ); - p_new_block->i_pts = p_new_block->i_dts = - p_subpic->i_start; - p_new_block->i_length = - p_subpic->i_start - p_subpic->i_stop; + subpicture_region_t *p_tmp_region; /* 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_size); - - if( p_subpic_tmp ) - { - tmp_region = *p_region; - *p_region = *p_subpic_tmp->p_region; - p_region->p_next = tmp_region.p_next; - *p_subpic_tmp->p_region = tmp_region; - p_spu->p_text->pf_sub_buffer_del( p_spu->p_text, - p_subpic_tmp ); - } + p_tmp_region = p_spu->p_text->pf_render_string( + p_spu->p_text, p_subpic, p_region ); + + if( p_tmp_region ) + { +// p_subpic->pf_destroy_region( p_spu, p_region ); + p_region = p_tmp_region; } } } @@ -613,7 +595,6 @@ void spu_RenderSubpictures( spu_t *p_spu, video_format_t *p_fmt, { picture_t *p_pic; - p_spu->p_scale->fmt_in.video = p_region->fmt; p_spu->p_scale->fmt_out.video = p_region->fmt; -- 2.39.2