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