1 /*****************************************************************************
2 * gradient.c : Gradient and edge detection video effects plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2000-2006 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 *****************************************************************************/
29 #include <math.h> /* sin(), cos() */
36 #include <vlc_plugin.h>
40 #include "vlc_filter.h"
42 enum { GRADIENT, EDGE, HOUGH };
44 /*****************************************************************************
46 *****************************************************************************/
47 static int Create ( vlc_object_t * );
48 static void Destroy ( vlc_object_t * );
50 static picture_t *Filter( filter_t *, picture_t * );
51 static int GradientCallback( vlc_object_t *, char const *,
52 vlc_value_t, vlc_value_t,
55 static void FilterGradient( filter_t *, picture_t *, picture_t * );
56 static void FilterEdge ( filter_t *, picture_t *, picture_t * );
57 static void FilterHough ( filter_t *, picture_t *, picture_t * );
59 /*****************************************************************************
61 *****************************************************************************/
62 #define MODE_TEXT N_("Distort mode")
63 #define MODE_LONGTEXT N_("Distort mode, one of \"gradient\", \"edge\" and \"hough\".")
65 #define GRADIENT_TEXT N_("Gradient image type")
66 #define GRADIENT_LONGTEXT N_("Gradient image type (0 or 1). 0 will " \
67 "turn the image to white while 1 will keep colors." )
69 #define CARTOON_TEXT N_("Apply cartoon effect")
70 #define CARTOON_LONGTEXT N_("Apply cartoon effect. It is only used by " \
71 "\"gradient\" and \"edge\".")
73 static const char *mode_list[] = { "gradient", "edge", "hough" };
74 static const char *mode_list_text[] = { N_("Gradient"), N_("Edge"), N_("Hough") };
76 #define FILTER_PREFIX "gradient-"
79 set_description( N_("Gradient video filter") );
80 set_shortname( N_( "Gradient" ));
81 set_capability( "video filter2", 0 );
82 set_category( CAT_VIDEO );
83 set_subcategory( SUBCAT_VIDEO_VFILTER );
85 add_string( FILTER_PREFIX "mode", "gradient", NULL,
86 MODE_TEXT, MODE_LONGTEXT, false );
87 change_string_list( mode_list, mode_list_text, 0 );
89 add_integer_with_range( FILTER_PREFIX "type", 0, 0, 1, NULL,
90 GRADIENT_TEXT, GRADIENT_LONGTEXT, false );
91 add_bool( FILTER_PREFIX "cartoon", 1, NULL,
92 CARTOON_TEXT, CARTOON_LONGTEXT, false );
94 add_shortcut( "gradient" );
95 set_callbacks( Create, Destroy );
98 static const char *ppsz_filter_options[] = {
99 "mode", "type", "cartoon", NULL
102 /*****************************************************************************
103 * vout_sys_t: Distort video output method descriptor
104 *****************************************************************************
105 * This structure is part of the video output thread descriptor.
106 * It describes the Distort specific properties of an output thread.
107 *****************************************************************************/
112 /* For the gradient mode */
117 uint32_t *p_buf32_bis;
124 /*****************************************************************************
125 * Create: allocates Distort video thread output method
126 *****************************************************************************
127 * This function allocates and initializes a Distort vout method.
128 *****************************************************************************/
129 static int Create( vlc_object_t *p_this )
131 filter_t *p_filter = (filter_t *)p_this;
134 /* Allocate structure */
135 p_filter->p_sys = malloc( sizeof( filter_sys_t ) );
136 if( p_filter->p_sys == NULL )
138 msg_Err( p_filter, "out of memory" );
142 p_filter->pf_video_filter = Filter;
144 p_filter->p_sys->p_pre_hough = NULL;
146 config_ChainParse( p_filter, FILTER_PREFIX, ppsz_filter_options,
150 var_CreateGetNonEmptyStringCommand( p_filter, FILTER_PREFIX "mode" )) )
152 msg_Err( p_filter, "configuration variable "
153 FILTER_PREFIX "mode empty" );
154 p_filter->p_sys->i_mode = GRADIENT;
158 if( !strcmp( psz_method, "gradient" ) )
160 p_filter->p_sys->i_mode = GRADIENT;
162 else if( !strcmp( psz_method, "edge" ) )
164 p_filter->p_sys->i_mode = EDGE;
166 else if( !strcmp( psz_method, "hough" ) )
168 p_filter->p_sys->i_mode = HOUGH;
172 msg_Err( p_filter, "no valid gradient mode provided (%s)", psz_method );
173 p_filter->p_sys->i_mode = GRADIENT;
178 p_filter->p_sys->i_gradient_type =
179 var_CreateGetIntegerCommand( p_filter, FILTER_PREFIX "type" );
180 p_filter->p_sys->b_cartoon =
181 var_CreateGetBoolCommand( p_filter, FILTER_PREFIX "cartoon" );
183 var_AddCallback( p_filter, FILTER_PREFIX "mode",
184 GradientCallback, p_filter->p_sys );
185 var_AddCallback( p_filter, FILTER_PREFIX "type",
186 GradientCallback, p_filter->p_sys );
187 var_AddCallback( p_filter, FILTER_PREFIX "cartoon",
188 GradientCallback, p_filter->p_sys );
190 p_filter->p_sys->p_buf32 = NULL;
191 p_filter->p_sys->p_buf32_bis = NULL;
192 p_filter->p_sys->p_buf8 = NULL;
197 /*****************************************************************************
198 * Destroy: destroy Distort video thread output method
199 *****************************************************************************
200 * Terminate an output method created by DistortCreateOutputMethod
201 *****************************************************************************/
202 static void Destroy( vlc_object_t *p_this )
204 filter_t *p_filter = (filter_t *)p_this;
206 free( p_filter->p_sys->p_buf32 );
207 free( p_filter->p_sys->p_buf32_bis );
208 free( p_filter->p_sys->p_buf8 );
209 free( p_filter->p_sys->p_pre_hough );
211 free( p_filter->p_sys );
214 /*****************************************************************************
215 * Render: displays previously rendered output
216 *****************************************************************************
217 * This function send the currently rendered image to Distort image, waits
218 * until it is displayed and switch the two rendering buffers, preparing next
220 *****************************************************************************/
221 static picture_t *Filter( filter_t *p_filter, picture_t *p_pic )
225 if( !p_pic ) return NULL;
227 p_outpic = p_filter->pf_vout_buffer_new( p_filter );
230 msg_Warn( p_filter, "can't get output picture" );
231 if( p_pic->pf_release )
232 p_pic->pf_release( p_pic );
236 switch( p_filter->p_sys->i_mode )
239 FilterEdge( p_filter, p_pic, p_outpic );
243 FilterGradient( p_filter, p_pic, p_outpic );
247 FilterHough( p_filter, p_pic, p_outpic );
254 p_outpic->date = p_pic->date;
255 p_outpic->b_force = p_pic->b_force;
256 p_outpic->i_nb_fields = p_pic->i_nb_fields;
257 p_outpic->b_progressive = p_pic->b_progressive;
258 p_outpic->b_top_field_first = p_pic->b_top_field_first;
260 if( p_pic->pf_release )
261 p_pic->pf_release( p_pic );
266 /*****************************************************************************
267 * Gaussian Convolution
268 *****************************************************************************
269 * Gaussian convolution ( sigma == 1.4 )
271 * | 2 4 5 4 2 | | 2 4 4 4 2 |
272 * | 4 9 12 9 4 | | 4 8 12 8 4 |
273 * | 5 12 15 12 5 | ~ | 4 12 16 12 4 |
274 * | 4 9 12 9 4 | | 4 8 12 8 4 |
275 * | 2 4 5 4 2 | | 2 4 4 4 2 |
276 *****************************************************************************/
277 static void GaussianConvolution( picture_t *p_inpic, uint32_t *p_smooth )
279 const uint8_t *p_inpix = p_inpic->p[Y_PLANE].p_pixels;
280 const int i_src_pitch = p_inpic->p[Y_PLANE].i_pitch;
281 const int i_src_visible = p_inpic->p[Y_PLANE].i_visible_pitch;
282 const int i_num_lines = p_inpic->p[Y_PLANE].i_visible_lines;
285 for( y = 2; y < i_num_lines - 2; y++ )
287 for( x = 2; x < i_src_visible - 2; x++ )
289 p_smooth[y*i_src_visible+x] = (uint32_t)(
291 ( p_inpix[(y-2)*i_src_pitch+x-2] )
292 + ((p_inpix[(y-2)*i_src_pitch+x-1]
293 + p_inpix[(y-2)*i_src_pitch+x]
294 + p_inpix[(y-2)*i_src_pitch+x+1])<<1 )
295 + ( p_inpix[(y-2)*i_src_pitch+x+2] )
297 + ((p_inpix[(y-1)*i_src_pitch+x-2]
298 + ( p_inpix[(y-1)*i_src_pitch+x-1]<<1 )
299 + ( p_inpix[(y-1)*i_src_pitch+x]*3 )
300 + ( p_inpix[(y-1)*i_src_pitch+x+1]<<1 )
301 + p_inpix[(y-1)*i_src_pitch+x+2]
303 + p_inpix[y*i_src_pitch+x-2]
304 + ( p_inpix[y*i_src_pitch+x-1]*3 )
305 + ( p_inpix[y*i_src_pitch+x]<<2 )
306 + ( p_inpix[y*i_src_pitch+x+1]*3 )
307 + p_inpix[y*i_src_pitch+x+2]
309 + p_inpix[(y+1)*i_src_pitch+x-2]
310 + ( p_inpix[(y+1)*i_src_pitch+x-1]<<1 )
311 + ( p_inpix[(y+1)*i_src_pitch+x]*3 )
312 + ( p_inpix[(y+1)*i_src_pitch+x+1]<<1 )
313 + p_inpix[(y+1)*i_src_pitch+x+2] )<<1 )
315 + ( p_inpix[(y+2)*i_src_pitch+x-2] )
316 + ((p_inpix[(y+2)*i_src_pitch+x-1]
317 + p_inpix[(y+2)*i_src_pitch+x]
318 + p_inpix[(y+2)*i_src_pitch+x+1])<<1 )
319 + ( p_inpix[(y+2)*i_src_pitch+x+2] )
325 /*****************************************************************************
326 * FilterGradient: Sobel
327 *****************************************************************************/
328 static void FilterGradient( filter_t *p_filter, picture_t *p_inpic,
329 picture_t *p_outpic )
332 const int i_src_pitch = p_inpic->p[Y_PLANE].i_pitch;
333 const int i_src_visible = p_inpic->p[Y_PLANE].i_visible_pitch;
334 const int i_dst_pitch = p_outpic->p[Y_PLANE].i_pitch;
335 const int i_num_lines = p_inpic->p[Y_PLANE].i_visible_lines;
337 const uint8_t *p_inpix = p_inpic->p[Y_PLANE].p_pixels;
338 uint8_t *p_outpix = p_outpic->p[Y_PLANE].p_pixels;
341 if( !p_filter->p_sys->p_buf32 )
342 p_filter->p_sys->p_buf32 =
343 (uint32_t *)malloc( i_num_lines * i_src_visible * sizeof(uint32_t));
344 p_smooth = p_filter->p_sys->p_buf32;
346 if( !p_smooth ) return;
348 if( p_filter->p_sys->b_cartoon )
350 vlc_memcpy( p_outpic->p[U_PLANE].p_pixels,
351 p_inpic->p[U_PLANE].p_pixels,
352 p_outpic->p[U_PLANE].i_lines * p_outpic->p[U_PLANE].i_pitch );
353 vlc_memcpy( p_outpic->p[V_PLANE].p_pixels,
354 p_inpic->p[V_PLANE].p_pixels,
355 p_outpic->p[V_PLANE].i_lines * p_outpic->p[V_PLANE].i_pitch );
359 vlc_memset( p_outpic->p[U_PLANE].p_pixels, 0x80,
360 p_outpic->p[U_PLANE].i_lines * p_outpic->p[U_PLANE].i_pitch );
361 vlc_memset( p_outpic->p[V_PLANE].p_pixels, 0x80,
362 p_outpic->p[V_PLANE].i_lines * p_outpic->p[V_PLANE].i_pitch );
365 GaussianConvolution( p_inpic, p_smooth );
370 | -2 0 2 | and | 0 0 0 |
371 | -1 0 1 | | -1 -2 -1 | */
374 for( y = 1; y < i_num_lines - 1; y++ ) \
376 for( x = 1; x < i_src_visible - 1; x++ ) \
381 ( p_smooth[(y-1)*i_src_visible+x-1] \
382 - p_smooth[(y+1)*i_src_visible+x-1] ) \
383 + ( ( p_smooth[(y-1)*i_src_visible+x] \
384 - p_smooth[(y+1)*i_src_visible+x] ) <<1 ) \
385 + ( p_smooth[(y-1)*i_src_visible+x+1] \
386 - p_smooth[(y+1)*i_src_visible+x+1] ) \
390 ( p_smooth[(y-1)*i_src_visible+x-1] \
391 - p_smooth[(y-1)*i_src_visible+x+1] ) \
392 + ( ( p_smooth[y*i_src_visible+x-1] \
393 - p_smooth[y*i_src_visible+x+1] ) <<1 ) \
394 + ( p_smooth[(y+1)*i_src_visible+x-1] \
395 - p_smooth[(y+1)*i_src_visible+x+1] ) \
398 if( p_filter->p_sys->i_gradient_type )
400 if( p_filter->p_sys->b_cartoon )
405 p_outpix[y*i_dst_pitch+x] = 0x00;
409 if( p_smooth[y*i_src_visible+x] > 0xa0 )
410 p_outpix[y*i_dst_pitch+x] =
411 0xff - ((0xff - p_inpix[y*i_src_pitch+x] )>>2);
412 else if( p_smooth[y*i_src_visible+x] > 0x70 )
413 p_outpix[y*i_dst_pitch+x] =
414 0xa0 - ((0xa0 - p_inpix[y*i_src_pitch+x] )>>2);
415 else if( p_smooth[y*i_src_visible+x] > 0x28 )
416 p_outpix[y*i_dst_pitch+x] =
417 0x70 - ((0x70 - p_inpix[y*i_src_pitch+x] )>>2);
419 p_outpix[y*i_dst_pitch+x] =
420 0x28 - ((0x28 - p_inpix[y*i_src_pitch+x] )>>2);
427 p_outpix[y*i_dst_pitch+x] = clip_uint8_vlc( a );
435 p_outpix[y*i_dst_pitch+x] = 0;
437 p_outpix[y*i_dst_pitch+x] = 0xff-(uint8_t)a;
443 /*****************************************************************************
444 * FilterEdge: Canny edge detection algorithm
445 *****************************************************************************
446 * http://fourier.eng.hmc.edu/e161/lectures/canny/node1.html
447 * (well ... my implementation isn't really the canny algorithm ... but some
448 * ideas are the same)
449 *****************************************************************************/
458 static void FilterEdge( filter_t *p_filter, picture_t *p_inpic,
459 picture_t *p_outpic )
463 const int i_src_pitch = p_inpic->p[Y_PLANE].i_pitch;
464 const int i_src_visible = p_inpic->p[Y_PLANE].i_visible_pitch;
465 const int i_dst_pitch = p_outpic->p[Y_PLANE].i_pitch;
466 const int i_num_lines = p_inpic->p[Y_PLANE].i_visible_lines;
468 const uint8_t *p_inpix = p_inpic->p[Y_PLANE].p_pixels;
469 uint8_t *p_outpix = p_outpic->p[Y_PLANE].p_pixels;
475 if( !p_filter->p_sys->p_buf32 )
476 p_filter->p_sys->p_buf32 =
477 (uint32_t *)malloc( i_num_lines * i_src_visible * sizeof(uint32_t));
478 p_smooth = p_filter->p_sys->p_buf32;
480 if( !p_filter->p_sys->p_buf32_bis )
481 p_filter->p_sys->p_buf32_bis =
482 (uint32_t *)malloc( i_num_lines * i_src_visible * sizeof(uint32_t));
483 p_grad = p_filter->p_sys->p_buf32_bis;
485 if( !p_filter->p_sys->p_buf8 )
486 p_filter->p_sys->p_buf8 =
487 (uint8_t *)malloc( i_num_lines * i_src_visible * sizeof(uint8_t));
488 p_theta = p_filter->p_sys->p_buf8;
490 if( !p_smooth || !p_grad || !p_theta ) return;
492 if( p_filter->p_sys->b_cartoon )
494 vlc_memcpy( p_outpic->p[U_PLANE].p_pixels,
495 p_inpic->p[U_PLANE].p_pixels,
496 p_outpic->p[U_PLANE].i_lines * p_outpic->p[U_PLANE].i_pitch );
497 vlc_memcpy( p_outpic->p[V_PLANE].p_pixels,
498 p_inpic->p[V_PLANE].p_pixels,
499 p_outpic->p[V_PLANE].i_lines * p_outpic->p[V_PLANE].i_pitch );
503 vlc_memset( p_outpic->p[Y_PLANE].p_pixels, 0xff,
504 p_outpic->p[Y_PLANE].i_lines * p_outpic->p[Y_PLANE].i_pitch );
505 vlc_memset( p_outpic->p[U_PLANE].p_pixels, 0x80,
506 p_outpic->p[U_PLANE].i_lines * p_outpic->p[U_PLANE].i_pitch );
507 vlc_memset( p_outpic->p[V_PLANE].p_pixels, 0x80,
508 p_outpic->p[V_PLANE].i_lines * p_outpic->p[V_PLANE].i_pitch );
511 GaussianConvolution( p_inpic, p_smooth );
516 | -2 0 2 | and | 0 0 0 |
517 | -1 0 1 | | -1 -2 -1 | */
519 for( y = 1; y < i_num_lines - 1; y++ )
521 for( x = 1; x < i_src_visible - 1; x++ )
525 ( p_smooth[(y-1)*i_src_visible+x-1]
526 - p_smooth[(y+1)*i_src_visible+x-1] )
527 + ( ( p_smooth[(y-1)*i_src_visible+x]
528 - p_smooth[(y+1)*i_src_visible+x] ) <<1 )
529 + ( p_smooth[(y-1)*i_src_visible+x+1]
530 - p_smooth[(y+1)*i_src_visible+x+1] );
532 ( p_smooth[(y-1)*i_src_visible+x-1]
533 - p_smooth[(y-1)*i_src_visible+x+1] )
534 + ( ( p_smooth[y*i_src_visible+x-1]
535 - p_smooth[y*i_src_visible+x+1] ) <<1 )
536 + ( p_smooth[(y+1)*i_src_visible+x-1]
537 - p_smooth[(y+1)*i_src_visible+x+1] );
539 p_grad[y*i_src_visible+x] = (uint32_t)(abs( gradx ) + abs( grady ));
541 /* tan( 22.5 ) = 0,414213562 .. * 128 = 53
542 * tan( 26,565051177 ) = 0.5
543 * tan( 45 + 22.5 ) = 2,414213562 .. * 128 = 309
544 * tan( 63,434948823 ) 2 */
545 if( (grady<<1) > gradx )
546 p_theta[y*i_src_visible+x] = THETA_P;
547 else if( (grady<<1) < -gradx )
548 p_theta[y*i_src_visible+x] = THETA_M;
549 else if( !gradx || abs(grady) > abs(gradx)<<1 )
550 p_theta[y*i_src_visible+x] = THETA_Y;
552 p_theta[y*i_src_visible+x] = THETA_X;
557 for( y = 1; y < i_num_lines - 1; y++ )
559 for( x = 1; x < i_src_visible - 1; x++ )
561 if( p_grad[y*i_src_visible+x] > 40 )
563 switch( p_theta[y*i_src_visible+x] )
566 if( p_grad[y*i_src_visible+x] > p_grad[(y-1)*i_src_visible+x]
567 && p_grad[y*i_src_visible+x] > p_grad[(y+1)*i_src_visible+x] )
569 p_outpix[y*i_dst_pitch+x] = 0;
571 } else goto colorize;
573 if( p_grad[y*i_src_visible+x] > p_grad[(y-1)*i_src_visible+x-1]
574 && p_grad[y*i_src_visible+x] > p_grad[(y+1)*i_src_visible+x+1] )
576 p_outpix[y*i_dst_pitch+x] = 0;
578 } else goto colorize;
580 if( p_grad[y*i_src_visible+x] > p_grad[(y-1)*i_src_visible+x+1]
581 && p_grad[y*i_src_visible+x] > p_grad[(y+1)*i_src_visible+x-1] )
583 p_outpix[y*i_dst_pitch+x] = 0;
585 } else goto colorize;
587 if( p_grad[y*i_src_visible+x] > p_grad[y*i_src_visible+x-1]
588 && p_grad[y*i_src_visible+x] > p_grad[y*i_src_visible+x+1] )
590 p_outpix[y*i_dst_pitch+x] = 0;
592 } else goto colorize;
598 if( p_filter->p_sys->b_cartoon )
600 if( p_smooth[y*i_src_visible+x] > 0xa0 )
601 p_outpix[y*i_dst_pitch+x] = (uint8_t)
602 0xff - ((0xff - p_inpix[y*i_src_pitch+x] )>>2);
603 else if( p_smooth[y*i_src_visible+x] > 0x70 )
604 p_outpix[y*i_dst_pitch+x] =(uint8_t)
605 0xa0 - ((0xa0 - p_inpix[y*i_src_pitch+x] )>>2);
606 else if( p_smooth[y*i_src_visible+x] > 0x28 )
607 p_outpix[y*i_dst_pitch+x] =(uint8_t)
608 0x70 - ((0x70 - p_inpix[y*i_src_pitch+x] )>>2);
610 p_outpix[y*i_dst_pitch+x] =(uint8_t)
611 0x28 - ((0x28 - p_inpix[y*i_src_pitch+x] )>>2);
618 /*****************************************************************************
620 *****************************************************************************/
621 #define p_pre_hough p_filter->p_sys->p_pre_hough
622 static void FilterHough( filter_t *p_filter, picture_t *p_inpic,
623 picture_t *p_outpic )
626 int i_src_visible = p_inpic->p[Y_PLANE].i_visible_pitch;
627 int i_dst_pitch = p_outpic->p[Y_PLANE].i_pitch;
628 int i_num_lines = p_inpic->p[Y_PLANE].i_visible_lines;
630 uint8_t *p_outpix = p_outpic->p[Y_PLANE].p_pixels;
632 int i_diag = sqrt( i_num_lines * i_num_lines +
633 i_src_visible * i_src_visible);
634 int i_max, i_phi_max, i_rho, i_rho_max;
636 double d_step = M_PI / i_nb_steps;
640 int *p_hough = malloc( i_diag * i_nb_steps * sizeof(int) );
641 if( ! p_hough ) return;
642 p_smooth = (uint32_t *)malloc( i_num_lines*i_src_visible*sizeof(uint32_t));
643 if( !p_smooth ) return;
647 msg_Dbg(p_filter, "Starting precalculation");
648 p_pre_hough = malloc( i_num_lines*i_src_visible*i_nb_steps*sizeof(int));
649 if( ! p_pre_hough ) return;
650 for( i = 0 ; i < i_nb_steps ; i++)
652 d_sin = sin(d_step * i);
653 d_cos = cos(d_step * i);
654 for( y = 0 ; y < i_num_lines ; y++ )
655 for( x = 0 ; x < i_src_visible ; x++ )
657 p_pre_hough[(i*i_num_lines+y)*i_src_visible + x] =
658 ceil(x*d_sin + y*d_cos);
661 msg_Dbg(p_filter, "Precalculation done");
664 vlc_memset( p_hough, 0, i_diag * i_nb_steps * sizeof(int) );
667 p_outpic->p[Y_PLANE].p_pixels, p_inpic->p[Y_PLANE].p_pixels,
668 p_outpic->p[Y_PLANE].i_lines * p_outpic->p[Y_PLANE].i_pitch );
670 p_outpic->p[U_PLANE].p_pixels, p_inpic->p[U_PLANE].p_pixels,
671 p_outpic->p[U_PLANE].i_lines * p_outpic->p[U_PLANE].i_pitch );
673 p_outpic->p[V_PLANE].p_pixels, p_inpic->p[V_PLANE].p_pixels,
674 p_outpic->p[V_PLANE].i_lines * p_outpic->p[V_PLANE].i_pitch );
676 GaussianConvolution( p_inpic, p_smooth );
681 | -2 0 2 | and | 0 0 0 |
682 | -1 0 1 | | -1 -2 -1 | */
687 for( y = 4; y < i_num_lines - 4; y++ )
689 for( x = 4; x < i_src_visible - 4; x++ )
694 ( ( p_smooth[(y-1)*i_src_visible+x]
695 - p_smooth[(y+1)*i_src_visible+x] ) <<1 )
696 + ( p_smooth[(y-1)*i_src_visible+x-1]
697 - p_smooth[(y+1)*i_src_visible+x-1] )
698 + ( p_smooth[(y-1)*i_src_visible+x+1]
699 - p_smooth[(y+1)*i_src_visible+x+1] )
703 ( ( p_smooth[y*i_src_visible+x-1]
704 - p_smooth[y*i_src_visible+x+1] ) <<1 )
705 + ( p_smooth[(y-1)*i_src_visible+x-1]
706 - p_smooth[(y-1)*i_src_visible+x+1] )
707 + ( p_smooth[(y+1)*i_src_visible+x-1]
708 - p_smooth[(y+1)*i_src_visible+x+1] )
713 for( i = 0 ; i < i_nb_steps ; i ++ )
715 i_rho = p_pre_hough[(i*i_num_lines+y)*i_src_visible + x];
716 if( p_hough[i_rho + i_diag/2 + i * i_diag]++ > i_max )
718 i_max = p_hough[i_rho + i_diag/2 + i * i_diag];
727 d_sin = sin(i_phi_max*d_step);
728 d_cos = cos(i_phi_max*d_step);
731 for( x = 0 ; x < i_src_visible ; x++ )
733 y = (i_rho_max - x * d_sin) / d_cos;
734 if( y >= 0 && y < i_num_lines )
735 p_outpix[y*i_dst_pitch+x] = 255;
745 static int GradientCallback( vlc_object_t *p_this, char const *psz_var,
746 vlc_value_t oldval, vlc_value_t newval,
750 filter_sys_t *p_sys = (filter_sys_t *)p_data;
751 if( !strcmp( psz_var, FILTER_PREFIX "mode" ) )
753 if( !strcmp( newval.psz_string, "gradient" ) )
755 p_sys->i_mode = GRADIENT;
757 else if( !strcmp( newval.psz_string, "edge" ) )
759 p_sys->i_mode = EDGE;
761 else if( !strcmp( newval.psz_string, "hough" ) )
763 p_sys->i_mode = HOUGH;
767 msg_Err( p_this, "no valid gradient mode provided (%s)", newval.psz_string );
768 p_sys->i_mode = GRADIENT;
771 else if( !strcmp( psz_var, FILTER_PREFIX "type" ) )
773 p_sys->i_gradient_type = newval.i_int;
775 else if( !strcmp( psz_var, FILTER_PREFIX "cartoon" ) )
777 p_sys->b_cartoon = newval.b_bool;