Remove unnedeeded msg_Error.
[vlc.git] / 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     /* Free the fake output buffers we allocated */
190     for( i_index = I_OUTPUTPICTURES ; i_index ; )
191     {
192         i_index--;
193         free( PP_OUTPUTPICTURE[ i_index ]->p_data_orig );
194     }
195
196     var_DelCallback( p_vout->p_sys->p_vout, "mouse-x", MouseEvent, p_vout);
197     var_DelCallback( p_vout->p_sys->p_vout, "mouse-y", MouseEvent, p_vout);
198     var_DelCallback( p_vout->p_sys->p_vout, "mouse-clicked", MouseEvent, p_vout);
199 }
200
201 /*****************************************************************************
202  * Destroy: destroy Magnify video thread output method
203  *****************************************************************************/
204 static void Destroy( vlc_object_t *p_this )
205 {
206     vout_thread_t *p_vout = (vout_thread_t *)p_this;
207
208     if( p_vout->p_sys->p_vout )
209     {
210         DEL_CALLBACKS( p_vout->p_sys->p_vout, SendEvents );
211         vlc_object_detach( p_vout->p_sys->p_vout );
212         vlc_object_release( p_vout->p_sys->p_vout );
213     }
214
215     image_HandlerDelete( p_vout->p_sys->p_image );
216
217     DEL_PARENT_CALLBACKS( SendEventsToChild );
218
219     free( p_vout->p_sys );
220 }
221
222 /*****************************************************************************
223  * Render: displays previously rendered output
224  *****************************************************************************/
225 static void Render( vout_thread_t *p_vout, picture_t *p_pic )
226 {
227     picture_t *p_outpic;
228
229     int o_x = p_vout->p_sys->i_x;
230     int o_y = p_vout->p_sys->i_y;
231     int o_zoom = p_vout->p_sys->i_zoom;
232     int x,y,o_yp,o_xp;
233     int v_w, v_h;
234     video_format_t fmt_out;
235     picture_t *p_converted;
236     plane_t *p_oyp=NULL;
237     int i_plane;
238
239     memset( &fmt_out, 0, sizeof(video_format_t) );
240     /* This is a new frame. Get a structure from the video_output. */
241     while( ( p_outpic = vout_CreatePicture( p_vout->p_sys->p_vout, 0, 0, 0 ) )
242               == NULL )
243     {
244         if( p_vout->b_die || p_vout->b_error )
245         {
246             return;
247         }
248         msleep( VOUT_OUTMEM_SLEEP );
249     }
250
251     vout_DatePicture( p_vout->p_sys->p_vout, p_outpic, p_pic->date );
252
253     p_oyp = &(p_outpic->p[Y_PLANE]);
254
255     /* background magnified image */
256     if( o_zoom != ZOOM_FACTOR )
257     {
258         for( i_plane = 0; i_plane < p_pic->i_planes; i_plane++ )
259         {
260             o_yp = o_y*p_outpic->p[i_plane].i_lines
261                    /p_outpic->p[Y_PLANE].i_lines;
262             o_xp = o_x*p_outpic->p[i_plane].i_pitch
263                    /p_outpic->p[Y_PLANE].i_pitch;
264             int i_pitch = p_outpic->p[i_plane].i_pitch;
265 #if 0
266             int o_zoom2 = o_zoom*o_zoom;
267             int o_zoom3 = o_zoom*o_zoom*o_zoom;
268             int o_zoom4 = o_zoom*o_zoom*o_zoom*o_zoom;
269             int o_zoom6 = o_zoom*o_zoom*o_zoom * o_zoom*o_zoom*o_zoom;
270 #endif
271             for( y=0; y<p_outpic->p[i_plane].i_visible_lines; y++ )
272             {
273                 for( x=0; x<p_outpic->p[i_plane].i_visible_pitch; x++ )
274                 {
275 #if 0
276                     /* Nearest neighbor */
277                     int nx = o_xp + x*ZOOM_FACTOR/o_zoom;
278                     int ny = o_yp + y*ZOOM_FACTOR/o_zoom;
279                     p_outpic->p[i_plane].p_pixels[y*i_pitch+x] =
280                         p_pic->p[i_plane].p_pixels[ny*i_pitch+nx];
281 #elif 1
282                     /* Bi-linear */
283                     int nx_real = o_xp*o_zoom + x*ZOOM_FACTOR;
284                     int ny_real = o_yp*o_zoom + y*ZOOM_FACTOR;
285                     int nx = nx_real/o_zoom;
286                     int ny = ny_real/o_zoom;
287                     int wtl = ((nx+1)*o_zoom-nx_real)*((ny+1)*o_zoom-ny_real);
288                     int wtr = (nx_real-nx*o_zoom)*((ny+1)*o_zoom-ny_real);
289                     int wbl = ((nx+1)*o_zoom-nx_real)*(ny_real-ny*o_zoom);
290                     int wbr = (nx_real-nx*o_zoom)*(ny_real-ny*o_zoom);
291                     p_outpic->p[i_plane].p_pixels[y*i_pitch+x] =
292                         ( wtl*p_pic->p[i_plane].p_pixels[ny*i_pitch+nx]
293                         + wtr*p_pic->p[i_plane].p_pixels[ny*i_pitch+(nx+1)]
294                         + wbl*p_pic->p[i_plane].p_pixels[(ny+1)*i_pitch+nx]
295                         + wbr*p_pic->p[i_plane].p_pixels[(ny+1)*i_pitch+(nx+1)]
296                         ) / (o_zoom*o_zoom);
297 #else
298                     /* Bi-cubic */
299                     /* FIXME: doesn't work */
300                     /* \Sigma_{i=0..3} \Sigma_{j=0..3} \alpha_{i,j} x^i y^j
301                      * 16 \alpha_{i,j} so we need to use the 16 nearest pixels
302                      *
303                      * In fact we should be able to write it as:
304                      * \Pi_{i=1..16} [ \Pi_{j!=i} ( x - x_j ) * ( y - y_j ) ]
305                      *   * z_i / [ \Pi_{j!=i} ( x_i - x_j ) * ( y_i - y_j ) ]
306                      * We also have to make sure that we don't use any
307                      * x_j == x_i or y_j == y_i in the \Pi on j (else we get
308                      * a 0/0 which kind of sucks) .
309                      */
310                     uint8_t *p = p_pic->p[i_plane].p_pixels;
311                     int nx_real = o_xp*o_zoom + x*ZOOM_FACTOR;
312                     int ny_real = o_yp*o_zoom + y*ZOOM_FACTOR;
313
314                     int nx = nx_real/o_zoom;
315                     int ny = ny_real/o_zoom;
316
317                     int xi, yi, xj, yj;
318                     int my = __MAX( ny-1, 0 );
319                     int mx = __MAX( nx-1, 0 );
320                     //p_outpic->p[i_plane].i_visible_lines - 4
321                     //p_outpic->p[i_plane].i_visible_pitch - 4
322                     int v = 1;
323                     for( yi = my; yi <= my+3; yi++ )
324                     {
325                         int numy = 1;
326                         int deny = 1;
327                         /*
328                         for( yj = my; yj <= my+3; yj++ )
329                         {
330                             if( yj != yi )
331                             {
332                                 numy *= (ny_real-yj*o_zoom);
333                                 deny *= (yi - yj);
334                             }
335                         }
336                         numy /= o_zoom2;*/
337                         for( xi = mx; xi <= mx+3; xi++ )
338                         {
339                             int num = numy;
340                             int den = deny;
341                             for( xj = mx; xj <= mx+3; xj++ )
342                             {
343                                 if( xj != xi )
344                                 {
345                                     num *= (nx_real-xj*o_zoom);
346                                     den *= (xi - xj);
347                                 }
348                             }
349                             v = ( v * (p[yi*i_pitch+xi] * num) ) / ( den * o_zoom3 );
350                         }
351                     }
352                     p_outpic->p[i_plane].p_pixels[y*i_pitch+x] = v;
353 #endif
354                 }
355             }
356         }
357     }
358     else
359     {
360         for( i_plane = 0; i_plane < p_pic->i_planes; i_plane++ )
361         {
362         vlc_memcpy( p_outpic->p[i_plane].p_pixels, p_pic->p[i_plane].p_pixels,
363             p_outpic->p[i_plane].i_lines * p_outpic->p[i_plane].i_pitch );
364         }
365     }
366
367     if( p_vout->p_sys->b_visible )
368     {
369         /* image visualization */
370         fmt_out = p_vout->fmt_out;
371         fmt_out.i_width = p_vout->render.i_width/VIS_ZOOM;
372         fmt_out.i_height = p_vout->render.i_height/VIS_ZOOM;
373         p_converted = image_Convert( p_vout->p_sys->p_image, p_pic,
374                                      &(p_pic->format), &fmt_out );
375         for( i_plane = 0; i_plane < p_pic->i_planes; i_plane++ )
376         {
377             for( y=0; y<p_converted->p[i_plane].i_visible_lines; y++)
378             {
379                 vlc_memcpy(
380                 p_outpic->p[i_plane].p_pixels+y*p_outpic->p[i_plane].i_pitch,
381                 p_converted->p[i_plane].p_pixels+y*p_converted->p[i_plane].i_pitch,
382                 p_converted->p[i_plane].i_visible_pitch );
383             }
384         }
385         p_converted->pf_release( p_converted );
386
387         /* white rectangle on visualization */
388         v_w = p_oyp->i_pitch*ZOOM_FACTOR/(VIS_ZOOM*o_zoom);
389         v_h = (o_y+p_oyp->i_lines*ZOOM_FACTOR/o_zoom)/VIS_ZOOM;
390         /* top line */
391         vlc_memset( p_oyp->p_pixels
392                                      + o_y/VIS_ZOOM*p_oyp->i_pitch
393                                      + o_x/VIS_ZOOM, 0xff, v_w+1 );
394
395         for( y = o_y/VIS_ZOOM+1; y < v_h; y++ )
396         {
397             /* left line */
398             p_oyp->p_pixels[
399                 y*p_oyp->i_pitch+o_x/VIS_ZOOM
400             ] = 0xff;
401             /* right line */
402             p_oyp->p_pixels[
403                 y*p_oyp->i_pitch+o_x/VIS_ZOOM + v_w
404             ] = 0xff;
405         }
406         /* bottom line */
407         vlc_memset( p_oyp->p_pixels
408                                      + v_h*p_oyp->i_pitch
409                                      + o_x/VIS_ZOOM, 0xff, v_w+1 );
410
411         /* */
412         v_h = p_oyp->i_lines/VIS_ZOOM;
413     }
414     else
415     {
416         v_h = 1;
417     }
418
419     /* print a small "VLC ZOOM" ... gruikkkkkkkkk */
420 #define DRAW(a) {int c,l=1;L a;}
421 #define L ;l++,c=1
422 #define X ;draw(l,c);c+=1
423 #define o +1
424 #define draw(y,x) p_oyp->p_pixels[(v_h+y)*p_oyp->i_pitch+x] = 0xff;
425 if( p_vout->p_sys->b_visible )
426 DRAW(
427 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
428 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
429 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
430 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
431 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
432 )
433 else
434 DRAW(
435 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
436 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
437 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
438 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
439 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
440 )
441 #undef DRAW
442 #undef L
443 #undef X
444 #undef O
445 #undef draw
446
447     if( p_vout->p_sys->b_visible )
448     {
449         /* zoom gauge */
450         vlc_memset( p_oyp->p_pixels + (v_h+9)*p_oyp->i_pitch, 0xff, 41 );
451         for( y = v_h + 10; y < v_h + 90; y++ )
452         {
453             int width = v_h + 90 - y;
454             width = (width*width)/160;
455             if( (80 - y + v_h)*ZOOM_FACTOR/10 < o_zoom )
456             {
457                 vlc_memset( p_oyp->p_pixels + y*p_oyp->i_pitch, 0xff, width );
458             }
459             else
460             {
461                 p_oyp->p_pixels[y*p_oyp->i_pitch] = 0xff;
462                 p_oyp->p_pixels[y*p_oyp->i_pitch + width - 1] = 0xff;
463             }
464         }
465     }
466
467     vout_DisplayPicture( p_vout->p_sys->p_vout, p_outpic );
468 }
469
470 /*****************************************************************************
471  * SendEvents: forward mouse and keyboard events to the parent p_vout
472  *****************************************************************************/
473 static int SendEvents( vlc_object_t *p_this, char const *psz_var,
474                        vlc_value_t oldval, vlc_value_t newval, void *p_data )
475 {
476     VLC_UNUSED(p_this); VLC_UNUSED(oldval);
477     var_Set( (vlc_object_t *)p_data, psz_var, newval );
478
479     return VLC_SUCCESS;
480 }
481
482 /*****************************************************************************
483  * SendEventsToChild: forward events to the child/children vout
484  *****************************************************************************/
485 static int SendEventsToChild( vlc_object_t *p_this, char const *psz_var,
486                        vlc_value_t oldval, vlc_value_t newval, void *p_data )
487 {
488     VLC_UNUSED(p_data); VLC_UNUSED(oldval);
489     vout_thread_t *p_vout = (vout_thread_t *)p_this;
490     var_Set( p_vout->p_sys->p_vout, psz_var, newval );
491     return VLC_SUCCESS;
492 }
493
494 /*****************************************************************************
495  * MouseEvent: callback for mouse events
496  *****************************************************************************/
497 static int MouseEvent( vlc_object_t *p_this, char const *psz_var,
498                        vlc_value_t oldval, vlc_value_t newval, void *p_data )
499 {
500     VLC_UNUSED(p_this);
501     vout_thread_t *p_vout = (vout_thread_t*)p_data;
502     vlc_value_t vald,valx,valy;
503
504 #define MOUSE_DOWN    1
505 #define MOUSE_CLICKED 2
506 #define MOUSE_MOVE_X  4
507 #define MOUSE_MOVE_Y  8
508 #define MOUSE_MOVE    12
509     uint8_t mouse= 0;
510
511     int v_h = p_vout->output.i_height*ZOOM_FACTOR/p_vout->p_sys->i_zoom;
512     int v_w = p_vout->output.i_width*ZOOM_FACTOR/p_vout->p_sys->i_zoom;
513
514     if( psz_var[6] == 'x' ) mouse |= MOUSE_MOVE_X;
515     if( psz_var[6] == 'y' ) mouse |= MOUSE_MOVE_Y;
516     if( psz_var[6] == 'c' ) mouse |= MOUSE_CLICKED;
517
518     var_Get( p_vout->p_sys->p_vout, "mouse-button-down", &vald );
519     if( vald.i_int & 0x1 ) mouse |= MOUSE_DOWN;
520     var_Get( p_vout->p_sys->p_vout, "mouse-y", &valy );
521     var_Get( p_vout->p_sys->p_vout, "mouse-x", &valx );
522
523     if( ( mouse&MOUSE_MOVE && mouse&MOUSE_DOWN)
524         || mouse&MOUSE_CLICKED )
525     {
526     /* (mouse moved and mouse button is down) or (mouse clicked) */
527         if( p_vout->p_sys->b_visible )
528         {
529             if(    0 <= valy.i_int
530                 && valy.i_int < (int)p_vout->output.i_height/VIS_ZOOM
531                 && 0 <= valx.i_int
532                 && valx.i_int < (int)p_vout->output.i_width/VIS_ZOOM )
533             {
534             /* mouse is over visualisation */
535                 p_vout->p_sys->i_x = __MIN( __MAX( valx.i_int*VIS_ZOOM - v_w/2, 0 ),
536                                             p_vout->output.i_width - v_w - 1);
537                 p_vout->p_sys->i_y = __MIN( __MAX( valy.i_int * VIS_ZOOM - v_h/2,
538                                         0 ), p_vout->output.i_height - v_h - 1);
539             }
540             else if( valx.i_int >= 0 && valx.i_int < 80
541                 && valy.i_int >= (int)p_vout->output.i_height/VIS_ZOOM
542                 && valy.i_int < (int)p_vout->output.i_height/VIS_ZOOM + 9
543                 && mouse&MOUSE_CLICKED )
544             {
545             /* mouse is over the "VLC ZOOM HIDE" text */
546                 p_vout->p_sys->b_visible = false;
547             }
548             else if(    (int)p_vout->output.i_height/VIS_ZOOM + 9 <= valy.i_int
549                      && valy.i_int <= (int)p_vout->output.i_height/VIS_ZOOM + 90
550                      && 0 <= valx.i_int
551                      && valx.i_int <=
552                      (( (int)p_vout->output.i_height/VIS_ZOOM + 90 -  valy.i_int)
553                *( (int)p_vout->output.i_height/VIS_ZOOM + 90 -  valy.i_int))/160 )
554             {
555             /* mouse is over zoom gauge */
556                 p_vout->p_sys->i_zoom = __MAX( ZOOM_FACTOR,
557                                 ( 80 + (int)p_vout->output.i_height/VIS_ZOOM
558                                    - valy.i_int + 2) * ZOOM_FACTOR/10 );
559             }
560             else if( mouse&MOUSE_MOVE_X && !(mouse&MOUSE_CLICKED) )
561             {
562                 p_vout->p_sys->i_x -= (newval.i_int - oldval.i_int)
563                                       *ZOOM_FACTOR/p_vout->p_sys->i_zoom;
564             }
565             else if( mouse&MOUSE_MOVE_Y && !(mouse&MOUSE_CLICKED) )
566             {
567                 p_vout->p_sys->i_y -= (newval.i_int - oldval.i_int)
568                                       *ZOOM_FACTOR/p_vout->p_sys->i_zoom;
569             }
570         }
571         else
572         {
573             if( valx.i_int >= 0 && valx.i_int < 80 && valy.i_int >= 0
574                 && valy.i_int <= 10 && mouse&MOUSE_CLICKED )
575             {
576             /* mouse is over the "VLC ZOOM SHOW" text */
577                 p_vout->p_sys->b_visible = true;
578             }
579             else if( mouse&MOUSE_MOVE_X && !(mouse&MOUSE_CLICKED) )
580             {
581                 p_vout->p_sys->i_x -= (newval.i_int - oldval.i_int)
582                                       *ZOOM_FACTOR/p_vout->p_sys->i_zoom;
583             }
584             else if( mouse&MOUSE_MOVE_Y && !(mouse&MOUSE_CLICKED) )
585             {
586                 p_vout->p_sys->i_y -= (newval.i_int - oldval.i_int)
587                                       *ZOOM_FACTOR/p_vout->p_sys->i_zoom;
588             }
589         }
590     }
591
592     p_vout->p_sys->i_x =
593          __MAX( 0, __MIN( p_vout->p_sys->i_x, (int)p_vout->output.i_width
594          - (int)p_vout->output.i_width*ZOOM_FACTOR/p_vout->p_sys->i_zoom - 1 ));
595     p_vout->p_sys->i_y =
596          __MAX( 0, __MIN( p_vout->p_sys->i_y, (int)p_vout->output.i_height
597         - (int)p_vout->output.i_height*ZOOM_FACTOR/p_vout->p_sys->i_zoom - 1 ));
598
599
600     return VLC_SUCCESS;
601 }