]> git.sesse.net Git - vlc/blob - modules/video_filter/panoramix.c
62f74afcee86f0f036aeb4949196feeafa4c54a0
[vlc] / 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 /*****************************************************************************
503  * F: Function to calculate Gamma correction
504  *****************************************************************************/
505 static uint8_t F(uint8_t i, float gamma)
506 {
507  double input = (double) i / 255.0;
508
509 // return clip(255 * pow(input, 1.0 / gamma));
510
511  if (input < 0.5)
512      return clip_uint8((255 * pow(2 * input, gamma)) / 2);
513  else
514      return clip_uint8(255 * (1 - pow(2 * (1 - input), gamma) / 2));
515
516 }
517 #endif
518 #endif
519
520 /*****************************************************************************
521  * AdjustHeight: ajust p_sys->i_height to have same BZ width for any ratio
522  *****************************************************************************/
523 static int AdjustHeight( vout_thread_t *p_vout )
524 {
525     vlc_bool_t b_fullscreen = var_CreateGetInteger( p_vout, "fullscreen" );
526     int i_window_width = p_vout->i_window_width;
527     int i_window_height = p_vout->i_window_height;
528     double d_halfLength = 0;
529     double d_halfLength_crop;
530     double d_halfLength_calculated;
531     int    i_offset = 0;
532
533 // OS DEPENDANT CODE to get display dimensions
534         if (b_fullscreen)
535         {
536 #ifdef SYS_MINGW32
537             i_window_width  = GetSystemMetrics(SM_CXSCREEN);
538             i_window_height = GetSystemMetrics(SM_CYSCREEN);
539 #else
540             Display *p_display = XOpenDisplay( "" );
541                 if (p_vout->p_sys->b_xinerama)
542                 {
543                     i_window_width = DisplayWidth(p_display, 0) / p_vout->p_sys->i_col;
544                     i_window_height = DisplayHeight(p_display, 0) / p_vout->p_sys->i_row;
545                  }
546                 else
547                 {
548                     i_window_width = DisplayWidth(p_display, 0);
549                     i_window_height = DisplayHeight(p_display, 0);
550                 }
551                 XCloseDisplay( p_display );
552                 free(p_display);
553 #endif
554         var_SetInteger( p_vout, "width", i_window_width);
555         var_SetInteger( p_vout, "height", i_window_height);
556         p_vout->i_window_width = i_window_width;
557            p_vout->i_window_height = i_window_height;
558         }
559
560         if (p_vout->p_sys->bz_length)
561         if ((!p_vout->p_sys->b_autocrop) && (!p_vout->p_sys->i_ratio))
562         {
563             if ((p_vout->p_sys->i_row > 1) || (p_vout->p_sys->i_col > 1))
564             {
565               while ((d_halfLength <= 0) || (d_halfLength > p_vout->render.i_width / (2 * p_vout->p_sys->i_col)))
566               {
567                 if (p_vout->p_sys->bz_length >= 50)
568                     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);
569                 else
570                 {
571                     d_halfLength = (p_vout->render.i_width * p_vout->p_sys->bz_length) / (100.0 * p_vout->p_sys->i_col);
572                     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);
573                 }
574                 if ((d_halfLength <= 0) || (d_halfLength > p_vout->render.i_width / (2 * p_vout->p_sys->i_col))) p_vout->p_sys->i_row--;
575                 if (p_vout->p_sys->i_row < 1 )
576                 {
577                     p_vout->p_sys->i_row = 1;
578                     break;
579                 }
580               }
581               p_vout->p_sys->i_halfLength = (d_halfLength + 0.5);
582               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;
583               var_SetInteger( p_vout, "bz-length", p_vout->p_sys->bz_length);
584               var_SetInteger( p_vout, "panoramix-rows", p_vout->p_sys->i_row);
585               }
586         }
587         else
588         {
589             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;
590             d_halfLength_crop = d_halfLength * VOUT_ASPECT_FACTOR * (double)p_vout->output.i_width
591                         / (double)i_window_height / (double)p_vout->render.i_aspect;
592             p_vout->p_sys->i_halfLength = (d_halfLength_crop + 0.5);
593             d_halfLength_calculated = p_vout->p_sys->i_halfLength * (double)i_window_height *
594                                 (double)p_vout->render.i_aspect  /     VOUT_ASPECT_FACTOR / (double)p_vout->output.i_width;
595
596             if (!p_vout->p_sys->b_attenuate)
597             {
598                 double d_bz_length = (p_vout->p_sys->i_halfLength * p_vout->p_sys->i_col * 100.0) / p_vout->render.i_width;
599                 // F(2x) != 2F(x) in opengl module
600                 if (p_vout->p_sys->i_col == 2) d_bz_length = (100.0 * d_bz_length) / (100.0 - d_bz_length) ;
601                 var_SetInteger( p_vout, "bz-length", (int)(d_bz_length + 0.5));
602             }
603             i_offset =  (int)d_halfLength - (int)
604                         (p_vout->p_sys->i_halfLength * (double)i_window_height *
605                         (double)p_vout->render.i_aspect  /     VOUT_ASPECT_FACTOR / (double)p_vout->output.i_width);
606         }
607         else
608             d_halfLength = 0;
609
610         return i_offset;
611 }
612 #endif
613
614
615 /*****************************************************************************
616  * Init: initialize Wall video thread output method
617  *****************************************************************************/
618 static int Init( vout_thread_t *p_vout )
619 {
620     int i_index, i_row, i_col, i_width, i_height;
621     picture_t *p_pic;
622
623     I_OUTPUTPICTURES = 0;
624
625     /* Initialize the output structure */
626     p_vout->output.i_chroma = p_vout->render.i_chroma;
627     p_vout->output.i_width  = p_vout->render.i_width;
628     p_vout->output.i_height = p_vout->render.i_height;
629     p_vout->output.i_aspect = p_vout->render.i_aspect;
630 #ifdef OVERLAP
631     p_vout->p_sys->b_has_changed = p_vout->p_sys->b_attenuate;
632         int i_video_x = var_GetInteger( p_vout, "video-x");
633     int i_video_y = var_GetInteger( p_vout, "video-y");
634 #ifdef GAMMA
635     if (p_vout->p_sys->b_attenuate)
636     {
637         int i_index2, i_plane;
638         int constantYUV[3] = {0,128,128};
639         float    f_BlackCrush[VOUT_MAX_PLANES];
640         float    f_BlackLevel[VOUT_MAX_PLANES];
641         float    f_WhiteCrush[VOUT_MAX_PLANES];
642         float    f_WhiteLevel[VOUT_MAX_PLANES];
643         p_vout->p_sys->f_gamma[0] = var_CreateGetFloat( p_vout, "bz-gamma-red" );
644         p_vout->p_sys->f_gamma[1] = var_CreateGetFloat( p_vout, "bz-gamma-green" );
645         p_vout->p_sys->f_gamma[2] = var_CreateGetFloat( p_vout, "bz-gamma-blue" );
646         f_BlackCrush[0] = var_CreateGetInteger( p_vout, "bz-blackcrush-red" ) / 255.0;
647         f_BlackCrush[1] = var_CreateGetInteger( p_vout, "bz-blackcrush-green" ) / 255.0;
648         f_BlackCrush[2] = var_CreateGetInteger( p_vout, "bz-blackcrush-blue" ) / 255.0;
649         f_WhiteCrush[0] = var_CreateGetInteger( p_vout, "bz-whitecrush-red" ) / 255.0;
650         f_WhiteCrush[1] = var_CreateGetInteger( p_vout, "bz-whitecrush-green" ) / 255.0;
651         f_WhiteCrush[2] = var_CreateGetInteger( p_vout, "bz-whitecrush-blue" ) / 255.0;
652         f_BlackLevel[0] = var_CreateGetInteger( p_vout, "bz-blacklevel-red" ) / 255.0;
653         f_BlackLevel[1] = var_CreateGetInteger( p_vout, "bz-blacklevel-green" ) / 255.0;
654         f_BlackLevel[2] = var_CreateGetInteger( p_vout, "bz-blacklevel-blue" ) / 255.0;
655         f_WhiteLevel[0] = var_CreateGetInteger( p_vout, "bz-whitelevel-red" ) / 255.0;
656         f_WhiteLevel[1] = var_CreateGetInteger( p_vout, "bz-whitelevel-green" ) / 255.0;
657         f_WhiteLevel[2] = var_CreateGetInteger( p_vout, "bz-whitelevel-blue" ) / 255.0;
658         switch (p_vout->render.i_chroma)
659         {
660         // planar YVU
661             case VLC_FOURCC('Y','V','1','2'):
662             case VLC_FOURCC('Y','V','U','9'):
663         // packed UYV
664             case VLC_FOURCC('U','Y','V','Y'):    // packed by 2
665             case VLC_FOURCC('U','Y','N','V'):    // packed by 2
666             case VLC_FOURCC('Y','4','2','2'):    // packed by 2
667     //        case VLC_FOURCC('c','y','u','v'):    // packed by 2
668                 p_vout->p_sys->f_gamma[2] = var_CreateGetFloat( p_vout, "bz-gamma-green" );
669                 p_vout->p_sys->f_gamma[1] = var_CreateGetFloat( p_vout, "bz-gamma-blue" );
670                 f_BlackCrush[2] = var_CreateGetInteger( p_vout, "bz-blackcrush-green" ) / 255.0;
671                 f_BlackCrush[1] = var_CreateGetInteger( p_vout, "bz-blackcrush-blue" ) / 255.0;
672                 f_WhiteCrush[2] = var_CreateGetInteger( p_vout, "bz-whitecrush-green" ) / 255.0;
673                 f_WhiteCrush[1] = var_CreateGetInteger( p_vout, "bz-whitecrush-blue" ) / 255.0;
674                 f_BlackLevel[2] = var_CreateGetInteger( p_vout, "bz-blacklevel-green" ) / 255.0;
675                 f_BlackLevel[1] = var_CreateGetInteger( p_vout, "bz-blacklevel-blue" ) / 255.0;
676                 f_WhiteLevel[2] = var_CreateGetInteger( p_vout, "bz-whitelevel-green" ) / 255.0;
677                 f_WhiteLevel[1] = var_CreateGetInteger( p_vout, "bz-whitelevel-blue" ) / 255.0;
678         // planar YUV
679             case VLC_FOURCC('I','4','4','4'):
680             case VLC_FOURCC('I','4','2','2'):
681             case VLC_FOURCC('I','4','2','0'):
682             case VLC_FOURCC('I','4','1','1'):
683             case VLC_FOURCC('I','4','1','0'):
684             case VLC_FOURCC('I','Y','U','V'):
685             case VLC_FOURCC('Y','U','V','A'):
686         // packed YUV
687             case VLC_FOURCC('Y','U','Y','2'):    // packed by 2
688             case VLC_FOURCC('Y','U','N','V'):    // packed by 2
689                 for (i_index = 0; i_index < 256; i_index++)
690                     for (i_index2 = 0; i_index2 <= ACCURACY; i_index2++)
691                         for (i_plane = 0; i_plane < VOUT_MAX_PLANES; i_plane++)
692                         {
693                             float f_lut = CLIP_01(1.0 -
694                                      ((ACCURACY - (float)i_index2)
695                                      * Gamma_Correction(i_plane, (float)i_index / 255.0, f_BlackCrush, f_WhiteCrush, f_BlackLevel, f_WhiteLevel, p_vout->p_sys->f_gamma)
696                                      / (ACCURACY - 1)));
697                             p_vout->p_sys->LUT[i_plane][i_index2][i_index] = f_lut * i_index + (int)((1.0 - f_lut) * (float)constantYUV[i_plane]);
698                         }
699                 break;
700         // packed RGB
701             case VLC_FOURCC('R','G','B','2'):    // packed by 1
702             case VLC_FOURCC('R','V','1','5'):    // packed by 2
703             case VLC_FOURCC('R','V','1','6'):    // packed by 2
704             case VLC_FOURCC('R','V','2','4'):    // packed by 3
705             case VLC_FOURCC('R','V','3','2'):    // packed by 4
706             for (i_index = 0; i_index < 256; i_index++)
707                     for (i_index2 = 0; i_index2 <= ACCURACY; i_index2++)
708                         for (i_plane = 0; i_plane < VOUT_MAX_PLANES; i_plane++)
709                         {
710                             float f_lut = CLIP_01(1.0 -
711                                      ((ACCURACY - (float)i_index2)
712                                      * Gamma_Correction(i_plane, (float)i_index / 255.0, f_BlackCrush, f_WhiteCrush, f_BlackLevel, f_WhiteLevel, p_vout->p_sys->f_gamma)
713                                      / (ACCURACY - 1)));
714                             p_vout->p_sys->LUT[i_plane][i_index2][i_index] = f_lut * i_index;
715                         }
716                 break;
717             default:
718                 msg_Err( p_vout, "colorspace not supported by plug-in !!!");
719                 free( p_vout->p_sys );
720                 return VLC_ENOMEM;
721         }
722     }
723 #endif
724     if (p_vout->p_sys->i_offset_x)
725         p_vout->p_sys->i_offset_x = AdjustHeight(p_vout);
726     else
727         AdjustHeight(p_vout);
728 #endif
729
730     /* Try to open the real video output */
731     msg_Dbg( p_vout, "spawning the real video outputs" );
732
733     p_vout->p_sys->i_vout = 0;
734
735     /* FIXME: use bresenham instead of those ugly divisions */
736     for( i_row = 0; i_row < p_vout->p_sys->i_row; i_row++ )
737     {
738         for( i_col = 0; i_col < p_vout->p_sys->i_col; i_col++ )
739         {
740             video_format_t fmt;
741
742             memset( &fmt, 0, sizeof(video_format_t) );
743
744             if( i_col + 1 < p_vout->p_sys->i_col )
745             {
746                 i_width = ( p_vout->render.i_width
747                              / p_vout->p_sys->i_col ) & ~0x1;
748             }
749             else
750             {
751                 i_width = p_vout->render.i_width
752                            - ( ( p_vout->render.i_width
753                                   / p_vout->p_sys->i_col ) & ~0x1 ) * i_col;
754
755             }
756 #ifdef OVERLAP
757             i_width += p_vout->p_sys->i_halfLength;
758             if (p_vout->p_sys->i_col > 2 ) i_width += p_vout->p_sys->i_halfLength;
759             i_width -= i_width % 2;
760 #endif
761             if( i_row + 1 < p_vout->p_sys->i_row )
762             {
763                 i_height = ( p_vout->render.i_height
764                               / p_vout->p_sys->i_row ) & ~0x3;
765             }
766             else
767             {
768                 i_height = p_vout->render.i_height
769                             - ( ( p_vout->render.i_height
770                                    / p_vout->p_sys->i_row ) & ~0x3 ) * i_row;
771             }
772
773 #ifdef OVERLAP
774             if (p_vout->p_sys->i_row >= 2)
775             {
776                 p_vout->p_sys->i_halfHeight = (p_vout->p_sys->i_halfLength * p_vout->p_sys->bz_height) / 100;
777                 p_vout->p_sys->i_halfHeight -= (p_vout->p_sys->i_halfHeight % 2);
778                 i_height += p_vout->p_sys->i_halfHeight;
779                 if (p_vout->p_sys->i_row > 2) i_height += p_vout->p_sys->i_halfHeight;
780             }
781             i_height -= i_height % 2;
782 #endif
783             p_vout->p_sys->pp_vout[ p_vout->p_sys->i_vout ].i_width = i_width;
784             p_vout->p_sys->pp_vout[ p_vout->p_sys->i_vout ].i_height = i_height;
785
786             if( !p_vout->p_sys->pp_vout[ p_vout->p_sys->i_vout ].b_active )
787             {
788                 p_vout->p_sys->i_vout++;
789                 continue;
790             }
791
792             fmt.i_width = fmt.i_visible_width = p_vout->render.i_width;
793             fmt.i_height = fmt.i_visible_height = p_vout->render.i_height;
794             fmt.i_x_offset = fmt.i_y_offset = 0;
795             fmt.i_chroma = p_vout->render.i_chroma;
796             fmt.i_aspect = p_vout->render.i_aspect;
797             fmt.i_sar_num = p_vout->render.i_aspect * fmt.i_height / fmt.i_width;
798             fmt.i_sar_den = VOUT_ASPECT_FACTOR;
799             fmt.i_width = fmt.i_visible_width = i_width;
800             fmt.i_height = fmt.i_visible_height = i_height;
801             fmt.i_aspect = p_vout->render.i_aspect
802                               * p_vout->render.i_height / i_height
803                               * i_width / p_vout->render.i_width;
804 #ifdef OVERLAP
805             if (p_vout->p_sys->i_offset_x < 0)
806             {
807                 var_SetInteger(p_vout, "video-x", -p_vout->p_sys->i_offset_x);
808                 p_vout->p_sys->i_offset_x = 0;
809             }
810 #endif
811             p_vout->p_sys->pp_vout[ p_vout->p_sys->i_vout ].p_vout =
812                 vout_Create( p_vout, &fmt);
813
814             if( p_vout->p_sys->pp_vout[ p_vout->p_sys->i_vout ].p_vout == NULL )
815             {
816                 msg_Err( p_vout, "failed to get %ix%i vout threads",
817                                  p_vout->p_sys->i_col, p_vout->p_sys->i_row );
818                 RemoveAllVout( p_vout );
819                 return VLC_EGENERIC;
820             }
821             ADD_CALLBACKS(
822                 p_vout->p_sys->pp_vout[ p_vout->p_sys->i_vout ].p_vout,
823                 SendEvents );
824 #ifdef OVERLAP
825             p_vout->p_sys->pp_vout[ p_vout->p_sys->i_vout ].p_vout->i_alignment = 0;
826             if (i_col == 0) p_vout->p_sys->pp_vout[ p_vout->p_sys->i_vout ].p_vout->i_alignment |= VOUT_ALIGN_RIGHT;
827             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;
828             if (p_vout->p_sys->i_row > 1)
829             {
830                 if (i_row == 0) p_vout->p_sys->pp_vout[ p_vout->p_sys->i_vout ].p_vout->i_alignment |= VOUT_ALIGN_BOTTOM;
831                 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;
832             }
833     // i_n : number of active pp_vout
834             int i_index, i_n = p_vout->p_sys->i_vout;
835                 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;
836             var_SetInteger( p_vout, "align", p_vout->p_sys->pp_vout[ p_vout->p_sys->i_vout ].p_vout->i_alignment );
837             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);
838             var_SetInteger( p_vout, "video-y",i_video_y + ((i_n + 1) / p_vout->p_sys->i_col) * p_vout->i_window_height);
839 #endif
840             p_vout->p_sys->i_vout++;
841         }
842     }
843
844     ALLOCATE_DIRECTBUFFERS( VOUT_MAX_PICTURES );
845
846     ADD_PARENT_CALLBACKS( SendEventsToChild );
847
848     return VLC_SUCCESS;
849 }
850
851 /*****************************************************************************
852  * End: terminate Wall video thread output method
853  *****************************************************************************/
854 static void End( vout_thread_t *p_vout )
855 {
856     int i_index;
857
858 #ifdef OVERLAP
859     var_SetInteger( p_vout, "bz-length", p_vout->p_sys->bz_length);
860 #endif
861     /* Free the fake output buffers we allocated */
862     for( i_index = I_OUTPUTPICTURES ; i_index ; )
863     {
864         i_index--;
865         free( PP_OUTPUTPICTURE[ i_index ]->p_data_orig );
866     }
867 }
868
869 /*****************************************************************************
870  * Destroy: destroy Wall video thread output method
871  *****************************************************************************
872  * Terminate an output method created by WallCreateOutputMethod
873  *****************************************************************************/
874 static void Destroy( vlc_object_t *p_this )
875 {
876     vout_thread_t *p_vout = (vout_thread_t *)p_this;
877
878 #ifdef GLOBAL_OUTPUT
879     DEL_CALLBACKS( p_vout->p_sys->p_vout, SendEvents);
880     vlc_object_detach( p_vout->p_sys->p_vout );
881     vout_Destroy( p_vout->p_sys->p_vout );
882     DEL_PARENT_CALLBACKS( SendEventsToChild);
883 #endif
884
885     RemoveAllVout( p_vout );
886     DEL_PARENT_CALLBACKS( SendEventsToChild );
887
888     free( p_vout->p_sys->pp_vout );
889     free( p_vout->p_sys );
890
891 }
892
893 /*****************************************************************************
894  * RenderPlanarYUV: displays previously rendered output
895  *****************************************************************************
896  * This function send the currently rendered image to Wall image, waits
897  * until it is displayed and switch the two rendering buffers, preparing next
898  * frame.
899  *****************************************************************************/
900 static void RenderPlanarYUV( vout_thread_t *p_vout, picture_t *p_pic )
901 {
902     picture_t *p_outpic = NULL;
903     int i_col, i_row, i_vout, i_plane;
904     int pi_left_skip[VOUT_MAX_PLANES], pi_top_skip[VOUT_MAX_PLANES];
905 #ifdef OVERLAP
906     int LeftOffset, TopOffset;
907     int constantYUV[3] = {0,128,128};
908     int Denom;
909     int a_2;
910     int a_1;
911     int a_0;
912     int i_index, i_index2;
913 #endif
914
915
916     i_vout = 0;
917
918     for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ )
919     {
920         pi_top_skip[i_plane] = 0;
921     }
922
923     for( i_row = 0; i_row < p_vout->p_sys->i_row; i_row++ )
924     {
925         for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ )
926         {
927             pi_left_skip[i_plane] = 0;
928         }
929
930         for( i_col = 0; i_col < p_vout->p_sys->i_col; i_col++ )
931         {
932             if( !p_vout->p_sys->pp_vout[ i_vout ].b_active )
933             {
934                 for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ )
935                 {
936                     pi_left_skip[i_plane] +=
937                         p_vout->p_sys->pp_vout[ i_vout ].i_width
938                          * p_pic->p[i_plane].i_pitch / p_vout->output.i_width;
939                 }
940                 i_vout++;
941                 continue;
942             }
943
944             while( ( p_outpic =
945                 vout_CreatePicture( p_vout->p_sys->pp_vout[ i_vout ].p_vout,
946                                     0, 0, 0 )
947                    ) == NULL )
948             {
949                 if( p_vout->b_die || p_vout->b_error )
950                 {
951                     vout_DestroyPicture(
952                         p_vout->p_sys->pp_vout[ i_vout ].p_vout, p_outpic );
953                     return;
954                 }
955
956                 msleep( VOUT_OUTMEM_SLEEP );
957             }
958
959             vout_DatePicture( p_vout->p_sys->pp_vout[ i_vout ].p_vout,
960                               p_outpic, p_pic->date );
961             vout_LinkPicture( p_vout->p_sys->pp_vout[ i_vout ].p_vout,
962                               p_outpic );
963
964             for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ )
965             {
966                 uint8_t *p_in, *p_in_end, *p_out;
967                 int i_in_pitch = p_pic->p[i_plane].i_pitch;
968                 int i_out_pitch = p_outpic->p[i_plane].i_pitch;
969                 int i_copy_pitch = p_outpic->p[i_plane].i_visible_pitch;
970                 int i_lines = p_outpic->p[i_plane].i_visible_lines;
971 #ifdef OVERLAP
972                 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);
973                 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);
974                 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);
975                 if ((!p_vout->p_sys->pp_vout[p_vout->p_sys->i_col].b_active))
976                     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);
977 // i_n : previous inactive pp_vout
978                 int i_n=0;
979                 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++;
980                 if ((i_col > 1) && i_n)
981                     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);
982
983                 p_in = p_pic->p[i_plane].p_pixels
984                 /* Wall proprities */
985                 + pi_top_skip[i_plane] + pi_left_skip[i_plane];
986
987                 if ((p_vout->p_sys->i_row > 2) &&
988                     ((!i_row) || (i_row + 1 == p_vout->p_sys->i_row)))
989                         i_lines -= (2 * p_vout->p_sys->i_halfHeight) / (p_vout->p_sys->pp_vout[i_vout].i_width / i_copy_pitch);
990
991 // 1088 lines bug in a mpeg2 stream of 1080 lines
992                 if ((p_vout->p_sys->i_row - 1 == i_row) &&
993                     (p_pic->p[i_plane].i_lines == 1088))
994                         i_lines -= 8 / (p_vout->p_sys->pp_vout[i_vout].i_width / i_copy_pitch);
995
996                 p_in_end = p_in + i_lines * p_pic->p[i_plane].i_pitch;
997 #else
998                 p_in = p_pic->p[i_plane].p_pixels
999                         + pi_top_skip[i_plane] + pi_left_skip[i_plane];
1000
1001                 p_in_end = p_in + i_lines * p_pic->p[i_plane].i_pitch;
1002 #endif
1003                 p_out = p_outpic->p[i_plane].p_pixels;
1004 #ifdef OVERLAP
1005         if ((p_vout->p_sys->i_row > 2) && (!i_row))
1006             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));
1007
1008         int length;
1009         int i_col_mod;
1010         length = 2 * p_vout->p_sys->i_halfLength / (p_vout->p_sys->pp_vout[i_vout].i_width / i_copy_pitch);
1011
1012         if (p_vout->p_sys->b_has_changed)
1013         {
1014             Denom = F2(length);
1015             a_2 = p_vout->p_sys->a_2 * (ACCURACY / 100);
1016             a_1 = p_vout->p_sys->a_1 * length * (ACCURACY / 100);
1017             a_0 = p_vout->p_sys->a_0 * Denom * (ACCURACY / 100);
1018             for(i_col_mod = 0; i_col_mod < 2; i_col_mod++)
1019              for (i_index = 0; i_index < length; i_index++)
1020              {
1021                 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);
1022                 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;
1023              }
1024         }
1025 #endif
1026             while( p_in < p_in_end )
1027             {
1028 #ifndef OVERLAP
1029                 p_vout->p_libvlc->pf_memcpy( p_out , p_in, i_copy_pitch);
1030 #else
1031                 if (p_vout->p_sys->i_col > 2)
1032                 {
1033                     length /= 2;
1034                     if (i_col == 0)
1035                         p_vout->p_libvlc->pf_memcpy( p_out + length , p_in, i_copy_pitch - length);
1036                     else if (i_col + 1 == p_vout->p_sys->i_col)
1037                             p_vout->p_libvlc->pf_memcpy( p_out, p_in - length, i_copy_pitch - length);
1038                          else
1039                             p_vout->p_libvlc->pf_memcpy( p_out, p_in - length, i_copy_pitch);
1040
1041                     if ((i_col == 0))
1042                     // black bar
1043                     {
1044                         LeftOffset = 0;
1045                         p_out += LeftOffset;
1046                         memset(p_out, constantYUV[i_plane], length);
1047                         p_out -= LeftOffset;
1048                     }
1049                     else if ((i_col + 1 == p_vout->p_sys->i_col ))
1050                     // black bar
1051                         {
1052                             LeftOffset = i_copy_pitch - length;
1053                             p_out += LeftOffset;
1054                             memset(p_out, constantYUV[i_plane], length);
1055                             p_out -= LeftOffset;
1056                         }
1057                     length *= 2;
1058                 }
1059                 else
1060                     p_vout->p_libvlc->pf_memcpy( p_out , p_in, i_copy_pitch);
1061
1062               if (p_vout->p_sys->b_attenuate)
1063             {
1064 // vertical blend
1065 // first blended zone
1066                 if (i_col)
1067                 {
1068                     LeftOffset = 0;
1069                     p_out += LeftOffset;
1070                     for (i_index = 0; i_index < length; i_index++)
1071                     {
1072 #ifndef GAMMA
1073                         *(p_out + i_index) = (p_vout->p_sys->lambda[1][i_plane][i_index] *
1074                                  (*(p_out + i_index))) / ACCURACY +
1075                                      p_vout->p_sys->cstYUV[1][i_plane][i_index];
1076 #else
1077                             *(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)];
1078 #endif
1079                     }
1080                     p_out -= LeftOffset;
1081                 }
1082 // second blended zone
1083                 if (i_col + 1 < p_vout->p_sys->i_col)
1084                 {
1085                     LeftOffset = i_copy_pitch - length;
1086                     p_out +=  LeftOffset;
1087                     for (i_index = 0; i_index < length; i_index++)
1088                     {
1089 #ifndef GAMMA
1090                             *(p_out + i_index) = (p_vout->p_sys->lambda[0][i_plane][i_index] *
1091                                      (*(p_out + i_index))) / ACCURACY +
1092                                      p_vout->p_sys->cstYUV[0][i_plane][i_index];
1093 #else
1094
1095                         *(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)];
1096 #endif
1097                     }
1098                     p_out -= LeftOffset;
1099                 }
1100 // end blended zone
1101             }
1102 #endif
1103                 p_in += i_in_pitch;
1104                 p_out += i_out_pitch;
1105             }
1106 #ifdef OVERLAP
1107 // horizontal blend
1108         if (!p_vout->p_sys->b_attenuate)
1109         {
1110             if ((i_row == 0) && (p_vout->p_sys->i_row > 2))
1111             // black bar
1112             {
1113                     int height = 2 * p_vout->p_sys->i_halfHeight / (p_vout->p_sys->pp_vout[i_vout].i_width / i_copy_pitch);
1114                     TopOffset = i_lines + (2 * p_vout->p_sys->i_halfHeight) / (p_vout->p_sys->pp_vout[i_vout].i_width / i_copy_pitch);
1115                     p_out -= TopOffset * p_outpic->p[i_plane].i_pitch;
1116                     for (i_index = 0; i_index < height; i_index++)
1117                         for (i_index2 = 0; i_index2 < i_copy_pitch; i_index2++)
1118                             *(p_out + (i_index * p_outpic->p[i_plane].i_pitch) + i_index2) = constantYUV[i_plane];
1119                     p_out += TopOffset * p_outpic->p[i_plane].i_pitch;
1120             }
1121             else if ((i_row + 1 == p_vout->p_sys->i_row) && (p_vout->p_sys->i_row > 2))
1122             // black bar
1123                 {
1124                         int height = 2 * p_vout->p_sys->i_halfHeight / (p_vout->p_sys->pp_vout[i_vout].i_width / i_copy_pitch);
1125                         TopOffset = height - (2 * p_vout->p_sys->i_halfHeight) / (p_vout->p_sys->pp_vout[i_vout].i_width / i_copy_pitch);
1126                         p_out -= TopOffset * p_outpic->p[i_plane].i_pitch;
1127                         for (i_index = 0; i_index < height; i_index++)
1128                             for (i_index2 = 0; i_index2 < i_copy_pitch; i_index2++)
1129                                 *(p_out + (i_index * p_outpic->p[i_plane].i_pitch) + i_index2) = constantYUV[i_plane];
1130                         p_out += TopOffset * p_outpic->p[i_plane].i_pitch;
1131                 }
1132         }
1133         else
1134         {
1135             if (p_vout->p_sys->i_row >= 2)
1136             {
1137                 length = 2 * p_vout->p_sys->i_halfHeight / (p_vout->p_sys->pp_vout[i_vout].i_width / i_copy_pitch);
1138                 if (p_vout->p_sys->b_has_changed)
1139                 {
1140                     Denom = F2(length);
1141                     a_2 = p_vout->p_sys->a_2 * (ACCURACY / 100);
1142                     a_1 = p_vout->p_sys->a_1 * length * (ACCURACY / 100);
1143                     a_0 = p_vout->p_sys->a_0 * Denom * (ACCURACY / 100);
1144                    for(i_col_mod = 0; i_col_mod < 2; i_col_mod++)
1145                     for (i_index = 0; i_index < length; i_index++)
1146                     {
1147                         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);
1148                         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;
1149                     }
1150                 }
1151 // first blended zone
1152
1153             if (i_row)
1154             {
1155                 TopOffset = i_lines;
1156                 p_out -= TopOffset * p_outpic->p[i_plane].i_pitch;
1157                 for (i_index = 0; i_index < length; i_index++)
1158                     for (i_index2 = 0; i_index2 < i_copy_pitch; i_index2++)
1159 #ifndef GAMMA
1160                         *(p_out + (i_index * p_outpic->p[i_plane].i_pitch) + i_index2) = (p_vout->p_sys->lambda2[1][i_plane][i_index] *
1161                                      (*(p_out + (i_index * p_outpic->p[i_plane].i_pitch) + i_index2))) / ACCURACY +
1162                                      p_vout->p_sys->cstYUV2[1][i_plane][i_index];
1163 #else
1164
1165                         *(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)];
1166 #endif
1167                 p_out += TopOffset * p_outpic->p[i_plane].i_pitch;
1168             }
1169             else if (p_vout->p_sys->i_row > 2)
1170             // black bar
1171             {
1172                 TopOffset = i_lines + (2 * p_vout->p_sys->i_halfHeight) / (p_vout->p_sys->pp_vout[i_vout].i_width / i_copy_pitch);
1173                 p_out -= TopOffset * p_outpic->p[i_plane].i_pitch;
1174                 for (i_index = 0; i_index < length; i_index++)
1175                     for (i_index2 = 0; i_index2 < i_copy_pitch; i_index2++)
1176                         *(p_out + (i_index * p_outpic->p[i_plane].i_pitch) + i_index2) = constantYUV[i_plane];
1177                 p_out += TopOffset * p_outpic->p[i_plane].i_pitch;
1178             }
1179
1180 // second blended zone
1181
1182             if (i_row + 1 < p_vout->p_sys->i_row)
1183             {
1184                 TopOffset = length;
1185                 p_out -= TopOffset * p_outpic->p[i_plane].i_pitch;
1186                 for (i_index = 0; i_index < length; i_index++)
1187                     for (i_index2 = 0; i_index2 < i_copy_pitch; i_index2++)
1188 #ifndef GAMMA
1189                         *(p_out + (i_index * p_outpic->p[i_plane].i_pitch) + i_index2) = (p_vout->p_sys->lambda2[0][i_plane][i_index] *
1190                                      (*(p_out + (i_index * p_outpic->p[i_plane].i_pitch) + i_index2))) / ACCURACY +
1191                                      p_vout->p_sys->cstYUV2[0][i_plane][i_index];
1192 #else
1193
1194                         *(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)];
1195
1196 #endif
1197                 p_out += TopOffset * p_outpic->p[i_plane].i_pitch;
1198             }
1199             else if (p_vout->p_sys->i_row > 2)
1200             // black bar
1201             {
1202                 TopOffset = length - (2 * p_vout->p_sys->i_halfHeight) / (p_vout->p_sys->pp_vout[i_vout].i_width / i_copy_pitch);
1203                 p_out -= TopOffset * p_outpic->p[i_plane].i_pitch;
1204                 for (i_index = 0; i_index < length; i_index++)
1205                     for (i_index2 = 0; i_index2 < i_copy_pitch; i_index2++)
1206                         *(p_out + (i_index * p_outpic->p[i_plane].i_pitch) + i_index2) = constantYUV[i_plane];
1207                 p_out += TopOffset * p_outpic->p[i_plane].i_pitch;
1208             }
1209 // end blended zone
1210             }
1211         }
1212 #endif
1213 // bug for wall filter : fix by CC
1214 //            pi_left_skip[i_plane] += i_out_pitch;
1215             pi_left_skip[i_plane] += i_copy_pitch;
1216             }
1217
1218             vout_UnlinkPicture( p_vout->p_sys->pp_vout[ i_vout ].p_vout,
1219                                 p_outpic );
1220             vout_DisplayPicture( p_vout->p_sys->pp_vout[ i_vout ].p_vout,
1221                                  p_outpic );
1222             i_vout++;
1223         }
1224
1225         for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ )
1226                 {
1227                     pi_top_skip[i_plane] += p_vout->p_sys->pp_vout[ i_vout ].i_height
1228                                              * p_pic->p[i_plane].i_lines
1229                                              / p_vout->output.i_height
1230                                              * p_pic->p[i_plane].i_pitch;
1231                 }
1232
1233     }
1234 #ifdef OVERLAP
1235     if (p_vout->p_sys->b_has_changed) p_vout->p_sys->b_has_changed = VLC_FALSE;
1236 #endif
1237 }
1238
1239
1240 /*****************************************************************************
1241  * RenderPackedRGB: displays previously rendered output
1242  *****************************************************************************
1243  * This function send the currently rendered image to Wall image, waits
1244  * until it is displayed and switch the two rendering buffers, preparing next
1245  * frame.
1246  *****************************************************************************/
1247 static void RenderPackedRGB( vout_thread_t *p_vout, picture_t *p_pic )
1248 {
1249     picture_t *p_outpic = NULL;
1250     int i_col, i_row, i_vout, i_plane;
1251     int pi_left_skip[VOUT_MAX_PLANES], pi_top_skip[VOUT_MAX_PLANES];
1252 #ifdef OVERLAP
1253     int LeftOffset, TopOffset;
1254     int Denom;
1255     int a_2;
1256     int a_1;
1257     int a_0;
1258     int i_index, i_index2;
1259 #endif
1260
1261     i_vout = 0;
1262
1263     for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ )
1264     {
1265         pi_top_skip[i_plane] = 0;
1266     }
1267
1268     for( i_row = 0; i_row < p_vout->p_sys->i_row; i_row++ )
1269     {
1270         for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ )
1271         {
1272             pi_left_skip[i_plane] = 0;
1273         }
1274
1275         for( i_col = 0; i_col < p_vout->p_sys->i_col; i_col++ )
1276         {
1277             if( !p_vout->p_sys->pp_vout[ i_vout ].b_active )
1278             {
1279                 for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ )
1280                 {
1281                     pi_left_skip[i_plane] +=
1282                         p_vout->p_sys->pp_vout[ i_vout ].i_width * p_pic->p->i_pixel_pitch;
1283                 }
1284                 i_vout++;
1285                 continue;
1286             }
1287
1288             while( ( p_outpic =
1289                 vout_CreatePicture( p_vout->p_sys->pp_vout[ i_vout ].p_vout,
1290                                     0, 0, 0 )
1291                    ) == NULL )
1292             {
1293                 if( p_vout->b_die || p_vout->b_error )
1294                 {
1295                     vout_DestroyPicture(
1296                         p_vout->p_sys->pp_vout[ i_vout ].p_vout, p_outpic );
1297                     return;
1298                 }
1299
1300                 msleep( VOUT_OUTMEM_SLEEP );
1301             }
1302
1303             vout_DatePicture( p_vout->p_sys->pp_vout[ i_vout ].p_vout,
1304                               p_outpic, p_pic->date );
1305             vout_LinkPicture( p_vout->p_sys->pp_vout[ i_vout ].p_vout,
1306                               p_outpic );
1307
1308             for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ )
1309             {
1310                 uint8_t *p_in, *p_in_end, *p_out;
1311                 int i_in_pitch = p_pic->p[i_plane].i_pitch;
1312                 int i_out_pitch = p_outpic->p[i_plane].i_pitch;
1313                 int i_copy_pitch = p_outpic->p[i_plane].i_visible_pitch;
1314
1315 #ifdef OVERLAP
1316                 if (i_col) pi_left_skip[i_plane] -= (2 * p_vout->p_sys->i_halfLength) * p_pic->p->i_pixel_pitch;
1317                 if ((i_row) && (!i_col)) pi_top_skip[i_plane] -= (2 * p_vout->p_sys->i_halfHeight * p_pic->p[i_plane].i_pitch);
1318                 if ((!p_vout->p_sys->pp_vout[p_vout->p_sys->i_col].b_active))
1319                     pi_top_skip[i_plane] -= (2 * p_vout->p_sys->i_halfHeight * i_row * p_pic->p[i_plane].i_pitch);
1320 // i_n : previous inactive pp_vout
1321                 int i_n=0;
1322                 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++;
1323                 if ((i_col > 1) && i_n)
1324                     pi_left_skip[i_plane] -= i_n*(2 * p_vout->p_sys->i_halfLength ) * p_pic->p->i_pixel_pitch;
1325
1326                 p_in = p_pic->p[i_plane].p_pixels
1327                 /* Wall proprities */
1328                 + pi_top_skip[i_plane] + pi_left_skip[i_plane];
1329
1330                 int i_lines = p_outpic->p[i_plane].i_visible_lines;
1331 // 1088 lines bug in a mpeg2 stream of 1080 lines
1332                 if ((p_vout->p_sys->i_row - 1 == i_row) &&
1333                     (p_pic->p[i_plane].i_lines == 1088))
1334                         i_lines -= 8;
1335
1336                 p_in_end = p_in + i_lines * p_pic->p[i_plane].i_pitch;
1337 #else
1338                 p_in = p_pic->p[i_plane].p_pixels
1339                         + pi_top_skip[i_plane] + pi_left_skip[i_plane];
1340
1341                 p_in_end = p_in + p_outpic->p[i_plane].i_visible_lines
1342                                         * p_pic->p[i_plane].i_pitch;
1343 #endif //OVERLAP
1344
1345                 p_out = p_outpic->p[i_plane].p_pixels;
1346
1347
1348 #ifdef OVERLAP
1349         if ((p_vout->p_sys->i_row > 2) && (!i_row))
1350             p_out += (p_outpic->p[i_plane].i_pitch * (2 * p_vout->p_sys->i_halfHeight) * p_pic->p->i_pixel_pitch);
1351
1352         int length;
1353         length = 2 * p_vout->p_sys->i_halfLength * p_pic->p->i_pixel_pitch;
1354
1355         if (p_vout->p_sys->b_has_changed)
1356         {
1357             int i_plane_;
1358             int i_col_mod;
1359             Denom = F2(length / p_pic->p->i_pixel_pitch);
1360             a_2 = p_vout->p_sys->a_2 * (ACCURACY / 100);
1361             a_1 = p_vout->p_sys->a_1 * 2 * p_vout->p_sys->i_halfLength * (ACCURACY / 100);
1362             a_0 = p_vout->p_sys->a_0 * Denom * (ACCURACY / 100);
1363             for(i_col_mod = 0; i_col_mod < 2; i_col_mod++)
1364                 for (i_index = 0; i_index < length / p_pic->p->i_pixel_pitch; i_index++)
1365                     for (i_plane_ =  0; i_plane_ < p_pic->p->i_pixel_pitch; i_plane_++)
1366                         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);
1367         }
1368 #endif
1369             while( p_in < p_in_end )
1370             {
1371 #ifndef OVERLAP
1372                 p_vout->p_libvlc->pf_memcpy( p_out, p_in, i_copy_pitch);
1373 #else
1374                 if (p_vout->p_sys->i_col > 2)
1375                 {
1376                     // vertical blend
1377                     length /= 2;
1378                     if (i_col == 0)
1379                         p_vout->p_libvlc->pf_memcpy( p_out + length, p_in, i_copy_pitch - length);
1380                     else if (i_col + 1 == p_vout->p_sys->i_col)
1381                             p_vout->p_libvlc->pf_memcpy( p_out, p_in - length, i_copy_pitch - length);
1382                          else
1383                             p_vout->p_libvlc->pf_memcpy( p_out, p_in - length, i_copy_pitch);
1384
1385                     if ((i_col == 0))
1386                     // black bar
1387                     {
1388                         LeftOffset = 0;
1389                         p_out += LeftOffset;
1390                         p_in += LeftOffset;
1391                         for (i_index = 0; i_index < length; i_index++)
1392                                 *(p_out + i_index) = 0;
1393                         p_out -= LeftOffset;
1394                         p_in -= LeftOffset;
1395                     }
1396                     else if ((i_col + 1 == p_vout->p_sys->i_col ))
1397                     // black bar
1398                         {
1399                             LeftOffset = i_copy_pitch - length;
1400                             p_out += LeftOffset;
1401                             p_in += LeftOffset;
1402                             for (i_index = 0; i_index < length; i_index++)
1403                                     *(p_out + i_index) = 0;
1404                             p_out -= LeftOffset;
1405                             p_in -= LeftOffset;
1406                         }
1407                     length *= 2;
1408                 }
1409                 else
1410                     p_vout->p_libvlc->pf_memcpy( p_out, p_in, i_copy_pitch);
1411
1412 // vertical blend
1413 // first blended zone
1414             if (i_col)
1415             {
1416                 LeftOffset = 0;
1417                 p_out += LeftOffset;
1418                 for (i_index = 0; i_index < length; i_index++)
1419 #ifndef GAMMA
1420                     *(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] *
1421                                  (*(p_out + i_index))) / ACCURACY;
1422 #else
1423                     *(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)];
1424 #endif
1425                 p_out -= LeftOffset;
1426             }
1427 // second blended zone
1428             if (i_col + 1 < p_vout->p_sys->i_col)
1429             {
1430                 LeftOffset = i_copy_pitch - length;
1431                 p_out +=  LeftOffset;
1432                 for (i_index = 0; i_index < length; i_index++)
1433 #ifndef GAMMA
1434                     *(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] *
1435                                  (*(p_out + i_index))) / ACCURACY;
1436 #else
1437                     *(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)];
1438 #endif
1439                 p_out -= LeftOffset;
1440             }
1441 // end blended zone
1442 #endif //OVERLAP
1443                 p_in += i_in_pitch;
1444                 p_out += i_out_pitch;
1445             }
1446 #ifdef OVERLAP
1447 // horizontal blend
1448         if (!p_vout->p_sys->b_attenuate)
1449         {
1450             if ((i_row == 0) && (p_vout->p_sys->i_row > 2))
1451             // black bar
1452             {
1453                     TopOffset = i_lines + (2 * p_vout->p_sys->i_halfHeight);
1454                     p_out -= TopOffset * p_outpic->p[i_plane].i_pitch;
1455                     for (i_index = 0; i_index < length; i_index++)
1456                         for (i_index2 = 0; i_index2 < i_copy_pitch; i_index2++)
1457                             *(p_out + (i_index * p_outpic->p[i_plane].i_pitch) + i_index2) = 0;
1458                     p_out += TopOffset * p_outpic->p[i_plane].i_pitch;
1459             }
1460             else if ((i_row + 1 == p_vout->p_sys->i_row) && (p_vout->p_sys->i_row > 2))
1461             // black bar
1462                 {
1463                     TopOffset = length - (2 * p_vout->p_sys->i_halfHeight);
1464                     p_out -= TopOffset * p_outpic->p[i_plane].i_pitch;
1465                     for (i_index = 0; i_index < length; i_index++)
1466                         for (i_index2 = 0; i_index2 < i_copy_pitch; i_index2++)
1467                             *(p_out + (i_index * p_outpic->p[i_plane].i_pitch) + i_index2) = 0;
1468                     p_out += TopOffset * p_outpic->p[i_plane].i_pitch;
1469                 }
1470         }
1471         else
1472         {
1473             if (p_vout->p_sys->i_row >= 2)
1474             {
1475                 length = 2 * p_vout->p_sys->i_halfHeight;
1476                 if (p_vout->p_sys->b_has_changed)
1477                 {
1478                     int i_plane_;
1479                     int i_row_mod;
1480                     Denom = F2(length);
1481                     a_2 = p_vout->p_sys->a_2 * (ACCURACY / 100);
1482                     a_1 = p_vout->p_sys->a_1 * length * (ACCURACY / 100);
1483                     a_0 = p_vout->p_sys->a_0 * Denom * (ACCURACY / 100);
1484                     for(i_row_mod = 0; i_row_mod < 2; i_row_mod++)
1485                       for (i_index = 0; i_index < length; i_index++)
1486                         for (i_plane_ =  0; i_plane_ < p_pic->p->i_pixel_pitch; i_plane_++)
1487                             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);
1488                 }
1489 // first blended zone
1490
1491             if (i_row)
1492             {
1493                 TopOffset = i_lines;
1494                 p_out -= TopOffset * p_outpic->p[i_plane].i_pitch;
1495                 for (i_index = 0; i_index < length; i_index++)
1496                     for (i_index2 = 0; i_index2 < i_copy_pitch; i_index2++)
1497 #ifndef GAMMA
1498                     *(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] *
1499                                  (*(p_out + (i_index * p_outpic->p[i_plane].i_pitch) + i_index2))) / ACCURACY;
1500 #else
1501                     *(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)];
1502 #endif
1503                 p_out += TopOffset * p_outpic->p[i_plane].i_pitch;
1504             }
1505             else if (p_vout->p_sys->i_row > 2)
1506             // black bar
1507             {
1508                 TopOffset = i_lines + (2 * p_vout->p_sys->i_halfHeight);
1509                 p_out -= TopOffset * p_outpic->p[i_plane].i_pitch;
1510                 for (i_index = 0; i_index < length; i_index++)
1511                     for (i_index2 = 0; i_index2 < i_copy_pitch; i_index2++)
1512                         *(p_out + (i_index * p_outpic->p[i_plane].i_pitch) + i_index2) = 0;
1513                 p_out += TopOffset * p_outpic->p[i_plane].i_pitch;
1514             }
1515
1516 // second blended zone
1517
1518             if (i_row + 1 < p_vout->p_sys->i_row)
1519             {
1520                 TopOffset = length;
1521                 p_out -= TopOffset * p_outpic->p[i_plane].i_pitch;
1522                 for (i_index = 0; i_index < length; i_index++)
1523                     for (i_index2 = 0; i_index2 < i_copy_pitch; i_index2++)
1524 #ifndef GAMMA
1525                     *(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] *
1526                                  (*(p_out + (i_index * p_outpic->p[i_plane].i_pitch) + i_index2))) / ACCURACY;
1527 #else
1528                     *(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)];
1529
1530 #endif
1531                 p_out += TopOffset * p_outpic->p[i_plane].i_pitch;
1532             }
1533             else if (p_vout->p_sys->i_row > 2)
1534             // black bar
1535             {
1536                 TopOffset = length - (2 * p_vout->p_sys->i_halfHeight);
1537                 p_out -= TopOffset * p_outpic->p[i_plane].i_pitch;
1538                 for (i_index = 0; i_index < length; i_index++)
1539                     for (i_index2 = 0; i_index2 < i_copy_pitch; i_index2++)
1540                         *(p_out + (i_index * p_outpic->p[i_plane].i_pitch) + i_index2) = 0;
1541                 p_out += TopOffset * p_outpic->p[i_plane].i_pitch;
1542             }
1543 // end blended zone
1544             }
1545         }
1546 #endif
1547 // bug for wall filter : fix by CC
1548 //            pi_left_skip[i_plane] += i_out_pitch;
1549             pi_left_skip[i_plane] += i_copy_pitch;
1550             }
1551
1552             vout_UnlinkPicture( p_vout->p_sys->pp_vout[ i_vout ].p_vout,
1553                                 p_outpic );
1554             vout_DisplayPicture( p_vout->p_sys->pp_vout[ i_vout ].p_vout,
1555                                  p_outpic );
1556             i_vout++;
1557         }
1558
1559         for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ )
1560         {
1561             pi_top_skip[i_plane] += p_vout->p_sys->pp_vout[ i_vout ].i_height
1562                                      * p_pic->p[i_plane].i_lines
1563                                      / p_vout->output.i_height
1564                                      * p_pic->p[i_plane].i_pitch;
1565         }
1566     }
1567 #ifdef OVERLAP
1568     if (p_vout->p_sys->b_has_changed) p_vout->p_sys->b_has_changed = VLC_FALSE;
1569 #endif
1570 }
1571
1572
1573 #ifdef PACKED_YUV
1574 // WARNING : NO DEBUGGED
1575 /*****************************************************************************
1576  * RenderPackedYUV: displays previously rendered output
1577  *****************************************************************************
1578  * This function send the currently rendered image to Wall image, waits
1579  * until it is displayed and switch the two rendering buffers, preparing next
1580  * frame.
1581  *****************************************************************************/
1582 static void RenderPackedYUV( vout_thread_t *p_vout, picture_t *p_pic )
1583 {
1584     picture_t *p_outpic = NULL;
1585     int i_col, i_row, i_vout, i_plane;
1586     int pi_left_skip[VOUT_MAX_PLANES], pi_top_skip[VOUT_MAX_PLANES];
1587 #ifdef OVERLAP
1588     int LeftOffset, TopOffset;
1589     int constantYUV[3] = {0,128,128};
1590     int Denom;
1591     int a_2;
1592     int a_1;
1593     int a_0;
1594     int i_index, i_index2;
1595 #endif
1596
1597
1598     i_vout = 0;
1599
1600     for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ )
1601     {
1602         pi_top_skip[i_plane] = 0;
1603     }
1604
1605     for( i_row = 0; i_row < p_vout->p_sys->i_row; i_row++ )
1606     {
1607         for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ )
1608         {
1609             pi_left_skip[i_plane] = 0;
1610         }
1611
1612         for( i_col = 0; i_col < p_vout->p_sys->i_col; i_col++ )
1613         {
1614             if( !p_vout->p_sys->pp_vout[ i_vout ].b_active )
1615             {
1616                 for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ )
1617                 {
1618                     pi_left_skip[i_plane] +=
1619                         p_vout->p_sys->pp_vout[ i_vout ].i_width
1620                          * p_pic->p[i_plane].i_pitch / p_vout->output.i_width;
1621                 }
1622                 i_vout++;
1623                 continue;
1624             }
1625
1626             while( ( p_outpic =
1627                 vout_CreatePicture( p_vout->p_sys->pp_vout[ i_vout ].p_vout,
1628                                     0, 0, 0 )
1629                    ) == NULL )
1630             {
1631                 if( p_vout->b_die || p_vout->b_error )
1632                 {
1633                     vout_DestroyPicture(
1634                         p_vout->p_sys->pp_vout[ i_vout ].p_vout, p_outpic );
1635                     return;
1636                 }
1637
1638                 msleep( VOUT_OUTMEM_SLEEP );
1639             }
1640
1641             vout_DatePicture( p_vout->p_sys->pp_vout[ i_vout ].p_vout,
1642                               p_outpic, p_pic->date );
1643             vout_LinkPicture( p_vout->p_sys->pp_vout[ i_vout ].p_vout,
1644                               p_outpic );
1645
1646             for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ )
1647             {
1648                 uint8_t *p_in, *p_in_end, *p_out;
1649                 int i_in_pitch = p_pic->p[i_plane].i_pitch;
1650                 int i_out_pitch = p_outpic->p[i_plane].i_pitch;
1651                 int i_copy_pitch = p_outpic->p[i_plane].i_visible_pitch;
1652
1653 #ifdef OVERLAP
1654                 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);
1655                 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);
1656                 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);
1657                 if ((!p_vout->p_sys->pp_vout[p_vout->p_sys->i_col].b_active))
1658                     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);
1659 // i_n : previous inactive pp_vout
1660                 int i_n=0;
1661                 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++;
1662                 if ((i_col > 1) && i_n)
1663                     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);
1664
1665                 p_in = p_pic->p[i_plane].p_pixels
1666                 /* Wall proprities */
1667                 + pi_top_skip[i_plane] + pi_left_skip[i_plane];
1668
1669                 int i_lines = p_outpic->p[i_plane].i_visible_lines;
1670 // 1088 lines bug in a mpeg2 stream of 1080 lines
1671                 if ((p_vout->p_sys->i_row - 1 == i_row) &&
1672                     (p_pic->p[i_plane].i_lines == 1088))
1673                         i_lines -= 8;
1674
1675                 p_in_end = p_in + i_lines * p_pic->p[i_plane].i_pitch;
1676 #else
1677                 p_in = p_pic->p[i_plane].p_pixels
1678                         + pi_top_skip[i_plane] + pi_left_skip[i_plane];
1679
1680                 p_in_end = p_in + p_outpic->p[i_plane].i_visible_lines
1681                                         * p_pic->p[i_plane].i_pitch;
1682 #endif
1683                 p_out = p_outpic->p[i_plane].p_pixels;
1684 #ifdef OVERLAP
1685         int length;
1686         length = 2 * p_vout->p_sys->i_halfLength * p_pic->p->i_pixel_pitch;
1687         LeftOffset = (i_col ? 0 : i_copy_pitch - length);
1688         if (p_vout->p_sys->b_has_changed)
1689         {
1690 #ifdef GAMMA
1691             int i_plane_;
1692             for (i_index = 0; i_index < length / p_pic->p->i_pixel_pitch; i_index++)
1693                 for (i_plane_ =  0; i_plane_ < p_pic->p->i_pixel_pitch; i_plane_++)
1694                     for (i_index2 = 0; i_index2 < 256; i_index2++)
1695                             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_]));
1696 #endif
1697             switch (p_vout->output.i_chroma)
1698                 {
1699                     case VLC_FOURCC('Y','U','Y','2'):    // packed by 2
1700                     case VLC_FOURCC('Y','U','N','V'):    // packed by 2
1701                         Denom = F2(length / p_pic->p->i_pixel_pitch);
1702                         a_2 = p_vout->p_sys->a_2 * (ACCURACY / 100);
1703                         a_1 = p_vout->p_sys->a_1 * 2 * p_vout->p_sys->i_halfLength * (ACCURACY / 100);
1704                         a_0 = p_vout->p_sys->a_0 * Denom * (ACCURACY / 100);
1705                         for (i_index = 0; i_index < length / p_pic->p->i_pixel_pitch; i_index+=p_pic->p->i_pixel_pitch)
1706                         // for each macropixel
1707                         {
1708                                 // first image pixel
1709                                 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);
1710                                 p_vout->p_sys->cstYUV[i_col][0][i_index] = ((ACCURACY - p_vout->p_sys->lambda[i_col][0][i_index]) * constantYUV[0]) / ACCURACY;
1711                                 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);
1712                                 p_vout->p_sys->cstYUV[i_col][1][i_index] = ((ACCURACY - p_vout->p_sys->lambda[i_col][1][i_index]) * constantYUV[1]) / ACCURACY;
1713                                 // second image pixel
1714                                 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);
1715                                 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;
1716                                 p_vout->p_sys->lambda[i_col][1][i_index + 1] = p_vout->p_sys->lambda[i_col][1][i_index];
1717                                 p_vout->p_sys->cstYUV[i_col][1][i_index + 1] = p_vout->p_sys->cstYUV[i_col][1][i_index];
1718                         }
1719                         break;
1720                     case VLC_FOURCC('U','Y','V','Y'):    // packed by 2
1721                     case VLC_FOURCC('U','Y','N','V'):    // packed by 2
1722                     case VLC_FOURCC('Y','4','2','2'):    // packed by 2
1723                         Denom = F2(length / p_pic->p->i_pixel_pitch);
1724                         a_2 = p_vout->p_sys->a_2 * (ACCURACY / 100);
1725                         a_1 = p_vout->p_sys->a_1 * 2 * p_vout->p_sys->i_halfLength * (ACCURACY / 100);
1726                         a_0 = p_vout->p_sys->a_0 * Denom * (ACCURACY / 100);
1727                         for (i_index = 0; i_index < length / p_pic->p->i_pixel_pitch; i_index+=p_pic->p->i_pixel_pitch)
1728                         // for each macropixel
1729                         {
1730                                 // first image pixel
1731                                 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);
1732                                 p_vout->p_sys->cstYUV[i_col][0][i_index] = ((ACCURACY - p_vout->p_sys->lambda[i_col][0][i_index]) * constantYUV[1]) / ACCURACY;
1733                                 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);
1734                                 p_vout->p_sys->cstYUV[i_col][1][i_index] = ((ACCURACY - p_vout->p_sys->lambda[i_col][1][i_index]) * constantYUV[0]) / ACCURACY;
1735                                 // second image pixel
1736                                 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);
1737                                 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;
1738                                 p_vout->p_sys->lambda[i_col][1][i_index + 1] = p_vout->p_sys->lambda[i_col][1][i_index];
1739                                 p_vout->p_sys->cstYUV[i_col][1][i_index + 1] = p_vout->p_sys->cstYUV[i_col][1][i_index];
1740                         }
1741                         break;
1742                     default :
1743                         break;
1744                 }
1745         }
1746 #endif
1747             while( p_in < p_in_end )
1748             {
1749 #ifndef OVERLAP
1750                 p_vout->p_libvlc->pf_memcpy( p_out, p_in, i_copy_pitch);
1751 #else
1752                 p_vout->p_libvlc->pf_memcpy( p_out + i_col * length, p_in + i_col * length, i_copy_pitch - length);
1753                 p_out += LeftOffset;
1754                 p_in += LeftOffset;
1755 #ifndef GAMMA
1756                 for (i_index = 0; i_index < length; i_index++)
1757                     *(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] *
1758                              (*(p_in + i_index))) / ACCURACY +
1759                              p_vout->p_sys->cstYUV[i_col][i_index % p_pic->p->i_pixel_pitch][i_index / p_pic->p->i_pixel_pitch];
1760 #else
1761                 for (i_index = 0; i_index < length; i_index++)
1762                     *(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] *
1763                              (*(p_in + i_index))) / ACCURACY +
1764                              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];
1765 #endif
1766                 p_out -= LeftOffset;
1767                 p_in -= LeftOffset;
1768 #endif
1769                 p_in += i_in_pitch;
1770                 p_out += i_out_pitch;
1771             }
1772 #ifdef OVERLAP
1773             if (p_vout->p_sys->i_row == 2)
1774             {
1775                         length = 2 * p_vout->p_sys->i_halfHeight * p_pic->p->i_pixel_pitch;
1776                         TopOffset = (i_row ? i_lines : length / p_pic->p->i_pixel_pitch);
1777                         if (p_vout->p_sys->b_has_changed)
1778                         {
1779 #ifdef GAMMA
1780                                 int i_plane_;
1781                                 for (i_index = 0; i_index < length / p_pic->p->i_pixel_pitch; i_index++)
1782                                     for (i_plane_ =  0; i_plane_ < p_pic->p->i_pixel_pitch; i_plane_++)
1783                                         for (i_index2 = 0; i_index2 < 256; i_index2++)
1784                                                 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_]));
1785 #endif
1786                                 switch (p_vout->output.i_chroma)
1787                                 {
1788                                     case VLC_FOURCC('Y','U','Y','2'):    // packed by 2
1789                                     case VLC_FOURCC('Y','U','N','V'):    // packed by 2
1790                                         Denom = F2(length / p_pic->p->i_pixel_pitch);
1791                                         a_2 = p_vout->p_sys->a_2 * (ACCURACY / 100);
1792                                         a_1 = p_vout->p_sys->a_1 * 2 * p_vout->p_sys->i_halfHeight * (ACCURACY / 100);
1793                                         a_0 = p_vout->p_sys->a_0 * Denom * (ACCURACY / 100);
1794                                         for (i_index = 0; i_index < length / p_pic->p->i_pixel_pitch; i_index+=p_pic->p->i_pixel_pitch)
1795                                         // for each macropixel
1796                                         {
1797                                                 // first image pixel
1798                                                 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);
1799                                                 p_vout->p_sys->cstYUV2[i_row][0][i_index] = ((ACCURACY - p_vout->p_sys->lambda2[i_row][0][i_index]) * constantYUV[0]) / ACCURACY;
1800                                                 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);
1801                                                 p_vout->p_sys->cstYUV2[i_row][1][i_index] = ((ACCURACY - p_vout->p_sys->lambda2[i_row][1][i_index]) * constantYUV[1]) / ACCURACY;
1802                                                 // second image pixel
1803                                                 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);
1804                                                 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;
1805                                                 p_vout->p_sys->lambda2[i_row][1][i_index + 1] = p_vout->p_sys->lambda2[i_row][1][i_index];
1806                                                 p_vout->p_sys->cstYUV2[i_row][1][i_index + 1] = p_vout->p_sys->cstYUV2[i_row][1][i_index];
1807                                         }
1808                                         break;
1809                                     case VLC_FOURCC('U','Y','V','Y'):    // packed by 2
1810                                     case VLC_FOURCC('U','Y','N','V'):    // packed by 2
1811                                     case VLC_FOURCC('Y','4','2','2'):    // packed by 2
1812                                         Denom = F2(length / p_pic->p->i_pixel_pitch);
1813                                         a_2 = p_vout->p_sys->a_2 * (ACCURACY / 100);
1814                                         a_1 = p_vout->p_sys->a_1 * 2 * p_vout->p_sys->i_halfHeight * (ACCURACY / 100);
1815                                         a_0 = p_vout->p_sys->a_0 * Denom * (ACCURACY / 100);
1816                                         for (i_index = 0; i_index < length / p_pic->p->i_pixel_pitch; i_index+=p_pic->p->i_pixel_pitch)
1817                                         // for each macropixel
1818                                         {
1819                                                 // first image pixel
1820                                                 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);
1821                                                 p_vout->p_sys->cstYUV2[i_row][0][i_index] = ((ACCURACY - p_vout->p_sys->lambda2[i_col][0][i_index]) * constantYUV[1]) / ACCURACY;
1822                                                 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);
1823                                                 p_vout->p_sys->cstYUV2[i_row][1][i_index] = ((ACCURACY - p_vout->p_sys->lambda2[i_row][1][i_index]) * constantYUV[0]) / ACCURACY;
1824                                                 // second image pixel
1825                                                 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);
1826                                                 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;
1827                                                 p_vout->p_sys->lambda2[i_row][1][i_index + 1] = p_vout->p_sys->lambda2[i_row][1][i_index];
1828                                                 p_vout->p_sys->cstYUV2[i_row][1][i_index + 1] = p_vout->p_sys->cstYUV2[i_row][1][i_index];
1829                                         }
1830                                         break;
1831                                     default :
1832                                         break;
1833                                 }
1834                         }
1835                         p_out -= TopOffset * p_outpic->p[i_plane].i_pitch;
1836 #ifndef GAMMA
1837                         for (i_index = 0; i_index < length / p_pic->p->i_pixel_pitch; i_index++)
1838                             for (i_index2 = 0; i_index2 < i_copy_pitch; i_index2++)
1839                                 *(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] *
1840                                      (*(p_out + (i_index * p_outpic->p[i_plane].i_pitch) + i_index2))) / ACCURACY +
1841                                      p_vout->p_sys->cstYUV2[i_row][i_index2 % p_pic->p->i_pixel_pitch][i_index];
1842 #else
1843                         for (i_index = 0; i_index < length / p_pic->p->i_pixel_pitch; i_index++)
1844                             for (i_index2 = 0; i_index2 < i_copy_pitch; i_index2++)
1845                                 *(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] *
1846                                      (*(p_out + (i_index * p_outpic->p[i_plane].i_pitch) + i_index2))) / ACCURACY +
1847                                      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];
1848
1849 #endif
1850                         p_out += TopOffset * p_outpic->p[i_plane].i_pitch;
1851             }
1852 #endif
1853 // bug for wall filter : fix by CC
1854 //            pi_left_skip[i_plane] += i_out_pitch;
1855             pi_left_skip[i_plane] += i_copy_pitch;
1856             }
1857
1858             vout_UnlinkPicture( p_vout->p_sys->pp_vout[ i_vout ].p_vout,
1859                                 p_outpic );
1860             vout_DisplayPicture( p_vout->p_sys->pp_vout[ i_vout ].p_vout,
1861                                  p_outpic );
1862             i_vout++;
1863         }
1864
1865         for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ )
1866         {
1867             pi_top_skip[i_plane] += p_vout->p_sys->pp_vout[ i_vout ].i_height
1868                                      * p_pic->p[i_plane].i_lines
1869                                      / p_vout->output.i_height
1870                                      * p_pic->p[i_plane].i_pitch;
1871         }
1872     }
1873 #ifdef OVERLAP
1874     if (p_vout->p_sys->b_has_changed) p_vout->p_sys->b_has_changed = VLC_FALSE;
1875 #endif
1876 }
1877 #endif
1878
1879
1880 /*****************************************************************************
1881  * RemoveAllVout: destroy all the child video output threads
1882  *****************************************************************************/
1883 static void RemoveAllVout( vout_thread_t *p_vout )
1884 {
1885     while( p_vout->p_sys->i_vout )
1886     {
1887          --p_vout->p_sys->i_vout;
1888          if( p_vout->p_sys->pp_vout[ p_vout->p_sys->i_vout ].b_active )
1889          {
1890              DEL_CALLBACKS(
1891                  p_vout->p_sys->pp_vout[ p_vout->p_sys->i_vout ].p_vout,
1892                  SendEvents );
1893              vlc_object_detach(
1894                  p_vout->p_sys->pp_vout[ p_vout->p_sys->i_vout ].p_vout );
1895              vout_Destroy(
1896                  p_vout->p_sys->pp_vout[ p_vout->p_sys->i_vout ].p_vout );
1897          }
1898     }
1899 }
1900
1901 /*****************************************************************************
1902  * SendEvents: forward mouse and keyboard events to the parent p_vout
1903  *****************************************************************************/
1904 static int SendEvents( vlc_object_t *p_this, char const *psz_var,
1905                        vlc_value_t oldval, vlc_value_t newval, void *_p_vout )
1906 {
1907     vout_thread_t *p_vout = (vout_thread_t *)_p_vout;
1908     int i_vout;
1909     vlc_value_t sentval = newval;
1910
1911     /* Find the video output index */
1912     for( i_vout = 0; i_vout < p_vout->p_sys->i_vout; i_vout++ )
1913     {
1914         if( p_this == (vlc_object_t *)p_vout->p_sys->pp_vout[ i_vout ].p_vout )
1915         {
1916             break;
1917         }
1918     }
1919
1920     if( i_vout == p_vout->p_sys->i_vout )
1921     {
1922         return VLC_EGENERIC;
1923     }
1924
1925     /* Translate the mouse coordinates */
1926     if( !strcmp( psz_var, "mouse-x" ) )
1927     {
1928 #ifdef OVERLAP
1929         int i_overlap = ((p_vout->p_sys->i_col > 2) ? 0 : 2 * p_vout->p_sys->i_halfLength);
1930            sentval.i_int += (p_vout->output.i_width - i_overlap)
1931 #else
1932            sentval.i_int += p_vout->output.i_width
1933 #endif
1934                          * (i_vout % p_vout->p_sys->i_col)
1935                           / p_vout->p_sys->i_col;
1936     }
1937     else if( !strcmp( psz_var, "mouse-y" ) )
1938     {
1939 #ifdef OVERLAP
1940         int i_overlap = ((p_vout->p_sys->i_row > 2) ? 0 : 2 * p_vout->p_sys->i_halfHeight);
1941            sentval.i_int += (p_vout->output.i_height - i_overlap)
1942 #else
1943            sentval.i_int += p_vout->output.i_height
1944 #endif
1945 //bug fix in Wall plug-in
1946 //                         * (i_vout / p_vout->p_sys->i_row)
1947                          * (i_vout / p_vout->p_sys->i_col)
1948                           / p_vout->p_sys->i_row;
1949     }
1950
1951     var_Set( p_vout, psz_var, sentval );
1952
1953     return VLC_SUCCESS;
1954 }
1955
1956 /*****************************************************************************
1957  * SendEventsToChild: forward events to the child/children vout
1958  *****************************************************************************/
1959 static int SendEventsToChild( vlc_object_t *p_this, char const *psz_var,
1960                        vlc_value_t oldval, vlc_value_t newval, void *p_data )
1961 {
1962
1963     vout_thread_t *p_vout = (vout_thread_t *)p_this;
1964     int i_row, i_col, i_vout = 0;
1965
1966     for( i_row = 0; i_row < p_vout->p_sys->i_row; i_row++ )
1967     {
1968         for( i_col = 0; i_col < p_vout->p_sys->i_col; i_col++ )
1969         {
1970             var_Set( p_vout->p_sys->pp_vout[ i_vout ].p_vout, psz_var, newval);
1971             if( !strcmp( psz_var, "fullscreen" ) ) break;
1972             i_vout++;
1973         }
1974     }
1975
1976     return VLC_SUCCESS;
1977 }