]> git.sesse.net Git - vlc/blob - modules/visualization/visual/effects.c
a6fda096325d9f5bcddfd344635a39b5a2e9b937
[vlc] / modules / visualization / visual / effects.c
1 /*****************************************************************************
2  * effects.c : Effects for the visualization system
3  *****************************************************************************
4  * Copyright (C) 2002 VideoLAN
5  * $Id: effects.c,v 1.1 2003/08/19 21:20:00 zorglub Exp $
6  *
7  * Authors: ClĂ©ment Stenac <zorglub@via.ecp.fr>
8  *
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.
13  * 
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.
18  *
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., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
22  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #include "visual.h"
28 #include <math.h>
29
30
31 /*****************************************************************************
32  * Argument list parsers                                                     *
33  *****************************************************************************/
34 int args_getint(char *psz_parse, char * name,const int defaut)
35 {
36     char *psz_eof;
37     int i_value;
38     if( psz_parse != NULL )
39     {
40         if(!strncmp( psz_parse, name, strlen(name) ) )
41         {
42             psz_parse += strlen( name );
43             psz_eof = strchr( psz_parse , ',' );
44             if( !psz_eof)
45                 psz_eof = psz_parse + strlen(psz_parse);
46             if( psz_eof )
47             {
48                 *psz_eof = '\0' ;
49             }
50             i_value = atoi(++psz_parse);
51             psz_parse= psz_eof;
52             psz_parse++;
53             return i_value;
54         }
55     }
56     return defaut;
57 }
58
59
60 char * args_getpsz(char *psz_parse, char * name,const char * defaut)                 
61 {
62     char *psz_eof;
63     char *psz_value;
64     if( psz_parse != NULL )
65     {
66         if(!strncmp( psz_parse, name, strlen(name) ) )                            
67         {
68             psz_parse += strlen( name );
69             psz_eof = strchr( psz_parse , ',' );
70             if( !psz_eof)
71                 psz_eof = psz_parse + strlen(psz_parse);
72             if( psz_eof )
73             {
74                 *psz_eof = '\0' ;
75             }
76             psz_value = strdup(++psz_parse);
77             psz_parse= psz_eof;
78             psz_parse++;
79             return psz_value;
80         }
81     }
82         return strdup(defaut);
83 }
84
85
86 /*****************************************************************************
87  * dummy_Run
88  *****************************************************************************/
89 int dummy_Run( visual_effect_t * p_effect, aout_instance_t *p_aout,
90                aout_buffer_t * p_buffer , picture_t * p_picture)
91 {
92     return 0;
93 }
94
95 /*****************************************************************************
96  * spectrum_Run: spectrum analyser
97  *****************************************************************************/
98 int spectrum_Run(visual_effect_t * p_effect, aout_instance_t *p_aout,
99                  aout_buffer_t * p_buffer , picture_t * p_picture)
100 {
101         return 0;
102 }
103
104         
105 /*****************************************************************************
106  * scope_Run: scope effect
107  *****************************************************************************/
108 int scope_Run(visual_effect_t * p_effect, aout_instance_t *p_aout,
109               aout_buffer_t * p_buffer , picture_t * p_picture)
110 {
111     int i_index;
112     float *p_sample ;
113     u8 *ppp_area[2][3];
114   
115     
116         for( i_index = 0 ; i_index < 2 ; i_index++ )
117         {
118             int j;
119             for( j = 0 ; j < 3 ; j++ )
120             {
121                 ppp_area[i_index][j] =
122                     p_picture->p[j].p_pixels + i_index * p_picture->p[j].i_lines
123                                 / 2 * p_picture->p[j].i_pitch;
124             }
125         }
126
127         for( i_index = 0, p_sample = (float *)p_buffer->p_buffer;
128              i_index < p_effect->i_width;
129              i_index++ )
130         {
131             u8 i_value;
132
133             /* Left channel */
134             i_value =  (*p_sample++ +1) * 127; 
135             *(ppp_area[0][0]
136                + p_picture->p[0].i_pitch * i_index / p_effect->i_width
137                + p_picture->p[0].i_lines * i_value / 512
138                    * p_picture->p[0].i_pitch) = 0xbf;
139             *(ppp_area[0][1]
140                 + p_picture->p[1].i_pitch * i_index / p_effect->i_width
141                 + p_picture->p[1].i_lines * i_value / 512
142                    * p_picture->p[1].i_pitch) = 0xff;
143
144                 
145            /* Right channel */
146            i_value = ( *p_sample++ +1 ) * 127;
147            *(ppp_area[1][0]
148               + p_picture->p[0].i_pitch * i_index / p_effect->i_width
149               + p_picture->p[0].i_lines * i_value / 512
150                  * p_picture->p[0].i_pitch) = 0x9f;
151            *(ppp_area[1][2]
152               + p_picture->p[2].i_pitch * i_index / p_effect->i_width
153               + p_picture->p[2].i_lines * i_value / 512
154                 * p_picture->p[2].i_pitch) = 0xdd;
155         }
156         return 0;
157 }
158
159
160 /*****************************************************************************
161  * random_Run:  random plots display effect
162  *****************************************************************************/
163 int random_Run(visual_effect_t * p_effect, aout_instance_t *p_aout,
164               aout_buffer_t * p_buffer , picture_t * p_picture)
165 {
166     int i_nb_plots;
167     char *psz_parse= NULL;
168     int i , i_y , i_u , i_v;
169     int i_position;
170     srand((unsigned int)mdate());
171
172     if( p_effect->psz_args )
173     {
174         psz_parse = strdup( p_effect->psz_args );
175         while(1)
176         {
177             i_nb_plots = args_getint ( psz_parse , "nb" , 200 );
178             if(i_nb_plots) break;
179             if( *psz_parse )
180                  psz_parse ++;
181             else
182                 break;
183         }
184     }
185     else
186     {
187         i_nb_plots = 200;
188     }
189
190     for( i = 0 ; i < i_nb_plots ; i++ )
191     {
192         i_position = rand() % (p_effect->i_width * p_effect->i_height );
193         i_y = rand() % 256;
194         i_u = rand() % 256;
195         i_v = rand() % 256;
196         *(p_picture->p[0].p_pixels + i_position )= i_u;
197     }
198     return 0;
199 }