]> git.sesse.net Git - vlc/blob - modules/video_filter/panoramix.c
4c23398d6a57a6abdaef908eb15684e85862f8d5
[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", true, 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     free( psz_display );
348     if( xcb_connection_has_error( conn ) )
349         return 0;
350
351     const xcb_setup_t *setup = xcb_get_setup( conn );
352     xcb_screen_t *scr = NULL;
353     for( xcb_screen_iterator_t i = xcb_setup_roots_iterator( setup );
354          i.rem > 0; xcb_screen_next( &i ) )
355     {
356          if( snum == 0 )
357          {
358              scr = i.data;
359              break;
360          }
361          snum--;
362     }
363
364     unsigned n = 0;
365     if( scr == NULL )
366         goto error;
367
368     xcb_randr_query_version_reply_t *v =
369         xcb_randr_query_version_reply( conn,
370             xcb_randr_query_version( conn, 1, 2 ), NULL );
371     if( v == NULL )
372         goto error;
373     msg_Dbg( obj, "using X RandR extension v%"PRIu32".%"PRIu32,
374              v->major_version, v->minor_version );
375     free( v );
376
377     xcb_randr_get_screen_resources_reply_t *r =
378         xcb_randr_get_screen_resources_reply( conn,
379             xcb_randr_get_screen_resources( conn, scr->root ), NULL );
380     if( r == NULL )
381         goto error;
382
383     const xcb_randr_output_t *outputs =
384         xcb_randr_get_screen_resources_outputs( r );
385     for( unsigned i = 0; i < r->num_outputs; i++ )
386     {
387         xcb_randr_get_output_info_reply_t *output =
388             xcb_randr_get_output_info_reply( conn,
389                 xcb_randr_get_output_info( conn, outputs[i], 0 ), NULL );
390         if( output == NULL )
391             continue;
392         /* FIXME: do not count cloned outputs multiple times */
393         /* XXX: what to do with UNKNOWN state connections? */
394         n += output->connection == XCB_RANDR_CONNECTION_CONNECTED;
395         free( output );
396     }
397     free( r );
398     msg_Dbg( obj, "X randr has %u outputs", n );
399
400 error:
401     xcb_disconnect( conn );
402     return n;
403 }
404 #endif
405
406 /*****************************************************************************
407  * Open: allocates Wall video thread output method
408  *****************************************************************************
409  * This function allocates and initializes a Wall vout method.
410  *****************************************************************************/
411 static int Open( vlc_object_t *p_this )
412 {
413     video_splitter_t *p_splitter = (video_splitter_t*)p_this;
414     video_splitter_sys_t *p_sys;
415
416     const panoramix_chroma_t *p_chroma;
417     for( int i = 0; ; i++ )
418     {
419         vlc_fourcc_t i_chroma = p_chroma_array[i].i_chroma;
420         if( !i_chroma )
421         {
422             msg_Err( p_splitter, "colorspace not supported by plug-in !" );
423             return VLC_EGENERIC;
424         }
425         if( i_chroma == p_splitter->fmt.i_chroma )
426         {
427             p_chroma = &p_chroma_array[i];
428             break;
429         }
430     }
431
432     /* Allocate structure */
433     p_splitter->p_sys = p_sys = malloc( sizeof( *p_sys ) );
434     if( !p_sys )
435         return VLC_ENOMEM;
436
437     /* */
438     p_sys->p_chroma = p_chroma;
439
440     /* */
441     config_ChainParse( p_splitter, CFG_PREFIX, ppsz_filter_options,
442                        p_splitter->p_cfg );
443
444     /* */
445     p_sys->i_col = var_CreateGetInteger( p_splitter, CFG_PREFIX "cols" );
446     p_sys->i_row = var_CreateGetInteger( p_splitter, CFG_PREFIX "rows" );
447
448     /* Autodetect number of displays */
449     if( p_sys->i_col < 0 || p_sys->i_row < 0 )
450     {
451 #ifdef WIN32
452         const int i_monitor_count = GetSystemMetrics(SM_CMONITORS);
453         if( i_monitor_count > 1 )
454         {
455             p_sys->i_col = GetSystemMetrics( SM_CXVIRTUALSCREEN ) / GetSystemMetrics( SM_CXSCREEN );
456             p_sys->i_row = GetSystemMetrics( SM_CYVIRTUALSCREEN ) / GetSystemMetrics( SM_CYSCREEN );
457             if( p_sys->i_col * p_sys->i_row != i_monitor_count )
458             {
459                 p_sys->i_col = i_monitor_count;
460                 p_sys->i_row = 1;
461             }
462         }
463 #else
464         const unsigned i_monitors = CountMonitors( p_this );
465         if( i_monitors > 1 ) /* Find closest to square */
466             for( unsigned w = 1; (i_monitors / w) >= w ; w++ )
467             {
468                 if( i_monitors % w )
469                     continue;
470                 p_sys->i_row = w;
471                 p_sys->i_col = i_monitors / w;
472             }
473 #endif
474         /* By default do 2x1 */
475         if( p_sys->i_row < 0 )
476             p_sys->i_row = 1;
477         if( p_sys->i_col < 0 )
478             p_sys->i_col = 2;
479         var_SetInteger( p_splitter, CFG_PREFIX "cols", p_sys->i_col);
480         var_SetInteger( p_splitter, CFG_PREFIX "rows", p_sys->i_row);
481     }
482
483     /* */
484     p_sys->b_attenuate = var_CreateGetBool( p_splitter, CFG_PREFIX "attenuate");
485     p_sys->bz_length = var_CreateGetInteger( p_splitter, CFG_PREFIX "bz-length" );
486     p_sys->bz_height = var_CreateGetInteger( p_splitter, CFG_PREFIX "bz-height" );
487     p_sys->bz_begin = var_CreateGetInteger( p_splitter, CFG_PREFIX "bz-begin" );
488     p_sys->bz_middle = var_CreateGetInteger( p_splitter, CFG_PREFIX "bz-middle" );
489     p_sys->bz_end = var_CreateGetInteger( p_splitter, CFG_PREFIX "bz-end" );
490     p_sys->bz_middle_pos = var_CreateGetInteger( p_splitter, CFG_PREFIX "bz-middle-pos" );
491     double d_p = 100.0 / p_sys->bz_middle_pos;
492
493     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;
494     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;
495     p_sys->a_0 =  p_sys->bz_begin;
496
497     /* */
498     p_sys->i_col = __MAX( 1, __MIN( COL_MAX, p_sys->i_col ) );
499     p_sys->i_row = __MAX( 1, __MIN( ROW_MAX, p_sys->i_row ) );
500     msg_Dbg( p_splitter, "opening a %i x %i wall",
501              p_sys->i_col, p_sys->i_row );
502
503     if( p_sys->bz_length > 0 && ( p_sys->i_row > 1 || p_sys->i_col > 1 ) )
504     {
505         const int i_overlap_w2_max = p_splitter->fmt.i_width  / p_sys->i_col / 2;
506         const int i_overlap_h2_max = p_splitter->fmt.i_height / p_sys->i_row / 2;
507         const int i_overlap2_max = __MIN( i_overlap_w2_max, i_overlap_h2_max );
508
509         if( p_sys->i_col > 1 )
510             p_sys->i_overlap_w2 = i_overlap2_max * p_sys->bz_length / 100;
511         else
512             p_sys->i_overlap_w2 = 0;
513
514         if( p_sys->i_row > 1 )
515             p_sys->i_overlap_h2 = i_overlap2_max * p_sys->bz_height / 100;
516         else
517             p_sys->i_overlap_h2 = 0;
518
519         /* */
520         int i_div_max_w = 1;
521         int i_div_max_h = 1;
522         for( int i = 0; i < VOUT_MAX_PLANES; i++ )
523         {
524             i_div_max_w = __MAX( i_div_max_w, p_chroma->pi_div_w[i] );
525             i_div_max_h = __MAX( i_div_max_h, p_chroma->pi_div_h[i] );
526         }
527         p_sys->i_overlap_w2 = i_div_max_w * (p_sys->i_overlap_w2 / i_div_max_w);
528         p_sys->i_overlap_h2 = i_div_max_h * (p_sys->i_overlap_h2 / i_div_max_h);
529     }
530     else
531     {
532         p_sys->i_overlap_w2 = 0;
533         p_sys->i_overlap_h2 = 0;
534     }
535
536     /* Compute attenuate parameters */
537     if( p_sys->b_attenuate )
538     {
539         panoramix_gamma_t p_gamma[VOUT_MAX_PLANES];
540
541         p_gamma[0].f_gamma = var_CreateGetFloat( p_splitter, CFG_PREFIX "bz-gamma-red" );
542         p_gamma[1].f_gamma = var_CreateGetFloat( p_splitter, CFG_PREFIX "bz-gamma-green" );
543         p_gamma[2].f_gamma = var_CreateGetFloat( p_splitter, CFG_PREFIX "bz-gamma-blue" );
544
545         p_gamma[0].f_black_crush = var_CreateGetInteger( p_splitter, CFG_PREFIX "bz-blackcrush-red" ) / 255.0;
546         p_gamma[1].f_black_crush = var_CreateGetInteger( p_splitter, CFG_PREFIX "bz-blackcrush-green" ) / 255.0;
547         p_gamma[2].f_black_crush = var_CreateGetInteger( p_splitter, CFG_PREFIX "bz-blackcrush-blue" ) / 255.0;
548         p_gamma[0].f_white_crush = var_CreateGetInteger( p_splitter, CFG_PREFIX "bz-whitecrush-red" ) / 255.0;
549         p_gamma[1].f_white_crush = var_CreateGetInteger( p_splitter, CFG_PREFIX "bz-whitecrush-green" ) / 255.0;
550         p_gamma[2].f_white_crush = var_CreateGetInteger( p_splitter, CFG_PREFIX "bz-whitecrush-blue" ) / 255.0;
551
552         p_gamma[0].f_black_level = var_CreateGetInteger( p_splitter, CFG_PREFIX "bz-blacklevel-red" ) / 255.0;
553         p_gamma[1].f_black_level = var_CreateGetInteger( p_splitter, CFG_PREFIX "bz-blacklevel-green" ) / 255.0;
554         p_gamma[2].f_black_level = var_CreateGetInteger( p_splitter, CFG_PREFIX "bz-blacklevel-blue" ) / 255.0;
555         p_gamma[0].f_white_level = var_CreateGetInteger( p_splitter, CFG_PREFIX "bz-whitelevel-red" ) / 255.0;
556         p_gamma[1].f_white_level = var_CreateGetInteger( p_splitter, CFG_PREFIX "bz-whitelevel-green" ) / 255.0;
557         p_gamma[2].f_white_level = var_CreateGetInteger( p_splitter, CFG_PREFIX "bz-whitelevel-blue" ) / 255.0;
558
559         for( int i = 3; i < VOUT_MAX_PLANES; i++ )
560         {
561             /* Initialize unsupported planes */
562             p_gamma[i].f_gamma = 1.0;
563             p_gamma[i].f_black_crush = 140.0/255.0;
564             p_gamma[i].f_white_crush = 200.0/255.0;
565             p_gamma[i].f_black_level = 150.0/255.0;
566             p_gamma[i].f_white_level = 0.0/255.0;
567         }
568
569         if( p_chroma->i_chroma == VLC_CODEC_YV12 )
570         {
571             /* Exchange U and V */
572             panoramix_gamma_t t = p_gamma[1];
573             p_gamma[1] = p_gamma[2];
574             p_gamma[2] = t;
575         }
576         
577         for( int i_index = 0; i_index < 256; i_index++ )
578         {
579             for( int i_index2 = 0; i_index2 <= ACCURACY; i_index2++ )
580             {
581                 for( int i_plane = 0; i_plane < VOUT_MAX_PLANES; i_plane++ )
582                 {
583                     double f_factor = GammaFactor( &p_gamma[i_plane], (float)i_index / 255.0 );
584
585                     float f_lut = clip_unit( 1.0 - ((ACCURACY - (float)i_index2) * f_factor / (ACCURACY - 1)) );
586
587                     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] );
588                 }
589             }
590         }
591
592         for( int i_plane = 0; i_plane < VOUT_MAX_PLANES; i_plane++ )
593         {
594             if( !p_chroma->pi_div_w[i_plane] || !p_chroma->pi_div_h[i_plane] )
595                 continue;
596             const int i_length_w = (2 * p_sys->i_overlap_w2) / p_chroma->pi_div_w[i_plane];
597             const int i_length_h = (2 * p_sys->i_overlap_h2) / p_chroma->pi_div_h[i_plane];
598
599             for( int i_dir = 0; i_dir < 2; i_dir++ )
600             {
601                 const int i_length = i_dir == 0 ? i_length_w : i_length_h;
602                 const int i_den = i_length * i_length;
603                 const int a_2 = p_sys->a_2 * (ACCURACY / 100);
604                 const int a_1 = p_sys->a_1 * i_length * (ACCURACY / 100);
605                 const int a_0 = p_sys->a_0 * i_den * (ACCURACY / 100);
606
607                 for( int i_position = 0; i_position < 2; i_position++ )
608                 {
609                     for( int i_index = 0; i_index < i_length; i_index++ )
610                     {
611                         const int v = i_position == 1 ? i_index : (i_length - i_index);
612                         const int i_lambda = clip_accuracy( ACCURACY - (a_2 * v*v + a_1 * v + a_0) / i_den );
613
614                         if( i_dir == 0 )
615                             p_sys->lambdav[i_plane][i_position][i_index] = i_lambda;
616                         else
617                             p_sys->lambdah[i_plane][i_position][i_index] = i_lambda;
618                     }
619                 }
620             }
621         }
622     }
623
624     /* */
625     char *psz_state = var_CreateGetNonEmptyString( p_splitter, CFG_PREFIX "active" );
626
627     /* */
628     bool pb_active[COL_MAX*ROW_MAX];
629
630     for( int i = 0; i < COL_MAX*ROW_MAX; i++ )
631         pb_active[i] = psz_state == NULL;
632
633     /* Parse active list if provided */
634     char *psz_tmp = psz_state;
635     while( psz_tmp && *psz_tmp )
636     {
637         char *psz_next = strchr( psz_tmp, ',' );
638         if( psz_next )
639             *psz_next++ = '\0';
640
641         const int i_index = atoi( psz_tmp );
642         if( i_index >= 0 && i_index < COL_MAX*ROW_MAX )
643             pb_active[i_index] = true;
644
645         psz_tmp = psz_next;
646     }
647     free( psz_state );
648
649     /* */
650     p_splitter->i_output =
651         Configuration( p_sys->pp_output,
652                        p_sys->i_col, p_sys->i_row,
653                        p_splitter->fmt.i_width, p_splitter->fmt.i_height,
654                        p_sys->i_overlap_w2, p_sys->i_overlap_h2,
655                        p_sys->b_attenuate,
656                        pb_active );
657     p_splitter->p_output = calloc( p_splitter->i_output,
658                                    sizeof(*p_splitter->p_output) );
659     if( !p_splitter->p_output )
660     {
661         free( p_sys );
662         return VLC_ENOMEM;
663     }
664
665     for( int y = 0; y < p_sys->i_row; y++ )
666     {
667         for( int x = 0; x < p_sys->i_col; x++ )
668         {
669             panoramix_output_t *p_output = &p_sys->pp_output[x][y];
670             if( !p_output->b_active )
671                 continue;
672
673             video_splitter_output_t *p_cfg = &p_splitter->p_output[p_output->i_output];
674
675             /* */
676             video_format_Copy( &p_cfg->fmt, &p_splitter->fmt );
677             p_cfg->fmt.i_visible_width  =
678             p_cfg->fmt.i_width          = p_output->i_width;
679             p_cfg->fmt.i_visible_height =
680             p_cfg->fmt.i_height         = p_output->i_height;
681
682             p_cfg->window.i_x     = p_output->i_x;
683             p_cfg->window.i_y     = p_output->i_y;
684             p_cfg->window.i_align = p_output->i_align;
685
686             p_cfg->psz_module = NULL;
687         }
688     }
689
690
691     /* */
692     p_splitter->pf_filter = Filter;
693     p_splitter->pf_mouse  = Mouse;
694
695     return VLC_SUCCESS;
696 }
697
698 /**
699  * Terminate a splitter module
700  */
701 static void Close( vlc_object_t *p_this )
702 {
703     video_splitter_t *p_splitter = (video_splitter_t*)p_this;
704     video_splitter_sys_t *p_sys = p_splitter->p_sys;
705
706     free( p_splitter->p_output );
707     free( p_sys );
708 }
709
710 /**
711  * It creates multiples pictures from the source one
712  */
713 static int Filter( video_splitter_t *p_splitter, picture_t *pp_dst[], picture_t *p_src )
714 {
715     video_splitter_sys_t *p_sys = p_splitter->p_sys;
716
717     if( video_splitter_NewPicture( p_splitter, pp_dst ) )
718     {
719         picture_Release( p_src );
720         return VLC_EGENERIC;
721     }
722
723     for( int y = 0; y < p_sys->i_row; y++ )
724     {
725         for( int x = 0; x < p_sys->i_col; x++ )
726         {
727             const panoramix_output_t *p_output = &p_sys->pp_output[x][y];
728             if( !p_output->b_active )
729                 continue;
730
731             /* */
732             picture_t *p_dst = pp_dst[p_output->i_output];
733
734             /* */
735             picture_CopyProperties( p_dst, p_src );
736
737             /* */
738             for( int i_plane = 0; i_plane < p_src->i_planes; i_plane++ )
739             {
740                 const int i_div_w = p_sys->p_chroma->pi_div_w[i_plane];
741                 const int i_div_h = p_sys->p_chroma->pi_div_h[i_plane];
742
743                 if( !i_div_w || !i_div_h )
744                     continue;
745
746                 const plane_t *p_srcp = &p_src->p[i_plane];
747                 const plane_t *p_dstp = &p_dst->p[i_plane];
748
749                 /* */
750                 panoramix_filter_t filter;
751                 filter.black.i_right  = p_output->filter.black.i_right / i_div_w;
752                 filter.black.i_left   = p_output->filter.black.i_left / i_div_w;
753                 filter.black.i_top    = p_output->filter.black.i_top / i_div_h;
754                 filter.black.i_bottom = p_output->filter.black.i_bottom / i_div_h;
755
756                 filter.attenuate.i_right  = p_output->filter.attenuate.i_right / i_div_w;
757                 filter.attenuate.i_left   = p_output->filter.attenuate.i_left / i_div_w;
758                 filter.attenuate.i_top    = p_output->filter.attenuate.i_top / i_div_h;
759                 filter.attenuate.i_bottom = p_output->filter.attenuate.i_bottom / i_div_h;
760
761                 /* */
762                 const int i_x = p_output->i_src_x/i_div_w;
763                 const int i_y = p_output->i_src_y/i_div_h;
764
765                 assert( p_sys->p_chroma->b_planar );
766                 FilterPlanar( p_dstp->p_pixels, p_dstp->i_pitch,
767                               &p_srcp->p_pixels[i_y * p_srcp->i_pitch + i_x * p_srcp->i_pixel_pitch], p_srcp->i_pitch,
768                               p_output->i_src_width/i_div_w, p_output->i_src_height/i_div_h,
769                               p_sys->p_chroma->pi_black[i_plane],
770                               &filter,
771                               p_sys->p_lut[i_plane],
772                               p_sys->lambdav[i_plane],
773                               p_sys->lambdah[i_plane] );
774             }
775         }
776     }
777
778     picture_Release( p_src );
779     return VLC_SUCCESS;
780 }
781
782 /**
783  * It converts mouse events
784  */
785 static int Mouse( video_splitter_t *p_splitter, vlc_mouse_t *p_mouse,
786                   int i_index,
787                   const vlc_mouse_t *p_old, const vlc_mouse_t *p_new )
788 {
789     video_splitter_sys_t *p_sys = p_splitter->p_sys;
790     VLC_UNUSED(p_old);
791
792     for( int y = 0; y < p_sys->i_row; y++ )
793     {
794         for( int x = 0; x < p_sys->i_col; x++ )
795         {
796             const panoramix_output_t *p_output = p_output = &p_sys->pp_output[x][y];
797             if( p_output->b_active && p_output->i_output == i_index )
798             {
799                 const int i_x = p_new->i_x - p_output->filter.black.i_left;
800                 const int i_y = p_new->i_y - p_output->filter.black.i_top;
801                 if( i_x >= 0 && i_x < p_output->i_width  - p_output->filter.black.i_right &&
802                     i_y >= 0 && i_y < p_output->i_height - p_output->filter.black.i_bottom )
803                 {
804                     *p_mouse = *p_new;
805                     p_mouse->i_x = p_output->i_src_x + i_x;
806                     p_mouse->i_y = p_output->i_src_y + i_y;
807                     return VLC_SUCCESS;
808                 }
809             }
810         }
811     }
812     return VLC_EGENERIC;
813 }
814
815 /* It return a coefficient between 0.0 and 1.0 to be applied to the given
816  * value
817  */
818 static double GammaFactor( const panoramix_gamma_t *g, float f_value )
819 {
820     if( f_value <= g->f_black_crush )
821     {
822         float f_input = f_value * g->f_black_level / g->f_black_crush + (1.0 - g->f_black_level);
823
824         return pow( f_input, 1.0 / g->f_gamma );
825     }
826     else if( f_value >= g->f_white_crush )
827     {
828         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);
829         return pow( f_input, 1.0 / g->f_gamma );
830     }
831     return 1.0;
832 }
833
834 /**
835  * It creates the panoramix configuration
836  */
837 static int Configuration( panoramix_output_t pp_output[ROW_MAX][COL_MAX],
838                           int i_col, int i_row,
839                           int i_src_width, int i_src_height,
840                           int i_half_w, int i_half_h,
841                           bool b_attenuate,
842                           const bool *pb_active )
843 {
844 #ifdef OVERLAP
845     const bool b_overlap = true;
846 #else
847     const bool b_overlap = false;
848 #endif
849
850     /* */
851     int i_output = 0;
852     for( int y = 0, i_src_y = 0, i_dst_y = 0; y < i_row; y++ )
853     {
854         const bool b_row_first = y == 0;
855         const bool b_row_last  = y == i_row - 1;
856
857         /* Compute source height */
858         int i_win_height = (i_src_height / i_row ) & ~1;
859         if( b_row_last )
860             i_win_height = i_src_height - y * i_win_height;
861
862         for( int x = 0, i_src_x = 0, i_dst_x = 0; x < i_col; x++ )
863         {
864             const bool b_col_first = x == 0;
865             const bool b_col_last  = x == i_col - 1;
866
867             /* Compute source width */
868             int i_win_width  = (i_src_width  / i_col ) & ~1;
869             if( b_col_last )
870                 i_win_width  = i_src_width  - x * i_win_width;
871
872             /* Compute filter configuration */
873             panoramix_filter_t cfg;
874
875             memset( &cfg, 0, sizeof(cfg) );
876             if( b_overlap && b_attenuate )
877             {
878                 if( i_col > 2 )
879                 {
880                     if( b_col_first )
881                         cfg.black.i_left   = i_half_w;
882                     if( b_col_last )
883                         cfg.black.i_right  = i_half_w;
884                 }
885                 if( i_row > 2 )
886                 {
887                     if( b_row_first )
888                         cfg.black.i_top    = i_half_h;
889                     if( b_row_last )
890                         cfg.black.i_bottom = i_half_h;
891                 }
892                 if( !b_col_first )
893                     cfg.attenuate.i_left   = 2 * i_half_w;
894                 if( !b_col_last )
895                     cfg.attenuate.i_right  = 2 * i_half_w;
896                 if( !b_row_first )
897                     cfg.attenuate.i_top    = 2 * i_half_h;
898                 if( !b_row_last )
899                     cfg.attenuate.i_bottom = 2 * i_half_h;
900             }
901
902             /* Compute alignment */
903             int i_align = 0;
904             if( i_col > 1 )
905             {
906                 if( b_col_first )
907                     i_align |= VOUT_ALIGN_RIGHT;
908                 if( b_col_last )
909                     i_align |= VOUT_ALIGN_LEFT;
910             }
911             if( i_row > 1 )
912             {
913                 if( b_row_first )
914                     i_align |= VOUT_ALIGN_BOTTOM;
915                 if( b_row_last )
916                     i_align |= VOUT_ALIGN_TOP;
917             }
918
919             /* */
920             panoramix_output_t *p_output = &pp_output[x][y];
921
922             /* */
923             p_output->i_src_x = i_src_x - cfg.attenuate.i_left/2;
924             p_output->i_src_y = i_src_y - cfg.attenuate.i_top/2;
925             p_output->i_src_width  = i_win_width  + cfg.attenuate.i_left/2 + cfg.attenuate.i_right/2;
926             p_output->i_src_height = i_win_height + cfg.attenuate.i_top/2  + cfg.attenuate.i_bottom/2;
927
928             /* */
929             p_output->filter = cfg;
930
931             /* */
932             p_output->i_align = i_align;
933             p_output->i_x = i_dst_x;
934             p_output->i_y = i_dst_y;
935
936             p_output->i_width  = cfg.black.i_left + p_output->i_src_width  + cfg.black.i_right;
937             p_output->i_height = cfg.black.i_top  + p_output->i_src_height + cfg.black.i_bottom;
938
939             /* */
940             p_output->b_active = pb_active[y * i_col + x] &&
941                                  p_output->i_width > 0 &&
942                                  p_output->i_height > 0;
943             if( p_output->b_active )
944                 p_output->i_output = i_output++;
945
946             /* */
947             i_src_x += i_win_width;
948             i_dst_x += p_output->i_width;
949         }
950         i_src_y += i_win_height;
951         i_dst_y += pp_output[0][y].i_height;
952     }
953     return i_output;
954 }
955
956 /**
957  * It filters a video plane
958  */
959 static void FilterPlanar( uint8_t *p_out, int i_out_pitch,
960                           const uint8_t *p_in, int i_in_pitch,
961                           int i_copy_pitch,
962                           int i_copy_lines,
963                           int i_pixel_black,
964                           const panoramix_filter_t *p_cfg,
965                           uint8_t p_lut[ACCURACY + 1][256],
966                           int lambdav[2][ACCURACY/2],
967                           int lambdah[2][ACCURACY/2] )
968 {
969     /* */
970     assert( !p_cfg->black.i_left   || !p_cfg->attenuate.i_left );
971     assert( !p_cfg->black.i_right  || !p_cfg->attenuate.i_right );
972     assert( !p_cfg->black.i_top    || !p_cfg->attenuate.i_top );
973     assert( !p_cfg->black.i_bottom || !p_cfg->attenuate.i_bottom );
974
975     const int i_out_width = p_cfg->black.i_left + i_copy_pitch + p_cfg->black.i_right;
976
977     /* Top black border */
978     for( int b = 0; b < p_cfg->black.i_top; b++ )
979     {
980         vlc_memset( p_out, i_pixel_black, i_out_width );
981         p_out += i_out_pitch;
982     }
983
984     for( int y = 0; y < i_copy_lines; y++ )
985     {
986         const uint8_t *p_src = p_in;
987         uint8_t *p_dst = p_out;
988
989         /* Black border on the left */
990         if( p_cfg->black.i_left > 0 )
991         {
992             memset( p_dst, i_pixel_black, p_cfg->black.i_left );
993             p_dst += p_cfg->black.i_left;
994         }
995         /* Attenuated video on the left */
996         for( int i = 0; i < p_cfg->attenuate.i_left; i++ )
997             *p_dst++ = p_lut[lambdav[0][i]][*p_src++];
998
999         /* Unmodified video */
1000         const int i_unmodified_width = i_copy_pitch - p_cfg->attenuate.i_left - p_cfg->attenuate.i_right;
1001         vlc_memcpy( p_dst, p_src, i_unmodified_width );
1002         p_dst += i_unmodified_width;
1003         p_src += i_unmodified_width;
1004
1005         /* Attenuated video on the right */
1006         for( int i = 0; i < p_cfg->attenuate.i_right; i++ )
1007             *p_dst++ = p_lut[lambdav[1][i]][*p_src++];
1008         /* Black border on the right */
1009         if( p_cfg->black.i_right > 0 )
1010         {
1011             memset( p_dst, i_pixel_black, p_cfg->black.i_right );
1012             p_dst += p_cfg->black.i_right;
1013         }
1014
1015         /* Attenuate complete line at top/bottom */
1016         const bool b_attenuate_top    = y < p_cfg->attenuate.i_top;
1017         const bool b_attenuate_bottom = y >= i_copy_lines - p_cfg->attenuate.i_bottom;
1018         if( b_attenuate_top || b_attenuate_bottom )
1019         {
1020             const int i_index = b_attenuate_top ? lambdah[0][y] : lambdah[1][y - (i_copy_lines - p_cfg->attenuate.i_bottom)];
1021             uint8_t *p_dst = &p_out[0];
1022             for( int i = 0; i < i_out_width; i++)
1023                 p_dst[i] = p_lut[i_index][p_dst[i]];
1024         }
1025
1026         /* */
1027         p_in  += i_in_pitch;
1028         p_out += i_out_pitch;
1029     }
1030     /* Bottom black border */
1031     for( int b = 0; b < p_cfg->black.i_bottom; b++ )
1032     {
1033         vlc_memset( p_out, i_pixel_black, i_out_width );
1034         p_out += i_out_pitch;
1035     }
1036 }
1037
1038
1039
1040 #if 0
1041 static void RenderPackedRGB( vout_thread_t *p_vout, picture_t *p_pic )
1042 {
1043     int length;
1044     length = 2 * p_sys->i_overlap_w2 * p_pic->p->i_pixel_pitch;
1045
1046     if (p_sys->b_has_changed)
1047     {
1048         int i_plane_;
1049         int i_col_mod;
1050         Denom = F2(length / p_pic->p->i_pixel_pitch);
1051         a_2 = p_sys->a_2 * (ACCURACY / 100);
1052         a_1 = p_sys->a_1 * 2 * p_sys->i_overlap_w2 * (ACCURACY / 100);
1053         a_0 = p_sys->a_0 * Denom * (ACCURACY / 100);
1054         for(i_col_mod = 0; i_col_mod < 2; i_col_mod++)
1055             for (i_index = 0; i_index < length / p_pic->p->i_pixel_pitch; i_index++)
1056                 for (i_plane_ =  0; i_plane_ < p_pic->p->i_pixel_pitch; i_plane_++)
1057                     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);
1058     }
1059
1060     length = 2 * p_sys->i_overlap_h2;
1061     if (p_sys->b_has_changed)
1062     {
1063         int i_plane_;
1064         int i_row_mod;
1065         Denom = F2(length);
1066         a_2 = p_sys->a_2 * (ACCURACY / 100);
1067         a_1 = p_sys->a_1 * length * (ACCURACY / 100);
1068         a_0 = p_sys->a_0 * Denom * (ACCURACY / 100);
1069         for(i_row_mod = 0; i_row_mod < 2; i_row_mod++)
1070           for (i_index = 0; i_index < length; i_index++)
1071             for (i_plane_ =  0; i_plane_ < p_pic->p->i_pixel_pitch; i_plane_++)
1072                 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);
1073     }
1074 }
1075 #endif
1076
1077