1 /*****************************************************************************
2 * psychedelic.c : Psychedelic video effect plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2000-2006 VLC authors and VideoLAN
6 * Authors: Samuel Hocevar <sam@zoy.org>
7 * Antoine Cellerier <dionoea -at- videolan -dot- org>
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU Lesser General Public License as published by
11 * the Free Software Foundation; either version 2.1 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public License
20 * along with this program; if not, write to the Free Software Foundation,
21 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
32 #include <math.h> /* sin(), cos() */
34 #include <vlc_common.h>
35 #include <vlc_plugin.h>
36 #include <vlc_filter.h>
37 #include <vlc_picture.h>
38 #include <vlc_image.h>
39 #include "filter_picture.h"
41 /*****************************************************************************
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 /*****************************************************************************
51 *****************************************************************************/
53 set_description( N_("Psychedelic video filter") )
54 set_shortname( N_( "Psychedelic" ))
55 set_capability( "video filter", 0 )
56 set_category( CAT_VIDEO
)
57 set_subcategory( SUBCAT_VIDEO_VFILTER
)
59 add_shortcut( "psychedelic" )
60 set_callbacks( Create
, Destroy
)
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 *****************************************************************************/
71 image_handler_t
*p_image
;
72 unsigned int x
, y
, scale
;
73 int xinc
, yinc
, scaleinc
;
77 /*****************************************************************************
78 * Create: allocates Distort video thread output method
79 *****************************************************************************
80 * This function allocates and initializes a Distort vout method.
81 *****************************************************************************/
82 static int Create( vlc_object_t
*p_this
)
84 filter_t
*p_filter
= (filter_t
*)p_this
;
86 const vlc_fourcc_t fourcc
= p_filter
->fmt_in
.video
.i_chroma
;
87 const vlc_chroma_description_t
*p_chroma
= vlc_fourcc_GetChromaDescription( fourcc
);
88 if( !p_chroma
|| p_chroma
->plane_count
!= 3 || p_chroma
->pixel_size
!= 1 ) {
89 msg_Err( p_filter
, "Unsupported chroma (%4.4s)", (char*)&fourcc
);
93 /* Allocate structure */
94 filter_sys_t
*p_sys
= malloc( sizeof( filter_sys_t
) );
97 p_filter
->p_sys
= p_sys
;
99 p_filter
->pf_video_filter
= Filter
;
109 p_sys
->p_image
= NULL
;
114 /*****************************************************************************
115 * Destroy: destroy Distort video thread output method
116 *****************************************************************************
117 * Terminate an output method created by DistortCreateOutputMethod
118 *****************************************************************************/
119 static void Destroy( vlc_object_t
*p_this
)
121 filter_t
*p_filter
= (filter_t
*)p_this
;
122 filter_sys_t
*p_sys
= p_filter
->p_sys
;
125 image_HandlerDelete( p_sys
->p_image
);
126 p_sys
->p_image
= NULL
;
131 /*****************************************************************************
132 * Render: displays previously rendered output
133 *****************************************************************************
134 * This function send the currently rendered image to Distort image, waits
135 * until it is displayed and switch the two rendering buffers, preparing next
137 *****************************************************************************/
138 static picture_t
*Filter( filter_t
*p_filter
, picture_t
*p_pic
)
145 picture_t
*p_converted
;
146 video_format_t fmt_out
;
148 if( !p_pic
) return NULL
;
150 p_outpic
= filter_NewPicture( p_filter
);
153 picture_Release( p_pic
);
157 filter_sys_t
*p_sys
= p_filter
->p_sys
;
159 if( !p_sys
->p_image
)
160 p_sys
->p_image
= image_HandlerCreate( p_filter
);
165 for( int y
= 0; y
< p_outpic
->p
[U_PLANE
].i_lines
; y
++ )
168 p_outpic
->p
[U_PLANE
].p_pixels
+y
*p_outpic
->p
[U_PLANE
].i_pitch
,
169 u
, p_outpic
->p
[U_PLANE
].i_pitch
);
171 p_outpic
->p
[V_PLANE
].p_pixels
+y
*p_outpic
->p
[V_PLANE
].i_pitch
,
172 v
, p_outpic
->p
[V_PLANE
].i_pitch
);
173 if( v
== 0 && u
!= 0 )
184 plane_CopyPixels( &p_outpic
->p
[Y_PLANE
], &p_pic
->p
[Y_PLANE
] );
186 /* image visualization */
187 fmt_out
= p_filter
->fmt_out
.video
;
188 fmt_out
.i_width
= p_filter
->fmt_out
.video
.i_width
*p_sys
->scale
/150;
189 fmt_out
.i_height
= p_filter
->fmt_out
.video
.i_height
*p_sys
->scale
/150;
190 fmt_out
.i_visible_width
= fmt_out
.i_width
;
191 fmt_out
.i_visible_height
= fmt_out
.i_height
;
192 p_converted
= image_Convert( p_sys
->p_image
, p_pic
,
193 &(p_pic
->format
), &fmt_out
);
197 #define copyimage( plane, b ) \
198 for( int y = 0; y<p_converted->p[plane].i_visible_lines; y++ ) { \
199 for( int x = 0; x<p_converted->p[plane].i_visible_pitch; x++ ) { \
201 if( p_sys->yinc == 1 ) \
204 ny = p_converted->p[plane].i_visible_lines-y -1; \
205 if( p_sys->xinc == 1 ) \
208 nx = p_converted->p[plane].i_visible_pitch-x -1; \
209 p_outpic->p[plane].p_pixels[(p_sys->x*b+nx)+(ny+p_sys->y*b)*p_outpic->p[plane].i_pitch ] = p_converted->p[plane].p_pixels[y*p_converted->p[plane].i_pitch+x]; \
211 copyimage( Y_PLANE
, 2 );
212 copyimage( U_PLANE
, 1 );
213 copyimage( V_PLANE
, 1 );
216 picture_Release( p_converted
);
220 msg_Err( p_filter
, "Image scaling failed miserably." );
223 p_sys
->x
+= p_sys
->xinc
;
224 p_sys
->y
+= p_sys
->yinc
;
226 p_sys
->scale
+= p_sys
->scaleinc
;
227 if( p_sys
->scale
>= 50 ) p_sys
->scaleinc
= -1;
228 if( p_sys
->scale
<= 1 ) p_sys
->scaleinc
= 1;
230 w
= p_filter
->fmt_out
.video
.i_width
*p_sys
->scale
/150;
231 h
= p_filter
->fmt_out
.video
.i_height
*p_sys
->scale
/150;
232 if( p_sys
->x
*2 + w
>= p_filter
->fmt_out
.video
.i_width
)
237 if( p_sys
->x
*2 + w
>= p_filter
->fmt_out
.video
.i_width
)
238 p_sys
->x
= (p_filter
->fmt_out
.video
.i_width
-w
)/2;
239 if( p_sys
->y
*2 + h
>= p_filter
->fmt_out
.video
.i_height
)
240 p_sys
->y
= (p_filter
->fmt_out
.video
.i_height
-h
)/2;
242 if( p_sys
->y
*2 + h
>= p_filter
->fmt_out
.video
.i_height
)
247 for( int y
= 0; y
< 16; y
++ )
249 if( p_sys
->v
== 0 && p_sys
->u
!= 0 )
251 else if( p_sys
->u
== 0xff )
253 else if( p_sys
->v
== 0xff )
255 else if( p_sys
->u
== 0 )
259 return CopyInfoAndRelease( p_outpic
, p_pic
);