1 /*****************************************************************************
2 * wave.c : Wave video effect plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2000-2008 the VideoLAN team
7 * Authors: Samuel Hocevar <sam@zoy.org>
8 * Antoine Cellerier <dionoea -at- videolan -dot- 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 <math.h> /* sin(), cos() */
35 #include <vlc_common.h>
36 #include <vlc_plugin.h>
39 #include "vlc_filter.h"
40 #include "filter_picture.h"
42 /*****************************************************************************
44 *****************************************************************************/
45 static int Create ( vlc_object_t * );
46 static void Destroy ( vlc_object_t * );
48 static picture_t *Filter( filter_t *, picture_t * );
50 /*****************************************************************************
52 *****************************************************************************/
54 set_description( N_("Wave video filter") );
55 set_shortname( N_( "Wave" ));
56 set_capability( "video filter2", 0 );
57 set_category( CAT_VIDEO );
58 set_subcategory( SUBCAT_VIDEO_VFILTER );
60 add_shortcut( "wave" );
61 set_callbacks( Create, Destroy );
64 /*****************************************************************************
65 * vout_sys_t: Distort video output method descriptor
66 *****************************************************************************
67 * This structure is part of the video output thread descriptor.
68 * It describes the Distort specific properties of an output thread.
69 *****************************************************************************/
76 /*****************************************************************************
77 * Create: allocates Distort video thread output method
78 *****************************************************************************
79 * This function allocates and initializes a Distort vout method.
80 *****************************************************************************/
81 static int Create( vlc_object_t *p_this )
83 filter_t *p_filter = (filter_t *)p_this;
85 /* Allocate structure */
86 p_filter->p_sys = malloc( sizeof( filter_sys_t ) );
87 if( p_filter->p_sys == NULL )
89 msg_Err( p_filter, "out of memory" );
93 p_filter->pf_video_filter = Filter;
95 p_filter->p_sys->f_angle = 0.0;
96 p_filter->p_sys->last_date = 0;
101 /*****************************************************************************
102 * Destroy: destroy Distort video thread output method
103 *****************************************************************************
104 * Terminate an output method created by DistortCreateOutputMethod
105 *****************************************************************************/
106 static void Destroy( vlc_object_t *p_this )
108 filter_t *p_filter = (filter_t *)p_this;
109 free( p_filter->p_sys );
112 /*****************************************************************************
113 * Render: displays previously rendered output
114 *****************************************************************************
115 * This function send the currently rendered image to Distort image, waits
116 * until it is displayed and switch the two rendering buffers, preparing next
118 *****************************************************************************/
119 static picture_t *Filter( filter_t *p_filter, picture_t *p_pic )
124 mtime_t new_date = mdate();
126 if( !p_pic ) return NULL;
128 p_outpic = p_filter->pf_vout_buffer_new( p_filter );
131 msg_Warn( p_filter, "can't get output picture" );
132 if( p_pic->pf_release )
133 p_pic->pf_release( p_pic );
137 p_filter->p_sys->f_angle += (new_date - p_filter->p_sys->last_date) / 200000.0;
138 p_filter->p_sys->last_date = new_date;
139 f_angle = p_filter->p_sys->f_angle;
141 for( i_index = 0 ; i_index < p_pic->i_planes ; i_index++ )
143 int i_line, i_num_lines, i_visible_pitch, i_pixel_pitch, i_offset,
146 uint8_t *p_in, *p_out;
148 p_in = p_pic->p[i_index].p_pixels;
149 p_out = p_outpic->p[i_index].p_pixels;
151 i_num_lines = p_pic->p[i_index].i_visible_lines;
152 i_visible_pitch = p_pic->p[i_index].i_visible_pitch;
153 i_pixel_pitch = p_pic->p[i_index].i_pixel_pitch;
154 i_visible_pixels = i_visible_pitch/i_pixel_pitch;
156 black_pixel = ( p_pic->i_planes > 1 && i_index == Y_PLANE ) ? 0x00
159 /* Ok, we do 3 times the sin() calculation for each line. So what ? */
160 for( i_line = 0 ; i_line < i_num_lines ; i_line++ )
162 /* Calculate today's offset, don't go above 1/20th of the screen */
163 i_offset = (int)( (double)(i_visible_pixels)
164 * sin( f_angle + 10.0 * (double)i_line
165 / (double)i_num_lines )
166 / 20.0 )*i_pixel_pitch;
172 vlc_memcpy( p_out, p_in - i_offset,
173 i_visible_pitch + i_offset );
174 p_in += p_pic->p[i_index].i_pitch;
175 p_out += p_outpic->p[i_index].i_pitch;
176 vlc_memset( p_out + i_offset, black_pixel, -i_offset );
180 vlc_memcpy( p_out + i_offset, p_in,
181 i_visible_pitch - i_offset );
182 vlc_memset( p_out, black_pixel, i_offset );
183 p_in += p_pic->p[i_index].i_pitch;
184 p_out += p_outpic->p[i_index].i_pitch;
189 vlc_memcpy( p_out, p_in, i_visible_pitch );
190 p_in += p_pic->p[i_index].i_pitch;
191 p_out += p_outpic->p[i_index].i_pitch;
197 return CopyInfoAndRelease( p_outpic, p_pic );