X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fvideo_filter%2Fscale.c;h=7aa4e98e2e23da36ed6a1ad3af3a37cea16cff04;hb=23fe953dbb391d1a20a6b75a79d41ff8a2d77f82;hp=388ce699b75d1c92940d8630c2e0bf8b84cecde7;hpb=da065dee8a42be3ce097f851b0c6b73b12bf0a67;p=vlc diff --git a/modules/video_filter/scale.c b/modules/video_filter/scale.c index 388ce699b7..7aa4e98e2e 100644 --- a/modules/video_filter/scale.c +++ b/modules/video_filter/scale.c @@ -1,11 +1,12 @@ /***************************************************************************** - * resize.c: video scaling module for YUVP/A pictures + * resize.c: video scaling module for YUVP/A, I420 and RGBA pictures * Uses the low quality "nearest neighbour" algorithm. ***************************************************************************** - * Copyright (C) 2003 the VideoLAN team + * Copyright (C) 2003-2007 the VideoLAN team * $Id$ * - * Author: Gildas Bazin + * Authors: Gildas Bazin + * Antoine Cellerier * * 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 @@ -25,7 +26,12 @@ /***************************************************************************** * Preamble *****************************************************************************/ -#include +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include +#include #include #include "vlc_filter.h" @@ -50,10 +56,8 @@ static picture_t *Filter( filter_t *, picture_t * ); * Module descriptor *****************************************************************************/ vlc_module_begin(); - set_description( _("Video scaling filter") ); - set_capability( "video filter2", 10000 ); -// set_category( CAT_VIDEO ); -// set_subcategory( SUBCAT_VIDEO_VFILTER2 ); + set_description( N_("Video scaling filter") ); + set_capability( "video filter2", 10 ); set_callbacks( OpenFilter, CloseFilter ); vlc_module_end(); @@ -67,6 +71,9 @@ static int OpenFilter( vlc_object_t *p_this ) if( ( p_filter->fmt_in.video.i_chroma != VLC_FOURCC('Y','U','V','P') && p_filter->fmt_in.video.i_chroma != VLC_FOURCC('Y','U','V','A') && + p_filter->fmt_in.video.i_chroma != VLC_FOURCC('I','4','2','0') && + p_filter->fmt_in.video.i_chroma != VLC_FOURCC('Y','V','1','2') && + p_filter->fmt_in.video.i_chroma != VLC_FOURCC('R','V','3','2') && p_filter->fmt_in.video.i_chroma != VLC_FOURCC('R','G','B','A') ) || p_filter->fmt_in.video.i_chroma != p_filter->fmt_out.video.i_chroma ) { @@ -76,10 +83,7 @@ static int OpenFilter( vlc_object_t *p_this ) /* Allocate the memory needed to store the decoder's structure */ if( ( p_filter->p_sys = p_sys = (filter_sys_t *)malloc(sizeof(filter_sys_t)) ) == NULL ) - { - msg_Err( p_filter, "out of memory" ); - return VLC_EGENERIC; - } + return VLC_ENOMEM; p_filter->pf_video_filter = Filter; @@ -107,85 +111,119 @@ static void CloseFilter( vlc_object_t *p_this ) static picture_t *Filter( filter_t *p_filter, picture_t *p_pic ) { picture_t *p_pic_dst; - int i_plane, i, j, k, l; + int i_plane; if( !p_pic ) return NULL; + if( (p_filter->fmt_in.video.i_height == 0) || + (p_filter->fmt_in.video.i_width == 0) ) + return NULL; + + if( (p_filter->fmt_out.video.i_height == 0) || + (p_filter->fmt_out.video.i_width == 0) ) + return NULL; + /* Request output picture */ - p_pic_dst = p_filter->pf_vout_buffer_new( p_filter ); + p_pic_dst = filter_NewPicture( p_filter ); if( !p_pic_dst ) { - msg_Warn( p_filter, "can't get output picture" ); - if( p_pic->pf_release ) - p_pic->pf_release( p_pic ); + picture_Release( p_pic ); return NULL; } - if( p_filter->fmt_in.video.i_chroma == VLC_FOURCC('Y','U','V','P') || - p_filter->fmt_in.video.i_chroma == VLC_FOURCC('Y','U','V','A') ) + if( p_filter->fmt_in.video.i_chroma != VLC_FOURCC('R','G','B','A') && + p_filter->fmt_in.video.i_chroma != VLC_FOURCC('R','V','3','2') ) { for( i_plane = 0; i_plane < p_pic_dst->i_planes; i_plane++ ) { + const int i_src_pitch = p_pic->p[i_plane].i_pitch; + const int i_dst_pitch = p_pic_dst->p[i_plane].i_pitch; + const int i_src_height = p_filter->fmt_in.video.i_height; + const int i_src_width = p_filter->fmt_in.video.i_width; + const int i_dst_height = p_filter->fmt_out.video.i_height; + const int i_dst_width = p_filter->fmt_out.video.i_width; + const int i_dst_visible_lines = + p_pic_dst->p[i_plane].i_visible_lines; + const int i_dst_visible_pitch = + p_pic_dst->p[i_plane].i_visible_pitch; + const int i_dst_hidden_pitch = i_dst_pitch - i_dst_visible_pitch; +#define SHIFT_SIZE 16 + const int i_height_coef = ( i_src_height << SHIFT_SIZE ) + / i_dst_height; + const int i_width_coef = ( i_src_width << SHIFT_SIZE ) + / i_dst_width; + const int i_src_height_1 = i_src_height - 1; + const int i_src_width_1 = i_src_width - 1; + uint8_t *p_src = p_pic->p[i_plane].p_pixels; uint8_t *p_dst = p_pic_dst->p[i_plane].p_pixels; - int i_src_pitch = p_pic->p[i_plane].i_pitch; - int i_dst_pitch = p_pic_dst->p[i_plane].i_pitch; + uint8_t *p_dstendline = p_dst + i_dst_visible_pitch; + const uint8_t *p_dstend = p_dst + i_dst_visible_lines*i_dst_pitch; - for( i = 0; i < p_pic_dst->p[i_plane].i_visible_lines; i++ ) - { - l = ( p_filter->fmt_in.video.i_height * i + - p_filter->fmt_out.video.i_height / 2 ) / - p_filter->fmt_out.video.i_height; + const int i_shift_height = i_dst_height / i_src_height; + const int i_shift_width = i_dst_width / i_src_width; - l = __MIN( (int)p_filter->fmt_in.video.i_height - 1, l ); + int l = 1<<(SHIFT_SIZE-i_shift_height); + for( ; p_dst < p_dstend; + p_dst += i_dst_hidden_pitch, + p_dstendline += i_dst_pitch, l += i_height_coef ) + { + int k = 1<<(SHIFT_SIZE-i_shift_width); + uint8_t *p_srcl = p_src + + (__MIN( i_src_height_1, l >> SHIFT_SIZE )*i_src_pitch); - for( j = 0; j < p_pic_dst->p[i_plane].i_visible_pitch; j++ ) + for( ; p_dst < p_dstendline; p_dst++, k += i_width_coef ) { - k = ( p_filter->fmt_in.video.i_width * j + - p_filter->fmt_out.video.i_width / 2 ) / - p_filter->fmt_out.video.i_width; - - k = __MIN( (int)p_filter->fmt_in.video.i_width - 1, k ); - - p_dst[i * i_dst_pitch + j] = p_src[l * i_src_pitch + k]; + *p_dst = p_srcl[__MIN( i_src_width_1, k >> SHIFT_SIZE )]; } } } } else /* RGBA */ { - uint8_t *p_src = p_pic->p->p_pixels; - uint8_t *p_dst = p_pic_dst->p->p_pixels; - int i_src_pitch = p_pic->p->i_pitch; - int i_dst_pitch = p_pic_dst->p->i_pitch; - for( i = 0; i < p_pic_dst->p->i_visible_lines; i++ ) + const int i_src_pitch = p_pic->p->i_pitch; + const int i_dst_pitch = p_pic_dst->p->i_pitch; + const int i_src_height = p_filter->fmt_in.video.i_height; + const int i_src_width = p_filter->fmt_in.video.i_width; + const int i_dst_height = p_filter->fmt_out.video.i_height; + const int i_dst_width = p_filter->fmt_out.video.i_width; + const int i_dst_visible_lines = + p_pic_dst->p->i_visible_lines; + const int i_dst_visible_pitch = + p_pic_dst->p->i_visible_pitch; + const int i_dst_hidden_pitch = i_dst_pitch - i_dst_visible_pitch; + const int i_height_coef = ( i_src_height << SHIFT_SIZE ) + / i_dst_height; + const int i_width_coef = ( i_src_width << SHIFT_SIZE ) + / i_dst_width; + const int i_src_height_1 = i_src_height - 1; + const int i_src_width_1 = i_src_width - 1; + + uint32_t *p_src = (uint32_t*)p_pic->p->p_pixels; + uint32_t *p_dst = (uint32_t*)p_pic_dst->p->p_pixels; + uint32_t *p_dstendline = p_dst + (i_dst_visible_pitch>>2); + const uint32_t *p_dstend = p_dst + i_dst_visible_lines*(i_dst_pitch>>2); + + const int i_shift_height = i_dst_height / i_src_height; + const int i_shift_width = i_dst_width / i_src_width; + + int l = 1<<(SHIFT_SIZE-i_shift_height); + for( ; p_dst < p_dstend; + p_dst += (i_dst_hidden_pitch>>2), + p_dstendline += (i_dst_pitch>>2), + l += i_height_coef ) { - l = ( p_filter->fmt_in.video.i_height * i + - p_filter->fmt_out.video.i_height / 2 ) / - p_filter->fmt_out.video.i_height; - - l = __MIN( (int)p_filter->fmt_in.video.i_height - 1, l ); - - for( j = 0; j < p_pic_dst->p->i_visible_pitch/4; j++ ) + int k = 1<<(SHIFT_SIZE-i_shift_width); + uint32_t *p_srcl = p_src + + (__MIN( i_src_height_1, l >> SHIFT_SIZE )*(i_src_pitch>>2)); + for( ; p_dst < p_dstendline; p_dst++, k += i_width_coef ) { - k = ( p_filter->fmt_in.video.i_width * j + - p_filter->fmt_out.video.i_width / 2 ) / - p_filter->fmt_out.video.i_width; - - k = __MIN( (int)p_filter->fmt_in.video.i_width - 1, k ); - - *(uint32_t*)(&p_dst[i * i_dst_pitch + 4*j]) = - *(uint32_t*)(&p_src[l * i_src_pitch + 4*k]); + *p_dst = p_srcl[__MIN( i_src_width_1, k >> SHIFT_SIZE )]; } } } - p_pic_dst->date = p_pic->date; - p_pic_dst->b_force = p_pic->b_force; - p_pic_dst->i_nb_fields = p_pic->i_nb_fields; - p_pic_dst->b_progressive = p_pic->b_progressive; - p_pic_dst->b_top_field_first = p_pic->b_top_field_first; - - p_pic->pf_release( p_pic ); + picture_CopyProperties( p_pic_dst, p_pic ); + picture_Release( p_pic ); return p_pic_dst; }