]> git.sesse.net Git - vlc/blob - src/video_output/vout_subpictures.c
f37a9325272c6cf6228379767f4e308dcb19b2a3
[vlc] / src / video_output / vout_subpictures.c
1 /*****************************************************************************
2  * vout_subpictures.c : subpicture management functions
3  *****************************************************************************
4  * Copyright (C) 2000-2004 VideoLAN
5  * $Id$
6  *
7  * Authors: Vincent Seguin <seguin@via.ecp.fr>
8  *          Samuel Hocevar <sam@zoy.org>
9  *          Gildas Bazin <gbazin@videolan.org>
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
24  *****************************************************************************/
25
26 /*****************************************************************************
27  * Preamble
28  *****************************************************************************/
29 #include <stdlib.h>                                                /* free() */
30 #include <stdio.h>                                              /* sprintf() */
31 #include <string.h>                                            /* strerror() */
32
33 #include <vlc/vlc.h>
34
35 #include "vlc_video.h"
36 #include "video_output.h"
37 #include "vlc_filter.h"
38 #include "osd.h"
39
40 static void UpdateSPU        ( vout_thread_t *, vlc_object_t * );
41 static int  CropCallback     ( vlc_object_t *, char const *,
42                                vlc_value_t, vlc_value_t, void * );
43
44 static subpicture_t *spu_new_buffer( filter_t * );
45 static void spu_del_buffer( filter_t *, subpicture_t * );
46
47 /**
48  * Initialise the subpicture decoder unit
49  *
50  * \param p_vout the vout in which to create the subpicture unit
51  */
52 void vout_InitSPU( vout_thread_t *p_vout )
53 {
54     vlc_object_t *p_input;
55     int i_index;
56
57     for( i_index = 0; i_index < VOUT_MAX_SUBPICTURES; i_index++)
58     {
59         p_vout->p_subpicture[i_index].i_status = FREE_SUBPICTURE;
60         p_vout->p_subpicture[i_index].i_type   = EMPTY_SUBPICTURE;
61     }
62
63     /* Load the text rendering module */
64     p_vout->p_text = vlc_object_create( p_vout, sizeof(filter_t) );
65     p_vout->p_text->pf_spu_buffer_new = spu_new_buffer;
66     p_vout->p_text->pf_spu_buffer_del = spu_del_buffer;
67     p_vout->p_text->p_owner = (filter_owner_sys_t *)p_vout;
68     vlc_object_attach( p_vout->p_text, p_vout );
69     p_vout->p_text->p_module =
70         module_Need( p_vout->p_text, "text renderer", 0, 0 );
71     if( p_vout->p_text->p_module == NULL )
72     {
73         msg_Warn( p_vout, "no suitable text renderer module" );
74         vlc_object_detach( p_vout->p_text );
75         vlc_object_destroy( p_vout->p_text );
76         p_vout->p_text = NULL;
77     }
78
79     p_vout->p_blend = NULL;
80
81     p_vout->i_crop_x = p_vout->i_crop_y =
82         p_vout->i_crop_width = p_vout->i_crop_height = 0;
83     p_vout->b_force_alpha = VLC_FALSE;
84     p_vout->b_force_crop = VLC_FALSE;
85
86     /* Create callback */
87     p_input = vlc_object_find( p_vout, VLC_OBJECT_INPUT, FIND_PARENT );
88     if( p_input )
89     {
90         UpdateSPU( p_vout, VLC_OBJECT(p_input) );
91         var_AddCallback( p_input, "highlight", CropCallback, p_vout );
92         vlc_object_release( p_input );
93     }
94 }
95
96 /**
97  * Destroy the subpicture decoder unit
98  *
99  * \param p_vout the vout in which to destroy the subpicture unit
100  */
101 void vout_DestroySPU( vout_thread_t *p_vout )
102 {
103     vlc_object_t *p_input;
104     int i_index;
105
106     /* Destroy all remaining subpictures */
107     for( i_index = 0; i_index < VOUT_MAX_SUBPICTURES; i_index++ )
108     {
109         if( p_vout->p_subpicture[i_index].i_status != FREE_SUBPICTURE )
110         {
111             vout_DestroySubPicture( p_vout,
112                                     &p_vout->p_subpicture[i_index] );
113         }
114     }
115
116     if( p_vout->p_text )
117     {
118         if( p_vout->p_text->p_module )
119             module_Unneed( p_vout->p_text, p_vout->p_text->p_module );
120
121         vlc_object_detach( p_vout->p_text );
122         vlc_object_destroy( p_vout->p_text );
123     }
124
125     if( p_vout->p_blend )
126     {
127         if( p_vout->p_blend->p_module )
128             module_Unneed( p_vout->p_blend, p_vout->p_blend->p_module );
129
130         vlc_object_detach( p_vout->p_blend );
131         vlc_object_destroy( p_vout->p_blend );
132     }
133
134     /* Delete callback */
135     p_input = vlc_object_find( p_vout, VLC_OBJECT_INPUT, FIND_PARENT );
136     if( p_input )
137     {
138         var_DelCallback( p_input, "highlight", CropCallback, p_vout );
139         vlc_object_release( p_input );
140     }
141 }
142
143 /**
144  * Create a subpicture region
145  *
146  * \param p_this vlc_object_t
147  * \param p_fmt the format that this subpicture region should have
148  */
149 subpicture_region_t *__spu_CreateRegion( vlc_object_t *p_this,
150                                          video_format_t *p_fmt )
151 {
152     subpicture_region_t *p_region = malloc( sizeof(subpicture_region_t) );
153     memset( p_region, 0, sizeof(subpicture_region_t) );
154     p_region->p_next = 0;
155     p_region->fmt = *p_fmt;
156
157     vout_AllocatePicture( p_this, &p_region->picture, p_fmt->i_chroma,
158                           p_fmt->i_width, p_fmt->i_height, p_fmt->i_aspect );
159
160     if( !p_region->picture.i_planes )
161     {
162         free( p_region );
163         return NULL;
164     }
165
166     if( p_fmt->i_chroma == VLC_FOURCC('Y','U','V','P') )
167         p_fmt->p_palette = p_region->fmt.p_palette =
168             malloc( sizeof(video_palette_t) );
169     else p_fmt->p_palette = p_region->fmt.p_palette = NULL;
170
171     return p_region;
172 }
173
174 /**
175  * Destroy a subpicture region
176  *
177  * \param p_this vlc_object_t
178  * \param p_region the subpicture region to destroy
179  */
180 void __spu_DestroyRegion( vlc_object_t *p_this, subpicture_region_t *p_region )
181 {
182     if( !p_region ) return;
183     if( p_region->picture.p_data_orig ) free( p_region->picture.p_data_orig );
184     if( p_region->fmt.p_palette ) free( p_region->fmt.p_palette );
185     free( p_region );
186 }
187
188 /**
189  * Display a subpicture unit
190  *
191  * Remove the reservation flag of a subpicture, which will cause it to be
192  * ready for display.
193  * \param p_vout the video output this subpicture should be displayed on
194  * \param p_subpic the subpicture to display
195  */
196 void vout_DisplaySubPicture( vout_thread_t *p_vout, subpicture_t *p_subpic )
197 {
198     int         i_margin;
199
200     /* Check if status is valid */
201     if( p_subpic->i_status != RESERVED_SUBPICTURE )
202     {
203         msg_Err( p_vout, "subpicture %p has invalid status #%d",
204                          p_subpic, p_subpic->i_status );
205     }
206
207     /* If the user requested an SPU margin, we force the position after
208      * having checked that it was a valid value. */
209     i_margin = config_GetInt( p_vout, "spumargin" );
210
211     if( i_margin >= 0 )
212     {
213         if( p_subpic->i_height + (unsigned int)i_margin
214                                                  <= p_vout->output.i_height )
215         {
216             p_subpic->i_y = p_vout->output.i_height
217                              - i_margin - p_subpic->i_height;
218         }
219     }
220
221     /* Remove reservation flag */
222     p_subpic->i_status = READY_SUBPICTURE;
223 }
224
225 /**
226  * Allocate a subpicture in the video output heap.
227  *
228  * This function create a reserved subpicture in the video output heap.
229  * A null pointer is returned if the function fails. This method provides an
230  * already allocated zone of memory in the spu data fields. It needs locking
231  * since several pictures can be created by several producers threads.
232  * \param p_vout the vout in which to create the subpicture
233  * \param i_channel the channel this subpicture should belong to
234  * \param i_type the type of the subpicture
235  * \return NULL on error, a reserved subpicture otherwise
236  */
237 subpicture_t *vout_CreateSubPicture( vout_thread_t *p_vout, int i_channel,
238                                      int i_type )
239 {
240     int                 i_subpic;                        /* subpicture index */
241     subpicture_t *      p_subpic = NULL;            /* first free subpicture */
242
243     /* Clear the default channel before writing into it */
244     if( i_channel == DEFAULT_CHAN )
245     {
246         vout_ClearOSDChannel( p_vout, DEFAULT_CHAN );
247     }
248
249     /* Get lock */
250     vlc_mutex_lock( &p_vout->subpicture_lock );
251
252     /*
253      * Look for an empty place
254      */
255     p_subpic = NULL;
256     for( i_subpic = 0; i_subpic < VOUT_MAX_SUBPICTURES; i_subpic++ )
257     {
258         if( p_vout->p_subpicture[i_subpic].i_status == FREE_SUBPICTURE )
259         {
260             /* Subpicture is empty and ready for allocation */
261             p_subpic = &p_vout->p_subpicture[i_subpic];
262             p_vout->p_subpicture[i_subpic].i_status = RESERVED_SUBPICTURE;
263             break;
264         }
265     }
266
267     /* If no free subpicture could be found */
268     if( p_subpic == NULL )
269     {
270         msg_Err( p_vout, "subpicture heap is full" );
271         vlc_mutex_unlock( &p_vout->subpicture_lock );
272         return NULL;
273     }
274
275     /* Copy subpicture information, set some default values */
276     p_subpic->i_channel = i_channel;
277     p_subpic->i_type    = i_type;
278     p_subpic->i_status  = RESERVED_SUBPICTURE;
279
280     p_subpic->i_start   = 0;
281     p_subpic->i_stop    = 0;
282     p_subpic->b_ephemer = VLC_FALSE;
283
284     p_subpic->i_x       = 0;
285     p_subpic->i_y       = 0;
286     p_subpic->i_width   = 0;
287     p_subpic->i_height  = 0;
288     p_subpic->b_absolute= VLC_TRUE;
289     p_subpic->i_flags   = 0;
290     p_subpic->pf_render = 0;
291     p_subpic->pf_destroy= 0;
292     p_subpic->p_sys     = 0;
293
294     /* Remain last subpicture displayed in DEFAULT_CHAN */
295     if( i_channel == DEFAULT_CHAN )
296     {
297         p_vout->p_default_channel = p_subpic;
298     }
299
300     vlc_mutex_unlock( &p_vout->subpicture_lock );
301
302     p_subpic->pf_create_region = __spu_CreateRegion;
303     p_subpic->pf_destroy_region = __spu_DestroyRegion;
304
305     return p_subpic;
306 }
307
308 /**
309  * Remove a subpicture from the heap
310  *
311  * This function frees a previously reserved subpicture.
312  * It is meant to be used when the construction of a picture aborted.
313  * This function does not need locking since reserved subpictures are ignored
314  * by the output thread.
315  */
316 void vout_DestroySubPicture( vout_thread_t *p_vout, subpicture_t *p_subpic )
317 {
318     /* Get lock */
319     vlc_mutex_lock( &p_vout->subpicture_lock );
320
321     /* There can be race conditions so we need to check the status */
322     if( p_subpic->i_status == FREE_SUBPICTURE )
323     {
324         vlc_mutex_unlock( &p_vout->subpicture_lock );
325         return;
326     }
327
328     /* Check if status is valid */
329     if( ( p_subpic->i_status != RESERVED_SUBPICTURE )
330            && ( p_subpic->i_status != READY_SUBPICTURE ) )
331     {
332         msg_Err( p_vout, "subpicture %p has invalid status %d",
333                          p_subpic, p_subpic->i_status );
334     }
335
336     while( p_subpic->p_region )
337     {
338         subpicture_region_t *p_region = p_subpic->p_region;
339         p_subpic->p_region = p_region->p_next;
340         spu_DestroyRegion( p_vout, p_region );
341     }
342
343     if( p_subpic->pf_destroy )
344     {
345         p_subpic->pf_destroy( p_subpic );
346     }
347
348     p_subpic->i_status = FREE_SUBPICTURE;
349
350     vlc_mutex_unlock( &p_vout->subpicture_lock );
351 }
352
353 /*****************************************************************************
354  * vout_RenderSubPictures: render a subpicture list
355  *****************************************************************************
356  * This function renders all sub picture units in the list.
357  *****************************************************************************/
358 void vout_RenderSubPictures( vout_thread_t *p_vout, picture_t *p_pic_dst,
359                              picture_t *p_pic_src, subpicture_t *p_subpic )
360 {
361     /* Load the blending module */
362     if( !p_vout->p_blend && p_subpic && p_subpic->p_region )
363     {
364         p_vout->p_blend = vlc_object_create( p_vout, sizeof(filter_t) );
365         vlc_object_attach( p_vout->p_blend, p_vout );
366         p_vout->p_blend->fmt_out.video.i_width =
367             p_vout->p_blend->fmt_out.video.i_visible_width =
368                 p_vout->render.i_width;
369         p_vout->p_blend->fmt_out.video.i_height =
370             p_vout->p_blend->fmt_out.video.i_visible_height =
371                 p_vout->render.i_height;
372         p_vout->p_blend->fmt_out.video.i_x_offset =
373             p_vout->p_blend->fmt_out.video.i_y_offset = 0;
374         p_vout->p_blend->fmt_out.video.i_aspect =
375             p_vout->render.i_aspect;
376         p_vout->p_blend->fmt_out.video.i_chroma =
377             p_vout->output.i_chroma;
378
379         p_vout->p_blend->fmt_in.video = p_subpic->p_region->fmt;
380
381         p_vout->p_blend->p_module =
382             module_Need( p_vout->p_blend, "video blending", 0, 0 );
383     }
384
385     /* Get lock */
386     vlc_mutex_lock( &p_vout->subpicture_lock );
387
388     /* Check i_status again to make sure spudec hasn't destroyed the subpic */
389     while( p_subpic != NULL && p_subpic->i_status != FREE_SUBPICTURE )
390     {
391         subpicture_region_t *p_region = p_subpic->p_region;
392
393         if( p_subpic->pf_render )
394         {
395             p_subpic->pf_render( p_vout, p_pic_dst, p_subpic );
396         }
397         else while( p_region && p_vout->p_blend &&
398                     p_vout->p_blend->pf_video_blend )
399         {
400             int i_x_offset = p_region->i_x + p_subpic->i_x;
401             int i_y_offset = p_region->i_y + p_subpic->i_y;
402
403             if( p_subpic->i_flags & OSD_ALIGN_BOTTOM )
404             {
405                 i_y_offset = p_vout->output.i_height - p_region->fmt.i_height -
406                     p_subpic->i_y;
407             }
408             else if ( !(p_subpic->i_flags & OSD_ALIGN_TOP) )
409             {
410                 i_y_offset = p_vout->output.i_height / 2 -
411                     p_region->fmt.i_height / 2;
412             }
413
414             if( p_subpic->i_flags & OSD_ALIGN_RIGHT )
415             {
416                 i_x_offset = p_vout->output.i_width - p_region->fmt.i_width -
417                     p_subpic->i_x;
418             }
419             else if ( !(p_subpic->i_flags & OSD_ALIGN_LEFT) )
420             {
421                 i_x_offset = p_vout->output.i_width / 2 -
422                     p_region->fmt.i_width / 2;
423             }
424
425             if( p_subpic->b_absolute )
426             {
427                 i_x_offset = p_region->i_x + p_subpic->i_x;
428                 i_y_offset = p_region->i_y + p_subpic->i_y;
429             }
430
431             p_vout->p_blend->fmt_in.video = p_region->fmt;
432
433             /* Force cropping if requested */
434             if( p_vout->b_force_crop )
435             {
436                 p_vout->p_blend->fmt_in.video.i_x_offset = p_vout->i_crop_x;
437                 p_vout->p_blend->fmt_in.video.i_y_offset = p_vout->i_crop_y;
438                 p_vout->p_blend->fmt_in.video.i_visible_width =
439                     p_vout->i_crop_width;
440                 p_vout->p_blend->fmt_in.video.i_visible_height =
441                     p_vout->i_crop_height;
442                 i_x_offset += p_vout->i_crop_x;
443                 i_y_offset += p_vout->i_crop_y;
444             }
445
446             /* Force palette if requested */
447             if( p_vout->b_force_alpha && VLC_FOURCC('Y','U','V','P') ==
448                 p_vout->p_blend->fmt_in.video.i_chroma )
449             {
450                 p_vout->p_blend->fmt_in.video.p_palette->palette[0][3] =
451                     p_vout->pi_alpha[0];
452                 p_vout->p_blend->fmt_in.video.p_palette->palette[1][3] =
453                     p_vout->pi_alpha[1];
454                 p_vout->p_blend->fmt_in.video.p_palette->palette[2][3] =
455                     p_vout->pi_alpha[2];
456                 p_vout->p_blend->fmt_in.video.p_palette->palette[3][3] =
457                     p_vout->pi_alpha[3];
458             }
459
460             p_vout->p_blend->pf_video_blend( p_vout->p_blend, p_pic_dst,
461                 p_pic_src, &p_region->picture, i_x_offset, i_y_offset );
462
463             p_region = p_region->p_next;
464         }
465
466         p_subpic = p_subpic->p_next;
467     }
468
469     vlc_mutex_unlock( &p_vout->subpicture_lock );
470 }
471
472 /*****************************************************************************
473  * vout_SortSubPictures: find the subpictures to display
474  *****************************************************************************
475  * This function parses all subpictures and decides which ones need to be
476  * displayed. This operation does not need lock, since only READY_SUBPICTURE
477  * are handled. If no picture has been selected, display_date will depend on
478  * the subpicture.
479  * We also check for ephemer DVD subpictures (subpictures that have
480  * to be removed if a newer one is available), which makes it a lot
481  * more difficult to guess if a subpicture has to be rendered or not.
482  *****************************************************************************/
483 subpicture_t *vout_SortSubPictures( vout_thread_t *p_vout,
484                                     mtime_t display_date )
485 {
486     int i_index;
487     subpicture_t *p_subpic     = NULL;
488     subpicture_t *p_ephemer    = NULL;
489     mtime_t       ephemer_date = 0;
490
491     /* We get an easily parsable chained list of subpictures which
492      * ends with NULL since p_subpic was initialized to NULL. */
493     for( i_index = 0; i_index < VOUT_MAX_SUBPICTURES; i_index++ )
494     {
495         if( p_vout->p_subpicture[i_index].i_status == READY_SUBPICTURE )
496         {
497             /* If it is a DVD subpicture, check its date */
498             if( p_vout->p_subpicture[i_index].i_type == MEMORY_SUBPICTURE )
499             {
500                 if( !p_vout->p_subpicture[i_index].b_ephemer
501                      && display_date > p_vout->p_subpicture[i_index].i_stop )
502                 {
503                     /* Too late, destroy the subpic */
504                     vout_DestroySubPicture( p_vout,
505                                     &p_vout->p_subpicture[i_index] );
506                     continue;
507                 }
508
509                 if( display_date
510                      && display_date < p_vout->p_subpicture[i_index].i_start )
511                 {
512                     /* Too early, come back next monday */
513                     continue;
514                 }
515
516                 /* If this is an ephemer subpic, see if it's the
517                  * youngest we have */
518                 if( p_vout->p_subpicture[i_index].b_ephemer )
519                 {
520                     if( p_ephemer == NULL )
521                     {
522                         p_ephemer = &p_vout->p_subpicture[i_index];
523                         continue;
524                     }
525
526                     if( p_vout->p_subpicture[i_index].i_start
527                                                      < p_ephemer->i_start )
528                     {
529                         /* Link the previous ephemer subpicture and
530                          * replace it with the current one */
531                         p_ephemer->p_next = p_subpic;
532                         p_subpic = p_ephemer;
533                         p_ephemer = &p_vout->p_subpicture[i_index];
534
535                         /* If it's the 2nd youngest subpicture,
536                          * register its date */
537                         if( !ephemer_date
538                               || ephemer_date > p_subpic->i_start )
539                         {
540                             ephemer_date = p_subpic->i_start;
541                         }
542
543                         continue;
544                     }
545                 }
546
547                 p_vout->p_subpicture[i_index].p_next = p_subpic;
548                 p_subpic = &p_vout->p_subpicture[i_index];
549
550                 /* If it's the 2nd youngest subpicture, register its date */
551                 if( !ephemer_date || ephemer_date > p_subpic->i_start )
552                 {
553                     ephemer_date = p_subpic->i_start;
554                 }
555             }
556             /* If it's not a DVD subpicture, just register it */
557             else
558             {
559                 p_vout->p_subpicture[i_index].p_next = p_subpic;
560                 p_subpic = &p_vout->p_subpicture[i_index];
561             }
562         }
563     }
564
565     /* If we found an ephemer subpicture, check if it has to be
566      * displayed */
567     if( p_ephemer != NULL )
568     {
569         if( p_ephemer->i_start < ephemer_date )
570         {
571             /* Ephemer subpicture has lived too long */
572             vout_DestroySubPicture( p_vout, p_ephemer );
573         }
574         else
575         {
576             /* Ephemer subpicture can still live a bit */
577             p_ephemer->p_next = p_subpic;
578             return p_ephemer;
579         }
580     }
581
582     return p_subpic;
583 }
584
585 /*****************************************************************************
586  * vout_RegisterOSDChannel: register an OSD channel
587  *****************************************************************************
588  * This function affects an ID to an OSD channel
589  *****************************************************************************/
590 int vout_RegisterOSDChannel( vout_thread_t *p_vout )
591 {
592     msg_Dbg( p_vout, "Registering OSD channel, ID: %i",
593              p_vout->i_channel_count + 1 );
594     return ++p_vout->i_channel_count;
595 }
596
597 /*****************************************************************************
598  * vout_ClearOSDChannel: clear an OSD channel
599  *****************************************************************************
600  * This function destroys the subpictures which belong to the OSD channel
601  * corresponding to i_channel_id.
602  *****************************************************************************/
603 void vout_ClearOSDChannel( vout_thread_t *p_vout, int i_channel )
604 {
605     int                 i_subpic;                        /* subpicture index */
606     subpicture_t *      p_subpic = NULL;            /* first free subpicture */
607
608     if( i_channel == DEFAULT_CHAN )
609     {
610         if( p_vout->p_default_channel != NULL )
611         {
612             vout_DestroySubPicture( p_vout, p_vout->p_default_channel );
613         }
614         p_vout->p_default_channel = NULL;
615         return;
616     }
617
618     vlc_mutex_lock( &p_vout->subpicture_lock );
619
620     for( i_subpic = 0; i_subpic < VOUT_MAX_SUBPICTURES; i_subpic++ )
621     {
622         p_subpic = &p_vout->p_subpicture[i_subpic];
623         if( p_subpic->i_status == FREE_SUBPICTURE
624             || ( p_subpic->i_status != RESERVED_SUBPICTURE
625                  && p_subpic->i_status != READY_SUBPICTURE ) )
626         {
627             continue;
628         }
629
630         if( p_subpic->i_channel == i_channel )
631         {
632             while( p_subpic->p_region )
633             {
634                 subpicture_region_t *p_region = p_subpic->p_region;
635                 p_subpic->p_region = p_region->p_next;
636                 spu_DestroyRegion( p_vout, p_region );
637             }
638
639             if( p_subpic->pf_destroy )
640             {
641                 p_subpic->pf_destroy( p_subpic );
642             }
643             p_subpic->i_status = FREE_SUBPICTURE;
644         }
645     }
646
647     vlc_mutex_unlock( &p_vout->subpicture_lock );
648 }
649
650 /*****************************************************************************
651  * UpdateSPU: update subpicture settings
652  *****************************************************************************
653  * This function is called from CropCallback and at initialization time, to
654  * retrieve crop information from the input.
655  *****************************************************************************/
656 static void UpdateSPU( vout_thread_t *p_vout, vlc_object_t *p_object )
657 {
658     vlc_value_t val;
659
660     p_vout->b_force_alpha = VLC_FALSE;
661     p_vout->b_force_crop = VLC_FALSE;
662
663     if( var_Get( p_object, "highlight", &val ) || !val.b_bool ) return;
664
665     p_vout->b_force_crop = VLC_TRUE;
666     var_Get( p_object, "x-start", &val );
667     p_vout->i_crop_x = val.i_int;
668     var_Get( p_object, "y-start", &val );
669     p_vout->i_crop_y = val.i_int;
670     var_Get( p_object, "x-end", &val );
671     p_vout->i_crop_width = val.i_int - p_vout->i_crop_x;
672     var_Get( p_object, "y-end", &val );
673     p_vout->i_crop_height = val.i_int - p_vout->i_crop_y;
674
675 #if 0
676     if( var_Get( p_object, "color", &val ) == VLC_SUCCESS )
677     {
678         int i;
679         for( i = 0; i < 4; i++ )
680         {
681             p_vout->pi_color[i] = ((uint8_t *)val.p_address)[i];
682         }
683     }
684 #endif
685
686     if( var_Get( p_object, "contrast", &val ) == VLC_SUCCESS )
687     {
688         int i;
689         for( i = 0; i < 4; i++ )
690         {
691             p_vout->pi_alpha[i] = ((uint8_t *)val.p_address)[i];
692             p_vout->pi_alpha[i] = p_vout->pi_alpha[i] == 0xf ?
693                 0xff : p_vout->pi_alpha[i] << 4;
694         }
695         p_vout->b_force_alpha = VLC_TRUE;
696     }
697
698     msg_Dbg( p_vout, "crop: %i,%i,%i,%i, alpha: %i",
699              p_vout->i_crop_x, p_vout->i_crop_y,
700              p_vout->i_crop_width, p_vout->i_crop_height,
701              p_vout->b_force_alpha );
702 }
703
704 /*****************************************************************************
705  * CropCallback: called when the highlight properties are changed
706  *****************************************************************************
707  * This callback is called from the input thread when we need cropping
708  *****************************************************************************/
709 static int CropCallback( vlc_object_t *p_object, char const *psz_var,
710                          vlc_value_t oldval, vlc_value_t newval, void *p_data )
711 {
712     UpdateSPU( (vout_thread_t *)p_data, p_object );
713     return VLC_SUCCESS;
714 }
715
716 /*****************************************************************************
717  * Buffers allocation callbacks for the filters
718  *****************************************************************************/
719 static subpicture_t *spu_new_buffer( filter_t *p_filter )
720 {
721     vout_thread_t *p_vout = (vout_thread_t *)p_filter->p_owner;
722     subpicture_t *p_spu;
723
724     p_spu = vout_CreateSubPicture( p_vout, !DEFAULT_CHAN, MEMORY_SUBPICTURE );
725     return p_spu;
726 }
727
728 static void spu_del_buffer( filter_t *p_filter, subpicture_t *p_spu )
729 {
730     vout_thread_t *p_vout = (vout_thread_t *)p_filter->p_owner;
731     vout_DestroySubPicture( p_vout, p_spu );
732 }