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