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_common.h>
33 #include <vlc_plugin.h>
35 #include "vlc_filter.h"
36 #include "filter_picture.h"
38 /*****************************************************************************
40 *****************************************************************************/
41 static int Create ( vlc_object_t * );
42 static void Destroy ( vlc_object_t * );
44 static picture_t *Filter( filter_t *, picture_t * );
46 /*****************************************************************************
48 *****************************************************************************/
50 set_description( N_("Invert video filter") )
51 set_shortname( N_("Color inversion" ))
52 set_category( CAT_VIDEO )
53 set_subcategory( SUBCAT_VIDEO_VFILTER )
54 set_capability( "video filter2", 0 )
55 add_shortcut( "invert" )
56 set_callbacks( Create, Destroy )
59 /*****************************************************************************
60 * filter_sys_t: Invert video output method descriptor
61 *****************************************************************************
62 * This structure is part of the video output thread descriptor.
63 * It describes the Invert specific properties of an output thread.
64 *****************************************************************************/
69 /*****************************************************************************
70 * Create: allocates Invert video thread output method
71 *****************************************************************************
72 * This function allocates and initializes a Invert vout method.
73 *****************************************************************************/
74 static int Create( vlc_object_t *p_this )
76 filter_t *p_filter = (filter_t *)p_this;
78 /* Allocate structure */
79 p_filter->p_sys = malloc( sizeof( filter_sys_t ) );
80 if( p_filter->p_sys == NULL )
83 p_filter->pf_video_filter = Filter;
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 )
95 filter_t *p_filter = (filter_t *)p_this;
97 free( p_filter->p_sys );
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
106 *****************************************************************************/
107 static picture_t *Filter( filter_t *p_filter, picture_t *p_pic )
113 if( !p_pic ) return NULL;
115 p_outpic = filter_NewPicture( p_filter );
118 msg_Warn( p_filter, "can't get output picture" );
119 picture_Release( p_pic );
123 if( p_pic->format.i_chroma == VLC_CODEC_YUVA )
125 /* We don't want to invert the alpha plane */
126 i_planes = p_pic->i_planes - 1;
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 while( p_in64 < (uint64_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 return CopyInfoAndRelease( p_outpic, p_pic );