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 *****************************************************************************/
32 #include "vlc_filter.h"
34 /*****************************************************************************
36 *****************************************************************************/
37 static int Create ( vlc_object_t * );
38 static void Destroy ( vlc_object_t * );
40 static picture_t *Filter( filter_t *, picture_t * );
42 /*****************************************************************************
44 *****************************************************************************/
46 set_description( _("Invert video filter") );
47 set_shortname( _("Color inversion" ));
48 set_category( CAT_VIDEO );
49 set_subcategory( SUBCAT_VIDEO_VFILTER );
50 set_capability( "video filter2", 0 );
51 add_shortcut( "invert" );
52 set_callbacks( Create, Destroy );
55 /*****************************************************************************
56 * vout_sys_t: Invert video output method descriptor
57 *****************************************************************************
58 * This structure is part of the video output thread descriptor.
59 * It describes the Invert specific properties of an output thread.
60 *****************************************************************************/
65 /*****************************************************************************
66 * Create: allocates Invert video thread output method
67 *****************************************************************************
68 * This function allocates and initializes a Invert vout method.
69 *****************************************************************************/
70 static int Create( vlc_object_t *p_this )
72 filter_t *p_filter = (filter_t *)p_this;
74 /* Allocate structure */
75 p_filter->p_sys = malloc( sizeof( filter_sys_t ) );
76 if( p_filter->p_sys == NULL )
78 msg_Err( p_filter, "out of memory" );
82 p_filter->pf_video_filter = Filter;
87 /*****************************************************************************
88 * Destroy: destroy Invert video thread output method
89 *****************************************************************************
90 * Terminate an output method created by InvertCreateOutputMethod
91 *****************************************************************************/
92 static void Destroy( vlc_object_t *p_this )
94 filter_t *p_filter = (filter_t *)p_this;
96 free( p_filter->p_sys );
99 /*****************************************************************************
100 * Render: displays previously rendered output
101 *****************************************************************************
102 * This function send the currently rendered image to Invert image, waits
103 * until it is displayed and switch the two rendering buffers, preparing next
105 *****************************************************************************/
106 static picture_t *Filter( filter_t *p_filter, picture_t *p_pic )
112 if( !p_pic ) return NULL;
114 p_outpic = p_filter->pf_vout_buffer_new( p_filter );
117 msg_Warn( p_filter, "can't get output picture" );
118 if( p_pic->pf_release )
119 p_pic->pf_release( p_pic );
123 if( p_pic->format.i_chroma == VLC_FOURCC('Y','U','V','A') )
125 /* We don't want to invert the alpha plane */
126 i_planes = p_pic->i_planes - 1;
127 p_filter->p_libvlc->pf_memcpy(
128 p_outpic->p[A_PLANE].p_pixels, p_pic->p[A_PLANE].p_pixels,
129 p_pic->p[A_PLANE].i_pitch * p_pic->p[A_PLANE].i_lines );
133 i_planes = p_pic->i_planes;
136 for( i_index = 0 ; i_index < i_planes ; i_index++ )
138 uint8_t *p_in, *p_in_end, *p_line_end, *p_out;
140 p_in = p_pic->p[i_index].p_pixels;
141 p_in_end = p_in + p_pic->p[i_index].i_visible_lines
142 * p_pic->p[i_index].i_pitch;
144 p_out = p_outpic->p[i_index].p_pixels;
146 for( ; p_in < p_in_end ; )
148 uint64_t *p_in64, *p_out64;
150 p_line_end = p_in + p_pic->p[i_index].i_visible_pitch - 64;
152 p_in64 = (uint64_t*)p_in;
153 p_out64 = (uint64_t*)p_out;
155 for( ; (ptrdiff_t)p_in64 < (ptrdiff_t)p_line_end ; )
157 /* Do 64 pixels at a time */
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 *p_out64++ = ~*p_in64++; *p_out64++ = ~*p_in64++;
164 p_in = (uint8_t*)p_in64;
165 p_out = (uint8_t*)p_out64;
168 for( ; p_in < p_line_end ; )
170 *p_out++ = ~( *p_in++ );
173 p_in += p_pic->p[i_index].i_pitch
174 - p_pic->p[i_index].i_visible_pitch;
175 p_out += p_outpic->p[i_index].i_pitch
176 - p_outpic->p[i_index].i_visible_pitch;
180 p_outpic->date = p_pic->date;
181 p_outpic->b_force = p_pic->b_force;
182 p_outpic->i_nb_fields = p_pic->i_nb_fields;
183 p_outpic->b_progressive = p_pic->b_progressive;
184 p_outpic->b_top_field_first = p_pic->b_top_field_first;
186 if( p_pic->pf_release )
187 p_pic->pf_release( p_pic );