From 8d19624ee75463ac9bdd89cb07bdec9f7b283891 Mon Sep 17 00:00:00 2001 From: Antoine Cellerier Date: Sat, 13 May 2006 23:16:24 +0000 Subject: [PATCH] Allow on the fly cropping size change with top, left, right and bottom offsets. alt+i -> crop one more pixel from the top alt+j -> crop one more from the left alt+k -> crop one more from the bottom alt+l -> crop one more from the right alt+shift+ -> crop one less --- include/vlc_keys.h | 8 ++ modules/control/hotkeys.c | 44 +++++++++ src/libvlc.h | 63 ++++++++++++ src/video_output/vout_intf.c | 180 +++++++++++++++++++++-------------- 4 files changed, 225 insertions(+), 70 deletions(-) diff --git a/include/vlc_keys.h b/include/vlc_keys.h index 2302b14414..f101e519ef 100644 --- a/include/vlc_keys.h +++ b/include/vlc_keys.h @@ -258,3 +258,11 @@ static inline int StringToKey( char *psz_key ) #define ACTIONID_DEINTERLACE 69 #define ACTIONID_ZOOM 70 #define ACTIONID_UNZOOM 71 +#define ACTIONID_CROP_TOP 72 +#define ACTIONID_UNCROP_TOP 73 +#define ACTIONID_CROP_LEFT 74 +#define ACTIONID_UNCROP_LEFT 75 +#define ACTIONID_CROP_BOTTOM 76 +#define ACTIONID_UNCROP_BOTTOM 77 +#define ACTIONID_CROP_RIGHT 78 +#define ACTIONID_UNCROP_RIGHT 79 diff --git a/modules/control/hotkeys.c b/modules/control/hotkeys.c index 3ded356035..faee64c5a7 100644 --- a/modules/control/hotkeys.c +++ b/modules/control/hotkeys.c @@ -618,6 +618,50 @@ static void Run( intf_thread_t *p_intf ) text_list.p_list->p_values[i].var.psz_name ); } } + else if( i_action == ACTIONID_CROP_TOP && p_vout ) + { + int i_val = var_GetInteger( p_vout, "crop-top" ); + var_SetInteger( p_vout, "crop-top", i_val+1 ); + } + else if( i_action == ACTIONID_UNCROP_TOP && p_vout ) + { + int i_val = var_GetInteger( p_vout, "crop-top" ); + if( i_val != 0 ) + var_SetInteger( p_vout, "crop-top", i_val-1 ); + } + else if( i_action == ACTIONID_CROP_BOTTOM && p_vout ) + { + int i_val = var_GetInteger( p_vout, "crop-bottom" ); + var_SetInteger( p_vout, "crop-bottom", i_val+1 ); + } + else if( i_action == ACTIONID_UNCROP_BOTTOM && p_vout ) + { + int i_val = var_GetInteger( p_vout, "crop-bottom" ); + if( i_val != 0 ) + var_SetInteger( p_vout, "crop-bottom", i_val-1 ); + } + else if( i_action == ACTIONID_CROP_LEFT && p_vout ) + { + int i_val = var_GetInteger( p_vout, "crop-left" ); + var_SetInteger( p_vout, "crop-left", i_val+1 ); + } + else if( i_action == ACTIONID_UNCROP_LEFT && p_vout ) + { + int i_val = var_GetInteger( p_vout, "crop-left" ); + if( i_val != 0 ) + var_SetInteger( p_vout, "crop-left", i_val-1 ); + } + else if( i_action == ACTIONID_CROP_RIGHT && p_vout ) + { + int i_val = var_GetInteger( p_vout, "crop-right" ); + var_SetInteger( p_vout, "crop-right", i_val+1 ); + } + else if( i_action == ACTIONID_UNCROP_RIGHT && p_vout ) + { + int i_val = var_GetInteger( p_vout, "crop-right" ); + if( i_val != 0 ) + var_SetInteger( p_vout, "crop-right", i_val-1 ); + } else if( i_action == ACTIONID_NEXT ) { p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, diff --git a/src/libvlc.h b/src/libvlc.h index 04068880a0..098ddaa876 100644 --- a/src/libvlc.h +++ b/src/libvlc.h @@ -1088,6 +1088,26 @@ static char *ppsz_clock_descriptions[] = #define UNZOOM_KEY_TEXT N_("Un-Zoom") #define UNZOOM_KEY_LONGTEXT N_("Un-Zoom") +#define CROP_TOP_KEY_TEXT N_("Crop one pixel from the top of the video") +#define CROP_TOP_KEY_LONGTEXT N_("Crop one pixel from the top of the video") +#define UNCROP_TOP_KEY_TEXT N_("Uncrop one pixel from the top of the video") +#define UNCROP_TOP_KEY_LONGTEXT N_("Uncrop one pixel from the top of the video") + +#define CROP_LEFT_KEY_TEXT N_("Crop one pixel from the left of the video") +#define CROP_LEFT_KEY_LONGTEXT N_("Crop one pixel from the left of the video") +#define UNCROP_LEFT_KEY_TEXT N_("Uncrop one pixel from the left of the video") +#define UNCROP_LEFT_KEY_LONGTEXT N_("Uncrop one pixel from the left of the video") + +#define CROP_BOTTOM_KEY_TEXT N_("Crop one pixel from the bottom of the video") +#define CROP_BOTTOM_KEY_LONGTEXT N_("Crop one pixel from the bottom of the video") +#define UNCROP_BOTTOM_KEY_TEXT N_("Uncrop one pixel from the bottom of the video") +#define UNCROP_BOTTOM_KEY_LONGTEXT N_("Uncrop one pixel from the bottom of the video") + +#define CROP_RIGHT_KEY_TEXT N_("Crop one pixel from the right of the video") +#define CROP_RIGHT_KEY_LONGTEXT N_("Crop one pixel from the right of the video") +#define UNCROP_RIGHT_KEY_TEXT N_("Uncrop one pixel from the right of the video") +#define UNCROP_RIGHT_KEY_LONGTEXT N_("Uncrop one pixel from the right of the video") + #define VLC_USAGE N_( \ "Usage: %s [options] [stream] ..." \ @@ -1661,6 +1681,15 @@ vlc_module_begin(); # define KEY_ZOOM 'z' # define KEY_UNZOOM KEY_MODIFIER_SHIFT|'z' +# define KEY_CROP_TOP KEY_MODIFIER_ALT|'i' +# define KEY_UNCROP_TOP KEY_MODIFIER_ALT|KEY_MODIFIER_SHIFT|'i' +# define KEY_CROP_LEFT KEY_MODIFIER_ALT|'j' +# define KEY_UNCROP_LEFT KEY_MODIFIER_ALT|KEY_MODIFIER_SHIFT|'j' +# define KEY_CROP_BOTTOM KEY_MODIFIER_ALT|'k' +# define KEY_UNCROP_BOTTOM KEY_MODIFIER_ALT|KEY_MODIFIER_SHIFT|'k' +# define KEY_CROP_RIGHT KEY_MODIFIER_ALT|'l' +# define KEY_UNCROP_RIGHT KEY_MODIFIER_ALT|KEY_MODIFIER_SHIFT|'l' + # define KEY_SET_BOOKMARK1 KEY_MODIFIER_COMMAND|KEY_F1 # define KEY_SET_BOOKMARK2 KEY_MODIFIER_COMMAND|KEY_F2 # define KEY_SET_BOOKMARK3 KEY_MODIFIER_COMMAND|KEY_F3 @@ -1734,6 +1763,15 @@ vlc_module_begin(); # define KEY_ZOOM 'z' # define KEY_UNZOOM KEY_MODIFIER_SHIFT|'z' +# define KEY_CROP_TOP KEY_MODIFIER_ALT|'i' +# define KEY_UNCROP_TOP KEY_MODIFIER_ALT|KEY_MODIFIER_SHIFT|'i' +# define KEY_CROP_LEFT KEY_MODIFIER_ALT|'j' +# define KEY_UNCROP_LEFT KEY_MODIFIER_ALT|KEY_MODIFIER_SHIFT|'j' +# define KEY_CROP_BOTTOM KEY_MODIFIER_ALT|'k' +# define KEY_UNCROP_BOTTOM KEY_MODIFIER_ALT|KEY_MODIFIER_SHIFT|'k' +# define KEY_CROP_RIGHT KEY_MODIFIER_ALT|'l' +# define KEY_UNCROP_RIGHT KEY_MODIFIER_ALT|KEY_MODIFIER_SHIFT|'l' + # define KEY_SET_BOOKMARK1 KEY_MODIFIER_CTRL|KEY_F1 # define KEY_SET_BOOKMARK2 KEY_MODIFIER_CTRL|KEY_F2 # define KEY_SET_BOOKMARK3 KEY_MODIFIER_CTRL|KEY_F3 @@ -1859,6 +1897,23 @@ vlc_module_begin(); add_key( "key-unzoom", KEY_UNZOOM, NULL, UNZOOM_KEY_TEXT, UNZOOM_KEY_LONGTEXT, VLC_TRUE ); + add_key( "key-crop-top", KEY_CROP_TOP, NULL, + CROP_TOP_KEY_TEXT, CROP_TOP_KEY_LONGTEXT, VLC_TRUE ); + add_key( "key-uncrop-top", KEY_UNCROP_TOP, NULL, + UNCROP_TOP_KEY_TEXT, UNCROP_TOP_KEY_LONGTEXT, VLC_TRUE ); + add_key( "key-crop-left", KEY_CROP_LEFT, NULL, + CROP_LEFT_KEY_TEXT, CROP_LEFT_KEY_LONGTEXT, VLC_TRUE ); + add_key( "key-uncrop-left", KEY_UNCROP_LEFT, NULL, + UNCROP_LEFT_KEY_TEXT, UNCROP_LEFT_KEY_LONGTEXT, VLC_TRUE ); + add_key( "key-crop-bottom", KEY_CROP_BOTTOM, NULL, + CROP_BOTTOM_KEY_TEXT, CROP_BOTTOM_KEY_LONGTEXT, VLC_TRUE ); + add_key( "key-uncrop-bottom", KEY_UNCROP_BOTTOM, NULL, + UNCROP_BOTTOM_KEY_TEXT, UNCROP_BOTTOM_KEY_LONGTEXT, VLC_TRUE ); + add_key( "key-crop-right", KEY_CROP_RIGHT, NULL, + CROP_RIGHT_KEY_TEXT, CROP_RIGHT_KEY_LONGTEXT, VLC_TRUE ); + add_key( "key-uncrop-right", KEY_UNCROP_RIGHT, NULL, + UNCROP_RIGHT_KEY_TEXT, UNCROP_RIGHT_KEY_LONGTEXT, VLC_TRUE ); + set_section ( N_("Jump sizes" ), NULL ); add_integer( "extrashort-jump-size", 3, NULL, JIEXTRASHORT_TEXT, JIEXTRASHORT_LONGTEXT, VLC_FALSE ); @@ -2014,6 +2069,14 @@ static struct hotkey p_hotkeys[] = { "key-snapshot", ACTIONID_SNAPSHOT, 0, 0, 0, 0 }, { "key-zoom", ACTIONID_ZOOM, 0, 0, 0, 0 }, { "key-unzoom", ACTIONID_UNZOOM, 0, 0, 0, 0 }, + { "key-crop-top", ACTIONID_CROP_TOP, 0, 0, 0, 0 }, + { "key-uncrop-top", ACTIONID_UNCROP_TOP, 0, 0, 0, 0 }, + { "key-crop-left", ACTIONID_CROP_LEFT, 0, 0, 0, 0 }, + { "key-uncrop-left", ACTIONID_UNCROP_LEFT, 0, 0, 0, 0 }, + { "key-crop-bottom", ACTIONID_CROP_BOTTOM, 0, 0, 0, 0 }, + { "key-uncrop-bottom", ACTIONID_UNCROP_BOTTOM, 0, 0, 0, 0 }, + { "key-crop-right", ACTIONID_CROP_RIGHT, 0, 0, 0, 0 }, + { "key-uncrop-right", ACTIONID_UNCROP_RIGHT, 0, 0, 0, 0 }, { "key-nav-activate", ACTIONID_NAV_ACTIVATE, 0, 0, 0, 0 }, { "key-nav-up", ACTIONID_NAV_UP, 0, 0, 0, 0 }, { "key-nav-down", ACTIONID_NAV_DOWN, 0, 0, 0, 0 }, diff --git a/src/video_output/vout_intf.c b/src/video_output/vout_intf.c index 3d8527efad..8ced97e264 100644 --- a/src/video_output/vout_intf.c +++ b/src/video_output/vout_intf.c @@ -225,6 +225,22 @@ void vout_IntfInit( vout_thread_t *p_vout ) var_AddCallback( p_vout, "zoom", ZoomCallback, NULL ); + /* Crop offset vars */ + var_Create( p_vout, "crop-left", VLC_VAR_INTEGER ); + var_Create( p_vout, "crop-top", VLC_VAR_INTEGER ); + var_Create( p_vout, "crop-right", VLC_VAR_INTEGER ); + var_Create( p_vout, "crop-bottom", VLC_VAR_INTEGER ); + + var_SetInteger( p_vout, "crop-left", 0 ); + var_SetInteger( p_vout, "crop-top", 0 ); + var_SetInteger( p_vout, "crop-right", 0 ); + var_SetInteger( p_vout, "crop-bottom", 0 ); + + var_AddCallback( p_vout, "crop-left", CropCallback, NULL ); + var_AddCallback( p_vout, "crop-top", CropCallback, NULL ); + var_AddCallback( p_vout, "crop-right", CropCallback, NULL ); + var_AddCallback( p_vout, "crop-bottom", CropCallback, NULL ); + /* Crop object var */ var_Create( p_vout, "crop", VLC_VAR_STRING | VLC_VAR_HASCHOICE | VLC_VAR_DOINHERIT ); @@ -782,105 +798,129 @@ static int CropCallback( vlc_object_t *p_this, char const *psz_cmd, int64_t i_aspect_num, i_aspect_den; unsigned int i_width, i_height; - char *psz_end, *psz_parser = strchr( newval.psz_string, ':' ); - /* Restore defaults */ p_vout->fmt_in.i_x_offset = p_vout->fmt_render.i_x_offset; p_vout->fmt_in.i_visible_width = p_vout->fmt_render.i_visible_width; p_vout->fmt_in.i_y_offset = p_vout->fmt_render.i_y_offset; p_vout->fmt_in.i_visible_height = p_vout->fmt_render.i_visible_height; - if( psz_parser ) + if( !strcmp( psz_cmd, "crop" ) ) { - /* We're using the 3:4 syntax */ - i_aspect_num = strtol( newval.psz_string, &psz_end, 10 ); - if( psz_end == newval.psz_string || !i_aspect_num ) goto crop_end; + char *psz_end, *psz_parser = strchr( newval.psz_string, ':' ); + if( psz_parser ) + { + /* We're using the 3:4 syntax */ + i_aspect_num = strtol( newval.psz_string, &psz_end, 10 ); + if( psz_end == newval.psz_string || !i_aspect_num ) goto crop_end; - i_aspect_den = strtol( ++psz_parser, &psz_end, 10 ); - if( psz_end == psz_parser || !i_aspect_den ) goto crop_end; + i_aspect_den = strtol( ++psz_parser, &psz_end, 10 ); + if( psz_end == psz_parser || !i_aspect_den ) goto crop_end; - i_width = p_vout->fmt_in.i_sar_den*p_vout->fmt_render.i_visible_height * - i_aspect_num / i_aspect_den / p_vout->fmt_in.i_sar_num; - i_height = p_vout->fmt_render.i_visible_width*p_vout->fmt_in.i_sar_num * - i_aspect_den / i_aspect_num / p_vout->fmt_in.i_sar_den; + i_width = p_vout->fmt_in.i_sar_den*p_vout->fmt_render.i_visible_height * + i_aspect_num / i_aspect_den / p_vout->fmt_in.i_sar_num; + i_height = p_vout->fmt_render.i_visible_width*p_vout->fmt_in.i_sar_num * + i_aspect_den / i_aspect_num / p_vout->fmt_in.i_sar_den; - if( i_width < p_vout->fmt_render.i_visible_width ) - { - p_vout->fmt_in.i_x_offset = p_vout->fmt_render.i_x_offset + - (p_vout->fmt_render.i_visible_width - i_width) / 2; - p_vout->fmt_in.i_visible_width = i_width; + if( i_width < p_vout->fmt_render.i_visible_width ) + { + p_vout->fmt_in.i_x_offset = p_vout->fmt_render.i_x_offset + + (p_vout->fmt_render.i_visible_width - i_width) / 2; + p_vout->fmt_in.i_visible_width = i_width; + } + else + { + p_vout->fmt_in.i_y_offset = p_vout->fmt_render.i_y_offset + + (p_vout->fmt_render.i_visible_height - i_height) / 2; + p_vout->fmt_in.i_visible_height = i_height; + } } else { - p_vout->fmt_in.i_y_offset = p_vout->fmt_render.i_y_offset + - (p_vout->fmt_render.i_visible_height - i_height) / 2; - p_vout->fmt_in.i_visible_height = i_height; - } - } - else - { - psz_parser = strchr( newval.psz_string, 'x' ); - if( psz_parser ) - { - /* Maybe we're using the x++ syntax */ - unsigned int i_crop_width, i_crop_height, i_crop_top, i_crop_left; - - i_crop_width = strtol( newval.psz_string, &psz_end, 10 ); - if( psz_end != psz_parser ) goto crop_end; + psz_parser = strchr( newval.psz_string, 'x' ); + if( psz_parser ) + { + /* Maybe we're using the x++ syntax */ + unsigned int i_crop_width, i_crop_height, i_crop_top, i_crop_left; - psz_parser = strchr( ++psz_end, '+' ); - i_crop_height = strtol( psz_end, &psz_end, 10 ); - if( psz_end != psz_parser ) goto crop_end; + i_crop_width = strtol( newval.psz_string, &psz_end, 10 ); + if( psz_end != psz_parser ) goto crop_end; - psz_parser = strchr( ++psz_end, '+' ); - i_crop_left = strtol( psz_end, &psz_end, 10 ); - if( psz_end != psz_parser ) goto crop_end; + psz_parser = strchr( ++psz_end, '+' ); + i_crop_height = strtol( psz_end, &psz_end, 10 ); + if( psz_end != psz_parser ) goto crop_end; - i_crop_top = strtol( ++psz_end, &psz_end, 10 ); - if( *psz_end != '\0' ) goto crop_end; + psz_parser = strchr( ++psz_end, '+' ); + i_crop_left = strtol( psz_end, &psz_end, 10 ); + if( psz_end != psz_parser ) goto crop_end; - i_width = i_crop_width; - p_vout->fmt_in.i_visible_width = i_width; + i_crop_top = strtol( ++psz_end, &psz_end, 10 ); + if( *psz_end != '\0' ) goto crop_end; - i_height = i_crop_height; - p_vout->fmt_in.i_visible_height = i_height; + i_width = i_crop_width; + p_vout->fmt_in.i_visible_width = i_width; - p_vout->fmt_in.i_x_offset = i_crop_left; - p_vout->fmt_in.i_y_offset = i_crop_top; - } - else - { - /* Maybe we're using the +++ syntax */ - unsigned int i_crop_top, i_crop_left, i_crop_bottom, i_crop_right; + i_height = i_crop_height; + p_vout->fmt_in.i_visible_height = i_height; - psz_parser = strchr( newval.psz_string, '+' ); - i_crop_left = strtol( newval.psz_string, &psz_end, 10 ); - if( psz_end != psz_parser ) goto crop_end; + p_vout->fmt_in.i_x_offset = i_crop_left; + p_vout->fmt_in.i_y_offset = i_crop_top; + } + else + { + /* Maybe we're using the +++ syntax */ + unsigned int i_crop_top, i_crop_left, i_crop_bottom, i_crop_right; - psz_parser = strchr( ++psz_end, '+' ); - i_crop_top = strtol( psz_end, &psz_end, 10 ); - if( psz_end != psz_parser ) goto crop_end; + psz_parser = strchr( newval.psz_string, '+' ); + i_crop_left = strtol( newval.psz_string, &psz_end, 10 ); + if( psz_end != psz_parser ) goto crop_end; - psz_parser = strchr( ++psz_end, '+' ); - i_crop_right = strtol( psz_end, &psz_end, 10 ); - if( psz_end != psz_parser ) goto crop_end; + psz_parser = strchr( ++psz_end, '+' ); + i_crop_top = strtol( psz_end, &psz_end, 10 ); + if( psz_end != psz_parser ) goto crop_end; - i_crop_bottom = strtol( ++psz_end, &psz_end, 10 ); - if( *psz_end != '\0' ) goto crop_end; + psz_parser = strchr( ++psz_end, '+' ); + i_crop_right = strtol( psz_end, &psz_end, 10 ); + if( psz_end != psz_parser ) goto crop_end; + i_crop_bottom = strtol( ++psz_end, &psz_end, 10 ); + if( *psz_end != '\0' ) goto crop_end; - i_width = p_vout->fmt_render.i_visible_width - - i_crop_left - i_crop_right; - p_vout->fmt_in.i_visible_width = i_width; + i_width = p_vout->fmt_render.i_visible_width + - i_crop_left - i_crop_right; + p_vout->fmt_in.i_visible_width = i_width; - i_height = p_vout->fmt_render.i_visible_height - - i_crop_top - i_crop_bottom; - p_vout->fmt_in.i_visible_height = i_height; + i_height = p_vout->fmt_render.i_visible_height + - i_crop_top - i_crop_bottom; + p_vout->fmt_in.i_visible_height = i_height; - p_vout->fmt_in.i_x_offset = i_crop_left; - p_vout->fmt_in.i_y_offset = i_crop_top; + p_vout->fmt_in.i_x_offset = i_crop_left; + p_vout->fmt_in.i_y_offset = i_crop_top; + } } } + else if( !strcmp( psz_cmd, "crop-top" ) + || !strcmp( psz_cmd, "crop-left" ) + || !strcmp( psz_cmd, "crop-bottom" ) + || !strcmp( psz_cmd, "crop-right" ) ) + { + unsigned int i_crop_top, i_crop_left, i_crop_bottom, i_crop_right; + + i_crop_top = var_GetInteger( p_vout, "crop-top" ); + i_crop_left = var_GetInteger( p_vout, "crop-left" ); + i_crop_right = var_GetInteger( p_vout, "crop-right" ); + i_crop_bottom = var_GetInteger( p_vout, "crop-bottom" ); + + i_width = p_vout->fmt_render.i_visible_width + - i_crop_left - i_crop_right; + p_vout->fmt_in.i_visible_width = i_width; + + i_height = p_vout->fmt_render.i_visible_height + - i_crop_top - i_crop_bottom; + p_vout->fmt_in.i_visible_height = i_height; + + p_vout->fmt_in.i_x_offset = i_crop_left; + p_vout->fmt_in.i_y_offset = i_crop_top; + } crop_end: InitWindowSize( p_vout, &p_vout->i_window_width, -- 2.39.2