]> git.sesse.net Git - vlc/blob - modules/video_filter/panoramix.c
Use var_InheritString for --decklink-video-connection.
[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 #include <math.h>
33 #include <assert.h>
34
35 #include <vlc_common.h>
36 #include <vlc_plugin.h>
37 #include <vlc_video_splitter.h>
38
39 /* FIXME it is needed for VOUT_ALIGN_* only */
40 #include <vlc_vout.h>
41
42 #define OVERLAP
43
44 #ifdef OVERLAP
45 /* OS CODE DEPENDENT to get display dimensions */
46 #   ifdef WIN32
47 #       include <windows.h>
48 #   else
49 #       include <xcb/xcb.h>
50 #       include <xcb/randr.h>
51 #   endif
52 #endif
53
54 /*****************************************************************************
55  * Module descriptor
56  *****************************************************************************/
57 #define COLS_TEXT N_("Number of columns")
58 #define COLS_LONGTEXT N_("Select the number of horizontal video windows in " \
59     "which to split the video")
60
61 #define ROWS_TEXT N_("Number of rows")
62 #define ROWS_LONGTEXT N_("Select the number of vertical video windows in " \
63     "which to split the video")
64
65 #define ACTIVE_TEXT N_("Active windows")
66 #define ACTIVE_LONGTEXT N_("Comma separated list of active windows, " \
67     "defaults to all")
68
69 #define CFG_PREFIX "panoramix-"
70
71 #define PANORAMIX_HELP N_("Split the video in multiple windows to " \
72     "display on a wall of screens")
73
74 static int  Open ( vlc_object_t * );
75 static void Close( vlc_object_t * );
76
77 vlc_module_begin()
78     set_description( N_("Panoramix: wall with overlap video filter") )
79     set_shortname( N_("Panoramix" ))
80     set_help(PANORAMIX_HELP)
81     set_capability( "video splitter", 0 )
82     set_category( CAT_VIDEO )
83     set_subcategory( SUBCAT_VIDEO_VFILTER )
84
85     add_integer( CFG_PREFIX "cols", -1, NULL, COLS_TEXT, COLS_LONGTEXT, true )
86     add_integer( CFG_PREFIX "rows", -1, NULL, ROWS_TEXT, ROWS_LONGTEXT, true )
87
88 #ifdef OVERLAP
89 #define LENGTH_TEXT N_("length of the overlapping area (in %)")
90 #define LENGTH_LONGTEXT N_("Select in percent the length of the blended zone")
91     add_integer_with_range( CFG_PREFIX "bz-length", 100, 0, 100, NULL, LENGTH_TEXT, LENGTH_LONGTEXT, true )
92
93 #define HEIGHT_TEXT N_("height of the overlapping area (in %)")
94 #define HEIGHT_LONGTEXT N_("Select in percent the height of the blended zone (case of 2x2 wall)")
95     add_integer_with_range( CFG_PREFIX "bz-height", 100, 0, 100, NULL, HEIGHT_TEXT, HEIGHT_LONGTEXT, true )
96
97 #define ATTENUATION_TEXT N_("Attenuation")
98 #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)")
99     add_bool( CFG_PREFIX "attenuate", true, NULL, ATTENUATION_TEXT, ATTENUATION_LONGTEXT, false )
100
101 #define BEGIN_TEXT N_("Attenuation, begin (in %)")
102 #define BEGIN_LONGTEXT N_("Select in percent the Lagrange coeff of the beginning blended zone")
103     add_integer_with_range( CFG_PREFIX "bz-begin", 0, 0, 100, NULL, BEGIN_TEXT, BEGIN_LONGTEXT, true )
104
105 #define MIDDLE_TEXT N_("Attenuation, middle (in %)")
106 #define MIDDLE_LONGTEXT N_("Select in percent the Lagrange coeff of the middle of blended zone")
107     add_integer_with_range( CFG_PREFIX "bz-middle", 50, 0, 100, NULL, MIDDLE_TEXT, MIDDLE_LONGTEXT, false )
108
109 #define END_TEXT N_("Attenuation, end (in %)")
110 #define END_LONGTEXT N_("Select in percent the Lagrange coeff of the end of blended zone")
111     add_integer_with_range( CFG_PREFIX "bz-end", 100, 0, 100, NULL, END_TEXT, END_LONGTEXT, true )
112
113 #define MIDDLE_POS_TEXT N_("middle position (in %)")
114 #define MIDDLE_POS_LONGTEXT N_("Select in percent (50 is center) the position of the middle point (Lagrange) of blended zone")
115     add_integer_with_range( CFG_PREFIX "bz-middle-pos", 50, 1, 99, NULL, MIDDLE_POS_TEXT, MIDDLE_POS_LONGTEXT, false )
116 #define RGAMMA_TEXT N_("Gamma (Red) correction")
117 #define RGAMMA_LONGTEXT N_("Select the gamma for the correction of blended zone (Red or Y component)")
118     add_float_with_range( CFG_PREFIX "bz-gamma-red", 1, 0, 5, NULL, RGAMMA_TEXT, RGAMMA_LONGTEXT, true )
119
120 #define GGAMMA_TEXT N_("Gamma (Green) correction")
121 #define GGAMMA_LONGTEXT N_("Select the gamma for the correction of blended zone (Green or U component)")
122     add_float_with_range( CFG_PREFIX "bz-gamma-green", 1, 0, 5, NULL, GGAMMA_TEXT, GGAMMA_LONGTEXT, true )
123
124 #define BGAMMA_TEXT N_("Gamma (Blue) correction")
125 #define BGAMMA_LONGTEXT N_("Select the gamma for the correction of blended zone (Blue or V component)")
126     add_float_with_range( CFG_PREFIX "bz-gamma-blue", 1, 0, 5, NULL, BGAMMA_TEXT, BGAMMA_LONGTEXT, true )
127
128 #define RGAMMA_BC_TEXT N_("Black Crush for Red")
129 #define RGAMMA_BC_LONGTEXT N_("Select the Black Crush of blended zone (Red or Y component)")
130 #define GGAMMA_BC_TEXT N_("Black Crush for Green")
131 #define GGAMMA_BC_LONGTEXT N_("Select the Black Crush of blended zone (Green or U component)")
132 #define BGAMMA_BC_TEXT N_("Black Crush for Blue")
133 #define BGAMMA_BC_LONGTEXT N_("Select the Black Crush of blended zone (Blue or V component)")
134
135 #define RGAMMA_WC_TEXT N_("White Crush for Red")
136 #define RGAMMA_WC_LONGTEXT N_("Select the White Crush of blended zone (Red or Y component)")
137 #define GGAMMA_WC_TEXT N_("White Crush for Green")
138 #define GGAMMA_WC_LONGTEXT N_("Select the White Crush of blended zone (Green or U component)")
139 #define BGAMMA_WC_TEXT N_("White Crush for Blue")
140 #define BGAMMA_WC_LONGTEXT N_("Select the White Crush of blended zone (Blue or V component)")
141
142 #define RGAMMA_BL_TEXT N_("Black Level for Red")
143 #define RGAMMA_BL_LONGTEXT N_("Select the Black Level of blended zone (Red or Y component)")
144 #define GGAMMA_BL_TEXT N_("Black Level for Green")
145 #define GGAMMA_BL_LONGTEXT N_("Select the Black Level of blended zone (Green or U component)")
146 #define BGAMMA_BL_TEXT N_("Black Level for Blue")
147 #define BGAMMA_BL_LONGTEXT N_("Select the Black Level of blended zone (Blue or V component)")
148
149 #define RGAMMA_WL_TEXT N_("White Level for Red")
150 #define RGAMMA_WL_LONGTEXT N_("Select the White Level of blended zone (Red or Y component)")
151 #define GGAMMA_WL_TEXT N_("White Level for Green")
152 #define GGAMMA_WL_LONGTEXT N_("Select the White Level of blended zone (Green or U component)")
153 #define BGAMMA_WL_TEXT N_("White Level for Blue")
154 #define BGAMMA_WL_LONGTEXT N_("Select the White Level of blended zone (Blue or V component)")
155     add_integer_with_range( CFG_PREFIX "bz-blackcrush-red", 140, 0, 255, NULL, RGAMMA_BC_TEXT, RGAMMA_BC_LONGTEXT, true )
156     add_integer_with_range( CFG_PREFIX "bz-blackcrush-green", 140, 0, 255, NULL, GGAMMA_BC_TEXT, GGAMMA_BC_LONGTEXT, true )
157     add_integer_with_range( CFG_PREFIX "bz-blackcrush-blue", 140, 0, 255, NULL, BGAMMA_BC_TEXT, BGAMMA_BC_LONGTEXT, true )
158     add_integer_with_range( CFG_PREFIX "bz-whitecrush-red", 200, 0, 255, NULL, RGAMMA_WC_TEXT, RGAMMA_WC_LONGTEXT, true )
159     add_integer_with_range( CFG_PREFIX "bz-whitecrush-green", 200, 0, 255, NULL, GGAMMA_WC_TEXT, GGAMMA_WC_LONGTEXT, true )
160     add_integer_with_range( CFG_PREFIX "bz-whitecrush-blue", 200, 0, 255, NULL, BGAMMA_WC_TEXT, BGAMMA_WC_LONGTEXT, true )
161     add_integer_with_range( CFG_PREFIX "bz-blacklevel-red", 150, 0, 255, NULL, RGAMMA_BL_TEXT, RGAMMA_BL_LONGTEXT, true )
162     add_integer_with_range( CFG_PREFIX "bz-blacklevel-green", 150, 0, 255, NULL, GGAMMA_BL_TEXT, GGAMMA_BL_LONGTEXT, true )
163     add_integer_with_range( CFG_PREFIX "bz-blacklevel-blue", 150, 0, 255, NULL, BGAMMA_BL_TEXT, BGAMMA_BL_LONGTEXT, true )
164     add_integer_with_range( CFG_PREFIX "bz-whitelevel-red", 0, 0, 255, NULL, RGAMMA_WL_TEXT, RGAMMA_WL_LONGTEXT, true )
165     add_integer_with_range( CFG_PREFIX "bz-whitelevel-green", 0, 0, 255, NULL, GGAMMA_WL_TEXT, GGAMMA_WL_LONGTEXT, true )
166     add_integer_with_range( CFG_PREFIX "bz-whitelevel-blue", 0, 0, 255, NULL, BGAMMA_WL_TEXT, BGAMMA_WL_LONGTEXT, true )
167 #ifndef WIN32
168     add_obsolete_bool( CFG_PREFIX "xinerama" );
169 #endif
170     add_obsolete_bool( CFG_PREFIX "offset-x" )
171 #endif
172
173     add_string( CFG_PREFIX "active", NULL, NULL, ACTIVE_TEXT, ACTIVE_LONGTEXT, true )
174
175     add_shortcut( "panoramix" )
176     set_callbacks( Open, Close )
177 vlc_module_end()
178
179
180 /*****************************************************************************
181  * Local prototypes
182  *****************************************************************************/
183 static const char *const ppsz_filter_options[] = {
184     "cols", "rows", "bz-length", "bz-height", "attenuate",
185     "bz-begin", "bz-middle", "bz-end", "bz-middle-pos", "bz-gamma-red",
186     "bz-gamma-green", "bz-gamma-blue", "bz-blackcrush-red",
187     "bz-blackcrush-green", "bz-blackcrush-blue", "bz-whitecrush-red",
188     "bz-whitecrush-green", "bz-whitecrush-blue", "bz-blacklevel-red",
189     "bz-blacklevel-green", "bz-blacklevel-blue", "bz-whitelevel-red",
190     "bz-whitelevel-green", "bz-whitelevel-blue", "active",
191     NULL
192 };
193
194 #define ROW_MAX (15)
195 #define COL_MAX (15)
196
197 #define ACCURACY 1000
198
199 /* */
200 static inline int clip_accuracy( int a )
201 {
202     return (a > ACCURACY) ? ACCURACY : (a < 0) ? 0 : a;
203 }
204 static inline float clip_unit( float f )
205 {
206     return f < 0.0 ? 0.0 : ( f > 1.0 ? 1.0 : f );
207 }
208
209 /* */
210 typedef struct
211 {
212     float f_black_crush;
213     float f_black_level;
214
215     float f_white_crush;
216     float f_white_level;
217
218     float f_gamma;
219 } panoramix_gamma_t;
220
221 typedef struct
222 {
223     struct
224     {
225         int i_left;
226         int i_right;
227         int i_top;
228         int i_bottom;
229     } black;
230     struct
231     {
232         int i_left;
233         int i_right;
234         int i_top;
235         int i_bottom;
236     } attenuate;
237 } panoramix_filter_t;
238
239 typedef struct
240 {
241     bool b_active;
242     int  i_output;
243
244     /* Output position and size */
245     int i_x;
246     int i_y;
247     int i_width;
248     int i_height;
249     int i_align;
250
251     /* Source position and size */
252     int  i_src_x;
253     int  i_src_y;
254     int  i_src_width;
255     int  i_src_height;
256
257     /* Filter configuration to use to create the output */
258     panoramix_filter_t filter;
259
260 } panoramix_output_t;
261
262 typedef struct
263 {
264     vlc_fourcc_t i_chroma;
265
266     const int pi_div_w[VOUT_MAX_PLANES];
267     const int pi_div_h[VOUT_MAX_PLANES];
268
269     const int pi_black[VOUT_MAX_PLANES];
270
271     bool b_planar;
272
273 } panoramix_chroma_t;
274
275 struct video_splitter_sys_t
276 {
277     const panoramix_chroma_t *p_chroma;
278
279     /* */
280     bool   b_attenuate;
281     unsigned int bz_length, bz_height;
282     unsigned int bz_begin, bz_middle, bz_end;
283     unsigned int bz_middle_pos;
284     unsigned int a_0, a_1, a_2;
285
286     int lambdav[VOUT_MAX_PLANES][2][ACCURACY/2]; /* [plane][position][?] */
287     int lambdah[VOUT_MAX_PLANES][2][ACCURACY/2];
288
289     unsigned int i_overlap_w2;  /* Half overlap width */
290     unsigned int i_overlap_h2;  /* Half overlap height */
291     uint8_t      p_lut[VOUT_MAX_PLANES][ACCURACY + 1][256];
292
293     /* */
294     int i_col;
295     int i_row;
296     panoramix_output_t pp_output[COL_MAX][ROW_MAX]; /* [x][y] */
297 };
298
299 /* */
300 static int Filter( video_splitter_t *, picture_t *pp_dst[], picture_t * );
301
302 static int Mouse( video_splitter_t *, vlc_mouse_t *,
303                   int i_index,
304                   const vlc_mouse_t *p_old, const vlc_mouse_t *p_new );
305
306
307 /* */
308 static int Configuration( panoramix_output_t pp_output[ROW_MAX][COL_MAX],
309                           int i_col, int i_row,
310                           int i_src_width, int i_src_height,
311                           int i_half_w, int i_half_h,
312                           bool b_attenuate,
313                           const bool *pb_active );
314 static double GammaFactor( const panoramix_gamma_t *, float f_value );
315
316 static void FilterPlanar( uint8_t *p_out, int i_out_pitch,
317                           const uint8_t *p_in, int i_in_pitch,
318                           int i_copy_pitch,
319                           int i_copy_lines,
320                           int i_pixel_black,
321                           const panoramix_filter_t *,
322                           uint8_t p_lut[ACCURACY + 1][256],
323                           int lambdav[2][ACCURACY/2],
324                           int lambdah[2][ACCURACY/2] );
325
326 /* */
327 static const panoramix_chroma_t p_chroma_array[] = {
328     /* Planar chroma */
329     { VLC_CODEC_I410, { 1, 4, 4, }, { 1, 1, 1, }, { 0, 128, 128 }, true },
330     { VLC_CODEC_I411, { 1, 4, 4, }, { 1, 4, 4, }, { 0, 128, 128 }, true },
331     { VLC_CODEC_YV12, { 1, 2, 2, }, { 1, 2, 2, }, { 0, 128, 128 }, true },
332     { VLC_CODEC_I420, { 1, 2, 2, }, { 1, 2, 2, }, { 0, 128, 128 }, true },
333     { VLC_CODEC_J420, { 1, 2, 2, }, { 1, 2, 2, }, { 0, 128, 128 }, true },
334     { VLC_CODEC_I422, { 1, 2, 2, }, { 1, 1, 1, }, { 0, 128, 128 }, true },
335     { VLC_CODEC_J422, { 1, 2, 2, }, { 1, 1, 1, }, { 0, 128, 128 }, true },
336     { VLC_CODEC_I440, { 1, 1, 1, }, { 1, 2, 2, }, { 0, 128, 128 }, true },
337     { VLC_CODEC_J440, { 1, 1, 1, }, { 1, 2, 2, }, { 0, 128, 128 }, true },
338     { VLC_CODEC_I444, { 1, 1, 1, }, { 1, 1, 1, }, { 0, 128, 128 }, true },
339     /* TODO packed chroma (yuv/rgb) ? */
340
341     { 0, {0, }, { 0, }, { 0, 0, 0 }, false }
342 };
343
344 #ifndef WIN32
345 /* Get the number of outputs */
346 static unsigned CountMonitors( vlc_object_t *obj )
347 {
348     char *psz_display = var_CreateGetNonEmptyString( obj, "x11-display" );
349     int snum;
350     xcb_connection_t *conn = xcb_connect( psz_display, &snum );
351     free( psz_display );
352     if( xcb_connection_has_error( conn ) )
353         return 0;
354
355     const xcb_setup_t *setup = xcb_get_setup( conn );
356     xcb_screen_t *scr = NULL;
357     for( xcb_screen_iterator_t i = xcb_setup_roots_iterator( setup );
358          i.rem > 0; xcb_screen_next( &i ) )
359     {
360          if( snum == 0 )
361          {
362              scr = i.data;
363              break;
364          }
365          snum--;
366     }
367
368     unsigned n = 0;
369     if( scr == NULL )
370         goto error;
371
372     xcb_randr_query_version_reply_t *v =
373         xcb_randr_query_version_reply( conn,
374             xcb_randr_query_version( conn, 1, 2 ), NULL );
375     if( v == NULL )
376         goto error;
377     msg_Dbg( obj, "using X RandR extension v%"PRIu32".%"PRIu32,
378              v->major_version, v->minor_version );
379     free( v );
380
381     xcb_randr_get_screen_resources_reply_t *r =
382         xcb_randr_get_screen_resources_reply( conn,
383             xcb_randr_get_screen_resources( conn, scr->root ), NULL );
384     if( r == NULL )
385         goto error;
386
387     const xcb_randr_output_t *outputs =
388         xcb_randr_get_screen_resources_outputs( r );
389     for( unsigned i = 0; i < r->num_outputs; i++ )
390     {
391         xcb_randr_get_output_info_reply_t *output =
392             xcb_randr_get_output_info_reply( conn,
393                 xcb_randr_get_output_info( conn, outputs[i], 0 ), NULL );
394         if( output == NULL )
395             continue;
396         /* FIXME: do not count cloned outputs multiple times */
397         /* XXX: what to do with UNKNOWN state connections? */
398         n += output->connection == XCB_RANDR_CONNECTION_CONNECTED;
399         free( output );
400     }
401     free( r );
402     msg_Dbg( obj, "X randr has %u outputs", n );
403
404 error:
405     xcb_disconnect( conn );
406     return n;
407 }
408 #endif
409
410 /*****************************************************************************
411  * Open: allocates Wall video thread output method
412  *****************************************************************************
413  * This function allocates and initializes a Wall vout method.
414  *****************************************************************************/
415 static int Open( vlc_object_t *p_this )
416 {
417     video_splitter_t *p_splitter = (video_splitter_t*)p_this;
418     video_splitter_sys_t *p_sys;
419
420     const panoramix_chroma_t *p_chroma;
421     for( int i = 0; ; i++ )
422     {
423         vlc_fourcc_t i_chroma = p_chroma_array[i].i_chroma;
424         if( !i_chroma )
425         {
426             msg_Err( p_splitter, "colorspace not supported by plug-in !" );
427             return VLC_EGENERIC;
428         }
429         if( i_chroma == p_splitter->fmt.i_chroma )
430         {
431             p_chroma = &p_chroma_array[i];
432             break;
433         }
434     }
435
436     /* Allocate structure */
437     p_splitter->p_sys = p_sys = malloc( sizeof( *p_sys ) );
438     if( !p_sys )
439         return VLC_ENOMEM;
440
441     /* */
442     p_sys->p_chroma = p_chroma;
443
444     /* */
445     config_ChainParse( p_splitter, CFG_PREFIX, ppsz_filter_options,
446                        p_splitter->p_cfg );
447
448     /* */
449     p_sys->i_col = var_CreateGetInteger( p_splitter, CFG_PREFIX "cols" );
450     p_sys->i_row = var_CreateGetInteger( p_splitter, CFG_PREFIX "rows" );
451
452     /* Autodetect number of displays */
453     if( p_sys->i_col < 0 || p_sys->i_row < 0 )
454     {
455 #ifdef WIN32
456         const int i_monitor_count = GetSystemMetrics(SM_CMONITORS);
457         if( i_monitor_count > 1 )
458         {
459             p_sys->i_col = GetSystemMetrics( SM_CXVIRTUALSCREEN ) / GetSystemMetrics( SM_CXSCREEN );
460             p_sys->i_row = GetSystemMetrics( SM_CYVIRTUALSCREEN ) / GetSystemMetrics( SM_CYSCREEN );
461             if( p_sys->i_col * p_sys->i_row != i_monitor_count )
462             {
463                 p_sys->i_col = i_monitor_count;
464                 p_sys->i_row = 1;
465             }
466         }
467 #else
468         const unsigned i_monitors = CountMonitors( p_this );
469         if( i_monitors > 1 ) /* Find closest to square */
470             for( unsigned w = 1; (i_monitors / w) >= w ; w++ )
471             {
472                 if( i_monitors % w )
473                     continue;
474                 p_sys->i_row = w;
475                 p_sys->i_col = i_monitors / w;
476             }
477 #endif
478         /* By default do 2x1 */
479         if( p_sys->i_row < 0 )
480             p_sys->i_row = 1;
481         if( p_sys->i_col < 0 )
482             p_sys->i_col = 2;
483         var_SetInteger( p_splitter, CFG_PREFIX "cols", p_sys->i_col);
484         var_SetInteger( p_splitter, CFG_PREFIX "rows", p_sys->i_row);
485     }
486
487     /* */
488     p_sys->b_attenuate = var_CreateGetBool( p_splitter, CFG_PREFIX "attenuate");
489     p_sys->bz_length = var_CreateGetInteger( p_splitter, CFG_PREFIX "bz-length" );
490     p_sys->bz_height = var_CreateGetInteger( p_splitter, CFG_PREFIX "bz-height" );
491     p_sys->bz_begin = var_CreateGetInteger( p_splitter, CFG_PREFIX "bz-begin" );
492     p_sys->bz_middle = var_CreateGetInteger( p_splitter, CFG_PREFIX "bz-middle" );
493     p_sys->bz_end = var_CreateGetInteger( p_splitter, CFG_PREFIX "bz-end" );
494     p_sys->bz_middle_pos = var_CreateGetInteger( p_splitter, CFG_PREFIX "bz-middle-pos" );
495     double d_p = 100.0 / p_sys->bz_middle_pos;
496
497     p_sys->a_2 = d_p * p_sys->bz_begin - (double)(d_p * d_p / (d_p - 1)) * p_sys->bz_middle + (double)(d_p / (d_p - 1)) * p_sys->bz_end;
498     p_sys->a_1 = -(d_p + 1) * p_sys->bz_begin + (double)(d_p * d_p / (d_p - 1)) * p_sys->bz_middle - (double)(1 / (d_p - 1)) * p_sys->bz_end;
499     p_sys->a_0 =  p_sys->bz_begin;
500
501     /* */
502     p_sys->i_col = __MAX( 1, __MIN( COL_MAX, p_sys->i_col ) );
503     p_sys->i_row = __MAX( 1, __MIN( ROW_MAX, p_sys->i_row ) );
504     msg_Dbg( p_splitter, "opening a %i x %i wall",
505              p_sys->i_col, p_sys->i_row );
506
507     if( p_sys->bz_length > 0 && ( p_sys->i_row > 1 || p_sys->i_col > 1 ) )
508     {
509         const int i_overlap_w2_max = p_splitter->fmt.i_width  / p_sys->i_col / 2;
510         const int i_overlap_h2_max = p_splitter->fmt.i_height / p_sys->i_row / 2;
511         const int i_overlap2_max = __MIN( i_overlap_w2_max, i_overlap_h2_max );
512
513         if( p_sys->i_col > 1 )
514             p_sys->i_overlap_w2 = i_overlap2_max * p_sys->bz_length / 100;
515         else
516             p_sys->i_overlap_w2 = 0;
517
518         if( p_sys->i_row > 1 )
519             p_sys->i_overlap_h2 = i_overlap2_max * p_sys->bz_height / 100;
520         else
521             p_sys->i_overlap_h2 = 0;
522
523         /* */
524         int i_div_max_w = 1;
525         int i_div_max_h = 1;
526         for( int i = 0; i < VOUT_MAX_PLANES; i++ )
527         {
528             i_div_max_w = __MAX( i_div_max_w, p_chroma->pi_div_w[i] );
529             i_div_max_h = __MAX( i_div_max_h, p_chroma->pi_div_h[i] );
530         }
531         p_sys->i_overlap_w2 = i_div_max_w * (p_sys->i_overlap_w2 / i_div_max_w);
532         p_sys->i_overlap_h2 = i_div_max_h * (p_sys->i_overlap_h2 / i_div_max_h);
533     }
534     else
535     {
536         p_sys->i_overlap_w2 = 0;
537         p_sys->i_overlap_h2 = 0;
538     }
539
540     /* Compute attenuate parameters */
541     if( p_sys->b_attenuate )
542     {
543         panoramix_gamma_t p_gamma[VOUT_MAX_PLANES];
544
545         p_gamma[0].f_gamma = var_CreateGetFloat( p_splitter, CFG_PREFIX "bz-gamma-red" );
546         p_gamma[1].f_gamma = var_CreateGetFloat( p_splitter, CFG_PREFIX "bz-gamma-green" );
547         p_gamma[2].f_gamma = var_CreateGetFloat( p_splitter, CFG_PREFIX "bz-gamma-blue" );
548
549         p_gamma[0].f_black_crush = var_CreateGetInteger( p_splitter, CFG_PREFIX "bz-blackcrush-red" ) / 255.0;
550         p_gamma[1].f_black_crush = var_CreateGetInteger( p_splitter, CFG_PREFIX "bz-blackcrush-green" ) / 255.0;
551         p_gamma[2].f_black_crush = var_CreateGetInteger( p_splitter, CFG_PREFIX "bz-blackcrush-blue" ) / 255.0;
552         p_gamma[0].f_white_crush = var_CreateGetInteger( p_splitter, CFG_PREFIX "bz-whitecrush-red" ) / 255.0;
553         p_gamma[1].f_white_crush = var_CreateGetInteger( p_splitter, CFG_PREFIX "bz-whitecrush-green" ) / 255.0;
554         p_gamma[2].f_white_crush = var_CreateGetInteger( p_splitter, CFG_PREFIX "bz-whitecrush-blue" ) / 255.0;
555
556         p_gamma[0].f_black_level = var_CreateGetInteger( p_splitter, CFG_PREFIX "bz-blacklevel-red" ) / 255.0;
557         p_gamma[1].f_black_level = var_CreateGetInteger( p_splitter, CFG_PREFIX "bz-blacklevel-green" ) / 255.0;
558         p_gamma[2].f_black_level = var_CreateGetInteger( p_splitter, CFG_PREFIX "bz-blacklevel-blue" ) / 255.0;
559         p_gamma[0].f_white_level = var_CreateGetInteger( p_splitter, CFG_PREFIX "bz-whitelevel-red" ) / 255.0;
560         p_gamma[1].f_white_level = var_CreateGetInteger( p_splitter, CFG_PREFIX "bz-whitelevel-green" ) / 255.0;
561         p_gamma[2].f_white_level = var_CreateGetInteger( p_splitter, CFG_PREFIX "bz-whitelevel-blue" ) / 255.0;
562
563         for( int i = 3; i < VOUT_MAX_PLANES; i++ )
564         {
565             /* Initialize unsupported planes */
566             p_gamma[i].f_gamma = 1.0;
567             p_gamma[i].f_black_crush = 140.0/255.0;
568             p_gamma[i].f_white_crush = 200.0/255.0;
569             p_gamma[i].f_black_level = 150.0/255.0;
570             p_gamma[i].f_white_level = 0.0/255.0;
571         }
572
573         if( p_chroma->i_chroma == VLC_CODEC_YV12 )
574         {
575             /* Exchange U and V */
576             panoramix_gamma_t t = p_gamma[1];
577             p_gamma[1] = p_gamma[2];
578             p_gamma[2] = t;
579         }
580         
581         for( int i_index = 0; i_index < 256; i_index++ )
582         {
583             for( int i_index2 = 0; i_index2 <= ACCURACY; i_index2++ )
584             {
585                 for( int i_plane = 0; i_plane < VOUT_MAX_PLANES; i_plane++ )
586                 {
587                     double f_factor = GammaFactor( &p_gamma[i_plane], (float)i_index / 255.0 );
588
589                     float f_lut = clip_unit( 1.0 - ((ACCURACY - (float)i_index2) * f_factor / (ACCURACY - 1)) );
590
591                     p_sys->p_lut[i_plane][i_index2][i_index] = f_lut * i_index + (int)( (1.0 - f_lut) * (float)p_chroma->pi_black[i_plane] );
592                 }
593             }
594         }
595
596         for( int i_plane = 0; i_plane < VOUT_MAX_PLANES; i_plane++ )
597         {
598             if( !p_chroma->pi_div_w[i_plane] || !p_chroma->pi_div_h[i_plane] )
599                 continue;
600             const int i_length_w = (2 * p_sys->i_overlap_w2) / p_chroma->pi_div_w[i_plane];
601             const int i_length_h = (2 * p_sys->i_overlap_h2) / p_chroma->pi_div_h[i_plane];
602
603             for( int i_dir = 0; i_dir < 2; i_dir++ )
604             {
605                 const int i_length = i_dir == 0 ? i_length_w : i_length_h;
606                 const int i_den = i_length * i_length;
607                 const int a_2 = p_sys->a_2 * (ACCURACY / 100);
608                 const int a_1 = p_sys->a_1 * i_length * (ACCURACY / 100);
609                 const int a_0 = p_sys->a_0 * i_den * (ACCURACY / 100);
610
611                 for( int i_position = 0; i_position < 2; i_position++ )
612                 {
613                     for( int i_index = 0; i_index < i_length; i_index++ )
614                     {
615                         const int v = i_position == 1 ? i_index : (i_length - i_index);
616                         const int i_lambda = clip_accuracy( ACCURACY - (a_2 * v*v + a_1 * v + a_0) / i_den );
617
618                         if( i_dir == 0 )
619                             p_sys->lambdav[i_plane][i_position][i_index] = i_lambda;
620                         else
621                             p_sys->lambdah[i_plane][i_position][i_index] = i_lambda;
622                     }
623                 }
624             }
625         }
626     }
627
628     /* */
629     char *psz_state = var_CreateGetNonEmptyString( p_splitter, CFG_PREFIX "active" );
630
631     /* */
632     bool pb_active[COL_MAX*ROW_MAX];
633
634     for( int i = 0; i < COL_MAX*ROW_MAX; i++ )
635         pb_active[i] = psz_state == NULL;
636
637     /* Parse active list if provided */
638     char *psz_tmp = psz_state;
639     while( psz_tmp && *psz_tmp )
640     {
641         char *psz_next = strchr( psz_tmp, ',' );
642         if( psz_next )
643             *psz_next++ = '\0';
644
645         const int i_index = atoi( psz_tmp );
646         if( i_index >= 0 && i_index < COL_MAX*ROW_MAX )
647             pb_active[i_index] = true;
648
649         psz_tmp = psz_next;
650     }
651     free( psz_state );
652
653     /* */
654     p_splitter->i_output =
655         Configuration( p_sys->pp_output,
656                        p_sys->i_col, p_sys->i_row,
657                        p_splitter->fmt.i_width, p_splitter->fmt.i_height,
658                        p_sys->i_overlap_w2, p_sys->i_overlap_h2,
659                        p_sys->b_attenuate,
660                        pb_active );
661     p_splitter->p_output = calloc( p_splitter->i_output,
662                                    sizeof(*p_splitter->p_output) );
663     if( !p_splitter->p_output )
664     {
665         free( p_sys );
666         return VLC_ENOMEM;
667     }
668
669     for( int y = 0; y < p_sys->i_row; y++ )
670     {
671         for( int x = 0; x < p_sys->i_col; x++ )
672         {
673             panoramix_output_t *p_output = &p_sys->pp_output[x][y];
674             if( !p_output->b_active )
675                 continue;
676
677             video_splitter_output_t *p_cfg = &p_splitter->p_output[p_output->i_output];
678
679             /* */
680             video_format_Copy( &p_cfg->fmt, &p_splitter->fmt );
681             p_cfg->fmt.i_visible_width  =
682             p_cfg->fmt.i_width          = p_output->i_width;
683             p_cfg->fmt.i_visible_height =
684             p_cfg->fmt.i_height         = p_output->i_height;
685
686             p_cfg->window.i_x     = p_output->i_x;
687             p_cfg->window.i_y     = p_output->i_y;
688             p_cfg->window.i_align = p_output->i_align;
689
690             p_cfg->psz_module = NULL;
691         }
692     }
693
694
695     /* */
696     p_splitter->pf_filter = Filter;
697     p_splitter->pf_mouse  = Mouse;
698
699     return VLC_SUCCESS;
700 }
701
702 /**
703  * Terminate a splitter module
704  */
705 static void Close( vlc_object_t *p_this )
706 {
707     video_splitter_t *p_splitter = (video_splitter_t*)p_this;
708     video_splitter_sys_t *p_sys = p_splitter->p_sys;
709
710     free( p_splitter->p_output );
711     free( p_sys );
712 }
713
714 /**
715  * It creates multiples pictures from the source one
716  */
717 static int Filter( video_splitter_t *p_splitter, picture_t *pp_dst[], picture_t *p_src )
718 {
719     video_splitter_sys_t *p_sys = p_splitter->p_sys;
720
721     if( video_splitter_NewPicture( p_splitter, pp_dst ) )
722     {
723         picture_Release( p_src );
724         return VLC_EGENERIC;
725     }
726
727     for( int y = 0; y < p_sys->i_row; y++ )
728     {
729         for( int x = 0; x < p_sys->i_col; x++ )
730         {
731             const panoramix_output_t *p_output = &p_sys->pp_output[x][y];
732             if( !p_output->b_active )
733                 continue;
734
735             /* */
736             picture_t *p_dst = pp_dst[p_output->i_output];
737
738             /* */
739             picture_CopyProperties( p_dst, p_src );
740
741             /* */
742             for( int i_plane = 0; i_plane < p_src->i_planes; i_plane++ )
743             {
744                 const int i_div_w = p_sys->p_chroma->pi_div_w[i_plane];
745                 const int i_div_h = p_sys->p_chroma->pi_div_h[i_plane];
746
747                 if( !i_div_w || !i_div_h )
748                     continue;
749
750                 const plane_t *p_srcp = &p_src->p[i_plane];
751                 const plane_t *p_dstp = &p_dst->p[i_plane];
752
753                 /* */
754                 panoramix_filter_t filter;
755                 filter.black.i_right  = p_output->filter.black.i_right / i_div_w;
756                 filter.black.i_left   = p_output->filter.black.i_left / i_div_w;
757                 filter.black.i_top    = p_output->filter.black.i_top / i_div_h;
758                 filter.black.i_bottom = p_output->filter.black.i_bottom / i_div_h;
759
760                 filter.attenuate.i_right  = p_output->filter.attenuate.i_right / i_div_w;
761                 filter.attenuate.i_left   = p_output->filter.attenuate.i_left / i_div_w;
762                 filter.attenuate.i_top    = p_output->filter.attenuate.i_top / i_div_h;
763                 filter.attenuate.i_bottom = p_output->filter.attenuate.i_bottom / i_div_h;
764
765                 /* */
766                 const int i_x = p_output->i_src_x/i_div_w;
767                 const int i_y = p_output->i_src_y/i_div_h;
768
769                 assert( p_sys->p_chroma->b_planar );
770                 FilterPlanar( p_dstp->p_pixels, p_dstp->i_pitch,
771                               &p_srcp->p_pixels[i_y * p_srcp->i_pitch + i_x * p_srcp->i_pixel_pitch], p_srcp->i_pitch,
772                               p_output->i_src_width/i_div_w, p_output->i_src_height/i_div_h,
773                               p_sys->p_chroma->pi_black[i_plane],
774                               &filter,
775                               p_sys->p_lut[i_plane],
776                               p_sys->lambdav[i_plane],
777                               p_sys->lambdah[i_plane] );
778             }
779         }
780     }
781
782     picture_Release( p_src );
783     return VLC_SUCCESS;
784 }
785
786 /**
787  * It converts mouse events
788  */
789 static int Mouse( video_splitter_t *p_splitter, vlc_mouse_t *p_mouse,
790                   int i_index,
791                   const vlc_mouse_t *p_old, const vlc_mouse_t *p_new )
792 {
793     video_splitter_sys_t *p_sys = p_splitter->p_sys;
794     VLC_UNUSED(p_old);
795
796     for( int y = 0; y < p_sys->i_row; y++ )
797     {
798         for( int x = 0; x < p_sys->i_col; x++ )
799         {
800             const panoramix_output_t *p_output = p_output = &p_sys->pp_output[x][y];
801             if( p_output->b_active && p_output->i_output == i_index )
802             {
803                 const int i_x = p_new->i_x - p_output->filter.black.i_left;
804                 const int i_y = p_new->i_y - p_output->filter.black.i_top;
805                 if( i_x >= 0 && i_x < p_output->i_width  - p_output->filter.black.i_right &&
806                     i_y >= 0 && i_y < p_output->i_height - p_output->filter.black.i_bottom )
807                 {
808                     *p_mouse = *p_new;
809                     p_mouse->i_x = p_output->i_src_x + i_x;
810                     p_mouse->i_y = p_output->i_src_y + i_y;
811                     return VLC_SUCCESS;
812                 }
813             }
814         }
815     }
816     return VLC_EGENERIC;
817 }
818
819 /* It return a coefficient between 0.0 and 1.0 to be applied to the given
820  * value
821  */
822 static double GammaFactor( const panoramix_gamma_t *g, float f_value )
823 {
824     if( f_value <= g->f_black_crush )
825     {
826         float f_input = f_value * g->f_black_level / g->f_black_crush + (1.0 - g->f_black_level);
827
828         return pow( f_input, 1.0 / g->f_gamma );
829     }
830     else if( f_value >= g->f_white_crush )
831     {
832         float f_input = (f_value * (1.0 - (g->f_white_level + 1.0)) + (g->f_white_level + 1.0) * g->f_white_crush - 1.0) / (g->f_white_crush - 1.0);
833         return pow( f_input, 1.0 / g->f_gamma );
834     }
835     return 1.0;
836 }
837
838 /**
839  * It creates the panoramix configuration
840  */
841 static int Configuration( panoramix_output_t pp_output[ROW_MAX][COL_MAX],
842                           int i_col, int i_row,
843                           int i_src_width, int i_src_height,
844                           int i_half_w, int i_half_h,
845                           bool b_attenuate,
846                           const bool *pb_active )
847 {
848 #ifdef OVERLAP
849     const bool b_overlap = true;
850 #else
851     const bool b_overlap = false;
852 #endif
853
854     /* */
855     int i_output = 0;
856     for( int y = 0, i_src_y = 0, i_dst_y = 0; y < i_row; y++ )
857     {
858         const bool b_row_first = y == 0;
859         const bool b_row_last  = y == i_row - 1;
860
861         /* Compute source height */
862         int i_win_height = (i_src_height / i_row ) & ~1;
863         if( b_row_last )
864             i_win_height = i_src_height - y * i_win_height;
865
866         for( int x = 0, i_src_x = 0, i_dst_x = 0; x < i_col; x++ )
867         {
868             const bool b_col_first = x == 0;
869             const bool b_col_last  = x == i_col - 1;
870
871             /* Compute source width */
872             int i_win_width  = (i_src_width  / i_col ) & ~1;
873             if( b_col_last )
874                 i_win_width  = i_src_width  - x * i_win_width;
875
876             /* Compute filter configuration */
877             panoramix_filter_t cfg;
878
879             memset( &cfg, 0, sizeof(cfg) );
880             if( b_overlap && b_attenuate )
881             {
882                 if( i_col > 2 )
883                 {
884                     if( b_col_first )
885                         cfg.black.i_left   = i_half_w;
886                     if( b_col_last )
887                         cfg.black.i_right  = i_half_w;
888                 }
889                 if( i_row > 2 )
890                 {
891                     if( b_row_first )
892                         cfg.black.i_top    = i_half_h;
893                     if( b_row_last )
894                         cfg.black.i_bottom = i_half_h;
895                 }
896                 if( !b_col_first )
897                     cfg.attenuate.i_left   = 2 * i_half_w;
898                 if( !b_col_last )
899                     cfg.attenuate.i_right  = 2 * i_half_w;
900                 if( !b_row_first )
901                     cfg.attenuate.i_top    = 2 * i_half_h;
902                 if( !b_row_last )
903                     cfg.attenuate.i_bottom = 2 * i_half_h;
904             }
905
906             /* Compute alignment */
907             int i_align = 0;
908             if( i_col > 1 )
909             {
910                 if( b_col_first )
911                     i_align |= VOUT_ALIGN_RIGHT;
912                 if( b_col_last )
913                     i_align |= VOUT_ALIGN_LEFT;
914             }
915             if( i_row > 1 )
916             {
917                 if( b_row_first )
918                     i_align |= VOUT_ALIGN_BOTTOM;
919                 if( b_row_last )
920                     i_align |= VOUT_ALIGN_TOP;
921             }
922
923             /* */
924             panoramix_output_t *p_output = &pp_output[x][y];
925
926             /* */
927             p_output->i_src_x = i_src_x - cfg.attenuate.i_left/2;
928             p_output->i_src_y = i_src_y - cfg.attenuate.i_top/2;
929             p_output->i_src_width  = i_win_width  + cfg.attenuate.i_left/2 + cfg.attenuate.i_right/2;
930             p_output->i_src_height = i_win_height + cfg.attenuate.i_top/2  + cfg.attenuate.i_bottom/2;
931
932             /* */
933             p_output->filter = cfg;
934
935             /* */
936             p_output->i_align = i_align;
937             p_output->i_x = i_dst_x;
938             p_output->i_y = i_dst_y;
939
940             p_output->i_width  = cfg.black.i_left + p_output->i_src_width  + cfg.black.i_right;
941             p_output->i_height = cfg.black.i_top  + p_output->i_src_height + cfg.black.i_bottom;
942
943             /* */
944             p_output->b_active = pb_active[y * i_col + x] &&
945                                  p_output->i_width > 0 &&
946                                  p_output->i_height > 0;
947             if( p_output->b_active )
948                 p_output->i_output = i_output++;
949
950             /* */
951             i_src_x += i_win_width;
952             i_dst_x += p_output->i_width;
953         }
954         i_src_y += i_win_height;
955         i_dst_y += pp_output[0][y].i_height;
956     }
957     return i_output;
958 }
959
960 /**
961  * It filters a video plane
962  */
963 static void FilterPlanar( uint8_t *p_out, int i_out_pitch,
964                           const uint8_t *p_in, int i_in_pitch,
965                           int i_copy_pitch,
966                           int i_copy_lines,
967                           int i_pixel_black,
968                           const panoramix_filter_t *p_cfg,
969                           uint8_t p_lut[ACCURACY + 1][256],
970                           int lambdav[2][ACCURACY/2],
971                           int lambdah[2][ACCURACY/2] )
972 {
973     /* */
974     assert( !p_cfg->black.i_left   || !p_cfg->attenuate.i_left );
975     assert( !p_cfg->black.i_right  || !p_cfg->attenuate.i_right );
976     assert( !p_cfg->black.i_top    || !p_cfg->attenuate.i_top );
977     assert( !p_cfg->black.i_bottom || !p_cfg->attenuate.i_bottom );
978
979     const int i_out_width = p_cfg->black.i_left + i_copy_pitch + p_cfg->black.i_right;
980
981     /* Top black border */
982     for( int b = 0; b < p_cfg->black.i_top; b++ )
983     {
984         vlc_memset( p_out, i_pixel_black, i_out_width );
985         p_out += i_out_pitch;
986     }
987
988     for( int y = 0; y < i_copy_lines; y++ )
989     {
990         const uint8_t *p_src = p_in;
991         uint8_t *p_dst = p_out;
992
993         /* Black border on the left */
994         if( p_cfg->black.i_left > 0 )
995         {
996             memset( p_dst, i_pixel_black, p_cfg->black.i_left );
997             p_dst += p_cfg->black.i_left;
998         }
999         /* Attenuated video on the left */
1000         for( int i = 0; i < p_cfg->attenuate.i_left; i++ )
1001             *p_dst++ = p_lut[lambdav[0][i]][*p_src++];
1002
1003         /* Unmodified video */
1004         const int i_unmodified_width = i_copy_pitch - p_cfg->attenuate.i_left - p_cfg->attenuate.i_right;
1005         vlc_memcpy( p_dst, p_src, i_unmodified_width );
1006         p_dst += i_unmodified_width;
1007         p_src += i_unmodified_width;
1008
1009         /* Attenuated video on the right */
1010         for( int i = 0; i < p_cfg->attenuate.i_right; i++ )
1011             *p_dst++ = p_lut[lambdav[1][i]][*p_src++];
1012         /* Black border on the right */
1013         if( p_cfg->black.i_right > 0 )
1014         {
1015             memset( p_dst, i_pixel_black, p_cfg->black.i_right );
1016             p_dst += p_cfg->black.i_right;
1017         }
1018
1019         /* Attenuate complete line at top/bottom */
1020         const bool b_attenuate_top    = y < p_cfg->attenuate.i_top;
1021         const bool b_attenuate_bottom = y >= i_copy_lines - p_cfg->attenuate.i_bottom;
1022         if( b_attenuate_top || b_attenuate_bottom )
1023         {
1024             const int i_index = b_attenuate_top ? lambdah[0][y] : lambdah[1][y - (i_copy_lines - p_cfg->attenuate.i_bottom)];
1025             uint8_t *p_dst = &p_out[0];
1026             for( int i = 0; i < i_out_width; i++)
1027                 p_dst[i] = p_lut[i_index][p_dst[i]];
1028         }
1029
1030         /* */
1031         p_in  += i_in_pitch;
1032         p_out += i_out_pitch;
1033     }
1034     /* Bottom black border */
1035     for( int b = 0; b < p_cfg->black.i_bottom; b++ )
1036     {
1037         vlc_memset( p_out, i_pixel_black, i_out_width );
1038         p_out += i_out_pitch;
1039     }
1040 }
1041
1042
1043
1044 #if 0
1045 static void RenderPackedRGB( vout_thread_t *p_vout, picture_t *p_pic )
1046 {
1047     int length;
1048     length = 2 * p_sys->i_overlap_w2 * p_pic->p->i_pixel_pitch;
1049
1050     if (p_sys->b_has_changed)
1051     {
1052         int i_plane_;
1053         int i_col_mod;
1054         Denom = F2(length / p_pic->p->i_pixel_pitch);
1055         a_2 = p_sys->a_2 * (ACCURACY / 100);
1056         a_1 = p_sys->a_1 * 2 * p_sys->i_overlap_w2 * (ACCURACY / 100);
1057         a_0 = p_sys->a_0 * Denom * (ACCURACY / 100);
1058         for(i_col_mod = 0; i_col_mod < 2; i_col_mod++)
1059             for (i_index = 0; i_index < length / p_pic->p->i_pixel_pitch; i_index++)
1060                 for (i_plane_ =  0; i_plane_ < p_pic->p->i_pixel_pitch; i_plane_++)
1061                     p_sys->lambda[i_col_mod][i_plane_][i_index] = clip_accuracy(!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);
1062     }
1063
1064     length = 2 * p_sys->i_overlap_h2;
1065     if (p_sys->b_has_changed)
1066     {
1067         int i_plane_;
1068         int i_row_mod;
1069         Denom = F2(length);
1070         a_2 = p_sys->a_2 * (ACCURACY / 100);
1071         a_1 = p_sys->a_1 * length * (ACCURACY / 100);
1072         a_0 = p_sys->a_0 * Denom * (ACCURACY / 100);
1073         for(i_row_mod = 0; i_row_mod < 2; i_row_mod++)
1074           for (i_index = 0; i_index < length; i_index++)
1075             for (i_plane_ =  0; i_plane_ < p_pic->p->i_pixel_pitch; i_plane_++)
1076                 p_sys->lambda2[i_row_mod][i_plane_][i_index] = clip_accuracy(!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);
1077     }
1078 }
1079 #endif
1080
1081