]> git.sesse.net Git - vlc/blob - modules/video_filter/wave.c
macosx: fixed menubar appearance in fullscreen mode by partially reverting [46c93c9cc...
[vlc] / modules / video_filter / wave.c
1 /*****************************************************************************
2  * wave.c : Wave video effect plugin for vlc
3  *****************************************************************************
4  * Copyright (C) 2000-2008 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 #ifdef HAVE_CONFIG_H
30 # include "config.h"
31 #endif
32
33 #include <math.h>                                            /* sin(), cos() */
34
35 #include <vlc_common.h>
36 #include <vlc_plugin.h>
37 #include <vlc_vout.h>
38
39 #include "vlc_filter.h"
40 #include "filter_picture.h"
41
42 /*****************************************************************************
43  * Local prototypes
44  *****************************************************************************/
45 static int  Create    ( vlc_object_t * );
46 static void Destroy   ( vlc_object_t * );
47
48 static picture_t *Filter( filter_t *, picture_t * );
49
50 /*****************************************************************************
51  * Module descriptor
52  *****************************************************************************/
53 vlc_module_begin ()
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 )
59
60     add_shortcut( "wave" )
61     set_callbacks( Create, Destroy )
62 vlc_module_end ()
63
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  *****************************************************************************/
70 struct filter_sys_t
71 {
72     double  f_angle;
73     mtime_t last_date;
74 };
75
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 )
82 {
83     filter_t *p_filter = (filter_t *)p_this;
84
85     /* Allocate structure */
86     p_filter->p_sys = malloc( sizeof( filter_sys_t ) );
87     if( p_filter->p_sys == NULL )
88         return VLC_ENOMEM;
89
90     p_filter->pf_video_filter = Filter;
91
92     p_filter->p_sys->f_angle = 0.0;
93     p_filter->p_sys->last_date = 0;
94
95     return VLC_SUCCESS;
96 }
97
98 /*****************************************************************************
99  * Destroy: destroy Distort video thread output method
100  *****************************************************************************
101  * Terminate an output method created by DistortCreateOutputMethod
102  *****************************************************************************/
103 static void Destroy( vlc_object_t *p_this )
104 {
105     filter_t *p_filter = (filter_t *)p_this;
106     free( p_filter->p_sys );
107 }
108
109 /*****************************************************************************
110  * Render: displays previously rendered output
111  *****************************************************************************
112  * This function send the currently rendered image to Distort image, waits
113  * until it is displayed and switch the two rendering buffers, preparing next
114  * frame.
115  *****************************************************************************/
116 static picture_t *Filter( filter_t *p_filter, picture_t *p_pic )
117 {
118     picture_t *p_outpic;
119     int i_index;
120     double f_angle;
121     mtime_t new_date = mdate();
122
123     if( !p_pic ) return NULL;
124
125     p_outpic = filter_NewPicture( p_filter );
126     if( !p_outpic )
127     {
128         picture_Release( p_pic );
129         return NULL;
130     }
131
132     p_filter->p_sys->f_angle += (new_date - p_filter->p_sys->last_date) / 200000.0;
133     p_filter->p_sys->last_date = new_date;
134     f_angle = p_filter->p_sys->f_angle;
135
136     for( i_index = 0 ; i_index < p_pic->i_planes ; i_index++ )
137     {
138         int i_line, i_num_lines, i_visible_pitch, i_pixel_pitch, i_offset,
139             i_visible_pixels;
140         uint8_t black_pixel;
141         uint8_t *p_in, *p_out;
142
143         p_in = p_pic->p[i_index].p_pixels;
144         p_out = p_outpic->p[i_index].p_pixels;
145
146         i_num_lines = p_pic->p[i_index].i_visible_lines;
147         i_visible_pitch = p_pic->p[i_index].i_visible_pitch;
148         i_pixel_pitch = p_pic->p[i_index].i_pixel_pitch;
149         i_visible_pixels = i_visible_pitch/i_pixel_pitch;
150
151         black_pixel = ( p_pic->i_planes > 1 && i_index == Y_PLANE ) ? 0x00
152                                                                     : 0x80;
153
154         /* Ok, we do 3 times the sin() calculation for each line. So what ? */
155         for( i_line = 0 ; i_line < i_num_lines ; i_line++ )
156         {
157             /* Calculate today's offset, don't go above 1/20th of the screen */
158             i_offset = (int)( (double)(i_visible_pixels)
159                          * sin( f_angle + 10.0 * (double)i_line
160                                                / (double)i_num_lines )
161                          / 20.0 )*i_pixel_pitch;
162
163             if( i_offset )
164             {
165                 if( i_offset < 0 )
166                 {
167                     vlc_memcpy( p_out, p_in - i_offset,
168                                 i_visible_pitch + i_offset );
169                     p_in += p_pic->p[i_index].i_pitch;
170                     p_out += p_outpic->p[i_index].i_pitch;
171                     vlc_memset( p_out + i_offset, black_pixel, -i_offset );
172                 }
173                 else
174                 {
175                     vlc_memcpy( p_out + i_offset, p_in,
176                                 i_visible_pitch - i_offset );
177                     vlc_memset( p_out, black_pixel, i_offset );
178                     p_in += p_pic->p[i_index].i_pitch;
179                     p_out += p_outpic->p[i_index].i_pitch;
180                 }
181             }
182             else
183             {
184                 vlc_memcpy( p_out, p_in, i_visible_pitch );
185                 p_in += p_pic->p[i_index].i_pitch;
186                 p_out += p_outpic->p[i_index].i_pitch;
187             }
188
189         }
190     }
191
192     return CopyInfoAndRelease( p_outpic, p_pic );
193 }