]> git.sesse.net Git - vlc/blob - modules/video_filter/invert.c
Plugins: include vlc_common.h directly instead of vlc/vlc.h
[vlc] / modules / video_filter / invert.c
1 /*****************************************************************************
2  * invert.c : Invert video plugin for vlc
3  *****************************************************************************
4  * Copyright (C) 2000-2006 the VideoLAN team
5  * $Id$
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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27
28 #ifdef HAVE_CONFIG_H
29 # include "config.h"
30 #endif
31
32 #include <vlc_common.h>
33 #include <vlc_plugin.h>
34 #include <vlc_vout.h>
35
36 #include "vlc_filter.h"
37
38 /*****************************************************************************
39  * Local prototypes
40  *****************************************************************************/
41 static int  Create      ( vlc_object_t * );
42 static void Destroy     ( vlc_object_t * );
43
44 static picture_t *Filter( filter_t *, picture_t * );
45
46 /*****************************************************************************
47  * Module descriptor
48  *****************************************************************************/
49 vlc_module_begin();
50     set_description( N_("Invert video filter") );
51     set_shortname( N_("Color inversion" ));
52     set_category( CAT_VIDEO );
53     set_subcategory( SUBCAT_VIDEO_VFILTER );
54     set_capability( "video filter2", 0 );
55     add_shortcut( "invert" );
56     set_callbacks( Create, Destroy );
57 vlc_module_end();
58
59 /*****************************************************************************
60  * vout_sys_t: Invert video output method descriptor
61  *****************************************************************************
62  * This structure is part of the video output thread descriptor.
63  * It describes the Invert specific properties of an output thread.
64  *****************************************************************************/
65 struct filter_sys_t
66 {
67 };
68
69 /*****************************************************************************
70  * Create: allocates Invert video thread output method
71  *****************************************************************************
72  * This function allocates and initializes a Invert vout method.
73  *****************************************************************************/
74 static int Create( vlc_object_t *p_this )
75 {
76     filter_t *p_filter = (filter_t *)p_this;
77
78     /* Allocate structure */
79     p_filter->p_sys = malloc( sizeof( filter_sys_t ) );
80     if( p_filter->p_sys == NULL )
81     {
82         msg_Err( p_filter, "out of memory" );
83         return VLC_ENOMEM;
84     }
85
86     p_filter->pf_video_filter = Filter;
87
88     return VLC_SUCCESS;
89 }
90
91 /*****************************************************************************
92  * Destroy: destroy Invert video thread output method
93  *****************************************************************************
94  * Terminate an output method created by InvertCreateOutputMethod
95  *****************************************************************************/
96 static void Destroy( vlc_object_t *p_this )
97 {
98     filter_t *p_filter = (filter_t *)p_this;
99
100     free( p_filter->p_sys );
101 }
102
103 /*****************************************************************************
104  * Render: displays previously rendered output
105  *****************************************************************************
106  * This function send the currently rendered image to Invert image, waits
107  * until it is displayed and switch the two rendering buffers, preparing next
108  * frame.
109  *****************************************************************************/
110 static picture_t *Filter( filter_t *p_filter, picture_t *p_pic )
111 {
112     picture_t *p_outpic;
113     int i_index;
114     int i_planes;
115
116     if( !p_pic ) return NULL;
117
118     p_outpic = p_filter->pf_vout_buffer_new( p_filter );
119     if( !p_outpic )
120     {
121         msg_Warn( p_filter, "can't get output picture" );
122         if( p_pic->pf_release )
123             p_pic->pf_release( p_pic );
124         return NULL;
125     }
126
127     if( p_pic->format.i_chroma == VLC_FOURCC('Y','U','V','A') )
128     {
129         /* We don't want to invert the alpha plane */
130         i_planes = p_pic->i_planes - 1;
131         vlc_memcpy(
132             p_outpic->p[A_PLANE].p_pixels, p_pic->p[A_PLANE].p_pixels,
133             p_pic->p[A_PLANE].i_pitch *  p_pic->p[A_PLANE].i_lines );
134     }
135     else
136     {
137         i_planes = p_pic->i_planes;
138     }
139
140     for( i_index = 0 ; i_index < i_planes ; i_index++ )
141     {
142         uint8_t *p_in, *p_in_end, *p_line_end, *p_out;
143
144         p_in = p_pic->p[i_index].p_pixels;
145         p_in_end = p_in + p_pic->p[i_index].i_visible_lines
146                            * p_pic->p[i_index].i_pitch;
147
148         p_out = p_outpic->p[i_index].p_pixels;
149
150         for( ; p_in < p_in_end ; )
151         {
152             uint64_t *p_in64, *p_out64;
153
154             p_line_end = p_in + p_pic->p[i_index].i_visible_pitch - 64;
155
156             p_in64 = (uint64_t*)p_in;
157             p_out64 = (uint64_t*)p_out;
158
159             while( p_in64 < (uint64_t *)p_line_end )
160             {
161                 /* Do 64 pixels at a time */
162                 *p_out64++ = ~*p_in64++; *p_out64++ = ~*p_in64++;
163                 *p_out64++ = ~*p_in64++; *p_out64++ = ~*p_in64++;
164                 *p_out64++ = ~*p_in64++; *p_out64++ = ~*p_in64++;
165                 *p_out64++ = ~*p_in64++; *p_out64++ = ~*p_in64++;
166             }
167
168             p_in = (uint8_t*)p_in64;
169             p_out = (uint8_t*)p_out64;
170             p_line_end += 64;
171
172             for( ; p_in < p_line_end ; )
173             {
174                 *p_out++ = ~( *p_in++ );
175             }
176
177             p_in += p_pic->p[i_index].i_pitch
178                      - p_pic->p[i_index].i_visible_pitch;
179             p_out += p_outpic->p[i_index].i_pitch
180                      - p_outpic->p[i_index].i_visible_pitch;
181         }
182     }
183
184     p_outpic->date = p_pic->date;
185     p_outpic->b_force = p_pic->b_force;
186     p_outpic->i_nb_fields = p_pic->i_nb_fields;
187     p_outpic->b_progressive = p_pic->b_progressive;
188     p_outpic->b_top_field_first = p_pic->b_top_field_first;
189
190     if( p_pic->pf_release )
191         p_pic->pf_release( p_pic );
192
193     return p_outpic;
194 }