invert.c 9.89 KB
Newer Older
Sam Hocevar's avatar
 
Sam Hocevar committed
1 2 3 4
/*****************************************************************************
 * invert.c : Invert video plugin for vlc
 *****************************************************************************
 * Copyright (C) 2000, 2001 VideoLAN
Gildas Bazin's avatar
 
Gildas Bazin committed
5
 * $Id: invert.c,v 1.14 2002/06/11 09:44:21 gbazin Exp $
Sam Hocevar's avatar
 
Sam Hocevar committed
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
 *
 * Authors: Samuel Hocevar <sam@zoy.org>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
 *****************************************************************************/

/*****************************************************************************
 * Preamble
 *****************************************************************************/
#include <errno.h>
#include <stdlib.h>                                      /* malloc(), free() */
#include <string.h>

31 32
#include <vlc/vlc.h>
#include <vlc/vout.h>
Sam Hocevar's avatar
 
Sam Hocevar committed
33

Sam Hocevar's avatar
 
Sam Hocevar committed
34 35
#include "filter_common.h"

Sam Hocevar's avatar
 
Sam Hocevar committed
36 37 38 39 40 41 42 43 44 45 46 47
/*****************************************************************************
 * Capabilities defined in the other files.
 *****************************************************************************/
static void vout_getfunctions( function_list_t * p_function_list );

/*****************************************************************************
 * Build configuration tree.
 *****************************************************************************/
MODULE_CONFIG_START
MODULE_CONFIG_STOP

MODULE_INIT_START
Sam Hocevar's avatar
 
Sam Hocevar committed
48
    SET_DESCRIPTION( _("invert video module") )
Sam Hocevar's avatar
 
Sam Hocevar committed
49 50
    /* Capability score set to 0 because we don't want to be spawned
     * as a video output unless explicitly requested to */
Gildas Bazin's avatar
 
Gildas Bazin committed
51
    ADD_CAPABILITY( VOUT_FILTER, 0 )
Sam Hocevar's avatar
 
Sam Hocevar committed
52
    ADD_SHORTCUT( "invert" )
Sam Hocevar's avatar
 
Sam Hocevar committed
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
MODULE_INIT_STOP

MODULE_ACTIVATE_START
    vout_getfunctions( &p_module->p_functions->vout );
MODULE_ACTIVATE_STOP

MODULE_DEACTIVATE_START
MODULE_DEACTIVATE_STOP

/*****************************************************************************
 * vout_sys_t: Invert video output method descriptor
 *****************************************************************************
 * This structure is part of the video output thread descriptor.
 * It describes the Invert specific properties of an output thread.
 *****************************************************************************/
68
struct vout_sys_s
Sam Hocevar's avatar
 
Sam Hocevar committed
69
{
70 71
    vout_thread_t *p_vout;
};
Sam Hocevar's avatar
 
Sam Hocevar committed
72 73 74 75

/*****************************************************************************
 * Local prototypes
 *****************************************************************************/
76 77 78 79 80 81 82
static int  vout_Create    ( vout_thread_t * );
static int  vout_Init      ( vout_thread_t * );
static void vout_End       ( vout_thread_t * );
static void vout_Destroy   ( vout_thread_t * );
static int  vout_Manage    ( vout_thread_t * );
static void vout_Render    ( vout_thread_t *, picture_t * );
static void vout_Display   ( vout_thread_t *, picture_t * );
Sam Hocevar's avatar
 
Sam Hocevar committed
83 84 85 86 87 88 89 90 91 92 93 94

/*****************************************************************************
 * Functions exported as capabilities. They are declared as static so that
 * we don't pollute the namespace too much.
 *****************************************************************************/
static void vout_getfunctions( function_list_t * p_function_list )
{
    p_function_list->functions.vout.pf_create     = vout_Create;
    p_function_list->functions.vout.pf_init       = vout_Init;
    p_function_list->functions.vout.pf_end        = vout_End;
    p_function_list->functions.vout.pf_destroy    = vout_Destroy;
    p_function_list->functions.vout.pf_manage     = vout_Manage;
Sam Hocevar's avatar
 
Sam Hocevar committed
95
    p_function_list->functions.vout.pf_render     = vout_Render;
Sam Hocevar's avatar
 
Sam Hocevar committed
96 97 98 99 100 101 102 103 104 105 106 107 108 109
    p_function_list->functions.vout.pf_display    = vout_Display;
}

/*****************************************************************************
 * vout_Create: allocates Invert video thread output method
 *****************************************************************************
 * This function allocates and initializes a Invert vout method.
 *****************************************************************************/
static int vout_Create( vout_thread_t *p_vout )
{
    /* Allocate structure */
    p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
    if( p_vout->p_sys == NULL )
    {
110
        msg_Err( p_vout, "out of memory" );
Sam Hocevar's avatar
 
Sam Hocevar committed
111 112 113 114 115 116 117 118 119 120 121 122 123
        return( 1 );
    }

    return( 0 );
}

/*****************************************************************************
 * vout_Init: initialize Invert video thread output method
 *****************************************************************************/
static int vout_Init( vout_thread_t *p_vout )
{
    int i_index;
    picture_t *p_pic;
Gildas Bazin's avatar
 
Gildas Bazin committed
124

Sam Hocevar's avatar
 
Sam Hocevar committed
125 126
    I_OUTPUTPICTURES = 0;

Sam Hocevar's avatar
 
Sam Hocevar committed
127
    /* Initialize the output structure */
Sam Hocevar's avatar
 
Sam Hocevar committed
128 129 130 131
    p_vout->output.i_chroma = p_vout->render.i_chroma;
    p_vout->output.i_width  = p_vout->render.i_width;
    p_vout->output.i_height = p_vout->render.i_height;
    p_vout->output.i_aspect = p_vout->render.i_aspect;
Sam Hocevar's avatar
 
Sam Hocevar committed
132

Sam Hocevar's avatar
 
Sam Hocevar committed
133
    /* Try to open the real video output */
134
    msg_Dbg( p_vout, "spawning the real video output" );
Gildas Bazin's avatar
 
Gildas Bazin committed
135

Sam Hocevar's avatar
 
Sam Hocevar committed
136
    p_vout->p_sys->p_vout =
137
        vout_CreateThread( p_vout,
Sam Hocevar's avatar
 
Sam Hocevar committed
138 139 140 141 142 143
                           p_vout->render.i_width, p_vout->render.i_height,
                           p_vout->render.i_chroma, p_vout->render.i_aspect );

    /* Everything failed */
    if( p_vout->p_sys->p_vout == NULL )
    {
144
        msg_Err( p_vout, "can't open vout, aborting" );
Sam Hocevar's avatar
 
Sam Hocevar committed
145 146 147 148

        return( 0 );
    }
 
Sam Hocevar's avatar
 
Sam Hocevar committed
149
    ALLOCATE_DIRECTBUFFERS( VOUT_MAX_PICTURES );
Sam Hocevar's avatar
 
Sam Hocevar committed
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164

    return( 0 );
}

/*****************************************************************************
 * vout_End: terminate Invert video thread output method
 *****************************************************************************/
static void vout_End( vout_thread_t *p_vout )
{
    int i_index;

    /* Free the fake output buffers we allocated */
    for( i_index = I_OUTPUTPICTURES ; i_index ; )
    {
        i_index--;
Gildas Bazin's avatar
 
Gildas Bazin committed
165
        free( PP_OUTPUTPICTURE[ i_index ]->p_data_orig );
Sam Hocevar's avatar
 
Sam Hocevar committed
166 167 168 169 170 171 172 173 174 175
    }
}

/*****************************************************************************
 * vout_Destroy: destroy Invert video thread output method
 *****************************************************************************
 * Terminate an output method created by InvertCreateOutputMethod
 *****************************************************************************/
static void vout_Destroy( vout_thread_t *p_vout )
{
176
    vout_DestroyThread( p_vout->p_sys->p_vout );
Sam Hocevar's avatar
 
Sam Hocevar committed
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192

    free( p_vout->p_sys );
}

/*****************************************************************************
 * vout_Manage: handle Invert events
 *****************************************************************************
 * This function should be called regularly by video output thread. It manages
 * console events. It returns a non null value on error.
 *****************************************************************************/
static int vout_Manage( vout_thread_t *p_vout )
{
    return( 0 );
}

/*****************************************************************************
Sam Hocevar's avatar
 
Sam Hocevar committed
193
 * vout_Render: displays previously rendered output
Sam Hocevar's avatar
 
Sam Hocevar committed
194 195 196 197 198
 *****************************************************************************
 * This function send the currently rendered image to Invert image, waits
 * until it is displayed and switch the two rendering buffers, preparing next
 * frame.
 *****************************************************************************/
Sam Hocevar's avatar
 
Sam Hocevar committed
199
static void vout_Render( vout_thread_t *p_vout, picture_t *p_pic )
Sam Hocevar's avatar
 
Sam Hocevar committed
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214
{
    picture_t *p_outpic;
    int i_index;

    /* This is a new frame. Get a structure from the video_output. */
    while( ( p_outpic = vout_CreatePicture( p_vout->p_sys->p_vout, 0, 0, 0 ) )
              == NULL )
    {
        if( p_vout->b_die || p_vout->b_error )
        {
            return;
        }
        msleep( VOUT_OUTMEM_SLEEP );
    }   

Sam Hocevar's avatar
 
Sam Hocevar committed
215
    vout_DatePicture( p_vout->p_sys->p_vout, p_outpic, p_pic->date );
Sam Hocevar's avatar
 
Sam Hocevar committed
216 217 218 219
    vout_LinkPicture( p_vout->p_sys->p_vout, p_outpic );

    for( i_index = 0 ; i_index < p_pic->i_planes ; i_index++ )
    {
Sam Hocevar's avatar
 
Sam Hocevar committed
220
        u8 *p_in, *p_in_end, *p_out;
Sam Hocevar's avatar
 
Sam Hocevar committed
221

Sam Hocevar's avatar
 
Sam Hocevar committed
222 223 224
        p_in = p_pic->p[i_index].p_pixels;
        p_in_end = p_in - 64 + p_pic->p[i_index].i_lines
                                * p_pic->p[i_index].i_pitch;
Sam Hocevar's avatar
 
Sam Hocevar committed
225

Sam Hocevar's avatar
 
Sam Hocevar committed
226
        p_out = p_outpic->p[i_index].p_pixels;
Sam Hocevar's avatar
 
Sam Hocevar committed
227

Sam Hocevar's avatar
 
Sam Hocevar committed
228
        for( ; p_in < p_in_end ; )
Sam Hocevar's avatar
 
Sam Hocevar committed
229
        {
Sam Hocevar's avatar
 
Sam Hocevar committed
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245
            /* Do 64 pixels at a time */
            *((u64*)p_out)++ = ~( *((u64*)p_in)++ );
            *((u64*)p_out)++ = ~( *((u64*)p_in)++ );
            *((u64*)p_out)++ = ~( *((u64*)p_in)++ );
            *((u64*)p_out)++ = ~( *((u64*)p_in)++ );
            *((u64*)p_out)++ = ~( *((u64*)p_in)++ );
            *((u64*)p_out)++ = ~( *((u64*)p_in)++ );
            *((u64*)p_out)++ = ~( *((u64*)p_in)++ );
            *((u64*)p_out)++ = ~( *((u64*)p_in)++ );
        }

        p_in_end += 64;

        for( ; p_in < p_in_end ; )
        {
            /* Do 1 pixel at a time */
Sam Hocevar's avatar
 
Sam Hocevar committed
246 247 248 249 250 251 252 253 254
            *p_out++ = ~( *p_in++ );
        }
    }

    vout_UnlinkPicture( p_vout->p_sys->p_vout, p_outpic );

    vout_DisplayPicture( p_vout->p_sys->p_vout, p_outpic );
}

Sam Hocevar's avatar
 
Sam Hocevar committed
255 256 257 258 259 260 261 262 263 264 265 266
/*****************************************************************************
 * vout_Display: displays previously rendered output
 *****************************************************************************
 * This function send the currently rendered image to Invert image, waits
 * until it is displayed and switch the two rendering buffers, preparing next
 * frame.
 *****************************************************************************/
static void vout_Display( vout_thread_t *p_vout, picture_t *p_pic )
{
    ;
}