1 /*****************************************************************************
2 * ball.c : Augmented reality ball video filter module
3 *****************************************************************************
4 * Copyright (C) 2000-2009 the VideoLAN team
6 * Author: Adrien Maglo <magsoft@videolan.org>
8 * The Canny edge detection algorithm comes from gradient.c which was
10 * Samuel Hocevar <sam@zoy.org>
11 * Antoine Cellerier <dionoea -at- videolan -dot- org>
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
26 *****************************************************************************/
29 /*****************************************************************************
31 *****************************************************************************/
37 #include <math.h> /* sin(), cos(), asin() */
39 #include <vlc_common.h>
40 #include <vlc_plugin.h>
44 #include "vlc_filter.h"
45 #include "filter_picture.h"
46 #include "vlc_image.h"
48 enum { RED, GREEN, BLUE, WHITE };
57 static COLOR colorList[4];
60 colorList[RED].comp1 = 255; colorList[RED].comp2 = 0; \
61 colorList[RED].comp3 = 0; \
62 colorList[GREEN].comp1 = 0; colorList[GREEN].comp2 = 255; \
63 colorList[GREEN].comp3 = 0; \
64 colorList[BLUE].comp1 = 0; colorList[BLUE].comp2 = 0; \
65 colorList[BLUE].comp3 = 255; \
66 colorList[WHITE].comp1 = 255; colorList[WHITE].comp2 = 255; \
67 colorList[WHITE].comp3 = 255;
70 colorList[RED].comp1 = 82; colorList[RED].comp2 = 240; \
71 colorList[RED].comp3 = 90; \
72 colorList[GREEN].comp1 = 145; colorList[GREEN].comp2 = 34; \
73 colorList[GREEN].comp3 = 54 ; \
74 colorList[BLUE].comp1 = 41; colorList[BLUE].comp2 = 146; \
75 colorList[BLUE].comp3 = 240; \
76 colorList[WHITE].comp1 = 255; colorList[WHITE].comp2 = 128; \
77 colorList[WHITE].comp3 = 128;
80 /*****************************************************************************
82 *****************************************************************************/
83 static int Create ( vlc_object_t * );
84 static void Destroy ( vlc_object_t * );
86 static picture_t *Filter( filter_t *, picture_t * );
88 static void drawBall( filter_sys_t *p_sys, picture_t *p_outpic );
89 static void drawPixelRGB24( filter_sys_t *p_sys, picture_t *p_outpic,
90 uint8_t R, uint8_t G, uint8_t B,
91 int x, int y, bool b_skip );
92 static void drawPixelI420( filter_sys_t *p_sys, picture_t *p_outpic,
93 uint8_t Y, uint8_t U, uint8_t V,
94 int x, int y, bool b_skip );
95 static void drawPixelPacked( filter_sys_t *p_sys, picture_t *p_outpic,
96 uint8_t Y, uint8_t U, uint8_t V,
97 int x, int y, bool b_skip );
99 static void FilterBall( filter_t *, picture_t *, picture_t * );
100 static int ballCallback( vlc_object_t *, char const *,
101 vlc_value_t, vlc_value_t,
103 static int getBallColor( vlc_object_t *p_this, char const *psz_newval );
106 /*****************************************************************************
108 *****************************************************************************/
109 #define BALL_COLOR_TEXT N_("Ball color")
110 #define BALL_COLOR_LONGTEXT N_("Ball color, one of \"red\", \"blue\" and \"green\".")
112 #define EDGE_VISIBLE_TEXT N_("Edge visible")
113 #define EDGE_VISIBLE_LONGTEXT N_("Set edge visibility.")
115 #define BALL_SPEED_TEXT N_("Ball speed")
116 #define BALL_SPEED_LONGTEXT N_("Set ball speed, the displacement value \
117 in number of pixels by frame.")
119 #define BALL_SIZE_TEXT N_("Ball size")
120 #define BALL_SIZE_LONGTEXT N_("Set ball size giving its radius in number \
123 #define GRAD_THRESH_TEXT N_("Gradient threshold")
124 #define GRAD_THRESH_LONGTEXT N_("Set gradient threshold for edge computation.")
126 #define FILTER_PREFIX "ball-"
128 static const char *const mode_list[] = { "red", "green", "blue", "white" };
129 static const char *const mode_list_text[] = { N_("Red"), N_("Green"),
130 N_("Blue"), N_("White") };
133 set_description( N_("Ball video filter") )
134 set_shortname( N_( "Ball" ))
135 set_capability( "video filter2", 0 )
136 set_category( CAT_VIDEO )
137 set_subcategory( SUBCAT_VIDEO_VFILTER )
139 add_string( FILTER_PREFIX "ball-color", "ball-color", NULL,
140 BALL_COLOR_TEXT, BALL_COLOR_LONGTEXT, false )
141 change_string_list( mode_list, mode_list_text, 0 )
143 add_integer_with_range( FILTER_PREFIX "ball-speed", 4, 1, 15, NULL,
144 BALL_SPEED_TEXT, BALL_SPEED_LONGTEXT, false )
146 add_integer_with_range( FILTER_PREFIX "ball-size", 10, 5, 30, NULL,
147 BALL_SIZE_TEXT, BALL_SIZE_LONGTEXT, false )
149 add_integer_with_range( FILTER_PREFIX "gradient-threshold", 40, 1, 200, NULL,
150 GRAD_THRESH_TEXT, GRAD_THRESH_LONGTEXT, false )
152 add_bool( FILTER_PREFIX "edge-visible", 1, NULL,
153 EDGE_VISIBLE_TEXT, EDGE_VISIBLE_LONGTEXT, true )
155 add_shortcut( "ball" )
156 set_callbacks( Create, Destroy )
159 static const char *const ppsz_filter_options[] = {
160 "ball-color", "ball-speed", "ball-size",
161 "gradient-threshold", "edge-visible", NULL
165 /*****************************************************************************
166 * filter_sys_t: Distort video output method descriptor
167 *****************************************************************************
168 * This structure is part of the video output thread descriptor.
169 * It describes the Distort specific properties of an output thread.
170 *****************************************************************************/
177 image_handler_t *p_image;
189 /* Offsets for YUV packed chroma */
194 /* Gradient values */
199 /* Gradient threshold */
212 /* Pointer on drawing function */
213 void ( *drawingPixelFunction )( filter_sys_t *, picture_t *,
214 uint8_t, uint8_t, uint8_t,
219 /*****************************************************************************
220 * Create: allocates Distort video thread output method
221 *****************************************************************************
222 * This function allocates and initializes a Distort vout method.
223 *****************************************************************************/
224 static int Create( vlc_object_t *p_this )
226 filter_t *p_filter = (filter_t *)p_this;
229 /* Allocate structure */
230 p_filter->p_sys = malloc( sizeof( filter_sys_t ) );
231 if( p_filter->p_sys == NULL )
234 switch( p_filter->fmt_in.video.i_chroma )
238 p_filter->p_sys->drawingPixelFunction = drawPixelI420;
242 p_filter->p_sys->drawingPixelFunction = drawPixelPacked;
244 GetPackedYuvOffsets( p_filter->fmt_in.video.i_chroma,
245 &p_filter->p_sys->i_y_offset,
246 &p_filter->p_sys->i_u_offset,
247 &p_filter->p_sys->i_v_offset );
249 case VLC_CODEC_RGB24:
250 p_filter->p_sys->drawingPixelFunction = drawPixelRGB24;
254 msg_Err( p_filter, "Unsupported input chroma (%4s)",
255 (char*)&(p_filter->fmt_in.video.i_chroma) );
259 p_filter->p_sys->p_image = image_HandlerCreate( p_filter );
260 if( p_filter->p_sys->p_image == NULL )
263 p_filter->pf_video_filter = Filter;
265 config_ChainParse( p_filter, FILTER_PREFIX, ppsz_filter_options,
269 var_CreateGetNonEmptyStringCommand( p_filter,
270 FILTER_PREFIX "ball-color" ) ) )
272 msg_Err( p_filter, "configuration variable "
273 FILTER_PREFIX "ball-color empty" );
274 p_filter->p_sys->ballColor = RED;
277 p_filter->p_sys->ballColor = getBallColor( p_this, psz_method );
281 p_filter->p_sys->i_ballSize =
282 var_CreateGetIntegerCommand( p_filter, FILTER_PREFIX "ball-size" );
283 p_filter->p_sys->i_ballSpeed =
284 var_CreateGetIntegerCommand( p_filter, FILTER_PREFIX "ball-speed" );
285 p_filter->p_sys->b_edgeVisible =
286 var_CreateGetBoolCommand( p_filter, FILTER_PREFIX "edge-visible" );
287 p_filter->p_sys->i_gradThresh =
288 var_CreateGetIntegerCommand( p_filter, FILTER_PREFIX "gradient-threshold" );
290 vlc_mutex_init( &p_filter->p_sys->lock );
292 var_AddCallback( p_filter, FILTER_PREFIX "ball-color",
293 ballCallback, p_filter->p_sys );
294 var_AddCallback( p_filter, FILTER_PREFIX "ball-size",
295 ballCallback, p_filter->p_sys );
296 var_AddCallback( p_filter, FILTER_PREFIX "ball-speed",
297 ballCallback, p_filter->p_sys );
298 var_AddCallback( p_filter, FILTER_PREFIX "edge-visible",
299 ballCallback, p_filter->p_sys );
301 p_filter->p_sys->p_smooth = NULL;
302 p_filter->p_sys->p_grad_x = NULL;
303 p_filter->p_sys->p_grad_y = NULL;
305 p_filter->p_sys->i_ball_x = 100;
306 p_filter->p_sys->i_ball_y = 100;
308 p_filter->p_sys->f_lastVect_x = 0;
309 p_filter->p_sys->f_lastVect_y = -1;
315 /*****************************************************************************
316 * Destroy: destroy Distort video thread output method
317 *****************************************************************************
318 * Terminate an output method created by DistortCreateOutputMethod
319 *****************************************************************************/
320 static void Destroy( vlc_object_t *p_this )
322 filter_t *p_filter = (filter_t *)p_this;
323 filter_sys_t *p_sys = p_filter->p_sys;
325 vlc_mutex_destroy( &p_sys->lock );
327 image_HandlerDelete( p_sys->p_image );
329 free( p_sys->p_smooth );
330 free( p_sys->p_grad_x );
331 free( p_sys->p_grad_y );
337 /*****************************************************************************
338 * Render: displays previously rendered output
339 *****************************************************************************
340 * This function send the currently rendered image to Distort image, waits
341 * until it is displayed and switch the two rendering buffers, preparing next
343 *****************************************************************************/
344 static picture_t *Filter( filter_t *p_filter, picture_t *p_pic )
348 if( !p_pic ) return NULL;
350 p_outpic = filter_NewPicture( p_filter );
353 picture_Release( p_pic );
357 vlc_mutex_lock( &p_filter->p_sys->lock );
358 FilterBall( p_filter, p_pic, p_outpic );
359 vlc_mutex_unlock( &p_filter->p_sys->lock );
361 return CopyInfoAndRelease( p_outpic, p_pic );
365 /*****************************************************************************
367 *****************************************************************************/
369 static void drawBall( filter_sys_t *p_sys, picture_t *p_outpic )
371 int x = p_sys->i_ball_x;
372 int y = p_sys->i_ball_y;
373 int size = p_sys->i_ballSize;
375 const int i_width = p_outpic->p[0].i_visible_pitch;
376 const int i_height = p_outpic->p[0].i_visible_lines;
378 for( int j = y - size; j <= y + size; j++ )
380 bool b_skip = ( x - size ) % 2;
381 for( int i = x - size; i <= x + size; i++ )
383 /* Draw the pixel if it is inside the disk
384 and check we don't write out the frame. */
385 if( ( i - x ) * ( i - x ) + ( j - y ) * ( j - y ) <= size * size
386 && i >= 0 && i < i_width
387 && j >= 0 && j < i_height )
389 ( *p_sys->drawingPixelFunction )( p_sys, p_outpic,
390 colorList[ p_sys->ballColor ].comp1,
391 colorList[ p_sys->ballColor ].comp2,
392 colorList[ p_sys->ballColor ].comp3,
401 static void drawPixelRGB24( filter_sys_t *p_sys, picture_t *p_outpic,
402 uint8_t R, uint8_t G, uint8_t B,
403 int x, int y, bool b_skip )
406 VLC_UNUSED( b_skip );
407 uint8_t *p_pixel = p_outpic->p[0].p_pixels
408 + p_outpic->p[0].i_pitch
416 static void drawPixelI420( filter_sys_t *p_sys, picture_t *p_outpic,
417 uint8_t Y, uint8_t U, uint8_t V,
418 int x, int y, bool b_skip )
421 *( p_outpic->p[0].p_pixels + p_outpic->p[0].i_pitch * y + x ) = Y;
424 *( p_outpic->p[2].p_pixels + p_outpic->p[2].i_pitch
425 * ( y / 2 ) + x / 2 ) = U;
426 *( p_outpic->p[1].p_pixels + p_outpic->p[1].i_pitch
427 * ( y / 2 ) + x / 2 ) = V;
432 static void drawPixelPacked( filter_sys_t *p_sys, picture_t *p_outpic,
433 uint8_t Y, uint8_t U, uint8_t V,
434 int x, int y, bool b_skip )
436 uint8_t *p_pixel = p_outpic->p[0].p_pixels
437 + p_outpic->p[0].i_pitch * y + x * 2;
438 *( p_pixel + p_sys->i_y_offset ) = Y;
441 *( p_pixel + p_sys->i_u_offset ) = U;
442 *( p_pixel + p_sys->i_v_offset ) = V;
447 /*****************************************************************************
449 *****************************************************************************
450 * Modify its value to set its norm to 1 and keep its direction.
451 *****************************************************************************/
452 static void NormalizeVector( float *vect_x, float *vect_y )
454 float norm = sqrt( *vect_x * *vect_x + *vect_y * *vect_y );
455 if( *vect_x != 0 || *vect_y != 0 )
463 /*****************************************************************************
464 * Gaussian Convolution
465 *****************************************************************************
466 * Gaussian convolution ( sigma == 1.4 )
468 * | 2 4 5 4 2 | | 2 4 4 4 2 |
469 * | 4 9 12 9 4 | | 4 8 12 8 4 |
470 * | 5 12 15 12 5 | ~ | 4 12 16 12 4 |
471 * | 4 9 12 9 4 | | 4 8 12 8 4 |
472 * | 2 4 5 4 2 | | 2 4 4 4 2 |
473 *****************************************************************************/
474 static void GaussianConvolution( picture_t *p_inpic, uint32_t *p_smooth )
476 const uint8_t *p_inpix = p_inpic->p[Y_PLANE].p_pixels;
477 const int i_src_pitch = p_inpic->p[Y_PLANE].i_pitch;
478 const int i_src_visible = p_inpic->p[Y_PLANE].i_visible_pitch;
479 const int i_numLines = p_inpic->p[Y_PLANE].i_visible_lines;
482 for( y = 2; y < i_numLines - 2; y++ )
484 for( x = 2; x < i_src_visible - 2; x++ )
486 p_smooth[y*i_src_visible+x] = (uint32_t)(
488 ( p_inpix[(y-2)*i_src_pitch+x-2] )
489 + ((p_inpix[(y-2)*i_src_pitch+x-1]
490 + p_inpix[(y-2)*i_src_pitch+x]
491 + p_inpix[(y-2)*i_src_pitch+x+1])<<1 )
492 + ( p_inpix[(y-2)*i_src_pitch+x+2] )
494 + ((p_inpix[(y-1)*i_src_pitch+x-2]
495 + ( p_inpix[(y-1)*i_src_pitch+x-1]<<1 )
496 + ( p_inpix[(y-1)*i_src_pitch+x]*3 )
497 + ( p_inpix[(y-1)*i_src_pitch+x+1]<<1 )
498 + p_inpix[(y-1)*i_src_pitch+x+2]
500 + p_inpix[y*i_src_pitch+x-2]
501 + ( p_inpix[y*i_src_pitch+x-1]*3 )
502 + ( p_inpix[y*i_src_pitch+x]<<2 )
503 + ( p_inpix[y*i_src_pitch+x+1]*3 )
504 + p_inpix[y*i_src_pitch+x+2]
506 + p_inpix[(y+1)*i_src_pitch+x-2]
507 + ( p_inpix[(y+1)*i_src_pitch+x-1]<<1 )
508 + ( p_inpix[(y+1)*i_src_pitch+x]*3 )
509 + ( p_inpix[(y+1)*i_src_pitch+x+1]<<1 )
510 + p_inpix[(y+1)*i_src_pitch+x+2] )<<1 )
512 + ( p_inpix[(y+2)*i_src_pitch+x-2] )
513 + ((p_inpix[(y+2)*i_src_pitch+x-1]
514 + p_inpix[(y+2)*i_src_pitch+x]
515 + p_inpix[(y+2)*i_src_pitch+x+1])<<1 )
516 + ( p_inpix[(y+2)*i_src_pitch+x+2] )
523 /*****************************************************************************
524 * FilterBall: Augmented reality ball video filter
525 *****************************************************************************
526 * The edge detection part comes from gradient.c video filter module.
527 * The Canny edge detection algorithm is used :
528 * http://fourier.eng.hmc.edu/e161/lectures/canny/node1.html
529 * (well ... the implementation isn't really the canny algorithm ... but some
530 * ideas are the same)
531 *****************************************************************************/
532 static void FilterBall( filter_t *p_filter, picture_t *p_inpic,
533 picture_t *p_outpic )
536 filter_sys_t *p_sys = p_filter->p_sys;
542 picture_t *p_converted;
543 video_format_t fmt_comp;
545 switch( p_filter->fmt_in.video.i_chroma )
547 case VLC_CODEC_RGB24:
549 fmt_comp.i_width = p_filter->fmt_in.video.i_width;
550 fmt_comp.i_height = p_filter->fmt_in.video.i_height;
551 fmt_comp.i_chroma = VLC_FOURCC('G','R','E','Y');
552 fmt_comp.i_visible_width = fmt_comp.i_width;
553 fmt_comp.i_visible_height = fmt_comp.i_height;
555 p_converted = image_Convert( p_filter->p_sys->p_image, p_inpic,
556 &(p_filter->fmt_in.video),
564 p_converted = p_inpic;
568 const int i_numCols = p_converted->p[0].i_visible_pitch;
569 const int i_numLines = p_converted->p[0].i_visible_lines;
571 if( !p_filter->p_sys->p_smooth )
572 p_filter->p_sys->p_smooth =
573 (uint32_t *)malloc( i_numLines * i_numCols
575 p_smooth = p_filter->p_sys->p_smooth;
577 if( !p_filter->p_sys->p_grad_x )
578 p_filter->p_sys->p_grad_x =
579 (int32_t *)malloc( i_numLines * i_numCols
581 p_grad_x = p_filter->p_sys->p_grad_x;
583 if( !p_filter->p_sys->p_grad_y )
584 p_filter->p_sys->p_grad_y =
585 (int32_t *)malloc( i_numLines * i_numCols
587 p_grad_y = p_filter->p_sys->p_grad_y;
589 if( !p_smooth || !p_grad_x || !p_grad_y ) return;
591 vlc_memcpy( p_outpic->p[0].p_pixels, p_inpic->p[0].p_pixels,
592 p_outpic->p[0].i_lines * p_outpic->p[0].i_pitch );
593 vlc_memcpy( p_outpic->p[1].p_pixels, p_inpic->p[1].p_pixels,
594 p_outpic->p[1].i_lines * p_outpic->p[1].i_pitch );
595 vlc_memcpy( p_outpic->p[2].p_pixels, p_inpic->p[2].p_pixels,
596 p_outpic->p[2].i_lines * p_outpic->p[2].i_pitch );
598 GaussianConvolution( p_converted, p_smooth );
600 /* Compute the picture Sobel gradient
602 | -2 0 2 | and | 0 0 0 |
603 | -1 0 1 | | -1 -2 -1 | */
605 for( y = 1; y < i_numLines - 1; y++ )
607 for( x = 1; x < i_numCols - 1; x++ )
610 p_grad_x[ y * i_numCols + x ] =
611 ( p_smooth[(y-1)*i_numCols+x-1]
612 - p_smooth[(y+1)*i_numCols+x-1] )
613 + ( ( p_smooth[(y-1)*i_numCols+x]
614 - p_smooth[(y+1)*i_numCols+x] ) <<1 )
615 + ( p_smooth[(y-1)*i_numCols+x+1]
616 - p_smooth[(y+1)*i_numCols+x+1] );
617 p_grad_y[ y * i_numCols + x ] =
618 ( p_smooth[(y-1)*i_numCols+x-1]
619 - p_smooth[(y-1)*i_numCols+x+1] )
620 + ( ( p_smooth[y*i_numCols+x-1]
621 - p_smooth[y*i_numCols+x+1] ) <<1 )
622 + ( p_smooth[(y+1)*i_numCols+x-1]
623 - p_smooth[(y+1)*i_numCols+x+1] );
627 if( p_sys->b_edgeVisible )
629 /* Display the edges. */
630 for( y = 1; y < i_numLines - 1; y++ )
632 for( x = 1; x < i_numCols - 1; x++ )
634 if( abs( p_grad_x[ y * i_numCols + x ] )
635 + abs( p_grad_y[ y * i_numCols + x ] )
636 > p_sys->i_gradThresh )
638 ( *p_sys->drawingPixelFunction )( p_sys, p_outpic,
639 colorList[ WHITE ].comp1,
640 colorList[ WHITE ].comp2,
641 colorList[ WHITE ].comp3,
650 float *pf_lastVect_x = &p_sys->f_lastVect_x;
651 float *pf_lastVect_y = &p_sys->f_lastVect_y;
653 float f_newVect_x = 0;
654 float f_newVect_y = 0;
655 float f_contVect_x = 0;
656 float f_contVect_y = 0;
658 int nb_collisions = 0;
662 /* Test collisions for each pixel the ball will cover in its
664 for ( i_motion = 0; i_motion <= p_sys->i_ballSpeed && !bounce; i_motion++ )
666 /* Compute next ball position */
667 x = roundf( (float)p_sys->i_ball_x
668 + *pf_lastVect_x * (float)i_motion );
669 y = roundf( (float)p_sys->i_ball_y
670 + *pf_lastVect_y * (float)i_motion );
672 for( int i = x - p_sys->i_ballSize; i <= x + p_sys->i_ballSize; i++ )
674 for( int j = y - p_sys->i_ballSize;
675 j <= y + p_sys->i_ballSize; j++ )
677 /* Test the pixel if it is inside the disk and check we don't
678 write out the frame. */
679 if( ( i - x ) * ( i - x ) + ( j - y ) * ( j - y )
680 == p_sys->i_ballSize * p_sys->i_ballSize
681 && j <= i_numLines - 1 && x <= i_numCols - 1
682 && j >= 0 && i >= 0 )
684 /* Test firstly the picture limit collisions. */
687 f_contVect_x = x - i;
697 f_contVect_y = y - j;
703 if( j >= i_numLines - 3 )
706 f_contVect_y = y - j;
712 if( i >= i_numCols - 3 )
714 f_contVect_x = x - i;
721 /* Test the collisions with edges. */
722 if( abs( p_grad_x[ j * i_numCols + i ] )
723 + abs( p_grad_y[ j * i_numCols + i ] )
724 > p_sys->i_gradThresh )
726 f_contVect_x += x - i;
727 f_contVect_y += y - j;
740 /* Compute normal vector. */
741 f_contVect_x /= nb_collisions;
742 f_contVect_y /= nb_collisions;
743 NormalizeVector( &f_contVect_x, &f_contVect_y );
745 /* Compute the new vector after the bounce. */
746 float cosinus = *pf_lastVect_x * f_contVect_x
747 + *pf_lastVect_y * f_contVect_y;
748 f_newVect_x = *pf_lastVect_x - 2 * cosinus * f_contVect_x;
749 f_newVect_y = *pf_lastVect_y - 2 * cosinus * f_contVect_y;
750 NormalizeVector( &f_newVect_x, &f_newVect_y );
752 *pf_lastVect_x = f_newVect_x;
753 *pf_lastVect_y = f_newVect_y;
758 /* Test if next pixel is outside the frame limits.
759 If it is the case, then the ball is blocked until it can move. */
760 x = roundf( (float)x + *pf_lastVect_x );
761 y = roundf( (float)y + *pf_lastVect_y );
762 if( x - p_sys->i_ballSize < 2
763 || x + p_sys->i_ballSize > i_numCols - 3
764 || y - p_sys->i_ballSize < 2
765 || y + p_sys->i_ballSize > i_numLines - 3 )
771 /* After a bouce, the first ball motion is always one pixel. */
772 i_motion = p_sys->i_ballSpeed - 1;
777 /* Compute next ball position. */
778 p_sys->i_ball_x = roundf( (float)p_sys->i_ball_x + *pf_lastVect_x
779 * (float)( p_sys->i_ballSpeed - i_motion ) );
780 p_sys->i_ball_y = roundf( p_sys->i_ball_y + *pf_lastVect_y
781 * (float)( p_sys->i_ballSpeed - i_motion ) );
784 drawBall( p_sys, p_outpic );
786 switch( p_filter->fmt_in.video.i_chroma )
788 case VLC_CODEC_RGB24:
790 picture_Release( p_converted );
797 /*****************************************************************************
799 *****************************************************************************
800 * filter parameter modification callback
801 *****************************************************************************/
802 static int ballCallback( vlc_object_t *p_this, char const *psz_var,
803 vlc_value_t oldval, vlc_value_t newval,
807 filter_sys_t *p_sys = (filter_sys_t *)p_data;
808 msg_Err( p_this, "Test" );
810 vlc_mutex_lock( &p_sys->lock );
811 if( !strcmp( psz_var, FILTER_PREFIX "ball-color" ) )
813 p_sys->ballColor = getBallColor( p_this, newval.psz_string );
815 else if( !strcmp( psz_var, FILTER_PREFIX "ball-size" ) )
817 p_sys->i_ballSize = newval.i_int;
819 else if( !strcmp( psz_var, FILTER_PREFIX "ball-speed" ) )
821 p_sys->i_ballSpeed = newval.i_int;
823 else if( !strcmp( psz_var, FILTER_PREFIX "edge-visible" ) )
825 p_sys->b_edgeVisible = newval.b_bool;
827 else if( !strcmp( psz_var, FILTER_PREFIX "gradient-threshold" ) )
829 p_sys->i_gradThresh = newval.i_int;
831 vlc_mutex_unlock( &p_sys->lock );
837 /*****************************************************************************
839 *****************************************************************************
840 * Get and assign the ball color value
841 *****************************************************************************/
842 static int getBallColor( vlc_object_t *p_this, char const *psz_newval )
845 if( !strcmp( psz_newval, "red" ) )
847 else if( !strcmp( psz_newval, "blue" ) )
849 else if( !strcmp( psz_newval, "green" ) )
851 else if( !strcmp( psz_newval, "white" ) )
855 msg_Err( p_this, "no valid ball color provided (%s)", psz_newval );