panoramix.c 90.3 KB
Newer Older
1 2 3 4
/*****************************************************************************
 * panoramix.c : Wall panoramic video with edge blending plugin for vlc
 *****************************************************************************
 * Copyright (C) 2000, 2001, 2002, 2003 VideoLAN
Pierre's avatar
Pierre committed
5
 * $Id$
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
 *
 * Authors: Cedric Cocquebert <cedric.cocquebert@supelec.fr>
 *          based on Samuel Hocevar <sam@zoy.org>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
 *****************************************************************************/

/*****************************************************************************
 * Preamble
 *****************************************************************************/

29 30 31 32
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

33
#include <vlc_common.h>
34
#include <vlc_plugin.h>
Clément Stenac's avatar
Clément Stenac committed
35
#include <vlc_vout.h>
36 37 38 39 40 41 42

#include "filter_common.h"

// add by cedric.cocquebert@supelec.fr
#define OVERLAP        2350
#ifdef OVERLAP
    #include <math.h>
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
43
    // OS CODE DEPENDENT to get display dimensions
44
    #ifdef WIN32
45
        #include <windows.h>
46 47
    #else
        #include <X11/Xlib.h>
48 49 50 51 52
    #endif
    #define GAMMA        1
//  #define PACKED_YUV    1
    #define F2(a) ((a)*(a))
    #define F4(a,b,x) ((a)*(F2(x))+((b)*(x)))
53
    #define ACCURACY 1000
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
    #define RATIO_MAX 2500
    #define CLIP_01(a) (a < 0.0 ? 0.0 : (a > 1.0 ? 1.0 : a))
//    #define CLIP_0A(a) (a < 0.0 ? 0.0 : (a > ACCURACY ? ACCURACY : a))
#endif

/*****************************************************************************
 * Local prototypes
 *****************************************************************************/
static int  Create    ( vlc_object_t * );
static void Destroy   ( vlc_object_t * );

static int  Init      ( vout_thread_t * );
static void End       ( vout_thread_t * );
#ifdef PACKED_YUV
static void RenderPackedYUV   ( vout_thread_t *, picture_t * );
#endif
static void RenderPlanarYUV   ( vout_thread_t *, picture_t * );
static void RenderPackedRGB   ( vout_thread_t *, picture_t * );

static void RemoveAllVout  ( vout_thread_t *p_vout );

static int  SendEvents( vlc_object_t *, char const *,
                        vlc_value_t, vlc_value_t, void * );

/*****************************************************************************
 * Module descriptor
 *****************************************************************************/
#define COLS_TEXT N_("Number of columns")
#define COLS_LONGTEXT N_("Select the number of horizontal video windows in " \
    "which to split the video")

#define ROWS_TEXT N_("Number of rows")
#define ROWS_LONGTEXT N_("Select the number of vertical video windows in " \
    "which to split the video")

#define ACTIVE_TEXT N_("Active windows")
#define ACTIVE_LONGTEXT N_("Comma separated list of active windows, " \
    "defaults to all")

93 94
#define CFG_PREFIX "panoramix-"

95 96 97 98 99 100
vlc_module_begin ()
    set_description( N_("Panoramix: wall with overlap video filter") )
    set_shortname( N_("Panoramix" ))
    set_capability( "video filter", 0 )
    set_category( CAT_VIDEO )
    set_subcategory( SUBCAT_VIDEO_VFILTER )
101

102
    add_integer( CFG_PREFIX "cols", -1, NULL,
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
103
                 COLS_TEXT, COLS_LONGTEXT, true )
104
    add_integer( CFG_PREFIX "rows", -1, NULL,
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
105
                 ROWS_TEXT, ROWS_LONGTEXT, true )
106 107 108 109

#ifdef OVERLAP
#define OFFSET_X_TEXT N_("Offset X offset (automatic compensation)")
#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 113

#define LENGTH_TEXT N_("length of the overlapping area (in %)")
#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 117

#define HEIGHT_TEXT N_("height of the overlapping area (in %)")
#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 121

#define ATTENUATION_TEXT N_("Attenuation")
#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 125

#define BEGIN_TEXT N_("Attenuation, begin (in %)")
#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 129

#define MIDDLE_TEXT N_("Attenuation, middle (in %)")
#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 133

#define END_TEXT N_("Attenuation, end (in %)")
#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 137

#define MIDDLE_POS_TEXT N_("middle position (in %)")
#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 140 141
#ifdef GAMMA
#define RGAMMA_TEXT N_("Gamma (Red) correction")
#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 145

#define GGAMMA_TEXT N_("Gamma (Green) correction")
#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 149

#define BGAMMA_TEXT N_("Gamma (Blue) correction")
#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 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
#endif
#define RGAMMA_BC_TEXT N_("Black Crush for Red")
#define RGAMMA_BC_LONGTEXT N_("Select the Black Crush of blended zone (Red or Y component)")
#define GGAMMA_BC_TEXT N_("Black Crush for Green")
#define GGAMMA_BC_LONGTEXT N_("Select the Black Crush of blended zone (Green or U component)")
#define BGAMMA_BC_TEXT N_("Black Crush for Blue")
#define BGAMMA_BC_LONGTEXT N_("Select the Black Crush of blended zone (Blue or V component)")

#define RGAMMA_WC_TEXT N_("White Crush for Red")
#define RGAMMA_WC_LONGTEXT N_("Select the White Crush of blended zone (Red or Y component)")
#define GGAMMA_WC_TEXT N_("White Crush for Green")
#define GGAMMA_WC_LONGTEXT N_("Select the White Crush of blended zone (Green or U component)")
#define BGAMMA_WC_TEXT N_("White Crush for Blue")
#define BGAMMA_WC_LONGTEXT N_("Select the White Crush of blended zone (Blue or V component)")

#define RGAMMA_BL_TEXT N_("Black Level for Red")
#define RGAMMA_BL_LONGTEXT N_("Select the Black Level of blended zone (Red or Y component)")
#define GGAMMA_BL_TEXT N_("Black Level for Green")
#define GGAMMA_BL_LONGTEXT N_("Select the Black Level of blended zone (Green or U component)")
#define BGAMMA_BL_TEXT N_("Black Level for Blue")
#define BGAMMA_BL_LONGTEXT N_("Select the Black Level of blended zone (Blue or V component)")

#define RGAMMA_WL_TEXT N_("White Level for Red")
#define RGAMMA_WL_LONGTEXT N_("Select the White Level of blended zone (Red or Y component)")
#define GGAMMA_WL_TEXT N_("White Level for Green")
#define GGAMMA_WL_LONGTEXT N_("Select the White Level of blended zone (Green or U component)")
#define BGAMMA_WL_TEXT N_("White Level for Blue")
#define BGAMMA_WL_LONGTEXT N_("Select the White Level of blended zone (Blue or V component)")
179 180 181 182 183 184 185 186 187 188 189 190
    add_integer_with_range( CFG_PREFIX "bz-blackcrush-red", 140, 0, 255, NULL, RGAMMA_BC_TEXT, RGAMMA_BC_LONGTEXT, true )
    add_integer_with_range( CFG_PREFIX "bz-blackcrush-green", 140, 0, 255, NULL, GGAMMA_BC_TEXT, GGAMMA_BC_LONGTEXT, true )
    add_integer_with_range( CFG_PREFIX "bz-blackcrush-blue", 140, 0, 255, NULL, BGAMMA_BC_TEXT, BGAMMA_BC_LONGTEXT, true )
    add_integer_with_range( CFG_PREFIX "bz-whitecrush-red", 200, 0, 255, NULL, RGAMMA_WC_TEXT, RGAMMA_WC_LONGTEXT, true )
    add_integer_with_range( CFG_PREFIX "bz-whitecrush-green", 200, 0, 255, NULL, GGAMMA_WC_TEXT, GGAMMA_WC_LONGTEXT, true )
    add_integer_with_range( CFG_PREFIX "bz-whitecrush-blue", 200, 0, 255, NULL, BGAMMA_WC_TEXT, BGAMMA_WC_LONGTEXT, true )
    add_integer_with_range( CFG_PREFIX "bz-blacklevel-red", 150, 0, 255, NULL, RGAMMA_BL_TEXT, RGAMMA_BL_LONGTEXT, true )
    add_integer_with_range( CFG_PREFIX "bz-blacklevel-green", 150, 0, 255, NULL, GGAMMA_BL_TEXT, GGAMMA_BL_LONGTEXT, true )
    add_integer_with_range( CFG_PREFIX "bz-blacklevel-blue", 150, 0, 255, NULL, BGAMMA_BL_TEXT, BGAMMA_BL_LONGTEXT, true )
    add_integer_with_range( CFG_PREFIX "bz-whitelevel-red", 0, 0, 255, NULL, RGAMMA_WL_TEXT, RGAMMA_WL_LONGTEXT, true )
    add_integer_with_range( CFG_PREFIX "bz-whitelevel-green", 0, 0, 255, NULL, GGAMMA_WL_TEXT, GGAMMA_WL_LONGTEXT, true )
    add_integer_with_range( CFG_PREFIX "bz-whitelevel-blue", 0, 0, 255, NULL, BGAMMA_WL_TEXT, BGAMMA_WL_LONGTEXT, true )
191
#ifndef WIN32
192 193
#define XINERAMA_TEXT N_("Xinerama option")
#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 196 197
#endif
#endif

198
    add_string( CFG_PREFIX "active", NULL, NULL, ACTIVE_TEXT, ACTIVE_LONGTEXT, true )
199

200 201 202
    add_shortcut( "panoramix" )
    set_callbacks( Create, Destroy )
vlc_module_end ()
203

204
static const char *const ppsz_filter_options[] = {
205 206 207 208 209 210 211 212 213 214
    "cols", "rows", "offset-x", "bz-length", "bz-height", "attenuate",
    "bz-begin", "bz-middle", "bz-end", "bz-middle-pos", "bz-gamma-red",
    "bz-gamma-green", "bz-gamma-blue", "bz-blackcrush-red",
    "bz-blackcrush-green", "bz-blackcrush-blue", "bz-whitecrush-red",
    "bz-whitecrush-green", "bz-whitecrush-blue", "bz-blacklevel-red",
    "bz-blacklevel-green", "bz-blacklevel-blue", "bz-whitelevel-red",
    "bz-whitelevel-green", "bz-whitelevel-blue", "xinerama", "active",
    NULL
};

215 216 217 218 219 220 221 222 223
/*****************************************************************************
 * vout_sys_t: Wall video output method descriptor
 *****************************************************************************
 * This structure is part of the video output thread descriptor.
 * It describes the Wall specific properties of an output thread.
 *****************************************************************************/
struct vout_sys_t
{
#ifdef OVERLAP
224 225
    bool   b_autocrop;
    bool   b_attenuate;
226 227 228 229
    unsigned int bz_length, bz_height, bz_begin, bz_middle, bz_end, bz_middle_pos;
    unsigned int i_ratio_max;
    unsigned int i_ratio;
    unsigned int a_0, a_1, a_2;
230
    bool     b_has_changed;
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246
    int lambda[2][VOUT_MAX_PLANES][500];
    int cstYUV[2][VOUT_MAX_PLANES][500];
    int lambda2[2][VOUT_MAX_PLANES][500];
    int cstYUV2[2][VOUT_MAX_PLANES][500];
    unsigned int i_halfLength;
    unsigned int i_halfHeight;
    int i_offset_x;
    int i_offset_y;
#ifdef GAMMA
    float        f_gamma_red, f_gamma_green, f_gamma_blue;
    float         f_gamma[VOUT_MAX_PLANES];
    uint8_t         LUT[VOUT_MAX_PLANES][ACCURACY + 1][256];
#ifdef PACKED_YUV
    uint8_t         LUT2[VOUT_MAX_PLANES][256][500];
#endif
#endif
247
#ifndef WIN32
248
    bool   b_xinerama;
249 250 251 252 253 254 255
#endif
#endif
    int    i_col;
    int    i_row;
    int    i_vout;
    struct vout_list_t
    {
256
        bool b_active;
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352
        int i_width;
        int i_height;
        vout_thread_t *p_vout;
    } *pp_vout;
};



/*****************************************************************************
 * Control: control facility for the vout (forwards to child vout)
 *****************************************************************************/
static int Control( vout_thread_t *p_vout, int i_query, va_list args )
{
    int i_row, i_col, i_vout = 0;

    for( i_row = 0; i_row < p_vout->p_sys->i_row; i_row++ )
    {
        for( i_col = 0; i_col < p_vout->p_sys->i_col; i_col++ )
        {
            vout_vaControl( p_vout->p_sys->pp_vout[ i_vout ].p_vout,
                            i_query, args );
            i_vout++;
        }
    }
    return VLC_SUCCESS;
}

/*****************************************************************************
 * Create: allocates Wall video thread output method
 *****************************************************************************
 * This function allocates and initializes a Wall vout method.
 *****************************************************************************/
static int Create( vlc_object_t *p_this )
{
    vout_thread_t *p_vout = (vout_thread_t *)p_this;
    char *psz_method, *psz_tmp, *psz_method_tmp;
    int i_vout;

    /* Allocate structure */
    p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
    if( p_vout->p_sys == NULL )
        return VLC_ENOMEM;

    p_vout->pf_init = Init;
    p_vout->pf_end = End;
    p_vout->pf_manage = NULL;
/* Color Format not supported
// Planar Y, packed UV
case VLC_FOURCC('Y','M','G','A'):
// Packed YUV 4:2:2, U:Y:V:Y, interlaced
case VLC_FOURCC('I','U','Y','V'):    // packed by 2
// Packed YUV 2:1:1, Y:U:Y:V
case VLC_FOURCC('Y','2','1','1'):     // packed by 4
// Packed YUV Reverted
case VLC_FOURCC('c','y','u','v'):    // packed by 2
*/
    switch (p_vout->render.i_chroma)
    {
    // planar YUV
        case VLC_FOURCC('I','4','4','4'):
        case VLC_FOURCC('I','4','2','2'):
        case VLC_FOURCC('I','4','2','0'):
        case VLC_FOURCC('Y','V','1','2'):
        case VLC_FOURCC('I','Y','U','V'):
        case VLC_FOURCC('I','4','1','1'):
        case VLC_FOURCC('I','4','1','0'):
        case VLC_FOURCC('Y','V','U','9'):
        case VLC_FOURCC('Y','U','V','A'):
            p_vout->pf_render = RenderPlanarYUV;
            break;
    // packed RGB
        case VLC_FOURCC('R','G','B','2'):    // packed by 1
        case VLC_FOURCC('R','V','1','5'):    // packed by 2
        case VLC_FOURCC('R','V','1','6'):    // packed by 2
        case VLC_FOURCC('R','V','2','4'):    // packed by 3
        case VLC_FOURCC('R','V','3','2'):    // packed by 4
            p_vout->pf_render = RenderPackedRGB;
            break;
#ifdef PACKED_YUV
    // packed YUV
        case VLC_FOURCC('Y','U','Y','2'):    // packed by 2
        case VLC_FOURCC('Y','U','N','V'):    // packed by 2
        case VLC_FOURCC('U','Y','V','Y'):    // packed by 2
        case VLC_FOURCC('U','Y','N','V'):    // packed by 2
        case VLC_FOURCC('Y','4','2','2'):    // packed by 2
            p_vout->pf_render = RenderPackedYUV;
            break;
#endif
        default:
            msg_Err( p_vout, "colorspace not supported by plug-in !!!");
            free( p_vout->p_sys );
            return VLC_ENOMEM;
    }
    p_vout->pf_display = NULL;
    p_vout->pf_control = Control;

353 354 355
    config_ChainParse( p_vout, CFG_PREFIX, ppsz_filter_options,
                       p_vout->p_cfg );

356
    /* Look what method was requested */
357 358
    p_vout->p_sys->i_col = var_CreateGetInteger( p_vout, CFG_PREFIX "cols" );
    p_vout->p_sys->i_row = var_CreateGetInteger( p_vout, CFG_PREFIX "rows" );
359

Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
360
// OS dependent code :  Autodetect number of displays in wall
361
#ifdef WIN32
362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380
    if ((p_vout->p_sys->i_col < 0) || (p_vout->p_sys->i_row < 0) )
    {
        int nbMonitors = GetSystemMetrics(SM_CMONITORS);
        if (nbMonitors == 1)
        {
            nbMonitors = 5; // 1 display => 5x1 simulation
            p_vout->p_sys->i_col = nbMonitors;
            p_vout->p_sys->i_row = 1;
        }
        else
        {
            p_vout->p_sys->i_col = GetSystemMetrics( SM_CXVIRTUALSCREEN ) / GetSystemMetrics( SM_CXSCREEN );
            p_vout->p_sys->i_row = GetSystemMetrics( SM_CYVIRTUALSCREEN ) / GetSystemMetrics( SM_CYSCREEN );
            if (p_vout->p_sys->i_col * p_vout->p_sys->i_row != nbMonitors)
            {
                p_vout->p_sys->i_col = nbMonitors;
                p_vout->p_sys->i_row = 1;
            }
        }
381 382
        var_SetInteger( p_vout, CFG_PREFIX "cols", p_vout->p_sys->i_col);
        var_SetInteger( p_vout, CFG_PREFIX "rows", p_vout->p_sys->i_row);
383 384 385 386
    }
#endif

#ifdef OVERLAP
Laurent Aimar's avatar
Laurent Aimar committed
387
    p_vout->p_sys->i_offset_x = var_CreateGetBool( p_vout, CFG_PREFIX "offset-x" );
388
    if (p_vout->p_sys->i_col > 2) p_vout->p_sys->i_offset_x = 0; // offset-x is used in case of 2x1 wall & autocrop
389
    p_vout->p_sys->b_autocrop = !(var_CreateGetInteger( p_vout, "crop-ratio" ) == 0);
390
    if (!p_vout->p_sys->b_autocrop) p_vout->p_sys->b_autocrop = var_CreateGetInteger( p_vout, "autocrop" );
Laurent Aimar's avatar
Laurent Aimar committed
391
    p_vout->p_sys->b_attenuate = var_CreateGetBool( p_vout, CFG_PREFIX "attenuate");
392
    p_vout->p_sys->bz_length = var_CreateGetInteger( p_vout, CFG_PREFIX "bz-length" );
393
    if (p_vout->p_sys->i_row > 1)
394
        p_vout->p_sys->bz_height = var_CreateGetInteger( p_vout, CFG_PREFIX "bz-height" );
395 396
    else
        p_vout->p_sys->bz_height = 100;
397 398 399 400
    p_vout->p_sys->bz_begin = var_CreateGetInteger( p_vout, CFG_PREFIX "bz-begin" );
    p_vout->p_sys->bz_middle = var_CreateGetInteger( p_vout, CFG_PREFIX "bz-middle" );
    p_vout->p_sys->bz_end = var_CreateGetInteger( p_vout, CFG_PREFIX "bz-end" );
    p_vout->p_sys->bz_middle_pos = var_CreateGetInteger( p_vout, CFG_PREFIX "bz-middle-pos" );
401
    double d_p = 100.0 / p_vout->p_sys->bz_middle_pos;
402
    p_vout->p_sys->i_ratio_max = var_CreateGetInteger( p_vout, "autocrop-ratio-max" ); // in crop module with autocrop ...
403
    p_vout->p_sys->i_ratio = var_CreateGetInteger( p_vout, "crop-ratio" ); // in crop module with manual ratio ...
404

405 406 407 408 409
    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;
    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;
    p_vout->p_sys->a_0 =  p_vout->p_sys->bz_begin;

#ifdef GAMMA
410 411 412
    p_vout->p_sys->f_gamma_red = var_CreateGetFloat( p_vout, CFG_PREFIX "bz-gamma-red" );
    p_vout->p_sys->f_gamma_green = var_CreateGetFloat( p_vout, CFG_PREFIX "bz-gamma-green" );
    p_vout->p_sys->f_gamma_blue = var_CreateGetFloat( p_vout, CFG_PREFIX "bz-gamma-blue" );
413
#endif
414
#ifndef WIN32
Laurent Aimar's avatar
Laurent Aimar committed
415
    p_vout->p_sys->b_xinerama = var_CreateGetBool( p_vout, CFG_PREFIX "xinerama" );
416 417 418 419 420 421 422 423 424
#endif
#else
    p_vout->p_sys->i_col = __MAX( 1, __MIN( 15, p_vout->p_sys->i_col ) );
    p_vout->p_sys->i_row = __MAX( 1, __MIN( 15, p_vout->p_sys->i_row ) );
#endif

    msg_Dbg( p_vout, "opening a %i x %i wall",
             p_vout->p_sys->i_col, p_vout->p_sys->i_row );

425 426
    p_vout->p_sys->pp_vout = calloc( p_vout->p_sys->i_row *
                                     p_vout->p_sys->i_col,
427 428 429 430 431 432 433
                                     sizeof(struct vout_list_t) );
    if( p_vout->p_sys->pp_vout == NULL )
    {
        free( p_vout->p_sys );
        return VLC_ENOMEM;
    }

434 435
    psz_method_tmp =
    psz_method = var_CreateGetNonEmptyString( p_vout, CFG_PREFIX "active" );
436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489

    /* If no trailing vout are specified, take them all */
    if( psz_method == NULL )
    {
        for( i_vout = p_vout->p_sys->i_row * p_vout->p_sys->i_col;
             i_vout--; )
        {
            p_vout->p_sys->pp_vout[i_vout].b_active = 1;
        }
    }
    /* If trailing vout are specified, activate only the requested ones */
    else
    {
        for( i_vout = p_vout->p_sys->i_row * p_vout->p_sys->i_col;
             i_vout--; )
        {
            p_vout->p_sys->pp_vout[i_vout].b_active = 0;
        }

        while( *psz_method )
        {
            psz_tmp = psz_method;
            while( *psz_tmp && *psz_tmp != ',' )
            {
                psz_tmp++;
            }

            if( *psz_tmp )
            {
                *psz_tmp = '\0';
                i_vout = atoi( psz_method );
                psz_method = psz_tmp + 1;
            }
            else
            {
                i_vout = atoi( psz_method );
                psz_method = psz_tmp;
            }

            if( i_vout >= 0 &&
                i_vout < p_vout->p_sys->i_row * p_vout->p_sys->i_col )
            {
                p_vout->p_sys->pp_vout[i_vout].b_active = 1;
            }
        }
    }

    free( psz_method_tmp );

    return VLC_SUCCESS;
}


#ifdef OVERLAP
490 491 492 493 494 495 496 497 498
/*****************************************************************************
 * CLIP_0A: clip between 0 and ACCURACY
 *****************************************************************************/
inline static int CLIP_0A( int a )
{
    return (a > ACCURACY) ? ACCURACY : (a < 0) ? 0 : a;
}

#ifdef GAMMA
499 500 501
/*****************************************************************************
 *  Gamma: Gamma correction
 *****************************************************************************/
502
static double Gamma_Correction(int i_plane, float f_component, float f_BlackCrush[VOUT_MAX_PLANES], float f_WhiteCrush[VOUT_MAX_PLANES], float f_BlackLevel[VOUT_MAX_PLANES], float f_WhiteLevel[VOUT_MAX_PLANES], float f_Gamma[VOUT_MAX_PLANES])
503 504 505 506 507
{
    float f_Input;

    f_Input = (f_component * f_BlackLevel[i_plane]) / (f_BlackCrush[i_plane]) + (1.0 - f_BlackLevel[i_plane]);
    if (f_component <= f_BlackCrush[i_plane])
508 509 510
    {
        return pow(f_Input, 1.0 / f_Gamma[i_plane]);
    }
511 512 513 514 515
    else if (f_component >= f_WhiteCrush[i_plane])
    {
        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);
        return pow(f_Input, 1.0 / f_Gamma[i_plane]);
    }
516 517 518 519
    else
    {
        return 1.0;
    }
520 521 522 523 524 525 526 527 528
}

#ifdef PACKED_YUV

/*****************************************************************************
 * F: Function to calculate Gamma correction
 *****************************************************************************/
static uint8_t F(uint8_t i, float gamma)
{
529
    double input = (double) i / 255.0;
530

531
    // return clip(255 * pow(input, 1.0 / gamma));
532

533 534 535 536
    if (input < 0.5)
        return clip_uint8((255 * pow(2 * input, gamma)) / 2);
    else
        return clip_uint8(255 * (1 - pow(2 * (1 - input), gamma) / 2));
537 538 539 540 541 542 543 544 545
}
#endif
#endif

/*****************************************************************************
 * AdjustHeight: ajust p_sys->i_height to have same BZ width for any ratio
 *****************************************************************************/
static int AdjustHeight( vout_thread_t *p_vout )
{
Laurent Aimar's avatar
Laurent Aimar committed
546
    bool b_fullscreen = p_vout->b_fullscreen;
547 548 549 550 551 552 553
    int i_window_width = p_vout->i_window_width;
    int i_window_height = p_vout->i_window_height;
    double d_halfLength = 0;
    double d_halfLength_crop;
    double d_halfLength_calculated;
    int    i_offset = 0;

Laurent Aimar's avatar
Laurent Aimar committed
554 555 556
    // OS DEPENDENT CODE to get display dimensions
    if (b_fullscreen )
    {
557
#ifdef WIN32
Laurent Aimar's avatar
Laurent Aimar committed
558 559
        i_window_width  = GetSystemMetrics(SM_CXSCREEN);
        i_window_height = GetSystemMetrics(SM_CYSCREEN);
560
#else
561 562 563 564
        char *psz_display = var_CreateGetNonEmptyString( p_vout,
                                                        "x11-display" );
        Display *p_display = XOpenDisplay( psz_display );
        free( psz_display );
Laurent Aimar's avatar
Laurent Aimar committed
565 566 567 568 569 570 571 572 573 574 575
        if (p_vout->p_sys->b_xinerama)
        {
            i_window_width = DisplayWidth(p_display, 0) / p_vout->p_sys->i_col;
            i_window_height = DisplayHeight(p_display, 0) / p_vout->p_sys->i_row;
        }
        else
        {
            i_window_width = DisplayWidth(p_display, 0);
            i_window_height = DisplayHeight(p_display, 0);
        }
        XCloseDisplay( p_display );
576 577 578 579
#endif
        var_SetInteger( p_vout, "width", i_window_width);
        var_SetInteger( p_vout, "height", i_window_height);
        p_vout->i_window_width = i_window_width;
Laurent Aimar's avatar
Laurent Aimar committed
580 581
        p_vout->i_window_height = i_window_height;
    }
582

Laurent Aimar's avatar
Laurent Aimar committed
583
    if( p_vout->p_sys->bz_length)
584 585 586 587
        if ((!p_vout->p_sys->b_autocrop) && (!p_vout->p_sys->i_ratio))
        {
            if ((p_vout->p_sys->i_row > 1) || (p_vout->p_sys->i_col > 1))
            {
588
                while ((d_halfLength <= 0) || (d_halfLength > p_vout->render.i_width / (2 * p_vout->p_sys->i_col)))
589
                {
590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605
                    if (p_vout->p_sys->bz_length >= 50)
                    {
                        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);
                    }
                    else
                    {
                        d_halfLength = (p_vout->render.i_width * p_vout->p_sys->bz_length) / (100.0 * p_vout->p_sys->i_col);
                        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);
                    }
                    if ((d_halfLength <= 0) || (d_halfLength > p_vout->render.i_width / (2 * p_vout->p_sys->i_col)))
                        p_vout->p_sys->i_row--;
                    if (p_vout->p_sys->i_row < 1 )
                    {
                        p_vout->p_sys->i_row = 1;
                        break;
                    }
606
                }
607 608 609 610 611
                p_vout->p_sys->i_halfLength = (d_halfLength + 0.5);
                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;
                var_SetInteger( p_vout, "bz-length", p_vout->p_sys->bz_length);
                var_SetInteger( p_vout, "panoramix-rows", p_vout->p_sys->i_row);
            }
612 613 614 615 616 617 618 619 620 621 622 623 624 625 626
        }
        else
        {
            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;
            d_halfLength_crop = d_halfLength * VOUT_ASPECT_FACTOR * (double)p_vout->output.i_width
                        / (double)i_window_height / (double)p_vout->render.i_aspect;
            p_vout->p_sys->i_halfLength = (d_halfLength_crop + 0.5);
            d_halfLength_calculated = p_vout->p_sys->i_halfLength * (double)i_window_height *
                                (double)p_vout->render.i_aspect  /     VOUT_ASPECT_FACTOR / (double)p_vout->output.i_width;

            if (!p_vout->p_sys->b_attenuate)
            {
                double d_bz_length = (p_vout->p_sys->i_halfLength * p_vout->p_sys->i_col * 100.0) / p_vout->render.i_width;
                // F(2x) != 2F(x) in opengl module
                if (p_vout->p_sys->i_col == 2) d_bz_length = (100.0 * d_bz_length) / (100.0 - d_bz_length) ;
627
                var_SetInteger( p_vout, "bz-length", (int)(d_bz_length + 0.5));
628 629 630 631 632
            }
            i_offset =  (int)d_halfLength - (int)
                        (p_vout->p_sys->i_halfLength * (double)i_window_height *
                        (double)p_vout->render.i_aspect  /     VOUT_ASPECT_FACTOR / (double)p_vout->output.i_width);
        }
Laurent Aimar's avatar
Laurent Aimar committed
633
    else
634
        p_vout->p_sys->i_halfLength = 0;
635

Laurent Aimar's avatar
Laurent Aimar committed
636
    return i_offset;
637 638 639 640 641 642 643
}
#endif


/*****************************************************************************
 * Init: initialize Wall video thread output method
 *****************************************************************************/
Laurent Aimar's avatar
Laurent Aimar committed
644 645
#define VLC_XCHG( type, a, b ) do { type __tmp = (b); (b) = (a); (a) = __tmp; } while(0)

646 647
static int Init( vout_thread_t *p_vout )
{
648
    int i_index, i_row, i_col;
649 650 651 652 653 654 655 656 657 658 659
    picture_t *p_pic;

    I_OUTPUTPICTURES = 0;

    /* Initialize the output structure */
    p_vout->output.i_chroma = p_vout->render.i_chroma;
    p_vout->output.i_width  = p_vout->render.i_width;
    p_vout->output.i_height = p_vout->render.i_height;
    p_vout->output.i_aspect = p_vout->render.i_aspect;
#ifdef OVERLAP
    p_vout->p_sys->b_has_changed = p_vout->p_sys->b_attenuate;
660
    int i_video_x = var_GetInteger( p_vout, "video-x");
661
    int i_video_y = var_GetInteger( p_vout, "video-y");
662 663 664 665 666 667 668 669 670
#ifdef GAMMA
    if (p_vout->p_sys->b_attenuate)
    {
        int i_index2, i_plane;
        int constantYUV[3] = {0,128,128};
        float    f_BlackCrush[VOUT_MAX_PLANES];
        float    f_BlackLevel[VOUT_MAX_PLANES];
        float    f_WhiteCrush[VOUT_MAX_PLANES];
        float    f_WhiteLevel[VOUT_MAX_PLANES];
671 672 673 674 675 676 677 678 679 680 681 682 683 684 685
        p_vout->p_sys->f_gamma[0] = var_CreateGetFloat( p_vout, CFG_PREFIX "bz-gamma-red" );
        p_vout->p_sys->f_gamma[1] = var_CreateGetFloat( p_vout, CFG_PREFIX "bz-gamma-green" );
        p_vout->p_sys->f_gamma[2] = var_CreateGetFloat( p_vout, CFG_PREFIX "bz-gamma-blue" );
        f_BlackCrush[0] = var_CreateGetInteger( p_vout, CFG_PREFIX "bz-blackcrush-red" ) / 255.0;
        f_BlackCrush[1] = var_CreateGetInteger( p_vout, CFG_PREFIX "bz-blackcrush-green" ) / 255.0;
        f_BlackCrush[2] = var_CreateGetInteger( p_vout, CFG_PREFIX "bz-blackcrush-blue" ) / 255.0;
        f_WhiteCrush[0] = var_CreateGetInteger( p_vout, CFG_PREFIX "bz-whitecrush-red" ) / 255.0;
        f_WhiteCrush[1] = var_CreateGetInteger( p_vout, CFG_PREFIX "bz-whitecrush-green" ) / 255.0;
        f_WhiteCrush[2] = var_CreateGetInteger( p_vout, CFG_PREFIX "bz-whitecrush-blue" ) / 255.0;
        f_BlackLevel[0] = var_CreateGetInteger( p_vout, CFG_PREFIX "bz-blacklevel-red" ) / 255.0;
        f_BlackLevel[1] = var_CreateGetInteger( p_vout, CFG_PREFIX "bz-blacklevel-green" ) / 255.0;
        f_BlackLevel[2] = var_CreateGetInteger( p_vout, CFG_PREFIX "bz-blacklevel-blue" ) / 255.0;
        f_WhiteLevel[0] = var_CreateGetInteger( p_vout, CFG_PREFIX "bz-whitelevel-red" ) / 255.0;
        f_WhiteLevel[1] = var_CreateGetInteger( p_vout, CFG_PREFIX "bz-whitelevel-green" ) / 255.0;
        f_WhiteLevel[2] = var_CreateGetInteger( p_vout, CFG_PREFIX "bz-whitelevel-blue" ) / 255.0;
Laurent Aimar's avatar
Laurent Aimar committed
686 687 688 689 690 691 692 693 694 695
        for( int i = 3; i < VOUT_MAX_PLANES; i++ )
        {
            /* Initialize unsupported planes */
            f_BlackCrush[i] = 140.0/255.0;
            f_WhiteCrush[i] = 200.0/255.0;
            f_BlackLevel[i] = 150.0/255.0;
            f_WhiteLevel[i] = 0.0/255.0;
            p_vout->p_sys->f_gamma[i] = 1.0;
        }

696 697 698 699 700 701 702 703 704 705
        switch (p_vout->render.i_chroma)
        {
        // planar YVU
            case VLC_FOURCC('Y','V','1','2'):
            case VLC_FOURCC('Y','V','U','9'):
        // packed UYV
            case VLC_FOURCC('U','Y','V','Y'):    // packed by 2
            case VLC_FOURCC('U','Y','N','V'):    // packed by 2
            case VLC_FOURCC('Y','4','2','2'):    // packed by 2
    //        case VLC_FOURCC('c','y','u','v'):    // packed by 2
Laurent Aimar's avatar
Laurent Aimar committed
706 707 708 709 710
                VLC_XCHG( float, p_vout->p_sys->f_gamma[1], p_vout->p_sys->f_gamma[2] );
                VLC_XCHG( float, f_BlackCrush[1], f_BlackCrush[2] );
                VLC_XCHG( float, f_WhiteCrush[1], f_WhiteCrush[2] );
                VLC_XCHG( float, f_BlackLevel[1], f_BlackLevel[2] );
                VLC_XCHG( float, f_WhiteLevel[1], f_WhiteLevel[2] );
711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760
        // planar YUV
            case VLC_FOURCC('I','4','4','4'):
            case VLC_FOURCC('I','4','2','2'):
            case VLC_FOURCC('I','4','2','0'):
            case VLC_FOURCC('I','4','1','1'):
            case VLC_FOURCC('I','4','1','0'):
            case VLC_FOURCC('I','Y','U','V'):
            case VLC_FOURCC('Y','U','V','A'):
        // packed YUV
            case VLC_FOURCC('Y','U','Y','2'):    // packed by 2
            case VLC_FOURCC('Y','U','N','V'):    // packed by 2
                for (i_index = 0; i_index < 256; i_index++)
                    for (i_index2 = 0; i_index2 <= ACCURACY; i_index2++)
                        for (i_plane = 0; i_plane < VOUT_MAX_PLANES; i_plane++)
                        {
                            float f_lut = CLIP_01(1.0 -
                                     ((ACCURACY - (float)i_index2)
                                     * Gamma_Correction(i_plane, (float)i_index / 255.0, f_BlackCrush, f_WhiteCrush, f_BlackLevel, f_WhiteLevel, p_vout->p_sys->f_gamma)
                                     / (ACCURACY - 1)));
                            p_vout->p_sys->LUT[i_plane][i_index2][i_index] = f_lut * i_index + (int)((1.0 - f_lut) * (float)constantYUV[i_plane]);
                        }
                break;
        // packed RGB
            case VLC_FOURCC('R','G','B','2'):    // packed by 1
            case VLC_FOURCC('R','V','1','5'):    // packed by 2
            case VLC_FOURCC('R','V','1','6'):    // packed by 2
            case VLC_FOURCC('R','V','2','4'):    // packed by 3
            case VLC_FOURCC('R','V','3','2'):    // packed by 4
            for (i_index = 0; i_index < 256; i_index++)
                    for (i_index2 = 0; i_index2 <= ACCURACY; i_index2++)
                        for (i_plane = 0; i_plane < VOUT_MAX_PLANES; i_plane++)
                        {
                            float f_lut = CLIP_01(1.0 -
                                     ((ACCURACY - (float)i_index2)
                                     * Gamma_Correction(i_plane, (float)i_index / 255.0, f_BlackCrush, f_WhiteCrush, f_BlackLevel, f_WhiteLevel, p_vout->p_sys->f_gamma)
                                     / (ACCURACY - 1)));
                            p_vout->p_sys->LUT[i_plane][i_index2][i_index] = f_lut * i_index;
                        }
                break;
            default:
                msg_Err( p_vout, "colorspace not supported by plug-in !!!");
                free( p_vout->p_sys );
                return VLC_ENOMEM;
        }
    }
#endif
    if (p_vout->p_sys->i_offset_x)
        p_vout->p_sys->i_offset_x = AdjustHeight(p_vout);
    else
        AdjustHeight(p_vout);
761 762 763 764 765
    if (p_vout->p_sys->i_row >= 2)
    {
        p_vout->p_sys->i_halfHeight = (p_vout->p_sys->i_halfLength * p_vout->p_sys->bz_height) / 100;
        p_vout->p_sys->i_halfHeight -= (p_vout->p_sys->i_halfHeight % 2);
    }
766 767 768 769 770 771
#endif

    /* Try to open the real video output */
    msg_Dbg( p_vout, "spawning the real video outputs" );

    /* FIXME: use bresenham instead of those ugly divisions */
772
    p_vout->p_sys->i_vout = 0;
773 774
    for( i_row = 0; i_row < p_vout->p_sys->i_row; i_row++ )
    {
775
        for( i_col = 0; i_col < p_vout->p_sys->i_col; i_col++, p_vout->p_sys->i_vout++ )
776
        {
777
            struct vout_list_t *p_entry = &p_vout->p_sys->pp_vout[ p_vout->p_sys->i_vout ];
778
            video_format_t fmt;
779
            int i_width, i_height;
780

781 782 783 784
            /* */
            i_width = ( p_vout->render.i_width / p_vout->p_sys->i_col ) & ~0x1;
            if( i_col + 1 == p_vout->p_sys->i_col )
                i_width = p_vout->render.i_width - i_col * i_width;
785 786 787

#ifdef OVERLAP
            i_width += p_vout->p_sys->i_halfLength;
788 789 790
            if (p_vout->p_sys->i_col > 2 )
                i_width += p_vout->p_sys->i_halfLength;
            i_width &= ~0x1;
791 792
#endif

793 794 795 796
            /* */
            i_height = ( p_vout->render.i_height / p_vout->p_sys->i_row ) & ~0x3;
            if( i_row + 1 == p_vout->p_sys->i_row )
                i_height = p_vout->render.i_height - i_row * i_height;
797
#ifdef OVERLAP
798
            if(p_vout->p_sys->i_row >= 2 )
799 800
            {
                i_height += p_vout->p_sys->i_halfHeight;
801 802
                if( p_vout->p_sys->i_row > 2 )
                    i_height += p_vout->p_sys->i_halfHeight;
803
            }
804
            i_height &= ~0x1;
805
#endif
806 807
            p_entry->i_width = i_width;
            p_entry->i_height = i_height;
808

809
            if( !p_entry->b_active )
810 811
                continue;

812 813
            /* */
            memset( &fmt, 0, sizeof(video_format_t) );
814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832
            fmt.i_width = fmt.i_visible_width = p_vout->render.i_width;
            fmt.i_height = fmt.i_visible_height = p_vout->render.i_height;
            fmt.i_x_offset = fmt.i_y_offset = 0;
            fmt.i_chroma = p_vout->render.i_chroma;
            fmt.i_aspect = p_vout->render.i_aspect;
            fmt.i_sar_num = p_vout->render.i_aspect * fmt.i_height / fmt.i_width;
            fmt.i_sar_den = VOUT_ASPECT_FACTOR;
            fmt.i_width = fmt.i_visible_width = i_width;
            fmt.i_height = fmt.i_visible_height = i_height;
            fmt.i_aspect = p_vout->render.i_aspect
                              * p_vout->render.i_height / i_height
                              * i_width / p_vout->render.i_width;
#ifdef OVERLAP
            if (p_vout->p_sys->i_offset_x < 0)
            {
                var_SetInteger(p_vout, "video-x", -p_vout->p_sys->i_offset_x);
                p_vout->p_sys->i_offset_x = 0;
            }
#endif
833
            p_entry->p_vout = vout_Create( p_vout, &fmt);
834

835
            if( p_entry->p_vout == NULL )
836 837 838 839 840 841
            {
                msg_Err( p_vout, "failed to get %ix%i vout threads",
                                 p_vout->p_sys->i_col, p_vout->p_sys->i_row );
                RemoveAllVout( p_vout );
                return VLC_EGENERIC;
            }
842
            ADD_CALLBACKS( p_entry->p_vout, SendEvents );
843
#ifdef OVERLAP
844 845 846 847 848
            p_entry->p_vout->i_alignment = 0;
            if (i_col == 0)
                p_entry->p_vout->i_alignment |= VOUT_ALIGN_RIGHT;
            else if (i_col == p_vout->p_sys->i_col -1)
                p_entry->p_vout->i_alignment |= VOUT_ALIGN_LEFT;
849 850
            if (p_vout->p_sys->i_row > 1)
            {
851 852 853 854 855
                if (i_row == 0)
                    p_entry->p_vout->i_alignment |= VOUT_ALIGN_BOTTOM;
                else if (i_row == p_vout->p_sys->i_row -1)
                    p_entry->p_vout->i_alignment |= VOUT_ALIGN_TOP;
            }
856
            // i_active : number of active pp_vout
857 858 859 860 861
            int i_active = 0;
            for( int i = 0; i <= p_vout->p_sys->i_vout; i++ )
            {
                if( p_vout->p_sys->pp_vout[i].b_active )
                    i_active++;
862
            }
863
            var_SetInteger( p_vout, "align", p_entry->p_vout->i_alignment );
864 865
            var_SetInteger( p_vout, "video-x", i_video_x + p_vout->p_sys->i_offset_x + (i_active % p_vout->p_sys->i_col) * p_vout->i_window_width);
            var_SetInteger( p_vout, "video-y", i_video_y +                             (i_active / p_vout->p_sys->i_col) * p_vout->i_window_height);
866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883
#endif
        }
    }

    ALLOCATE_DIRECTBUFFERS( VOUT_MAX_PICTURES );

    ADD_PARENT_CALLBACKS( SendEventsToChild );

    return VLC_SUCCESS;
}

/*****************************************************************************
 * End: terminate Wall video thread output method
 *****************************************************************************/
static void End( vout_thread_t *p_vout )
{
    int i_index;

884 885
    DEL_PARENT_CALLBACKS( SendEventsToChild );

886 887 888 889 890 891
    /* Free the fake output buffers we allocated */
    for( i_index = I_OUTPUTPICTURES ; i_index ; )
    {
        i_index--;
        free( PP_OUTPUTPICTURE[ i_index ]->p_data_orig );
    }
892 893 894 895 896 897

    RemoveAllVout( p_vout );

#ifdef OVERLAP
    var_SetInteger( p_vout, "bz-length", p_vout->p_sys->bz_length);
#endif
898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926
}

/*****************************************************************************
 * Destroy: destroy Wall video thread output method
 *****************************************************************************
 * Terminate an output method created by WallCreateOutputMethod
 *****************************************************************************/
static void Destroy( vlc_object_t *p_this )
{
    vout_thread_t *p_vout = (vout_thread_t *)p_this;

    free( p_vout->p_sys->pp_vout );
    free( p_vout->p_sys );

}

/*****************************************************************************
 * RenderPlanarYUV: displays previously rendered output
 *****************************************************************************
 * This function send the currently rendered image to Wall image, waits
 * until it is displayed and switch the two rendering buffers, preparing next
 * frame.
 *****************************************************************************/
static void RenderPlanarYUV( vout_thread_t *p_vout, picture_t *p_pic )
{
    picture_t *p_outpic = NULL;
    int i_col, i_row, i_vout, i_plane;
    int pi_left_skip[VOUT_MAX_PLANES], pi_top_skip[VOUT_MAX_PLANES];
#ifdef OVERLAP
927
    int TopOffset;
928 929 930 931 932 933 934 935 936 937 938
    int constantYUV[3] = {0,128,128};
    int Denom;
    int a_2;
    int a_1;
    int a_0;
    int i_index, i_index2;
#endif

    for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ )
        pi_top_skip[i_plane] = 0;

939
    for( i_vout = 0, i_row = 0; i_row < p_vout->p_sys->i_row; i_row++ )
940 941 942 943
    {
        for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ )
            pi_left_skip[i_plane] = 0;

944
        for( i_col = 0; i_col < p_vout->p_sys->i_col; i_col++, i_vout++ )
945
        {
946 947
            struct vout_list_t *p_entry = &p_vout->p_sys->pp_vout[ i_vout ];
            if( !p_entry->b_active )
948 949 950
            {
                for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ )
                {
951
                    pi_left_skip[i_plane] += p_entry->i_width * p_pic->p[i_plane].i_pitch / p_vout->output.i_width;
952 953 954 955
                }
                continue;
            }

956
            while( ( p_outpic = vout_CreatePicture( p_entry->p_vout, 0, 0, 0 )) == NULL )
957
            {
958
                if( !vlc_object_alive(p_vout) || p_vout->b_error )
959
                {
960
                    vout_DestroyPicture( p_entry->p_vout, p_outpic );
961 962 963 964 965
                    return;
                }
                msleep( VOUT_OUTMEM_SLEEP );
            }

966
            p_outpic->date = p_pic->date;
967
            vout_LinkPicture( p_entry->p_vout, p_outpic );
968 969 970 971 972 973 974 975

            for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ )
            {
                uint8_t *p_in, *p_in_end, *p_out;
                int i_in_pitch = p_pic->p[i_plane].i_pitch;
                int i_out_pitch = p_outpic->p[i_plane].i_pitch;
                int i_copy_pitch = p_outpic->p[i_plane].i_visible_pitch;
                int i_lines = p_outpic->p[i_plane].i_visible_lines;
976 977 978 979 980 981
                const int i_div = p_entry->i_width / i_copy_pitch;

                const bool b_row_first = i_row == 0;
                const bool b_row_last = i_row + 1 == p_vout->p_sys->i_row;
                const bool b_col_first = i_col == 0;
                const bool b_col_last = i_col + 1 == p_vout->p_sys->i_col;
Laurent Aimar's avatar
Laurent Aimar committed
982

983
#ifdef OVERLAP
984 985 986 987 988 989 990 991 992 993 994 995
                if( !b_col_first )
                    pi_left_skip[i_plane] -= (2 * p_vout->p_sys->i_halfLength ) / i_div;

                if( p_vout->p_sys->i_row >= 2 )
                {
                    if( !b_row_first && b_col_first )
                        pi_top_skip[i_plane] -= (2 * p_vout->p_sys->i_halfHeight * p_pic->p[i_plane].i_pitch) / i_div;
                    if( p_vout->p_sys->i_row > 2 && i_row == 1 && b_col_first )
                        pi_top_skip[i_plane] -= (2 * p_vout->p_sys->i_halfHeight * p_pic->p[i_plane].i_pitch) / i_div;
                    if( !p_vout->p_sys->pp_vout[p_vout->p_sys->i_col-1].b_active )
                        pi_top_skip[i_plane] -= (2 * p_vout->p_sys->i_halfHeight * i_row * p_pic->p[i_plane].i_pitch) / i_div;
                }
996 997
// i_n : previous inactive pp_vout
                int i_n=0;
Laurent Aimar's avatar
Laurent Aimar committed
998
                while( (i_col - i_n > 1) && (!p_vout->p_sys->pp_vout[i_row * p_vout->p_sys->i_col + i_col - 1 - i_n].b_active) ) i_n++;
999 1000
                if( i_col > 1 && i_n )
                    pi_left_skip[i_plane] -= i_n * (2 * p_vout->p_sys->i_halfLength ) / i_div;
1001 1002


1003 1004
                if( p_vout->p_sys->i_row > 2 && ( b_row_first || b_row_last ) )
                    i_lines -= (2 * p_vout->p_sys->i_halfHeight) / i_div;
1005 1006

// 1088 lines bug in a mpeg2 stream of 1080 lines
1007 1008
                if( b_row_last && p_pic->p[i_plane].i_lines == 1088 )
                    i_lines -= 8 / i_div;
1009
#endif
1010 1011 1012 1013
                /* */
                p_in = &p_pic->p[i_plane].p_pixels[ pi_top_skip[i_plane] + pi_left_skip[i_plane] ]; /* Wall proprities */
                p_in_end = &p_in[i_lines * p_pic->p[i_plane].i_pitch];

1014 1015
                p_out = p_outpic->p[i_plane].p_pixels;
#ifdef OVERLAP
1016 1017
                if( p_vout->p_sys->i_row > 2 && b_row_first )
                    p_out += p_outpic->p[i_plane].i_pitch * (2 * p_vout->p_sys->i_halfHeight) / i_div;
1018

1019 1020
                int i_col_mod;
                int length = 2 * p_vout->p_sys->i_halfLength / i_div;
1021

1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036
                if( p_vout->p_sys->b_has_changed )
                {
                    Denom = F2(length);
                    a_2 = p_vout->p_sys->a_2 * (ACCURACY / 100);
                    a_1 = p_vout->p_sys->a_1 * length * (ACCURACY / 100);
                    a_0 = p_vout->p_sys->a_0 * Denom * (ACCURACY / 100);
                    for( i_col_mod = 0; i_col_mod < 2; i_col_mod++ )
                    {
                        for( i_index = 0; i_index < length; i_index++ )
                        {
                            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);
                            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;
                        }
                    }
                }
1037
#endif
1038 1039
                while( p_in < p_in_end )
                {
1040
#ifndef OVERLAP
1041
                    vlc_memcpy( p_out, p_in, i_copy_pitch);
1042
#else
1043 1044 1045
                    if( p_vout->p_sys->i_col > 2 )
                    {
                        const int halfl = length / 2;
1046
                        if( b_col_first)
1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058
                            vlc_memcpy( &p_out[halfl], &p_in[0], i_copy_pitch - halfl );
                        else if( b_col_last )
                            vlc_memcpy( &p_out[    0], &p_in[-halfl], i_copy_pitch - halfl );
                        else
                            vlc_memcpy( &p_out[    0], &p_in[-halfl], i_copy_pitch);

                        // black bar
                        if( b_col_first )
                            memset( &p_out[0], constantYUV[i_plane], halfl);
                        else if( b_col_last )
                            memset( &p_out[i_copy_pitch - halfl], constantYUV[i_plane], halfl );
                    }
1059
                    else
1060
                    {
1061
                        vlc_memcpy( p_out , p_in, i_copy_pitch );
1062 1063
                    }

1064
                    if( p_vout->p_sys->b_attenuate )
1065
                    {
1066 1067 1068 1069 1070 1071 1072
                        // vertical blend
                        // first blended zone
                        if( !b_col_first )
                        {
                            uint8_t *p_dst = &p_out[0];
                            for (i_index = 0; i_index < length; i_index++)
                            {
1073
#ifndef GAMMA
1074 1075
                                p_dst[i_index] = (p_vout->p_sys->lambda[1][i_plane][i_index] * p_dst[i_index]) / ACCURACY +
                                                        p_vout->p_sys->cstYUV[1][i_plane][i_index];
1076
#else
1077
                                p_dst[i_index] = p_vout->p_sys->LUT[i_plane][p_vout->p_sys->lambda[1][i_plane][i_index]][p_dst[i_index]];
1078
#endif
1079 1080 1081 1082 1083 1084 1085 1086
                            }
                        }
                        // second blended zone
                        if( !b_col_last )
                        {
                            uint8_t *p_dst = &p_out[i_copy_pitch - length];
                            for (i_index = 0; i_index < length; i_index++)
                            {
1087
#ifndef GAMMA
1088 1089
                                p_dst[i_index] = (p_vout->p_sys->lambda[0][i_plane][i_index] * p_dst[i_index]) / ACCURACY +
                                                        p_vout->p_sys->cstYUV[0][i_plane][i_index];
1090
#else
1091
                               p_dst[i_index] = p_vout->p_sys->LUT[i_plane][p_vout->p_sys->lambda[0][i_plane][i_index]][p_dst[i_index]];
1092
#endif
1093 1094 1095
                            }
                        }
                        // end blended zone
1096 1097
                    }
#endif
1098 1099
                    p_in += i_in_pitch;
                    p_out += i_out_pitch;
1100
                }
1101
#ifdef OVERLAP
1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114
       // horizontal blend
        if ( p_vout->p_sys->i_row >= 2 )
        {
           // black bar
           if (( p_vout->p_sys->i_row > 2 ) && (( b_row_first ) || ( b_row_last )))
           {

               int height = 2 * p_vout->p_sys->i_halfHeight / i_div;
               if ( b_row_first )
               {
                    TopOffset = i_lines + (2 * p_vout->p_sys->i_halfHeight) / i_div;
               }
               else
1115
                {
1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141
                   TopOffset = height - (2 * p_vout->p_sys->i_halfHeight) / i_div;
                }
                uint8_t *p_dst = p_out - TopOffset * i_out_pitch;
                for (i_index = 0; i_index < height; i_index++)
                   for (i_index2 = 0; i_index2 < i_copy_pitch; i_index2++)
                       p_dst[i_index * i_out_pitch + i_index2] = constantYUV[i_plane];
           }
           if( p_vout->p_sys->b_attenuate )
           {
               length = 2 * p_vout->p_sys->i_halfHeight / (p_vout->p_sys->pp_vout[i_vout].i_width / i_copy_pitch);
               if (p_vout->p_sys->b_has_changed)
               {
                   Denom = F2(length);
                   a_2 = p_vout->p_sys->a_2 * (ACCURACY / 100);
                   a_1 = p_vout->p_sys->a_1 * length * (ACCURACY / 100);
                   a_0 = p_vout->p_sys->a_0 * Denom * (ACCURACY / 100);
                   for(i_col_mod = 0; i_col_mod < 2; i_col_mod++)
                       for (i_index = 0; i_index < length; i_index++)
                       {
                           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);
                           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;
                       }
               }
               // first blended zone
               if ( !b_row_first )
               {
1142 1143 1144 1145 1146 1147 1148
                        TopOffset = i_lines;
                        uint8_t *p_dst = p_out - TopOffset * i_out_pitch;

                        for (i_index = 0; i_index < length; i_index++)
                        {
                            for (i_index2 = 0; i_index2 < i_copy_pitch; i_index2++)
                            {
1149
#ifndef GAMMA
1150 1151 1152
                                p_dst[i_index * i_out_pitch + i_index2] = ( p_vout->p_sys->lambda2[1][i_plane][i_index] *
                                             p_dst[i_index * i_out_pitch + i_index2] ) / ACCURACY +
                                             p_vout->p_sys->cstYUV2[1][i_plane][i_index];
1153
#else
1154
                                p_dst[i_index * i_out_pitch + i_index2] = p_vout->p_sys->LUT[i_plane][p_vout->p_sys->lambda2[1][i_plane][i_index]][p_dst[i_index * i_out_pitch + i_index2]];
1155
#endif
1156 1157
                            }
                        }
1158 1159 1160 1161
               }
               // second blended zone
               if ( !b_row_last )
               {
1162 1163 1164 1165 1166 1167 1168
                        TopOffset = length;
                        uint8_t *p_dst = p_out - TopOffset * p_outpic->p[i_plane].i_pitch;

                        for (i_index = 0; i_index < length; i_index++)
                        {
                            for (i_index2 = 0; i_index2 < i_copy_pitch; i_index2++)
                            {
1169
#ifndef GAMMA
1170 1171 1172
                                p_dst[i_index * i_out_pitch + i_index2] = (p_vout->p_sys->lambda2[0][i_plane][i_index] *
                                             p_dst[i_index * i_out_pitch + i_index2]) / ACCURACY +
                                             p_vout->p_sys->cstYUV2[0][i_plane][i_index];
1173 1174
#else

1175
                                p_dst[i_index * i_out_pitch + i_index2] = p_vout->p_sys->LUT[i_plane][p_vout->p_sys->lambda2[0][i_plane][i_index]][p_dst[i_index * i_out_pitch + i_index2]];
1176
#endif
1177 1178
                            }
                        }
1179 1180 1181 1182
               }
           }
        }
       // end blended zone
1183
#endif
1184 1185 1186
                // bug for wall filter : fix by CC
                //            pi_left_skip[i_plane] += i_out_pitch;
                pi_left_skip[i_plane] += i_copy_pitch;
1187 1188 1189 1190 1191 1192 1193 1194 1195
            }

            vout_UnlinkPicture( p_vout->p_sys->pp_vout[ i_vout ].p_vout,
                                p_outpic );
            vout_DisplayPicture( p_vout->p_sys->pp_vout[ i_vout ].p_vout,
                                 p_outpic );
        }

        for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ )
1196 1197
        {
            pi_top_skip[i_plane] += p_vout->p_sys->pp_vout[ i_vout-1 ].i_height
1198 1199 1200
                                             * p_pic->p[i_plane].i_lines
                                             / p_vout->output.i_height
                                             * p_pic->p[i_plane].i_pitch;
1201
        }
1202 1203
    }
#ifdef OVERLAP
1204 1205
    if (p_vout->p_sys->b_has_changed)
        p_vout->p_sys->b_has_changed = false;
1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233
#endif
}


/*****************************************************************************
 * RenderPackedRGB: displays previously rendered output
 *****************************************************************************
 * This function send the currently rendered image to Wall image, waits
 * until it is displayed and switch the two rendering buffers, preparing next
 * frame.
 *****************************************************************************/
static void RenderPackedRGB( vout_thread_t *p_vout, picture_t *p_pic )
{
    picture_t *p_outpic = NULL;
    int i_col, i_row, i_vout, i_plane;
    int pi_left_skip[VOUT_MAX_PLANES], pi_top_skip[VOUT_MAX_PLANES];
#ifdef OVERLAP
    int LeftOffset, TopOffset;
    int Denom;
    int a_2;
    int a_1;
    int a_0;
    int i_index, i_index2;
#endif

    for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ )
        pi_top_skip[i_plane] = 0;

1234
    for( i_vout = 0, i_row = 0; i_row < p_vout->p_sys->i_row; i_row++ )
1235 1236 1237 1238
    {
        for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ )
            pi_left_skip[i_plane] = 0;

1239
        for( i_col = 0; i_col < p_vout->p_sys->i_col; i_col++, i_vout++ )
1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255
        {
            if( !p_vout->p_sys->pp_vout[ i_vout ].b_active )
            {
                for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ )
                {
                    pi_left_skip[i_plane] +=
                        p_vout->p_sys->pp_vout[ i_vout ].i_width * p_pic->p->i_pixel_pitch;
                }
                continue;
            }

            while( ( p_outpic =
                vout_CreatePicture( p_vout->p_sys->pp_vout[ i_vout ].p_vout,
                                    0, 0, 0 )
                   ) == NULL )
            {
1256
                if( !vlc_object_alive (p_vout) || p_vout->b_error )
1257 1258 1259 1260 1261 1262 1263 1264 1265
                {
                    vout_DestroyPicture(
                        p_vout->p_sys->pp_vout[ i_vout ].p_vout, p_outpic );
                    return;
                }

                msleep( VOUT_OUTMEM_SLEEP );
            }

1266
            p_outpic->date = p_pic->date;
1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277
            vout_LinkPicture( p_vout->p_sys->pp_vout[ i_vout ].p_vout,
                              p_outpic );

            for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ )
            {
                uint8_t *p_in, *p_in_end, *p_out;
                int i_in_pitch = p_pic->p[i_plane].i_pitch;
                int i_out_pitch = p_outpic->p[i_plane].i_pitch;
                int i_copy_pitch = p_outpic->p[i_plane].i_visible_pitch;

#ifdef OVERLAP
1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288
                if (i_col)
                    pi_left_skip[i_plane] -= (2 * p_vout->p_sys->i_halfLength) * p_pic->p->i_pixel_pitch;
                if( p_vout->p_sys->i_row >= 2 )
                {
                    if( (i_row) && (!i_col))
                        pi_top_skip[i_plane] -= (2 * p_vout->p_sys->i_halfHeight * p_pic->p[i_plane].i_pitch);
                    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);
                    if( !p_vout->p_sys->pp_vout[p_vout->p_sys->i_col-1].b_active )
                        pi_top_skip[i_plane] -= (2 * p_vout->p_sys->i_halfHeight * i_row * p_pic->p[i_plane].i_pitch);
                }
1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340
// i_n : previous inactive pp_vout
                int i_n=0;
                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++;
                if ((i_col > 1) && i_n)
                    pi_left_skip[i_plane] -= i_n*(2 * p_vout->p_sys->i_halfLength ) * p_pic->p->i_pixel_pitch;

                p_in = p_pic->p[i_plane].p_pixels
                /* Wall proprities */
                + pi_top_skip[i_plane] + pi_left_skip[i_plane];

                int i_lines = p_outpic->p[i_plane].i_visible_lines;
// 1088 lines bug in a mpeg2 stream of 1080 lines
                if ((p_vout->p_sys->i_row - 1 == i_row) &&
                    (p_pic->p[i_plane].i_lines == 1088))
                        i_lines -= 8;

                p_in_end = p_in + i_lines * p_pic->p[i_plane].i_pitch;
#else
                p_in = p_pic->p[i_plane].p_pixels
                        + pi_top_skip[i_plane] + pi_left_skip[i_plane];

                p_in_end = p_in + p_outpic->p[i_plane].i_visible_lines
                                        * p_pic->p[i_plane].i_pitch;
#endif //OVERLAP

                p_out = p_outpic->p[i_plane].p_pixels;


#ifdef OVERLAP
        if ((p_vout->p_sys->i_row > 2) && (!i_row))
            p_out += (p_outpic->p[i_plane].i_pitch * (2 * p_vout->p_sys->i_halfHeight) * p_pic->p->i_pixel_pitch);

        int length;
        length = 2 * p_vout->p_sys->i_halfLength * p_pic->p->i_pixel_pitch;

        if (p_vout->p_sys->b_has_changed)
        {
            int i_plane_;
            int i_col_mod;
            Denom = F2(length / p_pic->p->i_pixel_pitch);
            a_2 = p_vout->p_sys->a_2 * (ACCURACY / 100);
            a_1 = p_vout->p_sys->a_1 * 2 * p_vout->p_sys->i_halfLength * (ACCURACY / 100);
            a_0 = p_vout->p_sys->a_0 * Denom * (ACCURACY / 100);
            for(i_col_mod = 0; i_col_mod < 2; i_col_mod++)
                for (i_index = 0; i_index < length / p_pic->p->i_pixel_pitch; i_index++)
                    for (i_plane_ =  0; i_plane_ < p_pic->p->i_pixel_pitch; i_plane_++)
                        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);
        }
#endif
            while( p_in < p_in_end )
            {
#ifndef OVERLAP
1341
                vlc_memcpy( p_out, p_in, i_copy_pitch );
1342 1343 1344 1345 1346 1347
#else
                if (p_vout->p_sys->i_col > 2)
                {
                    // vertical blend
                    length /= 2;
                    if (i_col == 0)
1348
                        vlc_memcpy( p_out + length, p_in, i_copy_pitch - length);
1349
                    else if (i_col + 1 == p_vout->p_sys->i_col)
1350 1351 1352
                        vlc_memcpy( p_out, p_in - length, i_copy_pitch - length);
                    else
                        vlc_memcpy( p_out, p_in - length, i_copy_pitch);
1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378

                    if ((i_col == 0))
                    // black bar
                    {
                        LeftOffset = 0;
                        p_out += LeftOffset;
                        p_in += LeftOffset;
                        for (i_index = 0; i_index < length; i_index++)
                                *(p_out + i_index) = 0;
                        p_out -= LeftOffset;
                        p_in -= LeftOffset;
                    }
                    else if ((i_col + 1 == p_vout->p_sys->i_col ))
                    // black bar
                        {
                            LeftOffset = i_copy_pitch - length;
                            p_out += LeftOffset;
                            p_in += LeftOffset;
                            for (i_index = 0; i_index < length; i_index++)
                                    *(p_out + i_index) = 0;
                            p_out -= LeftOffset;
                            p_in -= LeftOffset;
                        }
                    length *= 2;
                }
                else
1379
                    vlc_memcpy( p_out, p_in, i_copy_pitch);
1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528

// vertical blend
// first blended zone
            if (i_col)
            {
                LeftOffset = 0;
                p_out += LeftOffset;
                for (i_index = 0; i_index < length; i_index++)
#ifndef GAMMA
                    *(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] *
                                 (*(p_out + i_index))) / ACCURACY;
#else
                    *(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)];
#endif
                p_out -= LeftOffset;
            }
// second blended zone
            if (i_col + 1 < p_vout->p_sys->i_col)
            {
                LeftOffset = i_copy_pitch - length;
                p_out +=  LeftOffset;
                for (i_index = 0; i_index < length; i_index++)
#ifndef GAMMA
                    *(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] *
                                 (*(p_out + i_index))) / ACCURACY;
#else
                    *(p_out + i_index) = p_vout->p_sys->LUT[i_index % p_pic->p->i_pixel_pitch][p_vout->p_sys