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