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