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