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