#include "subsdec.h"
#include <vlc_plugin.h>
+#include <assert.h>
/*****************************************************************************
* Local prototypes
{
decoder_t *p_dec = (decoder_t*)p_this;
decoder_sys_t *p_sys;
- vlc_value_t val;
if( p_dec->fmt_in.i_codec != VLC_FOURCC('u','s','f',' ') )
- {
return VLC_EGENERIC;
- }
-
- p_dec->pf_decode_sub = DecodeBlock;
/* Allocate the memory needed to store the decoder's structure */
- if( ( p_dec->p_sys = p_sys =
- (decoder_sys_t *)calloc(1, sizeof(decoder_sys_t)) ) == NULL )
- {
+ if( ( p_dec->p_sys = p_sys = calloc(1, sizeof(decoder_sys_t)) ) == NULL )
return VLC_ENOMEM;
- }
+
+ p_dec->pf_decode_sub = DecodeBlock;
/* Unused fields of p_sys - not needed for USF decoding */
p_sys->b_ass = false;
/* init of p_sys */
p_sys->i_align = 0;
- p_sys->i_original_height = -1;
- p_sys->i_original_width = -1;
+ p_sys->i_original_height = 0;
+ p_sys->i_original_width = 0;
TAB_INIT( p_sys->i_ssa_styles, p_sys->pp_ssa_styles );
TAB_INIT( p_sys->i_images, p_sys->pp_images );
/* USF subtitles are mandated to be UTF-8, so don't need vlc_iconv */
- var_Create( p_dec, "subsdec-align", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
- var_Get( p_dec, "subsdec-align", &val );
- p_sys->i_align = val.i_int;
+ p_sys->i_align = var_CreateGetInteger( p_dec, "subsdec-align" );
ParseImageAttachments( p_dec );
****************************************************************************/
static subpicture_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
{
- subpicture_t *p_spu = NULL;
+ subpicture_t *p_spu;
+ block_t *p_block;
- if( !pp_block || *pp_block == NULL ) return NULL;
+ if( !pp_block || *pp_block == NULL )
+ return NULL;
+
+ p_block = *pp_block;
+ if( p_block->i_rate != 0 )
+ p_block->i_length = p_block->i_length * p_block->i_rate / INPUT_RATE_DEFAULT;
- p_spu = ParseText( p_dec, *pp_block );
+ p_spu = ParseText( p_dec, p_block );
- block_Release( *pp_block );
+ block_Release( p_block );
*pp_block = NULL;
return p_spu;
continue;
if( p_sys->pp_images[i]->p_pic )
- p_sys->pp_images[i]->p_pic->pf_release( p_sys->pp_images[i]->p_pic );
+ picture_Release( p_sys->pp_images[i]->p_pic );
free( p_sys->pp_images[i]->psz_filename );
free( p_sys->pp_images[i] );
/* USF Subtitles are mandated to be UTF-8 -- make sure it is */
if (EnsureUTF8( psz_subtitle ) == NULL)
{
- msg_Err( p_dec, _("USF subtitles must be in UTF-8 format.\n"
- "This stream contains USF subtitles which aren't.") );
+ msg_Err( p_dec, "USF subtitles must be in UTF-8 format.\n"
+ "This stream contains USF subtitles which aren't." );
}
/* Create the subpicture unit */
return NULL;
}
- p_spu->b_pausable = true;
-
/* Decode USF strings */
p_spu->p_region = ParseUSFString( p_dec, psz_subtitle, p_spu );
fmt.i_aspect = 0;
fmt.i_width = fmt.i_height = 0;
fmt.i_x_offset = fmt.i_y_offset = 0;
- p_text_region = p_spu->pf_create_region( VLC_OBJECT(p_dec), &fmt );
+ p_text_region = subpicture_region_New( &fmt );
if( p_text_region != NULL )
{
p_text_region->psz_html = strndup( psz_subtitle, i_len );
if( ! p_text_region->psz_html )
{
- p_spu->pf_destroy_region( VLC_OBJECT(p_dec), p_text_region );
+ subpicture_region_Delete( p_text_region );
return NULL;
}
fmt_out.i_aspect = VOUT_ASPECT_FACTOR;
fmt_out.i_sar_num = fmt_out.i_sar_den = 1;
fmt_out.i_width =
- fmt_out.i_visible_width = p_pic->p[Y_PLANE].i_visible_pitch;
+ fmt_out.i_visible_width = p_pic->format.i_visible_width;
fmt_out.i_height =
- fmt_out.i_visible_height = p_pic->p[Y_PLANE].i_visible_lines;
+ fmt_out.i_visible_height = p_pic->format.i_visible_height;
- p_region = p_spu->pf_create_region( VLC_OBJECT(p_dec), &fmt_out );
+ p_region = subpicture_region_New( &fmt_out );
if( !p_region )
{
msg_Err( p_dec, "cannot allocate SPU region" );
return NULL;
}
- vout_CopyPicture( p_dec, &p_region->picture, p_pic );
+ assert( p_pic->format.i_chroma == VLC_FOURCC('Y','U','V','A') );
+ /* FIXME the copy is probably not needed anymore */
+ picture_CopyPixels( p_region->p_picture, p_pic );
/* This isn't the best way to do this - if you really want transparency, then
* you're much better off using an image type that supports it like PNG. The
*/
if( i_transparent_color > 0 )
{
- uint8_t i_r = ( i_transparent_color >> 16 ) & 0xff;
- uint8_t i_g = ( i_transparent_color >> 8 ) & 0xff;
- uint8_t i_b = ( i_transparent_color ) & 0xff;
- uint8_t i_y = ( ( ( 66 * i_r + 129 * i_g + 25 * i_b + 128 ) >> 8 ) + 16 );
- uint8_t i_u = ( ( -38 * i_r - 74 * i_g + 112 * i_b + 128 ) >> 8 ) + 128 ;
- uint8_t i_v = ( ( 112 * i_r - 94 * i_g - 18 * i_b + 128 ) >> 8 ) + 128 ;
-
- if( ( p_region->picture.Y_PITCH == p_region->picture.U_PITCH ) &&
- ( p_region->picture.Y_PITCH == p_region->picture.V_PITCH ) &&
- ( p_region->picture.Y_PITCH == p_region->picture.A_PITCH ) )
+ int i_r = ( i_transparent_color >> 16 ) & 0xff;
+ int i_g = ( i_transparent_color >> 8 ) & 0xff;
+ int i_b = ( i_transparent_color ) & 0xff;
+
+ /* FIXME it cannot work as the yuv conversion code will probably NOT match
+ * this one */
+ int i_y = ( ( ( 66 * i_r + 129 * i_g + 25 * i_b + 128 ) >> 8 ) + 16 );
+ int i_u = ( ( -38 * i_r - 74 * i_g + 112 * i_b + 128 ) >> 8 ) + 128 ;
+ int i_v = ( ( 112 * i_r - 94 * i_g - 18 * i_b + 128 ) >> 8 ) + 128 ;
+
+ assert( p_region->fmt.i_chroma == VLC_FOURCC('Y','U','V','A') );
+ for( unsigned int y = 0; y < p_region->fmt.i_height; y++ )
{
- int i_lines = p_region->picture.p[ Y_PLANE ].i_lines;
- if( i_lines > p_region->picture.p[ U_PLANE ].i_lines )
- i_lines = p_region->picture.p[ U_PLANE ].i_lines;
- if( i_lines > p_region->picture.p[ V_PLANE ].i_lines )
- i_lines = p_region->picture.p[ V_PLANE ].i_lines;
- if( i_lines > p_region->picture.p[ A_PLANE ].i_lines )
- i_lines = p_region->picture.p[ A_PLANE ].i_lines;
-
- int i;
-
- for( i = 0; i < p_region->picture.A_PITCH * i_lines; i++ )
+ for( unsigned int x = 0; x < p_region->fmt.i_width; x++ )
{
- if(( p_region->picture.Y_PIXELS[ i ] == i_y ) &&
- ( p_region->picture.U_PIXELS[ i ] == i_u ) &&
- ( p_region->picture.V_PIXELS[ i ] == i_v ) )
- {
- p_region->picture.A_PIXELS[ i ] = 1;
- }
+ if( p_region->p_picture->Y_PIXELS[y*p_region->p_picture->Y_PITCH + x] != i_y ||
+ p_region->p_picture->U_PIXELS[y*p_region->p_picture->U_PITCH + x] != i_u ||
+ p_region->p_picture->V_PIXELS[y*p_region->p_picture->V_PITCH + x] != i_v )
+ continue;
+ p_region->p_picture->A_PIXELS[y*p_region->p_picture->A_PITCH + x] = 0;
+
}
}
}