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