]> git.sesse.net Git - vlc/blob - modules/video_filter/magnify.c
Fixed filters implemented as vout (Init/End can be called multiple times
[vlc] / modules / video_filter / magnify.c
1 /*****************************************************************************
2  * magnify.c : Magnify/Zoom interactive effect
3  *****************************************************************************
4  * Copyright (C) 2005 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Antoine Cellerier <dionoea -at- videolan -dot- org>
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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27
28 #ifdef HAVE_CONFIG_H
29 # include "config.h"
30 #endif
31
32 #include <vlc_common.h>
33 #include <vlc_plugin.h>
34 #include <vlc_vout.h>
35
36 #include <math.h>
37
38 #include "filter_common.h"
39 #include "filter_picture.h"
40
41 #include "vlc_image.h"
42 #include "vlc_input.h"
43 #include "vlc_playlist.h"
44
45 /*****************************************************************************
46  * Local prototypes
47  *****************************************************************************/
48 static int  Create    ( vlc_object_t * );
49 static void Destroy   ( vlc_object_t * );
50
51 static int  Init      ( vout_thread_t * );
52 static void End       ( vout_thread_t * );
53 static void Render    ( vout_thread_t *, picture_t * );
54
55 static int  SendEvents   ( vlc_object_t *, char const *,
56                            vlc_value_t, vlc_value_t, void * );
57 static int  MouseEvent   ( vlc_object_t *, char const *,
58                            vlc_value_t, vlc_value_t, void * );
59
60 /*****************************************************************************
61  * Module descriptor
62  *****************************************************************************/
63 vlc_module_begin();
64     set_description( N_("Magnify/Zoom interactive video filter") );
65     set_shortname( N_( "Magnify" ));
66     set_capability( "video filter", 0 );
67     set_category( CAT_VIDEO );
68     set_subcategory( SUBCAT_VIDEO_VFILTER );
69
70     set_callbacks( Create, Destroy );
71 vlc_module_end();
72
73 /*****************************************************************************
74  * vout_sys_t: Magnify video output method descriptor
75  *****************************************************************************/
76 struct vout_sys_t
77 {
78     vout_thread_t *p_vout;
79
80     image_handler_t *p_image;
81
82     int i_zoom; /* zoom level in percent */
83     int i_x, i_y; /* top left corner coordinates in original image */
84
85     bool b_visible; /* is "interface" visible ? */
86 };
87
88 /*****************************************************************************
89  * Control: control facility for the vout (forwards to child vout)
90  *****************************************************************************/
91 static int Control( vout_thread_t *p_vout, int i_query, va_list args )
92 {
93     return vout_vaControl( p_vout->p_sys->p_vout, i_query, args );
94 }
95
96 /*****************************************************************************
97  * Create: allocates Magnify video thread output method
98  *****************************************************************************/
99 static int Create( vlc_object_t *p_this )
100 {
101     vout_thread_t *p_vout = (vout_thread_t *)p_this;
102
103     switch( p_vout->fmt_in.i_chroma )
104     {
105         CASE_PLANAR_YUV
106         case VLC_FOURCC('G','R','E','Y'):
107             break;
108         default:
109             msg_Err( p_vout, "Unsupported chroma" );
110             return VLC_EGENERIC;
111     }
112
113     /* Allocate structure */
114     p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
115     if( p_vout->p_sys == NULL )
116         return VLC_ENOMEM;
117
118     p_vout->p_sys->p_image = image_HandlerCreate( p_vout );
119
120     p_vout->pf_init = Init;
121     p_vout->pf_end = End;
122     p_vout->pf_manage = NULL;
123     p_vout->pf_render = Render;
124     p_vout->pf_display = NULL;
125     p_vout->pf_control = Control;
126
127     return VLC_SUCCESS;
128 }
129
130 /*****************************************************************************
131  * Init: initialize Magnify video thread output method
132  *****************************************************************************/
133 static int Init( vout_thread_t *p_vout )
134 {
135     int i_index;
136     picture_t *p_pic;
137     video_format_t fmt;
138
139     memset( &fmt, 0, sizeof(video_format_t) );
140     I_OUTPUTPICTURES = 0;
141
142     /* Initialize the output structure */
143     p_vout->output.i_chroma = p_vout->render.i_chroma;
144     p_vout->output.i_width  = p_vout->render.i_width;
145     p_vout->output.i_height = p_vout->render.i_height;
146     p_vout->output.i_aspect = p_vout->render.i_aspect;
147
148     p_vout->fmt_out = p_vout->fmt_in;
149     fmt = p_vout->fmt_out;
150
151     /* Try to open the real video output */
152     msg_Dbg( p_vout, "spawning the real video output" );
153
154     p_vout->p_sys->p_vout = vout_Create( p_vout, &fmt );
155
156     /* Everything failed */
157     if( p_vout->p_sys->p_vout == NULL )
158     {
159         msg_Err( p_vout, "cannot open vout, aborting" );
160         return VLC_EGENERIC;
161     }
162
163 #define VIS_ZOOM 4
164     p_vout->p_sys->i_x = 0;
165     p_vout->p_sys->i_y = 0;
166 #define ZOOM_FACTOR 8
167     p_vout->p_sys->i_zoom = 2*ZOOM_FACTOR;
168     p_vout->p_sys->b_visible = true;
169
170     var_AddCallback( p_vout->p_sys->p_vout, "mouse-x", MouseEvent, p_vout );
171     var_AddCallback( p_vout->p_sys->p_vout, "mouse-y", MouseEvent, p_vout );
172     var_AddCallback( p_vout->p_sys->p_vout, "mouse-clicked",
173                      MouseEvent, p_vout);
174
175     ALLOCATE_DIRECTBUFFERS( VOUT_MAX_PICTURES );
176     ADD_CALLBACKS( p_vout->p_sys->p_vout, SendEvents );
177     ADD_PARENT_CALLBACKS( SendEventsToChild );
178
179     return VLC_SUCCESS;
180 }
181
182 /*****************************************************************************
183  * End: terminate Magnify video thread output method
184  *****************************************************************************/
185 static void End( vout_thread_t *p_vout )
186 {
187     int i_index;
188
189     DEL_PARENT_CALLBACKS( SendEventsToChild );
190
191     DEL_CALLBACKS( p_vout->p_sys->p_vout, SendEvents );
192
193     /* Free the fake output buffers we allocated */
194     for( i_index = I_OUTPUTPICTURES ; i_index ; )
195     {
196         i_index--;
197         free( PP_OUTPUTPICTURE[ i_index ]->p_data_orig );
198     }
199
200     var_DelCallback( p_vout->p_sys->p_vout, "mouse-x", MouseEvent, p_vout);
201     var_DelCallback( p_vout->p_sys->p_vout, "mouse-y", MouseEvent, p_vout);
202     var_DelCallback( p_vout->p_sys->p_vout, "mouse-clicked", MouseEvent, p_vout);
203
204     vout_Destroy( p_vout->p_sys->p_vout );
205 }
206
207 /*****************************************************************************
208  * Destroy: destroy Magnify video thread output method
209  *****************************************************************************/
210 static void Destroy( vlc_object_t *p_this )
211 {
212     vout_thread_t *p_vout = (vout_thread_t *)p_this;
213
214     image_HandlerDelete( p_vout->p_sys->p_image );
215
216
217     free( p_vout->p_sys );
218 }
219
220 /*****************************************************************************
221  * Render: displays previously rendered output
222  *****************************************************************************/
223 static void Render( vout_thread_t *p_vout, picture_t *p_pic )
224 {
225     picture_t *p_outpic;
226
227     int o_x = p_vout->p_sys->i_x;
228     int o_y = p_vout->p_sys->i_y;
229     int o_zoom = p_vout->p_sys->i_zoom;
230     int x,y,o_yp,o_xp;
231     int v_w, v_h;
232     video_format_t fmt_out;
233     picture_t *p_converted;
234     plane_t *p_oyp=NULL;
235     int i_plane;
236
237     memset( &fmt_out, 0, sizeof(video_format_t) );
238     /* This is a new frame. Get a structure from the video_output. */
239     while( ( p_outpic = vout_CreatePicture( p_vout->p_sys->p_vout, 0, 0, 0 ) )
240               == NULL )
241     {
242         if( !vlc_object_alive (p_vout) || p_vout->b_error )
243         {
244             return;
245         }
246         msleep( VOUT_OUTMEM_SLEEP );
247     }
248
249     vout_DatePicture( p_vout->p_sys->p_vout, p_outpic, p_pic->date );
250
251     p_oyp = &(p_outpic->p[Y_PLANE]);
252
253     /* background magnified image */
254     if( o_zoom != ZOOM_FACTOR )
255     {
256         for( i_plane = 0; i_plane < p_pic->i_planes; i_plane++ )
257         {
258             o_yp = o_y*p_outpic->p[i_plane].i_lines
259                    /p_outpic->p[Y_PLANE].i_lines;
260             o_xp = o_x*p_outpic->p[i_plane].i_pitch
261                    /p_outpic->p[Y_PLANE].i_pitch;
262             int i_pitch = p_outpic->p[i_plane].i_pitch;
263 #if 0
264             int o_zoom2 = o_zoom*o_zoom;
265             int o_zoom3 = o_zoom*o_zoom*o_zoom;
266             int o_zoom4 = o_zoom*o_zoom*o_zoom*o_zoom;
267             int o_zoom6 = o_zoom*o_zoom*o_zoom * o_zoom*o_zoom*o_zoom;
268 #endif
269             for( y=0; y<p_outpic->p[i_plane].i_visible_lines; y++ )
270             {
271                 for( x=0; x<p_outpic->p[i_plane].i_visible_pitch; x++ )
272                 {
273 #if 0
274                     /* Nearest neighbor */
275                     int nx = o_xp + x*ZOOM_FACTOR/o_zoom;
276                     int ny = o_yp + y*ZOOM_FACTOR/o_zoom;
277                     p_outpic->p[i_plane].p_pixels[y*i_pitch+x] =
278                         p_pic->p[i_plane].p_pixels[ny*i_pitch+nx];
279 #elif 1
280                     /* Bi-linear */
281                     int nx_real = o_xp*o_zoom + x*ZOOM_FACTOR;
282                     int ny_real = o_yp*o_zoom + y*ZOOM_FACTOR;
283                     int nx = nx_real/o_zoom;
284                     int ny = ny_real/o_zoom;
285                     int wtl = ((nx+1)*o_zoom-nx_real)*((ny+1)*o_zoom-ny_real);
286                     int wtr = (nx_real-nx*o_zoom)*((ny+1)*o_zoom-ny_real);
287                     int wbl = ((nx+1)*o_zoom-nx_real)*(ny_real-ny*o_zoom);
288                     int wbr = (nx_real-nx*o_zoom)*(ny_real-ny*o_zoom);
289                     p_outpic->p[i_plane].p_pixels[y*i_pitch+x] =
290                         ( wtl*p_pic->p[i_plane].p_pixels[ny*i_pitch+nx]
291                         + wtr*p_pic->p[i_plane].p_pixels[ny*i_pitch+(nx+1)]
292                         + wbl*p_pic->p[i_plane].p_pixels[(ny+1)*i_pitch+nx]
293                         + wbr*p_pic->p[i_plane].p_pixels[(ny+1)*i_pitch+(nx+1)]
294                         ) / (o_zoom*o_zoom);
295 #else
296                     /* Bi-cubic */
297                     /* FIXME: doesn't work */
298                     /* \Sigma_{i=0..3} \Sigma_{j=0..3} \alpha_{i,j} x^i y^j
299                      * 16 \alpha_{i,j} so we need to use the 16 nearest pixels
300                      *
301                      * In fact we should be able to write it as:
302                      * \Pi_{i=1..16} [ \Pi_{j!=i} ( x - x_j ) * ( y - y_j ) ]
303                      *   * z_i / [ \Pi_{j!=i} ( x_i - x_j ) * ( y_i - y_j ) ]
304                      * We also have to make sure that we don't use any
305                      * x_j == x_i or y_j == y_i in the \Pi on j (else we get
306                      * a 0/0 which kind of sucks) .
307                      */
308                     uint8_t *p = p_pic->p[i_plane].p_pixels;
309                     int nx_real = o_xp*o_zoom + x*ZOOM_FACTOR;
310                     int ny_real = o_yp*o_zoom + y*ZOOM_FACTOR;
311
312                     int nx = nx_real/o_zoom;
313                     int ny = ny_real/o_zoom;
314
315                     int xi, yi, xj, yj;
316                     int my = __MAX( ny-1, 0 );
317                     int mx = __MAX( nx-1, 0 );
318                     //p_outpic->p[i_plane].i_visible_lines - 4
319                     //p_outpic->p[i_plane].i_visible_pitch - 4
320                     int v = 1;
321                     for( yi = my; yi <= my+3; yi++ )
322                     {
323                         int numy = 1;
324                         int deny = 1;
325                         /*
326                         for( yj = my; yj <= my+3; yj++ )
327                         {
328                             if( yj != yi )
329                             {
330                                 numy *= (ny_real-yj*o_zoom);
331                                 deny *= (yi - yj);
332                             }
333                         }
334                         numy /= o_zoom2;*/
335                         for( xi = mx; xi <= mx+3; xi++ )
336                         {
337                             int num = numy;
338                             int den = deny;
339                             for( xj = mx; xj <= mx+3; xj++ )
340                             {
341                                 if( xj != xi )
342                                 {
343                                     num *= (nx_real-xj*o_zoom);
344                                     den *= (xi - xj);
345                                 }
346                             }
347                             v = ( v * (p[yi*i_pitch+xi] * num) ) / ( den * o_zoom3 );
348                         }
349                     }
350                     p_outpic->p[i_plane].p_pixels[y*i_pitch+x] = v;
351 #endif
352                 }
353             }
354         }
355     }
356     else
357     {
358         for( i_plane = 0; i_plane < p_pic->i_planes; i_plane++ )
359         {
360         vlc_memcpy( p_outpic->p[i_plane].p_pixels, p_pic->p[i_plane].p_pixels,
361             p_outpic->p[i_plane].i_lines * p_outpic->p[i_plane].i_pitch );
362         }
363     }
364
365     if( p_vout->p_sys->b_visible )
366     {
367         /* image visualization */
368         fmt_out = p_vout->fmt_out;
369         fmt_out.i_width = p_vout->render.i_width/VIS_ZOOM;
370         fmt_out.i_height = p_vout->render.i_height/VIS_ZOOM;
371         p_converted = image_Convert( p_vout->p_sys->p_image, p_pic,
372                                      &(p_pic->format), &fmt_out );
373         for( i_plane = 0; i_plane < p_pic->i_planes; i_plane++ )
374         {
375             for( y=0; y<p_converted->p[i_plane].i_visible_lines; y++)
376             {
377                 vlc_memcpy(
378                 p_outpic->p[i_plane].p_pixels+y*p_outpic->p[i_plane].i_pitch,
379                 p_converted->p[i_plane].p_pixels+y*p_converted->p[i_plane].i_pitch,
380                 p_converted->p[i_plane].i_visible_pitch );
381             }
382         }
383         p_converted->pf_release( p_converted );
384
385         /* white rectangle on visualization */
386         v_w = p_oyp->i_pitch*ZOOM_FACTOR/(VIS_ZOOM*o_zoom);
387         v_h = (o_y+p_oyp->i_lines*ZOOM_FACTOR/o_zoom)/VIS_ZOOM;
388         /* top line */
389         vlc_memset( p_oyp->p_pixels
390                                      + o_y/VIS_ZOOM*p_oyp->i_pitch
391                                      + o_x/VIS_ZOOM, 0xff, v_w+1 );
392
393         for( y = o_y/VIS_ZOOM+1; y < v_h; y++ )
394         {
395             /* left line */
396             p_oyp->p_pixels[
397                 y*p_oyp->i_pitch+o_x/VIS_ZOOM
398             ] = 0xff;
399             /* right line */
400             p_oyp->p_pixels[
401                 y*p_oyp->i_pitch+o_x/VIS_ZOOM + v_w
402             ] = 0xff;
403         }
404         /* bottom line */
405         vlc_memset( p_oyp->p_pixels
406                                      + v_h*p_oyp->i_pitch
407                                      + o_x/VIS_ZOOM, 0xff, v_w+1 );
408
409         /* */
410         v_h = p_oyp->i_lines/VIS_ZOOM;
411     }
412     else
413     {
414         v_h = 1;
415     }
416
417     /* print a small "VLC ZOOM" ... gruikkkkkkkkk */
418 #define DRAW(a) {int c,l=1;L a;}
419 #define L ;l++,c=1
420 #define X ;draw(l,c);c+=1
421 #define o +1
422 #define draw(y,x) p_oyp->p_pixels[(v_h+y)*p_oyp->i_pitch+x] = 0xff;
423 if( p_vout->p_sys->b_visible )
424 DRAW(
425 X o o o X o X o o o o o o X X X X o o o X X X X X o o X X X o o o X X X o o X X o X X o o o X o o o X o X X X X X o X X X X o o X X X X X L
426 X o o o X o X o o o o o X o o o o o o o o o o X o o X o o o X o X o o o X o X o X o X o o o X o o o X o o o X o o o X o o o X o X o o o o L
427 o X o X o o X o o o o o X o o o o o o o o o X o o o X o o o X o X o o o X o X o o o X o o o X X X X X o o o X o o o X o o o X o X X X X o L
428 o X o X o o X o o o o o X o o o o o o o o X o o o o X o o o X o X o o o X o X o o o X o o o X o o o X o o o X o o o X o o o X o X o o o o L
429 o o X o o o X X X X X o o X X X X o o o X X X X X o o X X X o o o X X X o o X o o o X o o o X o o o X o X X X X X o X X X X o o X X X X X L
430 )
431 else
432 DRAW(
433 X o o o X o X o o o o o o X X X X o o o X X X X X o o X X X o o o X X X o o X X o X X o o o o X X X X o X o o o X o o X X X o o X o o o X L
434 X o o o X o X o o o o o X o o o o o o o o o o X o o X o o o X o X o o o X o X o X o X o o o X o o o o o X o o o X o X o o o X o X o o o X L
435 o X o X o o X o o o o o X o o o o o o o o o X o o o X o o o X o X o o o X o X o o o X o o o o X X X o o X X X X X o X o o o X o X o X o X L
436 o X o X o o X o o o o o X o o o o o o o o X o o o o X o o o X o X o o o X o X o o o X o o o o o o o X o X o o o X o X o o o X o X o X o X L
437 o o X o o o X X X X X o o X X X X o o o X X X X X o o X X X o o o X X X o o X o o o X o o o X X X X o o X o o o X o o X X X o o o X o X o L
438 )
439 #undef DRAW
440 #undef L
441 #undef X
442 #undef O
443 #undef draw
444
445     if( p_vout->p_sys->b_visible )
446     {
447         /* zoom gauge */
448         vlc_memset( p_oyp->p_pixels + (v_h+9)*p_oyp->i_pitch, 0xff, 41 );
449         for( y = v_h + 10; y < v_h + 90; y++ )
450         {
451             int width = v_h + 90 - y;
452             width = (width*width)/160;
453             if( (80 - y + v_h)*ZOOM_FACTOR/10 < o_zoom )
454             {
455                 vlc_memset( p_oyp->p_pixels + y*p_oyp->i_pitch, 0xff, width );
456             }
457             else
458             {
459                 p_oyp->p_pixels[y*p_oyp->i_pitch] = 0xff;
460                 p_oyp->p_pixels[y*p_oyp->i_pitch + width - 1] = 0xff;
461             }
462         }
463     }
464
465     vout_DisplayPicture( p_vout->p_sys->p_vout, p_outpic );
466 }
467
468 /*****************************************************************************
469  * SendEvents: forward mouse and keyboard events to the parent p_vout
470  *****************************************************************************/
471 static int SendEvents( vlc_object_t *p_this, char const *psz_var,
472                        vlc_value_t oldval, vlc_value_t newval, void *p_data )
473 {
474     VLC_UNUSED(p_this); VLC_UNUSED(oldval);
475     var_Set( (vlc_object_t *)p_data, psz_var, newval );
476
477     return VLC_SUCCESS;
478 }
479
480 /*****************************************************************************
481  * SendEventsToChild: forward events to the child/children vout
482  *****************************************************************************/
483 static int SendEventsToChild( vlc_object_t *p_this, char const *psz_var,
484                        vlc_value_t oldval, vlc_value_t newval, void *p_data )
485 {
486     VLC_UNUSED(p_data); VLC_UNUSED(oldval);
487     vout_thread_t *p_vout = (vout_thread_t *)p_this;
488     var_Set( p_vout->p_sys->p_vout, psz_var, newval );
489     return VLC_SUCCESS;
490 }
491
492 /*****************************************************************************
493  * MouseEvent: callback for mouse events
494  *****************************************************************************/
495 static int MouseEvent( vlc_object_t *p_this, char const *psz_var,
496                        vlc_value_t oldval, vlc_value_t newval, void *p_data )
497 {
498     VLC_UNUSED(p_this);
499     vout_thread_t *p_vout = (vout_thread_t*)p_data;
500     vlc_value_t vald,valx,valy;
501
502 #define MOUSE_DOWN    1
503 #define MOUSE_CLICKED 2
504 #define MOUSE_MOVE_X  4
505 #define MOUSE_MOVE_Y  8
506 #define MOUSE_MOVE    12
507     uint8_t mouse= 0;
508
509     int v_h = p_vout->output.i_height*ZOOM_FACTOR/p_vout->p_sys->i_zoom;
510     int v_w = p_vout->output.i_width*ZOOM_FACTOR/p_vout->p_sys->i_zoom;
511
512     if( psz_var[6] == 'x' ) mouse |= MOUSE_MOVE_X;
513     if( psz_var[6] == 'y' ) mouse |= MOUSE_MOVE_Y;
514     if( psz_var[6] == 'c' ) mouse |= MOUSE_CLICKED;
515
516     var_Get( p_vout->p_sys->p_vout, "mouse-button-down", &vald );
517     if( vald.i_int & 0x1 ) mouse |= MOUSE_DOWN;
518     var_Get( p_vout->p_sys->p_vout, "mouse-y", &valy );
519     var_Get( p_vout->p_sys->p_vout, "mouse-x", &valx );
520
521     if( ( mouse&MOUSE_MOVE && mouse&MOUSE_DOWN)
522         || mouse&MOUSE_CLICKED )
523     {
524     /* (mouse moved and mouse button is down) or (mouse clicked) */
525         if( p_vout->p_sys->b_visible )
526         {
527             if(    0 <= valy.i_int
528                 && valy.i_int < (int)p_vout->output.i_height/VIS_ZOOM
529                 && 0 <= valx.i_int
530                 && valx.i_int < (int)p_vout->output.i_width/VIS_ZOOM )
531             {
532             /* mouse is over visualisation */
533                 p_vout->p_sys->i_x = __MIN( __MAX( valx.i_int*VIS_ZOOM - v_w/2, 0 ),
534                                             p_vout->output.i_width - v_w - 1);
535                 p_vout->p_sys->i_y = __MIN( __MAX( valy.i_int * VIS_ZOOM - v_h/2,
536                                         0 ), p_vout->output.i_height - v_h - 1);
537             }
538             else if( valx.i_int >= 0 && valx.i_int < 80
539                 && valy.i_int >= (int)p_vout->output.i_height/VIS_ZOOM
540                 && valy.i_int < (int)p_vout->output.i_height/VIS_ZOOM + 9
541                 && mouse&MOUSE_CLICKED )
542             {
543             /* mouse is over the "VLC ZOOM HIDE" text */
544                 p_vout->p_sys->b_visible = false;
545             }
546             else if(    (int)p_vout->output.i_height/VIS_ZOOM + 9 <= valy.i_int
547                      && valy.i_int <= (int)p_vout->output.i_height/VIS_ZOOM + 90
548                      && 0 <= valx.i_int
549                      && valx.i_int <=
550                      (( (int)p_vout->output.i_height/VIS_ZOOM + 90 -  valy.i_int)
551                *( (int)p_vout->output.i_height/VIS_ZOOM + 90 -  valy.i_int))/160 )
552             {
553             /* mouse is over zoom gauge */
554                 p_vout->p_sys->i_zoom = __MAX( ZOOM_FACTOR,
555                                 ( 80 + (int)p_vout->output.i_height/VIS_ZOOM
556                                    - valy.i_int + 2) * ZOOM_FACTOR/10 );
557             }
558             else if( mouse&MOUSE_MOVE_X && !(mouse&MOUSE_CLICKED) )
559             {
560                 p_vout->p_sys->i_x -= (newval.i_int - oldval.i_int)
561                                       *ZOOM_FACTOR/p_vout->p_sys->i_zoom;
562             }
563             else if( mouse&MOUSE_MOVE_Y && !(mouse&MOUSE_CLICKED) )
564             {
565                 p_vout->p_sys->i_y -= (newval.i_int - oldval.i_int)
566                                       *ZOOM_FACTOR/p_vout->p_sys->i_zoom;
567             }
568         }
569         else
570         {
571             if( valx.i_int >= 0 && valx.i_int < 80 && valy.i_int >= 0
572                 && valy.i_int <= 10 && mouse&MOUSE_CLICKED )
573             {
574             /* mouse is over the "VLC ZOOM SHOW" text */
575                 p_vout->p_sys->b_visible = true;
576             }
577             else if( mouse&MOUSE_MOVE_X && !(mouse&MOUSE_CLICKED) )
578             {
579                 p_vout->p_sys->i_x -= (newval.i_int - oldval.i_int)
580                                       *ZOOM_FACTOR/p_vout->p_sys->i_zoom;
581             }
582             else if( mouse&MOUSE_MOVE_Y && !(mouse&MOUSE_CLICKED) )
583             {
584                 p_vout->p_sys->i_y -= (newval.i_int - oldval.i_int)
585                                       *ZOOM_FACTOR/p_vout->p_sys->i_zoom;
586             }
587         }
588     }
589
590     p_vout->p_sys->i_x =
591          __MAX( 0, __MIN( p_vout->p_sys->i_x, (int)p_vout->output.i_width
592          - (int)p_vout->output.i_width*ZOOM_FACTOR/p_vout->p_sys->i_zoom - 1 ));
593     p_vout->p_sys->i_y =
594          __MAX( 0, __MIN( p_vout->p_sys->i_y, (int)p_vout->output.i_height
595         - (int)p_vout->output.i_height*ZOOM_FACTOR/p_vout->p_sys->i_zoom - 1 ));
596
597
598     return VLC_SUCCESS;
599 }