1 /*****************************************************************************
2 * panoramix.c : Wall panoramic video with edge blending plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2000, 2001, 2002, 2003 VideoLAN
7 * Authors: Cedric Cocquebert <cedric.cocquebert@supelec.fr>
8 * based on Samuel Hocevar <sam@zoy.org>
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.
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.
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 *****************************************************************************/
25 /*****************************************************************************
27 *****************************************************************************/
35 #include <vlc_common.h>
36 #include <vlc_plugin.h>
37 #include <vlc_video_splitter.h>
39 /* FIXME it is needed for VOUT_ALIGN_* only */
45 /* OS CODE DEPENDENT to get display dimensions */
49 # include <X11/Xlib.h>
53 /*****************************************************************************
55 *****************************************************************************/
56 #define COLS_TEXT N_("Number of columns")
57 #define COLS_LONGTEXT N_("Select the number of horizontal video windows in " \
58 "which to split the video")
60 #define ROWS_TEXT N_("Number of rows")
61 #define ROWS_LONGTEXT N_("Select the number of vertical video windows in " \
62 "which to split the video")
64 #define ACTIVE_TEXT N_("Active windows")
65 #define ACTIVE_LONGTEXT N_("Comma separated list of active windows, " \
68 #define CFG_PREFIX "panoramix-"
70 static int Open ( vlc_object_t * );
71 static void Close( vlc_object_t * );
74 set_description( N_("Panoramix: wall with overlap video filter") )
75 set_shortname( N_("Panoramix" ))
76 set_capability( "video splitter", 0 )
77 set_category( CAT_VIDEO )
78 set_subcategory( SUBCAT_VIDEO_VFILTER )
80 add_integer( CFG_PREFIX "cols", -1, NULL, COLS_TEXT, COLS_LONGTEXT, true )
81 add_integer( CFG_PREFIX "rows", -1, NULL, ROWS_TEXT, ROWS_LONGTEXT, true )
84 #define LENGTH_TEXT N_("length of the overlapping area (in %)")
85 #define LENGTH_LONGTEXT N_("Select in percent the length of the blended zone")
86 add_integer_with_range( CFG_PREFIX "bz-length", 100, 0, 100, NULL, LENGTH_TEXT, LENGTH_LONGTEXT, true )
88 #define HEIGHT_TEXT N_("height of the overlapping area (in %)")
89 #define HEIGHT_LONGTEXT N_("Select in percent the height of the blended zone (case of 2x2 wall)")
90 add_integer_with_range( CFG_PREFIX "bz-height", 100, 0, 100, NULL, HEIGHT_TEXT, HEIGHT_LONGTEXT, true )
92 #define ATTENUATION_TEXT N_("Attenuation")
93 #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)")
94 add_bool( CFG_PREFIX "attenuate", 1, NULL, ATTENUATION_TEXT, ATTENUATION_LONGTEXT, false )
96 #define BEGIN_TEXT N_("Attenuation, begin (in %)")
97 #define BEGIN_LONGTEXT N_("Select in percent the Lagrange coeff of the beginning blended zone")
98 add_integer_with_range( CFG_PREFIX "bz-begin", 0, 0, 100, NULL, BEGIN_TEXT, BEGIN_LONGTEXT, true )
100 #define MIDDLE_TEXT N_("Attenuation, middle (in %)")
101 #define MIDDLE_LONGTEXT N_("Select in percent the Lagrange coeff of the middle of blended zone")
102 add_integer_with_range( CFG_PREFIX "bz-middle", 50, 0, 100, NULL, MIDDLE_TEXT, MIDDLE_LONGTEXT, false )
104 #define END_TEXT N_("Attenuation, end (in %)")
105 #define END_LONGTEXT N_("Select in percent the Lagrange coeff of the end of blended zone")
106 add_integer_with_range( CFG_PREFIX "bz-end", 100, 0, 100, NULL, END_TEXT, END_LONGTEXT, true )
108 #define MIDDLE_POS_TEXT N_("middle position (in %)")
109 #define MIDDLE_POS_LONGTEXT N_("Select in percent (50 is center) the position of the middle point (Lagrange) of blended zone")
110 add_integer_with_range( CFG_PREFIX "bz-middle-pos", 50, 1, 99, NULL, MIDDLE_POS_TEXT, MIDDLE_POS_LONGTEXT, false )
111 #define RGAMMA_TEXT N_("Gamma (Red) correction")
112 #define RGAMMA_LONGTEXT N_("Select the gamma for the correction of blended zone (Red or Y component)")
113 add_float_with_range( CFG_PREFIX "bz-gamma-red", 1, 0, 5, NULL, RGAMMA_TEXT, RGAMMA_LONGTEXT, true )
115 #define GGAMMA_TEXT N_("Gamma (Green) correction")
116 #define GGAMMA_LONGTEXT N_("Select the gamma for the correction of blended zone (Green or U component)")
117 add_float_with_range( CFG_PREFIX "bz-gamma-green", 1, 0, 5, NULL, GGAMMA_TEXT, GGAMMA_LONGTEXT, true )
119 #define BGAMMA_TEXT N_("Gamma (Blue) correction")
120 #define BGAMMA_LONGTEXT N_("Select the gamma for the correction of blended zone (Blue or V component)")
121 add_float_with_range( CFG_PREFIX "bz-gamma-blue", 1, 0, 5, NULL, BGAMMA_TEXT, BGAMMA_LONGTEXT, true )
123 #define RGAMMA_BC_TEXT N_("Black Crush for Red")
124 #define RGAMMA_BC_LONGTEXT N_("Select the Black Crush of blended zone (Red or Y component)")
125 #define GGAMMA_BC_TEXT N_("Black Crush for Green")
126 #define GGAMMA_BC_LONGTEXT N_("Select the Black Crush of blended zone (Green or U component)")
127 #define BGAMMA_BC_TEXT N_("Black Crush for Blue")
128 #define BGAMMA_BC_LONGTEXT N_("Select the Black Crush of blended zone (Blue or V component)")
130 #define RGAMMA_WC_TEXT N_("White Crush for Red")
131 #define RGAMMA_WC_LONGTEXT N_("Select the White Crush of blended zone (Red or Y component)")
132 #define GGAMMA_WC_TEXT N_("White Crush for Green")
133 #define GGAMMA_WC_LONGTEXT N_("Select the White Crush of blended zone (Green or U component)")
134 #define BGAMMA_WC_TEXT N_("White Crush for Blue")
135 #define BGAMMA_WC_LONGTEXT N_("Select the White Crush of blended zone (Blue or V component)")
137 #define RGAMMA_BL_TEXT N_("Black Level for Red")
138 #define RGAMMA_BL_LONGTEXT N_("Select the Black Level of blended zone (Red or Y component)")
139 #define GGAMMA_BL_TEXT N_("Black Level for Green")
140 #define GGAMMA_BL_LONGTEXT N_("Select the Black Level of blended zone (Green or U component)")
141 #define BGAMMA_BL_TEXT N_("Black Level for Blue")
142 #define BGAMMA_BL_LONGTEXT N_("Select the Black Level of blended zone (Blue or V component)")
144 #define RGAMMA_WL_TEXT N_("White Level for Red")
145 #define RGAMMA_WL_LONGTEXT N_("Select the White Level of blended zone (Red or Y component)")
146 #define GGAMMA_WL_TEXT N_("White Level for Green")
147 #define GGAMMA_WL_LONGTEXT N_("Select the White Level of blended zone (Green or U component)")
148 #define BGAMMA_WL_TEXT N_("White Level for Blue")
149 #define BGAMMA_WL_LONGTEXT N_("Select the White Level of blended zone (Blue or V component)")
150 add_integer_with_range( CFG_PREFIX "bz-blackcrush-red", 140, 0, 255, NULL, RGAMMA_BC_TEXT, RGAMMA_BC_LONGTEXT, true )
151 add_integer_with_range( CFG_PREFIX "bz-blackcrush-green", 140, 0, 255, NULL, GGAMMA_BC_TEXT, GGAMMA_BC_LONGTEXT, true )
152 add_integer_with_range( CFG_PREFIX "bz-blackcrush-blue", 140, 0, 255, NULL, BGAMMA_BC_TEXT, BGAMMA_BC_LONGTEXT, true )
153 add_integer_with_range( CFG_PREFIX "bz-whitecrush-red", 200, 0, 255, NULL, RGAMMA_WC_TEXT, RGAMMA_WC_LONGTEXT, true )
154 add_integer_with_range( CFG_PREFIX "bz-whitecrush-green", 200, 0, 255, NULL, GGAMMA_WC_TEXT, GGAMMA_WC_LONGTEXT, true )
155 add_integer_with_range( CFG_PREFIX "bz-whitecrush-blue", 200, 0, 255, NULL, BGAMMA_WC_TEXT, BGAMMA_WC_LONGTEXT, true )
156 add_integer_with_range( CFG_PREFIX "bz-blacklevel-red", 150, 0, 255, NULL, RGAMMA_BL_TEXT, RGAMMA_BL_LONGTEXT, true )
157 add_integer_with_range( CFG_PREFIX "bz-blacklevel-green", 150, 0, 255, NULL, GGAMMA_BL_TEXT, GGAMMA_BL_LONGTEXT, true )
158 add_integer_with_range( CFG_PREFIX "bz-blacklevel-blue", 150, 0, 255, NULL, BGAMMA_BL_TEXT, BGAMMA_BL_LONGTEXT, true )
159 add_integer_with_range( CFG_PREFIX "bz-whitelevel-red", 0, 0, 255, NULL, RGAMMA_WL_TEXT, RGAMMA_WL_LONGTEXT, true )
160 add_integer_with_range( CFG_PREFIX "bz-whitelevel-green", 0, 0, 255, NULL, GGAMMA_WL_TEXT, GGAMMA_WL_LONGTEXT, true )
161 add_integer_with_range( CFG_PREFIX "bz-whitelevel-blue", 0, 0, 255, NULL, BGAMMA_WL_TEXT, BGAMMA_WL_LONGTEXT, true )
163 add_deprecated_alias( CFG_PREFIX "xinerama" );
165 add_deprecated_alias( CFG_PREFIX "offset-x" )
168 add_string( CFG_PREFIX "active", NULL, NULL, ACTIVE_TEXT, ACTIVE_LONGTEXT, true )
170 add_shortcut( "panoramix" )
171 set_callbacks( Open, Close )
175 /*****************************************************************************
177 *****************************************************************************/
178 static const char *const ppsz_filter_options[] = {
179 "cols", "rows", "bz-length", "bz-height", "attenuate",
180 "bz-begin", "bz-middle", "bz-end", "bz-middle-pos", "bz-gamma-red",
181 "bz-gamma-green", "bz-gamma-blue", "bz-blackcrush-red",
182 "bz-blackcrush-green", "bz-blackcrush-blue", "bz-whitecrush-red",
183 "bz-whitecrush-green", "bz-whitecrush-blue", "bz-blacklevel-red",
184 "bz-blacklevel-green", "bz-blacklevel-blue", "bz-whitelevel-red",
185 "bz-whitelevel-green", "bz-whitelevel-blue", "active",
192 #define ACCURACY 1000
195 static inline int clip_accuracy( int a )
197 return (a > ACCURACY) ? ACCURACY : (a < 0) ? 0 : a;
199 static inline float clip_unit( float f )
201 return f < 0.0 ? 0.0 : ( f > 1.0 ? 1.0 : f );
232 } panoramix_filter_t;
239 /* Output position and size */
246 /* Source position and size */
252 /* Filter configuration to use to create the output */
253 panoramix_filter_t filter;
255 } panoramix_output_t;
259 vlc_fourcc_t i_chroma;
261 const int pi_div_w[VOUT_MAX_PLANES];
262 const int pi_div_h[VOUT_MAX_PLANES];
264 const int pi_black[VOUT_MAX_PLANES];
268 } panoramix_chroma_t;
270 struct video_splitter_sys_t
272 const panoramix_chroma_t *p_chroma;
276 unsigned int bz_length, bz_height;
277 unsigned int bz_begin, bz_middle, bz_end;
278 unsigned int bz_middle_pos;
279 unsigned int a_0, a_1, a_2;
281 int lambdav[VOUT_MAX_PLANES][2][ACCURACY/2]; /* [plane][position][?] */
282 int lambdah[VOUT_MAX_PLANES][2][ACCURACY/2];
284 unsigned int i_overlap_w2; /* Half overlap width */
285 unsigned int i_overlap_h2; /* Half overlap height */
286 uint8_t p_lut[VOUT_MAX_PLANES][ACCURACY + 1][256];
291 panoramix_output_t pp_output[COL_MAX][ROW_MAX]; /* [x][y] */
295 static int Filter( video_splitter_t *, picture_t *pp_dst[], picture_t * );
297 static int Mouse( video_splitter_t *, vlc_mouse_t *,
299 const vlc_mouse_t *p_old, const vlc_mouse_t *p_new );
303 static int Configuration( panoramix_output_t pp_output[ROW_MAX][COL_MAX],
304 int i_col, int i_row,
305 int i_src_width, int i_src_height,
306 int i_half_w, int i_half_h,
308 const bool *pb_active );
309 static double GammaFactor( const panoramix_gamma_t *, float f_value );
311 static void FilterPlanar( uint8_t *p_out, int i_out_pitch,
312 const uint8_t *p_in, int i_in_pitch,
316 const panoramix_filter_t *,
317 uint8_t p_lut[ACCURACY + 1][256],
318 int lambdav[2][ACCURACY/2],
319 int lambdah[2][ACCURACY/2] );
322 static const panoramix_chroma_t p_chroma_array[] = {
324 { VLC_CODEC_I410, { 1, 4, 4, }, { 1, 1, 1, }, { 0, 128, 128 }, true },
325 { VLC_CODEC_I411, { 1, 4, 4, }, { 1, 4, 4, }, { 0, 128, 128 }, true },
326 { VLC_CODEC_YV12, { 1, 2, 2, }, { 1, 2, 2, }, { 0, 128, 128 }, true },
327 { VLC_CODEC_I420, { 1, 2, 2, }, { 1, 2, 2, }, { 0, 128, 128 }, true },
328 { VLC_CODEC_J420, { 1, 2, 2, }, { 1, 2, 2, }, { 0, 128, 128 }, true },
329 { VLC_CODEC_I422, { 1, 2, 2, }, { 1, 1, 1, }, { 0, 128, 128 }, true },
330 { VLC_CODEC_J422, { 1, 2, 2, }, { 1, 1, 1, }, { 0, 128, 128 }, true },
331 { VLC_CODEC_I440, { 1, 1, 1, }, { 1, 2, 2, }, { 0, 128, 128 }, true },
332 { VLC_CODEC_J440, { 1, 1, 1, }, { 1, 2, 2, }, { 0, 128, 128 }, true },
333 { VLC_CODEC_I444, { 1, 1, 1, }, { 1, 1, 1, }, { 0, 128, 128 }, true },
334 /* TODO packed chroma (yuv/rgb) ? */
336 { 0, {0, }, { 0, }, { 0, 0, 0 }, false }
339 /*****************************************************************************
340 * Open: allocates Wall video thread output method
341 *****************************************************************************
342 * This function allocates and initializes a Wall vout method.
343 *****************************************************************************/
344 static int Open( vlc_object_t *p_this )
346 video_splitter_t *p_splitter = (video_splitter_t*)p_this;
347 video_splitter_sys_t *p_sys;
349 const panoramix_chroma_t *p_chroma;
350 for( int i = 0; ; i++ )
352 vlc_fourcc_t i_chroma = p_chroma_array[i].i_chroma;
355 msg_Err( p_splitter, "colorspace not supported by plug-in !" );
358 if( i_chroma == p_splitter->fmt.i_chroma )
360 p_chroma = &p_chroma_array[i];
365 /* Allocate structure */
366 p_splitter->p_sys = p_sys = malloc( sizeof( *p_sys ) );
371 p_sys->p_chroma = p_chroma;
374 config_ChainParse( p_splitter, CFG_PREFIX, ppsz_filter_options,
378 p_sys->i_col = var_CreateGetInteger( p_splitter, CFG_PREFIX "cols" );
379 p_sys->i_row = var_CreateGetInteger( p_splitter, CFG_PREFIX "rows" );
381 /* Autodetect number of displays */
382 if( p_sys->i_col < 0 || p_sys->i_row < 0 )
385 const int i_monitor_count = GetSystemMetrics(SM_CMONITORS);
386 if( i_monitor_count > 1 )
388 p_sys->i_col = GetSystemMetrics( SM_CXVIRTUALSCREEN ) / GetSystemMetrics( SM_CXSCREEN );
389 p_sys->i_row = GetSystemMetrics( SM_CYVIRTUALSCREEN ) / GetSystemMetrics( SM_CYSCREEN );
390 if( p_sys->i_col * p_sys->i_row != i_monitor_count )
392 p_sys->i_col = i_monitor_count;
399 /* By default do 2x1 */
400 if( p_sys->i_col < 0 || p_sys->i_row < 0 )
405 var_SetInteger( p_splitter, CFG_PREFIX "cols", p_sys->i_col);
406 var_SetInteger( p_splitter, CFG_PREFIX "rows", p_sys->i_row);
410 p_sys->b_attenuate = var_CreateGetBool( p_splitter, CFG_PREFIX "attenuate");
411 p_sys->bz_length = var_CreateGetInteger( p_splitter, CFG_PREFIX "bz-length" );
412 p_sys->bz_height = var_CreateGetInteger( p_splitter, CFG_PREFIX "bz-height" );
413 p_sys->bz_begin = var_CreateGetInteger( p_splitter, CFG_PREFIX "bz-begin" );
414 p_sys->bz_middle = var_CreateGetInteger( p_splitter, CFG_PREFIX "bz-middle" );
415 p_sys->bz_end = var_CreateGetInteger( p_splitter, CFG_PREFIX "bz-end" );
416 p_sys->bz_middle_pos = var_CreateGetInteger( p_splitter, CFG_PREFIX "bz-middle-pos" );
417 double d_p = 100.0 / p_sys->bz_middle_pos;
419 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;
420 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;
421 p_sys->a_0 = p_sys->bz_begin;
424 p_sys->i_col = __MAX( 1, __MIN( COL_MAX, p_sys->i_col ) );
425 p_sys->i_row = __MAX( 1, __MIN( ROW_MAX, p_sys->i_row ) );
426 msg_Dbg( p_splitter, "opening a %i x %i wall",
427 p_sys->i_col, p_sys->i_row );
429 if( p_sys->bz_length > 0 && ( p_sys->i_row > 1 || p_sys->i_col > 1 ) )
431 const int i_overlap_w2_max = p_splitter->fmt.i_width / p_sys->i_col / 2;
432 const int i_overlap_h2_max = p_splitter->fmt.i_height / p_sys->i_row / 2;
433 const int i_overlap2_max = __MIN( i_overlap_w2_max, i_overlap_h2_max );
435 if( p_sys->i_col > 1 )
436 p_sys->i_overlap_w2 = i_overlap2_max * p_sys->bz_length / 100;
438 p_sys->i_overlap_w2 = 0;
440 if( p_sys->i_row > 1 )
441 p_sys->i_overlap_h2 = i_overlap2_max * p_sys->bz_height / 100;
443 p_sys->i_overlap_h2 = 0;
448 for( int i = 0; i < VOUT_MAX_PLANES; i++ )
450 i_div_max_w = __MAX( i_div_max_w, p_chroma->pi_div_w[i] );
451 i_div_max_h = __MAX( i_div_max_h, p_chroma->pi_div_h[i] );
453 p_sys->i_overlap_w2 = i_div_max_w * (p_sys->i_overlap_w2 / i_div_max_w);
454 p_sys->i_overlap_h2 = i_div_max_h * (p_sys->i_overlap_h2 / i_div_max_h);
458 p_sys->i_overlap_w2 = 0;
459 p_sys->i_overlap_h2 = 0;
462 /* Compute attenuate parameters */
463 if( p_sys->b_attenuate )
465 panoramix_gamma_t p_gamma[VOUT_MAX_PLANES];
467 p_gamma[0].f_gamma = var_CreateGetFloat( p_splitter, CFG_PREFIX "bz-gamma-red" );
468 p_gamma[1].f_gamma = var_CreateGetFloat( p_splitter, CFG_PREFIX "bz-gamma-green" );
469 p_gamma[2].f_gamma = var_CreateGetFloat( p_splitter, CFG_PREFIX "bz-gamma-blue" );
471 p_gamma[0].f_black_crush = var_CreateGetInteger( p_splitter, CFG_PREFIX "bz-blackcrush-red" ) / 255.0;
472 p_gamma[1].f_black_crush = var_CreateGetInteger( p_splitter, CFG_PREFIX "bz-blackcrush-green" ) / 255.0;
473 p_gamma[2].f_black_crush = var_CreateGetInteger( p_splitter, CFG_PREFIX "bz-blackcrush-blue" ) / 255.0;
474 p_gamma[0].f_white_crush = var_CreateGetInteger( p_splitter, CFG_PREFIX "bz-whitecrush-red" ) / 255.0;
475 p_gamma[1].f_white_crush = var_CreateGetInteger( p_splitter, CFG_PREFIX "bz-whitecrush-green" ) / 255.0;
476 p_gamma[2].f_white_crush = var_CreateGetInteger( p_splitter, CFG_PREFIX "bz-whitecrush-blue" ) / 255.0;
478 p_gamma[0].f_black_level = var_CreateGetInteger( p_splitter, CFG_PREFIX "bz-blacklevel-red" ) / 255.0;
479 p_gamma[1].f_black_level = var_CreateGetInteger( p_splitter, CFG_PREFIX "bz-blacklevel-green" ) / 255.0;
480 p_gamma[2].f_black_level = var_CreateGetInteger( p_splitter, CFG_PREFIX "bz-blacklevel-blue" ) / 255.0;
481 p_gamma[0].f_white_level = var_CreateGetInteger( p_splitter, CFG_PREFIX "bz-whitelevel-red" ) / 255.0;
482 p_gamma[1].f_white_level = var_CreateGetInteger( p_splitter, CFG_PREFIX "bz-whitelevel-green" ) / 255.0;
483 p_gamma[2].f_white_level = var_CreateGetInteger( p_splitter, CFG_PREFIX "bz-whitelevel-blue" ) / 255.0;
485 for( int i = 3; i < VOUT_MAX_PLANES; i++ )
487 /* Initialize unsupported planes */
488 p_gamma[i].f_gamma = 1.0;
489 p_gamma[i].f_black_crush = 140.0/255.0;
490 p_gamma[i].f_white_crush = 200.0/255.0;
491 p_gamma[i].f_black_level = 150.0/255.0;
492 p_gamma[i].f_white_level = 0.0/255.0;
495 if( p_chroma->i_chroma == VLC_CODEC_YV12 )
497 /* Exchange U and V */
498 panoramix_gamma_t t = p_gamma[1];
499 p_gamma[1] = p_gamma[2];
503 for( int i_index = 0; i_index < 256; i_index++ )
505 for( int i_index2 = 0; i_index2 <= ACCURACY; i_index2++ )
507 for( int i_plane = 0; i_plane < VOUT_MAX_PLANES; i_plane++ )
509 double f_factor = GammaFactor( &p_gamma[i_plane], (float)i_index / 255.0 );
511 float f_lut = clip_unit( 1.0 - ((ACCURACY - (float)i_index2) * f_factor / (ACCURACY - 1)) );
513 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] );
518 for( int i_plane = 0; i_plane < VOUT_MAX_PLANES; i_plane++ )
520 if( !p_chroma->pi_div_w[i_plane] || !p_chroma->pi_div_h[i_plane] )
522 const int i_length_w = (2 * p_sys->i_overlap_w2) / p_chroma->pi_div_w[i_plane];
523 const int i_length_h = (2 * p_sys->i_overlap_h2) / p_chroma->pi_div_h[i_plane];
525 for( int i_dir = 0; i_dir < 2; i_dir++ )
527 const int i_length = i_dir == 0 ? i_length_w : i_length_h;
528 const int i_den = i_length * i_length;
529 const int a_2 = p_sys->a_2 * (ACCURACY / 100);
530 const int a_1 = p_sys->a_1 * i_length * (ACCURACY / 100);
531 const int a_0 = p_sys->a_0 * i_den * (ACCURACY / 100);
533 for( int i_position = 0; i_position < 2; i_position++ )
535 for( int i_index = 0; i_index < i_length; i_index++ )
537 const int v = i_position == 1 ? i_index : (i_length - i_index);
538 const int i_lambda = clip_accuracy( ACCURACY - (a_2 * v*v + a_1 * v + a_0) / i_den );
541 p_sys->lambdav[i_plane][i_position][i_index] = i_lambda;
543 p_sys->lambdah[i_plane][i_position][i_index] = i_lambda;
551 char *psz_state = var_CreateGetNonEmptyString( p_splitter, CFG_PREFIX "active" );
554 bool pb_active[COL_MAX*ROW_MAX];
556 for( int i = 0; i < COL_MAX*ROW_MAX; i++ )
557 pb_active[i] = psz_state == NULL;
559 /* Parse active list if provided */
560 char *psz_tmp = psz_state;
561 while( psz_tmp && *psz_tmp )
563 char *psz_next = strchr( psz_tmp, ',' );
567 const int i_index = atoi( psz_tmp );
568 if( i_index >= 0 && i_index < COL_MAX*ROW_MAX )
569 pb_active[i_index] = true;
576 p_splitter->i_output =
577 Configuration( p_sys->pp_output,
578 p_sys->i_col, p_sys->i_row,
579 p_splitter->fmt.i_width, p_splitter->fmt.i_height,
580 p_sys->i_overlap_w2, p_sys->i_overlap_h2,
583 p_splitter->p_output = calloc( p_splitter->i_output,
584 sizeof(*p_splitter->p_output) );
585 if( !p_splitter->p_output )
591 for( int y = 0; y < p_sys->i_row; y++ )
593 for( int x = 0; x < p_sys->i_col; x++ )
595 panoramix_output_t *p_output = &p_sys->pp_output[x][y];
596 if( !p_output->b_active )
599 video_splitter_output_t *p_cfg = &p_splitter->p_output[p_output->i_output];
602 video_format_Copy( &p_cfg->fmt, &p_splitter->fmt );
603 p_cfg->fmt.i_visible_width =
604 p_cfg->fmt.i_width = p_output->i_width;
605 p_cfg->fmt.i_visible_height =
606 p_cfg->fmt.i_height = p_output->i_height;
608 p_cfg->window.i_x = p_output->i_x;
609 p_cfg->window.i_y = p_output->i_y;
610 p_cfg->window.i_align = p_output->i_align;
612 p_cfg->psz_module = NULL;
618 p_splitter->pf_filter = Filter;
619 p_splitter->pf_mouse = Mouse;
625 * Terminate a splitter module
627 static void Close( vlc_object_t *p_this )
629 video_splitter_t *p_splitter = (video_splitter_t*)p_this;
630 video_splitter_sys_t *p_sys = p_splitter->p_sys;
632 free( p_splitter->p_output );
637 * It creates multiples pictures from the source one
639 static int Filter( video_splitter_t *p_splitter, picture_t *pp_dst[], picture_t *p_src )
641 video_splitter_sys_t *p_sys = p_splitter->p_sys;
643 if( video_splitter_NewPicture( p_splitter, pp_dst ) )
645 picture_Release( p_src );
649 for( int y = 0; y < p_sys->i_row; y++ )
651 for( int x = 0; x < p_sys->i_col; x++ )
653 const panoramix_output_t *p_output = &p_sys->pp_output[x][y];
654 if( !p_output->b_active )
658 picture_t *p_dst = pp_dst[p_output->i_output];
661 picture_CopyProperties( p_dst, p_src );
664 for( int i_plane = 0; i_plane < p_src->i_planes; i_plane++ )
666 const int i_div_w = p_sys->p_chroma->pi_div_w[i_plane];
667 const int i_div_h = p_sys->p_chroma->pi_div_h[i_plane];
669 if( !i_div_w || !i_div_h )
672 const plane_t *p_srcp = &p_src->p[i_plane];
673 const plane_t *p_dstp = &p_dst->p[i_plane];
676 panoramix_filter_t filter;
677 filter.black.i_right = p_output->filter.black.i_right / i_div_w;
678 filter.black.i_left = p_output->filter.black.i_left / i_div_w;
679 filter.black.i_top = p_output->filter.black.i_top / i_div_h;
680 filter.black.i_bottom = p_output->filter.black.i_bottom / i_div_h;
682 filter.attenuate.i_right = p_output->filter.attenuate.i_right / i_div_w;
683 filter.attenuate.i_left = p_output->filter.attenuate.i_left / i_div_w;
684 filter.attenuate.i_top = p_output->filter.attenuate.i_top / i_div_h;
685 filter.attenuate.i_bottom = p_output->filter.attenuate.i_bottom / i_div_h;
688 const int i_x = p_output->i_src_x/i_div_w;
689 const int i_y = p_output->i_src_y/i_div_h;
691 assert( p_sys->p_chroma->b_planar );
692 FilterPlanar( p_dstp->p_pixels, p_dstp->i_pitch,
693 &p_srcp->p_pixels[i_y * p_srcp->i_pitch + i_x * p_srcp->i_pixel_pitch], p_srcp->i_pitch,
694 p_output->i_src_width/i_div_w, p_output->i_src_height/i_div_h,
695 p_sys->p_chroma->pi_black[i_plane],
697 p_sys->p_lut[i_plane],
698 p_sys->lambdav[i_plane],
699 p_sys->lambdah[i_plane] );
704 picture_Release( p_src );
709 * It converts mouse events
711 static int Mouse( video_splitter_t *p_splitter, vlc_mouse_t *p_mouse,
713 const vlc_mouse_t *p_old, const vlc_mouse_t *p_new )
715 video_splitter_sys_t *p_sys = p_splitter->p_sys;
718 for( int y = 0; y < p_sys->i_row; y++ )
720 for( int x = 0; x < p_sys->i_col; x++ )
722 const panoramix_output_t *p_output = p_output = &p_sys->pp_output[x][y];
723 if( p_output->b_active && p_output->i_output == i_index )
725 const int i_x = p_new->i_x - p_output->filter.black.i_left;
726 const int i_y = p_new->i_y - p_output->filter.black.i_top;
727 if( i_x >= 0 && i_x < p_output->i_width - p_output->filter.black.i_right &&
728 i_y >= 0 && i_y < p_output->i_height - p_output->filter.black.i_bottom )
731 p_mouse->i_x = p_output->i_src_x + i_x;
732 p_mouse->i_y = p_output->i_src_y + i_y;
741 /* It return a coefficient between 0.0 and 1.0 to be applied to the given
744 static double GammaFactor( const panoramix_gamma_t *g, float f_value )
746 if( f_value <= g->f_black_crush )
748 float f_input = f_value * g->f_black_level / g->f_black_crush + (1.0 - g->f_black_level);
750 return pow( f_input, 1.0 / g->f_gamma );
752 else if( f_value >= g->f_white_crush )
754 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);
755 return pow( f_input, 1.0 / g->f_gamma );
761 * It creates the panoramix configuration
763 static int Configuration( panoramix_output_t pp_output[ROW_MAX][COL_MAX],
764 int i_col, int i_row,
765 int i_src_width, int i_src_height,
766 int i_half_w, int i_half_h,
768 const bool *pb_active )
771 const bool b_overlap = true;
773 const bool b_overlap = false;
778 for( int y = 0, i_src_y = 0, i_dst_y = 0; y < i_row; y++ )
780 const bool b_row_first = y == 0;
781 const bool b_row_last = y == i_row - 1;
783 /* Compute source height */
784 int i_win_height = (i_src_height / i_row ) & ~1;
786 i_win_height = i_src_height - y * i_win_height;
788 for( int x = 0, i_src_x = 0, i_dst_x = 0; x < i_col; x++ )
790 const bool b_col_first = x == 0;
791 const bool b_col_last = x == i_col - 1;
793 /* Compute source width */
794 int i_win_width = (i_src_width / i_col ) & ~1;
796 i_win_width = i_src_width - x * i_win_width;
798 /* Compute filter configuration */
799 panoramix_filter_t cfg;
801 memset( &cfg, 0, sizeof(cfg) );
802 if( b_overlap && b_attenuate )
807 cfg.black.i_left = i_half_w;
809 cfg.black.i_right = i_half_w;
814 cfg.black.i_top = i_half_h;
816 cfg.black.i_bottom = i_half_h;
819 cfg.attenuate.i_left = 2 * i_half_w;
821 cfg.attenuate.i_right = 2 * i_half_w;
823 cfg.attenuate.i_top = 2 * i_half_h;
825 cfg.attenuate.i_bottom = 2 * i_half_h;
828 /* Compute alignment */
833 i_align |= VOUT_ALIGN_RIGHT;
835 i_align |= VOUT_ALIGN_LEFT;
840 i_align |= VOUT_ALIGN_BOTTOM;
842 i_align |= VOUT_ALIGN_TOP;
846 panoramix_output_t *p_output = &pp_output[x][y];
849 p_output->i_src_x = i_src_x - cfg.attenuate.i_left/2;
850 p_output->i_src_y = i_src_y - cfg.attenuate.i_top/2;
851 p_output->i_src_width = i_win_width + cfg.attenuate.i_left/2 + cfg.attenuate.i_right/2;
852 p_output->i_src_height = i_win_height + cfg.attenuate.i_top/2 + cfg.attenuate.i_bottom/2;
855 p_output->filter = cfg;
858 p_output->i_align = i_align;
859 p_output->i_x = i_dst_x;
860 p_output->i_y = i_dst_y;
862 p_output->i_width = cfg.black.i_left + p_output->i_src_width + cfg.black.i_right;
863 p_output->i_height = cfg.black.i_top + p_output->i_src_height + cfg.black.i_bottom;
866 p_output->b_active = pb_active[y * i_col + x] &&
867 p_output->i_width > 0 &&
868 p_output->i_height > 0;
869 if( p_output->b_active )
870 p_output->i_output = i_output++;
873 i_src_x += i_win_width;
874 i_dst_x += p_output->i_width;
876 i_src_y += i_win_height;
877 i_dst_y += pp_output[0][y].i_height;
883 * It filters a video plane
885 static void FilterPlanar( uint8_t *p_out, int i_out_pitch,
886 const uint8_t *p_in, int i_in_pitch,
890 const panoramix_filter_t *p_cfg,
891 uint8_t p_lut[ACCURACY + 1][256],
892 int lambdav[2][ACCURACY/2],
893 int lambdah[2][ACCURACY/2] )
896 assert( !p_cfg->black.i_left || !p_cfg->attenuate.i_left );
897 assert( !p_cfg->black.i_right || !p_cfg->attenuate.i_right );
898 assert( !p_cfg->black.i_top || !p_cfg->attenuate.i_top );
899 assert( !p_cfg->black.i_bottom || !p_cfg->attenuate.i_bottom );
901 const int i_out_width = p_cfg->black.i_left + i_copy_pitch + p_cfg->black.i_right;
903 /* Top black border */
904 for( int b = 0; b < p_cfg->black.i_top; b++ )
906 vlc_memset( p_out, i_pixel_black, i_out_width );
907 p_out += i_out_pitch;
910 for( int y = 0; y < i_copy_lines; y++ )
912 const uint8_t *p_src = p_in;
913 uint8_t *p_dst = p_out;
915 /* Black border on the left */
916 if( p_cfg->black.i_left > 0 )
918 memset( p_dst, i_pixel_black, p_cfg->black.i_left );
919 p_dst += p_cfg->black.i_left;
921 /* Attenuated video on the left */
922 for( int i = 0; i < p_cfg->attenuate.i_left; i++ )
923 *p_dst++ = p_lut[lambdav[0][i]][*p_src++];
925 /* Unmodified video */
926 const int i_unmodified_width = i_copy_pitch - p_cfg->attenuate.i_left - p_cfg->attenuate.i_right;
927 vlc_memcpy( p_dst, p_src, i_unmodified_width );
928 p_dst += i_unmodified_width;
929 p_src += i_unmodified_width;
931 /* Attenuated video on the right */
932 for( int i = 0; i < p_cfg->attenuate.i_right; i++ )
933 *p_dst++ = p_lut[lambdav[1][i]][*p_src++];
934 /* Black border on the right */
935 if( p_cfg->black.i_right > 0 )
937 memset( p_dst, i_pixel_black, p_cfg->black.i_right );
938 p_dst += p_cfg->black.i_right;
941 /* Attenuate complete line at top/bottom */
942 const bool b_attenuate_top = y < p_cfg->attenuate.i_top;
943 const bool b_attenuate_bottom = y >= i_copy_lines - p_cfg->attenuate.i_bottom;
944 if( b_attenuate_top || b_attenuate_bottom )
946 const int i_index = b_attenuate_top ? lambdah[0][y] : lambdah[1][y - (i_copy_lines - p_cfg->attenuate.i_bottom)];
947 uint8_t *p_dst = &p_out[0];
948 for( int i = 0; i < i_out_width; i++)
949 p_dst[i] = p_lut[i_index][p_dst[i]];
954 p_out += i_out_pitch;
956 /* Bottom black border */
957 for( int b = 0; b < p_cfg->black.i_bottom; b++ )
959 vlc_memset( p_out, i_pixel_black, i_out_width );
960 p_out += i_out_pitch;
967 static void RenderPackedRGB( vout_thread_t *p_vout, picture_t *p_pic )
970 length = 2 * p_sys->i_overlap_w2 * p_pic->p->i_pixel_pitch;
972 if (p_sys->b_has_changed)
976 Denom = F2(length / p_pic->p->i_pixel_pitch);
977 a_2 = p_sys->a_2 * (ACCURACY / 100);
978 a_1 = p_sys->a_1 * 2 * p_sys->i_overlap_w2 * (ACCURACY / 100);
979 a_0 = p_sys->a_0 * Denom * (ACCURACY / 100);
980 for(i_col_mod = 0; i_col_mod < 2; i_col_mod++)
981 for (i_index = 0; i_index < length / p_pic->p->i_pixel_pitch; i_index++)
982 for (i_plane_ = 0; i_plane_ < p_pic->p->i_pixel_pitch; i_plane_++)
983 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);
986 length = 2 * p_sys->i_overlap_h2;
987 if (p_sys->b_has_changed)
992 a_2 = p_sys->a_2 * (ACCURACY / 100);
993 a_1 = p_sys->a_1 * length * (ACCURACY / 100);
994 a_0 = p_sys->a_0 * Denom * (ACCURACY / 100);
995 for(i_row_mod = 0; i_row_mod < 2; i_row_mod++)
996 for (i_index = 0; i_index < length; i_index++)
997 for (i_plane_ = 0; i_plane_ < p_pic->p->i_pixel_pitch; i_plane_++)
998 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);