X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fmisc%2Fsvg.c;h=afaa6f7ea182dac4876c3b66b1c1695f0d87b571;hb=75813fcf3472e7dab10984bcf9ae001eb7b77d9a;hp=8605bb9e872964b7eb795ed6cf37bbab5543d684;hpb=81c5ac29fa2e80426c1b1dfcc941a1aabe8bc808;p=vlc diff --git a/modules/misc/svg.c b/modules/misc/svg.c index 8605bb9e87..afaa6f7ea1 100644 --- a/modules/misc/svg.c +++ b/modules/misc/svg.c @@ -24,9 +24,13 @@ /***************************************************************************** * Preamble *****************************************************************************/ -#include -#include +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include +#include #include #include #include @@ -67,14 +71,14 @@ static char *svg_GetTemplate( vlc_object_t *p_this ); #define TEMPLATE_LONGTEXT N_( "Location of a file holding a SVG template "\ "for automatic string conversion" ) -vlc_module_begin(); - set_category( CAT_INPUT); - set_category( SUBCAT_INPUT_SCODEC ); - set_capability( "text renderer", 99 ); - add_shortcut( "svg" ); - add_string( "svg-template-file", "", NULL, TEMPLATE_TEXT, TEMPLATE_LONGTEXT, VLC_TRUE ); - set_callbacks( Create, Destroy ); -vlc_module_end(); +vlc_module_begin () + set_category( CAT_INPUT) + set_category( SUBCAT_INPUT_SCODEC ) + set_capability( "text renderer", 99 ) + add_shortcut( "svg" ) + add_string( "svg-template-file", "", NULL, TEMPLATE_TEXT, TEMPLATE_LONGTEXT, true ) + set_callbacks( Create, Destroy ) +vlc_module_end () /** Describes a SVG string to be displayed on the video @@ -127,16 +131,12 @@ static int Create( vlc_object_t *p_this ) /* Allocate structure */ p_sys = malloc( sizeof( filter_sys_t ) ); if( !p_sys ) - { - msg_Err( p_filter, "out of memory" ); return VLC_ENOMEM; - } /* Initialize psz_template */ p_sys->psz_template = svg_GetTemplate( p_this ); if( !p_sys->psz_template ) { - msg_Err( p_filter, "out of memory" ); free( p_sys ); return VLC_ENOMEM; } @@ -180,10 +180,8 @@ static char *svg_GetTemplate( vlc_object_t *p_this ) else { struct stat s; - int i_ret; - i_ret = utf8_stat( psz_filename, &s ); - if( i_ret ) + if( fstat( fileno( file ), &s ) ) { /* Problem accessing file information. Should not happen as we could open it. */ @@ -200,18 +198,23 @@ static char *svg_GetTemplate( vlc_object_t *p_this ) msg_Dbg( p_this, "reading %ld bytes from template %s", (unsigned long)s.st_size, psz_filename ); - psz_template = malloc( ( s.st_size + 42 ) * sizeof( char ) ); + psz_template = malloc( s.st_size + 42 ); if( !psz_template ) { - msg_Err( p_filter, "out of memory" ); + fclose( file ); + free( psz_filename ); return NULL; } memset( psz_template, 0, s.st_size + 1 ); - fread( psz_template, s.st_size, 1, file ); - fclose( file ); + if(! fread( psz_template, s.st_size, 1, file ) ) + { + msg_Dbg( p_this, "No data read from template." ); + } } + fclose( file ); } } + free( psz_filename ); if( !psz_template ) { /* Either there was no file, or there was an error. @@ -254,7 +257,6 @@ static int Render( filter_t *p_filter, subpicture_region_t *p_region, int channels_in; int alpha; picture_t *p_pic; - subpicture_region_t *p_region_tmp; if ( p_filter->p_sys->i_width != i_width || p_filter->p_sys->i_height != i_height ) @@ -281,31 +283,27 @@ static int Render( filter_t *p_filter, subpicture_region_t *p_region, fmt.i_width = fmt.i_visible_width = i_width; fmt.i_height = fmt.i_visible_height = i_height; fmt.i_x_offset = fmt.i_y_offset = 0; - p_region_tmp = spu_CreateRegion( p_filter, &fmt ); - if( !p_region_tmp ) - { - msg_Err( p_filter, "cannot allocate SPU region" ); + + p_region->p_picture = picture_New( fmt.i_chroma, fmt.i_width, fmt.i_height, fmt.i_aspect ); + if( !p_region->p_picture ) return VLC_EGENERIC; - } - p_region->fmt = p_region_tmp->fmt; - p_region->picture = p_region_tmp->picture; - free( p_region_tmp ); + p_region->fmt = fmt; 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; + p_y = p_region->p_picture->Y_PIXELS; + p_u = p_region->p_picture->U_PIXELS; + p_v = p_region->p_picture->V_PIXELS; + p_a = p_region->p_picture->A_PIXELS; - i_pitch = p_region->picture.Y_PITCH; - i_u_pitch = p_region->picture.U_PITCH; + i_pitch = p_region->p_picture->Y_PITCH; + i_u_pitch = p_region->p_picture->U_PITCH; /* Initialize the region pixels (only the alpha will be changed later) */ memset( p_y, 0x00, i_pitch * p_region->fmt.i_height ); memset( p_u, 0x80, i_u_pitch * p_region->fmt.i_height ); memset( p_v, 0x80, i_u_pitch * p_region->fmt.i_height ); - p_pic = &p_region->picture; + p_pic = p_region->p_picture; /* Copy the data */ @@ -414,8 +412,8 @@ static void svg_RenderPicture( filter_t *p_filter, rsvg_handle_set_size_callback( p_handle, svg_SizeCallback, p_filter, NULL ); if( ! rsvg_handle_write( p_handle, - ( guchar* )p_svg->psz_text, strlen( p_svg->psz_text ), - &error ) ) + ( guchar* )p_svg->psz_text, strlen( p_svg->psz_text ), + &error ) ) { msg_Err( p_filter, "error while rendering SVG: %s\n", error->message ); g_object_unref( G_OBJECT( p_handle ) ); @@ -449,10 +447,7 @@ static int RenderText( filter_t *p_filter, subpicture_region_t *p_region_out, p_svg = ( svg_rendition_t * )malloc( sizeof( svg_rendition_t ) ); if( !p_svg ) - { - msg_Err( p_filter, "out of memory" ); return VLC_ENOMEM; - } p_region_out->i_x = p_region_in->i_x; p_region_out->i_y = p_region_in->i_y; @@ -465,7 +460,6 @@ static int RenderText( filter_t *p_filter, subpicture_region_t *p_region_out, p_svg->psz_text = strdup( psz_string ); if( !p_svg->psz_text ) { - msg_Err( p_filter, "out of memory" ); free( p_svg ); return VLC_ENOMEM; } @@ -477,10 +471,9 @@ static int RenderText( filter_t *p_filter, subpicture_region_t *p_region_out, int length; char* psz_template = p_sys->psz_template; length = strlen( psz_string ) + strlen( psz_template ) + 42; - p_svg->psz_text = malloc( ( length + 1 ) * sizeof( char ) ); + p_svg->psz_text = malloc( length + 1 ); if( !p_svg->psz_text ) { - msg_Err( p_filter, "out of memory" ); free( p_svg ); return VLC_ENOMEM; } @@ -504,8 +497,7 @@ static int RenderText( filter_t *p_filter, subpicture_region_t *p_region_out, static void FreeString( svg_rendition_t *p_svg ) { - if( p_svg->psz_text ) - free( p_svg->psz_text ); + free( p_svg->psz_text ); /* p_svg->p_rendition is a GdkPixbuf, and its allocation is managed through ref. counting */ if( p_svg->p_rendition )