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