📄 crop.c
字号:
/***************************************************************************** * crop.c : Crop video plugin for vlc ***************************************************************************** * Copyright (C) 2002, 2003 VideoLAN * $Id: crop.c 10145 2005-03-05 16:49:15Z gbazin $ * * Authors: Samuel Hocevar <sam@zoy.org> * * 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 * (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. * * 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., 59 Temple Place - Suite 330, Boston, MA 02111, USA. *****************************************************************************//***************************************************************************** * Preamble *****************************************************************************/#include <stdlib.h> /* malloc(), free() */#include <string.h>#include <vlc/vlc.h>#include <vlc/vout.h>#include "filter_common.h"/***************************************************************************** * Local prototypes *****************************************************************************/static int Create ( vlc_object_t * );static void Destroy ( vlc_object_t * );static int Init ( vout_thread_t * );static void End ( vout_thread_t * );static int Manage ( vout_thread_t * );static void Render ( vout_thread_t *, picture_t * );static void UpdateStats ( vout_thread_t *, picture_t * );static int SendEvents( vlc_object_t *, char const *, vlc_value_t, vlc_value_t, void * );/***************************************************************************** * Module descriptor *****************************************************************************/#define GEOMETRY_TEXT N_("Crop geometry (pixels)")#define GEOMETRY_LONGTEXT N_("Set the geometry of the zone to crop. This is set as <width> x <height> + <left offset> + <top offset>.")#define AUTOCROP_TEXT N_("Automatic cropping")#define AUTOCROP_LONGTEXT N_("Activate automatic black border cropping.")vlc_module_begin(); set_description( _("Crop video filter") ); set_shortname( N_("Crop" )); set_category( CAT_VIDEO ); set_subcategory( SUBCAT_VIDEO_VFILTER ); set_capability( "video filter", 0 ); add_string( "crop-geometry", NULL, NULL, GEOMETRY_TEXT, GEOMETRY_LONGTEXT, VLC_FALSE ); add_bool( "autocrop", 0, NULL, AUTOCROP_TEXT, AUTOCROP_LONGTEXT, VLC_FALSE ); add_shortcut( "crop" ); set_callbacks( Create, Destroy );vlc_module_end();/***************************************************************************** * vout_sys_t: Crop video output method descriptor ***************************************************************************** * This structure is part of the video output thread descriptor. * It describes the Crop specific properties of an output thread. *****************************************************************************/struct vout_sys_t{ vout_thread_t *p_vout; unsigned int i_x, i_y; unsigned int i_width, i_height, i_aspect; vlc_bool_t b_autocrop; /* Autocrop specific variables */ unsigned int i_lastchange; vlc_bool_t b_changed;};/***************************************************************************** * Control: control facility for the vout (forwards to child vout) *****************************************************************************/static int Control( vout_thread_t *p_vout, int i_query, va_list args ){ return vout_vaControl( p_vout->p_sys->p_vout, i_query, args );}/***************************************************************************** * Create: allocates Crop video thread output method ***************************************************************************** * This function allocates and initializes a Crop vout method. *****************************************************************************/static int Create( vlc_object_t *p_this ){ vout_thread_t *p_vout = (vout_thread_t *)p_this; /* Allocate structure */ p_vout->p_sys = malloc( sizeof( vout_sys_t ) ); if( p_vout->p_sys == NULL ) { msg_Err( p_vout, "out of memory" ); return VLC_ENOMEM; } p_vout->pf_init = Init; p_vout->pf_end = End; p_vout->pf_manage = Manage; p_vout->pf_render = Render; p_vout->pf_display = NULL; p_vout->pf_control = Control; return VLC_SUCCESS;}/***************************************************************************** * Init: initialize Crop video thread output method *****************************************************************************/static int Init( vout_thread_t *p_vout ){ int i_index; char *psz_var; picture_t *p_pic; video_format_t fmt = {0}; I_OUTPUTPICTURES = 0; p_vout->p_sys->i_lastchange = 0; p_vout->p_sys->b_changed = VLC_FALSE; /* Initialize the output structure */ p_vout->output.i_chroma = p_vout->render.i_chroma; p_vout->output.i_width = p_vout->render.i_width; p_vout->output.i_height = p_vout->render.i_height; p_vout->output.i_aspect = p_vout->render.i_aspect; /* Shall we use autocrop ? */ p_vout->p_sys->b_autocrop = config_GetInt( p_vout, "autocrop" ); /* Get geometry value from the user */ psz_var = config_GetPsz( p_vout, "crop-geometry" ); if( psz_var ) { char *psz_parser, *psz_tmp; psz_parser = psz_tmp = psz_var; while( *psz_tmp && *psz_tmp != 'x' ) psz_tmp++; if( *psz_tmp ) { psz_tmp[0] = '\0'; p_vout->p_sys->i_width = atoi( psz_parser ); psz_parser = ++psz_tmp; while( *psz_tmp && *psz_tmp != '+' ) psz_tmp++; if( *psz_tmp ) { psz_tmp[0] = '\0'; p_vout->p_sys->i_height = atoi( psz_parser ); psz_parser = ++psz_tmp; while( *psz_tmp && *psz_tmp != '+' ) psz_tmp++; if( *psz_tmp ) { psz_tmp[0] = '\0'; p_vout->p_sys->i_x = atoi( psz_parser ); p_vout->p_sys->i_y = atoi( ++psz_tmp ); } else { p_vout->p_sys->i_x = atoi( psz_parser ); p_vout->p_sys->i_y = ( p_vout->output.i_height - p_vout->p_sys->i_height ) / 2; } } else { p_vout->p_sys->i_height = atoi( psz_parser ); p_vout->p_sys->i_x = ( p_vout->output.i_width - p_vout->p_sys->i_width ) / 2; p_vout->p_sys->i_y = ( p_vout->output.i_height - p_vout->p_sys->i_height ) / 2; } } else { p_vout->p_sys->i_width = atoi( psz_parser ); p_vout->p_sys->i_height = p_vout->output.i_height; p_vout->p_sys->i_x = ( p_vout->output.i_width - p_vout->p_sys->i_width ) / 2; p_vout->p_sys->i_y = ( p_vout->output.i_height - p_vout->p_sys->i_height ) / 2; } /* Check for validity */ if( p_vout->p_sys->i_x + p_vout->p_sys->i_width > p_vout->output.i_width ) { p_vout->p_sys->i_x = 0; if( p_vout->p_sys->i_width > p_vout->output.i_width ) { p_vout->p_sys->i_width = p_vout->output.i_width; } } if( p_vout->p_sys->i_y + p_vout->p_sys->i_height > p_vout->output.i_height ) { p_vout->p_sys->i_y = 0; if( p_vout->p_sys->i_height > p_vout->output.i_height ) { p_vout->p_sys->i_height = p_vout->output.i_height; } } free( psz_var ); } else { p_vout->p_sys->i_width = p_vout->output.i_width; p_vout->p_sys->i_height = p_vout->output.i_height; p_vout->p_sys->i_x = p_vout->p_sys->i_y = 0; } /* Pheeew. Parsing done. */ msg_Dbg( p_vout, "cropping at %ix%i+%i+%i, %sautocropping", p_vout->p_sys->i_width, p_vout->p_sys->i_height, p_vout->p_sys->i_x, p_vout->p_sys->i_y, p_vout->p_sys->b_autocrop ? "" : "not " ); /* Set current output image properties */ 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; 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; /* Try to open the real video output */ 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; } ALLOCATE_DIRECTBUFFERS( VOUT_MAX_PICTURES ); ADD_CALLBACKS( p_vout->p_sys->p_vout, SendEvents );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -