libass: fix compilation with older versions of libass
[vlc.git] / modules / video_filter / wave.c
blob8fce37128b52b7fcd699141402a915c24725c0b7
1 /*****************************************************************************
2 * wave.c : Wave video effect plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2000-2008 VLC authors and VideoLAN
5 * $Id$
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 it
11 * under the terms of the GNU Lesser General Public License as published by
12 * the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public License
21 * along with this program; if not, write to the Free Software Foundation,
22 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
25 /*****************************************************************************
26 * Preamble
27 *****************************************************************************/
29 #ifdef HAVE_CONFIG_H
30 # include "config.h"
31 #endif
33 #include <math.h> /* sin(), cos() */
35 #include <vlc_common.h>
36 #include <vlc_plugin.h>
37 #include <vlc_filter.h>
38 #include <vlc_picture.h>
39 #include "filter_picture.h"
41 /*****************************************************************************
42 * Local prototypes
43 *****************************************************************************/
44 static int Create ( vlc_object_t * );
45 static void Destroy ( vlc_object_t * );
47 static picture_t *Filter( filter_t *, picture_t * );
49 /*****************************************************************************
50 * Module descriptor
51 *****************************************************************************/
52 vlc_module_begin ()
53 set_description( N_("Wave video filter") )
54 set_shortname( N_( "Wave" ))
55 set_capability( "video filter", 0 )
56 set_category( CAT_VIDEO )
57 set_subcategory( SUBCAT_VIDEO_VFILTER )
59 add_shortcut( "wave" )
60 set_callbacks( Create, Destroy )
61 vlc_module_end ()
63 /*****************************************************************************
64 * filter_sys_t: Distort video output method descriptor
65 *****************************************************************************
66 * This structure is part of the video output thread descriptor.
67 * It describes the Distort specific properties of an output thread.
68 *****************************************************************************/
69 struct filter_sys_t
71 double f_angle;
72 mtime_t last_date;
75 /*****************************************************************************
76 * Create: allocates Distort video thread output method
77 *****************************************************************************
78 * This function allocates and initializes a Distort vout method.
79 *****************************************************************************/
80 static int Create( vlc_object_t *p_this )
82 filter_t *p_filter = (filter_t *)p_this;
84 const vlc_chroma_description_t *p_chroma =
85 vlc_fourcc_GetChromaDescription( p_filter->fmt_in.video.i_chroma );
86 if( p_chroma == NULL || p_chroma->plane_count == 0 )
87 return VLC_EGENERIC;
89 /* Allocate structure */
90 p_filter->p_sys = malloc( sizeof( filter_sys_t ) );
91 if( p_filter->p_sys == NULL )
92 return VLC_ENOMEM;
94 p_filter->pf_video_filter = Filter;
96 p_filter->p_sys->f_angle = 0.0;
97 p_filter->p_sys->last_date = 0;
99 return VLC_SUCCESS;
102 /*****************************************************************************
103 * Destroy: destroy Distort video thread output method
104 *****************************************************************************
105 * Terminate an output method created by DistortCreateOutputMethod
106 *****************************************************************************/
107 static void Destroy( vlc_object_t *p_this )
109 filter_t *p_filter = (filter_t *)p_this;
110 free( p_filter->p_sys );
113 /*****************************************************************************
114 * Render: displays previously rendered output
115 *****************************************************************************
116 * This function send the currently rendered image to Distort image, waits
117 * until it is displayed and switch the two rendering buffers, preparing next
118 * frame.
119 *****************************************************************************/
120 static picture_t *Filter( filter_t *p_filter, picture_t *p_pic )
122 picture_t *p_outpic;
123 double f_angle;
124 mtime_t new_date = mdate();
126 if( !p_pic ) return NULL;
128 p_outpic = filter_NewPicture( p_filter );
129 if( !p_outpic )
131 picture_Release( p_pic );
132 return NULL;
135 p_filter->p_sys->f_angle += (new_date - p_filter->p_sys->last_date) / 200000.0;
136 p_filter->p_sys->last_date = new_date;
137 f_angle = p_filter->p_sys->f_angle;
139 for( int i_index = 0 ; i_index < p_pic->i_planes ; i_index++ )
141 int i_num_lines, i_visible_pitch, i_pixel_pitch, i_offset,
142 i_visible_pixels;
143 uint8_t black_pixel;
144 uint8_t *p_in, *p_out;
146 p_in = p_pic->p[i_index].p_pixels;
147 p_out = p_outpic->p[i_index].p_pixels;
149 i_num_lines = p_pic->p[i_index].i_visible_lines;
150 i_visible_pitch = p_pic->p[i_index].i_visible_pitch;
151 i_pixel_pitch = p_pic->p[i_index].i_pixel_pitch;
152 switch( p_filter->fmt_in.video.i_chroma )
154 CASE_PACKED_YUV_422
155 // Quick hack to fix u/v inversion occuring with 2 byte pixel pitch
156 i_pixel_pitch *= 2;
157 break;
159 i_visible_pixels = i_visible_pitch/i_pixel_pitch;
161 black_pixel = ( p_pic->i_planes > 1 && i_index == Y_PLANE ) ? 0x00
162 : 0x80;
164 /* Ok, we do 3 times the sin() calculation for each line. So what ? */
165 for( int i_line = 0 ; i_line < i_num_lines ; i_line++ )
167 /* Calculate today's offset, don't go above 1/20th of the screen */
168 i_offset = (int)( (double)(i_visible_pixels)
169 * sin( f_angle + 10.0 * (double)i_line
170 / (double)i_num_lines )
171 / 20.0 )*i_pixel_pitch;
173 if( i_offset )
175 if( i_offset < 0 )
177 memcpy( p_out, p_in - i_offset,
178 i_visible_pitch + i_offset );
179 p_in += p_pic->p[i_index].i_pitch;
180 p_out += p_outpic->p[i_index].i_pitch;
181 memset( p_out + i_offset, black_pixel, -i_offset );
183 else
185 memcpy( p_out + i_offset, p_in,
186 i_visible_pitch - i_offset );
187 memset( p_out, black_pixel, i_offset );
188 p_in += p_pic->p[i_index].i_pitch;
189 p_out += p_outpic->p[i_index].i_pitch;
192 else
194 memcpy( p_out, p_in, i_visible_pitch );
195 p_in += p_pic->p[i_index].i_pitch;
196 p_out += p_outpic->p[i_index].i_pitch;
202 return CopyInfoAndRelease( p_outpic, p_pic );