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