1 /*****************************************************************************
2 * yuv.c : YUV plans modifier video plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2000, 2001 VideoLAN
5 * $Id: yuv.c,v 1.1 2002/10/26 01:08:13 garf Exp $
7 * Authors: Simon Latapie <garf@via.ecp.fr>, 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., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
28 #include <stdlib.h> /* malloc(), free() */
34 #include "filter_common.h"
36 /*****************************************************************************
38 *****************************************************************************/
39 static int Create ( vlc_object_t * );
40 static void Destroy ( vlc_object_t * );
42 static int Init ( vout_thread_t * );
43 static void End ( vout_thread_t * );
44 static void Render ( vout_thread_t *, picture_t * );
46 /*****************************************************************************
48 *****************************************************************************/
50 #define Y_TEXT N_("Y plan modifier")
51 #define Y_LONGTEXT N_("between 0 and 255, default to 255")
52 #define Y_INV_TEXT N_("invert Y plan")
53 #define Y_INV_LONGTEXT N_("same function as invert filter")
55 #define U_TEXT N_("U plan modifier")
56 #define U_LONGTEXT N_("between 0 and 255, default to 255")
57 #define U_INV_TEXT N_("invert U plan")
58 #define U_INV_LONGTEXT N_("same function as invert filter")
60 #define V_TEXT N_("V plan modifier")
61 #define V_LONGTEXT N_("between 0 and 255, default to 255")
62 #define V_INV_TEXT N_("invert V plan")
63 #define V_INV_LONGTEXT N_("same function as invert filter")
66 add_category_hint( N_("Miscellaneous"), NULL );
67 add_integer( "Y plan", 255, NULL, Y_TEXT, Y_LONGTEXT );
68 add_bool( "invert Y", 0, NULL, Y_INV_TEXT, Y_INV_LONGTEXT );
69 add_integer( "U plan", 255, NULL, U_TEXT, U_LONGTEXT );
70 add_bool( "invert U", 0, NULL, U_INV_TEXT, U_INV_LONGTEXT );
71 add_integer( "V plan", 255, NULL, V_TEXT, V_LONGTEXT );
72 add_bool( "invert V", 0, NULL, V_INV_TEXT, V_INV_LONGTEXT );
73 set_description( _("yuv plan modifier filter") );
74 set_capability( "video filter", 0 );
75 add_shortcut( "yuv" );
76 set_callbacks( Create, Destroy );
79 /*****************************************************************************
80 * vout_sys_t: YUV video output method descriptor
81 *****************************************************************************
82 * This structure is part of the video output thread descriptor.
83 * It describes the YUV specific properties of an output thread.
84 *****************************************************************************/
88 vlc_bool_t b_invert[3];
89 vout_thread_t *p_vout;
92 /*****************************************************************************
93 * Create: allocates YUV video thread output method
94 *****************************************************************************
95 * This function allocates and initializes a YUV vout method.
96 *****************************************************************************/
97 static int Create( vlc_object_t *p_this )
99 vout_thread_t *p_vout = (vout_thread_t *)p_this;
101 /* Allocate structure */
102 p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
103 if( p_vout->p_sys == NULL )
105 msg_Err( p_vout, "out of memory" );
109 p_vout->pf_init = Init;
110 p_vout->pf_end = End;
111 p_vout->pf_manage = NULL;
112 p_vout->pf_render = Render;
113 p_vout->pf_display = NULL;
118 /*****************************************************************************
119 * Init: initialize YUV video thread output method
120 *****************************************************************************/
121 static int Init( vout_thread_t *p_vout )
126 I_OUTPUTPICTURES = 0;
128 /* Initialize the output structure */
129 p_vout->output.i_chroma = p_vout->render.i_chroma;
130 p_vout->output.i_width = p_vout->render.i_width;
131 p_vout->output.i_height = p_vout->render.i_height;
132 p_vout->output.i_aspect = p_vout->render.i_aspect;
134 /* Try to open the real video output */
135 msg_Dbg( p_vout, "spawning the real video output" );
137 p_vout->p_sys->p_vout =
138 vout_CreateThread( p_vout,
139 p_vout->render.i_width, p_vout->render.i_height,
140 p_vout->render.i_chroma, p_vout->render.i_aspect );
142 /* Everything failed */
143 if( p_vout->p_sys->p_vout == NULL )
145 msg_Err( p_vout, "can't open vout, aborting" );
150 ALLOCATE_DIRECTBUFFERS( VOUT_MAX_PICTURES );
155 /*****************************************************************************
156 * End: terminate YUV video thread output method
157 *****************************************************************************/
158 static void End( vout_thread_t *p_vout )
162 /* Free the fake output buffers we allocated */
163 for( i_index = I_OUTPUTPICTURES ; i_index ; )
166 free( PP_OUTPUTPICTURE[ i_index ]->p_data_orig );
170 /*****************************************************************************
171 * Destroy: destroy YUV video thread output method
172 *****************************************************************************
173 * Terminate an output method created by YUVCreateOutputMethod
174 *****************************************************************************/
175 static void Destroy( vlc_object_t *p_this )
177 vout_thread_t *p_vout = (vout_thread_t *)p_this;
179 vout_DestroyThread( p_vout->p_sys->p_vout );
181 free( p_vout->p_sys );
184 /*****************************************************************************
185 * Render: displays previously rendered output
186 *****************************************************************************
187 * This function send the currently rendered image to YUV modified image,
188 * waits until it is displayed and switch the two rendering buffers, preparing
190 *****************************************************************************/
191 static void Render( vout_thread_t *p_vout, picture_t *p_pic )
196 /* This is a new frame. Get a structure from the video_output. */
198 p_vout->p_sys->i_coeff[0] = config_GetInt( p_vout, "Y plan" ) ;
199 p_vout->p_sys->i_coeff[1] = config_GetInt( p_vout, "U plan" ) ;
200 p_vout->p_sys->i_coeff[2] = config_GetInt( p_vout, "V plan" ) ;
202 p_vout->p_sys->b_invert[0] = config_GetInt( p_vout, "invert Y" ) ;
203 p_vout->p_sys->b_invert[1] = config_GetInt( p_vout, "invert U" ) ;
204 p_vout->p_sys->b_invert[2] = config_GetInt( p_vout, "invert V" ) ;
206 while( ( p_outpic = vout_CreatePicture( p_vout->p_sys->p_vout, 0, 0, 0 ) )
209 if( p_vout->b_die || p_vout->b_error )
213 msleep( VOUT_OUTMEM_SLEEP );
216 vout_DatePicture( p_vout->p_sys->p_vout, p_outpic, p_pic->date );
217 vout_LinkPicture( p_vout->p_sys->p_vout, p_outpic );
219 for( i_index = 0 ; i_index < p_pic->i_planes ; i_index++ )
221 u8 *p_in, *p_in_end, *p_out;
225 i_coeff = p_vout->p_sys->i_coeff[i_index];
226 b_inv = p_vout->p_sys->b_invert[i_index];
227 p_in = p_pic->p[i_index].p_pixels;
228 p_in_end = p_in + p_pic->p[i_index].i_lines
229 * p_pic->p[i_index].i_pitch -8;
231 p_out = p_outpic->p[i_index].p_pixels;
233 for( ; p_in < p_in_end ; )
235 /* Do 8 pixels at a time */
236 *p_out = ( *p_in * i_coeff * (1 - 2 * b_inv)) >> 8; p_out++; p_in++;
237 *p_out = ( *p_in * i_coeff * (1 - 2 * b_inv)) >> 8; p_out++; p_in++;
238 *p_out = ( *p_in * i_coeff * (1 - 2 * b_inv)) >> 8; p_out++; p_in++;
239 *p_out = ( *p_in * i_coeff * (1 - 2 * b_inv)) >> 8; p_out++; p_in++;
240 *p_out = ( *p_in * i_coeff * (1 - 2 * b_inv)) >> 8; p_out++; p_in++;
241 *p_out = ( *p_in * i_coeff * (1 - 2 * b_inv)) >> 8; p_out++; p_in++;
242 *p_out = ( *p_in * i_coeff * (1 - 2 * b_inv)) >> 8; p_out++; p_in++;
243 *p_out = ( *p_in * i_coeff * (1 - 2 * b_inv)) >> 8; p_out++; p_in++;
248 for( ; p_in < p_in_end ; )
250 /* Do 1 pixel at a time */
251 *p_out = ( *p_in * i_coeff * (1 - 2 * b_inv)) >> 8; p_out++; p_in++;
255 vout_UnlinkPicture( p_vout->p_sys->p_vout, p_outpic );
257 vout_DisplayPicture( p_vout->p_sys->p_vout, p_outpic );