X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fcodec%2Fzvbi.c;h=62862ce5bebef26f67ad244396e5c77414a997eb;hb=9925a34ee91b6debfc2f9f137fe9c77e7e0d6241;hp=019d99c4108f0218cc3779a05d64531eaf06af96;hpb=b3c35a7650362606c05362d85ff4414ec512fdf4;p=vlc diff --git a/modules/codec/zvbi.c b/modules/codec/zvbi.c index 019d99c410..62862ce5be 100644 --- a/modules/codec/zvbi.c +++ b/modules/codec/zvbi.c @@ -7,20 +7,21 @@ * Authors: Derk-Jan Hartman * Jean-Paul Saman * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/ + /***************************************************************************** * * information on teletext format can be found here : @@ -103,18 +104,20 @@ vlc_module_end () //Guessing table for missing "default region triplet" static const int pi_default_triplet[] = { - 0, 0, // slo cze + 0, 0, 0, 0, // slo slk cze ces 8, // pol - 24,24,24,24, //ssc scr slv rum + 24,24,24,24,24, //scc scr srp hrv slv + 24,24, //rum ron 32,32,32,32,32, //est lit rus bul ukr 48,48, //gre ell 64, //ara 88, //heb 16 }; //default static const char *const ppsz_default_triplet[] = { - "slo", "cze", + "slo", "slk", "cze", "ces", "pol", - "ssc", "scr", "slv", "rum", + "scc", "scr", "srp", "hrv", "slv", + "rum", "ron", "est", "lit", "rus", "bul", "ukr", "gre", "ell", "ara", @@ -180,7 +183,9 @@ static subpicture_t *Subpicture( decoder_t *p_dec, video_format_t *p_fmt, static void EventHandler( vbi_event *ev, void *user_data ); static int OpaquePage( picture_t *p_src, const vbi_page p_page, - const video_format_t fmt, bool b_opaque ); + const video_format_t fmt, bool b_opaque, const int text_offset ); +static int get_first_visible_row( vbi_char *p_text, int rows, int columns); +static int get_last_visible_row( vbi_char *p_text, int rows, int columns); /* Properties callbacks */ static int RequestPage( vlc_object_t *p_this, char const *psz_cmd, @@ -403,10 +408,21 @@ static subpicture_t *Decode( decoder_t *p_dec, block_t **pp_block ) msg_Dbg( p_dec, "we now have page: %d ready for display", i_wanted_page ); #endif + + /* Ignore transparent rows at the beginning and end */ + int i_first_row = get_first_visible_row( p_page.text, p_page.rows, p_page.columns ); + if ( i_first_row < 0 ) + goto error; + int i_num_rows = get_last_visible_row( p_page.text, p_page.rows, p_page.columns ) - i_first_row + 1; +#ifdef ZVBI_DEBUG + msg_Dbg( p_dec, "After top and tail of page we have rows %i-%i of %i", + i_first_row + 1, i_first_row + i_num_rows, p_page.rows ); +#endif + /* If there is a page or sub to render, then we do that here */ /* Create the subpicture unit */ p_spu = Subpicture( p_dec, &fmt, p_sys->b_text, - p_page.columns, p_page.rows, + p_page.columns, i_num_rows, i_align, p_block->i_pts ); if( !p_spu ) goto error; @@ -418,13 +434,9 @@ static subpicture_t *Decode( decoder_t *p_dec, block_t **pp_block ) char p_text[i_textsize+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 ); + "UTF-8", 0, 0, 0, i_first_row, p_page.columns, i_num_rows ); p_text[i_total] = '\0'; - /* Strip off the pagenumber */ - if( i_total <= 40 ) - goto error; - p_spu->p_region->psz_text = strdup( &p_text[8] ); - + p_spu->p_region->psz_text = strdup( p_text ); #ifdef ZVBI_DEBUG msg_Info( p_dec, "page %x-%x(%d)\n%s", p_page.pgno, p_page.subno, i_total, p_text ); #endif @@ -435,14 +447,22 @@ static subpicture_t *Decode( decoder_t *p_dec, block_t **pp_block ) /* ZVBI is stupid enough to assume pitch == width */ p_pic->p->i_pitch = 4 * fmt.i_width; - vbi_draw_vt_page( &p_page, ZVBI_PIXFMT_RGBA32, - p_spu->p_region->p_picture->p->p_pixels, 1, 1 ); + + /* Maintain subtitle postion */ + p_spu->p_region->i_y = i_first_row*10; + p_spu->i_original_picture_width = p_page.columns*12; + p_spu->i_original_picture_height = p_page.rows*10; + + vbi_draw_vt_page_region( &p_page, ZVBI_PIXFMT_RGBA32, + p_spu->p_region->p_picture->p->p_pixels, -1, + 0, i_first_row, p_page.columns, i_num_rows, + 1, 1); vlc_mutex_lock( &p_sys->lock ); memcpy( p_sys->nav_link, &p_page.nav_link, sizeof( p_sys->nav_link )) ; vlc_mutex_unlock( &p_sys->lock ); - OpaquePage( p_pic, p_page, fmt, b_opaque ); + OpaquePage( p_pic, p_page, fmt, b_opaque, i_first_row * p_page.columns ); } exit: @@ -510,7 +530,7 @@ static subpicture_t *Subpicture( decoder_t *p_dec, video_format_t *p_fmt, p_spu->i_start = i_pts; p_spu->i_stop = 0; p_spu->b_ephemer = true; - p_spu->b_absolute = false; + p_spu->b_absolute = true; if( !b_text ) { @@ -564,8 +584,34 @@ static void EventHandler( vbi_event *ev, void *user_data ) msg_Dbg( p_dec, "Network ID changed" ); } +static int get_first_visible_row( vbi_char *p_text, int rows, int columns) +{ + for ( int i = 0; i < rows * columns; i++ ) + { + if ( p_text[i].opacity != VBI_TRANSPARENT_SPACE ) + { + return i / columns; + } + } + + return rows; +} + +static int get_last_visible_row( vbi_char *p_text, int rows, int columns) +{ + for ( int i = rows * columns - 1; i >= 0; i-- ) + { + if (p_text[i].opacity != VBI_TRANSPARENT_SPACE) + { + return ( i + columns - 1) / columns; + } + } + + return 0; +} + static int OpaquePage( picture_t *p_src, const vbi_page p_page, - const video_format_t fmt, bool b_opaque ) + const video_format_t fmt, bool b_opaque, const int text_offset ) { unsigned int x, y; @@ -576,8 +622,8 @@ static int OpaquePage( picture_t *p_src, const vbi_page p_page, { for( x = 0; x < fmt.i_width; x++ ) { - const vbi_opacity opacity = p_page.text[ y/10 * p_page.columns + x/12 ].opacity; - const int background = p_page.text[ y/10 * p_page.columns + x/12 ].background; + const vbi_opacity opacity = p_page.text[ text_offset + y/10 * p_page.columns + x/12 ].opacity; + const int background = p_page.text[ text_offset + y/10 * p_page.columns + x/12 ].background; uint32_t *p_pixel = (uint32_t*)&p_src->p->p_pixels[y * p_src->p->i_pitch + 4*x]; switch( opacity )