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