A little more detail regarding using my github copies of the code with where it's...
[vlc/adversarial.git] / modules / video_filter / invert.c
blob3303030f501e07b08b3f729a6f16a1bff346ab36
1 /*****************************************************************************
2 * invert.c : Invert video plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2000-2006 VLC authors and VideoLAN
5 * $Id$
7 * Authors: Samuel Hocevar <sam@zoy.org>
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU Lesser General Public License as published by
11 * the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public License
20 * along with this program; if not, write to the Free Software Foundation,
21 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 /*****************************************************************************
25 * Preamble
26 *****************************************************************************/
28 #ifdef HAVE_CONFIG_H
29 # include "config.h"
30 #endif
32 #include <vlc_common.h>
33 #include <vlc_plugin.h>
35 #include <vlc_filter.h>
36 #include "filter_picture.h"
38 /*****************************************************************************
39 * Local prototypes
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 /*****************************************************************************
47 * Module descriptor
48 *****************************************************************************/
49 vlc_module_begin ()
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 )
57 vlc_module_end ()
59 /*****************************************************************************
60 * Create: allocates Invert video thread output method
61 *****************************************************************************
62 * This function allocates and initializes a Invert vout method.
63 *****************************************************************************/
64 static int Create( vlc_object_t *p_this )
66 filter_t *p_filter = (filter_t *)p_this;
67 vlc_fourcc_t fourcc = p_filter->fmt_in.video.i_chroma;
69 if( fourcc == VLC_CODEC_YUVP || fourcc == VLC_CODEC_RGBP
70 || fourcc == VLC_CODEC_RGBA || fourcc == VLC_CODEC_ARGB )
71 return VLC_EGENERIC;
73 const vlc_chroma_description_t *p_chroma =
74 vlc_fourcc_GetChromaDescription( fourcc );
75 if( p_chroma == NULL || p_chroma->plane_count == 0
76 || p_chroma->pixel_size * 8 != p_chroma->pixel_bits )
77 return VLC_EGENERIC;
79 p_filter->pf_video_filter = Filter;
80 return VLC_SUCCESS;
83 /*****************************************************************************
84 * Destroy: destroy Invert video thread output method
85 *****************************************************************************
86 * Terminate an output method created by InvertCreateOutputMethod
87 *****************************************************************************/
88 static void Destroy( vlc_object_t *p_this )
90 (void)p_this;
93 /*****************************************************************************
94 * Render: displays previously rendered output
95 *****************************************************************************
96 * This function send the currently rendered image to Invert image, waits
97 * until it is displayed and switch the two rendering buffers, preparing next
98 * frame.
99 *****************************************************************************/
100 static picture_t *Filter( filter_t *p_filter, picture_t *p_pic )
102 picture_t *p_outpic;
103 int i_index;
104 int i_planes;
106 if( !p_pic ) return NULL;
108 p_outpic = filter_NewPicture( p_filter );
109 if( !p_outpic )
111 msg_Warn( p_filter, "can't get output picture" );
112 picture_Release( p_pic );
113 return NULL;
116 if( p_pic->format.i_chroma == VLC_CODEC_YUVA )
118 /* We don't want to invert the alpha plane */
119 i_planes = p_pic->i_planes - 1;
120 memcpy(
121 p_outpic->p[A_PLANE].p_pixels, p_pic->p[A_PLANE].p_pixels,
122 p_pic->p[A_PLANE].i_pitch * p_pic->p[A_PLANE].i_lines );
124 else
126 i_planes = p_pic->i_planes;
129 for( i_index = 0 ; i_index < i_planes ; i_index++ )
131 uint8_t *p_in, *p_in_end, *p_line_end, *p_out;
133 p_in = p_pic->p[i_index].p_pixels;
134 p_in_end = p_in + p_pic->p[i_index].i_visible_lines
135 * p_pic->p[i_index].i_pitch;
137 p_out = p_outpic->p[i_index].p_pixels;
139 for( ; p_in < p_in_end ; )
141 uint64_t *p_in64, *p_out64;
143 p_line_end = p_in + p_pic->p[i_index].i_visible_pitch - 64;
145 p_in64 = (uint64_t*)p_in;
146 p_out64 = (uint64_t*)p_out;
148 while( p_in64 < (uint64_t *)p_line_end )
150 /* Do 64 pixels at a time */
151 *p_out64++ = ~*p_in64++; *p_out64++ = ~*p_in64++;
152 *p_out64++ = ~*p_in64++; *p_out64++ = ~*p_in64++;
153 *p_out64++ = ~*p_in64++; *p_out64++ = ~*p_in64++;
154 *p_out64++ = ~*p_in64++; *p_out64++ = ~*p_in64++;
157 p_in = (uint8_t*)p_in64;
158 p_out = (uint8_t*)p_out64;
159 p_line_end += 64;
161 for( ; p_in < p_line_end ; )
163 *p_out++ = ~( *p_in++ );
166 p_in += p_pic->p[i_index].i_pitch
167 - p_pic->p[i_index].i_visible_pitch;
168 p_out += p_outpic->p[i_index].i_pitch
169 - p_outpic->p[i_index].i_visible_pitch;
173 return CopyInfoAndRelease( p_outpic, p_pic );