]> git.sesse.net Git - vlc/blob - modules/codec/spudec/parse.c
* all: ported to new API.
[vlc] / modules / codec / spudec / parse.c
1 /*****************************************************************************
2  * parse.c: SPU parser
3  *****************************************************************************
4  * Copyright (C) 2000-2001 VideoLAN
5  * $Id: parse.c,v 1.14 2003/11/22 19:55:47 fenrir Exp $
6  *
7  * Authors: Samuel Hocevar <sam@zoy.org>
8  *          Laurent Aimar <fenrir@via.ecp.fr>
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
30 #include <vlc/vlc.h>
31 #include <vlc/vout.h>
32 #include <vlc/decoder.h>
33 #include <vlc/input.h>
34
35 #include "spudec.h"
36
37 /*****************************************************************************
38  * Local prototypes.
39  *****************************************************************************/
40 static int  ParseControlSeq  ( decoder_t *, subpicture_t * );
41 static int  ParseRLE         ( decoder_t *, subpicture_t * );
42
43 static void DestroySPU       ( subpicture_t * );
44
45 static void UpdateSPU        ( subpicture_t *, vlc_object_t * );
46 static int  CropCallback     ( vlc_object_t *, char const *,
47                                vlc_value_t, vlc_value_t, void * );
48
49 /*****************************************************************************
50  * AddNibble: read a nibble from a source packet and add it to our integer.
51  *****************************************************************************/
52 static inline unsigned int AddNibble( unsigned int i_code,
53                                       uint8_t *p_src, int *pi_index )
54 {
55     if( *pi_index & 0x1 )
56     {
57         return( i_code << 4 | ( p_src[(*pi_index)++ >> 1] & 0xf ) );
58     }
59     else
60     {
61         return( i_code << 4 | p_src[(*pi_index)++ >> 1] >> 4 );
62     }
63 }
64
65 /*****************************************************************************
66  * ParsePacket: parse an SPU packet and send it to the video output
67  *****************************************************************************
68  * This function parses the SPU packet and, if valid, sends it to the
69  * video output.
70  *****************************************************************************/
71 void E_(ParsePacket)( decoder_t *p_dec)
72 {
73     decoder_sys_t *p_sys = p_dec->p_sys;
74
75     subpicture_t  *p_spu;
76
77     /* Allocate the subpicture internal data. */
78     p_spu = vout_CreateSubPicture( p_sys->p_vout, MEMORY_SUBPICTURE );
79     if( p_spu == NULL )
80     {
81         return;
82     }
83
84     /* Rationale for the "p_spudec->i_rle_size * 4": we are going to
85      * expand the RLE stuff so that we won't need to read nibbles later
86      * on. This will speed things up a lot. Plus, we'll only need to do
87      * this stupid interlacing stuff once. */
88     p_spu->p_sys = malloc( sizeof( subpicture_sys_t ) + 4*p_sys->i_rle_size );
89
90     /* Fill the p_spu structure */
91     vlc_mutex_init( p_dec, &p_spu->p_sys->lock );
92
93     p_spu->pf_render = E_(RenderSPU);
94     p_spu->pf_destroy = DestroySPU;
95     p_spu->p_sys->p_data = (uint8_t*)p_spu->p_sys + sizeof( subpicture_sys_t );
96     p_spu->p_sys->b_palette = VLC_FALSE;
97
98     p_spu->p_sys->pi_alpha[0] = 0x00;
99     p_spu->p_sys->pi_alpha[1] = 0x0f;
100     p_spu->p_sys->pi_alpha[2] = 0x0f;
101     p_spu->p_sys->pi_alpha[3] = 0x0f;
102
103     p_spu->p_sys->b_crop = VLC_FALSE;
104
105     /* Get display time now. If we do it later, we may miss the PTS. */
106     p_spu->p_sys->i_pts = p_sys->i_pts;
107
108     /* Attach to our input thread */
109     p_spu->p_sys->p_input = vlc_object_find( p_dec,
110                                              VLC_OBJECT_INPUT, FIND_PARENT );
111     if( p_spu->p_sys->p_input )
112     {
113         vlc_value_t val;
114
115         if( !var_Get( p_spu->p_sys->p_input, "highlight-mutex", &val ) )
116         {
117             vlc_mutex_t *p_mutex = val.p_address;
118
119             vlc_mutex_lock( p_mutex );
120             UpdateSPU( p_spu, VLC_OBJECT(p_spu->p_sys->p_input) );
121
122             var_AddCallback( p_spu->p_sys->p_input,
123                              "highlight", CropCallback, p_spu );
124             vlc_mutex_unlock( p_mutex );
125         }
126     }
127
128     /* Getting the control part */
129     if( ParseControlSeq( p_dec, p_spu ) )
130     {
131         /* There was a parse error, delete the subpicture */
132         vout_DestroySubPicture( p_sys->p_vout, p_spu );
133         return;
134     }
135
136      /* We try to display it */
137     if( ParseRLE( p_dec, p_spu ) )
138     {
139         /* There was a parse error, delete the subpicture */
140         vout_DestroySubPicture( p_sys->p_vout, p_spu );
141         return;
142     }
143
144     msg_Dbg( p_dec, "total size: 0x%x, RLE offsets: 0x%x 0x%x",
145              p_sys->i_spu_size,
146              p_spu->p_sys->pi_offset[0], p_spu->p_sys->pi_offset[1] );
147
148     /* SPU is finished - we can ask the video output to display it */
149     vout_DisplaySubPicture( p_sys->p_vout, p_spu );
150
151     /* TODO: do stuff! */
152 }
153
154 /*****************************************************************************
155  * ParseControlSeq: parse all SPU control sequences
156  *****************************************************************************
157  * This is the most important part in SPU decoding. We get dates, palette
158  * information, coordinates, and so on. For more information on the
159  * subtitles format, see http://sam.zoy.org/doc/dvd/subtitles/index.html
160  *****************************************************************************/
161 static int ParseControlSeq( decoder_t *p_dec, subpicture_t * p_spu )
162 {
163     decoder_sys_t *p_sys = p_dec->p_sys;
164
165     /* Our current index in the SPU packet */
166     unsigned int i_index = p_sys->i_rle_size + 4;
167
168     /* The next start-of-control-sequence index and the previous one */
169     unsigned int i_next_seq = 0, i_cur_seq = 0;
170
171     /* Command and date */
172     uint8_t i_command = SPU_CMD_END;
173     mtime_t date = 0;
174
175     unsigned int i, pi_alpha[4];
176
177     /* Initialize the structure */
178     p_spu->i_start = p_spu->i_stop = 0;
179     p_spu->b_ephemer = VLC_FALSE;
180
181     do
182     {
183         if( (int)i_index >= p_sys->i_spu_size + 1 )
184         {
185             /* sanity
186              * XXX only on test by loop as p_sys->buffer is bigger than needed
187              * to avoid checking at each access
188              */
189             break;
190         }
191
192         /* If we just read a command sequence, read the next one;
193          * otherwise, go on with the commands of the current sequence. */
194         if( i_command == SPU_CMD_END )
195         {
196             /* Get the control sequence date */
197             date = (mtime_t)GetWBE( &p_sys->buffer[i_index] ) * 11000;
198             /* FIXME How to access i_rate
199                     * p_spudec->bit_stream.p_pes->i_rate / DEFAULT_RATE;
200             */
201
202             /* Next offset */
203             i_cur_seq = i_index;
204             i_next_seq = GetWBE( &p_sys->buffer[i_index+2] );
205
206             /* Skip what we just read */
207             i_index += 4;
208         }
209
210         i_command = p_sys->buffer[i_index++];
211
212         switch( i_command )
213         {
214         case SPU_CMD_FORCE_DISPLAY: /* 00 (force displaying) */
215             p_spu->i_start = p_spu->p_sys->i_pts + date;
216             p_spu->b_ephemer = VLC_TRUE;
217             break;
218
219         /* Convert the dates in seconds to PTS values */
220         case SPU_CMD_START_DISPLAY: /* 01 (start displaying) */
221             p_spu->i_start = p_spu->p_sys->i_pts + date;
222             break;
223
224         case SPU_CMD_STOP_DISPLAY: /* 02 (stop displaying) */
225             p_spu->i_stop = p_spu->p_sys->i_pts + date;
226             break;
227
228         case SPU_CMD_SET_PALETTE:
229
230             /* 03xxxx (palette) */
231             if( p_dec->p_fifo->p_demux_data
232                  && *(int*)p_dec->p_fifo->p_demux_data == 0xBeeF )
233             {
234                 unsigned int idx[4];
235
236                 p_spu->p_sys->b_palette = VLC_TRUE;
237
238                 idx[0] = (p_sys->buffer[i_index+0]>>4)&0x0f;
239                 idx[1] = (p_sys->buffer[i_index+0])&0x0f;
240                 idx[2] = (p_sys->buffer[i_index+1]>>4)&0x0f;
241                 idx[3] = (p_sys->buffer[i_index+1])&0x0f;
242
243                 for( i = 0; i < 4 ; i++ )
244                 {
245                     uint32_t i_color;
246                     i_color = ((uint32_t*)((char*)p_dec->p_fifo->p_demux_data +
247                                                    sizeof(int)))[idx[i]];
248
249                     /* FIXME: this job should be done sooner */
250                     p_spu->p_sys->pi_yuv[3-i][0] = (i_color>>16) & 0xff;
251                     p_spu->p_sys->pi_yuv[3-i][1] = (i_color>>0) & 0xff;
252                     p_spu->p_sys->pi_yuv[3-i][2] = (i_color>>8) & 0xff;
253                 }
254             }
255             i_index += 2;
256
257             break;
258
259         case SPU_CMD_SET_ALPHACHANNEL: /* 04xxxx (alpha channel) */
260             pi_alpha[3] = (p_sys->buffer[i_index+0]>>4)&0x0f;
261             pi_alpha[2] = (p_sys->buffer[i_index+0])&0x0f;
262             pi_alpha[1] = (p_sys->buffer[i_index+1]>>4)&0x0f;
263             pi_alpha[0] = (p_sys->buffer[i_index+1])&0x0f;
264
265             /* Ignore blank alpha palette. Sometimes spurious blank
266              * alpha palettes are present - dunno why. */
267             if( pi_alpha[0] | pi_alpha[1] | pi_alpha[2] | pi_alpha[3] )
268             {
269                 p_spu->p_sys->pi_alpha[0] = pi_alpha[0];
270                 p_spu->p_sys->pi_alpha[1] = pi_alpha[1];
271                 p_spu->p_sys->pi_alpha[2] = pi_alpha[2];
272                 p_spu->p_sys->pi_alpha[3] = pi_alpha[3];
273             }
274             else
275             {
276                 msg_Warn( p_dec, "ignoring blank alpha palette" );
277             }
278
279             i_index += 2;
280             break;
281
282         case SPU_CMD_SET_COORDINATES: /* 05xxxyyyxxxyyy (coordinates) */
283             p_spu->i_x = (p_sys->buffer[i_index+0]<<4)|
284                          ((p_sys->buffer[i_index+1]>>4)&0x0f);
285             p_spu->i_width = (((p_sys->buffer[i_index+1]&0x0f)<<8)|
286                               p_sys->buffer[i_index+2]) - p_spu->i_x + 1;
287
288             p_spu->i_y = (p_sys->buffer[i_index+3]<<4)|
289                          ((p_sys->buffer[i_index+4]>>4)&0x0f);
290             p_spu->i_height = (((p_sys->buffer[i_index+4]&0x0f)<<8)|
291                               p_sys->buffer[i_index+5]) - p_spu->i_y + 1;
292
293             i_index += 6;
294             break;
295
296         case SPU_CMD_SET_OFFSETS: /* 06xxxxyyyy (byte offsets) */
297             p_spu->p_sys->pi_offset[0] = GetWBE(&p_sys->buffer[i_index+0]) - 4;
298             p_spu->p_sys->pi_offset[1] = GetWBE(&p_sys->buffer[i_index+2]) - 4;
299             i_index += 4;
300             break;
301
302         case SPU_CMD_END: /* ff (end) */
303             break;
304
305         default: /* xx (unknown command) */
306             msg_Err( p_dec, "unknown command 0x%.2x", i_command );
307             return VLC_EGENERIC;
308         }
309
310         /* We need to check for quit commands here */
311         if( p_dec->b_die )
312         {
313             return VLC_EGENERIC;
314         }
315
316     } while( i_command != SPU_CMD_END || i_index == i_next_seq );
317
318     /* Check that the next sequence index matches the current one */
319     if( i_next_seq != i_cur_seq )
320     {
321         msg_Err( p_dec, "index mismatch (0x%.4x != 0x%.4x)",
322                  i_next_seq, i_cur_seq );
323         return VLC_EGENERIC;
324     }
325
326     if( (int)i_index > p_sys->i_spu_size )
327     {
328         msg_Err( p_dec, "uh-oh, we went too far (0x%.4x > 0x%.4x)",
329                  i_index, p_sys->i_spu_size );
330         return VLC_EGENERIC;
331     }
332
333     if( !p_spu->i_start )
334     {
335         msg_Err( p_dec, "no `start display' command" );
336     }
337
338     if( p_spu->i_stop <= p_spu->i_start && !p_spu->b_ephemer )
339     {
340         /* This subtitle will live for 5 seconds or until the next subtitle */
341         p_spu->i_stop = p_spu->i_start + (mtime_t)500 * 11000;
342         /* FIXME how to access i_rate ?
343                         * p_spudec->bit_stream.p_pes->i_rate / DEFAULT_RATE;
344         */
345         p_spu->b_ephemer = VLC_TRUE;
346     }
347
348     /* Get rid of padding bytes */
349     if( p_sys->i_spu_size > (int)i_index + 1 )
350     {
351         /* Zero or one padding byte, are quite usual
352          * More than one padding byte - this is very strange, but
353          * we can deal with it */
354         msg_Warn( p_dec, "%i padding bytes, we usually get 0 or 1 of them",
355                   p_sys->i_spu_size - i_index );
356     }
357
358     /* Successfully parsed ! */
359     return VLC_SUCCESS;
360 }
361
362 /*****************************************************************************
363  * ParseRLE: parse the RLE part of the subtitle
364  *****************************************************************************
365  * This part parses the subtitle graphical data and stores it in a more
366  * convenient structure for later decoding. For more information on the
367  * subtitles format, see http://sam.zoy.org/doc/dvd/subtitles/index.html
368  *****************************************************************************/
369 static int ParseRLE( decoder_t *p_dec, subpicture_t * p_spu )
370 {
371     decoder_sys_t *p_sys = p_dec->p_sys;
372     uint8_t       *p_src = &p_sys->buffer[4];
373
374     unsigned int i_code;
375
376     unsigned int i_width = p_spu->i_width;
377     unsigned int i_height = p_spu->i_height;
378     unsigned int i_x, i_y;
379
380     uint16_t *p_dest = (uint16_t *)p_spu->p_sys->p_data;
381
382     /* The subtitles are interlaced, we need two offsets */
383     unsigned int  i_id = 0;                   /* Start on the even SPU layer */
384     unsigned int  pi_table[ 2 ];
385     unsigned int *pi_offset;
386
387 #if 0 /* cropping */
388     vlc_bool_t b_empty_top = VLC_TRUE,
389                b_empty_bottom = VLC_FALSE;
390     unsigned int i_skipped_top = 0,
391                  i_skipped_bottom = 0;
392 #endif
393
394     /* Colormap statistics */
395     int i_border = -1;
396     int stats[4]; stats[0] = stats[1] = stats[2] = stats[3] = 0;
397
398     pi_table[ 0 ] = p_spu->p_sys->pi_offset[ 0 ] << 1;
399     pi_table[ 1 ] = p_spu->p_sys->pi_offset[ 1 ] << 1;
400
401     for( i_y = 0 ; i_y < i_height ; i_y++ )
402     {
403         pi_offset = pi_table + i_id;
404
405         for( i_x = 0 ; i_x < i_width ; i_x += i_code >> 2 )
406         {
407             i_code = AddNibble( 0, p_src, pi_offset );
408
409             if( i_code < 0x04 )
410             {
411                 i_code = AddNibble( i_code, p_src, pi_offset );
412
413                 if( i_code < 0x10 )
414                 {
415                     i_code = AddNibble( i_code, p_src, pi_offset );
416
417                     if( i_code < 0x040 )
418                     {
419                         i_code = AddNibble( i_code, p_src, pi_offset );
420
421                         if( i_code < 0x0100 )
422                         {
423                             /* If the 14 first bits are set to 0, then it's a
424                              * new line. We emulate it. */
425                             if( i_code < 0x0004 )
426                             {
427                                 i_code |= ( i_width - i_x ) << 2;
428                             }
429                             else
430                             {
431                                 /* We have a boo boo ! */
432                                 msg_Err( p_dec, "unknown RLE code "
433                                          "0x%.4x", i_code );
434                                 return VLC_EGENERIC;
435                             }
436                         }
437                     }
438                 }
439             }
440
441             if( ( (i_code >> 2) + i_x + i_y * i_width ) > i_height * i_width )
442             {
443                 msg_Err( p_dec,
444                          "out of bounds, %i at (%i,%i) is out of %ix%i",
445                          i_code >> 2, i_x, i_y, i_width, i_height );
446                 return VLC_EGENERIC;
447             }
448
449             /* Try to find the border color */
450             if( p_spu->p_sys->pi_alpha[ i_code & 0x3 ] != 0x00 )
451             {
452                 i_border = i_code & 0x3;
453                 stats[i_border] += i_code >> 2;
454             }
455
456 #if 0 /* cropping */
457             if( (i_code >> 2) == i_width
458                  && p_spu->p_sys->pi_alpha[ i_code & 0x3 ] == 0x00 )
459             {
460                 if( b_empty_top )
461                 {
462                     /* This is a blank top line, we skip it */
463                     i_skipped_top++;
464                 }
465                 else
466                 {
467                     /* We can't be sure the current lines will be skipped,
468                      * so we store the code just in case. */
469                     *p_dest++ = i_code;
470
471                     b_empty_bottom = VLC_TRUE;
472                     i_skipped_bottom++;
473                 }
474             }
475             else
476             {
477                 /* We got a valid code, store it */
478                 *p_dest++ = i_code;
479
480                 /* Valid code means no blank line */
481                 b_empty_top = VLC_FALSE;
482                 b_empty_bottom = VLC_FALSE;
483                 i_skipped_bottom = 0;
484             }
485 #else
486             *p_dest++ = i_code;
487 #endif
488         }
489
490         /* Check that we didn't go too far */
491         if( i_x > i_width )
492         {
493             msg_Err( p_dec, "i_x overflowed, %i > %i",
494                      i_x, i_width );
495             return VLC_EGENERIC;
496         }
497
498         /* Byte-align the stream */
499         if( *pi_offset & 0x1 )
500         {
501             (*pi_offset)++;
502         }
503
504         /* Swap fields */
505         i_id = ~i_id & 0x1;
506     }
507
508     /* We shouldn't get any padding bytes */
509     if( i_y < i_height )
510     {
511         msg_Err( p_dec, "padding bytes found in RLE sequence" );
512         msg_Err( p_dec, "send mail to <sam@zoy.org> if you "
513                         "want to help debugging this" );
514
515         /* Skip them just in case */
516         while( i_y < i_height )
517         {
518             *p_dest++ = i_width << 2;
519             i_y++;
520         }
521
522         return VLC_EGENERIC;
523     }
524
525     msg_Dbg( p_dec, "valid subtitle, size: %ix%i, position: %i,%i",
526              p_spu->i_width, p_spu->i_height, p_spu->i_x, p_spu->i_y );
527
528 #if 0 /* cropping */
529     /* Crop if necessary */
530     if( i_skipped_top || i_skipped_bottom )
531     {
532         p_spu->i_y += i_skipped_top;
533         p_spu->i_height -= i_skipped_top + i_skipped_bottom;
534
535         msg_Dbg( p_spudec->p_fifo, "cropped to: %ix%i, position: %i,%i",
536                  p_spu->i_width, p_spu->i_height, p_spu->i_x, p_spu->i_y );
537     }
538 #endif
539
540     /* Handle color if no palette was found */
541     if( !p_spu->p_sys->b_palette )
542     {
543         int i, i_inner = -1, i_shade = -1;
544
545         /* Set the border color */
546         p_spu->p_sys->pi_yuv[i_border][0] = 0x00;
547         p_spu->p_sys->pi_yuv[i_border][1] = 0x80;
548         p_spu->p_sys->pi_yuv[i_border][2] = 0x80;
549         stats[i_border] = 0;
550
551         /* Find the inner colors */
552         for( i = 0 ; i < 4 && i_inner == -1 ; i++ )
553         {
554             if( stats[i] )
555             {
556                 i_inner = i;
557             }
558         }
559
560         for(       ; i < 4 && i_shade == -1 ; i++ )
561         {
562             if( stats[i] )
563             {
564                 if( stats[i] > stats[i_inner] )
565                 {
566                     i_shade = i_inner;
567                     i_inner = i;
568                 }
569                 else
570                 {
571                     i_shade = i;
572                 }
573             }
574         }
575
576         /* Set the inner color */
577         if( i_inner != -1 )
578         {
579             p_spu->p_sys->pi_yuv[i_inner][0] = 0xff;
580             p_spu->p_sys->pi_yuv[i_inner][1] = 0x80;
581             p_spu->p_sys->pi_yuv[i_inner][2] = 0x80;
582         }
583
584         /* Set the anti-aliasing color */
585         if( i_shade != -1 )
586         {
587             p_spu->p_sys->pi_yuv[i_shade][0] = 0x80;
588             p_spu->p_sys->pi_yuv[i_shade][1] = 0x80;
589             p_spu->p_sys->pi_yuv[i_shade][2] = 0x80;
590         }
591
592         msg_Dbg( p_dec,
593                  "using custom palette (border %i, inner %i, shade %i)",
594                  i_border, i_inner, i_shade );
595     }
596
597     return VLC_SUCCESS;
598 }
599
600 /*****************************************************************************
601  * DestroySPU: subpicture destructor
602  *****************************************************************************/
603 static void DestroySPU( subpicture_t *p_spu )
604 {
605     if( p_spu->p_sys->p_input )
606     {
607         /* Detach from our input thread */
608         var_DelCallback( p_spu->p_sys->p_input, "highlight",
609                          CropCallback, p_spu );
610         vlc_object_release( p_spu->p_sys->p_input );
611     }
612
613     vlc_mutex_destroy( &p_spu->p_sys->lock );
614     free( p_spu->p_sys );
615 }
616
617 /*****************************************************************************
618  * UpdateSPU: update subpicture settings
619  *****************************************************************************
620  * This function is called from CropCallback and at initialization time, to
621  * retrieve crop information from the input.
622  *****************************************************************************/
623 static void UpdateSPU( subpicture_t *p_spu, vlc_object_t *p_object )
624 {
625     vlc_value_t val;
626
627     if( var_Get( p_object, "highlight", &val ) )
628     {
629         return;
630     }
631
632     p_spu->p_sys->b_crop = val.b_bool;
633     if( !p_spu->p_sys->b_crop )
634     {
635         return;
636     }
637
638     var_Get( p_object, "x-start", &val );
639     p_spu->p_sys->i_x_start = val.i_int;
640     var_Get( p_object, "y-start", &val );
641     p_spu->p_sys->i_y_start = val.i_int;
642     var_Get( p_object, "x-end", &val );
643     p_spu->p_sys->i_x_end = val.i_int;
644     var_Get( p_object, "y-end", &val );
645     p_spu->p_sys->i_y_end = val.i_int;
646
647 #if 0
648     if( var_Get( p_object, "color", &val ) == VLC_SUCCESS )
649     {
650         p_spu->p_sys->pi_color[0] = ((uint8_t *)val.p_address)[0];
651         p_spu->p_sys->pi_color[1] = ((uint8_t *)val.p_address)[1];
652         p_spu->p_sys->pi_color[2] = ((uint8_t *)val.p_address)[2];
653         p_spu->p_sys->pi_color[3] = ((uint8_t *)val.p_address)[3];
654     }
655 #endif
656
657     if( var_Get( p_object, "contrast", &val ) == VLC_SUCCESS )
658     {
659         p_spu->p_sys->pi_alpha[0] = ((uint8_t *)val.p_address)[0];
660         p_spu->p_sys->pi_alpha[1] = ((uint8_t *)val.p_address)[1];
661         p_spu->p_sys->pi_alpha[2] = ((uint8_t *)val.p_address)[2];
662         p_spu->p_sys->pi_alpha[3] = ((uint8_t *)val.p_address)[3];
663     }
664 }
665
666 /*****************************************************************************
667  * CropCallback: called when the highlight properties are changed
668  *****************************************************************************
669  * This callback is called from the input thread when we need cropping
670  *****************************************************************************/
671 static int CropCallback( vlc_object_t *p_object, char const *psz_var,
672                          vlc_value_t oldval, vlc_value_t newval, void *p_data )
673 {
674     UpdateSPU( (subpicture_t *)p_data, p_object );
675
676     return VLC_SUCCESS;
677 }
678