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