1 /*****************************************************************************
2 * invert.c : Invert video plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2000, 2001, 2002, 2003 VideoLAN
5 * $Id: invert.c,v 1.6 2003/03/18 23:30:28 gbazin Exp $
7 * Authors: Samuel Hocevar <sam@zoy.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 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 General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
27 #include <stdlib.h> /* malloc(), free() */
33 #include "filter_common.h"
35 /*****************************************************************************
37 *****************************************************************************/
38 static int Create ( vlc_object_t * );
39 static void Destroy ( vlc_object_t * );
41 static int Init ( vout_thread_t * );
42 static void End ( vout_thread_t * );
43 static void Render ( vout_thread_t *, picture_t * );
45 static int SendEvents( vlc_object_t *, char const *,
46 vlc_value_t, vlc_value_t, void * );
48 /*****************************************************************************
50 *****************************************************************************/
52 set_description( _("invert video module") );
53 set_capability( "video filter", 0 );
54 add_shortcut( "invert" );
55 set_callbacks( Create, Destroy );
58 /*****************************************************************************
59 * vout_sys_t: Invert video output method descriptor
60 *****************************************************************************
61 * This structure is part of the video output thread descriptor.
62 * It describes the Invert specific properties of an output thread.
63 *****************************************************************************/
66 vout_thread_t *p_vout;
69 /*****************************************************************************
70 * Create: allocates Invert video thread output method
71 *****************************************************************************
72 * This function allocates and initializes a Invert vout method.
73 *****************************************************************************/
74 static int Create( vlc_object_t *p_this )
76 vout_thread_t *p_vout = (vout_thread_t *)p_this;
78 /* Allocate structure */
79 p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
80 if( p_vout->p_sys == NULL )
82 msg_Err( p_vout, "out of memory" );
86 p_vout->pf_init = Init;
88 p_vout->pf_manage = NULL;
89 p_vout->pf_render = Render;
90 p_vout->pf_display = NULL;
95 /*****************************************************************************
96 * Init: initialize Invert video thread output method
97 *****************************************************************************/
98 static int Init( vout_thread_t *p_vout )
103 I_OUTPUTPICTURES = 0;
105 /* Initialize the output structure */
106 p_vout->output.i_chroma = p_vout->render.i_chroma;
107 p_vout->output.i_width = p_vout->render.i_width;
108 p_vout->output.i_height = p_vout->render.i_height;
109 p_vout->output.i_aspect = p_vout->render.i_aspect;
111 /* Try to open the real video output */
112 msg_Dbg( p_vout, "spawning the real video output" );
114 p_vout->p_sys->p_vout = vout_Create( p_vout,
115 p_vout->render.i_width, p_vout->render.i_height,
116 p_vout->render.i_chroma, p_vout->render.i_aspect );
118 /* Everything failed */
119 if( p_vout->p_sys->p_vout == NULL )
121 msg_Err( p_vout, "can't open vout, aborting" );
126 ALLOCATE_DIRECTBUFFERS( VOUT_MAX_PICTURES );
128 ADD_CALLBACKS( p_vout->p_sys->p_vout, SendEvents );
133 /*****************************************************************************
134 * End: terminate Invert video thread output method
135 *****************************************************************************/
136 static void End( vout_thread_t *p_vout )
140 /* Free the fake output buffers we allocated */
141 for( i_index = I_OUTPUTPICTURES ; i_index ; )
144 free( PP_OUTPUTPICTURE[ i_index ]->p_data_orig );
148 /*****************************************************************************
149 * Destroy: destroy Invert video thread output method
150 *****************************************************************************
151 * Terminate an output method created by InvertCreateOutputMethod
152 *****************************************************************************/
153 static void Destroy( vlc_object_t *p_this )
155 vout_thread_t *p_vout = (vout_thread_t *)p_this;
157 DEL_CALLBACKS( p_vout->p_sys->p_vout, SendEvents );
158 vlc_object_detach( p_vout->p_sys->p_vout );
159 vout_Destroy( p_vout->p_sys->p_vout );
161 free( p_vout->p_sys );
164 /*****************************************************************************
165 * Render: displays previously rendered output
166 *****************************************************************************
167 * This function send the currently rendered image to Invert image, waits
168 * until it is displayed and switch the two rendering buffers, preparing next
170 *****************************************************************************/
171 static void Render( vout_thread_t *p_vout, picture_t *p_pic )
176 /* This is a new frame. Get a structure from the video_output. */
177 while( ( p_outpic = vout_CreatePicture( p_vout->p_sys->p_vout, 0, 0, 0 ) )
180 if( p_vout->b_die || p_vout->b_error )
184 msleep( VOUT_OUTMEM_SLEEP );
187 vout_DatePicture( p_vout->p_sys->p_vout, p_outpic, p_pic->date );
188 vout_LinkPicture( p_vout->p_sys->p_vout, p_outpic );
190 for( i_index = 0 ; i_index < p_pic->i_planes ; i_index++ )
192 uint8_t *p_in, *p_in_end, *p_line_end, *p_out;
194 p_in = p_pic->p[i_index].p_pixels;
195 p_in_end = p_in + p_pic->p[i_index].i_lines
196 * p_pic->p[i_index].i_pitch;
198 p_out = p_outpic->p[i_index].p_pixels;
200 for( ; p_in < p_in_end ; )
202 p_line_end = p_in + p_pic->p[i_index].i_visible_pitch - 64;
204 for( ; p_in < p_line_end ; )
206 /* Do 64 pixels at a time */
207 *((uint64_t*)p_out)++ = ~( *((uint64_t*)p_in)++ );
208 *((uint64_t*)p_out)++ = ~( *((uint64_t*)p_in)++ );
209 *((uint64_t*)p_out)++ = ~( *((uint64_t*)p_in)++ );
210 *((uint64_t*)p_out)++ = ~( *((uint64_t*)p_in)++ );
211 *((uint64_t*)p_out)++ = ~( *((uint64_t*)p_in)++ );
212 *((uint64_t*)p_out)++ = ~( *((uint64_t*)p_in)++ );
213 *((uint64_t*)p_out)++ = ~( *((uint64_t*)p_in)++ );
214 *((uint64_t*)p_out)++ = ~( *((uint64_t*)p_in)++ );
219 for( ; p_in < p_line_end ; )
221 *p_out++ = ~( *p_in++ );
224 p_in += p_pic->p[i_index].i_pitch
225 - p_pic->p[i_index].i_visible_pitch;
226 p_out += p_outpic->p[i_index].i_pitch
227 - p_outpic->p[i_index].i_visible_pitch;
231 vout_UnlinkPicture( p_vout->p_sys->p_vout, p_outpic );
233 vout_DisplayPicture( p_vout->p_sys->p_vout, p_outpic );
236 /*****************************************************************************
237 * SendEvents: forward mouse and keyboard events to the parent p_vout
238 *****************************************************************************/
239 static int SendEvents( vlc_object_t *p_this, char const *psz_var,
240 vlc_value_t oldval, vlc_value_t newval, void *p_data )
242 var_Set( (vlc_object_t *)p_data, psz_var, newval );