]> git.sesse.net Git - vlc/blob - modules/video_filter/panoramix.c
macosx: fixed menubar appearance in fullscreen mode by partially reverting [46c93c9cc...
[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_FOURCC('Y','M','G','A'):
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_FOURCC('Y','2','1','1'):     // packed by 4
315 // Packed YUV Reverted
316 case VLC_FOURCC('c','y','u','v'):    // packed by 2
317 */
318     switch (p_vout->render.i_chroma)
319     {
320     // planar YUV
321         case VLC_FOURCC('I','4','4','4'):
322         case VLC_FOURCC('I','4','2','2'):
323         case VLC_FOURCC('I','4','2','0'):
324         case VLC_FOURCC('Y','V','1','2'):
325         case VLC_FOURCC('I','Y','U','V'):
326         case VLC_FOURCC('I','4','1','1'):
327         case VLC_FOURCC('I','4','1','0'):
328         case VLC_FOURCC('Y','V','U','9'):
329         case VLC_FOURCC('Y','U','V','A'):
330             p_vout->pf_render = RenderPlanarYUV;
331             break;
332     // packed RGB
333         case VLC_FOURCC('R','G','B','2'):    // packed by 1
334         case VLC_FOURCC('R','V','1','5'):    // packed by 2
335         case VLC_FOURCC('R','V','1','6'):    // packed by 2
336         case VLC_FOURCC('R','V','2','4'):    // packed by 3
337         case VLC_FOURCC('R','V','3','2'):    // packed by 4
338             p_vout->pf_render = RenderPackedRGB;
339             break;
340 #ifdef PACKED_YUV
341     // packed YUV
342         case VLC_FOURCC('Y','U','Y','2'):    // packed by 2
343         case VLC_FOURCC('Y','U','N','V'):    // packed by 2
344         case VLC_FOURCC('U','Y','V','Y'):    // packed by 2
345         case VLC_FOURCC('U','Y','N','V'):    // packed by 2
346         case VLC_FOURCC('Y','4','2','2'):    // packed by 2
347             p_vout->pf_render = RenderPackedYUV;
348             break;
349 #endif
350         default:
351             msg_Err( p_vout, "colorspace not supported by plug-in !!!");
352             free( p_vout->p_sys );
353             return VLC_ENOMEM;
354     }
355     p_vout->pf_display = NULL;
356     p_vout->pf_control = Control;
357
358     config_ChainParse( p_vout, CFG_PREFIX, ppsz_filter_options,
359                        p_vout->p_cfg );
360
361     /* Look what method was requested */
362     p_vout->p_sys->i_col = var_CreateGetInteger( p_vout, CFG_PREFIX "cols" );
363     p_vout->p_sys->i_row = var_CreateGetInteger( p_vout, CFG_PREFIX "rows" );
364
365 // OS dependent code :  Autodetect number of displays in wall
366 #ifdef WIN32
367     if ((p_vout->p_sys->i_col < 0) || (p_vout->p_sys->i_row < 0) )
368     {
369         int nbMonitors = GetSystemMetrics(SM_CMONITORS);
370         if (nbMonitors == 1)
371         {
372             nbMonitors = 5; // 1 display => 5x1 simulation
373             p_vout->p_sys->i_col = nbMonitors;
374             p_vout->p_sys->i_row = 1;
375         }
376         else
377         {
378             p_vout->p_sys->i_col = GetSystemMetrics( SM_CXVIRTUALSCREEN ) / GetSystemMetrics( SM_CXSCREEN );
379             p_vout->p_sys->i_row = GetSystemMetrics( SM_CYVIRTUALSCREEN ) / GetSystemMetrics( SM_CYSCREEN );
380             if (p_vout->p_sys->i_col * p_vout->p_sys->i_row != nbMonitors)
381             {
382                 p_vout->p_sys->i_col = nbMonitors;
383                 p_vout->p_sys->i_row = 1;
384             }
385         }
386         var_SetInteger( p_vout, CFG_PREFIX "cols", p_vout->p_sys->i_col);
387         var_SetInteger( p_vout, CFG_PREFIX "rows", p_vout->p_sys->i_row);
388     }
389 #endif
390
391 #ifdef OVERLAP
392     p_vout->p_sys->i_offset_x = var_CreateGetBool( p_vout, CFG_PREFIX "offset-x" );
393     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
394     p_vout->p_sys->b_autocrop = !(var_CreateGetInteger( p_vout, "crop-ratio" ) == 0);
395     if (!p_vout->p_sys->b_autocrop) p_vout->p_sys->b_autocrop = var_CreateGetInteger( p_vout, "autocrop" );
396     p_vout->p_sys->b_attenuate = var_CreateGetBool( p_vout, CFG_PREFIX "attenuate");
397     p_vout->p_sys->bz_length = var_CreateGetInteger( p_vout, CFG_PREFIX "bz-length" );
398     if (p_vout->p_sys->i_row > 1)
399         p_vout->p_sys->bz_height = var_CreateGetInteger( p_vout, CFG_PREFIX "bz-height" );
400     else
401         p_vout->p_sys->bz_height = 100;
402     p_vout->p_sys->bz_begin = var_CreateGetInteger( p_vout, CFG_PREFIX "bz-begin" );
403     p_vout->p_sys->bz_middle = var_CreateGetInteger( p_vout, CFG_PREFIX "bz-middle" );
404     p_vout->p_sys->bz_end = var_CreateGetInteger( p_vout, CFG_PREFIX "bz-end" );
405     p_vout->p_sys->bz_middle_pos = var_CreateGetInteger( p_vout, CFG_PREFIX "bz-middle-pos" );
406     double d_p = 100.0 / p_vout->p_sys->bz_middle_pos;
407     p_vout->p_sys->i_ratio_max = var_CreateGetInteger( p_vout, "autocrop-ratio-max" ); // in crop module with autocrop ...
408     p_vout->p_sys->i_ratio = var_CreateGetInteger( p_vout, "crop-ratio" ); // in crop module with manual ratio ...
409
410     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;
411     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;
412     p_vout->p_sys->a_0 =  p_vout->p_sys->bz_begin;
413
414 #ifdef GAMMA
415     p_vout->p_sys->f_gamma_red = var_CreateGetFloat( p_vout, CFG_PREFIX "bz-gamma-red" );
416     p_vout->p_sys->f_gamma_green = var_CreateGetFloat( p_vout, CFG_PREFIX "bz-gamma-green" );
417     p_vout->p_sys->f_gamma_blue = var_CreateGetFloat( p_vout, CFG_PREFIX "bz-gamma-blue" );
418 #endif
419 #ifndef WIN32
420     p_vout->p_sys->b_xinerama = var_CreateGetBool( p_vout, CFG_PREFIX "xinerama" );
421 #endif
422 #else
423     p_vout->p_sys->i_col = __MAX( 1, __MIN( 15, p_vout->p_sys->i_col ) );
424     p_vout->p_sys->i_row = __MAX( 1, __MIN( 15, p_vout->p_sys->i_row ) );
425 #endif
426
427     msg_Dbg( p_vout, "opening a %i x %i wall",
428              p_vout->p_sys->i_col, p_vout->p_sys->i_row );
429
430     p_vout->p_sys->pp_vout = calloc( p_vout->p_sys->i_row *
431                                      p_vout->p_sys->i_col,
432                                      sizeof(struct vout_list_t) );
433     if( p_vout->p_sys->pp_vout == NULL )
434     {
435         free( p_vout->p_sys );
436         return VLC_ENOMEM;
437     }
438
439     psz_method_tmp =
440     psz_method = var_CreateGetNonEmptyString( p_vout, CFG_PREFIX "active" );
441
442     /* If no trailing vout are specified, take them all */
443     if( psz_method == NULL )
444     {
445         for( i_vout = p_vout->p_sys->i_row * p_vout->p_sys->i_col;
446              i_vout--; )
447         {
448             p_vout->p_sys->pp_vout[i_vout].b_active = 1;
449         }
450     }
451     /* If trailing vout are specified, activate only the requested ones */
452     else
453     {
454         for( i_vout = p_vout->p_sys->i_row * p_vout->p_sys->i_col;
455              i_vout--; )
456         {
457             p_vout->p_sys->pp_vout[i_vout].b_active = 0;
458         }
459
460         while( *psz_method )
461         {
462             psz_tmp = psz_method;
463             while( *psz_tmp && *psz_tmp != ',' )
464             {
465                 psz_tmp++;
466             }
467
468             if( *psz_tmp )
469             {
470                 *psz_tmp = '\0';
471                 i_vout = atoi( psz_method );
472                 psz_method = psz_tmp + 1;
473             }
474             else
475             {
476                 i_vout = atoi( psz_method );
477                 psz_method = psz_tmp;
478             }
479
480             if( i_vout >= 0 &&
481                 i_vout < p_vout->p_sys->i_row * p_vout->p_sys->i_col )
482             {
483                 p_vout->p_sys->pp_vout[i_vout].b_active = 1;
484             }
485         }
486     }
487
488     free( psz_method_tmp );
489
490     return VLC_SUCCESS;
491 }
492
493
494 #ifdef OVERLAP
495 /*****************************************************************************
496  * CLIP_0A: clip between 0 and ACCURACY
497  *****************************************************************************/
498 inline static int CLIP_0A( int a )
499 {
500     return (a > ACCURACY) ? ACCURACY : (a < 0) ? 0 : a;
501 }
502
503 #ifdef GAMMA
504 /*****************************************************************************
505  *  Gamma: Gamma correction
506  *****************************************************************************/
507 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])
508 {
509     float f_Input;
510
511     f_Input = (f_component * f_BlackLevel[i_plane]) / (f_BlackCrush[i_plane]) + (1.0 - f_BlackLevel[i_plane]);
512     if (f_component <= f_BlackCrush[i_plane])
513     {
514         return pow(f_Input, 1.0 / f_Gamma[i_plane]);
515     }
516     else if (f_component >= f_WhiteCrush[i_plane])
517     {
518         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);
519         return pow(f_Input, 1.0 / f_Gamma[i_plane]);
520     }
521     else
522     {
523         return 1.0;
524     }
525 }
526
527 #ifdef PACKED_YUV
528
529 /*****************************************************************************
530  * F: Function to calculate Gamma correction
531  *****************************************************************************/
532 static uint8_t F(uint8_t i, float gamma)
533 {
534     double input = (double) i / 255.0;
535
536     // return clip(255 * pow(input, 1.0 / gamma));
537
538     if (input < 0.5)
539         return clip_uint8((255 * pow(2 * input, gamma)) / 2);
540     else
541         return clip_uint8(255 * (1 - pow(2 * (1 - input), gamma) / 2));
542 }
543 #endif
544 #endif
545
546 /*****************************************************************************
547  * AdjustHeight: ajust p_sys->i_height to have same BZ width for any ratio
548  *****************************************************************************/
549 static int AdjustHeight( vout_thread_t *p_vout )
550 {
551     bool b_fullscreen = p_vout->b_fullscreen;
552     int i_window_width = p_vout->i_window_width;
553     int i_window_height = p_vout->i_window_height;
554     double d_halfLength = 0;
555     double d_halfLength_crop;
556     double d_halfLength_calculated;
557     int    i_offset = 0;
558
559     // OS DEPENDENT CODE to get display dimensions
560     if (b_fullscreen )
561     {
562 #ifdef WIN32
563         i_window_width  = GetSystemMetrics(SM_CXSCREEN);
564         i_window_height = GetSystemMetrics(SM_CYSCREEN);
565 #else
566         char *psz_display = var_CreateGetNonEmptyString( p_vout,
567                                                         "x11-display" );
568         Display *p_display = XOpenDisplay( psz_display );
569         free( psz_display );
570         if (p_vout->p_sys->b_xinerama)
571         {
572             i_window_width = DisplayWidth(p_display, 0) / p_vout->p_sys->i_col;
573             i_window_height = DisplayHeight(p_display, 0) / p_vout->p_sys->i_row;
574         }
575         else
576         {
577             i_window_width = DisplayWidth(p_display, 0);
578             i_window_height = DisplayHeight(p_display, 0);
579         }
580         XCloseDisplay( p_display );
581 #endif
582         var_SetInteger( p_vout, "width", i_window_width);
583         var_SetInteger( p_vout, "height", i_window_height);
584         p_vout->i_window_width = i_window_width;
585         p_vout->i_window_height = i_window_height;
586     }
587
588     if( p_vout->p_sys->bz_length)
589         if ((!p_vout->p_sys->b_autocrop) && (!p_vout->p_sys->i_ratio))
590         {
591             if ((p_vout->p_sys->i_row > 1) || (p_vout->p_sys->i_col > 1))
592             {
593                 while ((d_halfLength <= 0) || (d_halfLength > p_vout->render.i_width / (2 * p_vout->p_sys->i_col)))
594                 {
595                     if (p_vout->p_sys->bz_length >= 50)
596                     {
597                         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);
598                     }
599                     else
600                     {
601                         d_halfLength = (p_vout->render.i_width * p_vout->p_sys->bz_length) / (100.0 * p_vout->p_sys->i_col);
602                         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);
603                     }
604                     if ((d_halfLength <= 0) || (d_halfLength > p_vout->render.i_width / (2 * p_vout->p_sys->i_col)))
605                         p_vout->p_sys->i_row--;
606                     if (p_vout->p_sys->i_row < 1 )
607                     {
608                         p_vout->p_sys->i_row = 1;
609                         break;
610                     }
611                 }
612                 p_vout->p_sys->i_halfLength = (d_halfLength + 0.5);
613                 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;
614                 var_SetInteger( p_vout, "bz-length", p_vout->p_sys->bz_length);
615                 var_SetInteger( p_vout, "panoramix-rows", p_vout->p_sys->i_row);
616             }
617         }
618         else
619         {
620             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;
621             d_halfLength_crop = d_halfLength * VOUT_ASPECT_FACTOR * (double)p_vout->output.i_width
622                         / (double)i_window_height / (double)p_vout->render.i_aspect;
623             p_vout->p_sys->i_halfLength = (d_halfLength_crop + 0.5);
624             d_halfLength_calculated = p_vout->p_sys->i_halfLength * (double)i_window_height *
625                                 (double)p_vout->render.i_aspect  /     VOUT_ASPECT_FACTOR / (double)p_vout->output.i_width;
626
627             if (!p_vout->p_sys->b_attenuate)
628             {
629                 double d_bz_length = (p_vout->p_sys->i_halfLength * p_vout->p_sys->i_col * 100.0) / p_vout->render.i_width;
630                 // F(2x) != 2F(x) in opengl module
631                 if (p_vout->p_sys->i_col == 2) d_bz_length = (100.0 * d_bz_length) / (100.0 - d_bz_length) ;
632                 var_SetInteger( p_vout, "bz-length", (int)(d_bz_length + 0.5));
633             }
634             i_offset =  (int)d_halfLength - (int)
635                         (p_vout->p_sys->i_halfLength * (double)i_window_height *
636                         (double)p_vout->render.i_aspect  /     VOUT_ASPECT_FACTOR / (double)p_vout->output.i_width);
637         }
638     else
639         p_vout->p_sys->i_halfLength = 0;
640
641     return i_offset;
642 }
643 #endif
644
645
646 /*****************************************************************************
647  * Init: initialize Wall video thread output method
648  *****************************************************************************/
649 #define VLC_XCHG( type, a, b ) do { type __tmp = (b); (b) = (a); (a) = __tmp; } while(0)
650
651 static int Init( vout_thread_t *p_vout )
652 {
653     int i_index, i_row, i_col;
654
655     I_OUTPUTPICTURES = 0;
656
657     /* Initialize the output structure */
658     p_vout->output.i_chroma = p_vout->render.i_chroma;
659     p_vout->output.i_width  = p_vout->render.i_width;
660     p_vout->output.i_height = p_vout->render.i_height;
661     p_vout->output.i_aspect = p_vout->render.i_aspect;
662 #ifdef OVERLAP
663     p_vout->p_sys->b_has_changed = p_vout->p_sys->b_attenuate;
664     int i_video_x = var_GetInteger( p_vout, "video-x");
665     int i_video_y = var_GetInteger( p_vout, "video-y");
666 #ifdef GAMMA
667     if (p_vout->p_sys->b_attenuate)
668     {
669         int i_index2, i_plane;
670         int constantYUV[3] = {0,128,128};
671         float    f_BlackCrush[VOUT_MAX_PLANES];
672         float    f_BlackLevel[VOUT_MAX_PLANES];
673         float    f_WhiteCrush[VOUT_MAX_PLANES];
674         float    f_WhiteLevel[VOUT_MAX_PLANES];
675         p_vout->p_sys->f_gamma[0] = var_CreateGetFloat( p_vout, CFG_PREFIX "bz-gamma-red" );
676         p_vout->p_sys->f_gamma[1] = var_CreateGetFloat( p_vout, CFG_PREFIX "bz-gamma-green" );
677         p_vout->p_sys->f_gamma[2] = var_CreateGetFloat( p_vout, CFG_PREFIX "bz-gamma-blue" );
678         f_BlackCrush[0] = var_CreateGetInteger( p_vout, CFG_PREFIX "bz-blackcrush-red" ) / 255.0;
679         f_BlackCrush[1] = var_CreateGetInteger( p_vout, CFG_PREFIX "bz-blackcrush-green" ) / 255.0;
680         f_BlackCrush[2] = var_CreateGetInteger( p_vout, CFG_PREFIX "bz-blackcrush-blue" ) / 255.0;
681         f_WhiteCrush[0] = var_CreateGetInteger( p_vout, CFG_PREFIX "bz-whitecrush-red" ) / 255.0;
682         f_WhiteCrush[1] = var_CreateGetInteger( p_vout, CFG_PREFIX "bz-whitecrush-green" ) / 255.0;
683         f_WhiteCrush[2] = var_CreateGetInteger( p_vout, CFG_PREFIX "bz-whitecrush-blue" ) / 255.0;
684         f_BlackLevel[0] = var_CreateGetInteger( p_vout, CFG_PREFIX "bz-blacklevel-red" ) / 255.0;
685         f_BlackLevel[1] = var_CreateGetInteger( p_vout, CFG_PREFIX "bz-blacklevel-green" ) / 255.0;
686         f_BlackLevel[2] = var_CreateGetInteger( p_vout, CFG_PREFIX "bz-blacklevel-blue" ) / 255.0;
687         f_WhiteLevel[0] = var_CreateGetInteger( p_vout, CFG_PREFIX "bz-whitelevel-red" ) / 255.0;
688         f_WhiteLevel[1] = var_CreateGetInteger( p_vout, CFG_PREFIX "bz-whitelevel-green" ) / 255.0;
689         f_WhiteLevel[2] = var_CreateGetInteger( p_vout, CFG_PREFIX "bz-whitelevel-blue" ) / 255.0;
690         for( int i = 3; i < VOUT_MAX_PLANES; i++ )
691         {
692             /* Initialize unsupported planes */
693             f_BlackCrush[i] = 140.0/255.0;
694             f_WhiteCrush[i] = 200.0/255.0;
695             f_BlackLevel[i] = 150.0/255.0;
696             f_WhiteLevel[i] = 0.0/255.0;
697             p_vout->p_sys->f_gamma[i] = 1.0;
698         }
699
700         switch (p_vout->render.i_chroma)
701         {
702         // planar YVU
703             case VLC_FOURCC('Y','V','1','2'):
704             case VLC_FOURCC('Y','V','U','9'):
705         // packed UYV
706             case VLC_FOURCC('U','Y','V','Y'):    // packed by 2
707             case VLC_FOURCC('U','Y','N','V'):    // packed by 2
708             case VLC_FOURCC('Y','4','2','2'):    // packed by 2
709     //        case VLC_FOURCC('c','y','u','v'):    // packed by 2
710                 VLC_XCHG( float, p_vout->p_sys->f_gamma[1], p_vout->p_sys->f_gamma[2] );
711                 VLC_XCHG( float, f_BlackCrush[1], f_BlackCrush[2] );
712                 VLC_XCHG( float, f_WhiteCrush[1], f_WhiteCrush[2] );
713                 VLC_XCHG( float, f_BlackLevel[1], f_BlackLevel[2] );
714                 VLC_XCHG( float, f_WhiteLevel[1], f_WhiteLevel[2] );
715         // planar YUV
716             case VLC_FOURCC('I','4','4','4'):
717             case VLC_FOURCC('I','4','2','2'):
718             case VLC_FOURCC('I','4','2','0'):
719             case VLC_FOURCC('I','4','1','1'):
720             case VLC_FOURCC('I','4','1','0'):
721             case VLC_FOURCC('I','Y','U','V'):
722             case VLC_FOURCC('Y','U','V','A'):
723         // packed YUV
724             case VLC_FOURCC('Y','U','Y','2'):    // packed by 2
725             case VLC_FOURCC('Y','U','N','V'):    // packed by 2
726                 for (i_index = 0; i_index < 256; i_index++)
727                     for (i_index2 = 0; i_index2 <= ACCURACY; i_index2++)
728                         for (i_plane = 0; i_plane < VOUT_MAX_PLANES; i_plane++)
729                         {
730                             float f_lut = CLIP_01(1.0 -
731                                      ((ACCURACY - (float)i_index2)
732                                      * Gamma_Correction(i_plane, (float)i_index / 255.0, f_BlackCrush, f_WhiteCrush, f_BlackLevel, f_WhiteLevel, p_vout->p_sys->f_gamma)
733                                      / (ACCURACY - 1)));
734                             p_vout->p_sys->LUT[i_plane][i_index2][i_index] = f_lut * i_index + (int)((1.0 - f_lut) * (float)constantYUV[i_plane]);
735                         }
736                 break;
737         // packed RGB
738             case VLC_FOURCC('R','G','B','2'):    // packed by 1
739             case VLC_FOURCC('R','V','1','5'):    // packed by 2
740             case VLC_FOURCC('R','V','1','6'):    // packed by 2
741             case VLC_FOURCC('R','V','2','4'):    // packed by 3
742             case VLC_FOURCC('R','V','3','2'):    // packed by 4
743             for (i_index = 0; i_index < 256; i_index++)
744                     for (i_index2 = 0; i_index2 <= ACCURACY; i_index2++)
745                         for (i_plane = 0; i_plane < VOUT_MAX_PLANES; i_plane++)
746                         {
747                             float f_lut = CLIP_01(1.0 -
748                                      ((ACCURACY - (float)i_index2)
749                                      * Gamma_Correction(i_plane, (float)i_index / 255.0, f_BlackCrush, f_WhiteCrush, f_BlackLevel, f_WhiteLevel, p_vout->p_sys->f_gamma)
750                                      / (ACCURACY - 1)));
751                             p_vout->p_sys->LUT[i_plane][i_index2][i_index] = f_lut * i_index;
752                         }
753                 break;
754             default:
755                 msg_Err( p_vout, "colorspace not supported by plug-in !!!");
756                 free( p_vout->p_sys );
757                 return VLC_ENOMEM;
758         }
759     }
760 #endif
761     if (p_vout->p_sys->i_offset_x)
762         p_vout->p_sys->i_offset_x = AdjustHeight(p_vout);
763     else
764         AdjustHeight(p_vout);
765     if (p_vout->p_sys->i_row >= 2)
766     {
767         p_vout->p_sys->i_halfHeight = (p_vout->p_sys->i_halfLength * p_vout->p_sys->bz_height) / 100;
768         p_vout->p_sys->i_halfHeight -= (p_vout->p_sys->i_halfHeight % 2);
769     }
770 #endif
771
772     /* Try to open the real video output */
773     msg_Dbg( p_vout, "spawning the real video outputs" );
774
775     /* FIXME: use bresenham instead of those ugly divisions */
776     p_vout->p_sys->i_vout = 0;
777     for( i_row = 0; i_row < p_vout->p_sys->i_row; i_row++ )
778     {
779         for( i_col = 0; i_col < p_vout->p_sys->i_col; i_col++, p_vout->p_sys->i_vout++ )
780         {
781             struct vout_list_t *p_entry = &p_vout->p_sys->pp_vout[ p_vout->p_sys->i_vout ];
782             video_format_t fmt;
783             int i_width, i_height;
784
785             /* */
786             i_width = ( p_vout->render.i_width / p_vout->p_sys->i_col ) & ~0x1;
787             if( i_col + 1 == p_vout->p_sys->i_col )
788                 i_width = p_vout->render.i_width - i_col * i_width;
789
790 #ifdef OVERLAP
791             i_width += p_vout->p_sys->i_halfLength;
792             if (p_vout->p_sys->i_col > 2 )
793                 i_width += p_vout->p_sys->i_halfLength;
794             i_width &= ~0x1;
795 #endif
796
797             /* */
798             i_height = ( p_vout->render.i_height / p_vout->p_sys->i_row ) & ~0x3;
799             if( i_row + 1 == p_vout->p_sys->i_row )
800                 i_height = p_vout->render.i_height - i_row * i_height;
801 #ifdef OVERLAP
802             if(p_vout->p_sys->i_row >= 2 )
803             {
804                 i_height += p_vout->p_sys->i_halfHeight;
805                 if( p_vout->p_sys->i_row > 2 )
806                     i_height += p_vout->p_sys->i_halfHeight;
807             }
808             i_height &= ~0x1;
809 #endif
810             p_entry->i_width = i_width;
811             p_entry->i_height = i_height;
812
813             if( !p_entry->b_active )
814                 continue;
815
816             /* */
817             memset( &fmt, 0, sizeof(video_format_t) );
818             fmt.i_width = fmt.i_visible_width = p_vout->render.i_width;
819             fmt.i_height = fmt.i_visible_height = p_vout->render.i_height;
820             fmt.i_x_offset = fmt.i_y_offset = 0;
821             fmt.i_chroma = p_vout->render.i_chroma;
822             fmt.i_aspect = p_vout->render.i_aspect;
823             fmt.i_sar_num = p_vout->render.i_aspect * fmt.i_height / fmt.i_width;
824             fmt.i_sar_den = VOUT_ASPECT_FACTOR;
825             fmt.i_width = fmt.i_visible_width = i_width;
826             fmt.i_height = fmt.i_visible_height = i_height;
827             fmt.i_aspect = p_vout->render.i_aspect
828                               * p_vout->render.i_height / i_height
829                               * i_width / p_vout->render.i_width;
830 #ifdef OVERLAP
831             if (p_vout->p_sys->i_offset_x < 0)
832             {
833                 var_SetInteger(p_vout, "video-x", -p_vout->p_sys->i_offset_x);
834                 p_vout->p_sys->i_offset_x = 0;
835             }
836 #endif
837             p_entry->p_vout = vout_Create( p_vout, &fmt);
838
839             if( p_entry->p_vout == NULL )
840             {
841                 msg_Err( p_vout, "failed to get %ix%i vout threads",
842                                  p_vout->p_sys->i_col, p_vout->p_sys->i_row );
843                 RemoveAllVout( p_vout );
844                 return VLC_EGENERIC;
845             }
846             vout_filter_SetupChild( p_vout, p_entry->p_vout,
847                                     MouseEvent, FullscreenEventUp, FullscreenEventDown, true );
848
849 #ifdef OVERLAP
850             p_entry->p_vout->i_alignment = 0;
851             if (i_col == 0)
852                 p_entry->p_vout->i_alignment |= VOUT_ALIGN_RIGHT;
853             else if (i_col == p_vout->p_sys->i_col -1)
854                 p_entry->p_vout->i_alignment |= VOUT_ALIGN_LEFT;
855             if (p_vout->p_sys->i_row > 1)
856             {
857                 if (i_row == 0)
858                     p_entry->p_vout->i_alignment |= VOUT_ALIGN_BOTTOM;
859                 else if (i_row == p_vout->p_sys->i_row -1)
860                     p_entry->p_vout->i_alignment |= VOUT_ALIGN_TOP;
861             }
862             // i_active : number of active pp_vout
863             int i_active = 0;
864             for( int i = 0; i <= p_vout->p_sys->i_vout; i++ )
865             {
866                 if( p_vout->p_sys->pp_vout[i].b_active )
867                     i_active++;
868             }
869             var_SetInteger( p_vout, "align", p_entry->p_vout->i_alignment );
870             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);
871             var_SetInteger( p_vout, "video-y", i_video_y +                             (i_active / p_vout->p_sys->i_col) * p_vout->i_window_height);
872 #endif
873         }
874     }
875
876     vout_filter_AllocateDirectBuffers( p_vout, VOUT_MAX_PICTURES );
877
878     return VLC_SUCCESS;
879 }
880
881 /*****************************************************************************
882  * End: terminate Wall video thread output method
883  *****************************************************************************/
884 static void End( vout_thread_t *p_vout )
885 {
886     RemoveAllVout( p_vout );
887
888     vout_filter_ReleaseDirectBuffers( p_vout );
889
890 #ifdef OVERLAP
891     var_SetInteger( p_vout, "bz-length", p_vout->p_sys->bz_length);
892 #endif
893 }
894
895 /*****************************************************************************
896  * Destroy: destroy Wall video thread output method
897  *****************************************************************************
898  * Terminate an output method created by WallCreateOutputMethod
899  *****************************************************************************/
900 static void Destroy( vlc_object_t *p_this )
901 {
902     vout_thread_t *p_vout = (vout_thread_t *)p_this;
903
904     free( p_vout->p_sys->pp_vout );
905     free( p_vout->p_sys );
906
907 }
908
909 /*****************************************************************************
910  * RenderPlanarYUV: displays previously rendered output
911  *****************************************************************************
912  * This function send the currently rendered image to Wall image, waits
913  * until it is displayed and switch the two rendering buffers, preparing next
914  * frame.
915  *****************************************************************************/
916 static void RenderPlanarYUV( vout_thread_t *p_vout, picture_t *p_pic )
917 {
918     picture_t *p_outpic = NULL;
919     int i_col, i_row, i_vout, i_plane;
920     int pi_left_skip[VOUT_MAX_PLANES], pi_top_skip[VOUT_MAX_PLANES];
921 #ifdef OVERLAP
922     int TopOffset;
923     int constantYUV[3] = {0,128,128};
924     int Denom;
925     int a_2;
926     int a_1;
927     int a_0;
928     int i_index, i_index2;
929 #endif
930
931     for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ )
932         pi_top_skip[i_plane] = 0;
933
934     for( i_vout = 0, i_row = 0; i_row < p_vout->p_sys->i_row; i_row++ )
935     {
936         for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ )
937             pi_left_skip[i_plane] = 0;
938
939         for( i_col = 0; i_col < p_vout->p_sys->i_col; i_col++, i_vout++ )
940         {
941             struct vout_list_t *p_entry = &p_vout->p_sys->pp_vout[ i_vout ];
942             if( !p_entry->b_active )
943             {
944                 for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ )
945                 {
946                     pi_left_skip[i_plane] += p_entry->i_width * p_pic->p[i_plane].i_pitch / p_vout->output.i_width;
947                 }
948                 continue;
949             }
950
951             while( ( p_outpic = vout_CreatePicture( p_entry->p_vout, 0, 0, 0 )) == NULL )
952             {
953                 if( !vlc_object_alive(p_vout) || p_vout->b_error )
954                 {
955                     vout_DestroyPicture( p_entry->p_vout, p_outpic );
956                     return;
957                 }
958                 msleep( VOUT_OUTMEM_SLEEP );
959             }
960
961             p_outpic->date = p_pic->date;
962             vout_LinkPicture( p_entry->p_vout, p_outpic );
963
964             for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ )
965             {
966                 uint8_t *p_in, *p_in_end, *p_out;
967                 int i_in_pitch = p_pic->p[i_plane].i_pitch;
968                 int i_out_pitch = p_outpic->p[i_plane].i_pitch;
969                 int i_copy_pitch = p_outpic->p[i_plane].i_visible_pitch;
970                 int i_lines = p_outpic->p[i_plane].i_visible_lines;
971                 const int i_div = p_entry->i_width / i_copy_pitch;
972
973                 const bool b_row_first = i_row == 0;
974                 const bool b_row_last = i_row + 1 == p_vout->p_sys->i_row;
975                 const bool b_col_first = i_col == 0;
976                 const bool b_col_last = i_col + 1 == p_vout->p_sys->i_col;
977
978 #ifdef OVERLAP
979                 if( !b_col_first )
980                     pi_left_skip[i_plane] -= (2 * p_vout->p_sys->i_halfLength ) / i_div;
981
982                 if( p_vout->p_sys->i_row >= 2 )
983                 {
984                     if( !b_row_first && b_col_first )
985                         pi_top_skip[i_plane] -= (2 * p_vout->p_sys->i_halfHeight * p_pic->p[i_plane].i_pitch) / i_div;
986                     if( p_vout->p_sys->i_row > 2 && i_row == 1 && b_col_first )
987                         pi_top_skip[i_plane] -= (2 * p_vout->p_sys->i_halfHeight * p_pic->p[i_plane].i_pitch) / i_div;
988                     if( !p_vout->p_sys->pp_vout[p_vout->p_sys->i_col-1].b_active )
989                         pi_top_skip[i_plane] -= (2 * p_vout->p_sys->i_halfHeight * i_row * p_pic->p[i_plane].i_pitch) / i_div;
990                 }
991 // i_n : previous inactive pp_vout
992                 int i_n=0;
993                 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++;
994                 if( i_col > 1 && i_n )
995                     pi_left_skip[i_plane] -= i_n * (2 * p_vout->p_sys->i_halfLength ) / i_div;
996
997
998                 if( p_vout->p_sys->i_row > 2 && ( b_row_first || b_row_last ) )
999                     i_lines -= (2 * p_vout->p_sys->i_halfHeight) / i_div;
1000
1001 // 1088 lines bug in a mpeg2 stream of 1080 lines
1002                 if( b_row_last && p_pic->p[i_plane].i_lines == 1088 )
1003                     i_lines -= 8 / i_div;
1004 #endif
1005                 /* */
1006                 p_in = &p_pic->p[i_plane].p_pixels[ pi_top_skip[i_plane] + pi_left_skip[i_plane] ]; /* Wall proprities */
1007                 p_in_end = &p_in[i_lines * p_pic->p[i_plane].i_pitch];
1008
1009                 p_out = p_outpic->p[i_plane].p_pixels;
1010 #ifdef OVERLAP
1011                 if( p_vout->p_sys->i_row > 2 && b_row_first )
1012                     p_out += p_outpic->p[i_plane].i_pitch * (2 * p_vout->p_sys->i_halfHeight) / i_div;
1013
1014                 int i_col_mod;
1015                 int length = 2 * p_vout->p_sys->i_halfLength / i_div;
1016
1017                 if( p_vout->p_sys->b_has_changed )
1018                 {
1019                     Denom = F2(length);
1020                     a_2 = p_vout->p_sys->a_2 * (ACCURACY / 100);
1021                     a_1 = p_vout->p_sys->a_1 * length * (ACCURACY / 100);
1022                     a_0 = p_vout->p_sys->a_0 * Denom * (ACCURACY / 100);
1023                     for( i_col_mod = 0; i_col_mod < 2; i_col_mod++ )
1024                     {
1025                         for( i_index = 0; i_index < length; i_index++ )
1026                         {
1027                             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);
1028                             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;
1029                         }
1030                     }
1031                 }
1032 #endif
1033                 while( p_in < p_in_end )
1034                 {
1035 #ifndef OVERLAP
1036                     vlc_memcpy( p_out, p_in, i_copy_pitch);
1037 #else
1038                     if( p_vout->p_sys->i_col > 2 )
1039                     {
1040                         const int halfl = length / 2;
1041                         if( b_col_first)
1042                             vlc_memcpy( &p_out[halfl], &p_in[0], i_copy_pitch - halfl );
1043                         else if( b_col_last )
1044                             vlc_memcpy( &p_out[    0], &p_in[-halfl], i_copy_pitch - halfl );
1045                         else
1046                             vlc_memcpy( &p_out[    0], &p_in[-halfl], i_copy_pitch);
1047
1048                         // black bar
1049                         if( b_col_first )
1050                             memset( &p_out[0], constantYUV[i_plane], halfl);
1051                         else if( b_col_last )
1052                             memset( &p_out[i_copy_pitch - halfl], constantYUV[i_plane], halfl );
1053                     }
1054                     else
1055                     {
1056                         vlc_memcpy( p_out , p_in, i_copy_pitch );
1057                     }
1058
1059                     if( p_vout->p_sys->b_attenuate )
1060                     {
1061                         // vertical blend
1062                         // first blended zone
1063                         if( !b_col_first )
1064                         {
1065                             uint8_t *p_dst = &p_out[0];
1066                             for (i_index = 0; i_index < length; i_index++)
1067                             {
1068 #ifndef GAMMA
1069                                 p_dst[i_index] = (p_vout->p_sys->lambda[1][i_plane][i_index] * p_dst[i_index]) / ACCURACY +
1070                                                         p_vout->p_sys->cstYUV[1][i_plane][i_index];
1071 #else
1072                                 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]];
1073 #endif
1074                             }
1075                         }
1076                         // second blended zone
1077                         if( !b_col_last )
1078                         {
1079                             uint8_t *p_dst = &p_out[i_copy_pitch - length];
1080                             for (i_index = 0; i_index < length; i_index++)
1081                             {
1082 #ifndef GAMMA
1083                                 p_dst[i_index] = (p_vout->p_sys->lambda[0][i_plane][i_index] * p_dst[i_index]) / ACCURACY +
1084                                                         p_vout->p_sys->cstYUV[0][i_plane][i_index];
1085 #else
1086                                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]];
1087 #endif
1088                             }
1089                         }
1090                         // end blended zone
1091                     }
1092 #endif
1093                     p_in += i_in_pitch;
1094                     p_out += i_out_pitch;
1095                 }
1096 #ifdef OVERLAP
1097        // horizontal blend
1098         if ( p_vout->p_sys->i_row >= 2 )
1099         {
1100            // black bar
1101            if (( p_vout->p_sys->i_row > 2 ) && (( b_row_first ) || ( b_row_last )))
1102            {
1103
1104                int height = 2 * p_vout->p_sys->i_halfHeight / i_div;
1105                if ( b_row_first )
1106                {
1107                     TopOffset = i_lines + (2 * p_vout->p_sys->i_halfHeight) / i_div;
1108                }
1109                else
1110                 {
1111                    TopOffset = height - (2 * p_vout->p_sys->i_halfHeight) / i_div;
1112                 }
1113                 uint8_t *p_dst = p_out - TopOffset * i_out_pitch;
1114                 for (i_index = 0; i_index < height; i_index++)
1115                    for (i_index2 = 0; i_index2 < i_copy_pitch; i_index2++)
1116                        p_dst[i_index * i_out_pitch + i_index2] = constantYUV[i_plane];
1117            }
1118            if( p_vout->p_sys->b_attenuate )
1119            {
1120                length = 2 * p_vout->p_sys->i_halfHeight / (p_vout->p_sys->pp_vout[i_vout].i_width / i_copy_pitch);
1121                if (p_vout->p_sys->b_has_changed)
1122                {
1123                    Denom = F2(length);
1124                    a_2 = p_vout->p_sys->a_2 * (ACCURACY / 100);
1125                    a_1 = p_vout->p_sys->a_1 * length * (ACCURACY / 100);
1126                    a_0 = p_vout->p_sys->a_0 * Denom * (ACCURACY / 100);
1127                    for(i_col_mod = 0; i_col_mod < 2; i_col_mod++)
1128                        for (i_index = 0; i_index < length; i_index++)
1129                        {
1130                            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);
1131                            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;
1132                        }
1133                }
1134                // first blended zone
1135                if ( !b_row_first )
1136                {
1137                         TopOffset = i_lines;
1138                         uint8_t *p_dst = p_out - TopOffset * i_out_pitch;
1139
1140                         for (i_index = 0; i_index < length; i_index++)
1141                         {
1142                             for (i_index2 = 0; i_index2 < i_copy_pitch; i_index2++)
1143                             {
1144 #ifndef GAMMA
1145                                 p_dst[i_index * i_out_pitch + i_index2] = ( p_vout->p_sys->lambda2[1][i_plane][i_index] *
1146                                              p_dst[i_index * i_out_pitch + i_index2] ) / ACCURACY +
1147                                              p_vout->p_sys->cstYUV2[1][i_plane][i_index];
1148 #else
1149                                 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]];
1150 #endif
1151                             }
1152                         }
1153                }
1154                // second blended zone
1155                if ( !b_row_last )
1156                {
1157                         TopOffset = length;
1158                         uint8_t *p_dst = p_out - TopOffset * p_outpic->p[i_plane].i_pitch;
1159
1160                         for (i_index = 0; i_index < length; i_index++)
1161                         {
1162                             for (i_index2 = 0; i_index2 < i_copy_pitch; i_index2++)
1163                             {
1164 #ifndef GAMMA
1165                                 p_dst[i_index * i_out_pitch + i_index2] = (p_vout->p_sys->lambda2[0][i_plane][i_index] *
1166                                              p_dst[i_index * i_out_pitch + i_index2]) / ACCURACY +
1167                                              p_vout->p_sys->cstYUV2[0][i_plane][i_index];
1168 #else
1169
1170                                 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]];
1171 #endif
1172                             }
1173                         }
1174                }
1175            }
1176         }
1177        // end blended zone
1178 #endif
1179                 // bug for wall filter : fix by CC
1180                 //            pi_left_skip[i_plane] += i_out_pitch;
1181                 pi_left_skip[i_plane] += i_copy_pitch;
1182             }
1183
1184             vout_UnlinkPicture( p_vout->p_sys->pp_vout[ i_vout ].p_vout,
1185                                 p_outpic );
1186             vout_DisplayPicture( p_vout->p_sys->pp_vout[ i_vout ].p_vout,
1187                                  p_outpic );
1188         }
1189
1190         for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ )
1191         {
1192             pi_top_skip[i_plane] += p_vout->p_sys->pp_vout[ i_vout-1 ].i_height
1193                                              * p_pic->p[i_plane].i_lines
1194                                              / p_vout->output.i_height
1195                                              * p_pic->p[i_plane].i_pitch;
1196         }
1197     }
1198 #ifdef OVERLAP
1199     if (p_vout->p_sys->b_has_changed)
1200         p_vout->p_sys->b_has_changed = false;
1201 #endif
1202 }
1203
1204
1205 /*****************************************************************************
1206  * RenderPackedRGB: displays previously rendered output
1207  *****************************************************************************
1208  * This function send the currently rendered image to Wall image, waits
1209  * until it is displayed and switch the two rendering buffers, preparing next
1210  * frame.
1211  *****************************************************************************/
1212 static void RenderPackedRGB( vout_thread_t *p_vout, picture_t *p_pic )
1213 {
1214     picture_t *p_outpic = NULL;
1215     int i_col, i_row, i_vout, i_plane;
1216     int pi_left_skip[VOUT_MAX_PLANES], pi_top_skip[VOUT_MAX_PLANES];
1217 #ifdef OVERLAP
1218     int LeftOffset, TopOffset;
1219     int Denom;
1220     int a_2;
1221     int a_1;
1222     int a_0;
1223     int i_index, i_index2;
1224 #endif
1225
1226     for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ )
1227         pi_top_skip[i_plane] = 0;
1228
1229     for( i_vout = 0, i_row = 0; i_row < p_vout->p_sys->i_row; i_row++ )
1230     {
1231         for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ )
1232             pi_left_skip[i_plane] = 0;
1233
1234         for( i_col = 0; i_col < p_vout->p_sys->i_col; i_col++, i_vout++ )
1235         {
1236             if( !p_vout->p_sys->pp_vout[ i_vout ].b_active )
1237             {
1238                 for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ )
1239                 {
1240                     pi_left_skip[i_plane] +=
1241                         p_vout->p_sys->pp_vout[ i_vout ].i_width * p_pic->p->i_pixel_pitch;
1242                 }
1243                 continue;
1244             }
1245
1246             while( ( p_outpic =
1247                 vout_CreatePicture( p_vout->p_sys->pp_vout[ i_vout ].p_vout,
1248                                     0, 0, 0 )
1249                    ) == NULL )
1250             {
1251                 if( !vlc_object_alive (p_vout) || p_vout->b_error )
1252                 {
1253                     vout_DestroyPicture(
1254                         p_vout->p_sys->pp_vout[ i_vout ].p_vout, p_outpic );
1255                     return;
1256                 }
1257
1258                 msleep( VOUT_OUTMEM_SLEEP );
1259             }
1260
1261             p_outpic->date = p_pic->date;
1262             vout_LinkPicture( p_vout->p_sys->pp_vout[ i_vout ].p_vout,
1263                               p_outpic );
1264
1265             for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ )
1266             {
1267                 uint8_t *p_in, *p_in_end, *p_out;
1268                 int i_in_pitch = p_pic->p[i_plane].i_pitch;
1269                 int i_out_pitch = p_outpic->p[i_plane].i_pitch;
1270                 int i_copy_pitch = p_outpic->p[i_plane].i_visible_pitch;
1271
1272 #ifdef OVERLAP
1273                 if (i_col)
1274                     pi_left_skip[i_plane] -= (2 * p_vout->p_sys->i_halfLength) * p_pic->p->i_pixel_pitch;
1275                 if( p_vout->p_sys->i_row >= 2 )
1276                 {
1277                     if( (i_row) && (!i_col))
1278                         pi_top_skip[i_plane] -= (2 * p_vout->p_sys->i_halfHeight * p_pic->p[i_plane].i_pitch);
1279                     if( (p_vout->p_sys->i_row > 2) && (i_row == 1) && (!i_col) )
1280                         pi_top_skip[i_plane] -= (2 * p_vout->p_sys->i_halfHeight * p_pic->p[i_plane].i_pitch);
1281                     if( !p_vout->p_sys->pp_vout[p_vout->p_sys->i_col-1].b_active )
1282                         pi_top_skip[i_plane] -= (2 * p_vout->p_sys->i_halfHeight * i_row * p_pic->p[i_plane].i_pitch);
1283                 }
1284 // i_n : previous inactive pp_vout
1285                 int i_n=0;
1286                 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++;
1287                 if ((i_col > 1) && i_n)
1288                     pi_left_skip[i_plane] -= i_n*(2 * p_vout->p_sys->i_halfLength ) * p_pic->p->i_pixel_pitch;
1289
1290                 p_in = p_pic->p[i_plane].p_pixels
1291                 /* Wall proprities */
1292                 + pi_top_skip[i_plane] + pi_left_skip[i_plane];
1293
1294                 int i_lines = p_outpic->p[i_plane].i_visible_lines;
1295 // 1088 lines bug in a mpeg2 stream of 1080 lines
1296                 if ((p_vout->p_sys->i_row - 1 == i_row) &&
1297                     (p_pic->p[i_plane].i_lines == 1088))
1298                         i_lines -= 8;
1299
1300                 p_in_end = p_in + i_lines * p_pic->p[i_plane].i_pitch;
1301 #else
1302                 p_in = p_pic->p[i_plane].p_pixels
1303                         + pi_top_skip[i_plane] + pi_left_skip[i_plane];
1304
1305                 p_in_end = p_in + p_outpic->p[i_plane].i_visible_lines
1306                                         * p_pic->p[i_plane].i_pitch;
1307 #endif //OVERLAP
1308
1309                 p_out = p_outpic->p[i_plane].p_pixels;
1310
1311
1312 #ifdef OVERLAP
1313         if ((p_vout->p_sys->i_row > 2) && (!i_row))
1314             p_out += (p_outpic->p[i_plane].i_pitch * (2 * p_vout->p_sys->i_halfHeight) * p_pic->p->i_pixel_pitch);
1315
1316         int length;
1317         length = 2 * p_vout->p_sys->i_halfLength * p_pic->p->i_pixel_pitch;
1318
1319         if (p_vout->p_sys->b_has_changed)
1320         {
1321             int i_plane_;
1322             int i_col_mod;
1323             Denom = F2(length / p_pic->p->i_pixel_pitch);
1324             a_2 = p_vout->p_sys->a_2 * (ACCURACY / 100);
1325             a_1 = p_vout->p_sys->a_1 * 2 * p_vout->p_sys->i_halfLength * (ACCURACY / 100);
1326             a_0 = p_vout->p_sys->a_0 * Denom * (ACCURACY / 100);
1327             for(i_col_mod = 0; i_col_mod < 2; i_col_mod++)
1328                 for (i_index = 0; i_index < length / p_pic->p->i_pixel_pitch; i_index++)
1329                     for (i_plane_ =  0; i_plane_ < p_pic->p->i_pixel_pitch; i_plane_++)
1330                         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);
1331         }
1332 #endif
1333             while( p_in < p_in_end )
1334             {
1335 #ifndef OVERLAP
1336                 vlc_memcpy( p_out, p_in, i_copy_pitch );
1337 #else
1338                 if (p_vout->p_sys->i_col > 2)
1339                 {
1340                     // vertical blend
1341                     length /= 2;
1342                     if (i_col == 0)
1343                         vlc_memcpy( p_out + length, p_in, i_copy_pitch - length);
1344                     else if (i_col + 1 == p_vout->p_sys->i_col)
1345                         vlc_memcpy( p_out, p_in - length, i_copy_pitch - length);
1346                     else
1347                         vlc_memcpy( p_out, p_in - length, i_copy_pitch);
1348
1349                     if ((i_col == 0))
1350                     // black bar
1351                     {
1352                         LeftOffset = 0;
1353                         p_out += LeftOffset;
1354                         p_in += LeftOffset;
1355                         for (i_index = 0; i_index < length; i_index++)
1356                                 *(p_out + i_index) = 0;
1357                         p_out -= LeftOffset;
1358                         p_in -= LeftOffset;
1359                     }
1360                     else if ((i_col + 1 == p_vout->p_sys->i_col ))
1361                     // black bar
1362                         {
1363                             LeftOffset = i_copy_pitch - length;
1364                             p_out += LeftOffset;
1365                             p_in += LeftOffset;
1366                             for (i_index = 0; i_index < length; i_index++)
1367                                     *(p_out + i_index) = 0;
1368                             p_out -= LeftOffset;
1369                             p_in -= LeftOffset;
1370                         }
1371                     length *= 2;
1372                 }
1373                 else
1374                     vlc_memcpy( p_out, p_in, i_copy_pitch);
1375
1376 // vertical blend
1377 // first blended zone
1378             if (i_col)
1379             {
1380                 LeftOffset = 0;
1381                 p_out += LeftOffset;
1382                 for (i_index = 0; i_index < length; i_index++)
1383 #ifndef GAMMA
1384                     *(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] *
1385                                  (*(p_out + i_index))) / ACCURACY;
1386 #else
1387                     *(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)];
1388 #endif
1389                 p_out -= LeftOffset;
1390             }
1391 // second blended zone
1392             if (i_col + 1 < p_vout->p_sys->i_col)
1393             {
1394                 LeftOffset = i_copy_pitch - length;
1395                 p_out +=  LeftOffset;
1396                 for (i_index = 0; i_index < length; i_index++)
1397 #ifndef GAMMA
1398                     *(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] *
1399                                  (*(p_out + i_index))) / ACCURACY;
1400 #else
1401                     *(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)];
1402 #endif
1403                 p_out -= LeftOffset;
1404             }
1405 // end blended zone
1406 #endif //OVERLAP
1407                 p_in += i_in_pitch;
1408                 p_out += i_out_pitch;
1409             }
1410 #ifdef OVERLAP
1411 // horizontal blend
1412         if (!p_vout->p_sys->b_attenuate)
1413         {
1414             if ((i_row == 0) && (p_vout->p_sys->i_row > 2))
1415             // black bar
1416             {
1417                     TopOffset = i_lines + (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             else if ((i_row + 1 == p_vout->p_sys->i_row) && (p_vout->p_sys->i_row > 2))
1425             // black bar
1426                 {
1427                     TopOffset = length - (2 * p_vout->p_sys->i_halfHeight);
1428                     p_out -= TopOffset * p_outpic->p[i_plane].i_pitch;
1429                     for (i_index = 0; i_index < length; i_index++)
1430                         for (i_index2 = 0; i_index2 < i_copy_pitch; i_index2++)
1431                             *(p_out + (i_index * p_outpic->p[i_plane].i_pitch) + i_index2) = 0;
1432                     p_out += TopOffset * p_outpic->p[i_plane].i_pitch;
1433                 }
1434         }
1435         else
1436         {
1437             if (p_vout->p_sys->i_row >= 2)
1438             {
1439                 length = 2 * p_vout->p_sys->i_halfHeight;
1440                 if (p_vout->p_sys->b_has_changed)
1441                 {
1442                     int i_plane_;
1443                     int i_row_mod;
1444                     Denom = F2(length);
1445                     a_2 = p_vout->p_sys->a_2 * (ACCURACY / 100);
1446                     a_1 = p_vout->p_sys->a_1 * length * (ACCURACY / 100);
1447                     a_0 = p_vout->p_sys->a_0 * Denom * (ACCURACY / 100);
1448                     for(i_row_mod = 0; i_row_mod < 2; i_row_mod++)
1449                       for (i_index = 0; i_index < length; i_index++)
1450                         for (i_plane_ =  0; i_plane_ < p_pic->p->i_pixel_pitch; i_plane_++)
1451                             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);
1452                 }
1453 // first blended zone
1454
1455             if (i_row)
1456             {
1457                 TopOffset = i_lines;
1458                 p_out -= TopOffset * p_outpic->p[i_plane].i_pitch;
1459                 for (i_index = 0; i_index < length; i_index++)
1460                     for (i_index2 = 0; i_index2 < i_copy_pitch; i_index2++)
1461 #ifndef GAMMA
1462                     *(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] *
1463                                  (*(p_out + (i_index * p_outpic->p[i_plane].i_pitch) + i_index2))) / ACCURACY;
1464 #else
1465                     *(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)];
1466 #endif
1467                 p_out += TopOffset * p_outpic->p[i_plane].i_pitch;
1468             }
1469             else if (p_vout->p_sys->i_row > 2)
1470             // black bar
1471             {
1472                 TopOffset = i_lines + (2 * p_vout->p_sys->i_halfHeight);
1473                 p_out -= TopOffset * p_outpic->p[i_plane].i_pitch;
1474                 for (i_index = 0; i_index < length; i_index++)
1475                     for (i_index2 = 0; i_index2 < i_copy_pitch; i_index2++)
1476                         *(p_out + (i_index * p_outpic->p[i_plane].i_pitch) + i_index2) = 0;
1477                 p_out += TopOffset * p_outpic->p[i_plane].i_pitch;
1478             }
1479
1480 // second blended zone
1481
1482             if (i_row + 1 < p_vout->p_sys->i_row)
1483             {
1484                 TopOffset = length;
1485                 p_out -= TopOffset * p_outpic->p[i_plane].i_pitch;
1486                 for (i_index = 0; i_index < length; i_index++)
1487                     for (i_index2 = 0; i_index2 < i_copy_pitch; i_index2++)
1488 #ifndef GAMMA
1489                     *(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] *
1490                                  (*(p_out + (i_index * p_outpic->p[i_plane].i_pitch) + i_index2))) / ACCURACY;
1491 #else
1492                     *(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)];
1493
1494 #endif
1495                 p_out += TopOffset * p_outpic->p[i_plane].i_pitch;
1496             }
1497             else if (p_vout->p_sys->i_row > 2)
1498             // black bar
1499             {
1500                 TopOffset = length - (2 * p_vout->p_sys->i_halfHeight);
1501                 p_out -= TopOffset * p_outpic->p[i_plane].i_pitch;
1502                 for (i_index = 0; i_index < length; i_index++)
1503                     for (i_index2 = 0; i_index2 < i_copy_pitch; i_index2++)
1504                         *(p_out + (i_index * p_outpic->p[i_plane].i_pitch) + i_index2) = 0;
1505                 p_out += TopOffset * p_outpic->p[i_plane].i_pitch;
1506             }
1507 // end blended zone
1508             }
1509         }
1510 #endif
1511 // bug for wall filter : fix by CC
1512 //            pi_left_skip[i_plane] += i_out_pitch;
1513             pi_left_skip[i_plane] += i_copy_pitch;
1514             }
1515
1516             vout_UnlinkPicture( p_vout->p_sys->pp_vout[ i_vout ].p_vout,
1517                                 p_outpic );
1518             vout_DisplayPicture( p_vout->p_sys->pp_vout[ i_vout ].p_vout,
1519                                  p_outpic );
1520         }
1521
1522         for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ )
1523         {
1524             pi_top_skip[i_plane] += p_vout->p_sys->pp_vout[ i_vout-1 ].i_height
1525                                      * p_pic->p[i_plane].i_lines
1526                                      / p_vout->output.i_height
1527                                      * p_pic->p[i_plane].i_pitch;
1528         }
1529     }
1530 #ifdef OVERLAP
1531     if (p_vout->p_sys->b_has_changed) p_vout->p_sys->b_has_changed = false;
1532 #endif
1533 }
1534
1535
1536 #ifdef PACKED_YUV
1537 // WARNING : NO DEBUGGED
1538 /*****************************************************************************
1539  * RenderPackedYUV: displays previously rendered output
1540  *****************************************************************************
1541  * This function send the currently rendered image to Wall image, waits
1542  * until it is displayed and switch the two rendering buffers, preparing next
1543  * frame.
1544  *****************************************************************************/
1545 static void RenderPackedYUV( vout_thread_t *p_vout, picture_t *p_pic )
1546 {
1547     picture_t *p_outpic = NULL;
1548     int i_col, i_row, i_vout, i_plane;
1549     int pi_left_skip[VOUT_MAX_PLANES], pi_top_skip[VOUT_MAX_PLANES];
1550 #ifdef OVERLAP
1551     int LeftOffset, TopOffset;
1552     int constantYUV[3] = {0,128,128};
1553     int Denom;
1554     int a_2;
1555     int a_1;
1556     int a_0;
1557     int i_index, i_index2;
1558 #endif
1559
1560     for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ )
1561         pi_top_skip[i_plane] = 0;
1562
1563     for( i_vout = 0;, i_row = 0; i_row < p_vout->p_sys->i_row; i_row++ )
1564     {
1565         for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ )
1566             pi_left_skip[i_plane] = 0;
1567
1568         for( i_col = 0; i_col < p_vout->p_sys->i_col; i_col++, i_vout++ )
1569         {
1570             if( !p_vout->p_sys->pp_vout[ i_vout ].b_active )
1571             {
1572                 for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ )
1573                 {
1574                     pi_left_skip[i_plane] +=
1575                         p_vout->p_sys->pp_vout[ i_vout ].i_width
1576                          * p_pic->p[i_plane].i_pitch / p_vout->output.i_width;
1577                 }
1578                 continue;
1579             }
1580
1581             while( ( p_outpic =
1582                 vout_CreatePicture( p_vout->p_sys->pp_vout[ i_vout ].p_vout,
1583                                     0, 0, 0 )
1584                    ) == NULL )
1585             {
1586                 if( !vlc_object_alive (p_vout) || p_vout->b_error )
1587                 {
1588                     vout_DestroyPicture(
1589                         p_vout->p_sys->pp_vout[ i_vout ].p_vout, p_outpic );
1590                     return;
1591                 }
1592
1593                 msleep( VOUT_OUTMEM_SLEEP );
1594             }
1595
1596             p_outpic->date = p_pic->date;
1597             vout_LinkPicture( p_vout->p_sys->pp_vout[ i_vout ].p_vout,
1598                               p_outpic );
1599
1600             for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ )
1601             {
1602                 uint8_t *p_in, *p_in_end, *p_out;
1603                 int i_in_pitch = p_pic->p[i_plane].i_pitch;
1604                 int i_out_pitch = p_outpic->p[i_plane].i_pitch;
1605                 int i_copy_pitch = p_outpic->p[i_plane].i_visible_pitch;
1606                 const int i_div = p_vout->p_sys->pp_vout[i_vout].i_width / i_copy_pitch;
1607
1608 #ifdef OVERLAP
1609                 if (i_col) pi_left_skip[i_plane] -= (2 * p_vout->p_sys->i_halfLength ) / i_div;
1610                 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;
1611                 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;
1612                 if( !p_vout->p_sys->pp_vout[p_vout->p_sys->i_col-1].b_active )
1613                     pi_top_skip[i_plane] -= (2 * p_vout->p_sys->i_halfHeight * i_row * p_pic->p[i_plane].i_pitch) / i_div;
1614 // i_n : previous inactive pp_vout
1615                 int i_n=0;
1616                 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++;
1617                 if ((i_col > 1) && i_n)
1618                     pi_left_skip[i_plane] -= i_n*(2 * p_vout->p_sys->i_halfLength ) / i_div;
1619
1620                 p_in = p_pic->p[i_plane].p_pixels
1621                 /* Wall proprities */
1622                 + pi_top_skip[i_plane] + pi_left_skip[i_plane];
1623
1624                 int i_lines = p_outpic->p[i_plane].i_visible_lines;
1625 // 1088 lines bug in a mpeg2 stream of 1080 lines
1626                 if ((p_vout->p_sys->i_row - 1 == i_row) &&
1627                     (p_pic->p[i_plane].i_lines == 1088))
1628                         i_lines -= 8;
1629
1630                 p_in_end = p_in + i_lines * p_pic->p[i_plane].i_pitch;
1631 #else
1632                 p_in = p_pic->p[i_plane].p_pixels
1633                         + pi_top_skip[i_plane] + pi_left_skip[i_plane];
1634
1635                 p_in_end = p_in + p_outpic->p[i_plane].i_visible_lines
1636                                         * p_pic->p[i_plane].i_pitch;
1637 #endif
1638                 p_out = p_outpic->p[i_plane].p_pixels;
1639 #ifdef OVERLAP
1640         int length;
1641         length = 2 * p_vout->p_sys->i_halfLength * p_pic->p->i_pixel_pitch;
1642         LeftOffset = (i_col ? 0 : i_copy_pitch - length);
1643         if (p_vout->p_sys->b_has_changed)
1644         {
1645 #ifdef GAMMA
1646             int i_plane_;
1647             for (i_index = 0; i_index < length / p_pic->p->i_pixel_pitch; i_index++)
1648                 for (i_plane_ =  0; i_plane_ < p_pic->p->i_pixel_pitch; i_plane_++)
1649                     for (i_index2 = 0; i_index2 < 256; i_index2++)
1650                             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_]));
1651 #endif
1652             switch (p_vout->output.i_chroma)
1653                 {
1654                     case VLC_FOURCC('Y','U','Y','2'):    // packed by 2
1655                     case VLC_FOURCC('Y','U','N','V'):    // packed by 2
1656                         Denom = F2(length / p_pic->p->i_pixel_pitch);
1657                         a_2 = p_vout->p_sys->a_2 * (ACCURACY / 100);
1658                         a_1 = p_vout->p_sys->a_1 * 2 * p_vout->p_sys->i_halfLength * (ACCURACY / 100);
1659                         a_0 = p_vout->p_sys->a_0 * Denom * (ACCURACY / 100);
1660                         for (i_index = 0; i_index < length / p_pic->p->i_pixel_pitch; i_index+=p_pic->p->i_pixel_pitch)
1661                         // for each macropixel
1662                         {
1663                                 // first image pixel
1664                                 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);
1665                                 p_vout->p_sys->cstYUV[i_col][0][i_index] = ((ACCURACY - p_vout->p_sys->lambda[i_col][0][i_index]) * constantYUV[0]) / ACCURACY;
1666                                 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);
1667                                 p_vout->p_sys->cstYUV[i_col][1][i_index] = ((ACCURACY - p_vout->p_sys->lambda[i_col][1][i_index]) * constantYUV[1]) / ACCURACY;
1668                                 // second image pixel
1669                                 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);
1670                                 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;
1671                                 p_vout->p_sys->lambda[i_col][1][i_index + 1] = p_vout->p_sys->lambda[i_col][1][i_index];
1672                                 p_vout->p_sys->cstYUV[i_col][1][i_index + 1] = p_vout->p_sys->cstYUV[i_col][1][i_index];
1673                         }
1674                         break;
1675                     case VLC_FOURCC('U','Y','V','Y'):    // packed by 2
1676                     case VLC_FOURCC('U','Y','N','V'):    // packed by 2
1677                     case VLC_FOURCC('Y','4','2','2'):    // packed by 2
1678                         Denom = F2(length / p_pic->p->i_pixel_pitch);
1679                         a_2 = p_vout->p_sys->a_2 * (ACCURACY / 100);
1680                         a_1 = p_vout->p_sys->a_1 * 2 * p_vout->p_sys->i_halfLength * (ACCURACY / 100);
1681                         a_0 = p_vout->p_sys->a_0 * Denom * (ACCURACY / 100);
1682                         for (i_index = 0; i_index < length / p_pic->p->i_pixel_pitch; i_index+=p_pic->p->i_pixel_pitch)
1683                         // for each macropixel
1684                         {
1685                                 // first image pixel
1686                                 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);
1687                                 p_vout->p_sys->cstYUV[i_col][0][i_index] = ((ACCURACY - p_vout->p_sys->lambda[i_col][0][i_index]) * constantYUV[1]) / ACCURACY;
1688                                 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);
1689                                 p_vout->p_sys->cstYUV[i_col][1][i_index] = ((ACCURACY - p_vout->p_sys->lambda[i_col][1][i_index]) * constantYUV[0]) / ACCURACY;
1690                                 // second image pixel
1691                                 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);
1692                                 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;
1693                                 p_vout->p_sys->lambda[i_col][1][i_index + 1] = p_vout->p_sys->lambda[i_col][1][i_index];
1694                                 p_vout->p_sys->cstYUV[i_col][1][i_index + 1] = p_vout->p_sys->cstYUV[i_col][1][i_index];
1695                         }
1696                         break;
1697                     default :
1698                         break;
1699                 }
1700         }
1701 #endif
1702             while( p_in < p_in_end )
1703             {
1704 #ifndef OVERLAP
1705                 vlc_memcpy( p_out, p_in, i_copy_pitch);
1706 #else
1707                 vlc_memcpy( p_out + i_col * length, p_in + i_col * length, i_copy_pitch - length);
1708                 p_out += LeftOffset;
1709                 p_in += LeftOffset;
1710 #ifndef GAMMA
1711                 for (i_index = 0; i_index < length; i_index++)
1712                     *(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] *
1713                              (*(p_in + i_index))) / ACCURACY +
1714                              p_vout->p_sys->cstYUV[i_col][i_index % p_pic->p->i_pixel_pitch][i_index / p_pic->p->i_pixel_pitch];
1715 #else
1716                 for (i_index = 0; i_index < length; i_index++)
1717                     *(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] *
1718                              (*(p_in + i_index))) / ACCURACY +
1719                              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];
1720 #endif
1721                 p_out -= LeftOffset;
1722                 p_in -= LeftOffset;
1723 #endif
1724                 p_in += i_in_pitch;
1725                 p_out += i_out_pitch;
1726             }
1727 #ifdef OVERLAP
1728             if (p_vout->p_sys->i_row == 2)
1729             {
1730                         length = 2 * p_vout->p_sys->i_halfHeight * p_pic->p->i_pixel_pitch;
1731                         TopOffset = (i_row ? i_lines : length / p_pic->p->i_pixel_pitch);
1732                         if (p_vout->p_sys->b_has_changed)
1733                         {
1734 #ifdef GAMMA
1735                                 int i_plane_;
1736                                 for (i_index = 0; i_index < length / p_pic->p->i_pixel_pitch; i_index++)
1737                                     for (i_plane_ =  0; i_plane_ < p_pic->p->i_pixel_pitch; i_plane_++)
1738                                         for (i_index2 = 0; i_index2 < 256; i_index2++)
1739                                                 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_]));
1740 #endif
1741                                 switch (p_vout->output.i_chroma)
1742                                 {
1743                                     case VLC_FOURCC('Y','U','Y','2'):    // packed by 2
1744                                     case VLC_FOURCC('Y','U','N','V'):    // packed by 2
1745                                         Denom = F2(length / p_pic->p->i_pixel_pitch);
1746                                         a_2 = p_vout->p_sys->a_2 * (ACCURACY / 100);
1747                                         a_1 = p_vout->p_sys->a_1 * 2 * p_vout->p_sys->i_halfHeight * (ACCURACY / 100);
1748                                         a_0 = p_vout->p_sys->a_0 * Denom * (ACCURACY / 100);
1749                                         for (i_index = 0; i_index < length / p_pic->p->i_pixel_pitch; i_index+=p_pic->p->i_pixel_pitch)
1750                                         // for each macropixel
1751                                         {
1752                                                 // first image pixel
1753                                                 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);
1754                                                 p_vout->p_sys->cstYUV2[i_row][0][i_index] = ((ACCURACY - p_vout->p_sys->lambda2[i_row][0][i_index]) * constantYUV[0]) / ACCURACY;
1755                                                 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);
1756                                                 p_vout->p_sys->cstYUV2[i_row][1][i_index] = ((ACCURACY - p_vout->p_sys->lambda2[i_row][1][i_index]) * constantYUV[1]) / ACCURACY;
1757                                                 // second image pixel
1758                                                 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);
1759                                                 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;
1760                                                 p_vout->p_sys->lambda2[i_row][1][i_index + 1] = p_vout->p_sys->lambda2[i_row][1][i_index];
1761                                                 p_vout->p_sys->cstYUV2[i_row][1][i_index + 1] = p_vout->p_sys->cstYUV2[i_row][1][i_index];
1762                                         }
1763                                         break;
1764                                     case VLC_FOURCC('U','Y','V','Y'):    // packed by 2
1765                                     case VLC_FOURCC('U','Y','N','V'):    // packed by 2
1766                                     case VLC_FOURCC('Y','4','2','2'):    // packed by 2
1767                                         Denom = F2(length / p_pic->p->i_pixel_pitch);
1768                                         a_2 = p_vout->p_sys->a_2 * (ACCURACY / 100);
1769                                         a_1 = p_vout->p_sys->a_1 * 2 * p_vout->p_sys->i_halfHeight * (ACCURACY / 100);
1770                                         a_0 = p_vout->p_sys->a_0 * Denom * (ACCURACY / 100);
1771                                         for (i_index = 0; i_index < length / p_pic->p->i_pixel_pitch; i_index+=p_pic->p->i_pixel_pitch)
1772                                         // for each macropixel
1773                                         {
1774                                                 // first image pixel
1775                                                 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);
1776                                                 p_vout->p_sys->cstYUV2[i_row][0][i_index] = ((ACCURACY - p_vout->p_sys->lambda2[i_col][0][i_index]) * constantYUV[1]) / ACCURACY;
1777                                                 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);
1778                                                 p_vout->p_sys->cstYUV2[i_row][1][i_index] = ((ACCURACY - p_vout->p_sys->lambda2[i_row][1][i_index]) * constantYUV[0]) / ACCURACY;
1779                                                 // second image pixel
1780                                                 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);
1781                                                 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;
1782                                                 p_vout->p_sys->lambda2[i_row][1][i_index + 1] = p_vout->p_sys->lambda2[i_row][1][i_index];
1783                                                 p_vout->p_sys->cstYUV2[i_row][1][i_index + 1] = p_vout->p_sys->cstYUV2[i_row][1][i_index];
1784                                         }
1785                                         break;
1786                                     default :
1787                                         break;
1788                                 }
1789                         }
1790                         p_out -= TopOffset * p_outpic->p[i_plane].i_pitch;
1791 #ifndef GAMMA
1792                         for (i_index = 0; i_index < length / p_pic->p->i_pixel_pitch; i_index++)
1793                             for (i_index2 = 0; i_index2 < i_copy_pitch; i_index2++)
1794                                 *(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] *
1795                                      (*(p_out + (i_index * p_outpic->p[i_plane].i_pitch) + i_index2))) / ACCURACY +
1796                                      p_vout->p_sys->cstYUV2[i_row][i_index2 % p_pic->p->i_pixel_pitch][i_index];
1797 #else
1798                         for (i_index = 0; i_index < length / p_pic->p->i_pixel_pitch; i_index++)
1799                             for (i_index2 = 0; i_index2 < i_copy_pitch; i_index2++)
1800                                 *(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] *
1801                                      (*(p_out + (i_index * p_outpic->p[i_plane].i_pitch) + i_index2))) / ACCURACY +
1802                                      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];
1803
1804 #endif
1805                         p_out += TopOffset * p_outpic->p[i_plane].i_pitch;
1806             }
1807 #endif
1808 // bug for wall filter : fix by CC
1809 //            pi_left_skip[i_plane] += i_out_pitch;
1810             pi_left_skip[i_plane] += i_copy_pitch;
1811             }
1812
1813             vout_UnlinkPicture( p_vout->p_sys->pp_vout[ i_vout ].p_vout,
1814                                 p_outpic );
1815             vout_DisplayPicture( p_vout->p_sys->pp_vout[ i_vout ].p_vout,
1816                                  p_outpic );
1817         }
1818
1819         for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ )
1820         {
1821             pi_top_skip[i_plane] += p_vout->p_sys->pp_vout[ i_vout-1 ].i_height
1822                                      * p_pic->p[i_plane].i_lines
1823                                      / p_vout->output.i_height
1824                                      * p_pic->p[i_plane].i_pitch;
1825         }
1826     }
1827 #ifdef OVERLAP
1828     if (p_vout->p_sys->b_has_changed) p_vout->p_sys->b_has_changed = false;
1829 #endif
1830 }
1831 #endif
1832
1833
1834 /*****************************************************************************
1835  * RemoveAllVout: destroy all the child video output threads
1836  *****************************************************************************/
1837 static void RemoveAllVout( vout_thread_t *p_vout )
1838 {
1839     vout_sys_t *p_sys = p_vout->p_sys;
1840
1841     for( int i = 0; i < p_vout->p_sys->i_vout; i++ )
1842     {
1843         if( p_sys->pp_vout[i].b_active )
1844         {
1845             vout_filter_SetupChild( p_vout, p_sys->pp_vout[i].p_vout,
1846                                     MouseEvent, FullscreenEventUp, FullscreenEventDown, true );
1847             vout_CloseAndRelease( p_sys->pp_vout[i].p_vout );
1848             p_sys->pp_vout[i].p_vout = NULL;
1849         }
1850     }
1851 }
1852
1853 /*****************************************************************************
1854  * SendEvents: forward mouse and keyboard events to the parent p_vout
1855  *****************************************************************************/
1856 static int MouseEvent( vlc_object_t *p_this, char const *psz_var,
1857                        vlc_value_t oldval, vlc_value_t newval, void *p_data )
1858 {
1859     vout_thread_t *p_vout = p_data;
1860     vout_sys_t *p_sys = p_vout->p_sys;
1861     VLC_UNUSED(oldval);
1862     int i_vout;
1863
1864     /* Find the video output index */
1865     for( i_vout = 0; i_vout < p_sys->i_vout; i_vout++ )
1866     {
1867         if( p_sys->pp_vout[i_vout].b_active &&
1868             p_this == VLC_OBJECT(p_sys->pp_vout[i_vout].p_vout) )
1869             break;
1870     }
1871     assert( i_vout < p_vout->p_sys->i_vout );
1872
1873     /* Translate the mouse coordinates */
1874     if( !strcmp( psz_var, "mouse-x" ) )
1875     {
1876 #ifdef OVERLAP
1877         int i_overlap = ((p_sys->i_col > 2) ? 0 : 2 * p_sys->i_halfLength);
1878            newval.i_int += (p_vout->output.i_width - i_overlap)
1879 #else
1880            newval.i_int += p_vout->output.i_width
1881 #endif
1882                          * (i_vout % p_sys->i_col)
1883                           / p_sys->i_col;
1884     }
1885     else if( !strcmp( psz_var, "mouse-y" ) )
1886     {
1887 #ifdef OVERLAP
1888         int i_overlap = ((p_sys->i_row > 2) ? 0 : 2 * p_sys->i_halfHeight);
1889            newval.i_int += (p_vout->output.i_height - i_overlap)
1890 #else
1891            newval.i_int += p_vout->output.i_height
1892 #endif
1893 //bug fix in Wall plug-in
1894 //                         * (i_vout / p_vout->p_sys->i_row)
1895                          * (i_vout / p_sys->i_col)
1896                           / p_sys->i_row;
1897     }
1898
1899     return var_Set( p_vout, psz_var, newval );
1900 }
1901
1902 /**
1903  * Forward fullscreen event to/from the childrens.
1904  * FIXME pretty much duplicated from wall.c
1905  */
1906 static bool IsFullscreenActive( vout_thread_t *p_vout )
1907 {
1908     vout_sys_t *p_sys = p_vout->p_sys;
1909     for( int i = 0; i < p_sys->i_vout; i++ )
1910     {
1911         if( p_sys->pp_vout[i].b_active &&
1912             var_GetBool( p_sys->pp_vout[i].p_vout, "fullscreen" ) )
1913             return true;
1914     }
1915     return false;
1916 }
1917 static int FullscreenEventUp( vlc_object_t *p_this, char const *psz_var,
1918                               vlc_value_t oldval, vlc_value_t newval, void *p_data )
1919 {
1920     vout_thread_t *p_vout = p_data;
1921     VLC_UNUSED(oldval); VLC_UNUSED(p_this); VLC_UNUSED(psz_var); VLC_UNUSED(newval);
1922
1923     const bool b_fullscreen = IsFullscreenActive( p_vout );
1924     if( !var_GetBool( p_vout, "fullscreen" ) != !b_fullscreen )
1925         return var_SetBool( p_vout, "fullscreen", b_fullscreen );
1926     return VLC_SUCCESS;
1927 }
1928 static int FullscreenEventDown( vlc_object_t *p_this, char const *psz_var,
1929                                 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1930 {
1931     vout_thread_t *p_vout = (vout_thread_t*)p_this;
1932     vout_sys_t *p_sys = p_vout->p_sys;
1933     VLC_UNUSED(oldval); VLC_UNUSED(p_data); VLC_UNUSED(psz_var);
1934
1935     const bool b_fullscreen = IsFullscreenActive( p_vout );
1936     if( !b_fullscreen != !newval.b_bool )
1937     {
1938         for( int i = 0; i < p_sys->i_vout; i++ )
1939         {
1940             if( !p_sys->pp_vout[i].b_active )
1941                 continue;
1942
1943             vout_thread_t *p_child = p_sys->pp_vout[i].p_vout;
1944             if( !var_GetBool( p_child, "fullscreen" ) != !newval.b_bool )
1945             {
1946                 var_SetBool( p_child, "fullscreen", newval.b_bool );
1947                 if( newval.b_bool )
1948                     return VLC_SUCCESS;
1949             }
1950         }
1951     }
1952     return VLC_SUCCESS;
1953 }
1954