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

📄 mosaic.c

📁 uclinux 下的vlc播放器源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
                uint8_t *p_a = p_converted->p[ A_PLANE ].p_pixels;                uint8_t *p_at = malloc( i_lines * i_pitch * sizeof( uint8_t ) );                uint8_t *p_u = p_converted->p[ U_PLANE ].p_pixels;                uint8_t *p_v = p_converted->p[ V_PLANE ].p_pixels;                uint8_t umin, umax, vmin, vmax;                umin = p_sys->i_bsu - p_sys->i_bsut >= 0x00 ?                       p_sys->i_bsu - p_sys->i_bsut : 0x00;                umax = p_sys->i_bsu + p_sys->i_bsut <= 0xff ?                       p_sys->i_bsu + p_sys->i_bsut : 0xff;                vmin = p_sys->i_bsv - p_sys->i_bsvt >= 0x00 ?                       p_sys->i_bsv - p_sys->i_bsvt : 0x00;                vmax = p_sys->i_bsv + p_sys->i_bsvt <= 0xff ?                       p_sys->i_bsv + p_sys->i_bsvt : 0xff;                for( i = 0; i < i_lines*i_pitch; i++ )                {                    if(    p_u[i] < umax                        && p_u[i] > umin                        && p_v[i] < vmax                        && p_v[i] > vmin )                    {                        p_at[i] = 0x00;                    }                    else                    {                        p_at[i] = 0xff;                    }                }                /* Gaussian convolution to make it look cleaner */                memset( p_a, 0, 2 * i_pitch );                for( i = 2; i < i_lines - 2; i++ )                {                    p_a[i*i_pitch] = 0x00;                    p_a[i*i_pitch+1] = 0x00;                    for( j = 2; j < i_pitch - 2; j ++ )                    {                        p_a[i*i_pitch+j] = (uint8_t)((                          /* 2 rows up */                            ( p_at[(i-2)*i_pitch+j-2]<<1 )                          + ( p_at[(i-2)*i_pitch+j-1]<<2 )                          + ( p_at[(i-2)*i_pitch+j]<<2 )                          + ( p_at[(i-2)*i_pitch+j+1]<<2 )                          + ( p_at[(i-2)*i_pitch+j+2]<<1 )                          /* 1 row up */                          + ( p_at[(i-1)*i_pitch+j-1]<<3 )                          + ( p_at[(i-1)*i_pitch+j-2]<<2 )                          + ( p_at[(i-1)*i_pitch+j]*12 )                          + ( p_at[(i-1)*i_pitch+j+1]<<3 )                          + ( p_at[(i-1)*i_pitch+j+2]<<2 )                          /* */                          + ( p_at[i*i_pitch+j-2]<<2 )                          + ( p_at[i*i_pitch+j-1]*12 )                          + ( p_at[i*i_pitch+j]<<4 )                          + ( p_at[i*i_pitch+j+1]*12 )                          + ( p_at[i*i_pitch+j+2]<<2 )                          /* 1 row down */                          + ( p_at[(i+1)*i_pitch+j-2]<<2 )                          + ( p_at[(i+1)*i_pitch+j-1]<<3 )                          + ( p_at[(i+1)*i_pitch+j]*12 )                          + ( p_at[(i+1)*i_pitch+j+1]<<3 )                          + ( p_at[(i+1)*i_pitch+j+2]<<2 )                          /* 2 rows down */                          + ( p_at[(i+2)*i_pitch+j-2]<<1 )                          + ( p_at[(i+2)*i_pitch+j-1]<<2 )                          + ( p_at[(i+2)*i_pitch+j]<<2 )                          + ( p_at[(i+2)*i_pitch+j+1]<<2 )                          + ( p_at[(i+2)*i_pitch+j+2]<<1 )                          )/152);                          if( p_a[i*i_pitch+j] < 0xbf ) p_a[i*i_pitch+j] = 0x00;                    }                }                free( p_at );            }        }        else        {            p_converted = p_es->p_picture;            p_converted->i_refcount++;            fmt_in.i_width = fmt_out.i_width = p_converted->format.i_width;            fmt_in.i_height = fmt_out.i_height = p_converted->format.i_height;            fmt_in.i_chroma = fmt_out.i_chroma = p_converted->format.i_chroma;            fmt_out.i_visible_width = fmt_out.i_width;            fmt_out.i_visible_height = fmt_out.i_height;        }        p_region = p_spu->pf_make_region( VLC_OBJECT(p_filter), &fmt_out,                                          p_converted );        if( !p_region )        {            msg_Err( p_filter, "cannot allocate SPU region" );            p_filter->pf_sub_buffer_del( p_filter, p_spu );            vlc_mutex_unlock( &p_sys->lock );            vlc_mutex_unlock( p_sys->p_lock );            return p_spu;        }        /* HACK ALERT : let's fix the pointers to avoid picture duplication.         * This is necessary because p_region->picture is not a pointer         * as it ought to be. */        if( !p_sys->b_keep )        {            free( p_converted );        }        else        {            /* Keep a pointer to the original picture (and its refcount...). */            p_region->picture.p_sys = (picture_sys_t *)p_converted;            p_region->picture.pf_release = MosaicReleasePicture;        }        if( fmt_out.i_width > col_inner_width ||            p_sys->b_ar || p_sys->b_keep )        {            /* we don't have to center the video since it takes the            whole rectangle area or it's larger than the rectangle */            p_region->i_x = p_sys->i_xoffset                        + i_col * ( p_sys->i_width / p_sys->i_cols )                        + ( i_col * p_sys->i_borderw ) / p_sys->i_cols;        }        else        {            /* center the video in the dedicated rectangle */            p_region->i_x = p_sys->i_xoffset                    + i_col * ( p_sys->i_width / p_sys->i_cols )                    + ( i_col * p_sys->i_borderw ) / p_sys->i_cols                    + ( col_inner_width - fmt_out.i_width ) / 2;        }        if( fmt_out.i_height < row_inner_height            || p_sys->b_ar || p_sys->b_keep )        {            /* we don't have to center the video since it takes the            whole rectangle area or it's taller than the rectangle */            p_region->i_y = p_sys->i_yoffset                    + i_row * ( p_sys->i_height / p_sys->i_rows )                    + ( i_row * p_sys->i_borderh ) / p_sys->i_rows;        }        else        {            /* center the video in the dedicated rectangle */            p_region->i_y = p_sys->i_yoffset                    + i_row * ( p_sys->i_height / p_sys->i_rows )                    + ( i_row * p_sys->i_borderh ) / p_sys->i_rows                    + ( row_inner_height - fmt_out.i_height ) / 2;        }        if( p_region_prev == NULL )        {            p_spu->p_region = p_region;        }        else        {            p_region_prev->p_next = p_region;        }        p_region_prev = p_region;    }    vlc_mutex_unlock( p_sys->p_lock );    vlc_mutex_unlock( &p_sys->lock );    return p_spu;}/****************************************************************************** Callback to update params on the fly*****************************************************************************/static int MosaicCallback( vlc_object_t *p_this, char const *psz_var,                            vlc_value_t oldval, vlc_value_t newval,                            void *p_data ){    filter_sys_t *p_sys = (filter_sys_t *) p_data;    if( !strcmp( psz_var, "mosaic-alpha" ) )    {        vlc_mutex_lock( &p_sys->lock );        msg_Dbg( p_this, "changing alpha from %d/255 to %d/255",                         p_sys->i_alpha, newval.i_int);        p_sys->i_alpha = __MIN( __MAX( newval.i_int, 0 ), 255 );        vlc_mutex_unlock( &p_sys->lock );    }    else if( !strcmp( psz_var, "mosaic-height" ) )    {        vlc_mutex_lock( &p_sys->lock );        msg_Dbg( p_this, "changing height from %dpx to %dpx",                          p_sys->i_height, newval.i_int );        p_sys->i_height = __MAX( newval.i_int, 0 );        vlc_mutex_unlock( &p_sys->lock );    }    else if( !strcmp( psz_var, "mosaic-width" ) )    {        vlc_mutex_lock( &p_sys->lock );        msg_Dbg( p_this, "changing width from %dpx to %dpx",                         p_sys->i_width, newval.i_int );        p_sys->i_width = __MAX( newval.i_int, 0 );        vlc_mutex_unlock( &p_sys->lock );    }    else if( !strcmp( psz_var, "mosaic-xoffset" ) )    {        vlc_mutex_lock( &p_sys->lock );        msg_Dbg( p_this, "changing x offset from %dpx to %dpx",                         p_sys->i_xoffset, newval.i_int );        p_sys->i_xoffset = __MAX( newval.i_int, 0 );        vlc_mutex_unlock( &p_sys->lock );    }    else if( !strcmp( psz_var, "mosaic-yoffset" ) )    {        vlc_mutex_lock( &p_sys->lock );        msg_Dbg( p_this, "changing y offset from %dpx to %dpx",                         p_sys->i_yoffset, newval.i_int );        p_sys->i_yoffset = __MAX( newval.i_int, 0 );        vlc_mutex_unlock( &p_sys->lock );    }    else if( !strcmp( psz_var, "mosaic-align" ) )    {        int i_old = 0, i_new = 0;        vlc_mutex_lock( &p_sys->lock );        newval.i_int = __MIN( __MAX( newval.i_int, 0 ), 10 );        if( newval.i_int == 3 || newval.i_int == 7 )            newval.i_int = 5;        while( pi_align_values[i_old] != p_sys->i_align ) i_old++;        while( pi_align_values[i_new] != newval.i_int ) i_new++;        msg_Dbg( p_this, "changing alignment from %d (%s) to %d (%s)",                     p_sys->i_align, ppsz_align_descriptions[i_old],                     newval.i_int, ppsz_align_descriptions[i_new] );        p_sys->i_align = newval.i_int;        vlc_mutex_unlock( &p_sys->lock );    }    else if( !strcmp( psz_var, "mosaic-borderw" ) )    {        vlc_mutex_lock( &p_sys->lock );        msg_Dbg( p_this, "changing border width from %dpx to %dpx",                         p_sys->i_borderw, newval.i_int );        p_sys->i_borderw = __MAX( newval.i_int, 0 );        vlc_mutex_unlock( &p_sys->lock );    }    else if( !strcmp( psz_var, "mosaic-borderh" ) )    {        vlc_mutex_lock( &p_sys->lock );        msg_Dbg( p_this, "changing border height from %dpx to %dpx",                         p_sys->i_borderh, newval.i_int );        p_sys->i_borderh = __MAX( newval.i_int, 0 );        vlc_mutex_unlock( &p_sys->lock );    }    else if( !strcmp( psz_var, "mosaic-position" ) )    {        if( newval.i_int > 1 || newval.i_int < 0 )        {            msg_Err( p_this, "Position is either 0 (auto) or 1 (fixed)" );        }        else        {            vlc_mutex_lock( &p_sys->lock );            msg_Dbg( p_this, "changing position method from %d (%s) to %d (%s)",                             p_sys->i_position, ppsz_pos_descriptions[p_sys->i_position],                             newval.i_int, ppsz_pos_descriptions[newval.i_int]);            p_sys->i_position = newval.i_int;            vlc_mutex_unlock( &p_sys->lock );        }    }    else if( !strcmp( psz_var, "mosaic-rows" ) )    {        vlc_mutex_lock( &p_sys->lock );        msg_Dbg( p_this, "changing number of rows from %d to %d",                         p_sys->i_rows, newval.i_int );        p_sys->i_rows = __MAX( newval.i_int, 1 );        vlc_mutex_unlock( &p_sys->lock );    }    else if( !strcmp( psz_var, "mosaic-cols" ) )    {        vlc_mutex_lock( &p_sys->lock );        msg_Dbg( p_this, "changing number of columns from %d to %d",                         p_sys->i_cols, newval.i_int );        p_sys->i_cols = __MAX( newval.i_int, 1 );        vlc_mutex_unlock( &p_sys->lock );    }    else if( !strcmp( psz_var, "mosaic-keep-aspect-ratio" ) )    {        vlc_mutex_lock( &p_sys->lock );        if( newval.i_int )        {            msg_Dbg( p_this, "keeping aspect ratio" );            p_sys->b_ar = 1;        }        else        {            msg_Dbg( p_this, "won't keep aspect ratio" );            p_sys->b_ar = 0;        }        vlc_mutex_unlock( &p_sys->lock );    }    return VLC_SUCCESS;}

⌨️ 快捷键说明

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