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