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