1 /*****************************************************************************
2 * invert.c : Invert video plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2000-2006 the VideoLAN team
7 * Authors: Samuel Hocevar <sam@zoy.org>
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.
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.
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 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
35 #include "vlc_filter.h"
37 /*****************************************************************************
39 *****************************************************************************/
40 static int Create ( vlc_object_t * );
41 static void Destroy ( vlc_object_t * );
43 static picture_t *Filter( filter_t *, picture_t * );
45 /*****************************************************************************
47 *****************************************************************************/
49 set_description( _("Invert video filter") );
50 set_shortname( _("Color inversion" ));
51 set_category( CAT_VIDEO );
52 set_subcategory( SUBCAT_VIDEO_VFILTER );
53 set_capability( "video filter2", 0 );
54 add_shortcut( "invert" );
55 set_callbacks( Create, Destroy );
58 /*****************************************************************************
59 * vout_sys_t: Invert video output method descriptor
60 *****************************************************************************
61 * This structure is part of the video output thread descriptor.
62 * It describes the Invert specific properties of an output thread.
63 *****************************************************************************/
68 /*****************************************************************************
69 * Create: allocates Invert video thread output method
70 *****************************************************************************
71 * This function allocates and initializes a Invert vout method.
72 *****************************************************************************/
73 static int Create( vlc_object_t *p_this )
75 filter_t *p_filter = (filter_t *)p_this;
77 /* Allocate structure */
78 p_filter->p_sys = malloc( sizeof( filter_sys_t ) );
79 if( p_filter->p_sys == NULL )
81 msg_Err( p_filter, "out of memory" );
85 p_filter->pf_video_filter = Filter;
90 /*****************************************************************************
91 * Destroy: destroy Invert video thread output method
92 *****************************************************************************
93 * Terminate an output method created by InvertCreateOutputMethod
94 *****************************************************************************/
95 static void Destroy( vlc_object_t *p_this )
97 filter_t *p_filter = (filter_t *)p_this;
99 free( p_filter->p_sys );
102 /*****************************************************************************
103 * Render: displays previously rendered output
104 *****************************************************************************
105 * This function send the currently rendered image to Invert image, waits
106 * until it is displayed and switch the two rendering buffers, preparing next
108 *****************************************************************************/
109 static picture_t *Filter( filter_t *p_filter, picture_t *p_pic )
115 if( !p_pic ) return NULL;
117 p_outpic = p_filter->pf_vout_buffer_new( p_filter );
120 msg_Warn( p_filter, "can't get output picture" );
121 if( p_pic->pf_release )
122 p_pic->pf_release( p_pic );
126 if( p_pic->format.i_chroma == VLC_FOURCC('Y','U','V','A') )
128 /* We don't want to invert the alpha plane */
129 i_planes = p_pic->i_planes - 1;
131 p_outpic->p[A_PLANE].p_pixels, p_pic->p[A_PLANE].p_pixels,
132 p_pic->p[A_PLANE].i_pitch * p_pic->p[A_PLANE].i_lines );
136 i_planes = p_pic->i_planes;
139 for( i_index = 0 ; i_index < i_planes ; i_index++ )
141 uint8_t *p_in, *p_in_end, *p_line_end, *p_out;
143 p_in = p_pic->p[i_index].p_pixels;
144 p_in_end = p_in + p_pic->p[i_index].i_visible_lines
145 * p_pic->p[i_index].i_pitch;
147 p_out = p_outpic->p[i_index].p_pixels;
149 for( ; p_in < p_in_end ; )
151 uint64_t *p_in64, *p_out64;
153 p_line_end = p_in + p_pic->p[i_index].i_visible_pitch - 64;
155 p_in64 = (uint64_t*)p_in;
156 p_out64 = (uint64_t*)p_out;
158 while( p_in64 < (uint64_t *)p_line_end )
160 /* Do 64 pixels at a time */
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 *p_out64++ = ~*p_in64++; *p_out64++ = ~*p_in64++;
167 p_in = (uint8_t*)p_in64;
168 p_out = (uint8_t*)p_out64;
171 for( ; p_in < p_line_end ; )
173 *p_out++ = ~( *p_in++ );
176 p_in += p_pic->p[i_index].i_pitch
177 - p_pic->p[i_index].i_visible_pitch;
178 p_out += p_outpic->p[i_index].i_pitch
179 - p_outpic->p[i_index].i_visible_pitch;
183 p_outpic->date = p_pic->date;
184 p_outpic->b_force = p_pic->b_force;
185 p_outpic->i_nb_fields = p_pic->i_nb_fields;
186 p_outpic->b_progressive = p_pic->b_progressive;
187 p_outpic->b_top_field_first = p_pic->b_top_field_first;
189 if( p_pic->pf_release )
190 p_pic->pf_release( p_pic );