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