]> git.sesse.net Git - vlc/blob - modules/video_filter/invert.c
* ./modules/video_output/wingdi.c: the GDI video output now properly sets
[vlc] / modules / video_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.2 2002/11/23 02:40:30 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 <stdlib.h>                                      /* malloc(), free() */
28 #include <string.h>
29
30 #include <vlc/vlc.h>
31 #include <vlc/vout.h>
32
33 #include "filter_common.h"
34
35 /*****************************************************************************
36  * Local prototypes
37  *****************************************************************************/
38 static int  Create    ( vlc_object_t * );
39 static void Destroy   ( vlc_object_t * );
40
41 static int  Init      ( vout_thread_t * );
42 static void End       ( vout_thread_t * );
43 static void Render    ( vout_thread_t *, picture_t * );
44
45 /*****************************************************************************
46  * Module descriptor
47  *****************************************************************************/
48 vlc_module_begin();
49     set_description( _("invert video module") );
50     set_capability( "video filter", 0 );
51     add_shortcut( "invert" );
52     set_callbacks( Create, Destroy );
53 vlc_module_end();
54
55 /*****************************************************************************
56  * vout_sys_t: Invert video output method descriptor
57  *****************************************************************************
58  * This structure is part of the video output thread descriptor.
59  * It describes the Invert specific properties of an output thread.
60  *****************************************************************************/
61 struct vout_sys_t
62 {
63     vout_thread_t *p_vout;
64 };
65
66 /*****************************************************************************
67  * Create: allocates Invert video thread output method
68  *****************************************************************************
69  * This function allocates and initializes a Invert vout method.
70  *****************************************************************************/
71 static int Create( vlc_object_t *p_this )
72 {
73     vout_thread_t *p_vout = (vout_thread_t *)p_this;
74
75     /* Allocate structure */
76     p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
77     if( p_vout->p_sys == NULL )
78     {
79         msg_Err( p_vout, "out of memory" );
80         return( 1 );
81     }
82
83     p_vout->pf_init = Init;
84     p_vout->pf_end = End;
85     p_vout->pf_manage = NULL;
86     p_vout->pf_render = Render;
87     p_vout->pf_display = NULL;
88
89     return( 0 );
90 }
91
92 /*****************************************************************************
93  * Init: initialize Invert video thread output method
94  *****************************************************************************/
95 static int Init( vout_thread_t *p_vout )
96 {
97     int i_index;
98     picture_t *p_pic;
99
100     I_OUTPUTPICTURES = 0;
101
102     /* Initialize the output structure */
103     p_vout->output.i_chroma = p_vout->render.i_chroma;
104     p_vout->output.i_width  = p_vout->render.i_width;
105     p_vout->output.i_height = p_vout->render.i_height;
106     p_vout->output.i_aspect = p_vout->render.i_aspect;
107
108     /* Try to open the real video output */
109     msg_Dbg( p_vout, "spawning the real video output" );
110
111     p_vout->p_sys->p_vout =
112         vout_CreateThread( p_vout,
113                            p_vout->render.i_width, p_vout->render.i_height,
114                            p_vout->render.i_chroma, p_vout->render.i_aspect );
115
116     /* Everything failed */
117     if( p_vout->p_sys->p_vout == NULL )
118     {
119         msg_Err( p_vout, "can't open vout, aborting" );
120
121         return( 0 );
122     }
123  
124     ALLOCATE_DIRECTBUFFERS( VOUT_MAX_PICTURES );
125
126     return( 0 );
127 }
128
129 /*****************************************************************************
130  * End: terminate Invert video thread output method
131  *****************************************************************************/
132 static void End( vout_thread_t *p_vout )
133 {
134     int i_index;
135
136     /* Free the fake output buffers we allocated */
137     for( i_index = I_OUTPUTPICTURES ; i_index ; )
138     {
139         i_index--;
140         free( PP_OUTPUTPICTURE[ i_index ]->p_data_orig );
141     }
142 }
143
144 /*****************************************************************************
145  * Destroy: destroy Invert video thread output method
146  *****************************************************************************
147  * Terminate an output method created by InvertCreateOutputMethod
148  *****************************************************************************/
149 static void Destroy( vlc_object_t *p_this )
150 {   
151     vout_thread_t *p_vout = (vout_thread_t *)p_this;
152
153     vout_DestroyThread( p_vout->p_sys->p_vout );
154
155     free( p_vout->p_sys );
156 }
157
158 /*****************************************************************************
159  * Render: displays previously rendered output
160  *****************************************************************************
161  * This function send the currently rendered image to Invert image, waits
162  * until it is displayed and switch the two rendering buffers, preparing next
163  * frame.
164  *****************************************************************************/
165 static void Render( vout_thread_t *p_vout, picture_t *p_pic )
166 {
167     picture_t *p_outpic;
168     int i_index;
169
170     /* This is a new frame. Get a structure from the video_output. */
171     while( ( p_outpic = vout_CreatePicture( p_vout->p_sys->p_vout, 0, 0, 0 ) )
172               == NULL )
173     {
174         if( p_vout->b_die || p_vout->b_error )
175         {
176             return;
177         }
178         msleep( VOUT_OUTMEM_SLEEP );
179     }   
180
181     vout_DatePicture( p_vout->p_sys->p_vout, p_outpic, p_pic->date );
182     vout_LinkPicture( p_vout->p_sys->p_vout, p_outpic );
183
184     for( i_index = 0 ; i_index < p_pic->i_planes ; i_index++ )
185     {
186         u8 *p_in, *p_in_end, *p_out;
187
188         p_in = p_pic->p[i_index].p_pixels;
189         p_in_end = p_in - 64 + p_pic->p[i_index].i_lines
190                                 * p_pic->p[i_index].i_pitch;
191
192         p_out = p_outpic->p[i_index].p_pixels;
193
194         for( ; p_in < p_in_end ; )
195         {
196             /* Do 64 pixels at a time */
197             *((u64*)p_out)++ = ~( *((u64*)p_in)++ );
198             *((u64*)p_out)++ = ~( *((u64*)p_in)++ );
199             *((u64*)p_out)++ = ~( *((u64*)p_in)++ );
200             *((u64*)p_out)++ = ~( *((u64*)p_in)++ );
201             *((u64*)p_out)++ = ~( *((u64*)p_in)++ );
202             *((u64*)p_out)++ = ~( *((u64*)p_in)++ );
203             *((u64*)p_out)++ = ~( *((u64*)p_in)++ );
204             *((u64*)p_out)++ = ~( *((u64*)p_in)++ );
205         }
206
207         p_in_end += 64;
208
209         for( ; p_in < p_in_end ; )
210         {
211             /* Do 1 pixel at a time */
212             *p_out++ = ~( *p_in++ );
213         }
214     }
215
216     vout_UnlinkPicture( p_vout->p_sys->p_vout, p_outpic );
217
218     vout_DisplayPicture( p_vout->p_sys->p_vout, p_outpic );
219 }
220