1 /*****************************************************************************
2 * resize.c: video scaling module for YUVP/A pictures
3 * Uses the low quality "nearest neighbour" algorithm.
4 *****************************************************************************
5 * Copyright (C) 2003 the VideoLAN team
8 * Author: Gildas Bazin <gbazin@videolan.org>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
25 /*****************************************************************************
27 *****************************************************************************/
29 #include <vlc/decoder.h>
30 #include "vlc_filter.h"
32 /*****************************************************************************
33 * filter_sys_t : filter descriptor
34 *****************************************************************************/
41 /****************************************************************************
43 ****************************************************************************/
44 static int OpenFilter ( vlc_object_t * );
45 static void CloseFilter( vlc_object_t * );
47 static picture_t *Filter( filter_t *, picture_t * );
49 /*****************************************************************************
51 *****************************************************************************/
53 set_description( _("Video scaling filter") );
54 set_capability( "video filter2", 10000 );
55 set_category( CAT_VIDEO );
56 set_subcategory( SUBCAT_VIDEO_VFILTER );
57 set_callbacks( OpenFilter, CloseFilter );
60 /*****************************************************************************
61 * OpenFilter: probe the filter and return score
62 *****************************************************************************/
63 static int OpenFilter( vlc_object_t *p_this )
65 filter_t *p_filter = (filter_t*)p_this;
68 if( ( p_filter->fmt_in.video.i_chroma != VLC_FOURCC('Y','U','V','P') &&
69 p_filter->fmt_in.video.i_chroma != VLC_FOURCC('Y','U','V','A') ) ||
70 p_filter->fmt_in.video.i_chroma != p_filter->fmt_out.video.i_chroma )
75 /* Allocate the memory needed to store the decoder's structure */
76 if( ( p_filter->p_sys = p_sys =
77 (filter_sys_t *)malloc(sizeof(filter_sys_t)) ) == NULL )
79 msg_Err( p_filter, "out of memory" );
83 p_filter->pf_video_filter = Filter;
85 msg_Dbg( p_filter, "%ix%i -> %ix%i", p_filter->fmt_in.video.i_width,
86 p_filter->fmt_in.video.i_height, p_filter->fmt_out.video.i_width,
87 p_filter->fmt_out.video.i_height );
92 /*****************************************************************************
93 * CloseFilter: clean up the filter
94 *****************************************************************************/
95 static void CloseFilter( vlc_object_t *p_this )
97 filter_t *p_filter = (filter_t*)p_this;
98 filter_sys_t *p_sys = p_filter->p_sys;
103 /****************************************************************************
104 * Filter: the whole thing
105 ****************************************************************************/
106 static picture_t *Filter( filter_t *p_filter, picture_t *p_pic )
108 picture_t *p_pic_dst;
109 int i_plane, i, j, k, l;
111 if( !p_pic ) return NULL;
113 /* Request output picture */
114 p_pic_dst = p_filter->pf_vout_buffer_new( p_filter );
117 msg_Warn( p_filter, "can't get output picture" );
118 if( p_pic->pf_release )
119 p_pic->pf_release( p_pic );
123 for( i_plane = 0; i_plane < p_pic_dst->i_planes; i_plane++ )
125 uint8_t *p_src = p_pic->p[i_plane].p_pixels;
126 uint8_t *p_dst = p_pic_dst->p[i_plane].p_pixels;
127 int i_src_pitch = p_pic->p[i_plane].i_pitch;
128 int i_dst_pitch = p_pic_dst->p[i_plane].i_pitch;
130 for( i = 0; i < p_pic_dst->p[i_plane].i_visible_lines; i++ )
132 l = ( p_filter->fmt_in.video.i_height * i +
133 p_filter->fmt_out.video.i_height / 2 ) /
134 p_filter->fmt_out.video.i_height;
136 l = __MIN( (int)p_filter->fmt_in.video.i_height - 1, l );
138 for( j = 0; j < p_pic_dst->p[i_plane].i_visible_pitch; j++ )
140 k = ( p_filter->fmt_in.video.i_width * j +
141 p_filter->fmt_out.video.i_width / 2 ) /
142 p_filter->fmt_out.video.i_width;
144 k = __MIN( (int)p_filter->fmt_in.video.i_width - 1, k );
146 p_dst[i * i_dst_pitch + j] = p_src[l * i_src_pitch + k];
151 p_pic_dst->date = p_pic->date;
152 p_pic_dst->b_force = p_pic->b_force;
153 p_pic_dst->i_nb_fields = p_pic->i_nb_fields;
154 p_pic_dst->b_progressive = p_pic->b_progressive;
155 p_pic_dst->b_top_field_first = p_pic->b_top_field_first;
157 p_pic->pf_release( p_pic );