+ char *psz_modulename = NULL;
+
+ 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 =
+ p_spu->p_text->fmt_out.video.i_visible_width =
+ p_fmt->i_width;
+ p_spu->p_text->fmt_out.video.i_height =
+ p_spu->p_text->fmt_out.video.i_visible_height =
+ p_fmt->i_height;
+
+ p_spu->p_text->pf_sub_buffer_new = spu_new_buffer;
+ p_spu->p_text->pf_sub_buffer_del = spu_del_buffer;
+
+ psz_modulename = var_CreateGetString( p_spu, "text-renderer" );
+ if( psz_modulename && *psz_modulename )
+ {
+ p_spu->p_text->p_module =
+ module_Need( p_spu->p_text, "text renderer",
+ psz_modulename, VLC_TRUE );
+ }
+ if( !p_spu->p_text->p_module )
+ {
+ p_spu->p_text->p_module =
+ module_Need( p_spu->p_text, "text renderer", 0, 0 );
+ }
+ if( psz_modulename ) free( psz_modulename );
+ }
+ if( p_spu->p_text )
+ {
+ if( (p_subpic->i_original_picture_height > 0) &&
+ (p_subpic->i_original_picture_width > 0) )
+ {
+ p_spu->p_text->fmt_out.video.i_width =
+ p_spu->p_text->fmt_out.video.i_visible_width =
+ p_subpic->i_original_picture_width;
+ p_spu->p_text->fmt_out.video.i_height =
+ p_spu->p_text->fmt_out.video.i_visible_height =
+ p_subpic->i_original_picture_height;
+ }
+ else
+ {
+ p_spu->p_text->fmt_out.video.i_width =
+ p_spu->p_text->fmt_out.video.i_visible_width =
+ p_fmt->i_width;
+ p_spu->p_text->fmt_out.video.i_height =
+ p_spu->p_text->fmt_out.video.i_visible_height =
+ p_fmt->i_height;
+ }
+ }
+
+ i_scale_width = i_scale_width_orig;
+ i_scale_height = i_scale_height_orig;
+
+ if( (p_subpic->i_original_picture_height > 0) &&
+ (p_subpic->i_original_picture_width > 0) )
+ {
+ i_scale_width = i_scale_width * p_fmt->i_width /
+ p_subpic->i_original_picture_width;
+ i_scale_height = i_scale_height * p_fmt->i_height /
+ p_subpic->i_original_picture_height;
+ }
+ else if( p_subpic->i_original_picture_height > 0 )
+ {
+ i_scale_height = i_scale_height * p_fmt->i_height /
+ p_subpic->i_original_picture_height;
+ i_scale_width = i_scale_height * i_scale_height / p_fmt->i_height;
+ }
+
+ /* Set default subpicture aspect ratio */
+ if( p_region && p_region->fmt.i_aspect &&
+ (!p_region->fmt.i_sar_num || !p_region->fmt.i_sar_den) )
+ {
+ p_region->fmt.i_sar_den = p_region->fmt.i_aspect;
+ p_region->fmt.i_sar_num = VOUT_ASPECT_FACTOR;
+ }
+ if( p_region &&
+ (!p_region->fmt.i_sar_num || !p_region->fmt.i_sar_den) )
+ {
+ p_region->fmt.i_sar_den = p_fmt->i_sar_den;
+ p_region->fmt.i_sar_num = p_fmt->i_sar_num;
+ }
+
+ /* Take care of the aspect ratio */
+ if( p_region && p_region->fmt.i_sar_num * p_fmt->i_sar_den !=
+ p_region->fmt.i_sar_den * p_fmt->i_sar_num )
+ {
+ i_scale_width = i_scale_width *
+ (int64_t)p_region->fmt.i_sar_num * p_fmt->i_sar_den /
+ p_region->fmt.i_sar_den / p_fmt->i_sar_num;
+ i_subpic_x = p_subpic->i_x * i_scale_width / 1000;
+ }
+
+ /* Load the scaling module */
+ if( !p_spu->p_scale &&
+ ((i_scale_width > 0) || (i_scale_height > 0)) &&
+ ((i_scale_width != 1000) || (i_scale_height != 1000)) )
+ {
+ p_spu->p_scale = vlc_object_create( p_spu, VLC_OBJECT_FILTER );
+ vlc_object_attach( p_spu->p_scale, p_spu );
+ p_spu->p_scale->fmt_out.video.i_chroma =
+ p_spu->p_scale->fmt_in.video.i_chroma =
+ VLC_FOURCC('Y','U','V','P');
+ /* XXX: We'll also be using it for YUVA and RGBA blending ... */
+ p_spu->p_scale->fmt_in.video.i_width =
+ p_spu->p_scale->fmt_in.video.i_height = 32;
+ p_spu->p_scale->fmt_out.video.i_width =
+ p_spu->p_scale->fmt_out.video.i_height = 16;
+
+ p_spu->p_scale->pf_vout_buffer_new = spu_new_video_buffer;
+ p_spu->p_scale->pf_vout_buffer_del = spu_del_video_buffer;
+ p_spu->p_scale->p_module =
+ module_Need( p_spu->p_scale, "video filter2", 0, 0 );
+ }
+
+ while( p_region && p_spu->p_blend && p_spu->p_blend->pf_video_blend )
+ {
+ video_format_t orig_fmt = p_region->fmt;
+ vlc_bool_t b_rerender_text = VLC_FALSE;
+ int i_fade_alpha = 255;
+ int i_x_offset = p_region->i_x + i_subpic_x;