📄 crop.c
字号:
{ i_count += (p_in[i_index] > i_lumThreshold) && (p_in[i_index + 1] > i_lumThreshold); if (i_count > i_nonBlackPixel) break; } break; case VLC_FOURCC('R','V','2','4'): // packed by 3 i_skipCount = (i_pitch * i_skipCountPercent) / 100; for (i_index = i_col/2 + i_skipCount/2 - (i_col/2 + i_skipCount/2) % 3; i_index <= i_visible_pitch/2 + i_col/2 - i_skipCount/2; i_index+=3) { i_count += (p_in[i_index] > i_lumThreshold) && (p_in[i_index + 1] > i_lumThreshold) && (p_in[i_index + 2] > i_lumThreshold); if (i_count > i_nonBlackPixel) break; } break; case VLC_FOURCC('R','V','3','2'): // packed by 4 i_skipCount = (i_pitch * i_skipCountPercent) / 100; for (i_index = i_col/2 + i_skipCount/2 - (i_col/2 + i_skipCount/2) % 4; i_index <= i_visible_pitch/2 + i_col/2 - i_skipCount/2; i_index+=4) { i_count += (uint32_t)(*(p_in + i_index)) > (uint32_t)i_lumThreshold; if (i_count > i_nonBlackPixel) break; } break; // packed YUV case VLC_FOURCC('Y','U','Y','2'): // packed by 2 case VLC_FOURCC('Y','U','N','V'): // packed by 2 case VLC_FOURCC('U','Y','V','Y'): // packed by 2 case VLC_FOURCC('U','Y','N','V'): // packed by 2 case VLC_FOURCC('Y','4','2','2'): // packed by 2 i_skipCount = (i_pitch * i_skipCountPercent) / 100; for (i_index = (i_col/2 + i_skipCount/2) - (i_col/2 + i_skipCount/2) % 2; i_index <= i_visible_pitch/2 + i_col/2 - i_skipCount/2; i_index+=2) { i_count += (p_in[i_index] > i_lumThreshold); if (i_count > i_nonBlackPixel) break; } break; default : break; } return (i_count > i_nonBlackPixel);}#endifstatic 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;#ifdef BEST_AUTOCROP int i_time = p_vout->p_sys->i_time; int i_diff = p_vout->p_sys->i_diff; if (!p_vout->p_sys->i_ratio) { /* Determine where black borders are */ for( i = 0 ; i < i_lines ; i++) { if (NonBlackLine(p_in, i, i_pitch, i_visible_pitch, i_lines, p_vout->p_sys->i_threshold, p_vout->p_sys->i_skipPercent, p_vout->p_sys->i_nonBlackPixel, p_vout->output.i_chroma)) { i_firstwhite = i; i_lastwhite = i_lines - i; break; } p_in += i_pitch; } /* Decide whether it's worth changing the size */ if( i_lastwhite == -1 ) { p_vout->p_sys->i_lastchange = 0; return; } if( (i_lastwhite - i_firstwhite) < (int) (p_vout->p_sys->i_height / 2) ) { p_vout->p_sys->i_lastchange = 0; return; } if (p_vout->output.i_aspect * p_vout->output.i_height / (i_lastwhite - i_firstwhite + 1) * p_vout->p_sys->i_width / p_vout->output.i_width > p_vout->p_sys->i_ratio_max * 432) { int i_height = ((p_vout->output.i_aspect / 432) * p_vout->output.i_height * p_vout->p_sys->i_width) / (p_vout->output.i_width * p_vout->p_sys->i_ratio_max); i_firstwhite = (p_vout->output.i_height - i_height) / 2; i_lastwhite = p_vout->output.i_height - i_firstwhite;/* p_vout->p_sys->i_lastchange = 0; return;*/ } if( (i_lastwhite - i_firstwhite) < (int) (p_vout->p_sys->i_height + i_diff) && (i_lastwhite - i_firstwhite + i_diff) > (int) p_vout->p_sys->i_height ) { p_vout->p_sys->i_lastchange = 0; return; } /* We need at least 'i_time' images to make up our mind */ p_vout->p_sys->i_lastchange++; if( p_vout->p_sys->i_lastchange < (unsigned int)i_time ) { return; } } else { if ( p_vout->p_sys->i_lastchange >= (unsigned int)i_time ) { p_vout->p_sys->i_aspect = p_vout->p_sys->i_ratio * 432; int i_height = p_vout->output.i_aspect * p_vout->output.i_height / p_vout->p_sys->i_aspect * p_vout->p_sys->i_width / p_vout->output.i_width; i_firstwhite = (p_vout->output.i_height - i_height) / 2; i_lastwhite = p_vout->output.i_height - i_firstwhite; } else { return; } }#else /* 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; }#endif //BEST_AUTOCROP /* 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;#ifdef BEST_AUTOCROP // check p_vout->p_sys->i_height <= p_vout->output.i_height if (p_vout->p_sys->i_height > p_vout->output.i_height) p_vout->p_sys->i_height = p_vout->output.i_height;#endif 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 = 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 ){ VLC_UNUSED(p_this); VLC_UNUSED(oldval); 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 ){ VLC_UNUSED(p_data); VLC_UNUSED(oldval); vout_thread_t *p_vout = (vout_thread_t *)p_this; var_Set( p_vout->p_sys->p_vout, psz_var, newval ); return VLC_SUCCESS;}#ifdef BEST_AUTOCROP/***************************************************************************** * FilterCallback: called when changing the ratio on the fly. *****************************************************************************/static int FilterCallback( vlc_object_t *p_this, char const *psz_var, vlc_value_t oldval, vlc_value_t newval, void *p_data ){ VLC_UNUSED(p_data); VLC_UNUSED(oldval); vout_thread_t * p_vout = (vout_thread_t *)p_this; if( !strcmp( psz_var, "ratio-crop" ) ) { if ( !strcmp( newval.psz_string, "Auto" ) ) p_vout->p_sys->i_ratio = 0; else { p_vout->p_sys->i_ratio = (unsigned int)atoi(newval.psz_string); p_vout->p_sys->i_lastchange = p_vout->p_sys->i_time; p_vout->p_sys->b_autocrop = true; } if (p_vout->p_sys->i_ratio) { if (p_vout->p_sys->i_ratio < (p_vout->output.i_width * 1000) / p_vout->output.i_height) p_vout->p_sys->i_ratio = (p_vout->output.i_width * 1000) / p_vout->output.i_height; if (p_vout->p_sys->i_ratio < p_vout->output.i_aspect / 432) p_vout->p_sys->i_ratio = p_vout->output.i_aspect / 432; } } return VLC_SUCCESS;}#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -