1 /*****************************************************************************
2 * gradient.c : Gradient and edge detection video effects plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2000-2008 the VideoLAN team
7 * Authors: Samuel Hocevar <sam@zoy.org>
8 * Antoine Cellerier <dionoea -at- videolan -dot- 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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
25 /*****************************************************************************
27 *****************************************************************************/
33 #include <math.h> /* sin(), cos() */
35 #include <vlc_common.h>
36 #include <vlc_plugin.h>
40 #include "vlc_filter.h"
41 #include "filter_picture.h"
43 enum { GRADIENT, EDGE, HOUGH };
45 /*****************************************************************************
47 *****************************************************************************/
48 static int Create ( vlc_object_t * );
49 static void Destroy ( vlc_object_t * );
51 static picture_t *Filter( filter_t *, picture_t * );
52 static int GradientCallback( vlc_object_t *, char const *,
53 vlc_value_t, vlc_value_t,
56 static void FilterGradient( filter_t *, picture_t *, picture_t * );
57 static void FilterEdge ( filter_t *, picture_t *, picture_t * );
58 static void FilterHough ( filter_t *, picture_t *, picture_t * );
60 /*****************************************************************************
62 *****************************************************************************/
63 #define MODE_TEXT N_("Distort mode")
64 #define MODE_LONGTEXT N_("Distort mode, one of \"gradient\", \"edge\" and \"hough\".")
66 #define GRADIENT_TEXT N_("Gradient image type")
67 #define GRADIENT_LONGTEXT N_("Gradient image type (0 or 1). 0 will " \
68 "turn the image to white while 1 will keep colors." )
70 #define CARTOON_TEXT N_("Apply cartoon effect")
71 #define CARTOON_LONGTEXT N_("Apply cartoon effect. It is only used by " \
72 "\"gradient\" and \"edge\".")
74 static const char *const mode_list[] = { "gradient", "edge", "hough" };
75 static const char *const mode_list_text[] = { N_("Gradient"), N_("Edge"), N_("Hough") };
77 #define FILTER_PREFIX "gradient-"
80 set_description( N_("Gradient video filter") )
81 set_shortname( N_( "Gradient" ))
82 set_capability( "video filter2", 0 )
83 set_category( CAT_VIDEO )
84 set_subcategory( SUBCAT_VIDEO_VFILTER )
86 add_string( FILTER_PREFIX "mode", "gradient", NULL,
87 MODE_TEXT, MODE_LONGTEXT, false )
88 change_string_list( mode_list, mode_list_text, 0 )
90 add_integer_with_range( FILTER_PREFIX "type", 0, 0, 1, NULL,
91 GRADIENT_TEXT, GRADIENT_LONGTEXT, false )
92 add_bool( FILTER_PREFIX "cartoon", 1, NULL,
93 CARTOON_TEXT, CARTOON_LONGTEXT, false )
95 add_shortcut( "gradient" )
96 set_callbacks( Create, Destroy )
99 static const char *const ppsz_filter_options[] = {
100 "mode", "type", "cartoon", NULL
103 /*****************************************************************************
104 * filter_sys_t: Distort video output method descriptor
105 *****************************************************************************
106 * This structure is part of the video output thread descriptor.
107 * It describes the Distort specific properties of an output thread.
108 *****************************************************************************/
114 /* For the gradient mode */
119 uint32_t *p_buf32_bis;
126 /*****************************************************************************
127 * Create: allocates Distort video thread output method
128 *****************************************************************************
129 * This function allocates and initializes a Distort vout method.
130 *****************************************************************************/
131 static int Create( vlc_object_t *p_this )
133 filter_t *p_filter = (filter_t *)p_this;
136 switch( p_filter->fmt_in.video.i_chroma )
142 msg_Err( p_filter, "Unsupported input chroma (%4s)",
143 (char*)&(p_filter->fmt_in.video.i_chroma) );
147 /* Allocate structure */
148 p_filter->p_sys = malloc( sizeof( filter_sys_t ) );
149 if( p_filter->p_sys == NULL )
152 p_filter->pf_video_filter = Filter;
154 p_filter->p_sys->p_pre_hough = NULL;
156 config_ChainParse( p_filter, FILTER_PREFIX, ppsz_filter_options,
160 var_CreateGetNonEmptyStringCommand( p_filter, FILTER_PREFIX "mode" )) )
162 msg_Err( p_filter, "configuration variable "
163 FILTER_PREFIX "mode empty" );
164 p_filter->p_sys->i_mode = GRADIENT;
168 if( !strcmp( psz_method, "gradient" ) )
170 p_filter->p_sys->i_mode = GRADIENT;
172 else if( !strcmp( psz_method, "edge" ) )
174 p_filter->p_sys->i_mode = EDGE;
176 else if( !strcmp( psz_method, "hough" ) )
178 p_filter->p_sys->i_mode = HOUGH;
182 msg_Err( p_filter, "no valid gradient mode provided (%s)", psz_method );
183 p_filter->p_sys->i_mode = GRADIENT;
188 p_filter->p_sys->i_gradient_type =
189 var_CreateGetIntegerCommand( p_filter, FILTER_PREFIX "type" );
190 p_filter->p_sys->b_cartoon =
191 var_CreateGetBoolCommand( p_filter, FILTER_PREFIX "cartoon" );
193 vlc_mutex_init( &p_filter->p_sys->lock );
194 var_AddCallback( p_filter, FILTER_PREFIX "mode",
195 GradientCallback, p_filter->p_sys );
196 var_AddCallback( p_filter, FILTER_PREFIX "type",
197 GradientCallback, p_filter->p_sys );
198 var_AddCallback( p_filter, FILTER_PREFIX "cartoon",
199 GradientCallback, p_filter->p_sys );
201 p_filter->p_sys->p_buf32 = NULL;
202 p_filter->p_sys->p_buf32_bis = NULL;
203 p_filter->p_sys->p_buf8 = NULL;
208 /*****************************************************************************
209 * Destroy: destroy Distort video thread output method
210 *****************************************************************************
211 * Terminate an output method created by DistortCreateOutputMethod
212 *****************************************************************************/
213 static void Destroy( vlc_object_t *p_this )
215 filter_t *p_filter = (filter_t *)p_this;
216 filter_sys_t *p_sys = p_filter->p_sys;
218 var_DelCallback( p_filter, FILTER_PREFIX "mode",
219 GradientCallback, p_sys );
220 var_DelCallback( p_filter, FILTER_PREFIX "type",
221 GradientCallback, p_sys );
222 var_DelCallback( p_filter, FILTER_PREFIX "cartoon",
223 GradientCallback, p_sys );
224 vlc_mutex_destroy( &p_sys->lock );
226 free( p_sys->p_buf32 );
227 free( p_sys->p_buf32_bis );
228 free( p_sys->p_buf8 );
229 free( p_sys->p_pre_hough );
234 /*****************************************************************************
235 * Render: displays previously rendered output
236 *****************************************************************************
237 * This function send the currently rendered image to Distort image, waits
238 * until it is displayed and switch the two rendering buffers, preparing next
240 *****************************************************************************/
241 static picture_t *Filter( filter_t *p_filter, picture_t *p_pic )
245 if( !p_pic ) return NULL;
247 p_outpic = filter_NewPicture( p_filter );
250 picture_Release( p_pic );
254 vlc_mutex_lock( &p_filter->p_sys->lock );
255 switch( p_filter->p_sys->i_mode )
258 FilterEdge( p_filter, p_pic, p_outpic );
262 FilterGradient( p_filter, p_pic, p_outpic );
266 FilterHough( p_filter, p_pic, p_outpic );
272 vlc_mutex_unlock( &p_filter->p_sys->lock );
274 return CopyInfoAndRelease( p_outpic, p_pic );
277 /*****************************************************************************
278 * Gaussian Convolution
279 *****************************************************************************
280 * Gaussian convolution ( sigma == 1.4 )
282 * | 2 4 5 4 2 | | 2 4 4 4 2 |
283 * | 4 9 12 9 4 | | 4 8 12 8 4 |
284 * | 5 12 15 12 5 | ~ | 4 12 16 12 4 |
285 * | 4 9 12 9 4 | | 4 8 12 8 4 |
286 * | 2 4 5 4 2 | | 2 4 4 4 2 |
287 *****************************************************************************/
288 static void GaussianConvolution( picture_t *p_inpic, uint32_t *p_smooth )
290 const uint8_t *p_inpix = p_inpic->p[Y_PLANE].p_pixels;
291 const int i_src_pitch = p_inpic->p[Y_PLANE].i_pitch;
292 const int i_src_visible = p_inpic->p[Y_PLANE].i_visible_pitch;
293 const int i_num_lines = p_inpic->p[Y_PLANE].i_visible_lines;
296 for( y = 2; y < i_num_lines - 2; y++ )
298 for( x = 2; x < i_src_visible - 2; x++ )
300 p_smooth[y*i_src_visible+x] = (uint32_t)(
302 ( p_inpix[(y-2)*i_src_pitch+x-2] )
303 + ((p_inpix[(y-2)*i_src_pitch+x-1]
304 + p_inpix[(y-2)*i_src_pitch+x]
305 + p_inpix[(y-2)*i_src_pitch+x+1])<<1 )
306 + ( p_inpix[(y-2)*i_src_pitch+x+2] )
308 + ((p_inpix[(y-1)*i_src_pitch+x-2]
309 + ( p_inpix[(y-1)*i_src_pitch+x-1]<<1 )
310 + ( p_inpix[(y-1)*i_src_pitch+x]*3 )
311 + ( p_inpix[(y-1)*i_src_pitch+x+1]<<1 )
312 + p_inpix[(y-1)*i_src_pitch+x+2]
314 + p_inpix[y*i_src_pitch+x-2]
315 + ( p_inpix[y*i_src_pitch+x-1]*3 )
316 + ( p_inpix[y*i_src_pitch+x]<<2 )
317 + ( p_inpix[y*i_src_pitch+x+1]*3 )
318 + p_inpix[y*i_src_pitch+x+2]
320 + p_inpix[(y+1)*i_src_pitch+x-2]
321 + ( p_inpix[(y+1)*i_src_pitch+x-1]<<1 )
322 + ( p_inpix[(y+1)*i_src_pitch+x]*3 )
323 + ( p_inpix[(y+1)*i_src_pitch+x+1]<<1 )
324 + p_inpix[(y+1)*i_src_pitch+x+2] )<<1 )
326 + ( p_inpix[(y+2)*i_src_pitch+x-2] )
327 + ((p_inpix[(y+2)*i_src_pitch+x-1]
328 + p_inpix[(y+2)*i_src_pitch+x]
329 + p_inpix[(y+2)*i_src_pitch+x+1])<<1 )
330 + ( p_inpix[(y+2)*i_src_pitch+x+2] )
336 /*****************************************************************************
337 * FilterGradient: Sobel
338 *****************************************************************************/
339 static void FilterGradient( filter_t *p_filter, picture_t *p_inpic,
340 picture_t *p_outpic )
343 const int i_src_pitch = p_inpic->p[Y_PLANE].i_pitch;
344 const int i_src_visible = p_inpic->p[Y_PLANE].i_visible_pitch;
345 const int i_dst_pitch = p_outpic->p[Y_PLANE].i_pitch;
346 const int i_num_lines = p_inpic->p[Y_PLANE].i_visible_lines;
348 const uint8_t *p_inpix = p_inpic->p[Y_PLANE].p_pixels;
349 uint8_t *p_outpix = p_outpic->p[Y_PLANE].p_pixels;
352 if( !p_filter->p_sys->p_buf32 )
353 p_filter->p_sys->p_buf32 =
354 (uint32_t *)malloc( i_num_lines * i_src_visible * sizeof(uint32_t));
355 p_smooth = p_filter->p_sys->p_buf32;
357 if( !p_smooth ) return;
359 if( p_filter->p_sys->b_cartoon )
361 vlc_memcpy( p_outpic->p[U_PLANE].p_pixels,
362 p_inpic->p[U_PLANE].p_pixels,
363 p_outpic->p[U_PLANE].i_lines * p_outpic->p[U_PLANE].i_pitch );
364 vlc_memcpy( p_outpic->p[V_PLANE].p_pixels,
365 p_inpic->p[V_PLANE].p_pixels,
366 p_outpic->p[V_PLANE].i_lines * p_outpic->p[V_PLANE].i_pitch );
370 vlc_memset( p_outpic->p[U_PLANE].p_pixels, 0x80,
371 p_outpic->p[U_PLANE].i_lines * p_outpic->p[U_PLANE].i_pitch );
372 vlc_memset( p_outpic->p[V_PLANE].p_pixels, 0x80,
373 p_outpic->p[V_PLANE].i_lines * p_outpic->p[V_PLANE].i_pitch );
376 GaussianConvolution( p_inpic, p_smooth );
381 | -2 0 2 | and | 0 0 0 |
382 | -1 0 1 | | -1 -2 -1 | */
385 for( y = 1; y < i_num_lines - 1; y++ ) \
387 for( x = 1; x < i_src_visible - 1; x++ ) \
392 ( p_smooth[(y-1)*i_src_visible+x-1] \
393 - p_smooth[(y+1)*i_src_visible+x-1] ) \
394 + ( ( p_smooth[(y-1)*i_src_visible+x] \
395 - p_smooth[(y+1)*i_src_visible+x] ) <<1 ) \
396 + ( p_smooth[(y-1)*i_src_visible+x+1] \
397 - p_smooth[(y+1)*i_src_visible+x+1] ) \
401 ( p_smooth[(y-1)*i_src_visible+x-1] \
402 - p_smooth[(y-1)*i_src_visible+x+1] ) \
403 + ( ( p_smooth[y*i_src_visible+x-1] \
404 - p_smooth[y*i_src_visible+x+1] ) <<1 ) \
405 + ( p_smooth[(y+1)*i_src_visible+x-1] \
406 - p_smooth[(y+1)*i_src_visible+x+1] ) \
409 if( p_filter->p_sys->i_gradient_type )
411 if( p_filter->p_sys->b_cartoon )
416 p_outpix[y*i_dst_pitch+x] = 0x00;
420 if( p_smooth[y*i_src_visible+x] > 0xa0 )
421 p_outpix[y*i_dst_pitch+x] =
422 0xff - ((0xff - p_inpix[y*i_src_pitch+x] )>>2);
423 else if( p_smooth[y*i_src_visible+x] > 0x70 )
424 p_outpix[y*i_dst_pitch+x] =
425 0xa0 - ((0xa0 - p_inpix[y*i_src_pitch+x] )>>2);
426 else if( p_smooth[y*i_src_visible+x] > 0x28 )
427 p_outpix[y*i_dst_pitch+x] =
428 0x70 - ((0x70 - p_inpix[y*i_src_pitch+x] )>>2);
430 p_outpix[y*i_dst_pitch+x] =
431 0x28 - ((0x28 - p_inpix[y*i_src_pitch+x] )>>2);
438 p_outpix[y*i_dst_pitch+x] = clip_uint8_vlc( a );
446 p_outpix[y*i_dst_pitch+x] = 0;
448 p_outpix[y*i_dst_pitch+x] = 0xff-(uint8_t)a;
454 /*****************************************************************************
455 * FilterEdge: Canny edge detection algorithm
456 *****************************************************************************
457 * http://fourier.eng.hmc.edu/e161/lectures/canny/node1.html
458 * (well ... my implementation isn't really the canny algorithm ... but some
459 * ideas are the same)
460 *****************************************************************************/
469 static void FilterEdge( filter_t *p_filter, picture_t *p_inpic,
470 picture_t *p_outpic )
474 const int i_src_pitch = p_inpic->p[Y_PLANE].i_pitch;
475 const int i_src_visible = p_inpic->p[Y_PLANE].i_visible_pitch;
476 const int i_dst_pitch = p_outpic->p[Y_PLANE].i_pitch;
477 const int i_num_lines = p_inpic->p[Y_PLANE].i_visible_lines;
479 const uint8_t *p_inpix = p_inpic->p[Y_PLANE].p_pixels;
480 uint8_t *p_outpix = p_outpic->p[Y_PLANE].p_pixels;
486 if( !p_filter->p_sys->p_buf32 )
487 p_filter->p_sys->p_buf32 =
488 (uint32_t *)malloc( i_num_lines * i_src_visible * sizeof(uint32_t));
489 p_smooth = p_filter->p_sys->p_buf32;
491 if( !p_filter->p_sys->p_buf32_bis )
492 p_filter->p_sys->p_buf32_bis =
493 (uint32_t *)malloc( i_num_lines * i_src_visible * sizeof(uint32_t));
494 p_grad = p_filter->p_sys->p_buf32_bis;
496 if( !p_filter->p_sys->p_buf8 )
497 p_filter->p_sys->p_buf8 =
498 (uint8_t *)malloc( i_num_lines * i_src_visible * sizeof(uint8_t));
499 p_theta = p_filter->p_sys->p_buf8;
501 if( !p_smooth || !p_grad || !p_theta ) return;
503 if( p_filter->p_sys->b_cartoon )
505 vlc_memcpy( p_outpic->p[U_PLANE].p_pixels,
506 p_inpic->p[U_PLANE].p_pixels,
507 p_outpic->p[U_PLANE].i_lines * p_outpic->p[U_PLANE].i_pitch );
508 vlc_memcpy( p_outpic->p[V_PLANE].p_pixels,
509 p_inpic->p[V_PLANE].p_pixels,
510 p_outpic->p[V_PLANE].i_lines * p_outpic->p[V_PLANE].i_pitch );
514 vlc_memset( p_outpic->p[Y_PLANE].p_pixels, 0xff,
515 p_outpic->p[Y_PLANE].i_lines * p_outpic->p[Y_PLANE].i_pitch );
516 vlc_memset( p_outpic->p[U_PLANE].p_pixels, 0x80,
517 p_outpic->p[U_PLANE].i_lines * p_outpic->p[U_PLANE].i_pitch );
518 vlc_memset( p_outpic->p[V_PLANE].p_pixels, 0x80,
519 p_outpic->p[V_PLANE].i_lines * p_outpic->p[V_PLANE].i_pitch );
522 GaussianConvolution( p_inpic, p_smooth );
527 | -2 0 2 | and | 0 0 0 |
528 | -1 0 1 | | -1 -2 -1 | */
530 for( y = 1; y < i_num_lines - 1; y++ )
532 for( x = 1; x < i_src_visible - 1; x++ )
536 ( p_smooth[(y-1)*i_src_visible+x-1]
537 - p_smooth[(y+1)*i_src_visible+x-1] )
538 + ( ( p_smooth[(y-1)*i_src_visible+x]
539 - p_smooth[(y+1)*i_src_visible+x] ) <<1 )
540 + ( p_smooth[(y-1)*i_src_visible+x+1]
541 - p_smooth[(y+1)*i_src_visible+x+1] );
543 ( p_smooth[(y-1)*i_src_visible+x-1]
544 - p_smooth[(y-1)*i_src_visible+x+1] )
545 + ( ( p_smooth[y*i_src_visible+x-1]
546 - p_smooth[y*i_src_visible+x+1] ) <<1 )
547 + ( p_smooth[(y+1)*i_src_visible+x-1]
548 - p_smooth[(y+1)*i_src_visible+x+1] );
550 p_grad[y*i_src_visible+x] = (uint32_t)(abs( gradx ) + abs( grady ));
552 /* tan( 22.5 ) = 0,414213562 .. * 128 = 53
553 * tan( 26,565051177 ) = 0.5
554 * tan( 45 + 22.5 ) = 2,414213562 .. * 128 = 309
555 * tan( 63,434948823 ) 2 */
556 if( (grady<<1) > gradx )
557 p_theta[y*i_src_visible+x] = THETA_P;
558 else if( (grady<<1) < -gradx )
559 p_theta[y*i_src_visible+x] = THETA_M;
560 else if( !gradx || abs(grady) > abs(gradx)<<1 )
561 p_theta[y*i_src_visible+x] = THETA_Y;
563 p_theta[y*i_src_visible+x] = THETA_X;
568 for( y = 1; y < i_num_lines - 1; y++ )
570 for( x = 1; x < i_src_visible - 1; x++ )
572 if( p_grad[y*i_src_visible+x] > 40 )
574 switch( p_theta[y*i_src_visible+x] )
577 if( p_grad[y*i_src_visible+x] > p_grad[(y-1)*i_src_visible+x]
578 && p_grad[y*i_src_visible+x] > p_grad[(y+1)*i_src_visible+x] )
580 p_outpix[y*i_dst_pitch+x] = 0;
582 } else goto colorize;
584 if( p_grad[y*i_src_visible+x] > p_grad[(y-1)*i_src_visible+x-1]
585 && p_grad[y*i_src_visible+x] > p_grad[(y+1)*i_src_visible+x+1] )
587 p_outpix[y*i_dst_pitch+x] = 0;
589 } else goto colorize;
591 if( p_grad[y*i_src_visible+x] > p_grad[(y-1)*i_src_visible+x+1]
592 && p_grad[y*i_src_visible+x] > p_grad[(y+1)*i_src_visible+x-1] )
594 p_outpix[y*i_dst_pitch+x] = 0;
596 } else goto colorize;
598 if( p_grad[y*i_src_visible+x] > p_grad[y*i_src_visible+x-1]
599 && p_grad[y*i_src_visible+x] > p_grad[y*i_src_visible+x+1] )
601 p_outpix[y*i_dst_pitch+x] = 0;
603 } else goto colorize;
609 if( p_filter->p_sys->b_cartoon )
611 if( p_smooth[y*i_src_visible+x] > 0xa0 )
612 p_outpix[y*i_dst_pitch+x] = (uint8_t)
613 0xff - ((0xff - p_inpix[y*i_src_pitch+x] )>>2);
614 else if( p_smooth[y*i_src_visible+x] > 0x70 )
615 p_outpix[y*i_dst_pitch+x] =(uint8_t)
616 0xa0 - ((0xa0 - p_inpix[y*i_src_pitch+x] )>>2);
617 else if( p_smooth[y*i_src_visible+x] > 0x28 )
618 p_outpix[y*i_dst_pitch+x] =(uint8_t)
619 0x70 - ((0x70 - p_inpix[y*i_src_pitch+x] )>>2);
621 p_outpix[y*i_dst_pitch+x] =(uint8_t)
622 0x28 - ((0x28 - p_inpix[y*i_src_pitch+x] )>>2);
629 /*****************************************************************************
631 *****************************************************************************/
632 #define p_pre_hough p_filter->p_sys->p_pre_hough
633 static void FilterHough( filter_t *p_filter, picture_t *p_inpic,
634 picture_t *p_outpic )
637 int i_src_visible = p_inpic->p[Y_PLANE].i_visible_pitch;
638 int i_dst_pitch = p_outpic->p[Y_PLANE].i_pitch;
639 int i_num_lines = p_inpic->p[Y_PLANE].i_visible_lines;
641 uint8_t *p_outpix = p_outpic->p[Y_PLANE].p_pixels;
643 int i_diag = sqrt( i_num_lines * i_num_lines +
644 i_src_visible * i_src_visible);
645 int i_max, i_phi_max, i_rho, i_rho_max;
647 double d_step = M_PI / i_nb_steps;
652 int *p_hough = malloc( i_diag * i_nb_steps * sizeof(int) );
653 if( ! p_hough ) return;
655 p_smooth = (uint32_t *)malloc( i_num_lines*i_src_visible*sizeof(uint32_t));
664 msg_Dbg(p_filter, "Starting precalculation");
665 p_pre_hough = malloc( i_num_lines*i_src_visible*i_nb_steps*sizeof(int));
672 for( i = 0 ; i < i_nb_steps ; i++)
674 d_sin = sin(d_step * i);
675 d_cos = cos(d_step * i);
676 for( y = 0 ; y < i_num_lines ; y++ )
677 for( x = 0 ; x < i_src_visible ; x++ )
679 p_pre_hough[(i*i_num_lines+y)*i_src_visible + x] =
680 ceil(x*d_sin + y*d_cos);
683 msg_Dbg(p_filter, "Precalculation done");
686 vlc_memset( p_hough, 0, i_diag * i_nb_steps * sizeof(int) );
689 p_outpic->p[Y_PLANE].p_pixels, p_inpic->p[Y_PLANE].p_pixels,
690 p_outpic->p[Y_PLANE].i_lines * p_outpic->p[Y_PLANE].i_pitch );
692 p_outpic->p[U_PLANE].p_pixels, p_inpic->p[U_PLANE].p_pixels,
693 p_outpic->p[U_PLANE].i_lines * p_outpic->p[U_PLANE].i_pitch );
695 p_outpic->p[V_PLANE].p_pixels, p_inpic->p[V_PLANE].p_pixels,
696 p_outpic->p[V_PLANE].i_lines * p_outpic->p[V_PLANE].i_pitch );
698 GaussianConvolution( p_inpic, p_smooth );
703 | -2 0 2 | and | 0 0 0 |
704 | -1 0 1 | | -1 -2 -1 | */
709 for( y = 4; y < i_num_lines - 4; y++ )
711 for( x = 4; x < i_src_visible - 4; x++ )
716 ( ( p_smooth[(y-1)*i_src_visible+x]
717 - p_smooth[(y+1)*i_src_visible+x] ) <<1 )
718 + ( p_smooth[(y-1)*i_src_visible+x-1]
719 - p_smooth[(y+1)*i_src_visible+x-1] )
720 + ( p_smooth[(y-1)*i_src_visible+x+1]
721 - p_smooth[(y+1)*i_src_visible+x+1] )
725 ( ( p_smooth[y*i_src_visible+x-1]
726 - p_smooth[y*i_src_visible+x+1] ) <<1 )
727 + ( p_smooth[(y-1)*i_src_visible+x-1]
728 - p_smooth[(y-1)*i_src_visible+x+1] )
729 + ( p_smooth[(y+1)*i_src_visible+x-1]
730 - p_smooth[(y+1)*i_src_visible+x+1] )
735 for( i = 0 ; i < i_nb_steps ; i ++ )
737 i_rho = p_pre_hough[(i*i_num_lines+y)*i_src_visible + x];
738 if( p_hough[i_rho + i_diag/2 + i * i_diag]++ > i_max )
740 i_max = p_hough[i_rho + i_diag/2 + i * i_diag];
749 d_sin = sin(i_phi_max*d_step);
750 d_cos = cos(i_phi_max*d_step);
753 for( x = 0 ; x < i_src_visible ; x++ )
755 y = (i_rho_max - x * d_sin) / d_cos;
756 if( y >= 0 && y < i_num_lines )
757 p_outpix[y*i_dst_pitch+x] = 255;
767 static int GradientCallback( vlc_object_t *p_this, char const *psz_var,
768 vlc_value_t oldval, vlc_value_t newval,
772 filter_sys_t *p_sys = (filter_sys_t *)p_data;
774 vlc_mutex_lock( &p_sys->lock );
775 if( !strcmp( psz_var, FILTER_PREFIX "mode" ) )
777 if( !strcmp( newval.psz_string, "gradient" ) )
779 p_sys->i_mode = GRADIENT;
781 else if( !strcmp( newval.psz_string, "edge" ) )
783 p_sys->i_mode = EDGE;
785 else if( !strcmp( newval.psz_string, "hough" ) )
787 p_sys->i_mode = HOUGH;
791 msg_Err( p_this, "no valid gradient mode provided (%s)", newval.psz_string );
792 p_sys->i_mode = GRADIENT;
795 else if( !strcmp( psz_var, FILTER_PREFIX "type" ) )
797 p_sys->i_gradient_type = newval.i_int;
799 else if( !strcmp( psz_var, FILTER_PREFIX "cartoon" ) )
801 p_sys->b_cartoon = newval.b_bool;
803 vlc_mutex_unlock( &p_sys->lock );