2004-09-15 18:02:45 +02:00
|
|
|
/*****************************************************************************
|
2007-04-19 19:43:16 +02:00
|
|
|
* resize.c: video scaling module for YUVP/A, I420 and RGBA pictures
|
2004-09-15 18:02:45 +02:00
|
|
|
* Uses the low quality "nearest neighbour" algorithm.
|
|
|
|
*****************************************************************************
|
2007-04-19 19:43:16 +02:00
|
|
|
* Copyright (C) 2003-2007 the VideoLAN team
|
2004-09-15 18:02:45 +02:00
|
|
|
* $Id$
|
|
|
|
*
|
2007-04-19 19:43:16 +02:00
|
|
|
* Authors: Gildas Bazin <gbazin@videolan.org>
|
|
|
|
* Antoine Cellerier <dionoea @t videolan dot org>
|
2004-09-15 18:02:45 +02:00
|
|
|
*
|
|
|
|
* 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
|
2006-01-13 00:10:04 +01:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
|
2004-09-15 18:02:45 +02:00
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
* Preamble
|
|
|
|
*****************************************************************************/
|
|
|
|
#include <vlc/vlc.h>
|
2006-11-26 15:20:34 +01:00
|
|
|
#include <vlc_vout.h>
|
2004-09-15 18:02:45 +02:00
|
|
|
#include "vlc_filter.h"
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
* filter_sys_t : filter descriptor
|
|
|
|
*****************************************************************************/
|
|
|
|
struct filter_sys_t
|
|
|
|
{
|
|
|
|
es_format_t fmt_in;
|
|
|
|
es_format_t fmt_out;
|
|
|
|
};
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Local prototypes
|
|
|
|
****************************************************************************/
|
|
|
|
static int OpenFilter ( vlc_object_t * );
|
|
|
|
static void CloseFilter( vlc_object_t * );
|
|
|
|
|
|
|
|
static picture_t *Filter( filter_t *, picture_t * );
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
* Module descriptor
|
|
|
|
*****************************************************************************/
|
|
|
|
vlc_module_begin();
|
|
|
|
set_description( _("Video scaling filter") );
|
|
|
|
set_capability( "video filter2", 10000 );
|
2006-07-16 23:22:31 +02:00
|
|
|
// set_category( CAT_VIDEO );
|
|
|
|
// set_subcategory( SUBCAT_VIDEO_VFILTER2 );
|
2004-09-15 18:02:45 +02:00
|
|
|
set_callbacks( OpenFilter, CloseFilter );
|
|
|
|
vlc_module_end();
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
* OpenFilter: probe the filter and return score
|
|
|
|
*****************************************************************************/
|
|
|
|
static int OpenFilter( vlc_object_t *p_this )
|
|
|
|
{
|
|
|
|
filter_t *p_filter = (filter_t*)p_this;
|
|
|
|
filter_sys_t *p_sys;
|
|
|
|
|
|
|
|
if( ( p_filter->fmt_in.video.i_chroma != VLC_FOURCC('Y','U','V','P') &&
|
2007-03-31 18:02:28 +02:00
|
|
|
p_filter->fmt_in.video.i_chroma != VLC_FOURCC('Y','U','V','A') &&
|
2007-04-02 18:24:23 +02:00
|
|
|
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') &&
|
2007-03-31 18:02:28 +02:00
|
|
|
p_filter->fmt_in.video.i_chroma != VLC_FOURCC('R','G','B','A') ) ||
|
2004-09-15 18:02:45 +02:00
|
|
|
p_filter->fmt_in.video.i_chroma != p_filter->fmt_out.video.i_chroma )
|
|
|
|
{
|
|
|
|
return VLC_EGENERIC;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
p_filter->pf_video_filter = Filter;
|
|
|
|
|
|
|
|
msg_Dbg( p_filter, "%ix%i -> %ix%i", p_filter->fmt_in.video.i_width,
|
|
|
|
p_filter->fmt_in.video.i_height, p_filter->fmt_out.video.i_width,
|
|
|
|
p_filter->fmt_out.video.i_height );
|
|
|
|
|
|
|
|
return VLC_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
* CloseFilter: clean up the filter
|
|
|
|
*****************************************************************************/
|
|
|
|
static void CloseFilter( vlc_object_t *p_this )
|
|
|
|
{
|
|
|
|
filter_t *p_filter = (filter_t*)p_this;
|
|
|
|
filter_sys_t *p_sys = p_filter->p_sys;
|
|
|
|
|
|
|
|
free( p_sys );
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Filter: the whole thing
|
|
|
|
****************************************************************************/
|
|
|
|
static picture_t *Filter( filter_t *p_filter, picture_t *p_pic )
|
|
|
|
{
|
|
|
|
picture_t *p_pic_dst;
|
2007-04-19 19:43:16 +02:00
|
|
|
int i_plane;
|
2004-09-15 18:02:45 +02:00
|
|
|
|
2005-08-23 19:58:55 +02:00
|
|
|
if( !p_pic ) return NULL;
|
2007-03-31 18:02:28 +02:00
|
|
|
|
2004-09-15 18:02:45 +02:00
|
|
|
/* Request output picture */
|
|
|
|
p_pic_dst = p_filter->pf_vout_buffer_new( p_filter );
|
|
|
|
if( !p_pic_dst )
|
|
|
|
{
|
|
|
|
msg_Warn( p_filter, "can't get output picture" );
|
2005-02-04 17:13:11 +01:00
|
|
|
if( p_pic->pf_release )
|
|
|
|
p_pic->pf_release( p_pic );
|
2004-09-15 18:02:45 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2007-04-02 18:24:23 +02:00
|
|
|
if( p_filter->fmt_in.video.i_chroma != VLC_FOURCC('R','G','B','A') )
|
2004-09-15 18:02:45 +02:00
|
|
|
{
|
2007-03-31 18:02:28 +02:00
|
|
|
for( i_plane = 0; i_plane < p_pic_dst->i_planes; i_plane++ )
|
|
|
|
{
|
2007-04-19 19:43:16 +02:00
|
|
|
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;
|
|
|
|
|
2007-03-31 18:02:28 +02:00
|
|
|
uint8_t *p_src = p_pic->p[i_plane].p_pixels;
|
|
|
|
uint8_t *p_dst = p_pic_dst->p[i_plane].p_pixels;
|
2007-04-19 19:43:16 +02:00
|
|
|
uint8_t *p_dstendline = p_dst + i_dst_visible_pitch;
|
|
|
|
const uint8_t *p_dstend = p_dst + i_dst_visible_lines*i_dst_pitch;
|
2007-03-31 18:02:28 +02:00
|
|
|
|
2007-04-19 19:43:16 +02:00
|
|
|
int l = 1<<(SHIFT_SIZE-1);
|
|
|
|
for( ; p_dst < p_dstend;
|
|
|
|
p_dst += i_dst_hidden_pitch,
|
|
|
|
p_dstendline += i_dst_pitch, l += i_height_coef )
|
2007-03-31 18:02:28 +02:00
|
|
|
{
|
2007-04-19 19:43:16 +02:00
|
|
|
int k = 1<<(SHIFT_SIZE-1);
|
|
|
|
uint8_t *p_srcl = p_src
|
|
|
|
+ (__MIN( i_src_height_1, l >> SHIFT_SIZE )*i_src_pitch);
|
2007-03-31 18:02:28 +02:00
|
|
|
|
2007-04-19 19:43:16 +02:00
|
|
|
for( ; p_dst < p_dstendline; p_dst++, k += i_width_coef )
|
2007-03-31 18:02:28 +02:00
|
|
|
{
|
2007-04-19 19:43:16 +02:00
|
|
|
*p_dst = p_srcl[__MIN( i_src_width_1, k >> SHIFT_SIZE )];
|
2007-03-31 18:02:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else /* RGBA */
|
|
|
|
{
|
2007-04-19 19:43:16 +02:00
|
|
|
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);
|
|
|
|
|
|
|
|
int l = 1<<(SHIFT_SIZE-1);
|
|
|
|
for( ; p_dst < p_dstend;
|
|
|
|
p_dst += (i_dst_hidden_pitch>>2),
|
|
|
|
p_dstendline += (i_dst_pitch>>2),
|
|
|
|
l += i_height_coef )
|
2004-09-15 18:02:45 +02:00
|
|
|
{
|
2007-04-19 19:43:16 +02:00
|
|
|
int k = 1<<(SHIFT_SIZE-1);
|
|
|
|
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 )
|
2004-09-15 18:02:45 +02:00
|
|
|
{
|
2007-04-19 19:43:16 +02:00
|
|
|
*p_dst = p_srcl[__MIN( i_src_width_1, k >> SHIFT_SIZE )];
|
2004-09-15 18:02:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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 );
|
|
|
|
return p_pic_dst;
|
|
|
|
}
|