Patch by Cedric Cocquebert to improve the panoramix module.
[vlc.git] / modules / video_filter / panoramix.c
1 /*****************************************************************************
2  * panoramix.c : Wall panoramic video with edge blending plugin for vlc
3  *****************************************************************************
4  * Copyright (C) 2000, 2001, 2002, 2003 VideoLAN
5  * $Id: panoramix.c  2006-08-29 16:20:15Z ced $
6  *
7  * Authors: Cedric Cocquebert <cedric.cocquebert@supelec.fr>
8  *          based on Samuel Hocevar <sam@zoy.org>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
23  *****************************************************************************/
24
25 /*****************************************************************************
26  * Preamble
27  *****************************************************************************/
28 #include <stdlib.h>                                      /* malloc(), free() */
29 #include <string.h>
30
31 #include <vlc/vlc.h>
32 #include <vlc_vout.h>
33
34 #include "filter_common.h"
35
36 // add by cedric.cocquebert@supelec.fr
37 #define OVERLAP        2350
38 #ifdef OVERLAP
39     #include <math.h>
40     // OS CODE DEPENDANT to get display dimensions
41     #ifdef SYS_MINGW32
42         #include <windows.h>
43     #else 
44         #include <X11/Xlib.h>   
45     #endif
46     #define GAMMA        1
47 //  #define PACKED_YUV    1
48     #define F2(a) ((a)*(a))
49     #define F4(a,b,x) ((a)*(F2(x))+((b)*(x)))
50     #define ACCURACY 1000
51     #define RATIO_MAX 2500
52     #define CLIP_01(a) (a < 0.0 ? 0.0 : (a > 1.0 ? 1.0 : a))
53 //    #define CLIP_0A(a) (a < 0.0 ? 0.0 : (a > ACCURACY ? ACCURACY : a))
54 #endif
55
56 /*****************************************************************************
57  * Local prototypes
58  *****************************************************************************/
59 static int  Create    ( vlc_object_t * );
60 static void Destroy   ( vlc_object_t * );
61
62 static int  Init      ( vout_thread_t * );
63 static void End       ( vout_thread_t * );
64 #ifdef PACKED_YUV
65 static void RenderPackedYUV   ( vout_thread_t *, picture_t * );
66 #endif
67 static void RenderPlanarYUV   ( vout_thread_t *, picture_t * );
68 static void RenderPackedRGB   ( vout_thread_t *, picture_t * );
69
70 static void RemoveAllVout  ( vout_thread_t *p_vout );
71
72 static int  SendEvents( vlc_object_t *, char const *,
73                         vlc_value_t, vlc_value_t, void * );
74
75 /*****************************************************************************
76  * Module descriptor
77  *****************************************************************************/
78 #define COLS_TEXT N_("Number of columns")
79 #define COLS_LONGTEXT N_("Select the number of horizontal video windows in " \
80     "which to split the video")
81
82 #define ROWS_TEXT N_("Number of rows")
83 #define ROWS_LONGTEXT N_("Select the number of vertical video windows in " \
84     "which to split the video")
85
86 #define ACTIVE_TEXT N_("Active windows")
87 #define ACTIVE_LONGTEXT N_("Comma separated list of active windows, " \
88     "defaults to all")
89
90 vlc_module_begin();
91     set_description( N_("Panoramix: wall with overlap video filter") );
92     set_shortname( _("Panoramix" ));
93     set_capability( "video filter", 0 );
94     set_category( CAT_VIDEO );
95     set_subcategory( SUBCAT_VIDEO_VFILTER );
96
97     add_integer( "panoramix-cols", -1, NULL, COLS_TEXT, COLS_LONGTEXT, VLC_TRUE );
98     add_integer( "panoramix-rows", -1, NULL, ROWS_TEXT, ROWS_LONGTEXT, VLC_TRUE );
99
100 #ifdef OVERLAP
101 #define OFFSET_X_TEXT N_("Offset X offset (automatic compensation)")
102 #define OFFSET_X_LONGTEXT N_("Select if you want an automatic offset in horizontal (in case of misalignment due to autoratio control)")
103     add_bool( "offset-x", 1, NULL, OFFSET_X_TEXT, OFFSET_X_LONGTEXT, VLC_TRUE );
104
105 #define LENGTH_TEXT N_("length of the overlapping area (in %)")
106 #define LENGTH_LONGTEXT N_("Select in percent the length of the blended zone")
107     add_integer_with_range( "bz-length", 100, 0, 100, NULL, LENGTH_TEXT, LENGTH_LONGTEXT, VLC_TRUE );
108
109 #define HEIGHT_TEXT N_("height of the overlapping area (in %)")
110 #define HEIGHT_LONGTEXT N_("Select in percent the height of the blended zone (case of 2x2 wall)")
111     add_integer_with_range( "bz-height", 100, 0, 100, NULL, HEIGHT_TEXT, HEIGHT_LONGTEXT, VLC_TRUE );
112
113 #define ATTENUATION_TEXT N_("Attenuation")
114 #define ATTENUATION_LONGTEXT N_("Check this option if you want attenuate blended zone by this plug-in (if option is unchecked, attenuate is made by opengl)")
115     add_bool( "panoramix-attenuate", 1, NULL, ATTENUATION_TEXT, ATTENUATION_LONGTEXT, VLC_FALSE );
116
117 #define BEGIN_TEXT N_("Attenuation, begin (in %)")
118 #define BEGIN_LONGTEXT N_("Select in percent the Lagrange coeff of the beginning blended zone")
119     add_integer_with_range( "bz-begin", 0, 0, 100, NULL, BEGIN_TEXT, BEGIN_LONGTEXT, VLC_TRUE );
120
121 #define MIDDLE_TEXT N_("Attenuation, middle (in %)")
122 #define MIDDLE_LONGTEXT N_("Select in percent the Lagrange coeff of the middle of blended zone")
123     add_integer_with_range( "bz-middle", 50, 0, 100, NULL, MIDDLE_TEXT, MIDDLE_LONGTEXT, VLC_FALSE );
124
125 #define END_TEXT N_("Attenuation, end (in %)")
126 #define END_LONGTEXT N_("Select in percent the Lagrange coeff of the end of blended zone")
127     add_integer_with_range( "bz-end", 100, 0, 100, NULL, END_TEXT, END_LONGTEXT, VLC_TRUE );
128
129 #define MIDDLE_POS_TEXT N_("middle position (in %)")
130 #define MIDDLE_POS_LONGTEXT N_("Select in percent (50 is center) the position of the middle point (Lagrange) of blended zone")
131     add_integer_with_range( "bz-middle-pos", 50, 1, 99, NULL, MIDDLE_POS_TEXT, MIDDLE_POS_LONGTEXT, VLC_FALSE );
132 #ifdef GAMMA
133 #define RGAMMA_TEXT N_("Gamma (Red) correction")
134 #define RGAMMA_LONGTEXT N_("Select the gamma for the correction of blended zone (Red or Y component)")
135     add_float_with_range( "bz-gamma-red", 1, 0, 5, NULL, RGAMMA_TEXT, RGAMMA_LONGTEXT, VLC_TRUE );
136
137 #define GGAMMA_TEXT N_("Gamma (Green) correction")
138 #define GGAMMA_LONGTEXT N_("Select the gamma for the correction of blended zone (Green or U component)")
139     add_float_with_range( "bz-gamma-green", 1, 0, 5, NULL, GGAMMA_TEXT, GGAMMA_LONGTEXT, VLC_TRUE );
140
141 #define BGAMMA_TEXT N_("Gamma (Blue) correction")
142 #define BGAMMA_LONGTEXT N_("Select the gamma for the correction of blended zone (Blue or V component)")
143     add_float_with_range( "bz-gamma-blue", 1, 0, 5, NULL, BGAMMA_TEXT, BGAMMA_LONGTEXT, VLC_TRUE );
144 #endif
145 #define RGAMMA_BC_TEXT N_("Black Crush for Red")
146 #define RGAMMA_BC_LONGTEXT N_("Select the Black Crush of blended zone (Red or Y component)")
147 #define GGAMMA_BC_TEXT N_("Black Crush for Green")
148 #define GGAMMA_BC_LONGTEXT N_("Select the Black Crush of blended zone (Green or U component)")
149 #define BGAMMA_BC_TEXT N_("Black Crush for Blue")
150 #define BGAMMA_BC_LONGTEXT N_("Select the Black Crush of blended zone (Blue or V component)")
151
152 #define RGAMMA_WC_TEXT N_("White Crush for Red")
153 #define RGAMMA_WC_LONGTEXT N_("Select the White Crush of blended zone (Red or Y component)")
154 #define GGAMMA_WC_TEXT N_("White Crush for Green")
155 #define GGAMMA_WC_LONGTEXT N_("Select the White Crush of blended zone (Green or U component)")
156 #define BGAMMA_WC_TEXT N_("White Crush for Blue")
157 #define BGAMMA_WC_LONGTEXT N_("Select the White Crush of blended zone (Blue or V component)")
158
159 #define RGAMMA_BL_TEXT N_("Black Level for Red")
160 #define RGAMMA_BL_LONGTEXT N_("Select the Black Level of blended zone (Red or Y component)")
161 #define GGAMMA_BL_TEXT N_("Black Level for Green")
162 #define GGAMMA_BL_LONGTEXT N_("Select the Black Level of blended zone (Green or U component)")
163 #define BGAMMA_BL_TEXT N_("Black Level for Blue")
164 #define BGAMMA_BL_LONGTEXT N_("Select the Black Level of blended zone (Blue or V component)")
165
166 #define RGAMMA_WL_TEXT N_("White Level for Red")
167 #define RGAMMA_WL_LONGTEXT N_("Select the White Level of blended zone (Red or Y component)")
168 #define GGAMMA_WL_TEXT N_("White Level for Green")
169 #define GGAMMA_WL_LONGTEXT N_("Select the White Level of blended zone (Green or U component)")
170 #define BGAMMA_WL_TEXT N_("White Level for Blue")
171 #define BGAMMA_WL_LONGTEXT N_("Select the White Level of blended zone (Blue or V component)")
172     add_integer_with_range( "bz-blackcrush-red", 140, 0, 255, NULL, RGAMMA_BC_TEXT, RGAMMA_BC_LONGTEXT, VLC_TRUE );
173     add_integer_with_range( "bz-blackcrush-green", 140, 0, 255, NULL, GGAMMA_BC_TEXT, GGAMMA_BC_LONGTEXT, VLC_TRUE );
174     add_integer_with_range( "bz-blackcrush-blue", 140, 0, 255, NULL, BGAMMA_BC_TEXT, BGAMMA_BC_LONGTEXT, VLC_TRUE );
175     add_integer_with_range( "bz-whitecrush-red", 200, 0, 255, NULL, RGAMMA_WC_TEXT, RGAMMA_WC_LONGTEXT, VLC_TRUE );
176     add_integer_with_range( "bz-whitecrush-green", 200, 0, 255, NULL, GGAMMA_WC_TEXT, GGAMMA_WC_LONGTEXT, VLC_TRUE );
177     add_integer_with_range( "bz-whitecrush-blue", 200, 0, 255, NULL, BGAMMA_WC_TEXT, BGAMMA_WC_LONGTEXT, VLC_TRUE );
178     add_integer_with_range( "bz-blacklevel-red", 150, 0, 255, NULL, RGAMMA_BL_TEXT, RGAMMA_BL_LONGTEXT, VLC_TRUE );
179     add_integer_with_range( "bz-blacklevel-green", 150, 0, 255, NULL, GGAMMA_BL_TEXT, GGAMMA_BL_LONGTEXT, VLC_TRUE );
180     add_integer_with_range( "bz-blacklevel-blue", 150, 0, 255, NULL, BGAMMA_BL_TEXT, BGAMMA_BL_LONGTEXT, VLC_TRUE );
181     add_integer_with_range( "bz-whitelevel-red", 0, 0, 255, NULL, RGAMMA_WL_TEXT, RGAMMA_WL_LONGTEXT, VLC_TRUE );
182     add_integer_with_range( "bz-whitelevel-green", 0, 0, 255, NULL, GGAMMA_WL_TEXT, GGAMMA_WL_LONGTEXT, VLC_TRUE );
183     add_integer_with_range( "bz-whitelevel-blue", 0, 0, 255, NULL, BGAMMA_WL_TEXT, BGAMMA_WL_LONGTEXT, VLC_TRUE );
184 #ifndef SYS_MINGW32
185 #define XINERAMA_TEXT N_("Xinerama option")
186 #define XINERAMA_LONGTEXT N_("Uncheck if you have not used xinerama")
187     add_bool( "xinerama", 1, NULL, XINERAMA_TEXT, XINERAMA_LONGTEXT, VLC_TRUE );
188 #endif
189 #endif
190
191     add_string( "wall-active", NULL, NULL, ACTIVE_TEXT, ACTIVE_LONGTEXT, VLC_TRUE );
192
193     add_shortcut( "panoramix" );
194     set_callbacks( Create, Destroy );
195 vlc_module_end();
196
197 /*****************************************************************************
198  * vout_sys_t: Wall video output method descriptor
199  *****************************************************************************
200  * This structure is part of the video output thread descriptor.
201  * It describes the Wall specific properties of an output thread.
202  *****************************************************************************/
203 struct vout_sys_t
204 {
205 #ifdef OVERLAP
206     vlc_bool_t   b_autocrop;
207     vlc_bool_t   b_attenuate;
208     unsigned int bz_length, bz_height, bz_begin, bz_middle, bz_end, bz_middle_pos;
209     unsigned int i_ratio_max;
210     unsigned int i_ratio;
211     unsigned int a_0, a_1, a_2;
212     vlc_bool_t     b_has_changed;
213     int lambda[2][VOUT_MAX_PLANES][500];
214     int cstYUV[2][VOUT_MAX_PLANES][500];
215     int lambda2[2][VOUT_MAX_PLANES][500];
216     int cstYUV2[2][VOUT_MAX_PLANES][500];
217     unsigned int i_halfLength;
218     unsigned int i_halfHeight;
219     int i_offset_x;
220     int i_offset_y;
221 #ifdef GAMMA
222     float        f_gamma_red, f_gamma_green, f_gamma_blue;
223     float         f_gamma[VOUT_MAX_PLANES];
224     uint8_t         LUT[VOUT_MAX_PLANES][ACCURACY + 1][256];
225 #ifdef PACKED_YUV
226     uint8_t         LUT2[VOUT_MAX_PLANES][256][500];
227 #endif
228 #endif
229 #ifndef SYS_MINGW32
230     vlc_bool_t   b_xinerama;
231 #endif
232 #endif
233     int    i_col;
234     int    i_row;
235     int    i_vout;
236     struct vout_list_t
237     {
238         vlc_bool_t b_active;
239         int i_width;
240         int i_height;
241         vout_thread_t *p_vout;
242     } *pp_vout;
243 };
244
245
246
247 /*****************************************************************************
248  * Control: control facility for the vout (forwards to child vout)
249  *****************************************************************************/
250 static int Control( vout_thread_t *p_vout, int i_query, va_list args )
251 {
252     int i_row, i_col, i_vout = 0;
253
254     for( i_row = 0; i_row < p_vout->p_sys->i_row; i_row++ )
255     {
256         for( i_col = 0; i_col < p_vout->p_sys->i_col; i_col++ )
257         {
258             vout_vaControl( p_vout->p_sys->pp_vout[ i_vout ].p_vout,
259                             i_query, args );
260             i_vout++;
261         }
262     }
263     return VLC_SUCCESS;
264 }
265
266 /*****************************************************************************
267  * Create: allocates Wall video thread output method
268  *****************************************************************************
269  * This function allocates and initializes a Wall vout method.
270  *****************************************************************************/
271 static int Create( vlc_object_t *p_this )
272 {
273     vout_thread_t *p_vout = (vout_thread_t *)p_this;
274     char *psz_method, *psz_tmp, *psz_method_tmp;
275     int i_vout;
276
277     /* Allocate structure */
278     p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
279     if( p_vout->p_sys == NULL )
280     {
281         msg_Err( p_vout, "out of memory" );
282         return VLC_ENOMEM;
283     }
284
285     p_vout->pf_init = Init;
286     p_vout->pf_end = End;
287     p_vout->pf_manage = NULL;
288 /* Color Format not supported
289 // Planar Y, packed UV
290 case VLC_FOURCC('Y','M','G','A'):
291 // Packed YUV 4:2:2, U:Y:V:Y, interlaced
292 case VLC_FOURCC('I','U','Y','V'):    // packed by 2
293 // Packed YUV 2:1:1, Y:U:Y:V
294 case VLC_FOURCC('Y','2','1','1'):     // packed by 4
295 // Packed YUV Reverted
296 case VLC_FOURCC('c','y','u','v'):    // packed by 2
297 */
298     switch (p_vout->render.i_chroma)
299     {
300     // planar YUV
301         case VLC_FOURCC('I','4','4','4'):
302         case VLC_FOURCC('I','4','2','2'):
303         case VLC_FOURCC('I','4','2','0'):
304         case VLC_FOURCC('Y','V','1','2'):
305         case VLC_FOURCC('I','Y','U','V'):
306         case VLC_FOURCC('I','4','1','1'):
307         case VLC_FOURCC('I','4','1','0'):
308         case VLC_FOURCC('Y','V','U','9'):
309         case VLC_FOURCC('Y','U','V','A'):
310             p_vout->pf_render = RenderPlanarYUV;
311             break;
312     // packed RGB
313         case VLC_FOURCC('R','G','B','2'):    // packed by 1
314         case VLC_FOURCC('R','V','1','5'):    // packed by 2
315         case VLC_FOURCC('R','V','1','6'):    // packed by 2
316         case VLC_FOURCC('R','V','2','4'):    // packed by 3
317         case VLC_FOURCC('R','V','3','2'):    // packed by 4
318             p_vout->pf_render = RenderPackedRGB;
319             break;
320 #ifdef PACKED_YUV
321     // packed YUV
322         case VLC_FOURCC('Y','U','Y','2'):    // packed by 2
323         case VLC_FOURCC('Y','U','N','V'):    // packed by 2
324         case VLC_FOURCC('U','Y','V','Y'):    // packed by 2
325         case VLC_FOURCC('U','Y','N','V'):    // packed by 2
326         case VLC_FOURCC('Y','4','2','2'):    // packed by 2
327             p_vout->pf_render = RenderPackedYUV;
328             break;
329 #endif
330         default:
331             msg_Err( p_vout, "colorspace not supported by plug-in !!!");
332             free( p_vout->p_sys );
333             return VLC_ENOMEM;
334     }
335     p_vout->pf_display = NULL;
336     p_vout->pf_control = Control;
337
338     /* Look what method was requested */
339     p_vout->p_sys->i_col = var_CreateGetInteger( p_vout, "panoramix-cols" );
340     p_vout->p_sys->i_row = var_CreateGetInteger( p_vout, "panoramix-rows" );
341
342 // OS dependant code :  Autodetect number of displays in wall
343 #ifdef SYS_MINGW32
344     if ((p_vout->p_sys->i_col < 0) || (p_vout->p_sys->i_row < 0) )
345     {
346         int nbMonitors = GetSystemMetrics(SM_CMONITORS);
347         if (nbMonitors == 1)
348         {
349             nbMonitors = 5; // 1 display => 5x1 simulation
350             p_vout->p_sys->i_col = nbMonitors;
351             p_vout->p_sys->i_row = 1;
352         }
353         else
354         {
355             p_vout->p_sys->i_col = GetSystemMetrics( SM_CXVIRTUALSCREEN ) / GetSystemMetrics( SM_CXSCREEN );
356             p_vout->p_sys->i_row = GetSystemMetrics( SM_CYVIRTUALSCREEN ) / GetSystemMetrics( SM_CYSCREEN );
357             if (p_vout->p_sys->i_col * p_vout->p_sys->i_row != nbMonitors)
358             {
359                 p_vout->p_sys->i_col = nbMonitors;
360                 p_vout->p_sys->i_row = 1;
361             }
362         }
363         var_SetInteger( p_vout, "panoramix-cols", p_vout->p_sys->i_col);
364         var_SetInteger( p_vout, "panoramix-rows", p_vout->p_sys->i_row);
365     }
366 #endif
367
368 #ifdef OVERLAP
369     p_vout->p_sys->i_offset_x = var_CreateGetInteger( p_vout, "offset-x" );
370     if (p_vout->p_sys->i_col > 2) p_vout->p_sys->i_offset_x = 0; // offset-x is used in case of 2x1 wall & autocrop    
371     p_vout->p_sys->b_autocrop = !(var_CreateGetInteger( p_vout, "crop-ratio" ) == 0);
372     if (!p_vout->p_sys->b_autocrop) p_vout->p_sys->b_autocrop = var_CreateGetInteger( p_vout, "autocrop" );             
373     p_vout->p_sys->b_attenuate = var_CreateGetInteger( p_vout, "panoramix-attenuate");
374     p_vout->p_sys->bz_length = var_CreateGetInteger( p_vout, "bz-length" );
375     if (p_vout->p_sys->i_row > 1)
376         p_vout->p_sys->bz_height = var_CreateGetInteger( p_vout, "bz-height" );
377     else
378         p_vout->p_sys->bz_height = 100;
379     p_vout->p_sys->bz_begin = var_CreateGetInteger( p_vout, "bz-begin" );
380     p_vout->p_sys->bz_middle = var_CreateGetInteger( p_vout, "bz-middle" );
381     p_vout->p_sys->bz_end = var_CreateGetInteger( p_vout, "bz-end" );
382     p_vout->p_sys->bz_middle_pos = var_CreateGetInteger( p_vout, "bz-middle-pos" );
383     double d_p = 100.0 / p_vout->p_sys->bz_middle_pos;
384     p_vout->p_sys->i_ratio_max = var_CreateGetInteger( p_vout, "autocrop-ratio-max" ); // in crop module with autocrop ...
385     p_vout->p_sys->i_ratio = var_CreateGetInteger( p_vout, "crop-ratio" ); // in crop module with manual ratio ...      
386     
387     p_vout->p_sys->a_2 = d_p * p_vout->p_sys->bz_begin - (double)(d_p * d_p / (d_p - 1)) * p_vout->p_sys->bz_middle + (double)(d_p / (d_p - 1)) * p_vout->p_sys->bz_end;
388     p_vout->p_sys->a_1 = -(d_p + 1) * p_vout->p_sys->bz_begin + (double)(d_p * d_p / (d_p - 1)) * p_vout->p_sys->bz_middle - (double)(1 / (d_p - 1)) * p_vout->p_sys->bz_end;
389     p_vout->p_sys->a_0 =  p_vout->p_sys->bz_begin;
390
391 #ifdef GAMMA
392     p_vout->p_sys->f_gamma_red = var_CreateGetFloat( p_vout, "bz-gamma-red" );
393     p_vout->p_sys->f_gamma_green = var_CreateGetFloat( p_vout, "bz-gamma-green" );
394     p_vout->p_sys->f_gamma_blue = var_CreateGetFloat( p_vout, "bz-gamma-blue" );
395 #endif
396 #ifndef SYS_MINGW32
397     p_vout->p_sys->b_xinerama= var_CreateGetInteger( p_vout, "xinerama" );
398 #endif
399 #else
400     p_vout->p_sys->i_col = __MAX( 1, __MIN( 15, p_vout->p_sys->i_col ) );
401     p_vout->p_sys->i_row = __MAX( 1, __MIN( 15, p_vout->p_sys->i_row ) );
402 #endif
403
404     msg_Dbg( p_vout, "opening a %i x %i wall",
405              p_vout->p_sys->i_col, p_vout->p_sys->i_row );
406
407     p_vout->p_sys->pp_vout = malloc( p_vout->p_sys->i_row *
408                                      p_vout->p_sys->i_col *
409                                      sizeof(struct vout_list_t) );
410     if( p_vout->p_sys->pp_vout == NULL )
411     {
412         msg_Err( p_vout, "out of memory" );
413         free( p_vout->p_sys );
414         return VLC_ENOMEM;
415     }
416
417     psz_method_tmp = psz_method = config_GetPsz( p_vout, "wall-active" );
418
419     /* If no trailing vout are specified, take them all */
420     if( psz_method == NULL )
421     {
422         for( i_vout = p_vout->p_sys->i_row * p_vout->p_sys->i_col;
423              i_vout--; )
424         {
425             p_vout->p_sys->pp_vout[i_vout].b_active = 1;
426         }
427     }
428     /* If trailing vout are specified, activate only the requested ones */
429     else
430     {
431         for( i_vout = p_vout->p_sys->i_row * p_vout->p_sys->i_col;
432              i_vout--; )
433         {
434             p_vout->p_sys->pp_vout[i_vout].b_active = 0;
435         }
436
437         while( *psz_method )
438         {
439             psz_tmp = psz_method;
440             while( *psz_tmp && *psz_tmp != ',' )
441             {
442                 psz_tmp++;
443             }
444
445             if( *psz_tmp )
446             {
447                 *psz_tmp = '\0';
448                 i_vout = atoi( psz_method );
449                 psz_method = psz_tmp + 1;
450             }
451             else
452             {
453                 i_vout = atoi( psz_method );
454                 psz_method = psz_tmp;
455             }
456
457             if( i_vout >= 0 &&
458                 i_vout < p_vout->p_sys->i_row * p_vout->p_sys->i_col )
459             {
460                 p_vout->p_sys->pp_vout[i_vout].b_active = 1;
461             }
462         }
463     }
464
465     free( psz_method_tmp );
466
467     return VLC_SUCCESS;
468 }
469
470
471 #ifdef OVERLAP
472 /*****************************************************************************
473  * CLIP_0A: clip between 0 and ACCURACY
474  *****************************************************************************/
475 inline static int CLIP_0A( int a )
476 {
477     return (a > ACCURACY) ? ACCURACY : (a < 0) ? 0 : a;
478 }
479
480 #ifdef GAMMA
481 /*****************************************************************************
482  *  Gamma: Gamma correction
483  *****************************************************************************/
484 static double Gamma_Correction(int i_plane, float f_component, float f_BlackCrush[VOUT_MAX_PLANES], float f_WhiteCrush[VOUT_MAX_PLANES], float f_BlackLevel[VOUT_MAX_PLANES], float f_WhiteLevel[VOUT_MAX_PLANES], float f_Gamma[VOUT_MAX_PLANES])
485 {
486     float f_Input;
487
488     f_Input = (f_component * f_BlackLevel[i_plane]) / (f_BlackCrush[i_plane]) + (1.0 - f_BlackLevel[i_plane]);
489     if (f_component <= f_BlackCrush[i_plane])
490          return pow(f_Input, 1.0 / f_Gamma[i_plane]);
491     else if (f_component >= f_WhiteCrush[i_plane])
492     {
493         f_Input = (f_component * (1.0 - (f_WhiteLevel[i_plane] + 1.0)) + (f_WhiteLevel[i_plane] + 1.0) * f_WhiteCrush[i_plane] - 1.0) / (f_WhiteCrush[i_plane] - 1.0);
494         return pow(f_Input, 1.0 / f_Gamma[i_plane]);
495     }
496            else
497             return 1.0;
498 }
499
500 #ifdef PACKED_YUV
501 /*****************************************************************************
502  * Clip: clip an 32 bits int in 8 bits
503  *****************************************************************************/
504 inline static int32_t clip( int32_t a )
505 {
506     return (a > 255) ? 255 : (a < 0) ? 0 : a;
507 }
508
509 /*****************************************************************************
510  * F: Function to calculate Gamma correction
511  *****************************************************************************/
512 static uint8_t F(uint8_t i, float gamma)
513 {
514  double input = (double) i / 255.0;
515
516 // return clip(255 * pow(input, 1.0 / gamma));
517
518  if (input < 0.5)
519      return clip((255 * pow(2 * input, gamma)) / 2);
520  else
521      return clip(255 * (1 - pow(2 * (1 - input), gamma) / 2));
522
523 }
524 #endif
525 #endif
526
527 /*****************************************************************************
528  * AdjustHeight: ajust p_sys->i_height to have same BZ width for any ratio
529  *****************************************************************************/
530 static int AdjustHeight( vout_thread_t *p_vout )
531 {
532     vlc_bool_t b_fullscreen = var_CreateGetInteger( p_vout, "fullscreen" );
533     int i_window_width = p_vout->i_window_width;
534     int i_window_height = p_vout->i_window_height;
535     double d_halfLength = 0;
536     double d_halfLength_crop;
537     double d_halfLength_calculated;
538     int    i_offset = 0;
539
540 // OS DEPENDANT CODE to get display dimensions
541         if (b_fullscreen)
542         {
543 #ifdef SYS_MINGW32
544             i_window_width  = GetSystemMetrics(SM_CXSCREEN);
545             i_window_height = GetSystemMetrics(SM_CYSCREEN);
546 #else            
547             Display *p_display = XOpenDisplay( "" );
548                 if (p_vout->p_sys->b_xinerama)
549                 {
550                     i_window_width = DisplayWidth(p_display, 0) / p_vout->p_sys->i_col;
551                     i_window_height = DisplayHeight(p_display, 0) / p_vout->p_sys->i_row;
552                  }
553                 else
554                 {
555                     i_window_width = DisplayWidth(p_display, 0);
556                     i_window_height = DisplayHeight(p_display, 0);
557                 } 
558                 XCloseDisplay( p_display );     
559                 free(p_display);  
560 #endif
561         var_SetInteger( p_vout, "width", i_window_width);
562         var_SetInteger( p_vout, "height", i_window_height);
563         p_vout->i_window_width = i_window_width;
564            p_vout->i_window_height = i_window_height;
565         }
566
567         if (p_vout->p_sys->bz_length)
568         if ((!p_vout->p_sys->b_autocrop) && (!p_vout->p_sys->i_ratio))
569         {
570             if ((p_vout->p_sys->i_row > 1) || (p_vout->p_sys->i_col > 1))
571             {
572               while ((d_halfLength <= 0) || (d_halfLength > p_vout->render.i_width / (2 * p_vout->p_sys->i_col)))
573               {
574                 if (p_vout->p_sys->bz_length >= 50)
575                     d_halfLength = i_window_width * p_vout->render.i_height / (2 * i_window_height * p_vout->p_sys->i_row) - p_vout->render.i_width / (2 * p_vout->p_sys->i_col);
576                 else
577                 {
578                     d_halfLength = (p_vout->render.i_width * p_vout->p_sys->bz_length) / (100.0 * p_vout->p_sys->i_col);
579                     d_halfLength = __MAX(i_window_width * p_vout->render.i_height / (2 * i_window_height * p_vout->p_sys->i_row) - p_vout->render.i_width / (2 * p_vout->p_sys->i_col), d_halfLength);
580                 }
581                 if ((d_halfLength <= 0) || (d_halfLength > p_vout->render.i_width / (2 * p_vout->p_sys->i_col))) p_vout->p_sys->i_row--;
582                 if (p_vout->p_sys->i_row < 1 )
583                 {
584                     p_vout->p_sys->i_row = 1;
585                     break;
586                 }
587               }
588               p_vout->p_sys->i_halfLength = (d_halfLength + 0.5);
589               p_vout->p_sys->bz_length = (p_vout->p_sys->i_halfLength * 100.0 * p_vout->p_sys->i_col) / p_vout->render.i_width;
590               var_SetInteger( p_vout, "bz-length", p_vout->p_sys->bz_length);
591               var_SetInteger( p_vout, "panoramix-rows", p_vout->p_sys->i_row);
592               }
593         }
594         else
595         {
596             d_halfLength = ((2 * (double)i_window_width - (double)(p_vout->p_sys->i_ratio_max * i_window_height) / 1000.0 ) * (double)p_vout->p_sys->bz_length) / 200.0;
597             d_halfLength_crop = d_halfLength * VOUT_ASPECT_FACTOR * (double)p_vout->output.i_width
598                         / (double)i_window_height / (double)p_vout->render.i_aspect;
599             p_vout->p_sys->i_halfLength = (d_halfLength_crop + 0.5);
600             d_halfLength_calculated = p_vout->p_sys->i_halfLength * (double)i_window_height *
601                                 (double)p_vout->render.i_aspect  /     VOUT_ASPECT_FACTOR / (double)p_vout->output.i_width;
602
603             if (!p_vout->p_sys->b_attenuate)
604             {
605                 double d_bz_length = (p_vout->p_sys->i_halfLength * p_vout->p_sys->i_col * 100.0) / p_vout->render.i_width;
606                 // F(2x) != 2F(x) in opengl module
607                 if (p_vout->p_sys->i_col == 2) d_bz_length = (100.0 * d_bz_length) / (100.0 - d_bz_length) ;
608                 var_SetInteger( p_vout, "bz-length", (int)(d_bz_length + 0.5));
609             }
610             i_offset =  (int)d_halfLength - (int)
611                         (p_vout->p_sys->i_halfLength * (double)i_window_height *
612                         (double)p_vout->render.i_aspect  /     VOUT_ASPECT_FACTOR / (double)p_vout->output.i_width);
613         }
614         else
615             d_halfLength = 0;
616
617         return i_offset;
618 }
619 #endif
620
621
622 /*****************************************************************************
623  * Init: initialize Wall video thread output method
624  *****************************************************************************/
625 static int Init( vout_thread_t *p_vout )
626 {
627     int i_index, i_row, i_col, i_width, i_height;
628     picture_t *p_pic;
629
630     I_OUTPUTPICTURES = 0;
631
632     /* Initialize the output structure */
633     p_vout->output.i_chroma = p_vout->render.i_chroma;
634     p_vout->output.i_width  = p_vout->render.i_width;
635     p_vout->output.i_height = p_vout->render.i_height;
636     p_vout->output.i_aspect = p_vout->render.i_aspect;
637 #ifdef OVERLAP
638     p_vout->p_sys->b_has_changed = p_vout->p_sys->b_attenuate;
639 #ifdef GAMMA
640     if (p_vout->p_sys->b_attenuate)
641     {
642         int i_index2, i_plane;
643         int constantYUV[3] = {0,128,128};
644         float    f_BlackCrush[VOUT_MAX_PLANES];
645         float    f_BlackLevel[VOUT_MAX_PLANES];
646         float    f_WhiteCrush[VOUT_MAX_PLANES];
647         float    f_WhiteLevel[VOUT_MAX_PLANES];
648         p_vout->p_sys->f_gamma[0] = var_CreateGetFloat( p_vout, "bz-gamma-red" );
649         p_vout->p_sys->f_gamma[1] = var_CreateGetFloat( p_vout, "bz-gamma-green" );
650         p_vout->p_sys->f_gamma[2] = var_CreateGetFloat( p_vout, "bz-gamma-blue" );
651         f_BlackCrush[0] = var_CreateGetInteger( p_vout, "bz-blackcrush-red" ) / 255.0;
652         f_BlackCrush[1] = var_CreateGetInteger( p_vout, "bz-blackcrush-green" ) / 255.0;
653         f_BlackCrush[2] = var_CreateGetInteger( p_vout, "bz-blackcrush-blue" ) / 255.0;
654         f_WhiteCrush[0] = var_CreateGetInteger( p_vout, "bz-whitecrush-red" ) / 255.0;
655         f_WhiteCrush[1] = var_CreateGetInteger( p_vout, "bz-whitecrush-green" ) / 255.0;
656         f_WhiteCrush[2] = var_CreateGetInteger( p_vout, "bz-whitecrush-blue" ) / 255.0;
657         f_BlackLevel[0] = var_CreateGetInteger( p_vout, "bz-blacklevel-red" ) / 255.0;
658         f_BlackLevel[1] = var_CreateGetInteger( p_vout, "bz-blacklevel-green" ) / 255.0;
659         f_BlackLevel[2] = var_CreateGetInteger( p_vout, "bz-blacklevel-blue" ) / 255.0;
660         f_WhiteLevel[0] = var_CreateGetInteger( p_vout, "bz-whitelevel-red" ) / 255.0;
661         f_WhiteLevel[1] = var_CreateGetInteger( p_vout, "bz-whitelevel-green" ) / 255.0;
662         f_WhiteLevel[2] = var_CreateGetInteger( p_vout, "bz-whitelevel-blue" ) / 255.0;
663         switch (p_vout->render.i_chroma)
664         {
665         // planar YVU
666             case VLC_FOURCC('Y','V','1','2'):
667             case VLC_FOURCC('Y','V','U','9'):
668         // packed UYV
669             case VLC_FOURCC('U','Y','V','Y'):    // packed by 2
670             case VLC_FOURCC('U','Y','N','V'):    // packed by 2
671             case VLC_FOURCC('Y','4','2','2'):    // packed by 2
672     //        case VLC_FOURCC('c','y','u','v'):    // packed by 2
673                 p_vout->p_sys->f_gamma[2] = var_CreateGetFloat( p_vout, "bz-gamma-green" );
674                 p_vout->p_sys->f_gamma[1] = var_CreateGetFloat( p_vout, "bz-gamma-blue" );
675                 f_BlackCrush[2] = var_CreateGetInteger( p_vout, "bz-blackcrush-green" ) / 255.0;
676                 f_BlackCrush[1] = var_CreateGetInteger( p_vout, "bz-blackcrush-blue" ) / 255.0;
677                 f_WhiteCrush[2] = var_CreateGetInteger( p_vout, "bz-whitecrush-green" ) / 255.0;
678                 f_WhiteCrush[1] = var_CreateGetInteger( p_vout, "bz-whitecrush-blue" ) / 255.0;
679                 f_BlackLevel[2] = var_CreateGetInteger( p_vout, "bz-blacklevel-green" ) / 255.0;
680                 f_BlackLevel[1] = var_CreateGetInteger( p_vout, "bz-blacklevel-blue" ) / 255.0;
681                 f_WhiteLevel[2] = var_CreateGetInteger( p_vout, "bz-whitelevel-green" ) / 255.0;
682                 f_WhiteLevel[1] = var_CreateGetInteger( p_vout, "bz-whitelevel-blue" ) / 255.0;
683         // planar YUV
684             case VLC_FOURCC('I','4','4','4'):
685             case VLC_FOURCC('I','4','2','2'):
686             case VLC_FOURCC('I','4','2','0'):
687             case VLC_FOURCC('I','4','1','1'):
688             case VLC_FOURCC('I','4','1','0'):
689             case VLC_FOURCC('I','Y','U','V'):
690             case VLC_FOURCC('Y','U','V','A'):
691         // packed YUV
692             case VLC_FOURCC('Y','U','Y','2'):    // packed by 2
693             case VLC_FOURCC('Y','U','N','V'):    // packed by 2
694                 for (i_index = 0; i_index < 256; i_index++)
695                     for (i_index2 = 0; i_index2 <= ACCURACY; i_index2++)
696                         for (i_plane = 0; i_plane < VOUT_MAX_PLANES; i_plane++)
697                         {
698                             float f_lut = CLIP_01(1.0 -
699                                      ((ACCURACY - (float)i_index2)
700                                      * Gamma_Correction(i_plane, (float)i_index / 255.0, f_BlackCrush, f_WhiteCrush, f_BlackLevel, f_WhiteLevel, p_vout->p_sys->f_gamma)
701                                      / (ACCURACY - 1)));
702                             p_vout->p_sys->LUT[i_plane][i_index2][i_index] = f_lut * i_index + (int)((1.0 - f_lut) * (float)constantYUV[i_plane]);
703                         }
704                 break;
705         // packed RGB
706             case VLC_FOURCC('R','G','B','2'):    // packed by 1
707             case VLC_FOURCC('R','V','1','5'):    // packed by 2
708             case VLC_FOURCC('R','V','1','6'):    // packed by 2
709             case VLC_FOURCC('R','V','2','4'):    // packed by 3
710             case VLC_FOURCC('R','V','3','2'):    // packed by 4
711             for (i_index = 0; i_index < 256; i_index++)
712                     for (i_index2 = 0; i_index2 <= ACCURACY; i_index2++)
713                         for (i_plane = 0; i_plane < VOUT_MAX_PLANES; i_plane++)
714                         {
715                             float f_lut = CLIP_01(1.0 -
716                                      ((ACCURACY - (float)i_index2)
717                                      * Gamma_Correction(i_plane, (float)i_index / 255.0, f_BlackCrush, f_WhiteCrush, f_BlackLevel, f_WhiteLevel, p_vout->p_sys->f_gamma)
718                                      / (ACCURACY - 1)));
719                             p_vout->p_sys->LUT[i_plane][i_index2][i_index] = f_lut * i_index;
720                         }
721                 break;
722             default:
723                 msg_Err( p_vout, "colorspace not supported by plug-in !!!");
724                 free( p_vout->p_sys );
725                 return VLC_ENOMEM;
726         }
727     }
728 #endif
729     if (p_vout->p_sys->i_offset_x)
730         p_vout->p_sys->i_offset_x = AdjustHeight(p_vout);
731     else
732         AdjustHeight(p_vout);
733 #endif
734
735     /* Try to open the real video output */
736     msg_Dbg( p_vout, "spawning the real video outputs" );
737
738     p_vout->p_sys->i_vout = 0;
739
740     /* FIXME: use bresenham instead of those ugly divisions */
741     for( i_row = 0; i_row < p_vout->p_sys->i_row; i_row++ )
742     {
743         for( i_col = 0; i_col < p_vout->p_sys->i_col; i_col++ )
744         {
745             video_format_t fmt;
746
747             memset( &fmt, 0, sizeof(video_format_t) );
748
749             if( i_col + 1 < p_vout->p_sys->i_col )
750             {
751                 i_width = ( p_vout->render.i_width
752                              / p_vout->p_sys->i_col ) & ~0x1;
753             }
754             else
755             {
756                 i_width = p_vout->render.i_width
757                            - ( ( p_vout->render.i_width
758                                   / p_vout->p_sys->i_col ) & ~0x1 ) * i_col;
759
760             }
761 #ifdef OVERLAP
762             i_width += p_vout->p_sys->i_halfLength;
763             if (p_vout->p_sys->i_col > 2 ) i_width += p_vout->p_sys->i_halfLength;
764             i_width -= i_width % 2;
765 #endif
766             if( i_row + 1 < p_vout->p_sys->i_row )
767             {
768                 i_height = ( p_vout->render.i_height
769                               / p_vout->p_sys->i_row ) & ~0x3;
770             }
771             else
772             {
773                 i_height = p_vout->render.i_height
774                             - ( ( p_vout->render.i_height
775                                    / p_vout->p_sys->i_row ) & ~0x3 ) * i_row;
776             }
777
778 #ifdef OVERLAP
779             if (p_vout->p_sys->i_row >= 2)
780             {
781                 p_vout->p_sys->i_halfHeight = (p_vout->p_sys->i_halfLength * p_vout->p_sys->bz_height) / 100;
782                 p_vout->p_sys->i_halfHeight -= (p_vout->p_sys->i_halfHeight % 2);
783                 i_height += p_vout->p_sys->i_halfHeight;
784                 if (p_vout->p_sys->i_row > 2) i_height += p_vout->p_sys->i_halfHeight;
785             }
786             i_height -= i_height % 2;
787 #endif
788             p_vout->p_sys->pp_vout[ p_vout->p_sys->i_vout ].i_width = i_width;
789             p_vout->p_sys->pp_vout[ p_vout->p_sys->i_vout ].i_height = i_height;
790
791             if( !p_vout->p_sys->pp_vout[ p_vout->p_sys->i_vout ].b_active )
792             {
793                 p_vout->p_sys->i_vout++;
794                 continue;
795             }
796
797             fmt.i_width = fmt.i_visible_width = p_vout->render.i_width;
798             fmt.i_height = fmt.i_visible_height = p_vout->render.i_height;
799             fmt.i_x_offset = fmt.i_y_offset = 0;
800             fmt.i_chroma = p_vout->render.i_chroma;
801             fmt.i_aspect = p_vout->render.i_aspect;
802             fmt.i_sar_num = p_vout->render.i_aspect * fmt.i_height / fmt.i_width;
803             fmt.i_sar_den = VOUT_ASPECT_FACTOR;
804             fmt.i_width = fmt.i_visible_width = i_width;
805             fmt.i_height = fmt.i_visible_height = i_height;
806             fmt.i_aspect = p_vout->render.i_aspect
807                               * p_vout->render.i_height / i_height
808                               * i_width / p_vout->render.i_width;
809 #ifdef OVERLAP
810             if (p_vout->p_sys->i_offset_x < 0)
811             {
812                 var_SetInteger(p_vout, "video-x", -p_vout->p_sys->i_offset_x);
813                 p_vout->p_sys->i_offset_x = 0;
814             }
815 #endif
816             p_vout->p_sys->pp_vout[ p_vout->p_sys->i_vout ].p_vout =
817                 vout_Create( p_vout, &fmt);
818
819             if( p_vout->p_sys->pp_vout[ p_vout->p_sys->i_vout ].p_vout == NULL )
820             {
821                 msg_Err( p_vout, "failed to get %ix%i vout threads",
822                                  p_vout->p_sys->i_col, p_vout->p_sys->i_row );
823                 RemoveAllVout( p_vout );
824                 return VLC_EGENERIC;
825             }
826             ADD_CALLBACKS(
827                 p_vout->p_sys->pp_vout[ p_vout->p_sys->i_vout ].p_vout,
828                 SendEvents );
829 #ifdef OVERLAP
830             p_vout->p_sys->pp_vout[ p_vout->p_sys->i_vout ].p_vout->i_alignment = 0;
831             if (i_col == 0) p_vout->p_sys->pp_vout[ p_vout->p_sys->i_vout ].p_vout->i_alignment |= VOUT_ALIGN_RIGHT;
832             else if (i_col == p_vout->p_sys->i_col -1) p_vout->p_sys->pp_vout[ p_vout->p_sys->i_vout ].p_vout->i_alignment |= VOUT_ALIGN_LEFT;
833             if (p_vout->p_sys->i_row > 1)
834             {
835                 if (i_row == 0) p_vout->p_sys->pp_vout[ p_vout->p_sys->i_vout ].p_vout->i_alignment |= VOUT_ALIGN_BOTTOM;
836                 else if (i_row == p_vout->p_sys->i_row -1) p_vout->p_sys->pp_vout[ p_vout->p_sys->i_vout ].p_vout->i_alignment |= VOUT_ALIGN_TOP;
837             }
838     // i_n : number of active pp_vout
839                         int i_video_x = var_GetInteger( p_vout, "video-x");    
840                 int i_video_y = var_GetInteger( p_vout, "video-y");     
841             int i_index, i_n = p_vout->p_sys->i_vout;
842                 for (i_index = p_vout->p_sys->i_vout; i_index >= 0; i_index--) if (!p_vout->p_sys->pp_vout[i_index].b_active) i_n -= 1;
843             var_SetInteger( p_vout, "align", p_vout->p_sys->pp_vout[ p_vout->p_sys->i_vout ].p_vout->i_alignment );
844             var_SetInteger( p_vout, "video-x",i_video_x + p_vout->p_sys->i_offset_x + ((i_n + 1) % p_vout->p_sys->i_col) * p_vout->i_window_width);
845             var_SetInteger( p_vout, "video-y",i_video_y + ((i_n + 1) / p_vout->p_sys->i_col) * p_vout->i_window_height);
846 #endif
847             p_vout->p_sys->i_vout++;
848         }
849     }
850
851     ALLOCATE_DIRECTBUFFERS( VOUT_MAX_PICTURES );
852
853     ADD_PARENT_CALLBACKS( SendEventsToChild );
854
855     return VLC_SUCCESS;
856 }
857
858 /*****************************************************************************
859  * End: terminate Wall video thread output method
860  *****************************************************************************/
861 static void End( vout_thread_t *p_vout )
862 {
863     int i_index;
864
865 #ifdef OVERLAP
866     var_SetInteger( p_vout, "bz-length", p_vout->p_sys->bz_length);
867 #endif
868     /* Free the fake output buffers we allocated */
869     for( i_index = I_OUTPUTPICTURES ; i_index ; )
870     {
871         i_index--;
872         free( PP_OUTPUTPICTURE[ i_index ]->p_data_orig );
873     }
874 }
875
876 /*****************************************************************************
877  * Destroy: destroy Wall video thread output method
878  *****************************************************************************
879  * Terminate an output method created by WallCreateOutputMethod
880  *****************************************************************************/
881 static void Destroy( vlc_object_t *p_this )
882 {
883     vout_thread_t *p_vout = (vout_thread_t *)p_this;
884
885 #ifdef GLOBAL_OUTPUT
886     DEL_CALLBACKS( p_vout->p_sys->p_vout, SendEvents);
887     vlc_object_detach( p_vout->p_sys->p_vout );
888     vout_Destroy( p_vout->p_sys->p_vout );
889     DEL_PARENT_CALLBACKS( SendEventsToChild);
890 #endif
891
892     RemoveAllVout( p_vout );
893     DEL_PARENT_CALLBACKS( SendEventsToChild );
894
895     free( p_vout->p_sys->pp_vout );
896     free( p_vout->p_sys );
897
898 }
899
900 /*****************************************************************************
901  * RenderPlanarYUV: displays previously rendered output
902  *****************************************************************************
903  * This function send the currently rendered image to Wall image, waits
904  * until it is displayed and switch the two rendering buffers, preparing next
905  * frame.
906  *****************************************************************************/
907 static void RenderPlanarYUV( vout_thread_t *p_vout, picture_t *p_pic )
908 {
909     picture_t *p_outpic = NULL;
910     int i_col, i_row, i_vout, i_plane;
911     int pi_left_skip[VOUT_MAX_PLANES], pi_top_skip[VOUT_MAX_PLANES];
912 #ifdef OVERLAP
913     int LeftOffset, TopOffset;
914     int constantYUV[3] = {0,128,128};
915     int Denom;
916     int a_2;
917     int a_1;
918     int a_0;
919     int i_index, i_index2;
920 #endif
921
922
923     i_vout = 0;
924
925     for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ )
926     {
927         pi_top_skip[i_plane] = 0;
928     }
929
930     for( i_row = 0; i_row < p_vout->p_sys->i_row; i_row++ )
931     {
932         for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ )
933         {
934             pi_left_skip[i_plane] = 0;
935         }
936
937         for( i_col = 0; i_col < p_vout->p_sys->i_col; i_col++ )
938         {
939             if( !p_vout->p_sys->pp_vout[ i_vout ].b_active )
940             {
941                 for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ )
942                 {
943                     pi_left_skip[i_plane] +=
944                         p_vout->p_sys->pp_vout[ i_vout ].i_width
945                          * p_pic->p[i_plane].i_pitch / p_vout->output.i_width;
946                 }
947                 i_vout++;
948                 continue;
949             }
950
951             while( ( p_outpic =
952                 vout_CreatePicture( p_vout->p_sys->pp_vout[ i_vout ].p_vout,
953                                     0, 0, 0 )
954                    ) == NULL )
955             {
956                 if( p_vout->b_die || p_vout->b_error )
957                 {
958                     vout_DestroyPicture(
959                         p_vout->p_sys->pp_vout[ i_vout ].p_vout, p_outpic );
960                     return;
961                 }
962
963                 msleep( VOUT_OUTMEM_SLEEP );
964             }
965
966             vout_DatePicture( p_vout->p_sys->pp_vout[ i_vout ].p_vout,
967                               p_outpic, p_pic->date );
968             vout_LinkPicture( p_vout->p_sys->pp_vout[ i_vout ].p_vout,
969                               p_outpic );
970
971             for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ )
972             {
973                 uint8_t *p_in, *p_in_end, *p_out;
974                 int i_in_pitch = p_pic->p[i_plane].i_pitch;
975                 int i_out_pitch = p_outpic->p[i_plane].i_pitch;
976                 int i_copy_pitch = p_outpic->p[i_plane].i_visible_pitch;
977                 int i_lines = p_outpic->p[i_plane].i_visible_lines;
978 #ifdef OVERLAP
979                 if (i_col) pi_left_skip[i_plane] -= (2 * p_vout->p_sys->i_halfLength ) / (p_vout->p_sys->pp_vout[i_vout].i_width / i_copy_pitch);
980                 if ((i_row) && (!i_col)) pi_top_skip[i_plane] -= (2 * p_vout->p_sys->i_halfHeight * p_pic->p[i_plane].i_pitch) / (p_vout->p_sys->pp_vout[i_vout].i_width / i_copy_pitch);
981                 if ((p_vout->p_sys->i_row > 2) && (i_row == 1) && (!i_col)) pi_top_skip[i_plane] -= (2 * p_vout->p_sys->i_halfHeight * p_pic->p[i_plane].i_pitch) / (p_vout->p_sys->pp_vout[i_vout].i_width / i_copy_pitch);
982                 if ((!p_vout->p_sys->pp_vout[p_vout->p_sys->i_col].b_active))
983                     pi_top_skip[i_plane] -= (2 * p_vout->p_sys->i_halfHeight * i_row * p_pic->p[i_plane].i_pitch) / (p_vout->p_sys->pp_vout[i_vout].i_width / i_copy_pitch);
984 // i_n : previous inactive pp_vout
985                 int i_n=0;
986                 while ((!p_vout->p_sys->pp_vout[i_row * p_vout->p_sys->i_col + i_col - 1 - i_n].b_active) && (i_col - i_n > 1)) i_n++;
987                 if ((i_col > 1) && i_n)
988                     pi_left_skip[i_plane] -= i_n*(2 * p_vout->p_sys->i_halfLength ) / (p_vout->p_sys->pp_vout[i_vout].i_width / i_copy_pitch);
989
990                 p_in = p_pic->p[i_plane].p_pixels
991                 /* Wall proprities */
992                 + pi_top_skip[i_plane] + pi_left_skip[i_plane];
993
994                 if ((p_vout->p_sys->i_row > 2) &&
995                     ((!i_row) || (i_row + 1 == p_vout->p_sys->i_row)))
996                         i_lines -= (2 * p_vout->p_sys->i_halfHeight) / (p_vout->p_sys->pp_vout[i_vout].i_width / i_copy_pitch);
997
998 // 1088 lines bug in a mpeg2 stream of 1080 lines
999                 if ((p_vout->p_sys->i_row - 1 == i_row) &&
1000                     (p_pic->p[i_plane].i_lines == 1088))
1001                         i_lines -= 8 / (p_vout->p_sys->pp_vout[i_vout].i_width / i_copy_pitch);
1002
1003                 p_in_end = p_in + i_lines * p_pic->p[i_plane].i_pitch;
1004 #else
1005                 p_in = p_pic->p[i_plane].p_pixels
1006                         + pi_top_skip[i_plane] + pi_left_skip[i_plane];
1007
1008                 p_in_end = p_in + i_lines * p_pic->p[i_plane].i_pitch;
1009 #endif
1010                 p_out = p_outpic->p[i_plane].p_pixels;
1011 #ifdef OVERLAP
1012         if ((p_vout->p_sys->i_row > 2) && (!i_row))
1013             p_out += (p_outpic->p[i_plane].i_pitch * (2 * p_vout->p_sys->i_halfHeight) / (p_vout->p_sys->pp_vout[i_vout].i_width / i_copy_pitch));
1014
1015         int length;
1016         int i_col_mod;
1017         length = 2 * p_vout->p_sys->i_halfLength / (p_vout->p_sys->pp_vout[i_vout].i_width / i_copy_pitch);
1018
1019         if (p_vout->p_sys->b_has_changed)
1020         {
1021             Denom = F2(length);
1022             a_2 = p_vout->p_sys->a_2 * (ACCURACY / 100);
1023             a_1 = p_vout->p_sys->a_1 * length * (ACCURACY / 100);
1024             a_0 = p_vout->p_sys->a_0 * Denom * (ACCURACY / 100);
1025             for(i_col_mod = 0; i_col_mod < 2; i_col_mod++)
1026              for (i_index = 0; i_index < length; i_index++)
1027              {
1028                 p_vout->p_sys->lambda[i_col_mod][i_plane][i_index] = CLIP_0A(!i_col_mod ? ACCURACY - (F4(a_2, a_1, i_index) + a_0) / Denom : ACCURACY - (F4(a_2, a_1,length - i_index) + a_0) / Denom);
1029                 p_vout->p_sys->cstYUV[i_col_mod][i_plane][i_index] = ((ACCURACY - p_vout->p_sys->lambda[i_col_mod][i_plane][i_index]) * constantYUV[i_plane]) / ACCURACY;
1030              }
1031         }
1032 #endif
1033             while( p_in < p_in_end )
1034             {
1035 #ifndef OVERLAP
1036                 p_vout->p_libvlc->pf_memcpy( p_out , p_in, i_copy_pitch);
1037 #else
1038                 if (p_vout->p_sys->i_col > 2)
1039                 {
1040                     length /= 2;
1041                     if (i_col == 0)
1042                         p_vout->p_libvlc->pf_memcpy( p_out + length , p_in, i_copy_pitch - length);
1043                     else if (i_col + 1 == p_vout->p_sys->i_col)
1044                             p_vout->p_libvlc->pf_memcpy( p_out, p_in - length, i_copy_pitch - length);
1045                          else
1046                             p_vout->p_libvlc->pf_memcpy( p_out, p_in - length, i_copy_pitch);
1047
1048                     if ((i_col == 0))
1049                     // black bar
1050                     {
1051                         LeftOffset = 0;
1052                         p_out += LeftOffset;
1053                         memset(p_out, constantYUV[i_plane], length);
1054                         p_out -= LeftOffset;
1055                     }
1056                     else if ((i_col + 1 == p_vout->p_sys->i_col ))
1057                     // black bar
1058                         {
1059                             LeftOffset = i_copy_pitch - length;
1060                             p_out += LeftOffset;
1061                             memset(p_out, constantYUV[i_plane], length);
1062                             p_out -= LeftOffset;
1063                         }
1064                     length *= 2;
1065                 }
1066                 else
1067                     p_vout->p_libvlc->pf_memcpy( p_out , p_in, i_copy_pitch);
1068
1069               if (p_vout->p_sys->b_attenuate)
1070             {
1071 // vertical blend
1072 // first blended zone
1073                 if (i_col)
1074                 {
1075                     LeftOffset = 0;
1076                     p_out += LeftOffset;
1077                     for (i_index = 0; i_index < length; i_index++)
1078                     {
1079 #ifndef GAMMA
1080                         *(p_out + i_index) = (p_vout->p_sys->lambda[1][i_plane][i_index] *
1081                                  (*(p_out + i_index))) / ACCURACY +
1082                                      p_vout->p_sys->cstYUV[1][i_plane][i_index];
1083 #else
1084                             *(p_out + i_index) = p_vout->p_sys->LUT[i_plane][p_vout->p_sys->lambda[1][i_plane][i_index]][*(p_out + i_index)];
1085 #endif
1086                     }
1087                     p_out -= LeftOffset;
1088                 }
1089 // second blended zone
1090                 if (i_col + 1 < p_vout->p_sys->i_col)
1091                 {
1092                     LeftOffset = i_copy_pitch - length;
1093                     p_out +=  LeftOffset;
1094                     for (i_index = 0; i_index < length; i_index++)
1095                     {
1096 #ifndef GAMMA
1097                             *(p_out + i_index) = (p_vout->p_sys->lambda[0][i_plane][i_index] *
1098                                      (*(p_out + i_index))) / ACCURACY +
1099                                      p_vout->p_sys->cstYUV[0][i_plane][i_index];
1100 #else
1101
1102                         *(p_out + i_index) = p_vout->p_sys->LUT[i_plane][p_vout->p_sys->lambda[0][i_plane][i_index]][*(p_out + i_index)];
1103 #endif
1104                     }
1105                     p_out -= LeftOffset;
1106                 }
1107 // end blended zone
1108             }
1109 #endif
1110                 p_in += i_in_pitch;
1111                 p_out += i_out_pitch;
1112             }
1113 #ifdef OVERLAP
1114 // horizontal blend
1115         if (!p_vout->p_sys->b_attenuate)
1116         {
1117             if ((i_row == 0) && (p_vout->p_sys->i_row > 2))
1118             // black bar
1119             {
1120                     int height = 2 * p_vout->p_sys->i_halfHeight / (p_vout->p_sys->pp_vout[i_vout].i_width / i_copy_pitch);
1121                     TopOffset = i_lines + (2 * p_vout->p_sys->i_halfHeight) / (p_vout->p_sys->pp_vout[i_vout].i_width / i_copy_pitch);
1122                     p_out -= TopOffset * p_outpic->p[i_plane].i_pitch;
1123                     for (i_index = 0; i_index < height; i_index++)
1124                         for (i_index2 = 0; i_index2 < i_copy_pitch; i_index2++)
1125                             *(p_out + (i_index * p_outpic->p[i_plane].i_pitch) + i_index2) = constantYUV[i_plane];
1126                     p_out += TopOffset * p_outpic->p[i_plane].i_pitch;
1127             }
1128             else if ((i_row + 1 == p_vout->p_sys->i_row) && (p_vout->p_sys->i_row > 2))
1129             // black bar
1130                 {
1131                         int height = 2 * p_vout->p_sys->i_halfHeight / (p_vout->p_sys->pp_vout[i_vout].i_width / i_copy_pitch);
1132                         TopOffset = height - (2 * p_vout->p_sys->i_halfHeight) / (p_vout->p_sys->pp_vout[i_vout].i_width / i_copy_pitch);
1133                         p_out -= TopOffset * p_outpic->p[i_plane].i_pitch;
1134                         for (i_index = 0; i_index < height; i_index++)
1135                             for (i_index2 = 0; i_index2 < i_copy_pitch; i_index2++)
1136                                 *(p_out + (i_index * p_outpic->p[i_plane].i_pitch) + i_index2) = constantYUV[i_plane];
1137                         p_out += TopOffset * p_outpic->p[i_plane].i_pitch;
1138                 }
1139         }
1140         else
1141         {
1142             if (p_vout->p_sys->i_row >= 2)
1143             {
1144                 length = 2 * p_vout->p_sys->i_halfHeight / (p_vout->p_sys->pp_vout[i_vout].i_width / i_copy_pitch);
1145                 if (p_vout->p_sys->b_has_changed)
1146                 {
1147                     Denom = F2(length);
1148                     a_2 = p_vout->p_sys->a_2 * (ACCURACY / 100);
1149                     a_1 = p_vout->p_sys->a_1 * length * (ACCURACY / 100);
1150                     a_0 = p_vout->p_sys->a_0 * Denom * (ACCURACY / 100);
1151                    for(i_col_mod = 0; i_col_mod < 2; i_col_mod++)
1152                     for (i_index = 0; i_index < length; i_index++)
1153                     {
1154                         p_vout->p_sys->lambda2[i_col_mod][i_plane][i_index] = CLIP_0A(!i_col_mod ? ACCURACY - (F4(a_2, a_1, i_index) + a_0) / Denom : ACCURACY - (F4(a_2, a_1,length - i_index) + a_0) / Denom);
1155                         p_vout->p_sys->cstYUV2[i_col_mod][i_plane][i_index] = ((ACCURACY - p_vout->p_sys->lambda2[i_col_mod][i_plane][i_index]) * constantYUV[i_plane]) / ACCURACY;
1156                     }
1157                 }
1158 // first blended zone
1159
1160             if (i_row)
1161             {
1162                 TopOffset = i_lines;
1163                 p_out -= TopOffset * p_outpic->p[i_plane].i_pitch;
1164                 for (i_index = 0; i_index < length; i_index++)
1165                     for (i_index2 = 0; i_index2 < i_copy_pitch; i_index2++)
1166 #ifndef GAMMA
1167                         *(p_out + (i_index * p_outpic->p[i_plane].i_pitch) + i_index2) = (p_vout->p_sys->lambda2[1][i_plane][i_index] *
1168                                      (*(p_out + (i_index * p_outpic->p[i_plane].i_pitch) + i_index2))) / ACCURACY +
1169                                      p_vout->p_sys->cstYUV2[1][i_plane][i_index];
1170 #else
1171
1172                         *(p_out + (i_index * p_outpic->p[i_plane].i_pitch) + i_index2) = p_vout->p_sys->LUT[i_plane][p_vout->p_sys->lambda2[1][i_plane][i_index]][*(p_out + (i_index * p_outpic->p[i_plane].i_pitch) + i_index2)];
1173 #endif
1174                 p_out += TopOffset * p_outpic->p[i_plane].i_pitch;
1175             }
1176             else if (p_vout->p_sys->i_row > 2)
1177             // black bar
1178             {
1179                 TopOffset = i_lines + (2 * p_vout->p_sys->i_halfHeight) / (p_vout->p_sys->pp_vout[i_vout].i_width / i_copy_pitch);
1180                 p_out -= TopOffset * p_outpic->p[i_plane].i_pitch;
1181                 for (i_index = 0; i_index < length; i_index++)
1182                     for (i_index2 = 0; i_index2 < i_copy_pitch; i_index2++)
1183                         *(p_out + (i_index * p_outpic->p[i_plane].i_pitch) + i_index2) = constantYUV[i_plane];
1184                 p_out += TopOffset * p_outpic->p[i_plane].i_pitch;
1185             }
1186
1187 // second blended zone
1188
1189             if (i_row + 1 < p_vout->p_sys->i_row)
1190             {
1191                 TopOffset = length;
1192                 p_out -= TopOffset * p_outpic->p[i_plane].i_pitch;
1193                 for (i_index = 0; i_index < length; i_index++)
1194                     for (i_index2 = 0; i_index2 < i_copy_pitch; i_index2++)
1195 #ifndef GAMMA
1196                         *(p_out + (i_index * p_outpic->p[i_plane].i_pitch) + i_index2) = (p_vout->p_sys->lambda2[0][i_plane][i_index] *
1197                                      (*(p_out + (i_index * p_outpic->p[i_plane].i_pitch) + i_index2))) / ACCURACY +
1198                                      p_vout->p_sys->cstYUV2[0][i_plane][i_index];
1199 #else
1200
1201                         *(p_out + (i_index * p_outpic->p[i_plane].i_pitch) + i_index2) = p_vout->p_sys->LUT[i_plane][p_vout->p_sys->lambda2[0][i_plane][i_index]][*(p_out + (i_index * p_outpic->p[i_plane].i_pitch) + i_index2)];
1202
1203 #endif
1204                 p_out += TopOffset * p_outpic->p[i_plane].i_pitch;
1205             }
1206             else if (p_vout->p_sys->i_row > 2)
1207             // black bar
1208             {
1209                 TopOffset = length - (2 * p_vout->p_sys->i_halfHeight) / (p_vout->p_sys->pp_vout[i_vout].i_width / i_copy_pitch);
1210                 p_out -= TopOffset * p_outpic->p[i_plane].i_pitch;
1211                 for (i_index = 0; i_index < length; i_index++)
1212                     for (i_index2 = 0; i_index2 < i_copy_pitch; i_index2++)
1213                         *(p_out + (i_index * p_outpic->p[i_plane].i_pitch) + i_index2) = constantYUV[i_plane];
1214                 p_out += TopOffset * p_outpic->p[i_plane].i_pitch;
1215             }
1216 // end blended zone
1217             }
1218         }
1219 #endif
1220 // bug for wall filter : fix by CC
1221 //            pi_left_skip[i_plane] += i_out_pitch;
1222             pi_left_skip[i_plane] += i_copy_pitch;
1223             }
1224
1225             vout_UnlinkPicture( p_vout->p_sys->pp_vout[ i_vout ].p_vout,
1226                                 p_outpic );
1227             vout_DisplayPicture( p_vout->p_sys->pp_vout[ i_vout ].p_vout,
1228                                  p_outpic );
1229             i_vout++;
1230         }
1231
1232         for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ )
1233                 {
1234                     pi_top_skip[i_plane] += p_vout->p_sys->pp_vout[ i_vout ].i_height
1235                                              * p_pic->p[i_plane].i_lines
1236                                              / p_vout->output.i_height
1237                                              * p_pic->p[i_plane].i_pitch;
1238                 }
1239
1240     }
1241 #ifdef OVERLAP
1242     if (p_vout->p_sys->b_has_changed) p_vout->p_sys->b_has_changed = VLC_FALSE;
1243 #endif
1244 }
1245
1246
1247 /*****************************************************************************
1248  * RenderPackedRGB: displays previously rendered output
1249  *****************************************************************************
1250  * This function send the currently rendered image to Wall image, waits
1251  * until it is displayed and switch the two rendering buffers, preparing next
1252  * frame.
1253  *****************************************************************************/
1254 static void RenderPackedRGB( vout_thread_t *p_vout, picture_t *p_pic )
1255 {
1256     picture_t *p_outpic = NULL;
1257     int i_col, i_row, i_vout, i_plane;
1258     int pi_left_skip[VOUT_MAX_PLANES], pi_top_skip[VOUT_MAX_PLANES];
1259 #ifdef OVERLAP
1260     int LeftOffset, TopOffset;
1261     int Denom;
1262     int a_2;
1263     int a_1;
1264     int a_0;
1265     int i_index, i_index2;
1266 #endif
1267
1268     i_vout = 0;
1269
1270     for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ )
1271     {
1272         pi_top_skip[i_plane] = 0;
1273     }
1274
1275     for( i_row = 0; i_row < p_vout->p_sys->i_row; i_row++ )
1276     {
1277         for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ )
1278         {
1279             pi_left_skip[i_plane] = 0;
1280         }
1281
1282         for( i_col = 0; i_col < p_vout->p_sys->i_col; i_col++ )
1283         {
1284             if( !p_vout->p_sys->pp_vout[ i_vout ].b_active )
1285             {
1286                 for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ )
1287                 {
1288                     pi_left_skip[i_plane] +=
1289                         p_vout->p_sys->pp_vout[ i_vout ].i_width * p_pic->p->i_pixel_pitch;
1290                 }
1291                 i_vout++;
1292                 continue;
1293             }
1294
1295             while( ( p_outpic =
1296                 vout_CreatePicture( p_vout->p_sys->pp_vout[ i_vout ].p_vout,
1297                                     0, 0, 0 )
1298                    ) == NULL )
1299             {
1300                 if( p_vout->b_die || p_vout->b_error )
1301                 {
1302                     vout_DestroyPicture(
1303                         p_vout->p_sys->pp_vout[ i_vout ].p_vout, p_outpic );
1304                     return;
1305                 }
1306
1307                 msleep( VOUT_OUTMEM_SLEEP );
1308             }
1309
1310             vout_DatePicture( p_vout->p_sys->pp_vout[ i_vout ].p_vout,
1311                               p_outpic, p_pic->date );
1312             vout_LinkPicture( p_vout->p_sys->pp_vout[ i_vout ].p_vout,
1313                               p_outpic );
1314
1315             for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ )
1316             {
1317                 uint8_t *p_in, *p_in_end, *p_out;
1318                 int i_in_pitch = p_pic->p[i_plane].i_pitch;
1319                 int i_out_pitch = p_outpic->p[i_plane].i_pitch;
1320                 int i_copy_pitch = p_outpic->p[i_plane].i_visible_pitch;
1321
1322 #ifdef OVERLAP
1323                 if (i_col) pi_left_skip[i_plane] -= (2 * p_vout->p_sys->i_halfLength) * p_pic->p->i_pixel_pitch;
1324                 if ((i_row) && (!i_col)) pi_top_skip[i_plane] -= (2 * p_vout->p_sys->i_halfHeight * p_pic->p[i_plane].i_pitch);
1325                 if ((!p_vout->p_sys->pp_vout[p_vout->p_sys->i_col].b_active))
1326                     pi_top_skip[i_plane] -= (2 * p_vout->p_sys->i_halfHeight * i_row * p_pic->p[i_plane].i_pitch);
1327 // i_n : previous inactive pp_vout
1328                 int i_n=0;
1329                 while ((!p_vout->p_sys->pp_vout[i_row * p_vout->p_sys->i_col + i_col - 1 - i_n].b_active) && (i_col - i_n > 1)) i_n++;
1330                 if ((i_col > 1) && i_n)
1331                     pi_left_skip[i_plane] -= i_n*(2 * p_vout->p_sys->i_halfLength ) * p_pic->p->i_pixel_pitch;
1332
1333                 p_in = p_pic->p[i_plane].p_pixels
1334                 /* Wall proprities */
1335                 + pi_top_skip[i_plane] + pi_left_skip[i_plane];
1336
1337                 int i_lines = p_outpic->p[i_plane].i_visible_lines;
1338 // 1088 lines bug in a mpeg2 stream of 1080 lines
1339                 if ((p_vout->p_sys->i_row - 1 == i_row) &&
1340                     (p_pic->p[i_plane].i_lines == 1088))
1341                         i_lines -= 8;
1342
1343                 p_in_end = p_in + i_lines * p_pic->p[i_plane].i_pitch;
1344 #else
1345                 p_in = p_pic->p[i_plane].p_pixels
1346                         + pi_top_skip[i_plane] + pi_left_skip[i_plane];
1347
1348                 p_in_end = p_in + p_outpic->p[i_plane].i_visible_lines
1349                                         * p_pic->p[i_plane].i_pitch;
1350 #endif //OVERLAP
1351
1352                 p_out = p_outpic->p[i_plane].p_pixels;
1353
1354
1355 #ifdef OVERLAP
1356         if ((p_vout->p_sys->i_row > 2) && (!i_row))
1357             p_out += (p_outpic->p[i_plane].i_pitch * (2 * p_vout->p_sys->i_halfHeight) * p_pic->p->i_pixel_pitch);
1358
1359         int length;
1360         length = 2 * p_vout->p_sys->i_halfLength * p_pic->p->i_pixel_pitch;
1361
1362         if (p_vout->p_sys->b_has_changed)
1363         {
1364             int i_plane_;
1365             int i_col_mod;
1366             Denom = F2(length / p_pic->p->i_pixel_pitch);
1367             a_2 = p_vout->p_sys->a_2 * (ACCURACY / 100);
1368             a_1 = p_vout->p_sys->a_1 * 2 * p_vout->p_sys->i_halfLength * (ACCURACY / 100);
1369             a_0 = p_vout->p_sys->a_0 * Denom * (ACCURACY / 100);
1370             for(i_col_mod = 0; i_col_mod < 2; i_col_mod++)
1371                 for (i_index = 0; i_index < length / p_pic->p->i_pixel_pitch; i_index++)
1372                     for (i_plane_ =  0; i_plane_ < p_pic->p->i_pixel_pitch; i_plane_++)
1373                         p_vout->p_sys->lambda[i_col_mod][i_plane_][i_index] = CLIP_0A(!i_col_mod ? ACCURACY - (F4(a_2, a_1, i_index) + a_0) / Denom : ACCURACY - (F4(a_2, a_1,(length / p_pic->p->i_pixel_pitch) - i_index) + a_0) / Denom);
1374         }
1375 #endif
1376             while( p_in < p_in_end )
1377             {
1378 #ifndef OVERLAP
1379                 p_vout->p_libvlc->pf_memcpy( p_out, p_in, i_copy_pitch);
1380 #else
1381                 if (p_vout->p_sys->i_col > 2)
1382                 {
1383                     // vertical blend
1384                     length /= 2;
1385                     if (i_col == 0)
1386                         p_vout->p_libvlc->pf_memcpy( p_out + length, p_in, i_copy_pitch - length);
1387                     else if (i_col + 1 == p_vout->p_sys->i_col)
1388                             p_vout->p_libvlc->pf_memcpy( p_out, p_in - length, i_copy_pitch - length);
1389                          else
1390                             p_vout->p_libvlc->pf_memcpy( p_out, p_in - length, i_copy_pitch);
1391
1392                     if ((i_col == 0))
1393                     // black bar
1394                     {
1395                         LeftOffset = 0;
1396                         p_out += LeftOffset;
1397                         p_in += LeftOffset;
1398                         for (i_index = 0; i_index < length; i_index++)
1399                                 *(p_out + i_index) = 0;
1400                         p_out -= LeftOffset;
1401                         p_in -= LeftOffset;
1402                     }
1403                     else if ((i_col + 1 == p_vout->p_sys->i_col ))
1404                     // black bar
1405                         {
1406                             LeftOffset = i_copy_pitch - length;
1407                             p_out += LeftOffset;
1408                             p_in += LeftOffset;
1409                             for (i_index = 0; i_index < length; i_index++)
1410                                     *(p_out + i_index) = 0;
1411                             p_out -= LeftOffset;
1412                             p_in -= LeftOffset;
1413                         }
1414                     length *= 2;
1415                 }
1416                 else
1417                     p_vout->p_libvlc->pf_memcpy( p_out, p_in, i_copy_pitch);
1418
1419 // vertical blend
1420 // first blended zone
1421             if (i_col)
1422             {
1423                 LeftOffset = 0;
1424                 p_out += LeftOffset;
1425                 for (i_index = 0; i_index < length; i_index++)
1426 #ifndef GAMMA
1427                     *(p_out + i_index) = (p_vout->p_sys->lambda[1][i_index % p_pic->p->i_pixel_pitch][i_index / p_pic->p->i_pixel_pitch] *
1428                                  (*(p_out + i_index))) / ACCURACY;
1429 #else
1430                     *(p_out + i_index) = p_vout->p_sys->LUT[i_index % p_pic->p->i_pixel_pitch][p_vout->p_sys->lambda[1][i_index % p_pic->p->i_pixel_pitch][i_index / p_pic->p->i_pixel_pitch]][*(p_out + i_index)];
1431 #endif
1432                 p_out -= LeftOffset;
1433             }
1434 // second blended zone
1435             if (i_col + 1 < p_vout->p_sys->i_col)
1436             {
1437                 LeftOffset = i_copy_pitch - length;
1438                 p_out +=  LeftOffset;
1439                 for (i_index = 0; i_index < length; i_index++)
1440 #ifndef GAMMA
1441                     *(p_out + i_index) = (p_vout->p_sys->lambda[0][i_index % p_pic->p->i_pixel_pitch][i_index / p_pic->p->i_pixel_pitch] *
1442                                  (*(p_out + i_index))) / ACCURACY;
1443 #else
1444                     *(p_out + i_index) = p_vout->p_sys->LUT[i_index % p_pic->p->i_pixel_pitch][p_vout->p_sys->lambda[0][i_index % p_pic->p->i_pixel_pitch][i_index / p_pic->p->i_pixel_pitch]][*(p_out + i_index)];
1445 #endif
1446                 p_out -= LeftOffset;
1447             }
1448 // end blended zone
1449 #endif //OVERLAP
1450                 p_in += i_in_pitch;
1451                 p_out += i_out_pitch;
1452             }
1453 #ifdef OVERLAP
1454 // horizontal blend
1455         if (!p_vout->p_sys->b_attenuate)
1456         {
1457             if ((i_row == 0) && (p_vout->p_sys->i_row > 2))
1458             // black bar
1459             {
1460                     TopOffset = i_lines + (2 * p_vout->p_sys->i_halfHeight);
1461                     p_out -= TopOffset * p_outpic->p[i_plane].i_pitch;
1462                     for (i_index = 0; i_index < length; i_index++)
1463                         for (i_index2 = 0; i_index2 < i_copy_pitch; i_index2++)
1464                             *(p_out + (i_index * p_outpic->p[i_plane].i_pitch) + i_index2) = 0;
1465                     p_out += TopOffset * p_outpic->p[i_plane].i_pitch;
1466             }
1467             else if ((i_row + 1 == p_vout->p_sys->i_row) && (p_vout->p_sys->i_row > 2))
1468             // black bar
1469                 {
1470                     TopOffset = length - (2 * p_vout->p_sys->i_halfHeight);
1471                     p_out -= TopOffset * p_outpic->p[i_plane].i_pitch;
1472                     for (i_index = 0; i_index < length; i_index++)
1473                         for (i_index2 = 0; i_index2 < i_copy_pitch; i_index2++)
1474                             *(p_out + (i_index * p_outpic->p[i_plane].i_pitch) + i_index2) = 0;
1475                     p_out += TopOffset * p_outpic->p[i_plane].i_pitch;
1476                 }
1477         }
1478         else
1479         {
1480             if (p_vout->p_sys->i_row >= 2)
1481             {
1482                 length = 2 * p_vout->p_sys->i_halfHeight;
1483                 if (p_vout->p_sys->b_has_changed)
1484                 {
1485                     int i_plane_;
1486                     int i_row_mod;
1487                     Denom = F2(length);
1488                     a_2 = p_vout->p_sys->a_2 * (ACCURACY / 100);
1489                     a_1 = p_vout->p_sys->a_1 * length * (ACCURACY / 100);
1490                     a_0 = p_vout->p_sys->a_0 * Denom * (ACCURACY / 100);
1491                     for(i_row_mod = 0; i_row_mod < 2; i_row_mod++)
1492                       for (i_index = 0; i_index < length; i_index++)
1493                         for (i_plane_ =  0; i_plane_ < p_pic->p->i_pixel_pitch; i_plane_++)
1494                             p_vout->p_sys->lambda2[i_row_mod][i_plane_][i_index] = CLIP_0A(!i_row_mod ? ACCURACY - (F4(a_2, a_1, i_index) + a_0) / Denom : ACCURACY - (F4(a_2, a_1,(length) - i_index) + a_0) / Denom);
1495                 }
1496 // first blended zone
1497
1498             if (i_row)
1499             {
1500                 TopOffset = i_lines;
1501                 p_out -= TopOffset * p_outpic->p[i_plane].i_pitch;
1502                 for (i_index = 0; i_index < length; i_index++)
1503                     for (i_index2 = 0; i_index2 < i_copy_pitch; i_index2++)
1504 #ifndef GAMMA
1505                     *(p_out + (i_index * p_outpic->p[i_plane].i_pitch) + i_index2) = (p_vout->p_sys->lambda2[1][i_index2 % p_pic->p->i_pixel_pitch][i_index] *
1506                                  (*(p_out + (i_index * p_outpic->p[i_plane].i_pitch) + i_index2))) / ACCURACY;
1507 #else
1508                     *(p_out + (i_index * p_outpic->p[i_plane].i_pitch) + i_index2) = p_vout->p_sys->LUT[i_index2 % p_pic->p->i_pixel_pitch][p_vout->p_sys->lambda2[1][i_index2 % p_pic->p->i_pixel_pitch][i_index]][*(p_out + (i_index * p_outpic->p[i_plane].i_pitch) + i_index2)];
1509 #endif
1510                 p_out += TopOffset * p_outpic->p[i_plane].i_pitch;
1511             }
1512             else if (p_vout->p_sys->i_row > 2)
1513             // black bar
1514             {
1515                 TopOffset = i_lines + (2 * p_vout->p_sys->i_halfHeight);
1516                 p_out -= TopOffset * p_outpic->p[i_plane].i_pitch;
1517                 for (i_index = 0; i_index < length; i_index++)
1518                     for (i_index2 = 0; i_index2 < i_copy_pitch; i_index2++)
1519                         *(p_out + (i_index * p_outpic->p[i_plane].i_pitch) + i_index2) = 0;
1520                 p_out += TopOffset * p_outpic->p[i_plane].i_pitch;
1521             }
1522
1523 // second blended zone
1524
1525             if (i_row + 1 < p_vout->p_sys->i_row)
1526             {
1527                 TopOffset = length;
1528                 p_out -= TopOffset * p_outpic->p[i_plane].i_pitch;
1529                 for (i_index = 0; i_index < length; i_index++)
1530                     for (i_index2 = 0; i_index2 < i_copy_pitch; i_index2++)
1531 #ifndef GAMMA
1532                     *(p_out + (i_index * p_outpic->p[i_plane].i_pitch) + i_index2) = (p_vout->p_sys->lambda2[0][i_index2 % p_pic->p->i_pixel_pitch][i_index] *
1533                                  (*(p_out + (i_index * p_outpic->p[i_plane].i_pitch) + i_index2))) / ACCURACY;
1534 #else
1535                     *(p_out + (i_index * p_outpic->p[i_plane].i_pitch) + i_index2) = p_vout->p_sys->LUT[i_index2 % p_pic->p->i_pixel_pitch][p_vout->p_sys->lambda2[0][i_index2 % p_pic->p->i_pixel_pitch][i_index]][*(p_out + (i_index * p_outpic->p[i_plane].i_pitch) + i_index2)];
1536
1537 #endif
1538                 p_out += TopOffset * p_outpic->p[i_plane].i_pitch;
1539             }
1540             else if (p_vout->p_sys->i_row > 2)
1541             // black bar
1542             {
1543                 TopOffset = length - (2 * p_vout->p_sys->i_halfHeight);
1544                 p_out -= TopOffset * p_outpic->p[i_plane].i_pitch;
1545                 for (i_index = 0; i_index < length; i_index++)
1546                     for (i_index2 = 0; i_index2 < i_copy_pitch; i_index2++)
1547                         *(p_out + (i_index * p_outpic->p[i_plane].i_pitch) + i_index2) = 0;
1548                 p_out += TopOffset * p_outpic->p[i_plane].i_pitch;
1549             }
1550 // end blended zone
1551             }
1552         }
1553 #endif
1554 // bug for wall filter : fix by CC
1555 //            pi_left_skip[i_plane] += i_out_pitch;
1556             pi_left_skip[i_plane] += i_copy_pitch;
1557             }
1558
1559             vout_UnlinkPicture( p_vout->p_sys->pp_vout[ i_vout ].p_vout,
1560                                 p_outpic );
1561             vout_DisplayPicture( p_vout->p_sys->pp_vout[ i_vout ].p_vout,
1562                                  p_outpic );
1563             i_vout++;
1564         }
1565
1566         for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ )
1567         {
1568             pi_top_skip[i_plane] += p_vout->p_sys->pp_vout[ i_vout ].i_height
1569                                      * p_pic->p[i_plane].i_lines
1570                                      / p_vout->output.i_height
1571                                      * p_pic->p[i_plane].i_pitch;
1572         }
1573     }
1574 #ifdef OVERLAP
1575     if (p_vout->p_sys->b_has_changed) p_vout->p_sys->b_has_changed = VLC_FALSE;
1576 #endif
1577 }
1578
1579
1580 #ifdef PACKED_YUV
1581 // WARNING : NO DEBUGGED
1582 /*****************************************************************************
1583  * RenderPackedYUV: displays previously rendered output
1584  *****************************************************************************
1585  * This function send the currently rendered image to Wall image, waits
1586  * until it is displayed and switch the two rendering buffers, preparing next
1587  * frame.
1588  *****************************************************************************/
1589 static void RenderPackedYUV( vout_thread_t *p_vout, picture_t *p_pic )
1590 {
1591     picture_t *p_outpic = NULL;
1592     int i_col, i_row, i_vout, i_plane;
1593     int pi_left_skip[VOUT_MAX_PLANES], pi_top_skip[VOUT_MAX_PLANES];
1594 #ifdef OVERLAP
1595     int LeftOffset, TopOffset;
1596     int constantYUV[3] = {0,128,128};
1597     int Denom;
1598     int a_2;
1599     int a_1;
1600     int a_0;
1601     int i_index, i_index2;
1602 #endif
1603
1604
1605     i_vout = 0;
1606
1607     for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ )
1608     {
1609         pi_top_skip[i_plane] = 0;
1610     }
1611
1612     for( i_row = 0; i_row < p_vout->p_sys->i_row; i_row++ )
1613     {
1614         for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ )
1615         {
1616             pi_left_skip[i_plane] = 0;
1617         }
1618
1619         for( i_col = 0; i_col < p_vout->p_sys->i_col; i_col++ )
1620         {
1621             if( !p_vout->p_sys->pp_vout[ i_vout ].b_active )
1622             {
1623                 for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ )
1624                 {
1625                     pi_left_skip[i_plane] +=
1626                         p_vout->p_sys->pp_vout[ i_vout ].i_width
1627                          * p_pic->p[i_plane].i_pitch / p_vout->output.i_width;
1628                 }
1629                 i_vout++;
1630                 continue;
1631             }
1632
1633             while( ( p_outpic =
1634                 vout_CreatePicture( p_vout->p_sys->pp_vout[ i_vout ].p_vout,
1635                                     0, 0, 0 )
1636                    ) == NULL )
1637             {
1638                 if( p_vout->b_die || p_vout->b_error )
1639                 {
1640                     vout_DestroyPicture(
1641                         p_vout->p_sys->pp_vout[ i_vout ].p_vout, p_outpic );
1642                     return;
1643                 }
1644
1645                 msleep( VOUT_OUTMEM_SLEEP );
1646             }
1647
1648             vout_DatePicture( p_vout->p_sys->pp_vout[ i_vout ].p_vout,
1649                               p_outpic, p_pic->date );
1650             vout_LinkPicture( p_vout->p_sys->pp_vout[ i_vout ].p_vout,
1651                               p_outpic );
1652
1653             for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ )
1654             {
1655                 uint8_t *p_in, *p_in_end, *p_out;
1656                 int i_in_pitch = p_pic->p[i_plane].i_pitch;
1657                 int i_out_pitch = p_outpic->p[i_plane].i_pitch;
1658                 int i_copy_pitch = p_outpic->p[i_plane].i_visible_pitch;
1659
1660 #ifdef OVERLAP
1661                 if (i_col) pi_left_skip[i_plane] -= (2 * p_vout->p_sys->i_halfLength ) / (p_vout->p_sys->pp_vout[i_vout].i_width / i_copy_pitch);
1662                 if ((i_row) && (!i_col)) pi_top_skip[i_plane] -= (2 * p_vout->p_sys->i_halfHeight * p_pic->p[i_plane].i_pitch) / (p_vout->p_sys->pp_vout[i_vout].i_width / i_copy_pitch);
1663                 if ((p_vout->p_sys->i_row > 2) && (i_row == 1) && (!i_col)) pi_top_skip[i_plane] -= (2 * p_vout->p_sys->i_halfHeight * p_pic->p[i_plane].i_pitch) / (p_vout->p_sys->pp_vout[i_vout].i_width / i_copy_pitch);
1664                 if ((!p_vout->p_sys->pp_vout[p_vout->p_sys->i_col].b_active))
1665                     pi_top_skip[i_plane] -= (2 * p_vout->p_sys->i_halfHeight * i_row * p_pic->p[i_plane].i_pitch) / (p_vout->p_sys->pp_vout[i_vout].i_width / i_copy_pitch);
1666 // i_n : previous inactive pp_vout
1667                 int i_n=0;
1668                 while ((!p_vout->p_sys->pp_vout[i_row * p_vout->p_sys->i_col + i_col - 1 - i_n].b_active) && (i_col - i_n > 1)) i_n++;
1669                 if ((i_col > 1) && i_n)
1670                     pi_left_skip[i_plane] -= i_n*(2 * p_vout->p_sys->i_halfLength ) / (p_vout->p_sys->pp_vout[i_vout].i_width / i_copy_pitch);
1671
1672                 p_in = p_pic->p[i_plane].p_pixels
1673                 /* Wall proprities */
1674                 + pi_top_skip[i_plane] + pi_left_skip[i_plane];
1675
1676                 int i_lines = p_outpic->p[i_plane].i_visible_lines;
1677 // 1088 lines bug in a mpeg2 stream of 1080 lines
1678                 if ((p_vout->p_sys->i_row - 1 == i_row) &&
1679                     (p_pic->p[i_plane].i_lines == 1088))
1680                         i_lines -= 8;
1681
1682                 p_in_end = p_in + i_lines * p_pic->p[i_plane].i_pitch;
1683 #else
1684                 p_in = p_pic->p[i_plane].p_pixels
1685                         + pi_top_skip[i_plane] + pi_left_skip[i_plane];
1686
1687                 p_in_end = p_in + p_outpic->p[i_plane].i_visible_lines
1688                                         * p_pic->p[i_plane].i_pitch;
1689 #endif
1690                 p_out = p_outpic->p[i_plane].p_pixels;
1691 #ifdef OVERLAP
1692         int length;
1693         length = 2 * p_vout->p_sys->i_halfLength * p_pic->p->i_pixel_pitch;
1694         LeftOffset = (i_col ? 0 : i_copy_pitch - length);
1695         if (p_vout->p_sys->b_has_changed)
1696         {
1697 #ifdef GAMMA
1698             int i_plane_;
1699             for (i_index = 0; i_index < length / p_pic->p->i_pixel_pitch; i_index++)
1700                 for (i_plane_ =  0; i_plane_ < p_pic->p->i_pixel_pitch; i_plane_++)
1701                     for (i_index2 = 0; i_index2 < 256; i_index2++)
1702                             p_vout->p_sys->LUT[i_plane_][i_index2][i_index] = F(i_index2, (length / p_pic->p->i_pixel_pitch, i_index, p_vout->p_sys->f_gamma[i_plane_]));
1703 #endif
1704             switch (p_vout->output.i_chroma)
1705                 {
1706                     case VLC_FOURCC('Y','U','Y','2'):    // packed by 2
1707                     case VLC_FOURCC('Y','U','N','V'):    // packed by 2
1708                         Denom = F2(length / p_pic->p->i_pixel_pitch);
1709                         a_2 = p_vout->p_sys->a_2 * (ACCURACY / 100);
1710                         a_1 = p_vout->p_sys->a_1 * 2 * p_vout->p_sys->i_halfLength * (ACCURACY / 100);
1711                         a_0 = p_vout->p_sys->a_0 * Denom * (ACCURACY / 100);
1712                         for (i_index = 0; i_index < length / p_pic->p->i_pixel_pitch; i_index+=p_pic->p->i_pixel_pitch)
1713                         // for each macropixel
1714                         {
1715                                 // first image pixel
1716                                 p_vout->p_sys->lambda[i_col][0][i_index] = CLIP_0A(!i_col ? ACCURACY - (F4(a_2, a_1, i_index) + a_0) / Denom : ACCURACY - (F4(a_2, a_1,(length / p_pic->p->i_pixel_pitch) - i_index) + a_0) / Denom);
1717                                 p_vout->p_sys->cstYUV[i_col][0][i_index] = ((ACCURACY - p_vout->p_sys->lambda[i_col][0][i_index]) * constantYUV[0]) / ACCURACY;
1718                                 p_vout->p_sys->lambda[i_col][1][i_index] = CLIP_0A(!i_col ? ACCURACY - (F4(a_2, a_1, i_index) + a_0) / Denom : ACCURACY - (F4(a_2, a_1,(length / p_pic->p->i_pixel_pitch) - i_index) + a_0) / Denom);
1719                                 p_vout->p_sys->cstYUV[i_col][1][i_index] = ((ACCURACY - p_vout->p_sys->lambda[i_col][1][i_index]) * constantYUV[1]) / ACCURACY;
1720                                 // second image pixel
1721                                 p_vout->p_sys->lambda[i_col][0][i_index + 1] = CLIP_0A(!i_col ? ACCURACY - (F4(a_2, a_1, i_index + 1) + a_0) / Denom : ACCURACY - (F4(a_2, a_1,(length / p_pic->p->i_pixel_pitch) - (i_index + 1)) + a_0) / Denom);
1722                                 p_vout->p_sys->cstYUV[i_col][0][i_index + 1] = ((ACCURACY - p_vout->p_sys->lambda[i_col][0][i_index]) * constantYUV[0]) / ACCURACY;
1723                                 p_vout->p_sys->lambda[i_col][1][i_index + 1] = p_vout->p_sys->lambda[i_col][1][i_index];
1724                                 p_vout->p_sys->cstYUV[i_col][1][i_index + 1] = p_vout->p_sys->cstYUV[i_col][1][i_index];
1725                         }
1726                         break;
1727                     case VLC_FOURCC('U','Y','V','Y'):    // packed by 2
1728                     case VLC_FOURCC('U','Y','N','V'):    // packed by 2
1729                     case VLC_FOURCC('Y','4','2','2'):    // packed by 2
1730                         Denom = F2(length / p_pic->p->i_pixel_pitch);
1731                         a_2 = p_vout->p_sys->a_2 * (ACCURACY / 100);
1732                         a_1 = p_vout->p_sys->a_1 * 2 * p_vout->p_sys->i_halfLength * (ACCURACY / 100);
1733                         a_0 = p_vout->p_sys->a_0 * Denom * (ACCURACY / 100);
1734                         for (i_index = 0; i_index < length / p_pic->p->i_pixel_pitch; i_index+=p_pic->p->i_pixel_pitch)
1735                         // for each macropixel
1736                         {
1737                                 // first image pixel
1738                                 p_vout->p_sys->lambda[i_col][0][i_index] = CLIP_0A(!i_col ? ACCURACY - (F4(a_2, a_1, i_index) + a_0) / Denom : ACCURACY - (F4(a_2, a_1,(length / p_pic->p->i_pixel_pitch) - i_index) + a_0) / Denom);
1739                                 p_vout->p_sys->cstYUV[i_col][0][i_index] = ((ACCURACY - p_vout->p_sys->lambda[i_col][0][i_index]) * constantYUV[1]) / ACCURACY;
1740                                 p_vout->p_sys->lambda[i_col][1][i_index] = CLIP_0A(!i_col ? ACCURACY - (F4(a_2, a_1, i_index) + a_0) / Denom : ACCURACY - (F4(a_2, a_1,(length / p_pic->p->i_pixel_pitch) - i_index) + a_0) / Denom);
1741                                 p_vout->p_sys->cstYUV[i_col][1][i_index] = ((ACCURACY - p_vout->p_sys->lambda[i_col][1][i_index]) * constantYUV[0]) / ACCURACY;
1742                                 // second image pixel
1743                                 p_vout->p_sys->lambda[i_col][0][i_index + 1] = CLIP_0A(!i_col ? ACCURACY - (F4(a_2, a_1, i_index + 1) + a_0) / Denom : ACCURACY - (F4(a_2, a_1,(length / p_pic->p->i_pixel_pitch) - (i_index + 1)) + a_0) / Denom);
1744                                 p_vout->p_sys->cstYUV[i_col][0][i_index + 1] = ((ACCURACY - p_vout->p_sys->lambda[i_col][0][i_index]) * constantYUV[1]) / ACCURACY;
1745                                 p_vout->p_sys->lambda[i_col][1][i_index + 1] = p_vout->p_sys->lambda[i_col][1][i_index];
1746                                 p_vout->p_sys->cstYUV[i_col][1][i_index + 1] = p_vout->p_sys->cstYUV[i_col][1][i_index];
1747                         }
1748                         break;
1749                     default :
1750                         break;
1751                 }
1752         }
1753 #endif
1754             while( p_in < p_in_end )
1755             {
1756 #ifndef OVERLAP
1757                 p_vout->p_libvlc->pf_memcpy( p_out, p_in, i_copy_pitch);
1758 #else
1759                 p_vout->p_libvlc->pf_memcpy( p_out + i_col * length, p_in + i_col * length, i_copy_pitch - length);
1760                 p_out += LeftOffset;
1761                 p_in += LeftOffset;
1762 #ifndef GAMMA
1763                 for (i_index = 0; i_index < length; i_index++)
1764                     *(p_out + i_index) = (p_vout->p_sys->lambda[i_col][i_index % p_pic->p->i_pixel_pitch][i_index / p_pic->p->i_pixel_pitch] *
1765                              (*(p_in + i_index))) / ACCURACY +
1766                              p_vout->p_sys->cstYUV[i_col][i_index % p_pic->p->i_pixel_pitch][i_index / p_pic->p->i_pixel_pitch];
1767 #else
1768                 for (i_index = 0; i_index < length; i_index++)
1769                     *(p_out + i_index) = p_vout->p_sys->LUT[i_index % p_pic->p->i_pixel_pitch][(p_vout->p_sys->lambda[i_col][i_index % p_pic->p->i_pixel_pitch][i_index / p_pic->p->i_pixel_pitch] *
1770                              (*(p_in + i_index))) / ACCURACY +
1771                              p_vout->p_sys->cstYUV[i_col][i_index % p_pic->p->i_pixel_pitch][i_index / p_pic->p->i_pixel_pitch]][i_index / p_pic->p->i_pixel_pitch];
1772 #endif
1773                 p_out -= LeftOffset;
1774                 p_in -= LeftOffset;
1775 #endif
1776                 p_in += i_in_pitch;
1777                 p_out += i_out_pitch;
1778             }
1779 #ifdef OVERLAP
1780             if (p_vout->p_sys->i_row == 2)
1781             {
1782                         length = 2 * p_vout->p_sys->i_halfHeight * p_pic->p->i_pixel_pitch;
1783                         TopOffset = (i_row ? i_lines : length / p_pic->p->i_pixel_pitch);
1784                         if (p_vout->p_sys->b_has_changed)
1785                         {
1786 #ifdef GAMMA
1787                                 int i_plane_;
1788                                 for (i_index = 0; i_index < length / p_pic->p->i_pixel_pitch; i_index++)
1789                                     for (i_plane_ =  0; i_plane_ < p_pic->p->i_pixel_pitch; i_plane_++)
1790                                         for (i_index2 = 0; i_index2 < 256; i_index2++)
1791                                                 p_vout->p_sys->LUT2[i_plane_][i_index2][i_index] = F(i_index2, (length / p_pic->p->i_pixel_pitch, i_index, p_vout->p_sys->f_gamma[i_plane_]));
1792 #endif
1793                                 switch (p_vout->output.i_chroma)
1794                                 {
1795                                     case VLC_FOURCC('Y','U','Y','2'):    // packed by 2
1796                                     case VLC_FOURCC('Y','U','N','V'):    // packed by 2
1797                                         Denom = F2(length / p_pic->p->i_pixel_pitch);
1798                                         a_2 = p_vout->p_sys->a_2 * (ACCURACY / 100);
1799                                         a_1 = p_vout->p_sys->a_1 * 2 * p_vout->p_sys->i_halfHeight * (ACCURACY / 100);
1800                                         a_0 = p_vout->p_sys->a_0 * Denom * (ACCURACY / 100);
1801                                         for (i_index = 0; i_index < length / p_pic->p->i_pixel_pitch; i_index+=p_pic->p->i_pixel_pitch)
1802                                         // for each macropixel
1803                                         {
1804                                                 // first image pixel
1805                                                 p_vout->p_sys->lambda2[i_row][0][i_index] = CLIP_0A(!i_row ? ACCURACY - (F4(a_2, a_1, i_index) + a_0) / Denom : ACCURACY - (F4(a_2, a_1,(length / p_pic->p->i_pixel_pitch) - i_index) + a_0) / Denom);
1806                                                 p_vout->p_sys->cstYUV2[i_row][0][i_index] = ((ACCURACY - p_vout->p_sys->lambda2[i_row][0][i_index]) * constantYUV[0]) / ACCURACY;
1807                                                 p_vout->p_sys->lambda2[i_row][1][i_index] = CLIP_0A(!i_row ? ACCURACY - (F4(a_2, a_1, i_index) + a_0) / Denom : ACCURACY - (F4(a_2, a_1,(length / p_pic->p->i_pixel_pitch) - i_index) + a_0) / Denom);
1808                                                 p_vout->p_sys->cstYUV2[i_row][1][i_index] = ((ACCURACY - p_vout->p_sys->lambda2[i_row][1][i_index]) * constantYUV[1]) / ACCURACY;
1809                                                 // second image pixel
1810                                                 p_vout->p_sys->lambda2[i_row][0][i_index + 1] = CLIP_0A(!i_row ? ACCURACY - (F4(a_2, a_1, i_index + 1) + a_0) / Denom : ACCURACY - (F4(a_2, a_1,(length / p_pic->p->i_pixel_pitch) - (i_index + 1)) + a_0) / Denom);
1811                                                 p_vout->p_sys->cstYUV2[i_row][0][i_index + 1] = ((ACCURACY - p_vout->p_sys->lambda2[i_row][0][i_index]) * constantYUV[0]) / ACCURACY;
1812                                                 p_vout->p_sys->lambda2[i_row][1][i_index + 1] = p_vout->p_sys->lambda2[i_row][1][i_index];
1813                                                 p_vout->p_sys->cstYUV2[i_row][1][i_index + 1] = p_vout->p_sys->cstYUV2[i_row][1][i_index];
1814                                         }
1815                                         break;
1816                                     case VLC_FOURCC('U','Y','V','Y'):    // packed by 2
1817                                     case VLC_FOURCC('U','Y','N','V'):    // packed by 2
1818                                     case VLC_FOURCC('Y','4','2','2'):    // packed by 2
1819                                         Denom = F2(length / p_pic->p->i_pixel_pitch);
1820                                         a_2 = p_vout->p_sys->a_2 * (ACCURACY / 100);
1821                                         a_1 = p_vout->p_sys->a_1 * 2 * p_vout->p_sys->i_halfHeight * (ACCURACY / 100);
1822                                         a_0 = p_vout->p_sys->a_0 * Denom * (ACCURACY / 100);
1823                                         for (i_index = 0; i_index < length / p_pic->p->i_pixel_pitch; i_index+=p_pic->p->i_pixel_pitch)
1824                                         // for each macropixel
1825                                         {
1826                                                 // first image pixel
1827                                                 p_vout->p_sys->lambda2[i_row][0][i_index] = CLIP_0A(!i_row ? ACCURACY - (F4(a_2, a_1, i_index) + a_0) / Denom : ACCURACY - (F4(a_2, a_1,(length / p_pic->p->i_pixel_pitch) - i_index) + a_0) / Denom);
1828                                                 p_vout->p_sys->cstYUV2[i_row][0][i_index] = ((ACCURACY - p_vout->p_sys->lambda2[i_col][0][i_index]) * constantYUV[1]) / ACCURACY;
1829                                                 p_vout->p_sys->lambda2[i_row][1][i_index] = CLIP_0A(!i_row ? ACCURACY - (F4(a_2, a_1, i_index) + a_0) / Denom : ACCURACY - (F4(a_2, a_1,(length / p_pic->p->i_pixel_pitch) - i_index) + a_0) / Denom);
1830                                                 p_vout->p_sys->cstYUV2[i_row][1][i_index] = ((ACCURACY - p_vout->p_sys->lambda2[i_row][1][i_index]) * constantYUV[0]) / ACCURACY;
1831                                                 // second image pixel
1832                                                 p_vout->p_sys->lambda2[i_row][0][i_index + 1] = CLIP_0A(!i_row ? ACCURACY - (F4(a_2, a_1, i_index + 1) + a_0) / Denom : ACCURACY - (F4(a_2, a_1,(length / p_pic->p->i_pixel_pitch) - (i_index + 1)) + a_0) / Denom);
1833                                                 p_vout->p_sys->cstYUV2[i_row][0][i_index + 1] = ((ACCURACY - p_vout->p_sys->lambda2[i_row][0][i_index]) * constantYUV[1]) / ACCURACY;
1834                                                 p_vout->p_sys->lambda2[i_row][1][i_index + 1] = p_vout->p_sys->lambda2[i_row][1][i_index];
1835                                                 p_vout->p_sys->cstYUV2[i_row][1][i_index + 1] = p_vout->p_sys->cstYUV2[i_row][1][i_index];
1836                                         }
1837                                         break;
1838                                     default :
1839                                         break;
1840                                 }
1841                         }
1842                         p_out -= TopOffset * p_outpic->p[i_plane].i_pitch;
1843 #ifndef GAMMA
1844                         for (i_index = 0; i_index < length / p_pic->p->i_pixel_pitch; i_index++)
1845                             for (i_index2 = 0; i_index2 < i_copy_pitch; i_index2++)
1846                                 *(p_out + (i_index * p_outpic->p[i_plane].i_pitch) + i_index2) = (p_vout->p_sys->lambda2[i_row][i_index2 % p_pic->p->i_pixel_pitch][i_index] *
1847                                      (*(p_out + (i_index * p_outpic->p[i_plane].i_pitch) + i_index2))) / ACCURACY +
1848                                      p_vout->p_sys->cstYUV2[i_row][i_index2 % p_pic->p->i_pixel_pitch][i_index];
1849 #else
1850                         for (i_index = 0; i_index < length / p_pic->p->i_pixel_pitch; i_index++)
1851                             for (i_index2 = 0; i_index2 < i_copy_pitch; i_index2++)
1852                                 *(p_out + (i_index * p_outpic->p[i_plane].i_pitch) + i_index2) = p_vout->p_sys->LUT[i_index % p_pic->p->i_pixel_pitch][(p_vout->p_sys->lambda2[i_row][i_index2 % p_pic->p->i_pixel_pitch][i_index] *
1853                                      (*(p_out + (i_index * p_outpic->p[i_plane].i_pitch) + i_index2))) / ACCURACY +
1854                                      p_vout->p_sys->cstYUV2[i_row][i_index2 % p_pic->p->i_pixel_pitch][i_index]][i_index / p_pic->p->i_pixel_pitch];
1855
1856 #endif
1857                         p_out += TopOffset * p_outpic->p[i_plane].i_pitch;
1858             }
1859 #endif
1860 // bug for wall filter : fix by CC
1861 //            pi_left_skip[i_plane] += i_out_pitch;
1862             pi_left_skip[i_plane] += i_copy_pitch;
1863             }
1864
1865             vout_UnlinkPicture( p_vout->p_sys->pp_vout[ i_vout ].p_vout,
1866                                 p_outpic );
1867             vout_DisplayPicture( p_vout->p_sys->pp_vout[ i_vout ].p_vout,
1868                                  p_outpic );
1869             i_vout++;
1870         }
1871
1872         for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ )
1873         {
1874             pi_top_skip[i_plane] += p_vout->p_sys->pp_vout[ i_vout ].i_height
1875                                      * p_pic->p[i_plane].i_lines
1876                                      / p_vout->output.i_height
1877                                      * p_pic->p[i_plane].i_pitch;
1878         }
1879     }
1880 #ifdef OVERLAP
1881     if (p_vout->p_sys->b_has_changed) p_vout->p_sys->b_has_changed = VLC_FALSE;
1882 #endif
1883 }
1884 #endif
1885
1886
1887 /*****************************************************************************
1888  * RemoveAllVout: destroy all the child video output threads
1889  *****************************************************************************/
1890 static void RemoveAllVout( vout_thread_t *p_vout )
1891 {
1892     while( p_vout->p_sys->i_vout )
1893     {
1894          --p_vout->p_sys->i_vout;
1895          if( p_vout->p_sys->pp_vout[ p_vout->p_sys->i_vout ].b_active )
1896          {
1897              DEL_CALLBACKS(
1898                  p_vout->p_sys->pp_vout[ p_vout->p_sys->i_vout ].p_vout,
1899                  SendEvents );
1900              vlc_object_detach(
1901                  p_vout->p_sys->pp_vout[ p_vout->p_sys->i_vout ].p_vout );
1902              vout_Destroy(
1903                  p_vout->p_sys->pp_vout[ p_vout->p_sys->i_vout ].p_vout );
1904          }
1905     }
1906 }
1907
1908 /*****************************************************************************
1909  * SendEvents: forward mouse and keyboard events to the parent p_vout
1910  *****************************************************************************/
1911 static int SendEvents( vlc_object_t *p_this, char const *psz_var,
1912                        vlc_value_t oldval, vlc_value_t newval, void *_p_vout )
1913 {
1914     vout_thread_t *p_vout = (vout_thread_t *)_p_vout;
1915     int i_vout;
1916     vlc_value_t sentval = newval;
1917
1918     /* Find the video output index */
1919     for( i_vout = 0; i_vout < p_vout->p_sys->i_vout; i_vout++ )
1920     {
1921         if( p_this == (vlc_object_t *)p_vout->p_sys->pp_vout[ i_vout ].p_vout )
1922         {
1923             break;
1924         }
1925     }
1926
1927     if( i_vout == p_vout->p_sys->i_vout )
1928     {
1929         return VLC_EGENERIC;
1930     }
1931
1932     /* Translate the mouse coordinates */
1933     if( !strcmp( psz_var, "mouse-x" ) )
1934     {
1935 #ifdef OVERLAP
1936         int i_overlap = ((p_vout->p_sys->i_col > 2) ? 0 : 2 * p_vout->p_sys->i_halfLength);
1937            sentval.i_int += (p_vout->output.i_width - i_overlap)
1938 #else
1939            sentval.i_int += p_vout->output.i_width
1940 #endif
1941                          * (i_vout % p_vout->p_sys->i_col)
1942                           / p_vout->p_sys->i_col;
1943     }
1944     else if( !strcmp( psz_var, "mouse-y" ) )
1945     {
1946 #ifdef OVERLAP
1947         int i_overlap = ((p_vout->p_sys->i_row > 2) ? 0 : 2 * p_vout->p_sys->i_halfHeight);
1948            sentval.i_int += (p_vout->output.i_height - i_overlap)
1949 #else
1950            sentval.i_int += p_vout->output.i_height
1951 #endif
1952 //bug fix in Wall plug-in
1953 //                         * (i_vout / p_vout->p_sys->i_row)
1954                          * (i_vout / p_vout->p_sys->i_col)
1955                           / p_vout->p_sys->i_row;
1956     }
1957
1958     var_Set( p_vout, psz_var, sentval );
1959
1960     return VLC_SUCCESS;
1961 }
1962
1963 /*****************************************************************************
1964  * SendEventsToChild: forward events to the child/children vout
1965  *****************************************************************************/
1966 static int SendEventsToChild( vlc_object_t *p_this, char const *psz_var,
1967                        vlc_value_t oldval, vlc_value_t newval, void *p_data )
1968 {
1969
1970     vout_thread_t *p_vout = (vout_thread_t *)p_this;
1971     int i_row, i_col, i_vout = 0;
1972
1973     for( i_row = 0; i_row < p_vout->p_sys->i_row; i_row++ )
1974     {
1975         for( i_col = 0; i_col < p_vout->p_sys->i_col; i_col++ )
1976         {
1977             var_Set( p_vout->p_sys->pp_vout[ i_vout ].p_vout, psz_var, newval);
1978             if( !strcmp( psz_var, "fullscreen" ) ) break;
1979             i_vout++;
1980         }
1981     }
1982
1983     return VLC_SUCCESS;
1984 }