Commit 6d12ddeb authored by Jean-Paul Saman's avatar Jean-Paul Saman Committed by Jean-Paul Saman

Add option --vbi-text to output Teletext subtitles as plain text.

parent 197c9bdc
......@@ -78,6 +78,10 @@ static subpicture_t *Decode( decoder_t *, block_t ** );
"(0=center, 1=left, 2=right, 4=top, 8=bottom, you can " \
"also use combinations of these values, eg. 6 = top-right).")
#define TELX_TEXT N_("Teletext text subtitles")
#define TELX_LONGTEXT N_( "Output teletext subtitles as text " \
"instead of as RGBA" )
static int pi_pos_values[] = { 0, 1, 2, 4, 8, 5, 6, 9, 10 };
static char *ppsz_pos_descriptions[] =
{ N_("Center"), N_("Left"), N_("Right"), N_("Top"), N_("Bottom"),
......@@ -97,6 +101,8 @@ vlc_module_begin();
OPAQUE_TEXT, OPAQUE_LONGTEXT, VLC_FALSE );
add_integer( "vbi-position", 4, NULL, POS_TEXT, POS_LONGTEXT, VLC_FALSE );
change_integer_list( pi_pos_values, ppsz_pos_descriptions, 0 );
add_bool( "vbi-text", VLC_FALSE, NULL,
TELX_TEXT, TELX_LONGTEXT, VLC_FALSE );
vlc_module_end();
/****************************************************************************
......@@ -112,6 +118,9 @@ struct decoder_sys_t
vlc_bool_t b_update;
vlc_bool_t b_opaque;
/* Subtitles as text */
vlc_bool_t b_text;
/* Positioning of Teletext images */
int i_align;
};
......@@ -176,8 +185,15 @@ static int Open( vlc_object_t *p_this )
p_sys->i_align = var_CreateGetInteger( p_dec, "vbi-position" );
var_AddCallback( p_dec, "vbi-position", Position, p_sys );
es_format_Init( &p_dec->fmt_out, SPU_ES, VLC_FOURCC( 's','p','u',' ' ) );
p_dec->fmt_out.video.i_chroma = VLC_FOURCC('R','G','B','A');
p_sys->b_text = var_CreateGetBool( p_dec, "vbi-text" );
// var_AddCallback( p_dec, "vbi-text", Text, p_sys );
// es_format_Init( &p_dec->fmt_out, SPU_ES, VLC_FOURCC( 's','p','u',' ' ) );
// if( p_sys->b_text )
// p_dec->fmt_out.video.i_chroma = VLC_FOURCC('T','E','X','T');
// else
// p_dec->fmt_out.video.i_chroma = VLC_FOURCC('R','G','B','A');
return VLC_SUCCESS;
}
......@@ -266,12 +282,12 @@ static subpicture_t *Decode( decoder_t *p_dec, block_t **pp_block )
/* Create a new subpicture region */
memset( &fmt, 0, sizeof(video_format_t) );
fmt.i_chroma = VLC_FOURCC('R','G','B','A');
fmt.i_chroma = p_sys->b_text ? VLC_FOURCC('T','E','X','T') : VLC_FOURCC('R','G','B','A');
fmt.i_aspect = VOUT_ASPECT_FACTOR;
fmt.i_sar_num = fmt.i_sar_den = 1;
fmt.i_width = fmt.i_visible_width = p_page.columns * 12;
fmt.i_height = fmt.i_visible_height = p_page.rows * 10;
fmt.i_bits_per_pixel = 32;
fmt.i_bits_per_pixel = p_sys->b_text ? 0 : 32;
fmt.i_x_offset = fmt.i_y_offset = 0;
p_spu->p_region = p_spu->pf_create_region( VLC_OBJECT(p_dec), &fmt );
......@@ -295,60 +311,70 @@ static subpicture_t *Decode( decoder_t *p_dec, block_t **pp_block )
p_spu->i_original_picture_width = p_page.columns * 12;
p_spu->i_original_picture_height = p_page.rows * 10;
vbi_draw_vt_page( &p_page, VBI_PIXFMT_RGBA32_LE,
p_spu->p_region->picture.p->p_pixels, 1, 1 );
p_spu->p_region->picture.p->i_lines = p_page.rows * 10;
p_spu->p_region->picture.p->i_pitch = p_page.columns * 12 * 4;
if( p_sys->b_text )
{
/* Separate subs and print as ASCII */
unsigned int i_total, i_textsize = 7000;
char p_text[7000];
// "ISO-8859-1"
i_total = vbi_print_page_region( &p_page, p_text, i_textsize,
"UTF-8", 0, 0, 0, 0,
p_page.columns, p_page.rows );
p_text[i_total] = '\0';
if( i_total == 0 ) goto error;
p_spu->p_region->psz_text = strdup( &p_text[0] );
msg_Dbg( p_dec, "page %x-%x\n%s", p_page.pgno, p_page.subno, p_text );
}
else
{
vbi_draw_vt_page( &p_page, VBI_PIXFMT_RGBA32_LE,
p_spu->p_region->picture.p->p_pixels, 1, 1 );
p_spu->p_region->picture.p->i_lines = p_page.rows * 10;
p_spu->p_region->picture.p->i_pitch = p_page.columns * 12 * 4;
}
/* Kludge since zvbi doesn't provide an option to specify opacity. */
p_begin = (uint32_t *)p_spu->p_region->picture.p->p_pixels;
p_end = (uint32_t *)p_spu->p_region->picture.p->p_pixels+(fmt.i_width * fmt.i_height);
for( ; p_begin < p_end; p_begin++ )
if( p_sys->b_opaque && !p_sys->b_text )
{
opacity = p_page.text[ y / 10 * p_page.columns + x / 12 ].opacity;
switch( opacity )
p_begin = (uint32_t *)p_spu->p_region->picture.p->p_pixels;
p_end = (uint32_t *)p_spu->p_region->picture.p->p_pixels+(fmt.i_width * fmt.i_height);
for( ; p_begin < p_end; p_begin++ )
{
/* Show video instead of this character */
case VBI_TRANSPARENT_SPACE:
*p_begin = 0;
break;
/* To make the boxed text "closed captioning" transparent
* change VLC_TRUE to VLC_FALSE.
*/
case VBI_OPAQUE:
if( p_sys->b_opaque )
break;
/* Full text transparency. only foreground color is show */
case VBI_TRANSPARENT_FULL:
/* Transparency for boxed text */
case VBI_SEMI_TRANSPARENT:
if( (*p_begin & 0xffffff00) == 0xff )
opacity = p_page.text[ y / 10 * p_page.columns + x / 12 ].opacity;
switch( opacity )
{
/* Show video instead of this character */
case VBI_TRANSPARENT_SPACE:
*p_begin = 0;
break;
default:
break;
}
x++;
if( x >= fmt.i_width )
{
x = 0;
y++;
break;
/* To make the boxed text "closed captioning" transparent
* change VLC_TRUE to VLC_FALSE.
*/
case VBI_OPAQUE:
if( p_sys->b_opaque )
break;
/* Full text transparency. only foreground color is show */
case VBI_TRANSPARENT_FULL:
/* Transparency for boxed text */
case VBI_SEMI_TRANSPARENT:
if( (*p_begin & 0xffffff00) == 0xff )
*p_begin = 0;
break;
default:
break;
}
x++;
if( x >= fmt.i_width )
{
x = 0;
y++;
}
}
}
/* end of kludge */
#if 0
/* Separate subs and print as ASCII */
unsigned int i_total, i_textsize = 7000;
char p_text[7000];
i_total = vbi_print_page_region( &p_page, p_text, i_textsize,
"ISO-8859-1", 0, 0, 0, 0,
p_page.columns, p_page.rows );
p_text[i_total] = '\0';
msg_Dbg( p_dec, "page %x-%x\n%s", p_page.pgno, p_page.subno, p_text );
#endif
vbi_unref_page( &p_page );
block_Release( p_block );
......
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