]> git.sesse.net Git - vlc/blob - plugins/filter/invert.c
* ./BUGS: added a list of known bugs. Please add your findings!
[vlc] / plugins / filter / invert.c
1 /*****************************************************************************
2  * invert.c : Invert video plugin for vlc
3  *****************************************************************************
4  * Copyright (C) 2000, 2001 VideoLAN
5  * $Id: invert.c,v 1.5 2002/01/04 14:01:34 sam Exp $
6  *
7  * Authors: Samuel Hocevar <sam@zoy.org>
8  *
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.
13  * 
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.
18  *
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  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #include <errno.h>
28 #include <stdlib.h>                                      /* malloc(), free() */
29 #include <string.h>
30
31 #include <videolan/vlc.h>
32
33 #include "video.h"
34 #include "video_output.h"
35
36 #include "filter_common.h"
37
38 /*****************************************************************************
39  * Capabilities defined in the other files.
40  *****************************************************************************/
41 static void vout_getfunctions( function_list_t * p_function_list );
42
43 /*****************************************************************************
44  * Build configuration tree.
45  *****************************************************************************/
46 MODULE_CONFIG_START
47 MODULE_CONFIG_STOP
48
49 MODULE_INIT_START
50     SET_DESCRIPTION( "invert video module" )
51     /* Capability score set to 0 because we don't want to be spawned
52      * as a video output unless explicitly requested to */
53     ADD_CAPABILITY( VOUT, 0 )
54     ADD_SHORTCUT( "invert" )
55 MODULE_INIT_STOP
56
57 MODULE_ACTIVATE_START
58     vout_getfunctions( &p_module->p_functions->vout );
59 MODULE_ACTIVATE_STOP
60
61 MODULE_DEACTIVATE_START
62 MODULE_DEACTIVATE_STOP
63
64 /*****************************************************************************
65  * vout_sys_t: Invert video output method descriptor
66  *****************************************************************************
67  * This structure is part of the video output thread descriptor.
68  * It describes the Invert specific properties of an output thread.
69  *****************************************************************************/
70 typedef struct vout_sys_s
71 {
72     struct vout_thread_s *p_vout;
73
74 } vout_sys_t;
75
76 /*****************************************************************************
77  * Local prototypes
78  *****************************************************************************/
79 static int  vout_Probe     ( probedata_t *p_data );
80 static int  vout_Create    ( struct vout_thread_s * );
81 static int  vout_Init      ( struct vout_thread_s * );
82 static void vout_End       ( struct vout_thread_s * );
83 static void vout_Destroy   ( struct vout_thread_s * );
84 static int  vout_Manage    ( struct vout_thread_s * );
85 static void vout_Render    ( struct vout_thread_s *, struct picture_s * );
86 static void vout_Display   ( struct vout_thread_s *, struct picture_s * );
87
88 /*****************************************************************************
89  * Functions exported as capabilities. They are declared as static so that
90  * we don't pollute the namespace too much.
91  *****************************************************************************/
92 static void vout_getfunctions( function_list_t * p_function_list )
93 {
94     p_function_list->pf_probe = vout_Probe;
95     p_function_list->functions.vout.pf_create     = vout_Create;
96     p_function_list->functions.vout.pf_init       = vout_Init;
97     p_function_list->functions.vout.pf_end        = vout_End;
98     p_function_list->functions.vout.pf_destroy    = vout_Destroy;
99     p_function_list->functions.vout.pf_manage     = vout_Manage;
100     p_function_list->functions.vout.pf_render     = vout_Render;
101     p_function_list->functions.vout.pf_display    = vout_Display;
102     p_function_list->functions.vout.pf_setpalette = NULL;
103 }
104
105 /*****************************************************************************
106  * intf_Probe: return a score
107  *****************************************************************************/
108 static int vout_Probe( probedata_t *p_data )
109 {
110     return( 0 );
111 }
112
113 /*****************************************************************************
114  * vout_Create: allocates Invert video thread output method
115  *****************************************************************************
116  * This function allocates and initializes a Invert vout method.
117  *****************************************************************************/
118 static int vout_Create( vout_thread_t *p_vout )
119 {
120     /* Allocate structure */
121     p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
122     if( p_vout->p_sys == NULL )
123     {
124         intf_ErrMsg("error: %s", strerror(ENOMEM) );
125         return( 1 );
126     }
127
128     return( 0 );
129 }
130
131 /*****************************************************************************
132  * vout_Init: initialize Invert video thread output method
133  *****************************************************************************/
134 static int vout_Init( vout_thread_t *p_vout )
135 {
136     int i_index;
137     char *psz_filter;
138     picture_t *p_pic;
139     
140     I_OUTPUTPICTURES = 0;
141
142     /* Initialize the output structure */
143     p_vout->output.i_chroma = p_vout->render.i_chroma;
144     p_vout->output.i_width  = p_vout->render.i_width;
145     p_vout->output.i_height = p_vout->render.i_height;
146     p_vout->output.i_aspect = p_vout->render.i_aspect;
147
148     /* Try to open the real video output */
149     psz_filter = main_GetPszVariable( VOUT_FILTER_VAR, "" );
150     main_PutPszVariable( VOUT_FILTER_VAR, "" );
151
152     intf_WarnMsg( 1, "filter: spawning the real video output" );
153         
154     p_vout->p_sys->p_vout =
155         vout_CreateThread( NULL,
156                            p_vout->render.i_width, p_vout->render.i_height,
157                            p_vout->render.i_chroma, p_vout->render.i_aspect );
158
159     /* Everything failed */
160     if( p_vout->p_sys->p_vout == NULL )
161     {
162         intf_ErrMsg( "filter error: can't open vout, aborting" );
163
164         return( 0 );
165     }
166  
167     main_PutPszVariable( VOUT_FILTER_VAR, psz_filter );
168
169     ALLOCATE_DIRECTBUFFERS( VOUT_MAX_PICTURES );
170
171     return( 0 );
172 }
173
174 /*****************************************************************************
175  * vout_End: terminate Invert video thread output method
176  *****************************************************************************/
177 static void vout_End( vout_thread_t *p_vout )
178 {
179     int i_index;
180
181     /* Free the fake output buffers we allocated */
182     for( i_index = I_OUTPUTPICTURES ; i_index ; )
183     {
184         i_index--;
185         free( PP_OUTPUTPICTURE[ i_index ]->p_data );
186     }
187 }
188
189 /*****************************************************************************
190  * vout_Destroy: destroy Invert video thread output method
191  *****************************************************************************
192  * Terminate an output method created by InvertCreateOutputMethod
193  *****************************************************************************/
194 static void vout_Destroy( vout_thread_t *p_vout )
195 {
196     vout_DestroyThread( p_vout->p_sys->p_vout, NULL );
197
198     free( p_vout->p_sys );
199 }
200
201 /*****************************************************************************
202  * vout_Manage: handle Invert events
203  *****************************************************************************
204  * This function should be called regularly by video output thread. It manages
205  * console events. It returns a non null value on error.
206  *****************************************************************************/
207 static int vout_Manage( vout_thread_t *p_vout )
208 {
209     return( 0 );
210 }
211
212 /*****************************************************************************
213  * vout_Render: displays previously rendered output
214  *****************************************************************************
215  * This function send the currently rendered image to Invert image, waits
216  * until it is displayed and switch the two rendering buffers, preparing next
217  * frame.
218  *****************************************************************************/
219 static void vout_Render( vout_thread_t *p_vout, picture_t *p_pic )
220 {
221     picture_t *p_outpic;
222     int i_index;
223
224     /* This is a new frame. Get a structure from the video_output. */
225     while( ( p_outpic = vout_CreatePicture( p_vout->p_sys->p_vout, 0, 0, 0 ) )
226               == NULL )
227     {
228         if( p_vout->b_die || p_vout->b_error )
229         {
230             return;
231         }
232         msleep( VOUT_OUTMEM_SLEEP );
233     }   
234
235     vout_DatePicture( p_vout->p_sys->p_vout, p_outpic, p_pic->date );
236     vout_LinkPicture( p_vout->p_sys->p_vout, p_outpic );
237
238     for( i_index = 0 ; i_index < p_pic->i_planes ; i_index++ )
239     {
240         u8 *p_in, *p_in_end, *p_out;
241
242         p_in = p_pic->p[i_index].p_pixels;
243         p_in_end = p_in - 64 + p_pic->p[i_index].i_lines
244                                 * p_pic->p[i_index].i_pitch;
245
246         p_out = p_outpic->p[i_index].p_pixels;
247
248         for( ; p_in < p_in_end ; )
249         {
250             /* Do 64 pixels at a time */
251             *((u64*)p_out)++ = ~( *((u64*)p_in)++ );
252             *((u64*)p_out)++ = ~( *((u64*)p_in)++ );
253             *((u64*)p_out)++ = ~( *((u64*)p_in)++ );
254             *((u64*)p_out)++ = ~( *((u64*)p_in)++ );
255             *((u64*)p_out)++ = ~( *((u64*)p_in)++ );
256             *((u64*)p_out)++ = ~( *((u64*)p_in)++ );
257             *((u64*)p_out)++ = ~( *((u64*)p_in)++ );
258             *((u64*)p_out)++ = ~( *((u64*)p_in)++ );
259         }
260
261         p_in_end += 64;
262
263         for( ; p_in < p_in_end ; )
264         {
265             /* Do 1 pixel at a time */
266             *p_out++ = ~( *p_in++ );
267         }
268     }
269
270     vout_UnlinkPicture( p_vout->p_sys->p_vout, p_outpic );
271
272     vout_DisplayPicture( p_vout->p_sys->p_vout, p_outpic );
273 }
274
275 /*****************************************************************************
276  * vout_Display: displays previously rendered output
277  *****************************************************************************
278  * This function send the currently rendered image to Invert image, waits
279  * until it is displayed and switch the two rendering buffers, preparing next
280  * frame.
281  *****************************************************************************/
282 static void vout_Display( vout_thread_t *p_vout, picture_t *p_pic )
283 {
284     ;
285 }
286