⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dvbsub.c

📁 VLC Player Source Code
💻 C
📖 第 1 页 / 共 5 页
字号:
            {                if( bs_read( s, 1 ) == 0x00 )     //Switch2                {                    switch( bs_read( s, 2 ) )     //Switch3                    {                    case 0x00:                        b_stop = true;                        break;                    case 0x01:                        i_count = 2;                        break;                    case 0x02:                        i_count =  12 + bs_read( s, 4 );                        i_color = bs_read( s, 2 );                        break;                    case 0x03:                        i_count =  29 + bs_read( s, 8 );                        i_color = bs_read( s, 2 );                        break;                    default:                        break;                    }                }                else                {                    /* 1 pixel color 0 */                    i_count = 1;                }            }        }        if( !i_count ) continue;        /* Sanity check */        if( ( i_count + *pi_off ) > i_width ) break;        if( i_count == 1 ) p[*pi_off] = i_color;        else memset( ( p + *pi_off ), i_color, i_count );        (*pi_off) += i_count;    }    bs_align( s );}static void dvbsub_pdata4bpp( bs_t *s, uint8_t *p, int i_width, int *pi_off ){    bool b_stop = false;    while( !b_stop && !bs_eof( s ) )    {        int i_count = 0, i_color = 0;        i_color = bs_read( s, 4 );        if( i_color != 0x00 )        {            /* Add 1 pixel */            i_count = 1;        }        else        {            if( bs_read( s, 1 ) == 0x00 )           // Switch1            {                if( bs_show( s, 3 ) != 0x00 )                {                    i_count = 2 + bs_read( s, 3 );                }                else                {                    bs_skip( s, 3 );                    b_stop = true;                }            }            else            {                if( bs_read( s, 1 ) == 0x00)        //Switch2                {                    i_count =  4 + bs_read( s, 2 );                    i_color = bs_read( s, 4 );                }                else                {                    switch ( bs_read( s, 2 ) )     //Switch3                    {                    case 0x0:                        i_count = 1;                        break;                    case 0x1:                        i_count = 2;                        break;                    case 0x2:                        i_count = 9 + bs_read( s, 4 );                        i_color = bs_read( s, 4 );                        break;                    case 0x3:                        i_count= 25 + bs_read( s, 8 );                        i_color = bs_read( s, 4 );                        break;                    }                }            }        }        if( !i_count ) continue;        /* Sanity check */        if( ( i_count + *pi_off ) > i_width ) break;        if( i_count == 1 ) p[*pi_off] = i_color;        else memset( ( p + *pi_off ), i_color, i_count );        (*pi_off) += i_count;    }    bs_align( s );}static void dvbsub_pdata8bpp( bs_t *s, uint8_t *p, int i_width, int *pi_off ){    bool b_stop = false;    while( !b_stop && !bs_eof( s ) )    {        int i_count = 0, i_color = 0;        i_color = bs_read( s, 8 );        if( i_color != 0x00 )        {            /* Add 1 pixel */            i_count = 1;        }        else        {            if( bs_read( s, 1 ) == 0x00 )           // Switch1            {                if( bs_show( s, 7 ) != 0x00 )                {                    i_count = bs_read( s, 7 );                }                else                {                    bs_skip( s, 7 );                    b_stop = true;                }            }            else            {                i_count = bs_read( s, 7 );                i_color = bs_read( s, 8 );            }        }        if( !i_count ) continue;        /* Sanity check */        if( ( i_count + *pi_off ) > i_width ) break;        if( i_count == 1 ) p[*pi_off] = i_color;        else memset( ( p + *pi_off ), i_color, i_count );        (*pi_off) += i_count;    }    bs_align( s );}static void free_all( decoder_t *p_dec ){    decoder_sys_t *p_sys = p_dec->p_sys;    dvbsub_region_t *p_reg, *p_reg_next;    dvbsub_clut_t *p_clut, *p_clut_next;    free( p_sys->p_display );    for( p_clut = p_sys->p_cluts; p_clut != NULL; p_clut = p_clut_next )    {        p_clut_next = p_clut->p_next;        free( p_clut );    }    p_sys->p_cluts = NULL;    for( p_reg = p_sys->p_regions; p_reg != NULL; p_reg = p_reg_next )    {        int i;        p_reg_next = p_reg->p_next;        for( i = 0; i < p_reg->i_object_defs; i++ )            free( p_reg->p_object_defs[i].psz_text );        if( p_reg->i_object_defs ) free( p_reg->p_object_defs );        free( p_reg->p_pixbuf );        free( p_reg );    }    p_sys->p_regions = NULL;    if( p_sys->p_page )    {        if( p_sys->p_page->i_region_defs )            free( p_sys->p_page->p_region_defs );        free( p_sys->p_page );    }    p_sys->p_page = NULL;}static subpicture_t *render( decoder_t *p_dec ){    decoder_sys_t *p_sys = p_dec->p_sys;    subpicture_t *p_spu;    subpicture_region_t **pp_spu_region;    int i, j, i_timeout = 0;    /* Allocate the subpicture internal data. */    p_spu = p_dec->pf_spu_buffer_new( p_dec );    if( !p_spu ) return NULL;    pp_spu_region = &p_spu->p_region;    /* Loop on region definitions */#ifdef DEBUG_DVBSUB    if( p_sys->p_page )        msg_Dbg( p_dec, "rendering %i regions", p_sys->p_page->i_region_defs );#endif    for( i = 0; p_sys->p_page && ( i < p_sys->p_page->i_region_defs ); i++ )    {        dvbsub_region_t     *p_region;        dvbsub_regiondef_t  *p_regiondef;        dvbsub_clut_t       *p_clut;        dvbsub_color_t      *p_color;        subpicture_region_t *p_spu_region;        uint8_t *p_src, *p_dst;        video_format_t fmt;        int i_pitch;        i_timeout = p_sys->p_page->i_timeout;        p_regiondef = &p_sys->p_page->p_region_defs[i];#ifdef DEBUG_DVBSUB        msg_Dbg( p_dec, "rendering region %i (%i,%i)", i,                 p_regiondef->i_x, p_regiondef->i_y );#endif        /* Find associated region */        for( p_region = p_sys->p_regions; p_region != NULL;             p_region = p_region->p_next )        {            if( p_regiondef->i_id == p_region->i_id ) break;        }        if( !p_region )        {            msg_Dbg( p_dec, "region %i not found", p_regiondef->i_id );            continue;        }        /* Find associated CLUT */        for( p_clut = p_sys->p_cluts; p_clut != NULL; p_clut = p_clut->p_next )        {            if( p_region->i_clut == p_clut->i_id ) break;        }        if( !p_clut )        {            msg_Dbg( p_dec, "clut %i not found", p_region->i_clut );            continue;        }        /* FIXME: don't create a subpicture region with VLC_FOURCC YUVP          * when it actually is a TEXT region */        /* Create new SPU region */        memset( &fmt, 0, sizeof(video_format_t) );        fmt.i_chroma = VLC_FOURCC('Y','U','V','P');        fmt.i_aspect = 0; /* 0 means use aspect ratio of background video */        fmt.i_width = fmt.i_visible_width = p_region->i_width;        fmt.i_height = fmt.i_visible_height = p_region->i_height;        fmt.i_x_offset = fmt.i_y_offset = 0;        p_spu_region = p_spu->pf_create_region( VLC_OBJECT(p_dec), &fmt );        if( !p_spu_region )        {            msg_Err( p_dec, "cannot allocate SPU region" );            continue;        }        p_spu_region->i_x = p_regiondef->i_x;        p_spu_region->i_y = p_regiondef->i_y;        p_spu_region->i_align = p_sys->i_spu_position;        *pp_spu_region = p_spu_region;        pp_spu_region = &p_spu_region->p_next;        /* Build palette */        fmt.p_palette->i_entries = ( p_region->i_depth == 1 ) ? 4 :            ( ( p_region->i_depth == 2 ) ? 16 : 256 );        p_color = ( p_region->i_depth == 1 ) ? p_clut->c_2b :            ( ( p_region->i_depth == 2 ) ? p_clut->c_4b : p_clut->c_8b );        for( j = 0; j < fmt.p_palette->i_entries; j++ )        {            fmt.p_palette->palette[j][0] = p_color[j].Y;            fmt.p_palette->palette[j][1] = p_color[j].Cb; /* U == Cb */            fmt.p_palette->palette[j][2] = p_color[j].Cr; /* V == Cr */            fmt.p_palette->palette[j][3] = 0xff - p_color[j].T;        }        p_src = p_region->p_pixbuf;        p_dst = p_spu_region->picture.Y_PIXELS;        i_pitch = p_spu_region->picture.Y_PITCH;        /* Copy pixel buffer */        for( j = 0; j < p_region->i_height; j++ )        {            memcpy( p_dst, p_src, p_region->i_width );            p_src += p_region->i_width;            p_dst += i_pitch;        }        /* Check subtitles encoded as strings of characters         * (since there are not rendered in the pixbuffer) */        for( j = 0; j < p_region->i_object_defs; j++ )        {            dvbsub_objectdef_t *p_object_def = &p_region->p_object_defs[j];            if( ( p_object_def->i_type != 1 ) || !p_object_def->psz_text )                continue;            /* Create new SPU region */            memset( &fmt, 0, sizeof(video_format_t) );            fmt.i_chroma = VLC_FOURCC('T','E','X','T');            fmt.i_aspect = VOUT_ASPECT_FACTOR;            fmt.i_width = fmt.i_visible_width = p_region->i_width;            fmt.i_height = fmt.i_visible_height = p_region->i_height;            fmt.i_x_offset = fmt.i_y_offset = 0;            p_spu_region = p_spu->pf_create_region( VLC_OBJECT(p_dec), &fmt );            if( !p_region )            {                msg_Err( p_dec, "cannot allocate SPU region" );                continue;            }            p_spu_region->psz_text = strdup( p_object_def->psz_text );            p_spu_region->i_x = p_regiondef->i_x + p_object_def->i_x;            p_spu_region->i_y = p_regiondef->i_y + p_object_def->i_y;            p_spu_region->i_align = p_sys->i_spu_position;            *pp_spu_region = p_spu_region;            pp_spu_region = &p_spu_region->p_next;        }    }    /* Set the pf_render callback */    p_spu->i_start = (mtime_t) p_sys->i_pts;    //p_spu->i_stop = (mtime_t) 0;    p_spu->b_ephemer = true;    p_spu->b_pausable = true;    //p_spu->b_fade = true;    //p_spu->i_stop = p_spu->i_start + (mtime_t) (i_timeout * 1000000);    /* Correct positioning of SPU */    p_spu->b_absolute = p_sys->b_absolute;    p_spu->i_x = p_sys->i_spu_x;    p_spu->i_y = p_sys->i_spu_y;    p_spu->i_original_picture_width = 720;    p_spu->i_original_picture_height = 576;    if( p_sys->p_display )    {        p_spu->i_original_picture_width = p_sys->p_display->i_width;        p_spu->i_original_picture_height = p_sys->p_display->i_height;        if( p_sys->p_display->b_windowed )        {            /* TODO: check that this actually works */            p_spu->i_original_picture_width = p_sys->p_display->i_max_x - p_sys->p_display->i_x;            p_spu->i_original_picture_height = p_sys->p_display->i_max_y - p_sys->p_display->i_y;            p_spu->i_x += p_sys->p_display->i_x;            p_spu->i_y += p_sys->p_display->i_y;        }    }    return p_spu;}/***************************************************************************** * encoder_sys_t : encoder descriptor *****************************************************************************/typedef struct encoder_region_t{    int i_width;    int i_height;} encoder_region_t;struct encoder_sys_t{    unsigned int i_page_ver;    unsigned int i_region_ver;    unsigned int i_clut_ver;    int i_regions;    encoder_region_t *p_regions;    mtime_t i_pts;    /* subpicture positioning */    int i_offset_x;    int i_offset_y;};static void encode_page_composition( encoder_t *, bs_t *, subpicture_t * );static void encode_clut( encoder_t *, bs_t *, subpicture_t * );static void encode_region_composition( encoder_t *, bs_t *, subpicture_t * );static void encode_object( encoder_t *, bs_t *, subpicture_t * );/***************************************************************************** * OpenEncoder: probe the encoder and return score *****************************************************************************/static int OpenEncoder( vlc_object_t *p_this )

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -