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

📄 crop.c

📁 video linux conference
💻 C
📖 第 1 页 / 共 2 页
字号:
    ADD_PARENT_CALLBACKS( SendEventsToChild );    return VLC_SUCCESS;}/***************************************************************************** * End: terminate Crop video thread output method *****************************************************************************/static void End( vout_thread_t *p_vout ){    int i_index;    /* Free the fake output buffers we allocated */    for( i_index = I_OUTPUTPICTURES ; i_index ; )    {        i_index--;        free( PP_OUTPUTPICTURE[ i_index ]->p_data_orig );    }}/***************************************************************************** * Destroy: destroy Crop video thread output method ***************************************************************************** * Terminate an output method created by CropCreateOutputMethod *****************************************************************************/static void Destroy( vlc_object_t *p_this ){    vout_thread_t *p_vout = (vout_thread_t *)p_this;    if( p_vout->p_sys->p_vout )    {        DEL_CALLBACKS( p_vout->p_sys->p_vout, SendEvents );        vlc_object_detach( p_vout->p_sys->p_vout );        vout_Destroy( p_vout->p_sys->p_vout );    }    DEL_PARENT_CALLBACKS( SendEventsToChild );    free( p_vout->p_sys );}/***************************************************************************** * Manage: handle Crop events ***************************************************************************** * This function should be called regularly by video output thread. It manages * console events. It returns a non null value on error. *****************************************************************************/static int Manage( vout_thread_t *p_vout ){    video_format_t fmt = {0};    if( !p_vout->p_sys->b_changed )    {        return VLC_SUCCESS;    }    vout_Destroy( p_vout->p_sys->p_vout );    fmt.i_width = fmt.i_visible_width = p_vout->p_sys->i_width;    fmt.i_height = fmt.i_visible_height = p_vout->p_sys->i_height;    fmt.i_x_offset = fmt.i_y_offset = 0;    fmt.i_chroma = p_vout->render.i_chroma;    fmt.i_aspect = p_vout->p_sys->i_aspect;    fmt.i_sar_num = p_vout->p_sys->i_aspect * fmt.i_height / fmt.i_width;    fmt.i_sar_den = VOUT_ASPECT_FACTOR;    p_vout->p_sys->p_vout = vout_Create( p_vout, &fmt );    if( p_vout->p_sys->p_vout == NULL )    {        msg_Err( p_vout, "failed to create vout" );        return VLC_EGENERIC;    }    p_vout->p_sys->b_changed = VLC_FALSE;    p_vout->p_sys->i_lastchange = 0;    return VLC_SUCCESS;}/***************************************************************************** * Render: display previously rendered output ***************************************************************************** * This function sends the currently rendered image to Crop image, waits * until it is displayed and switches the two rendering buffers, preparing next * frame. *****************************************************************************/static void Render( vout_thread_t *p_vout, picture_t *p_pic ){    picture_t *p_outpic = NULL;    int i_plane;    if( p_vout->p_sys->b_changed )    {        return;    }    while( ( p_outpic =                 vout_CreatePicture( p_vout->p_sys->p_vout, 0, 0, 0 )           ) == NULL )    {        if( p_vout->b_die || p_vout->b_error )        {            vout_DestroyPicture( p_vout->p_sys->p_vout, p_outpic );            return;        }        msleep( VOUT_OUTMEM_SLEEP );    }    vout_DatePicture( p_vout->p_sys->p_vout, p_outpic, p_pic->date );    vout_LinkPicture( p_vout->p_sys->p_vout, p_outpic );    for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ )    {        uint8_t *p_in, *p_out, *p_out_end;        int i_in_pitch = p_pic->p[i_plane].i_pitch;        const int i_out_pitch = p_outpic->p[i_plane].i_pitch;        const int i_copy_pitch = p_outpic->p[i_plane].i_visible_pitch;        p_in = p_pic->p[i_plane].p_pixels                /* Skip the right amount of lines */                + i_in_pitch * ( p_pic->p[i_plane].i_visible_lines *                                 p_vout->p_sys->i_y / p_vout->output.i_height )                /* Skip the right amount of columns */                + i_in_pitch * p_vout->p_sys->i_x / p_vout->output.i_width;        p_out = p_outpic->p[i_plane].p_pixels;        p_out_end = p_out + i_out_pitch * p_outpic->p[i_plane].i_visible_lines;        while( p_out < p_out_end )        {            p_vout->p_vlc->pf_memcpy( p_out, p_in, i_copy_pitch );            p_in += i_in_pitch;            p_out += i_out_pitch;        }    }    vout_UnlinkPicture( p_vout->p_sys->p_vout, p_outpic );    vout_DisplayPicture( p_vout->p_sys->p_vout, p_outpic );    /* The source image may still be in the cache ... parse it! */    if( p_vout->p_sys->b_autocrop )    {        UpdateStats( p_vout, p_pic );    }}static void UpdateStats( vout_thread_t *p_vout, picture_t *p_pic ){    uint8_t *p_in = p_pic->p[0].p_pixels;    int i_pitch = p_pic->p[0].i_pitch;    int i_visible_pitch = p_pic->p[0].i_visible_pitch;    int i_lines = p_pic->p[0].i_visible_lines;    int i_firstwhite = -1, i_lastwhite = -1, i;    /* Determine where black borders are */    switch( p_vout->output.i_chroma )    {    case VLC_FOURCC('I','4','2','0'):        /* XXX: Do not laugh ! I know this is very naive. But it's just a         *      proof of concept code snippet... */        for( i = i_lines ; i-- ; )        {            const int i_col = i * i_pitch / i_lines;            if( p_in[i_col/2] > 40                 && p_in[i_visible_pitch/2] > 40                 && p_in[i_visible_pitch/2 + i_col/2] > 40 )            {                if( i_lastwhite == -1 )                {                    i_lastwhite = i;                }                i_firstwhite = i;            }            p_in += i_pitch;        }        break;    default:        break;    }    /* Decide whether it's worth changing the size */    if( i_lastwhite == -1 )    {        p_vout->p_sys->i_lastchange = 0;        return;    }    if( (unsigned int)(i_lastwhite - i_firstwhite)                                           < p_vout->p_sys->i_height / 2 )    {        p_vout->p_sys->i_lastchange = 0;        return;    }    if( (unsigned int)(i_lastwhite - i_firstwhite)                                          < p_vout->p_sys->i_height + 16         && (unsigned int)(i_lastwhite - i_firstwhite + 16)                                                > p_vout->p_sys->i_height )    {        p_vout->p_sys->i_lastchange = 0;        return;    }    /* We need at least 25 images to make up our mind */    p_vout->p_sys->i_lastchange++;    if( p_vout->p_sys->i_lastchange < 25 )    {        return;    }    /* Tune a few values */    if( i_firstwhite & 1 )    {        i_firstwhite--;    }    if( !(i_lastwhite & 1) )    {        i_lastwhite++;    }    /* Change size */    p_vout->p_sys->i_y = i_firstwhite;    p_vout->p_sys->i_height = i_lastwhite - i_firstwhite + 1;    p_vout->p_sys->i_aspect = p_vout->output.i_aspect                            * p_vout->output.i_height / p_vout->p_sys->i_height                            * p_vout->p_sys->i_width / p_vout->output.i_width;    p_vout->p_sys->b_changed = VLC_TRUE;}/***************************************************************************** * SendEvents: forward mouse and keyboard events to the parent p_vout *****************************************************************************/static int SendEvents( vlc_object_t *p_this, char const *psz_var,                       vlc_value_t oldval, vlc_value_t newval, void *_p_vout ){    vout_thread_t *p_vout = (vout_thread_t *)_p_vout;    vlc_value_t sentval = newval;    /* Translate the mouse coordinates */    if( !strcmp( psz_var, "mouse-x" ) )    {        sentval.i_int += p_vout->p_sys->i_x;    }    else if( !strcmp( psz_var, "mouse-y" ) )    {        sentval.i_int += p_vout->p_sys->i_y;    }    var_Set( p_vout, psz_var, sentval );    return VLC_SUCCESS;}/***************************************************************************** * SendEventsToChild: forward events to the child/children vout *****************************************************************************/static int SendEventsToChild( vlc_object_t *p_this, char const *psz_var,                       vlc_value_t oldval, vlc_value_t newval, void *p_data ){    vout_thread_t *p_vout = (vout_thread_t *)p_this;    var_Set( p_vout->p_sys->p_vout, psz_var, newval );    return VLC_SUCCESS;}

⌨️ 快捷键说明

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