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