]> git.sesse.net Git - vlc/blob - modules/video_filter/logo.c
modules/video_filter/logo.c: use image handler.
[vlc] / modules / video_filter / logo.c
1 /*****************************************************************************
2  * logo.c : logo video plugin for vlc
3  *****************************************************************************
4  * Copyright (C) 2003-2004 VideoLAN
5  * $Id$
6  *
7  * Authors: Gildas Bazin <gbazin@videolan.org>
8  *          Simon Latapie <garf@videolan.org>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
23  *****************************************************************************/
24
25 /*****************************************************************************
26  * Preamble
27  *****************************************************************************/
28 #include <stdlib.h>                                      /* malloc(), free() */
29 #include <string.h>
30
31 #include <vlc/vlc.h>
32 #include <vlc/vout.h>
33
34 #include "vlc_filter.h"
35 #include "filter_common.h"
36 #include "vlc_image.h"
37
38 /*****************************************************************************
39  * Local prototypes
40  *****************************************************************************/
41 static int  Create    ( vlc_object_t * );
42 static void Destroy   ( vlc_object_t * );
43
44 static int  Init      ( vout_thread_t * );
45 static void End       ( vout_thread_t * );
46 static void Render    ( vout_thread_t *, picture_t * );
47
48 static int  SendEvents( vlc_object_t *, char const *,
49                         vlc_value_t, vlc_value_t, void * );
50 static int  MouseEvent( vlc_object_t *, char const *,
51                         vlc_value_t , vlc_value_t , void * );
52 static int  Control   ( vout_thread_t *, int, va_list );
53
54 static int  CreateFilter ( vlc_object_t * );
55 static void DestroyFilter( vlc_object_t * );
56
57 static int LogoCallback( vlc_object_t *, char const *,
58                          vlc_value_t, vlc_value_t, void * );
59
60 /*****************************************************************************
61  * Module descriptor
62  *****************************************************************************/
63 #define FILE_TEXT N_("Logo filename")
64 #define FILE_LONGTEXT N_("Full path of the PNG file to use.")
65 #define POSX_TEXT N_("X coordinate of the logo")
66 #define POSX_LONGTEXT N_("You can move the logo by left-clicking on it." )
67 #define POSY_TEXT N_("Y coordinate of the logo")
68 #define POSY_LONGTEXT N_("You can move the logo by left-clicking on it." )
69 #define TRANS_TEXT N_("Transparency of the logo")
70 #define TRANS_LONGTEXT N_("You can set the logo transparency value here " \
71   "(from 0 for full transparency to 255 for full opacity)." )
72 #define POS_TEXT N_("Logo position")
73 #define POS_LONGTEXT N_( \
74   "You can enforce the logo position on the video " \
75   "(0=center, 1=left, 2=right, 4=top, 8=bottom, you can " \
76   "also use combinations of these values).")
77
78 static int pi_pos_values[] = { 0, 1, 2, 4, 8, 5, 6, 9, 10 };
79 static char *ppsz_pos_descriptions[] =
80 { N_("Center"), N_("Left"), N_("Right"), N_("Top"), N_("Bottom"),
81   N_("Top-Left"), N_("Top-Right"), N_("Bottom-Left"), N_("Bottom-Right") };
82
83 vlc_module_begin();
84     set_description( _("Logo video filter") );
85     set_capability( "video filter", 0 );
86     set_shortname( N_("Logo overlay") );
87     set_category( CAT_VIDEO );
88     set_subcategory( SUBCAT_VIDEO_VFILTER );
89     add_shortcut( "logo" );
90     set_callbacks( Create, Destroy );
91
92     add_file( "logo-file", NULL, NULL, FILE_TEXT, FILE_LONGTEXT, VLC_FALSE );
93     add_integer( "logo-x", -1, NULL, POSX_TEXT, POSX_LONGTEXT, VLC_FALSE );
94     add_integer( "logo-y", -1, NULL, POSY_TEXT, POSY_LONGTEXT, VLC_FALSE );
95     add_integer_with_range( "logo-transparency", 255, 0, 255, NULL,
96         TRANS_TEXT, TRANS_LONGTEXT, VLC_FALSE );
97     add_integer( "logo-position", 6, NULL, POS_TEXT, POS_LONGTEXT, VLC_TRUE );
98         change_integer_list( pi_pos_values, ppsz_pos_descriptions, 0 );
99
100     /* subpicture filter submodule */
101     add_submodule();
102     set_capability( "sub filter", 0 );
103     set_callbacks( CreateFilter, DestroyFilter );
104     set_description( _("Logo sub filter") );
105     add_shortcut( "logo" );
106 vlc_module_end();
107
108 /*****************************************************************************
109  * LoadImage: loads the logo image into memory
110  *****************************************************************************/
111 static picture_t *LoadImage( vlc_object_t *p_this, char *psz_filename )
112 {
113     picture_t *p_pic;
114     image_handler_t *p_image;
115     video_format_t fmt_in = {0}, fmt_out = {0};
116
117     fmt_out.i_chroma = VLC_FOURCC('Y','U','V','A');
118     p_image = image_HandlerCreate( p_this );
119     p_pic = image_ReadUrl( p_image, psz_filename, &fmt_in, &fmt_out );
120     image_HandlerDelete( p_image );
121
122     return p_pic;
123 }
124
125 /*****************************************************************************
126  * vout_sys_t: logo video output method descriptor
127  *****************************************************************************
128  * This structure is part of the video output thread descriptor.
129  * It describes the Invert specific properties of an output thread.
130  *****************************************************************************/
131 struct vout_sys_t
132 {
133     vout_thread_t *p_vout;
134
135     filter_t *p_blend;
136     picture_t *p_pic;
137
138     int i_width, i_height;
139     int pos, posx, posy;
140     char *psz_filename;
141     int i_trans;
142 };
143
144 /*****************************************************************************
145  * Create: allocates logo video thread output method
146  *****************************************************************************/
147 static int Create( vlc_object_t *p_this )
148 {
149     vout_thread_t *p_vout = (vout_thread_t *)p_this;
150     vout_sys_t *p_sys;
151     vlc_value_t val;
152
153     /* Allocate structure */
154     p_sys = p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
155     if( p_sys == NULL )
156     {
157         msg_Err( p_vout, "out of memory" );
158         return VLC_ENOMEM;
159     }
160
161     p_vout->pf_init = Init;
162     p_vout->pf_end = End;
163     p_vout->pf_manage = NULL;
164     p_vout->pf_render = Render;
165     p_vout->pf_display = NULL;
166     p_vout->pf_control = Control;
167     
168     p_sys->psz_filename = var_CreateGetString( p_this , "logo-file" ); 
169     if( !p_sys->psz_filename || !*p_sys->psz_filename )
170     {
171         msg_Err( p_this, "logo file not specified" );
172         return 0;
173     }
174
175     var_Create( p_this, "logo-position", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
176     var_Get( p_this, "logo-position", &val );
177     p_sys->pos = val.i_int;
178     var_Create( p_this, "logo-x", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
179     var_Get( p_this, "logo-x", &val );
180     p_sys->posx = val.i_int;
181     var_Create( p_this, "logo-y", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
182     var_Get( p_this, "logo-y", &val );
183     p_sys->posy = val.i_int;
184     var_Create(p_this, "logo-transparency", VLC_VAR_INTEGER|VLC_VAR_DOINHERIT);
185     var_Get( p_this, "logo-transparency", &val );
186     p_sys->i_trans = __MAX( __MIN( val.i_int, 255 ), 0 );
187
188     p_sys->p_pic = LoadImage( p_this, p_sys->psz_filename );
189     if( !p_sys->p_pic )
190     {
191         free( p_sys );
192         return VLC_EGENERIC;
193     }
194
195     p_sys->i_width = p_sys->p_pic->p[Y_PLANE].i_visible_pitch;
196     p_sys->i_height = p_sys->p_pic->p[Y_PLANE].i_visible_lines;
197
198     return VLC_SUCCESS;
199 }
200
201 /*****************************************************************************
202  * Init: initialize logo video thread output method
203  *****************************************************************************/
204 static int Init( vout_thread_t *p_vout )
205 {
206     vout_sys_t *p_sys = p_vout->p_sys;
207     picture_t *p_pic;
208     int i_index;
209
210     I_OUTPUTPICTURES = 0;
211
212     /* Initialize the output structure */
213     p_vout->output.i_chroma = p_vout->render.i_chroma;
214     p_vout->output.i_width  = p_vout->render.i_width;
215     p_vout->output.i_height = p_vout->render.i_height;
216     p_vout->output.i_aspect = p_vout->render.i_aspect;
217
218     /* Load the video blending filter */
219     p_sys->p_blend = vlc_object_create( p_vout, sizeof(filter_t) );
220     vlc_object_attach( p_sys->p_blend, p_vout );
221     p_sys->p_blend->fmt_out.video.i_x_offset =
222         p_sys->p_blend->fmt_out.video.i_y_offset = 0;
223     p_sys->p_blend->fmt_in.video.i_x_offset =
224         p_sys->p_blend->fmt_in.video.i_y_offset = 0;
225     p_sys->p_blend->fmt_out.video.i_aspect = p_vout->render.i_aspect;
226     p_sys->p_blend->fmt_out.video.i_chroma = p_vout->output.i_chroma;
227     p_sys->p_blend->fmt_in.video.i_chroma = VLC_FOURCC('Y','U','V','A');
228     p_sys->p_blend->fmt_in.video.i_aspect = VOUT_ASPECT_FACTOR;
229     p_sys->p_blend->fmt_in.video.i_width =
230         p_sys->p_blend->fmt_in.video.i_visible_width =
231             p_sys->p_pic->p[Y_PLANE].i_visible_pitch;
232     p_sys->p_blend->fmt_in.video.i_height =
233         p_sys->p_blend->fmt_in.video.i_visible_height =
234             p_sys->p_pic->p[Y_PLANE].i_visible_lines;
235     p_sys->p_blend->fmt_out.video.i_width =
236         p_sys->p_blend->fmt_out.video.i_visible_width =
237            p_vout->output.i_width;
238     p_sys->p_blend->fmt_out.video.i_height =
239         p_sys->p_blend->fmt_out.video.i_visible_height =
240             p_vout->output.i_height;
241
242     p_sys->p_blend->p_module =
243         module_Need( p_sys->p_blend, "video blending", 0, 0 );
244     if( !p_sys->p_blend->p_module )
245     {
246         msg_Err( p_vout, "can't open blending filter, aborting" );
247         vlc_object_detach( p_sys->p_blend );
248         vlc_object_destroy( p_sys->p_blend );
249         return VLC_EGENERIC;
250     }
251
252     if( p_sys->posx < 0 || p_sys->posy < 0 )
253     {
254         p_sys->posx = 0; p_sys->posy = 0;
255
256         if( p_sys->pos & SUBPICTURE_ALIGN_BOTTOM )
257         {
258             p_sys->posy = p_vout->render.i_height - p_sys->i_height;
259         }
260         else if ( !(p_sys->pos & SUBPICTURE_ALIGN_TOP) )
261         {
262             p_sys->posy = p_vout->render.i_height / 2 - p_sys->i_height / 2;
263         }
264
265         if( p_sys->pos & SUBPICTURE_ALIGN_RIGHT )
266         {
267             p_sys->posx = p_vout->render.i_width - p_sys->i_width;
268         }
269         else if ( !(p_sys->pos & SUBPICTURE_ALIGN_LEFT) )
270         {
271             p_sys->posx = p_vout->render.i_width / 2 - p_sys->i_width / 2;
272         }
273     }
274
275     /* Try to open the real video output */
276     msg_Dbg( p_vout, "spawning the real video output" );
277
278     p_sys->p_vout =
279         vout_Create( p_vout, p_vout->render.i_width, p_vout->render.i_height,
280                      p_vout->render.i_chroma, p_vout->render.i_aspect );
281
282     /* Everything failed */
283     if( p_sys->p_vout == NULL )
284     {
285         msg_Err( p_vout, "can't open vout, aborting" );
286         return VLC_EGENERIC;
287     }
288
289     var_AddCallback( p_sys->p_vout, "mouse-x", MouseEvent, p_vout);
290     var_AddCallback( p_sys->p_vout, "mouse-y", MouseEvent, p_vout);
291
292     ALLOCATE_DIRECTBUFFERS( VOUT_MAX_PICTURES );
293     ADD_CALLBACKS( p_sys->p_vout, SendEvents );
294     ADD_PARENT_CALLBACKS( SendEventsToChild );
295
296     return VLC_SUCCESS;
297 }
298
299 /*****************************************************************************
300  * End: terminate logo video thread output method
301  *****************************************************************************/
302 static void End( vout_thread_t *p_vout )
303 {
304     vout_sys_t *p_sys = p_vout->p_sys;
305     int i_index;
306
307     /* Free the fake output buffers we allocated */
308     for( i_index = I_OUTPUTPICTURES ; i_index ; )
309     {
310         i_index--;
311         free( PP_OUTPUTPICTURE[ i_index ]->p_data_orig );
312     }
313
314     var_DelCallback( p_sys->p_vout, "mouse-x", MouseEvent, p_vout);
315     var_DelCallback( p_sys->p_vout, "mouse-y", MouseEvent, p_vout);
316
317     if( p_sys->p_vout )
318     {
319         DEL_CALLBACKS( p_sys->p_vout, SendEvents );
320         vlc_object_detach( p_sys->p_vout );
321         vout_Destroy( p_sys->p_vout );
322     }
323
324     if( p_sys->p_blend->p_module )
325         module_Unneed( p_sys->p_blend, p_sys->p_blend->p_module );
326     vlc_object_detach( p_sys->p_blend );
327     vlc_object_destroy( p_sys->p_blend );
328 }
329
330 /*****************************************************************************
331  * Destroy: destroy logo video thread output method
332  *****************************************************************************/
333 static void Destroy( vlc_object_t *p_this )
334 {
335     vout_thread_t *p_vout = (vout_thread_t *)p_this;
336     vout_sys_t *p_sys = p_vout->p_sys;
337
338     DEL_PARENT_CALLBACKS( SendEventsToChild );
339
340     if( p_sys->p_pic ) p_sys->p_pic->pf_release( p_sys->p_pic );
341     free( p_sys );
342 }
343
344 /*****************************************************************************
345  * Render: render the logo onto the video
346  *****************************************************************************/
347 static void Render( vout_thread_t *p_vout, picture_t *p_pic )
348 {
349     vout_sys_t *p_sys = p_vout->p_sys;
350     picture_t *p_outpic;
351
352     /* This is a new frame. Get a structure from the video_output. */
353     while( !(p_outpic = vout_CreatePicture( p_sys->p_vout, 0, 0, 0 )) )
354     {
355         if( p_vout->b_die || p_vout->b_error ) return;
356         msleep( VOUT_OUTMEM_SLEEP );
357     }
358
359     vout_CopyPicture( p_vout, p_outpic, p_pic );
360     vout_DatePicture( p_sys->p_vout, p_outpic, p_pic->date );
361
362     p_sys->p_blend->pf_video_blend( p_sys->p_blend, p_outpic, p_outpic,
363                                     p_sys->p_pic, p_sys->posx, p_sys->posy,
364                                     p_sys->i_trans );
365
366     vout_DisplayPicture( p_sys->p_vout, p_outpic );
367 }
368
369 /*****************************************************************************
370  * SendEvents: forward mouse and keyboard events to the parent p_vout
371  *****************************************************************************/
372 static int SendEvents( vlc_object_t *p_this, char const *psz_var,
373                        vlc_value_t oldval, vlc_value_t newval, void *p_data )
374 {
375     var_Set( (vlc_object_t *)p_data, psz_var, newval );
376     return VLC_SUCCESS;
377 }
378
379 /*****************************************************************************
380  * MouseEvent: callback for mouse events
381  *****************************************************************************/
382 static int MouseEvent( vlc_object_t *p_this, char const *psz_var,
383                        vlc_value_t oldval, vlc_value_t newval, void *p_data )
384 {
385     vout_thread_t *p_vout = (vout_thread_t*)p_data;
386     vout_sys_t *p_sys = p_vout->p_sys;
387     vlc_value_t valb;
388     int i_delta;
389
390     var_Get( p_vout->p_sys->p_vout, "mouse-button-down", &valb );
391
392     i_delta = newval.i_int - oldval.i_int;
393
394     if( (valb.i_int & 0x1) == 0 )
395     {
396         return VLC_SUCCESS;
397     }
398
399     if( psz_var[6] == 'x' )
400     {
401         vlc_value_t valy;
402         var_Get( p_vout->p_sys->p_vout, "mouse-y", &valy );
403         if( newval.i_int >= (int)p_sys->posx &&
404             valy.i_int >= (int)p_sys->posy &&
405             newval.i_int <= (int)(p_sys->posx + p_sys->i_width) &&
406             valy.i_int <= (int)(p_sys->posy + p_sys->i_height) )
407         {
408             p_sys->posx = __MIN( __MAX( p_sys->posx + i_delta, 0 ),
409                           p_vout->output.i_width - p_sys->i_width );
410         }
411     }
412     else if( psz_var[6] == 'y' )
413     {
414         vlc_value_t valx;
415         var_Get( p_vout->p_sys->p_vout, "mouse-x", &valx );
416         if( valx.i_int >= (int)p_sys->posx &&
417             newval.i_int >= (int)p_sys->posy &&
418             valx.i_int <= (int)(p_sys->posx + p_sys->i_width) &&
419             newval.i_int <= (int)(p_sys->posy + p_sys->i_height) )
420         {
421             p_sys->posy = __MIN( __MAX( p_sys->posy + i_delta, 0 ),
422                           p_vout->output.i_height - p_sys->i_height );
423         }
424     }
425
426     return VLC_SUCCESS;
427 }
428
429 /*****************************************************************************
430  * Control: control facility for the vout (forwards to child vout)
431  *****************************************************************************/
432 static int Control( vout_thread_t *p_vout, int i_query, va_list args )
433 {
434     return vout_vaControl( p_vout->p_sys->p_vout, i_query, args );
435 }
436
437 /*****************************************************************************
438  * SendEventsToChild: forward events to the child/children vout
439  *****************************************************************************/
440 static int SendEventsToChild( vlc_object_t *p_this, char const *psz_var,
441                        vlc_value_t oldval, vlc_value_t newval, void *p_data )
442 {
443     vout_thread_t *p_vout = (vout_thread_t *)p_this;
444     var_Set( p_vout->p_sys->p_vout, psz_var, newval );
445     return VLC_SUCCESS;
446 }
447
448 /*****************************************************************************
449  * filter_sys_t: logo filter descriptor
450  *****************************************************************************/
451 struct filter_sys_t
452 {
453     picture_t *p_pic;
454
455     int i_width, i_height;
456     int pos, posx, posy;
457     char *psz_filename;
458     int i_trans;
459     
460     vlc_bool_t b_absolute;
461
462     mtime_t i_last_date;
463
464     /* On the fly control variable */
465     vlc_bool_t b_need_update;
466     vlc_bool_t b_new_image;
467 };
468
469 static subpicture_t *Filter( filter_t *, mtime_t );
470
471 /*****************************************************************************
472  * CreateFilter: allocates logo video filter
473  *****************************************************************************/
474 static int CreateFilter( vlc_object_t *p_this )
475 {
476     filter_t *p_filter = (filter_t *)p_this;
477     filter_sys_t *p_sys;
478     vlc_object_t *p_input;
479
480     /* Allocate structure */
481     p_sys = p_filter->p_sys = malloc( sizeof( filter_sys_t ) );
482     if( p_sys == NULL )
483     {
484         msg_Err( p_filter, "out of memory" );
485         return VLC_ENOMEM;
486     }
487
488     /* Hook used for callback variables */
489     p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_PARENT );
490     if( !p_input )
491     {
492         free( p_sys );
493         return VLC_ENOOBJ;
494     }
495
496     p_sys->psz_filename =
497         var_CreateGetString( p_input->p_libvlc , "logo-file" ); 
498     if( !p_sys->psz_filename || !*p_sys->psz_filename )
499     {
500         msg_Err( p_this, "logo file not specified" );
501         vlc_object_release( p_input );
502         if( p_sys->psz_filename ) free( p_sys->psz_filename );
503         free( p_sys );
504         return VLC_EGENERIC;
505     }
506
507     p_sys->posx = var_CreateGetInteger( p_input->p_libvlc , "logo-x" );
508     p_sys->posy = var_CreateGetInteger( p_input->p_libvlc , "logo-y" );
509     p_sys->pos = var_CreateGetInteger( p_input->p_libvlc , "logo-position" );
510     p_sys->i_trans =
511         var_CreateGetInteger( p_input->p_libvlc, "logo-transparency");
512     p_sys->i_trans = __MAX( __MIN( p_sys->i_trans, 255 ), 0 );
513
514     var_AddCallback( p_input->p_libvlc, "logo-file", LogoCallback, p_sys );
515     var_AddCallback( p_input->p_libvlc, "logo-x", LogoCallback, p_sys );
516     var_AddCallback( p_input->p_libvlc, "logo-y", LogoCallback, p_sys );
517     var_AddCallback( p_input->p_libvlc, "logo-position", LogoCallback, p_sys );
518     var_AddCallback( p_input->p_libvlc, "logo-transparency", LogoCallback, p_sys );
519     vlc_object_release( p_input );
520
521     p_sys->b_absolute = VLC_TRUE;
522     if( p_sys->posx < 0 || p_sys->posy < 0 )
523     {
524         p_sys->b_absolute = VLC_FALSE;
525         p_sys->posx = 0; p_sys->posy = 0;
526     }
527
528     p_sys->p_pic = LoadImage( p_this, p_sys->psz_filename );
529     if( !p_sys->p_pic )
530     {
531         free( p_sys );
532         msg_Err( p_this, "couldn't load logo file" );
533         return VLC_EGENERIC;
534     }
535
536     /* Misc init */
537     p_filter->pf_sub_filter = Filter;
538     p_sys->i_width = p_sys->p_pic->p[Y_PLANE].i_visible_pitch;
539     p_sys->i_height = p_sys->p_pic->p[Y_PLANE].i_visible_lines;
540     p_sys->b_need_update = VLC_TRUE;
541     p_sys->b_new_image = VLC_FALSE;
542     p_sys->i_last_date = 0;
543
544     return VLC_SUCCESS;
545 }
546
547 /*****************************************************************************
548  * DestroyFilter: destroy logo video filter
549  *****************************************************************************/
550 static void DestroyFilter( vlc_object_t *p_this )
551 {
552     filter_t *p_filter = (filter_t *)p_this;
553     filter_sys_t *p_sys = p_filter->p_sys;
554     vlc_object_t *p_input;
555
556     if( p_sys->p_pic ) p_sys->p_pic->pf_release( p_sys->p_pic );
557     if( p_sys->psz_filename ) free( p_sys->psz_filename );
558     free( p_sys );
559
560     /* Delete the logo variables from INPUT */
561     p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_PARENT );
562     if( !p_input ) return;
563
564     var_Destroy( p_input->p_libvlc , "logo-file" );
565     var_Destroy( p_input->p_libvlc , "logo-x" );
566     var_Destroy( p_input->p_libvlc , "logo-y" );
567     var_Destroy( p_input->p_libvlc , "logo-position" );
568     var_Destroy( p_input->p_libvlc , "logo-transparency" );
569     vlc_object_release( p_input );
570 }
571
572 /*****************************************************************************
573  * Filter: the whole thing
574  *****************************************************************************
575  * This function outputs subpictures at regular time intervals.
576  *****************************************************************************/
577 static subpicture_t *Filter( filter_t *p_filter, mtime_t date )
578 {
579     filter_sys_t *p_sys = p_filter->p_sys;
580     subpicture_t *p_spu;
581     subpicture_region_t *p_region;
582     video_format_t fmt;
583
584     if( !p_sys->b_need_update && p_sys->i_last_date +5000000 > date ) return 0;
585
586     if( p_sys->b_new_image )
587     {
588         if( p_sys->p_pic ) p_sys->p_pic->pf_release( p_sys->p_pic );
589
590         p_sys->p_pic = LoadImage( VLC_OBJECT(p_filter), p_sys->psz_filename );
591         if( p_sys->p_pic )
592         {
593             p_sys->i_width = p_sys->p_pic->p[Y_PLANE].i_visible_pitch;
594             p_sys->i_height = p_sys->p_pic->p[Y_PLANE].i_visible_lines;
595         }
596
597         p_sys->b_new_image = VLC_FALSE;
598     }
599
600     p_sys->b_need_update = VLC_FALSE;
601
602     /* Allocate the subpicture internal data. */
603     p_spu = p_filter->pf_sub_buffer_new( p_filter );
604     if( !p_spu ) return NULL;
605
606     p_spu->b_absolute = p_sys->b_absolute;
607     p_spu->i_start = p_sys->i_last_date = date;
608     p_spu->i_stop = 0;
609     p_spu->b_ephemer = VLC_TRUE;
610
611     p_sys->b_need_update = VLC_FALSE;
612
613     if( !p_sys->p_pic || !p_sys->i_trans )
614     {
615         /* Send an empty subpicture to clear the display */
616         return p_spu;
617     }
618
619     /* Create new SPU region */
620     memset( &fmt, 0, sizeof(video_format_t) );
621     fmt.i_chroma = VLC_FOURCC('Y','U','V','A');
622     fmt.i_aspect = VOUT_ASPECT_FACTOR;
623     fmt.i_sar_num = fmt.i_sar_den = 1;
624     fmt.i_width = fmt.i_visible_width = p_sys->i_width;
625     fmt.i_height = fmt.i_visible_height = p_sys->i_height;
626     fmt.i_x_offset = fmt.i_y_offset = 0;
627     p_region = p_spu->pf_create_region( VLC_OBJECT(p_filter), &fmt );
628     if( !p_region )
629     {
630         msg_Err( p_filter, "cannot allocate SPU region" );
631         p_filter->pf_sub_buffer_del( p_filter, p_spu );
632         return NULL;
633     }
634
635     vout_CopyPicture( p_filter, &p_region->picture, p_sys->p_pic );
636     p_region->i_x = 0;
637     p_region->i_y = 0;
638     p_spu->i_x = p_sys->posx;
639     p_spu->i_y = p_sys->posy;
640     p_spu->i_flags = p_sys->pos;
641     p_spu->p_region = p_region;
642     //p_subpic->i_alpha = p_sys->i_trans;
643
644     return p_spu;
645 }
646
647 /*****************************************************************************
648  * Callback to update params on the fly
649  *****************************************************************************/
650 static int LogoCallback( vlc_object_t *p_this, char const *psz_var,
651                          vlc_value_t oldval, vlc_value_t newval, void *p_data )
652 {
653     filter_sys_t *p_sys = (filter_sys_t *)p_data;
654
655     if( !strncmp( psz_var, "logo-file", 6 ) )
656     {
657         if( p_sys->psz_filename ) free( p_sys->psz_filename );
658         p_sys->psz_filename = strdup( newval.psz_string ); 
659         p_sys->b_new_image = VLC_TRUE;
660     }
661     else if ( !strncmp( psz_var, "logo-x", 6 ) )
662     {
663         p_sys->posx = newval.i_int;
664     }
665     else if ( !strncmp( psz_var, "logo-y", 6 ) )
666     {
667         p_sys->posy = newval.i_int;
668     }
669     else if ( !strncmp( psz_var, "logo-position", 12 ) )
670     {
671         p_sys->pos = newval.i_int;
672     }
673     else if ( !strncmp( psz_var, "logo-transparency", 9 ) )
674     {
675         p_sys->i_trans = __MAX( __MIN( newval.i_int, 255 ), 0 );
676     }
677     p_sys->b_need_update = VLC_TRUE;
678     return VLC_SUCCESS;
679 }