Contrib: upnp/win32, remove strerror use, and other small hacks...
[vlc/asuraparaju-public.git] / modules / video_filter / noise.c
blob9f2a6b5f30b0ad24e5af7b9503b97c03d08f00fc
1 /*****************************************************************************
2 * noise.c : "add noise to image" video filter
3 *****************************************************************************
4 * Copyright (C) 2000-2006 the VideoLAN team
5 * $Id$
7 * Authors: Antoine Cellerier <dionoea -at- videolan -dot- org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 /*****************************************************************************
25 * Preamble
26 *****************************************************************************/
28 #ifdef HAVE_CONFIG_H
29 # include "config.h"
30 #endif
32 #include <vlc_common.h>
33 #include <vlc_plugin.h>
34 #include <vlc_rand.h>
36 #include <vlc_filter.h>
37 #include "filter_picture.h"
39 /*****************************************************************************
40 * Local prototypes
41 *****************************************************************************/
42 static int Create ( vlc_object_t * );
43 static picture_t *Filter( filter_t *, picture_t * );
45 #define FILTER_PREFIX "noise-"
47 /*****************************************************************************
48 * Module descriptor
49 *****************************************************************************/
50 vlc_module_begin ()
51 set_description( N_("Noise video filter") )
52 set_shortname( N_( "Noise" ))
53 set_capability( "video filter2", 0 )
54 set_category( CAT_VIDEO )
55 set_subcategory( SUBCAT_VIDEO_VFILTER )
57 add_shortcut( "noise" )
58 set_callbacks( Create, NULL )
59 vlc_module_end ()
61 /*****************************************************************************
62 * Create: allocates Distort video thread output method
63 *****************************************************************************
64 * This function allocates and initializes a Distort vout method.
65 *****************************************************************************/
66 static int Create( vlc_object_t *p_this )
68 filter_t *p_filter = (filter_t *)p_this;
69 p_filter->pf_video_filter = Filter;
71 return VLC_SUCCESS;
74 /*****************************************************************************
75 * Render: displays previously rendered output
76 *****************************************************************************
77 * This function send the currently rendered image to Distort image, waits
78 * until it is displayed and switch the two rendering buffers, preparing next
79 * frame.
80 *****************************************************************************/
81 static picture_t *Filter( filter_t *p_filter, picture_t *p_pic )
83 picture_t *p_outpic;
84 int i_index;
86 if( !p_pic ) return NULL;
88 p_outpic = filter_NewPicture( p_filter );
89 if( !p_outpic )
91 msg_Warn( p_filter, "can't get output picture" );
92 picture_Release( p_pic );
93 return NULL;
96 for( i_index = 0 ; i_index < p_pic->i_planes ; i_index++ )
98 uint8_t *p_in = p_pic->p[i_index].p_pixels;
99 uint8_t *p_out = p_outpic->p[i_index].p_pixels;
101 const int i_num_lines = p_pic->p[i_index].i_visible_lines;
102 const int i_num_cols = p_pic->p[i_index].i_visible_pitch;
103 const int i_in_pitch = p_pic->p[i_index].i_pitch;
104 const int i_out_pitch = p_outpic->p[i_index].i_pitch;
106 int i_line, i_col;
108 for( i_line = 0 ; i_line < i_num_lines ; i_line++ )
110 if( vlc_mrand48()&7 )
112 /* line isn't noisy */
113 vlc_memcpy( p_out+i_line*i_out_pitch, p_in+i_line*i_in_pitch,
114 i_num_cols );
116 else
118 /* this line is noisy */
119 unsigned noise_level = (vlc_mrand48()&7)+2;
120 for( i_col = 0; i_col < i_num_cols ; i_col++ )
122 if( ((unsigned)vlc_mrand48())%noise_level )
124 p_out[i_line*i_out_pitch+i_col] =
125 p_in[i_line*i_in_pitch+i_col];
127 else
129 p_out[i_line*i_out_pitch+i_col] = (vlc_mrand48()&3)*0x7f;
136 return CopyInfoAndRelease( p_outpic, p_pic );