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