X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fvideo_filter%2Ftransform.c;h=b658ffe39b559e956f3aa17b20fcdbd69edc9846;hb=c8b59ecdd5e8110647d5864e22d75ef92861d449;hp=fd201bcdd2c8b406790f9e6aac3b1d392e79a84c;hpb=2cb472dba008f7d877ffe6bae9c5575253365282;p=vlc diff --git a/modules/video_filter/transform.c b/modules/video_filter/transform.c index fd201bcdd2..b658ffe39b 100644 --- a/modules/video_filter/transform.c +++ b/modules/video_filter/transform.c @@ -1,7 +1,7 @@ /***************************************************************************** * transform.c : transform image module for vlc ***************************************************************************** - * Copyright (C) 2000-2004 the VideoLAN team + * Copyright (C) 2000-2006 the VideoLAN team * $Id$ * * Authors: Samuel Hocevar @@ -24,13 +24,16 @@ /***************************************************************************** * Preamble *****************************************************************************/ -#include /* malloc(), free() */ -#include + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif #include -#include +#include #include "filter_common.h" +#include "filter_picture.h" #define TRANSFORM_MODE_HFLIP 1 #define TRANSFORM_MODE_VFLIP 2 @@ -48,6 +51,9 @@ static int Init ( vout_thread_t * ); static void End ( vout_thread_t * ); static void Render ( vout_thread_t *, picture_t * ); +static void FilterPlanar( vout_thread_t *, const picture_t *, picture_t * ); +static void FilterYUYV( vout_thread_t *, const picture_t *, picture_t * ); + static int SendEvents( vlc_object_t *, char const *, vlc_value_t, vlc_value_t, void * ); @@ -57,19 +63,21 @@ static int SendEvents( vlc_object_t *, char const *, #define TYPE_TEXT N_("Transform type") #define TYPE_LONGTEXT N_("One of '90', '180', '270', 'hflip' and 'vflip'") -static char *type_list[] = { "90", "180", "270", "hflip", "vflip" }; -static char *type_list_text[] = { N_("Rotate by 90 degrees"), +static const char *type_list[] = { "90", "180", "270", "hflip", "vflip" }; +static const char *type_list_text[] = { N_("Rotate by 90 degrees"), N_("Rotate by 180 degrees"), N_("Rotate by 270 degrees"), N_("Flip horizontally"), N_("Flip vertically") }; +#define CFG_PREFIX "transform-" + vlc_module_begin(); set_description( _("Video transformation filter") ); - set_shortname( N_("Transformation")); + set_shortname( _("Transformation")); set_capability( "video filter", 0 ); set_category( CAT_VIDEO ); set_subcategory( SUBCAT_VIDEO_VFILTER ); - add_string( "transform-type", "90", NULL, + add_string( CFG_PREFIX "type", "90", NULL, TYPE_TEXT, TYPE_LONGTEXT, VLC_FALSE); change_string_list( type_list, type_list_text, 0); @@ -77,6 +85,10 @@ vlc_module_begin(); set_callbacks( Create, Destroy ); vlc_module_end(); +static const char *ppsz_filter_options[] = { + "type", NULL +}; + /***************************************************************************** * vout_sys_t: Transform video output method descriptor ***************************************************************************** @@ -88,6 +100,8 @@ struct vout_sys_t int i_mode; vlc_bool_t b_rotation; vout_thread_t *p_vout; + + void (*pf_filter)( vout_thread_t *, const picture_t *, picture_t * ); }; /***************************************************************************** @@ -123,8 +137,28 @@ static int Create( vlc_object_t *p_this ) p_vout->pf_display = NULL; p_vout->pf_control = Control; + config_ChainParse( p_vout, CFG_PREFIX, ppsz_filter_options, + p_vout->p_cfg ); + /* Look what method was requested */ - psz_method = config_GetPsz( p_vout, "transform-type" ); + psz_method = var_CreateGetNonEmptyString( p_vout, "transform-type" ); + + switch( p_vout->fmt_in.i_chroma ) + { + CASE_PLANAR_YUV + case VLC_FOURCC('G','R','E','Y'): + p_vout->p_sys->pf_filter = FilterPlanar; + break; + + CASE_PACKED_YUV_422 + p_vout->p_sys->pf_filter = FilterYUYV; + break; + + default: + msg_Err( p_vout, "Unsupported chroma" ); + free( p_vout->p_sys ); + return VLC_EGENERIC; + } if( psz_method == NULL ) { @@ -180,9 +214,10 @@ static int Init( vout_thread_t *p_vout ) { int i_index; picture_t *p_pic; - video_format_t fmt = {0}; + video_format_t fmt; I_OUTPUTPICTURES = 0; + memset( &fmt, 0, sizeof(video_format_t) ); /* Initialize the output structure */ p_vout->output.i_chroma = p_vout->render.i_chroma; @@ -210,14 +245,10 @@ static int Init( vout_thread_t *p_vout ) fmt.i_sar_num = p_vout->fmt_out.i_sar_den; fmt.i_sar_den = p_vout->fmt_out.i_sar_num; - - p_vout->p_sys->p_vout = vout_Create( p_vout, &fmt ); - } - else - { - p_vout->p_sys->p_vout = vout_Create( p_vout, &fmt ); } + p_vout->p_sys->p_vout = vout_Create( p_vout, &fmt ); + /* Everything failed */ if( p_vout->p_sys->p_vout == NULL ) { @@ -280,7 +311,6 @@ static void Destroy( vlc_object_t *p_this ) static void Render( vout_thread_t *p_vout, picture_t *p_pic ) { picture_t *p_outpic; - int i_index; /* This is a new frame. Get a structure from the video_output. */ while( ( p_outpic = vout_CreatePicture( p_vout->p_sys->p_vout, 0, 0, 0 ) ) @@ -296,6 +326,90 @@ static void Render( vout_thread_t *p_vout, picture_t *p_pic ) vout_DatePicture( p_vout->p_sys->p_vout, p_outpic, p_pic->date ); vout_LinkPicture( p_vout->p_sys->p_vout, p_outpic ); + p_vout->p_sys->pf_filter( p_vout, p_pic, p_outpic ); + + vout_UnlinkPicture( p_vout->p_sys->p_vout, p_outpic ); + + vout_DisplayPicture( p_vout->p_sys->p_vout, p_outpic ); +} + +/***************************************************************************** + * 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" ) ) + { + switch( p_vout->p_sys->i_mode ) + { + case TRANSFORM_MODE_270: + sentval.i_int = p_vout->p_sys->p_vout->output.i_width + - sentval.i_int; + case TRANSFORM_MODE_90: + var_Set( p_vout, "mouse-y", sentval ); + return VLC_SUCCESS; + + case TRANSFORM_MODE_180: + case TRANSFORM_MODE_HFLIP: + sentval.i_int = p_vout->p_sys->p_vout->output.i_width + - sentval.i_int; + break; + + case TRANSFORM_MODE_VFLIP: + default: + break; + } + } + else if( !strcmp( psz_var, "mouse-y" ) ) + { + switch( p_vout->p_sys->i_mode ) + { + case TRANSFORM_MODE_90: + sentval.i_int = p_vout->p_sys->p_vout->output.i_height + - sentval.i_int; + case TRANSFORM_MODE_270: + var_Set( p_vout, "mouse-x", sentval ); + return VLC_SUCCESS; + + case TRANSFORM_MODE_180: + case TRANSFORM_MODE_VFLIP: + sentval.i_int = p_vout->p_sys->p_vout->output.i_height + - sentval.i_int; + break; + + case TRANSFORM_MODE_HFLIP: + default: + break; + } + } + + 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; +} + +static void FilterPlanar( vout_thread_t *p_vout, + const picture_t *p_pic, picture_t *p_outpic ) +{ + int i_index; switch( p_vout->p_sys->i_mode ) { case TRANSFORM_MODE_90: @@ -401,7 +515,7 @@ static void Render( vout_thread_t *p_vout, picture_t *p_pic ) for( ; p_in < p_in_end ; ) { p_in_end -= p_pic->p[i_index].i_pitch; - p_vout->p_vlc->pf_memcpy( p_out, p_in_end, + p_vout->p_libvlc->pf_memcpy( p_out, p_in_end, p_pic->p[i_index].i_visible_pitch ); p_out += p_pic->p[i_index].i_pitch; } @@ -413,14 +527,14 @@ static void Render( vout_thread_t *p_vout, picture_t *p_pic ) { uint8_t *p_in = p_pic->p[i_index].p_pixels; uint8_t *p_in_end = p_in + p_pic->p[i_index].i_visible_lines - * p_pic->p[i_index].i_pitch; + * p_pic->p[i_index].i_pitch; uint8_t *p_out = p_outpic->p[i_index].p_pixels; for( ; p_in < p_in_end ; ) { uint8_t *p_line_end = p_in - + p_pic->p[i_index].i_visible_pitch; + + p_pic->p[i_index].i_visible_pitch; for( ; p_in < p_line_end ; ) { @@ -435,79 +549,190 @@ static void Render( vout_thread_t *p_vout, picture_t *p_pic ) default: break; } - - vout_UnlinkPicture( p_vout->p_sys->p_vout, p_outpic ); - - vout_DisplayPicture( p_vout->p_sys->p_vout, p_outpic ); } -/***************************************************************************** - * 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 ) +static void FilterYUYV( vout_thread_t *p_vout, + const picture_t *p_pic, picture_t *p_outpic ) { - vout_thread_t *p_vout = (vout_thread_t *)_p_vout; - vlc_value_t sentval = newval; + int i_index; + int i_y_offset, i_u_offset, i_v_offset; + if( GetPackedYuvOffsets( p_pic->format.i_chroma, &i_y_offset, + &i_u_offset, &i_v_offset ) != VLC_SUCCESS ) + return; - /* Translate the mouse coordinates */ - if( !strcmp( psz_var, "mouse-x" ) ) + switch( p_vout->p_sys->i_mode ) { - switch( p_vout->p_sys->i_mode ) - { - case TRANSFORM_MODE_270: - sentval.i_int = p_vout->p_sys->p_vout->output.i_width - - sentval.i_int; case TRANSFORM_MODE_90: - var_Set( p_vout, "mouse-y", sentval ); - return VLC_SUCCESS; + for( i_index = 0 ; i_index < p_pic->i_planes ; i_index++ ) + { + int i_pitch = p_pic->p[i_index].i_pitch; - case TRANSFORM_MODE_180: - case TRANSFORM_MODE_HFLIP: - sentval.i_int = p_vout->p_sys->p_vout->output.i_width - - sentval.i_int; + uint8_t *p_in = p_pic->p[i_index].p_pixels; + + uint8_t *p_out = p_outpic->p[i_index].p_pixels; + uint8_t *p_out_end = p_out + + p_outpic->p[i_index].i_visible_lines * + p_outpic->p[i_index].i_pitch; + + int i_offset = i_u_offset; + int i_offset2 = i_v_offset; + for( ; p_out < p_out_end ; ) + { + uint8_t *p_line_end; + + p_out_end -= p_outpic->p[i_index].i_pitch + - p_outpic->p[i_index].i_visible_pitch; + p_line_end = p_in + p_pic->p[i_index].i_visible_lines * + i_pitch; + + for( ; p_in < p_line_end ; ) + { + p_line_end -= i_pitch; + p_out_end -= 4; + p_out_end[i_y_offset+2] = p_line_end[i_y_offset]; + p_out_end[i_u_offset] = p_line_end[i_offset]; + p_line_end -= i_pitch; + p_out_end[i_y_offset] = p_line_end[i_y_offset]; + p_out_end[i_v_offset] = p_line_end[i_offset2]; + } + + p_in += 2; + + { + int a = i_offset; + i_offset = i_offset2; + i_offset2 = a; + } + } + } break; - case TRANSFORM_MODE_VFLIP: - default: + case TRANSFORM_MODE_180: + for( i_index = 0 ; i_index < p_pic->i_planes ; i_index++ ) + { + uint8_t *p_in = p_pic->p[i_index].p_pixels; + uint8_t *p_in_end = p_in + p_pic->p[i_index].i_visible_lines + * p_pic->p[i_index].i_pitch; + + uint8_t *p_out = p_outpic->p[i_index].p_pixels; + + for( ; p_in < p_in_end ; ) + { + uint8_t *p_line_start = p_in_end + - p_pic->p[i_index].i_pitch; + p_in_end -= p_pic->p[i_index].i_pitch + - p_pic->p[i_index].i_visible_pitch; + + for( ; p_line_start < p_in_end ; ) + { + p_in_end -= 4; + p_out[i_y_offset] = p_in_end[i_y_offset+2]; + p_out[i_u_offset] = p_in_end[i_u_offset]; + p_out[i_y_offset+2] = p_in_end[i_y_offset]; + p_out[i_v_offset] = p_in_end[i_v_offset]; + p_out += 4; + } + + p_out += p_outpic->p[i_index].i_pitch + - p_outpic->p[i_index].i_visible_pitch; + } + } break; - } - } - else if( !strcmp( psz_var, "mouse-y" ) ) - { - switch( p_vout->p_sys->i_mode ) - { - case TRANSFORM_MODE_90: - sentval.i_int = p_vout->p_sys->p_vout->output.i_height - - sentval.i_int; + case TRANSFORM_MODE_270: - var_Set( p_vout, "mouse-x", sentval ); - return VLC_SUCCESS; + for( i_index = 0 ; i_index < p_pic->i_planes ; i_index++ ) + { + int i_pitch = p_pic->p[i_index].i_pitch; - case TRANSFORM_MODE_180: - case TRANSFORM_MODE_VFLIP: - sentval.i_int = p_vout->p_sys->p_vout->output.i_height - - sentval.i_int; + uint8_t *p_in = p_pic->p[i_index].p_pixels; + + uint8_t *p_out = p_outpic->p[i_index].p_pixels; + uint8_t *p_out_end = p_out + + p_outpic->p[i_index].i_visible_lines * + p_outpic->p[i_index].i_pitch; + + int i_offset = i_u_offset; + int i_offset2 = i_v_offset; + for( ; p_out < p_out_end ; ) + { + uint8_t *p_in_end; + + p_in_end = p_in + + p_pic->p[i_index].i_visible_lines * i_pitch; + + for( ; p_in < p_in_end ; ) + { + p_in_end -= i_pitch; + p_out[i_y_offset] = p_in_end[i_y_offset]; + p_out[i_u_offset] = p_in_end[i_offset]; + p_in_end -= i_pitch; + p_out[i_y_offset+2] = p_in_end[i_y_offset]; + p_out[i_v_offset] = p_in_end[i_offset2]; + p_out += 4; + } + + p_out += p_outpic->p[i_index].i_pitch + - p_outpic->p[i_index].i_visible_pitch; + p_in += 2; + + { + int a = i_offset; + i_offset = i_offset2; + i_offset2 = a; + } + } + } break; case TRANSFORM_MODE_HFLIP: - default: + for( i_index = 0 ; i_index < p_pic->i_planes ; i_index++ ) + { + uint8_t *p_in = p_pic->p[i_index].p_pixels; + uint8_t *p_in_end = p_in + p_pic->p[i_index].i_visible_lines + * p_pic->p[i_index].i_pitch; + + uint8_t *p_out = p_outpic->p[i_index].p_pixels; + + for( ; p_in < p_in_end ; ) + { + p_in_end -= p_pic->p[i_index].i_pitch; + p_vout->p_libvlc->pf_memcpy( p_out, p_in_end, + p_pic->p[i_index].i_visible_pitch ); + p_out += p_pic->p[i_index].i_pitch; + } + } break; - } - } - var_Set( p_vout, psz_var, sentval ); + case TRANSFORM_MODE_VFLIP: + for( i_index = 0 ; i_index < p_pic->i_planes ; i_index++ ) + { + uint8_t *p_in = p_pic->p[i_index].p_pixels; + uint8_t *p_in_end = p_in + p_pic->p[i_index].i_visible_lines + * p_pic->p[i_index].i_pitch; - return VLC_SUCCESS; -} + uint8_t *p_out = p_outpic->p[i_index].p_pixels; -/***************************************************************************** - * 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; + for( ; p_in < p_in_end ; ) + { + uint8_t *p_line_end = p_in + + p_pic->p[i_index].i_visible_pitch; + + for( ; p_in < p_line_end ; ) + { + p_line_end -= 4; + p_out[i_y_offset] = p_line_end[i_y_offset+2]; + p_out[i_u_offset] = p_line_end[i_u_offset]; + p_out[i_y_offset+2] = p_line_end[i_y_offset]; + p_out[i_v_offset] = p_line_end[i_v_offset]; + p_out += 4; + } + + p_in += p_pic->p[i_index].i_pitch; + } + } + break; + + default: + break; + } }