1 /*****************************************************************************
2 * spu_decoder.c : spu decoder thread
3 *****************************************************************************
4 * Copyright (C) 2000-2001 VideoLAN
5 * $Id: spu_decoder.c,v 1.28 2002/06/05 18:18:49 stef Exp $
7 * Authors: Samuel Hocevar <sam@zoy.org>
8 * Rudolf Cornelissen <rag.cornelissen@inter.nl.net>
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.
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.
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 *****************************************************************************/
25 /*****************************************************************************
27 *****************************************************************************/
28 #include <stdlib.h> /* malloc(), free() */
29 #include <string.h> /* memcpy(), memset() */
33 #include <vlc/decoder.h>
36 # include <unistd.h> /* getpid() */
39 #ifdef WIN32 /* getpid() for win32 is located in process.h */
43 #include "spu_decoder.h"
45 /*****************************************************************************
47 *****************************************************************************/
48 static int decoder_Probe ( u8 * );
49 static int decoder_Run ( decoder_fifo_t * );
50 static int InitThread ( spudec_thread_t * );
51 static void EndThread ( spudec_thread_t * );
53 static int SyncPacket ( spudec_thread_t * );
54 static void ParsePacket ( spudec_thread_t * );
55 static int ParseControlSequences( spudec_thread_t *, subpicture_t * );
56 static int ParseRLE ( spudec_thread_t *, subpicture_t *, u8 * );
57 static void RenderSPU ( vout_thread_t *, picture_t *,
58 const subpicture_t * );
60 /*****************************************************************************
62 *****************************************************************************/
63 void _M( spudec_getfunctions )( function_list_t * p_function_list )
65 p_function_list->functions.dec.pf_probe = decoder_Probe;
66 p_function_list->functions.dec.pf_run = decoder_Run;
69 /*****************************************************************************
70 * Build configuration tree.
71 *****************************************************************************/
76 SET_DESCRIPTION( _("DVD subtitles decoder module") )
77 ADD_CAPABILITY( DECODER, 50 )
81 _M( spudec_getfunctions )( &p_module->p_functions->dec );
84 MODULE_DEACTIVATE_START
85 MODULE_DEACTIVATE_STOP
87 /*****************************************************************************
88 * decoder_Probe: probe the decoder and return score
89 *****************************************************************************
90 * Tries to launch a decoder and return score so that the interface is able
92 *****************************************************************************/
93 static int decoder_Probe( u8 *pi_type )
95 return ( *pi_type == DVD_SPU_ES ) ? 0 : -1;
98 /*****************************************************************************
99 * decoder_Run: this function is called just after the thread is created
100 *****************************************************************************/
101 static int decoder_Run( decoder_fifo_t * p_fifo )
103 spudec_thread_t * p_spudec;
105 /* Allocate the memory needed to store the thread's structure */
106 p_spudec = (spudec_thread_t *)malloc( sizeof(spudec_thread_t) );
108 if ( p_spudec == NULL )
110 msg_Err( p_fifo, "out of memory" );
111 DecoderError( p_fifo );
116 * Initialize the thread properties
118 p_spudec->p_vout = NULL;
119 p_spudec->p_fifo = p_fifo;
122 * Initialize thread and free configuration
124 p_spudec->p_fifo->b_error = InitThread( p_spudec );
127 * Main loop - it is not executed if an error occured during
130 while( (!p_spudec->p_fifo->b_die) && (!p_spudec->p_fifo->b_error) )
132 if( !SyncPacket( p_spudec ) )
134 ParsePacket( p_spudec );
141 if( p_spudec->p_fifo->b_error )
143 DecoderError( p_spudec->p_fifo );
146 EndThread( p_spudec );
151 EndThread( p_spudec );
155 /* following functions are local */
157 /*****************************************************************************
158 * InitThread: initialize spu decoder thread
159 *****************************************************************************
160 * This function is called from RunThread and performs the second step of the
161 * initialization. It returns 0 on success. Note that the thread's flag are not
162 * modified inside this function.
163 *****************************************************************************/
164 static int InitThread( spudec_thread_t *p_spudec )
166 /* Find an available video output */
169 if( p_spudec->p_fifo->b_die || p_spudec->p_fifo->b_error )
174 p_spudec->p_vout = vlc_object_find( p_spudec->p_fifo, VLC_OBJECT_VOUT,
177 if( p_spudec->p_vout )
182 msleep( VOUT_OUTMEM_SLEEP );
186 InitBitstream( &p_spudec->bit_stream, p_spudec->p_fifo, NULL, NULL );
188 /* Mark thread as running and return */
192 /*****************************************************************************
193 * EndThread: thread destruction
194 *****************************************************************************
195 * This function is called when the thread ends after a sucessful
197 *****************************************************************************/
198 static void EndThread( spudec_thread_t *p_spudec )
200 if( p_spudec->p_vout != NULL
201 && p_spudec->p_vout->p_subpicture != NULL )
203 subpicture_t * p_subpic;
206 for( i_subpic = 0; i_subpic < VOUT_MAX_SUBPICTURES; i_subpic++ )
208 p_subpic = &p_spudec->p_vout->p_subpicture[i_subpic];
210 if( p_subpic != NULL &&
211 ( ( p_subpic->i_status == RESERVED_SUBPICTURE )
212 || ( p_subpic->i_status == READY_SUBPICTURE ) ) )
214 vout_DestroySubPicture( p_spudec->p_vout, p_subpic );
218 vlc_object_release( p_spudec->p_vout );
224 /*****************************************************************************
225 * SyncPacket: get in sync with the stream
226 *****************************************************************************
227 * This function makes a few sanity checks and returns 0 if it looks like we
228 * are at the beginning of a subpicture packet.
229 *****************************************************************************/
230 static int SyncPacket( spudec_thread_t *p_spudec )
232 /* Re-align the buffer on an 8-bit boundary */
233 RealignBits( &p_spudec->bit_stream );
235 /* The total SPU packet size, often bigger than a PS packet */
236 p_spudec->i_spu_size = GetBits( &p_spudec->bit_stream, 16 );
238 /* The RLE stuff size (remove 4 because we just read 32 bits) */
239 p_spudec->i_rle_size = ShowBits( &p_spudec->bit_stream, 16 ) - 4;
241 /* If the values we got are a bit strange, skip packet */
242 if( !p_spudec->i_spu_size
243 || ( p_spudec->i_rle_size >= p_spudec->i_spu_size ) )
248 RemoveBits( &p_spudec->bit_stream, 16 );
253 /*****************************************************************************
254 * ParsePacket: parse an SPU packet and send it to the video output
255 *****************************************************************************
256 * This function parses the SPU packet and, if valid, sends it to the
258 *****************************************************************************/
259 static void ParsePacket( spudec_thread_t *p_spudec )
261 subpicture_t * p_spu;
263 unsigned int i_offset;
265 msg_Dbg( p_spudec->p_fifo, "trying to gather a 0x%.2x long subtitle",
266 p_spudec->i_spu_size );
268 /* We cannot display a subpicture with no date */
269 if( p_spudec->p_fifo->p_first->i_pts == 0 )
271 msg_Warn( p_spudec->p_fifo, "subtitle without a date" );
275 /* Allocate the subpicture internal data. */
276 p_spu = vout_CreateSubPicture( p_spudec->p_vout, MEMORY_SUBPICTURE,
277 sizeof( subpicture_sys_t )
278 + p_spudec->i_rle_size * 4 );
279 /* Rationale for the "p_spudec->i_rle_size * 4": we are going to
280 * expand the RLE stuff so that we won't need to read nibbles later
281 * on. This will speed things up a lot. Plus, we'll only need to do
282 * this stupid interlacing stuff once. */
289 /* Fill the p_spu structure */
290 p_spu->pf_render = RenderSPU;
291 p_spu->p_sys->p_data = (u8*)p_spu->p_sys + sizeof( subpicture_sys_t );
292 p_spu->p_sys->b_palette = 0;
294 /* Get display time now. If we do it later, we may miss the PTS. */
295 p_spu->p_sys->i_pts = p_spudec->p_fifo->p_first->i_pts;
297 /* Allocate the temporary buffer we will parse */
298 p_src = malloc( p_spudec->i_rle_size );
302 msg_Err( p_spudec->p_fifo, "out of memory" );
303 vout_DestroySubPicture( p_spudec->p_vout, p_spu );
308 for( i_offset = 0; i_offset < p_spudec->i_rle_size;
309 i_offset += SPU_CHUNK_SIZE )
311 GetChunk( &p_spudec->bit_stream, p_src + i_offset,
312 ( i_offset + SPU_CHUNK_SIZE < p_spudec->i_rle_size ) ?
313 SPU_CHUNK_SIZE : p_spudec->i_rle_size - i_offset );
315 /* Abort subtitle parsing if we were requested to stop */
316 if( p_spudec->p_fifo->b_die )
319 vout_DestroySubPicture( p_spudec->p_vout, p_spu );
325 /* Dump the subtitle info */
326 intf_WarnHexDump( 5, p_spu->p_sys->p_data, p_spudec->i_rle_size );
329 /* Getting the control part */
330 if( ParseControlSequences( p_spudec, p_spu ) )
332 /* There was a parse error, delete the subpicture */
334 vout_DestroySubPicture( p_spudec->p_vout, p_spu );
338 /* At this point, no more GetBit() command is needed, so we have all
339 * the data we need to tell whether the subtitle is valid. Thus we
340 * try to display it and we ignore b_die. */
342 if( ParseRLE( p_spudec, p_spu, p_src ) )
344 /* There was a parse error, delete the subpicture */
346 vout_DestroySubPicture( p_spudec->p_vout, p_spu );
350 msg_Dbg( p_spudec->p_fifo, "total size: 0x%x, RLE offsets: 0x%x 0x%x",
351 p_spudec->i_spu_size,
352 p_spu->p_sys->pi_offset[0], p_spu->p_sys->pi_offset[1] );
354 /* SPU is finished - we can ask the video output to display it */
355 vout_DisplaySubPicture( p_spudec->p_vout, p_spu );
361 /*****************************************************************************
362 * ParseControlSequences: parse all SPU control sequences
363 *****************************************************************************
364 * This is the most important part in SPU decoding. We get dates, palette
365 * information, coordinates, and so on. For more information on the
366 * subtitles format, see http://sam.zoy.org/doc/dvd/subtitles/index.html
367 *****************************************************************************/
368 static int ParseControlSequences( spudec_thread_t *p_spudec,
369 subpicture_t * p_spu )
371 /* Our current index in the SPU packet */
372 int i_index = p_spudec->i_rle_size + 4;
374 /* The next start-of-control-sequence index and the previous one */
375 int i_next_seq, i_cur_seq;
377 /* Command time and date */
383 /* XXX: temporary variables */
384 vlc_bool_t b_force_display = 0;
386 /* Initialize the structure */
387 p_spu->i_start = p_spu->i_stop = 0;
388 p_spu->b_ephemer = 0;
392 /* Get the control sequence date */
393 i_date = GetBits( &p_spudec->bit_stream, 16 );
397 i_next_seq = GetBits( &p_spudec->bit_stream, 16 );
399 /* Skip what we just read */
404 i_command = GetBits( &p_spudec->bit_stream, 8 );
409 case SPU_CMD_FORCE_DISPLAY:
411 /* 00 (force displaying) */
412 p_spu->i_start = p_spu->p_sys->i_pts + ( i_date * 11000 );
417 /* Convert the dates in seconds to PTS values */
418 case SPU_CMD_START_DISPLAY:
420 /* 01 (start displaying) */
421 p_spu->i_start = p_spu->p_sys->i_pts + ( i_date * 11000 );
425 case SPU_CMD_STOP_DISPLAY:
427 /* 02 (stop displaying) */
428 p_spu->i_stop = p_spu->p_sys->i_pts + ( i_date * 11000 );
432 case SPU_CMD_SET_PALETTE:
434 /* 03xxxx (palette) */
435 if( p_spudec->p_fifo->p_demux_data &&
436 *(int*)p_spudec->p_fifo->p_demux_data == 0xBeeF )
440 p_spu->p_sys->b_palette = 1;
441 for( i = 0; i < 4 ; i++ )
443 i_color = ((u32*)((char*)p_spudec->p_fifo->
444 p_demux_data + sizeof(int)))[
445 GetBits(&p_spudec->bit_stream, 4) ];
447 p_spu->p_sys->pi_yuv[3-i][0] = (i_color>>16) & 0xff;
448 p_spu->p_sys->pi_yuv[3-i][1] = (i_color>>0) & 0xff;
449 p_spu->p_sys->pi_yuv[3-i][2] = (i_color>>8) & 0xff;
454 RemoveBits( &p_spudec->bit_stream, 16 );
460 case SPU_CMD_SET_ALPHACHANNEL:
462 /* 04xxxx (alpha channel) */
463 for( i = 0; i < 4 ; i++ )
465 p_spu->p_sys->pi_alpha[3-i]
466 = GetBits( &p_spudec->bit_stream, 4 );
472 case SPU_CMD_SET_COORDINATES:
474 /* 05xxxyyyxxxyyy (coordinates) */
475 p_spu->i_x = GetBits( &p_spudec->bit_stream, 12 );
476 p_spu->i_width = GetBits( &p_spudec->bit_stream, 12 )
479 p_spu->i_y = GetBits( &p_spudec->bit_stream, 12 );
480 p_spu->i_height = GetBits( &p_spudec->bit_stream, 12 )
487 case SPU_CMD_SET_OFFSETS:
489 /* 06xxxxyyyy (byte offsets) */
490 p_spu->p_sys->pi_offset[0] =
491 GetBits( &p_spudec->bit_stream, 16 ) - 4;
493 p_spu->p_sys->pi_offset[1] =
494 GetBits( &p_spudec->bit_stream, 16 ) - 4;
507 /* xx (unknown command) */
508 msg_Err( p_spudec->p_fifo, "unknown command 0x%.2x",
513 /* We need to check for quit commands here */
514 if( p_spudec->p_fifo->b_die )
519 } while( i_command != SPU_CMD_END );
521 } while( i_index == i_next_seq );
523 /* Check that the next sequence index matches the current one */
524 if( i_next_seq != i_cur_seq )
526 msg_Err( p_spudec->p_fifo, "index mismatch (0x%.4x != 0x%.4x)",
527 i_next_seq, i_cur_seq );
531 if( i_index > p_spudec->i_spu_size )
533 msg_Err( p_spudec->p_fifo, "uh-oh, we went too far (0x%.4x > 0x%.4x)",
534 i_index, p_spudec->i_spu_size );
538 if( !p_spu->i_start )
540 msg_Err( p_spudec->p_fifo, "no `start display' command" );
545 /* This subtitle will live for 5 seconds or until the next subtitle */
546 p_spu->i_stop = p_spu->i_start + 500 * 11000;
547 p_spu->b_ephemer = 1;
550 /* Get rid of padding bytes */
551 switch( p_spudec->i_spu_size - i_index )
553 /* Zero or one padding byte, quite usual */
555 RemoveBits( &p_spudec->bit_stream, 8 );
560 /* More than one padding byte - this is very strange, but
561 * we can deal with it */
563 msg_Warn( p_spudec->p_fifo,
564 "%i padding bytes, we usually get 0 or 1 of them",
565 p_spudec->i_spu_size - i_index );
567 while( i_index < p_spudec->i_spu_size )
569 RemoveBits( &p_spudec->bit_stream, 8 );
576 if( b_force_display )
578 msg_Err( p_spudec->p_fifo, "\"force display\" command" );
579 msg_Err( p_spudec->p_fifo, "send mail to <sam@zoy.org> if you "
580 "want to help debugging this" );
583 /* Successfully parsed ! */
587 /*****************************************************************************
588 * ParseRLE: parse the RLE part of the subtitle
589 *****************************************************************************
590 * This part parses the subtitle graphical data and stores it in a more
591 * convenient structure for later decoding. For more information on the
592 * subtitles format, see http://sam.zoy.org/doc/dvd/subtitles/index.html
593 *****************************************************************************/
594 static int ParseRLE( spudec_thread_t *p_spudec,
595 subpicture_t * p_spu, u8 * p_src )
599 unsigned int i_width = p_spu->i_width;
600 unsigned int i_height = p_spu->i_height;
601 unsigned int i_x, i_y;
603 u16 *p_dest = (u16 *)p_spu->p_sys->p_data;
605 /* The subtitles are interlaced, we need two offsets */
606 unsigned int i_id = 0; /* Start on the even SPU layer */
607 unsigned int pi_table[ 2 ];
608 unsigned int *pi_offset;
610 vlc_bool_t b_empty_top = 1,
612 unsigned int i_skipped_top = 0,
613 i_skipped_bottom = 0;
615 /* Colormap statistics */
617 int stats[4]; stats[0] = stats[1] = stats[2] = stats[3] = 0;
619 pi_table[ 0 ] = p_spu->p_sys->pi_offset[ 0 ] << 1;
620 pi_table[ 1 ] = p_spu->p_sys->pi_offset[ 1 ] << 1;
622 for( i_y = 0 ; i_y < i_height ; i_y++ )
624 pi_offset = pi_table + i_id;
626 for( i_x = 0 ; i_x < i_width ; i_x += i_code >> 2 )
628 i_code = AddNibble( 0, p_src, pi_offset );
632 i_code = AddNibble( i_code, p_src, pi_offset );
636 i_code = AddNibble( i_code, p_src, pi_offset );
640 i_code = AddNibble( i_code, p_src, pi_offset );
642 if( i_code < 0x0100 )
644 /* If the 14 first bits are set to 0, then it's a
645 * new line. We emulate it. */
646 if( i_code < 0x0004 )
648 i_code |= ( i_width - i_x ) << 2;
652 /* We have a boo boo ! */
653 msg_Err( p_spudec->p_fifo, "unknown RLE code "
662 if( ( (i_code >> 2) + i_x + i_y * i_width ) > i_height * i_width )
664 msg_Err( p_spudec->p_fifo,
665 "out of bounds, %i at (%i,%i) is out of %ix%i",
666 i_code >> 2, i_x, i_y, i_width, i_height );
670 /* Try to find the border color */
671 if( p_spu->p_sys->pi_alpha[ i_code & 0x3 ] != 0x00 )
673 i_border = i_code & 0x3;
674 stats[i_border] += i_code >> 2;
677 if( (i_code >> 2) == i_width
678 && p_spu->p_sys->pi_alpha[ i_code & 0x3 ] == 0x00 )
682 /* This is a blank top line, we skip it */
687 /* We can't be sure the current lines will be skipped,
688 * so we store the code just in case. */
697 /* We got a valid code, store it */
700 /* Valid code means no blank line */
703 i_skipped_bottom = 0;
707 /* Check that we didn't go too far */
710 msg_Err( p_spudec->p_fifo, "i_x overflowed, %i > %i",
715 /* Byte-align the stream */
716 if( *pi_offset & 0x1 )
725 /* We shouldn't get any padding bytes */
728 msg_Err( p_spudec->p_fifo, "padding bytes found in RLE sequence" );
729 msg_Err( p_spudec->p_fifo, "send mail to <sam@zoy.org> if you "
730 "want to help debugging this" );
732 /* Skip them just in case */
733 while( i_y < i_height )
735 *p_dest++ = i_width << 2;
742 msg_Dbg( p_spudec->p_fifo, "valid subtitle, size: %ix%i, position: %i,%i",
743 p_spu->i_width, p_spu->i_height, p_spu->i_x, p_spu->i_y );
745 /* Crop if necessary */
746 if( i_skipped_top || i_skipped_bottom )
748 p_spu->i_y += i_skipped_top;
749 p_spu->i_height -= i_skipped_top + i_skipped_bottom;
751 msg_Dbg( p_spudec->p_fifo, "cropped to: %ix%i, position: %i,%i",
752 p_spu->i_width, p_spu->i_height, p_spu->i_x, p_spu->i_y );
755 /* Handle color if no palette was found */
756 if( !p_spu->p_sys->b_palette )
758 int i, i_inner = -1, i_shade = -1;
760 /* Set the border color */
761 p_spu->p_sys->pi_yuv[i_border][0] = 0x00;
762 p_spu->p_sys->pi_yuv[i_border][1] = 0x80;
763 p_spu->p_sys->pi_yuv[i_border][2] = 0x80;
766 /* Find the inner colors */
767 for( i = 0 ; i < 4 && i_inner == -1 ; i++ )
775 for( ; i < 4 && i_shade == -1 ; i++ )
779 if( stats[i] > stats[i_inner] )
791 /* Set the inner color */
794 p_spu->p_sys->pi_yuv[i_inner][0] = 0xff;
795 p_spu->p_sys->pi_yuv[i_inner][1] = 0x80;
796 p_spu->p_sys->pi_yuv[i_inner][2] = 0x80;
799 /* Set the anti-aliasing color */
802 p_spu->p_sys->pi_yuv[i_shade][0] = 0x80;
803 p_spu->p_sys->pi_yuv[i_shade][1] = 0x80;
804 p_spu->p_sys->pi_yuv[i_shade][2] = 0x80;
807 msg_Dbg( p_spudec->p_fifo,
808 "using custom palette (border %i, inner %i, shade %i)",
809 i_border, i_inner, i_shade );
815 /*****************************************************************************
816 * RenderSPU: draw an SPU on a picture
817 *****************************************************************************
818 * This is a fast implementation of the subpicture drawing code. The data
819 * has been preprocessed once, so we don't need to parse the RLE buffer again
820 * and again. Most sanity checks are already done so that this routine can be
821 * as fast as possible.
822 *****************************************************************************/
823 static void RenderSPU( vout_thread_t *p_vout, picture_t *p_pic,
824 const subpicture_t *p_spu )
826 /* Common variables */
830 u16 *p_source = (u16 *)p_spu->p_sys->p_data;
837 int i_xscale, i_yscale, i_width, i_height, i_ytmp, i_yreal, i_ynext;
839 switch( p_vout->output.i_chroma )
841 /* I420 target, no scaling */
846 p_dest = p_pic->Y_PIXELS + p_spu->i_x + p_spu->i_width
847 + p_pic->Y_PITCH * ( p_spu->i_y + p_spu->i_height );
849 /* Draw until we reach the bottom of the subtitle */
850 for( i_y = p_spu->i_height * p_pic->Y_PITCH ;
852 i_y -= p_pic->Y_PITCH )
854 /* Draw until we reach the end of the line */
855 for( i_x = p_spu->i_width ; i_x ; )
857 /* Get the RLE part, then draw the line */
858 i_color = *p_source & 0x3;
860 switch( p_spu->p_sys->pi_alpha[ i_color ] )
863 i_x -= *p_source++ >> 2;
867 i_len = *p_source++ >> 2;
868 memset( p_dest - i_x - i_y,
869 p_spu->p_sys->pi_yuv[i_color][0], i_len );
874 /* FIXME: we should do transparency */
875 i_len = *p_source++ >> 2;
876 memset( p_dest - i_x - i_y,
877 p_spu->p_sys->pi_yuv[i_color][0], i_len );
886 /* RV16 target, scaling */
889 /* XXX: this is a COMPLETE HACK, memcpy is unable to do u16s anyway */
890 /* FIXME: get this from the DVD */
891 for( i_color = 0; i_color < 4; i_color++ )
893 p_clut16[i_color] = 0x1111
894 * ( (u16)p_spu->p_sys->pi_yuv[i_color][0] >> 4 );
897 i_xscale = ( p_vout->output.i_width << 6 ) / p_vout->render.i_width;
898 i_yscale = ( p_vout->output.i_height << 6 ) / p_vout->render.i_height;
900 i_width = p_spu->i_width * i_xscale;
901 i_height = p_spu->i_height * i_yscale;
903 p_dest = p_pic->p->p_pixels + ( i_width >> 6 ) * 2
904 /* Add the picture coordinates and the SPU coordinates */
905 + ( (p_spu->i_x * i_xscale) >> 6 ) * 2
906 + ( (p_spu->i_y * i_yscale) >> 6 ) * p_pic->p->i_pitch;
908 /* Draw until we reach the bottom of the subtitle */
909 for( i_y = 0 ; i_y < i_height ; )
914 /* Check whether we need to draw one line or more than one */
915 if( i_ytmp + 1 >= ( i_y >> 6 ) )
917 /* Just one line : we precalculate i_y >> 6 */
918 i_yreal = p_pic->p->i_pitch * i_ytmp;
920 /* Draw until we reach the end of the line */
921 for( i_x = i_width ; i_x ; )
923 /* Get the RLE part, then draw the line */
924 i_color = *p_source & 0x3;
926 switch( p_spu->p_sys->pi_alpha[ i_color ] )
929 i_x -= i_xscale * ( *p_source++ >> 2 );
933 i_len = i_xscale * ( *p_source++ >> 2 );
934 memset( p_dest - 2 * ( i_x >> 6 ) + i_yreal,
936 2 * ( ( i_len >> 6 ) + 1 ) );
941 /* FIXME: we should do transparency */
942 i_len = i_xscale * ( *p_source++ >> 2 );
943 memset( p_dest - 2 * ( i_x >> 6 ) + i_yreal,
945 2 * ( ( i_len >> 6 ) + 1 ) );
954 i_yreal = p_pic->p->i_pitch * i_ytmp;
955 i_ynext = p_pic->p->i_pitch * i_y >> 6;
957 /* Draw until we reach the end of the line */
958 for( i_x = i_width ; i_x ; )
960 /* Get the RLE part, then draw as many lines as needed */
961 i_color = *p_source & 0x3;
963 switch( p_spu->p_sys->pi_alpha[ i_color ] )
966 i_x -= i_xscale * ( *p_source++ >> 2 );
970 i_len = i_xscale * ( *p_source++ >> 2 );
971 for( i_ytmp = i_yreal ; i_ytmp < i_ynext ;
972 i_ytmp += p_pic->p->i_pitch )
974 memset( p_dest - 2 * ( i_x >> 6 ) + i_ytmp,
976 2 * ( ( i_len >> 6 ) + 1 ) );
982 /* FIXME: we should do transparency */
983 i_len = i_xscale * ( *p_source++ >> 2 );
984 for( i_ytmp = i_yreal ; i_ytmp < i_ynext ;
985 i_ytmp += p_pic->p->i_pitch )
987 memset( p_dest - 2 * ( i_x >> 6 ) + i_ytmp,
989 2 * ( ( i_len >> 6 ) + 1 ) );
1000 /* RV32 target, scaling */
1004 /* XXX: this is a COMPLETE HACK, memcpy is unable to do u32s anyway */
1005 /* FIXME: get this from the DVD */
1006 for( i_color = 0; i_color < 4; i_color++ )
1008 p_clut32[i_color] = 0x11111111
1009 * ( (u16)p_spu->p_sys->pi_yuv[i_color][0] >> 4 );
1012 i_xscale = ( p_vout->output.i_width << 6 ) / p_vout->render.i_width;
1013 i_yscale = ( p_vout->output.i_height << 6 ) / p_vout->render.i_height;
1015 i_width = p_spu->i_width * i_xscale;
1016 i_height = p_spu->i_height * i_yscale;
1018 p_dest = p_pic->p->p_pixels + ( i_width >> 6 ) * 4
1019 /* Add the picture coordinates and the SPU coordinates */
1020 + ( (p_spu->i_x * i_xscale) >> 6 ) * 4
1021 + ( (p_spu->i_y * i_yscale) >> 6 ) * p_pic->p->i_pitch;
1023 /* Draw until we reach the bottom of the subtitle */
1024 for( i_y = 0 ; i_y < i_height ; )
1029 /* Check whether we need to draw one line or more than one */
1030 if( i_ytmp + 1 >= ( i_y >> 6 ) )
1032 /* Just one line : we precalculate i_y >> 6 */
1033 i_yreal = p_pic->p->i_pitch * i_ytmp;
1035 /* Draw until we reach the end of the line */
1036 for( i_x = i_width ; i_x ; )
1038 /* Get the RLE part, then draw the line */
1039 i_color = *p_source & 0x3;
1041 switch( p_spu->p_sys->pi_alpha[ i_color ] )
1044 i_x -= i_xscale * ( *p_source++ >> 2 );
1048 i_len = i_xscale * ( *p_source++ >> 2 );
1049 memset( p_dest - 4 * ( i_x >> 6 ) + i_yreal,
1050 p_clut32[ i_color ], 4 * ( ( i_len >> 6 ) + 1 ) );
1055 /* FIXME: we should do transparency */
1056 i_len = i_xscale * ( *p_source++ >> 2 );
1057 memset( p_dest - 4 * ( i_x >> 6 ) + i_yreal,
1058 p_clut32[ i_color ], 4 * ( ( i_len >> 6 ) + 1 ) );
1067 i_yreal = p_pic->p->i_pitch * i_ytmp;
1068 i_ynext = p_pic->p->i_pitch * i_y >> 6;
1070 /* Draw until we reach the end of the line */
1071 for( i_x = i_width ; i_x ; )
1073 /* Get the RLE part, then draw as many lines as needed */
1074 i_color = *p_source & 0x3;
1076 switch( p_spu->p_sys->pi_alpha[ i_color ] )
1079 i_x -= i_xscale * ( *p_source++ >> 2 );
1083 i_len = i_xscale * ( *p_source++ >> 2 );
1084 for( i_ytmp = i_yreal ; i_ytmp < i_ynext ;
1085 i_ytmp += p_pic->p->i_pitch )
1087 memset( p_dest - 4 * ( i_x >> 6 ) + i_ytmp,
1088 p_clut32[ i_color ],
1089 4 * ( ( i_len >> 6 ) + 1 ) );
1095 /* FIXME: we should do transparency */
1096 i_len = i_xscale * ( *p_source++ >> 2 );
1097 for( i_ytmp = i_yreal ; i_ytmp < i_ynext ;
1098 i_ytmp += p_pic->p->i_pitch )
1100 memset( p_dest - 4 * ( i_x >> 6 ) + i_ytmp,
1101 p_clut32[ i_color ],
1102 4 * ( ( i_len >> 6 ) + 1 ) );
1113 /* NVidia overlay, no scaling */
1116 p_dest = p_pic->p->p_pixels +
1117 (p_spu->i_x + p_spu->i_width +
1118 p_vout->output.i_width * ( p_spu->i_y + p_spu->i_height )) * 2;
1119 /* Draw until we reach the bottom of the subtitle */
1120 for( i_y = p_spu->i_height * p_vout->output.i_width;
1122 i_y -= p_vout->output.i_width )
1124 /* Draw until we reach the end of the line */
1125 for( i_x = p_spu->i_width ; i_x ; )
1127 /* Get the RLE part, then draw the line */
1128 i_color = *p_source & 0x3;
1130 switch( p_spu->p_sys->pi_alpha[ i_color ] )
1133 i_x -= *p_source++ >> 2;
1137 i_len = *p_source++ >> 2;
1138 for( i_cnt = 0; i_cnt < i_len; i_cnt++ )
1142 memset( p_dest - i_x * 2 - i_y * 2 + i_cnt * 2,
1143 p_spu->p_sys->pi_yuv[i_color][0], 1);
1145 if (!(i_cnt & 0x01))
1148 memset( p_dest - i_x * 2 - i_y * 2 + i_cnt * 2 + 1,
1150 memset( p_dest - i_x * 2 - i_y * 2 + i_cnt * 2 + 3,
1158 /* FIXME: we should do transparency */
1159 i_len = *p_source++ >> 2;
1160 for( i_cnt = 0; i_cnt < i_len; i_cnt++ )
1164 memset( p_dest - i_x * 2 - i_y * 2 + i_cnt * 2,
1165 p_spu->p_sys->pi_yuv[i_color][0], 1);
1167 if (!(i_cnt & 0x01))
1170 memset( p_dest - i_x * 2 - i_y * 2 + i_cnt * 2 + 1,
1172 memset( p_dest - i_x * 2 - i_y * 2 + i_cnt * 2 + 3,
1186 msg_Err( p_vout, "unknown chroma, can't render SPU" );