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