1 /*****************************************************************************
2 * invert.c : Invert video plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2000, 2001 VideoLAN
5 * $Id: invert.c,v 1.11 2002/05/19 12:57:32 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 *****************************************************************************/
28 #include <stdlib.h> /* malloc(), free() */
31 #include <videolan/vlc.h>
34 #include "video_output.h"
36 #include "filter_common.h"
38 /*****************************************************************************
39 * Capabilities defined in the other files.
40 *****************************************************************************/
41 static void vout_getfunctions( function_list_t * p_function_list );
43 /*****************************************************************************
44 * Build configuration tree.
45 *****************************************************************************/
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" )
58 vout_getfunctions( &p_module->p_functions->vout );
61 MODULE_DEACTIVATE_START
62 MODULE_DEACTIVATE_STOP
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
72 struct vout_thread_s *p_vout;
76 /*****************************************************************************
78 *****************************************************************************/
79 static int vout_Create ( struct vout_thread_s * );
80 static int vout_Init ( struct vout_thread_s * );
81 static void vout_End ( struct vout_thread_s * );
82 static void vout_Destroy ( struct vout_thread_s * );
83 static int vout_Manage ( struct vout_thread_s * );
84 static void vout_Render ( struct vout_thread_s *, struct picture_s * );
85 static void vout_Display ( struct vout_thread_s *, struct picture_s * );
87 /*****************************************************************************
88 * Functions exported as capabilities. They are declared as static so that
89 * we don't pollute the namespace too much.
90 *****************************************************************************/
91 static void vout_getfunctions( function_list_t * p_function_list )
93 p_function_list->functions.vout.pf_create = vout_Create;
94 p_function_list->functions.vout.pf_init = vout_Init;
95 p_function_list->functions.vout.pf_end = vout_End;
96 p_function_list->functions.vout.pf_destroy = vout_Destroy;
97 p_function_list->functions.vout.pf_manage = vout_Manage;
98 p_function_list->functions.vout.pf_render = vout_Render;
99 p_function_list->functions.vout.pf_display = vout_Display;
102 /*****************************************************************************
103 * vout_Create: allocates Invert video thread output method
104 *****************************************************************************
105 * This function allocates and initializes a Invert vout method.
106 *****************************************************************************/
107 static int vout_Create( vout_thread_t *p_vout )
109 /* Allocate structure */
110 p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
111 if( p_vout->p_sys == NULL )
113 intf_ErrMsg("error: %s", strerror(ENOMEM) );
120 /*****************************************************************************
121 * vout_Init: initialize Invert video thread output method
122 *****************************************************************************/
123 static int vout_Init( vout_thread_t *p_vout )
129 I_OUTPUTPICTURES = 0;
131 /* Initialize the output structure */
132 p_vout->output.i_chroma = p_vout->render.i_chroma;
133 p_vout->output.i_width = p_vout->render.i_width;
134 p_vout->output.i_height = p_vout->render.i_height;
135 p_vout->output.i_aspect = p_vout->render.i_aspect;
137 /* Try to open the real video output */
138 psz_filter = config_GetPszVariable( "filter" );
139 config_PutPszVariable( "filter", NULL );
141 intf_WarnMsg( 1, "filter: spawning the real video output" );
143 p_vout->p_sys->p_vout =
144 vout_CreateThread( NULL,
145 p_vout->render.i_width, p_vout->render.i_height,
146 p_vout->render.i_chroma, p_vout->render.i_aspect );
148 config_PutPszVariable( "filter", psz_filter );
149 if( psz_filter ) free( psz_filter );
151 /* Everything failed */
152 if( p_vout->p_sys->p_vout == NULL )
154 intf_ErrMsg( "filter error: can't open vout, aborting" );
159 ALLOCATE_DIRECTBUFFERS( VOUT_MAX_PICTURES );
164 /*****************************************************************************
165 * vout_End: terminate Invert video thread output method
166 *****************************************************************************/
167 static void vout_End( vout_thread_t *p_vout )
171 /* Free the fake output buffers we allocated */
172 for( i_index = I_OUTPUTPICTURES ; i_index ; )
175 free( PP_OUTPUTPICTURE[ i_index ]->p_data_orig );
179 /*****************************************************************************
180 * vout_Destroy: destroy Invert video thread output method
181 *****************************************************************************
182 * Terminate an output method created by InvertCreateOutputMethod
183 *****************************************************************************/
184 static void vout_Destroy( vout_thread_t *p_vout )
186 vout_DestroyThread( p_vout->p_sys->p_vout, NULL );
188 free( p_vout->p_sys );
191 /*****************************************************************************
192 * vout_Manage: handle Invert events
193 *****************************************************************************
194 * This function should be called regularly by video output thread. It manages
195 * console events. It returns a non null value on error.
196 *****************************************************************************/
197 static int vout_Manage( vout_thread_t *p_vout )
202 /*****************************************************************************
203 * vout_Render: displays previously rendered output
204 *****************************************************************************
205 * This function send the currently rendered image to Invert image, waits
206 * until it is displayed and switch the two rendering buffers, preparing next
208 *****************************************************************************/
209 static void vout_Render( vout_thread_t *p_vout, picture_t *p_pic )
214 /* This is a new frame. Get a structure from the video_output. */
215 while( ( p_outpic = vout_CreatePicture( p_vout->p_sys->p_vout, 0, 0, 0 ) )
218 if( p_vout->b_die || p_vout->b_error )
222 msleep( VOUT_OUTMEM_SLEEP );
225 vout_DatePicture( p_vout->p_sys->p_vout, p_outpic, p_pic->date );
226 vout_LinkPicture( p_vout->p_sys->p_vout, p_outpic );
228 for( i_index = 0 ; i_index < p_pic->i_planes ; i_index++ )
230 u8 *p_in, *p_in_end, *p_out;
232 p_in = p_pic->p[i_index].p_pixels;
233 p_in_end = p_in - 64 + p_pic->p[i_index].i_lines
234 * p_pic->p[i_index].i_pitch;
236 p_out = p_outpic->p[i_index].p_pixels;
238 for( ; p_in < p_in_end ; )
240 /* Do 64 pixels at a time */
241 *((u64*)p_out)++ = ~( *((u64*)p_in)++ );
242 *((u64*)p_out)++ = ~( *((u64*)p_in)++ );
243 *((u64*)p_out)++ = ~( *((u64*)p_in)++ );
244 *((u64*)p_out)++ = ~( *((u64*)p_in)++ );
245 *((u64*)p_out)++ = ~( *((u64*)p_in)++ );
246 *((u64*)p_out)++ = ~( *((u64*)p_in)++ );
247 *((u64*)p_out)++ = ~( *((u64*)p_in)++ );
248 *((u64*)p_out)++ = ~( *((u64*)p_in)++ );
253 for( ; p_in < p_in_end ; )
255 /* Do 1 pixel at a time */
256 *p_out++ = ~( *p_in++ );
260 vout_UnlinkPicture( p_vout->p_sys->p_vout, p_outpic );
262 vout_DisplayPicture( p_vout->p_sys->p_vout, p_outpic );
265 /*****************************************************************************
266 * vout_Display: displays previously rendered output
267 *****************************************************************************
268 * This function send the currently rendered image to Invert image, waits
269 * until it is displayed and switch the two rendering buffers, preparing next
271 *****************************************************************************/
272 static void vout_Display( vout_thread_t *p_vout, picture_t *p_pic )