]> git.sesse.net Git - vlc/blob - modules/video_filter/wave.c
Use gettext_noop() consistently
[vlc] / modules / video_filter / wave.c
1 /*****************************************************************************
2  * wave.c : Wave video effect plugin for vlc
3  *****************************************************************************
4  * Copyright (C) 2000-2006 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Samuel Hocevar <sam@zoy.org>
8  *          Antoine Cellerier <dionoea -at- videolan -dot- org>
9  *
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.
14  *
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.
19  *
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  *****************************************************************************/
24
25 /*****************************************************************************
26  * Preamble
27  *****************************************************************************/
28
29 #include <math.h>                                            /* sin(), cos() */
30
31 #ifdef HAVE_CONFIG_H
32 # include "config.h"
33 #endif
34
35 #include <vlc/vlc.h>
36 #include <vlc_plugin.h>
37 #include <vlc_vout.h>
38
39 #include "vlc_filter.h"
40
41 /*****************************************************************************
42  * Local prototypes
43  *****************************************************************************/
44 static int  Create    ( vlc_object_t * );
45 static void Destroy   ( vlc_object_t * );
46
47 static picture_t *Filter( filter_t *, picture_t * );
48
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 filter2", 0 );
56     set_category( CAT_VIDEO );
57     set_subcategory( SUBCAT_VIDEO_VFILTER );
58
59     add_shortcut( "wave" );
60     set_callbacks( Create, Destroy );
61 vlc_module_end();
62
63 /*****************************************************************************
64  * vout_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
70 {
71     double  f_angle;
72     mtime_t last_date;
73 };
74
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 )
81 {
82     filter_t *p_filter = (filter_t *)p_this;
83
84     /* Allocate structure */
85     p_filter->p_sys = malloc( sizeof( filter_sys_t ) );
86     if( p_filter->p_sys == NULL )
87     {
88         msg_Err( p_filter, "out of memory" );
89         return VLC_ENOMEM;
90     }
91
92     p_filter->pf_video_filter = Filter;
93
94     p_filter->p_sys->f_angle = 0.0;
95     p_filter->p_sys->last_date = 0;
96
97     return VLC_SUCCESS;
98 }
99
100 /*****************************************************************************
101  * Destroy: destroy Distort video thread output method
102  *****************************************************************************
103  * Terminate an output method created by DistortCreateOutputMethod
104  *****************************************************************************/
105 static void Destroy( vlc_object_t *p_this )
106 {
107     filter_t *p_filter = (filter_t *)p_this;
108     free( p_filter->p_sys );
109 }
110
111 /*****************************************************************************
112  * Render: displays previously rendered output
113  *****************************************************************************
114  * This function send the currently rendered image to Distort image, waits
115  * until it is displayed and switch the two rendering buffers, preparing next
116  * frame.
117  *****************************************************************************/
118 static picture_t *Filter( filter_t *p_filter, picture_t *p_pic )
119 {
120     picture_t *p_outpic;
121     int i_index;
122     double f_angle;
123     mtime_t new_date = mdate();
124
125     if( !p_pic ) return NULL;
126
127     p_outpic = p_filter->pf_vout_buffer_new( p_filter );
128     if( !p_outpic )
129     {
130         msg_Warn( p_filter, "can't get output picture" );
131         if( p_pic->pf_release )
132             p_pic->pf_release( p_pic );
133         return NULL;
134     }
135
136     p_filter->p_sys->f_angle += (new_date - p_filter->p_sys->last_date) / 200000.0;
137     p_filter->p_sys->last_date = new_date;
138     f_angle = p_filter->p_sys->f_angle;
139
140     for( i_index = 0 ; i_index < p_pic->i_planes ; i_index++ )
141     {
142         int i_line, i_num_lines, i_visible_pitch, i_pixel_pitch, i_offset,
143             i_visible_pixels;
144         uint8_t black_pixel;
145         uint8_t *p_in, *p_out;
146
147         p_in = p_pic->p[i_index].p_pixels;
148         p_out = p_outpic->p[i_index].p_pixels;
149
150         i_num_lines = p_pic->p[i_index].i_visible_lines;
151         i_visible_pitch = p_pic->p[i_index].i_visible_pitch;
152         i_pixel_pitch = p_pic->p[i_index].i_pixel_pitch;
153         i_visible_pixels = i_visible_pitch/i_pixel_pitch;
154
155         black_pixel = ( i_index == Y_PLANE ) ? 0x00 : 0x80;
156
157         /* Ok, we do 3 times the sin() calculation for each line. So what ? */
158         for( i_line = 0 ; i_line < i_num_lines ; i_line++ )
159         {
160             /* Calculate today's offset, don't go above 1/20th of the screen */
161             i_offset = (int)( (double)(i_visible_pixels)
162                          * sin( f_angle + 10.0 * (double)i_line
163                                                / (double)i_num_lines )
164                          / 20.0 )*i_pixel_pitch;
165
166             if( i_offset )
167             {
168                 if( i_offset < 0 )
169                 {
170                     vlc_memcpy( p_out, p_in - i_offset,
171                                 i_visible_pitch + i_offset );
172                     p_in += p_pic->p[i_index].i_pitch;
173                     p_out += p_outpic->p[i_index].i_pitch;
174                     vlc_memset( p_out + i_offset, black_pixel, -i_offset );
175                 }
176                 else
177                 {
178                     vlc_memcpy( p_out + i_offset, p_in,
179                                 i_visible_pitch - i_offset );
180                     vlc_memset( p_out, black_pixel, i_offset );
181                     p_in += p_pic->p[i_index].i_pitch;
182                     p_out += p_outpic->p[i_index].i_pitch;
183                 }
184             }
185             else
186             {
187                 vlc_memcpy( p_out, p_in, i_visible_pitch );
188                 p_in += p_pic->p[i_index].i_pitch;
189                 p_out += p_outpic->p[i_index].i_pitch;
190             }
191
192         }
193     }
194
195     p_outpic->date = p_pic->date;
196     p_outpic->b_force = p_pic->b_force;
197     p_outpic->i_nb_fields = p_pic->i_nb_fields;
198     p_outpic->b_progressive = p_pic->b_progressive;
199     p_outpic->b_top_field_first = p_pic->b_top_field_first;
200
201     if( p_pic->pf_release )
202         p_pic->pf_release( p_pic );
203
204     return p_outpic;
205 }