1 /*****************************************************************************
2 * ripple.c : Ripple video effect plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2000-2006 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 *****************************************************************************/
33 #include <math.h> /* sin(), cos() */
35 #include <vlc_common.h>
36 #include <vlc_plugin.h>
37 #include <vlc_filter.h>
38 #include "filter_picture.h"
40 /*****************************************************************************
42 *****************************************************************************/
43 static int Create ( vlc_object_t
* );
44 static void Destroy ( vlc_object_t
* );
46 static picture_t
*Filter( filter_t
*, picture_t
* );
48 /*****************************************************************************
50 *****************************************************************************/
52 set_description( N_("Ripple video filter") )
53 set_shortname( N_( "Ripple" ))
54 set_capability( "video filter2", 0 )
55 set_category( CAT_VIDEO
)
56 set_subcategory( SUBCAT_VIDEO_VFILTER
)
58 add_shortcut( "ripple" )
59 set_callbacks( Create
, Destroy
)
62 /*****************************************************************************
63 * filter_sys_t: Distort video output method descriptor
64 *****************************************************************************
65 * This structure is part of the video output thread descriptor.
66 * It describes the Distort specific properties of an output thread.
67 *****************************************************************************/
74 /*****************************************************************************
75 * Create: allocates Distort video thread output method
76 *****************************************************************************
77 * This function allocates and initializes a Distort vout method.
78 *****************************************************************************/
79 static int Create( vlc_object_t
*p_this
)
81 filter_t
*p_filter
= (filter_t
*)p_this
;
83 /* Allocate structure */
84 p_filter
->p_sys
= malloc( sizeof( filter_sys_t
) );
85 if( p_filter
->p_sys
== NULL
)
88 p_filter
->pf_video_filter
= Filter
;
90 p_filter
->p_sys
->f_angle
= 0.0;
91 p_filter
->p_sys
->last_date
= 0;
96 /*****************************************************************************
97 * Destroy: destroy Distort video thread output method
98 *****************************************************************************
99 * Terminate an output method created by DistortCreateOutputMethod
100 *****************************************************************************/
101 static void Destroy( vlc_object_t
*p_this
)
103 filter_t
*p_filter
= (filter_t
*)p_this
;
104 free( p_filter
->p_sys
);
107 /*****************************************************************************
108 * Render: displays previously rendered output
109 *****************************************************************************
110 * This function send the currently rendered image to Distort image, waits
111 * until it is displayed and switch the two rendering buffers, preparing next
113 *****************************************************************************/
114 static picture_t
*Filter( filter_t
*p_filter
, picture_t
*p_pic
)
119 mtime_t new_date
= mdate();
121 if( !p_pic
) return NULL
;
123 p_outpic
= filter_NewPicture( p_filter
);
126 picture_Release( p_pic
);
130 p_filter
->p_sys
->f_angle
-= (p_filter
->p_sys
->last_date
- new_date
) / 100000.0;
131 p_filter
->p_sys
->last_date
= new_date
;
132 f_angle
= p_filter
->p_sys
->f_angle
;
134 for( i_index
= 0 ; i_index
< p_pic
->i_planes
; i_index
++ )
136 int i_line
, i_first_line
, i_num_lines
, i_offset
, i_pixel_pitch
,
139 uint8_t *p_in
, *p_out
;
141 black_pixel
= ( p_pic
->i_planes
> 1 && i_index
== Y_PLANE
) ? 0x00
144 i_num_lines
= p_pic
->p
[i_index
].i_visible_lines
;
145 i_pixel_pitch
= p_pic
->p
[i_index
].i_pixel_pitch
;
146 switch( p_filter
->fmt_in
.video
.i_chroma
)
149 // Quick hack to fix u/v inversion occuring with 2 byte pixel pitch
154 i_visible_pixels
= p_pic
->p
[i_index
].i_visible_pitch
/i_pixel_pitch
;
156 i_first_line
= i_num_lines
* 4 / 5;
158 p_in
= p_pic
->p
[i_index
].p_pixels
;
159 p_out
= p_outpic
->p
[i_index
].p_pixels
;
161 for( i_line
= 0 ; i_line
< i_first_line
; i_line
++ )
163 vlc_memcpy( p_out
, p_in
, p_pic
->p
[i_index
].i_visible_pitch
);
164 p_in
+= p_pic
->p
[i_index
].i_pitch
;
165 p_out
+= p_outpic
->p
[i_index
].i_pitch
;
168 /* Ok, we do 3 times the sin() calculation for each line. So what ? */
169 for( i_line
= i_first_line
; i_line
< i_num_lines
; i_line
++ )
171 /* Calculate today's offset, don't go above 1/20th of the screen */
172 i_offset
= (int)( (double)(i_visible_pixels
)
173 * sin( f_angle
+ 2.0 * (double)i_line
174 / (double)( 1 + i_line
176 * (double)(i_line
- i_first_line
)
177 / (double)i_num_lines
178 / 8.0 )*i_pixel_pitch
;
184 vlc_memcpy( p_out
, p_in
- i_offset
,
185 p_pic
->p
[i_index
].i_visible_pitch
+ i_offset
);
186 p_in
-= p_pic
->p
[i_index
].i_pitch
;
187 p_out
+= p_outpic
->p
[i_index
].i_pitch
;
188 vlc_memset( p_out
+ i_offset
, black_pixel
, -i_offset
);
192 vlc_memcpy( p_out
+ i_offset
, p_in
,
193 p_pic
->p
[i_index
].i_visible_pitch
- i_offset
);
194 vlc_memset( p_out
, black_pixel
, i_offset
);
195 p_in
-= p_pic
->p
[i_index
].i_pitch
;
196 p_out
+= p_outpic
->p
[i_index
].i_pitch
;
201 vlc_memcpy( p_out
, p_in
, p_pic
->p
[i_index
].i_visible_pitch
);
202 p_in
-= p_pic
->p
[i_index
].i_pitch
;
203 p_out
+= p_outpic
->p
[i_index
].i_pitch
;
209 return CopyInfoAndRelease( p_outpic
, p_pic
);